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 queue(const queue::type type) const -> const graphics::queue& {
81 return _queues.at(utility::to_underlying(type));
82 }
83
84 auto wait_idle() const -> void;
85
86private:
87
88 struct queue_family_indices {
89 std::optional<std::uint32_t> graphics{};
90 std::optional<std::uint32_t> present{};
91 std::optional<std::uint32_t> compute{};
92 std::optional<std::uint32_t> transfer{};
93 }; // struct queue_family_indices
94
95 template<queue::type Type>
96 auto _get_queue(const std::uint32_t queue_family_index, std::uint32_t index = 0u) -> void {
97 auto handle = VkQueue{};
98
99 vkGetDeviceQueue(_handle, queue_family_index, index, &handle);
100
101 _queues.at(utility::to_underlying(Type)) = graphics::queue{handle, queue_family_index};
102 }
103
104 auto _get_queue_family_indices(const physical_device& physical_device) const -> queue_family_indices;
105
106 auto _get_enabled_features(const physical_device& physical_device) const -> physical_device::device_features;
107
108 auto _create_logical_device(const physical_device& physical_device) -> void;
109
110 VkDevice _handle{};
111 physical_device::device_features _enabled_features{};
112 // std::unordered_map<queue::type, graphics::queue> _queues{};
113 std::array<graphics::queue, 4u> _queues{};
114
115}; // class logical_device
116
117} // namespace sbx::graphics
118
119#endif // LIBSBX_GRAPHICS_DEVICES_LOGICAL_DEVICE_HPP_
120
Definition: logical_device.hpp:61
Definition: physical_device.hpp:17
Definition: logical_device.hpp:19
Definition: physical_device.hpp:21
Definition: noncopyable.hpp:7