sandbox
Loading...
Searching...
No Matches
logical_device.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_GRAPHICS_DEVICES_LOGICAL_DEVICE_HPP_
3#define LIBSBX_GRAPHICS_DEVICES_LOGICAL_DEVICE_HPP_
4
5#include <unordered_map>
6#include <optional>
7#include <cinttypes>
8
9#include <vulkan/vulkan.hpp>
10
11#include <libsbx/utility/noncopyable.hpp>
12#include <libsbx/utility/enum.hpp>
13
14#include <libsbx/graphics/devices/instance.hpp>
15#include <libsbx/graphics/devices/physical_device.hpp>
16
17namespace sbx::graphics {
18
20
21 friend class logical_device;
22
23public:
24
25 enum class type : std::uint32_t {
26 graphics = 0,
27 present = 1,
28 compute = 2,
29 transfer = 3
30 }; // enum class type
31
32 queue(queue&& other) noexcept = default;
33
34 ~queue() = default;
35
36 auto operator=(queue&& other) noexcept -> queue& = default;
37
38 auto handle() const noexcept -> const VkQueue&;
39
40 operator const VkQueue&() const noexcept;
41
42 auto family() const noexcept -> std::uint32_t;
43
44 auto wait_idle() const -> void;
45
46private:
47
48 queue()
49 : _handle{VK_NULL_HANDLE},
50 _family{0xFFFFFFFF} { }
51
52 queue(const VkQueue& handle, std::uint32_t family)
53 : _handle{handle},
54 _family{family} { }
55
56 VkQueue _handle{};
57 std::uint32_t _family{};
58
59}; // class queue
60
62
63public:
64
66
68
69 auto handle() const noexcept -> const VkDevice&;
70
71 operator const VkDevice&() const noexcept;
72
73 auto enabled_features() const -> const physical_device::device_features&;
74
75 template<queue::type Type>
76 auto queue() const -> const graphics::queue& {
77 return _queues.at(utility::to_underlying(Type));
78 }
79
80 auto wait_idle() const -> void;
81
82private:
83
84 struct queue_family_indices {
85 std::optional<std::uint32_t> graphics{};
86 std::optional<std::uint32_t> present{};
87 std::optional<std::uint32_t> compute{};
88 std::optional<std::uint32_t> transfer{};
89 }; // struct queue_family_indices
90
91 template<queue::type Type>
92 auto _get_queue(const std::uint32_t queue_family_index, std::uint32_t index = 0u) -> void {
93 auto handle = VkQueue{};
94
95 vkGetDeviceQueue(_handle, queue_family_index, index, &handle);
96
97 _queues.at(utility::to_underlying(Type)) = graphics::queue{handle, queue_family_index};
98 }
99
100 auto _get_queue_family_indices(const physical_device& physical_device) const -> queue_family_indices;
101
102 auto _get_enabled_features(const physical_device& physical_device) const -> physical_device::device_features;
103
104 auto _create_logical_device(const physical_device& physical_device) -> void;
105
106 VkDevice _handle{};
107 physical_device::device_features _enabled_features{};
108 // std::unordered_map<queue::type, graphics::queue> _queues{};
109 std::array<graphics::queue, 4u> _queues{};
110
111}; // class logical_device
112
113} // namespace sbx::graphics
114
115#endif // LIBSBX_GRAPHICS_DEVICES_LOGICAL_DEVICE_HPP_
116
Definition: logical_device.hpp:61
Definition: physical_device.hpp:17
Definition: logical_device.hpp:19
Definition: physical_device.hpp:21
Definition: noncopyable.hpp:7