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
12#include <libsbx/graphics/devices/instance.hpp>
13#include <libsbx/graphics/devices/physical_device.hpp>
14
15namespace sbx::graphics {
16
18
19 friend class logical_device;
20
21public:
22
23 enum class type : std::uint32_t {
24 graphics,
25 present,
26 compute,
27 transfer
28 }; // enum class type
29
30 queue(queue&& other) noexcept = default;
31
32 ~queue() = default;
33
34 auto operator=(queue&& other) noexcept -> queue& = default;
35
36 auto handle() const noexcept -> const VkQueue&;
37
38 operator const VkQueue&() const noexcept;
39
40 auto family() const noexcept -> std::uint32_t;
41
42 auto wait_idle() const -> void;
43
44private:
45
46 queue(const VkQueue& handle, std::uint32_t family)
47 : _handle{handle},
48 _family{family} { }
49
50 VkQueue _handle{};
51 std::uint32_t _family{};
52
53}; // class queue
54
56
57public:
58
60
62
63 auto handle() const noexcept -> const VkDevice&;
64
65 operator const VkDevice&() const noexcept;
66
67 auto enabled_features() const -> const VkPhysicalDeviceFeatures&;
68
69 template<queue::type Type>
70 auto queue() const -> const graphics::queue& {
71 return _queues.at(Type);
72 }
73
74 auto wait_idle() const -> void;
75
76private:
77
78 struct queue_family_indices {
79 std::optional<std::uint32_t> graphics{};
80 std::optional<std::uint32_t> present{};
81 std::optional<std::uint32_t> compute{};
82 std::optional<std::uint32_t> transfer{};
83 }; // struct queue_family_indices
84
85 auto _get_queue_family_indices(const physical_device& physical_device) const -> queue_family_indices;
86
87 auto _get_enabled_features(const physical_device& physical_device) const -> VkPhysicalDeviceFeatures;
88
89 auto _create_logical_device(const physical_device& physical_device) -> void;
90
91 VkDevice _handle{};
92 VkPhysicalDeviceFeatures _enabled_features{};
93 std::unordered_map<queue::type, graphics::queue> _queues{};
94
95}; // class logical_device
96
97} // namespace sbx::graphics
98
99#endif // LIBSBX_GRAPHICS_DEVICES_LOGICAL_DEVICE_HPP_
100
Definition: logical_device.hpp:55
Definition: physical_device.hpp:16
Definition: logical_device.hpp:17
Definition: noncopyable.hpp:6