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