1.3.72
 
Loading...
Searching...
No Matches
VulkanDevice.h
Go to the documentation of this file.
1
16#ifndef VULKAN_DEVICE_H
17#define VULKAN_DEVICE_H
18
19#include "global.h"
20#include <vulkan/vulkan.h>
21
22// Suppress nullability warnings from VMA header on macOS
23#ifdef __clang__
24#pragma clang diagnostic push
25#pragma clang diagnostic ignored "-Wnullability-completeness"
26#endif
27#include <vk_mem_alloc.h>
28#ifdef __clang__
29#pragma clang diagnostic pop
30#endif
31
32#include <vector>
33#include <string>
34
35namespace helios {
36
48 public:
51
52 // Delete copy/move constructors - this class manages Vulkan resources
53 VulkanDevice(const VulkanDevice &) = delete;
54 VulkanDevice &operator=(const VulkanDevice &) = delete;
55 VulkanDevice(VulkanDevice &&) = delete;
56 VulkanDevice &operator=(VulkanDevice &&) = delete;
57
65 void initialize(bool enable_validation = false);
66
72 void shutdown();
73
81 bool supportsAtomicFloat() const {
82 return has_atomic_float;
83 }
84
92 bool isMoltenVK() const {
93 return is_moltenvk;
94 }
95
99 VkInstance getInstance() const {
100 return instance;
101 }
102
106 VkPhysicalDevice getPhysicalDevice() const {
107 return physical_device;
108 }
109
113 VkDevice getDevice() const {
114 return device;
115 }
116
120 VkQueue getComputeQueue() const {
121 return compute_queue;
122 }
123
127 uint32_t getComputeQueueFamily() const {
128 return compute_queue_family;
129 }
130
134 VmaAllocator getAllocator() const {
135 return allocator;
136 }
137
141 const VkPhysicalDeviceProperties &getDeviceProperties() const {
142 return device_properties;
143 }
144
148 void printDeviceInfo() const;
149
162
163 private:
164 // Vulkan handles
165 VkInstance instance = VK_NULL_HANDLE;
166 VkPhysicalDevice physical_device = VK_NULL_HANDLE;
167 VkDevice device = VK_NULL_HANDLE;
168 VkQueue compute_queue = VK_NULL_HANDLE;
169 uint32_t compute_queue_family = 0;
170
171 // Memory allocator
172 VmaAllocator allocator = VK_NULL_HANDLE;
173
174 // Device properties and features
175 VkPhysicalDeviceProperties device_properties{};
176 bool has_atomic_float = false;
177 bool is_moltenvk = false;
178
179 // Optional: validation layers
180 VkDebugUtilsMessengerEXT debug_messenger = VK_NULL_HANDLE;
181
185 void createInstance(bool enable_validation);
186
190 void selectPhysicalDevice();
191
195 void createLogicalDevice();
196
200 void createAllocator();
201
205 void setupDebugMessenger();
206
212 uint32_t findComputeQueueFamily(VkPhysicalDevice device_candidate) const;
213
219 uint32_t scorePhysicalDevice(VkPhysicalDevice device_candidate) const;
220
224 bool isDeviceSuitable(VkPhysicalDevice device_candidate) const;
225
229 void detectMoltenVK();
230
234 void detectAtomicFloat();
235 };
236
237} // namespace helios
238
239#endif // VULKAN_DEVICE_H