15 : m_physical_device(other.m_physical_device)
16 , m_logical_device(other.m_logical_device)
17 , m_graphics_queue(other.m_graphics_queue)
18 , m_compute_queue(other.m_compute_queue)
19 , m_transfer_queue(other.m_transfer_queue)
20 , m_queue_families(other.m_queue_families)
22 other.m_physical_device = VK_NULL_HANDLE;
23 other.m_logical_device = VK_NULL_HANDLE;
24 other.m_graphics_queue = VK_NULL_HANDLE;
25 other.m_compute_queue = VK_NULL_HANDLE;
26 other.m_transfer_queue = VK_NULL_HANDLE;
33 m_physical_device = other.m_physical_device;
34 m_logical_device = other.m_logical_device;
35 m_graphics_queue = other.m_graphics_queue;
36 m_compute_queue = other.m_compute_queue;
37 m_transfer_queue = other.m_transfer_queue;
38 m_queue_families = other.m_queue_families;
40 other.m_physical_device = VK_NULL_HANDLE;
41 other.m_logical_device = VK_NULL_HANDLE;
42 other.m_graphics_queue = VK_NULL_HANDLE;
43 other.m_compute_queue = VK_NULL_HANDLE;
44 other.m_transfer_queue = VK_NULL_HANDLE;
74 vk::Instance vk_instance(instance);
75 auto devices = vk_instance.enumeratePhysicalDevices();
77 if (devices.empty()) {
79 std::source_location::current(),
80 "Failed to find GPUs with Vulkan support!");
83 for (
const auto& device : devices) {
90 vk::PhysicalDeviceProperties props = device.getProperties();
92 "Selected GPU: {}", props.deviceName.data());
98 std::source_location::current(),
99 "Failed to find a suitable GPU!");
106 auto queue_families = device.getQueueFamilyProperties();
109 for (
const auto& queue_family : queue_families) {
110 if (queue_family.queueCount > 0 && queue_family.queueFlags & vk::QueueFlagBits::eGraphics) {
114 if (queue_family.queueCount > 0 && queue_family.queueFlags & vk::QueueFlagBits::eCompute && !(queue_family.queueFlags & vk::QueueFlagBits::eGraphics)) {
118 if (queue_family.queueCount > 0 && queue_family.queueFlags & vk::QueueFlagBits::eTransfer && !(queue_family.queueFlags & vk::QueueFlagBits::eGraphics) && !(queue_family.queueFlags & vk::QueueFlagBits::eCompute)) {
122 if (surface && queue_family.queueCount > 0) {
123 vk::Bool32 presentSupport = device.getSurfaceSupportKHR(i, surface);
124 if (presentSupport) {
127 "Found presentation support in queue family {}", i);
150 "No surface provided for presentation support check");
156 for (uint32_t i = 0; i < queue_families.size(); i++) {
157 if (queue_families[i].queueCount > 0) {
159 if (presentSupport) {
164 "Graphics queue family {} supports presentation", i);
171 for (uint32_t i = 0; i < queue_families.size(); i++) {
172 if (queue_families[i].queueCount > 0) {
174 if (presentSupport) {
178 "Found presentation support in queue family {}", i);
185 "No queue family with presentation support found!");
191 std::vector<vk::ExtensionProperties> availableExtensions =
m_physical_device.enumerateDeviceExtensionProperties();
194 for (
const auto& extension : availableExtensions) {
195 std::cout <<
"\t- " << extension.extensionName <<
" (Version: " << extension.specVersion <<
")\n";
204 std::source_location::current(),
205 "No graphics queue family found!");
208 std::set<uint32_t> unique_queue_families;
219 std::vector<vk::DeviceQueueCreateInfo> queue_create_infos;
220 float queue_priority = 1.0F;
222 for (uint32_t queue_family : unique_queue_families) {
223 vk::DeviceQueueCreateInfo queue_create_info {};
224 queue_create_info.queueFamilyIndex = queue_family;
225 queue_create_info.queueCount = 1;
226 queue_create_info.pQueuePriorities = &queue_priority;
227 queue_create_infos.push_back(queue_create_info);
230 vk::PhysicalDeviceFeatures device_features {};
237 std::vector<const char*> device_extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
240 device_extensions.push_back(ext.c_str());
243 vk::DeviceCreateInfo create_info {};
244 create_info.queueCreateInfoCount =
static_cast<uint32_t
>(queue_create_infos.size());
245 create_info.pQueueCreateInfos = queue_create_infos.data();
246 create_info.pEnabledFeatures = &device_features;
247 create_info.enabledExtensionCount =
static_cast<uint32_t
>(device_extensions.size());
248 create_info.ppEnabledExtensionNames = device_extensions.data();
253 }
catch (
const std::exception& e) {
255 std::source_location::current(),
256 "Failed to create logical device: {}", e.what());
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_PRINT(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
void query_supported_extensions()
Query and log supported device extensions.
bool pick_physical_device(vk::Instance instance, vk::SurfaceKHR temp_surface)
Pick a suitable physical device (GPU)
void cleanup()
Cleanup device resources.
VKDevice & operator=(const VKDevice &)=delete
vk::PhysicalDevice m_physical_device
Selected physical device (GPU)
vk::Queue m_compute_queue
Compute queue handle.
bool create_logical_device(vk::Instance instance, const GraphicsBackendInfo &backend_info)
Create the logical device and retrieve queue handles.
vk::Queue m_transfer_queue
Transfer queue handle.
vk::Device m_logical_device
Logical device handle.
QueueFamilyIndices find_queue_families(vk::PhysicalDevice device, vk::SurfaceKHR surface=nullptr)
Find queue families on the given physical device.
bool update_presentation_queue(vk::SurfaceKHR surface)
Update presentation queue family for a specific surface.
bool m_presentation_initialized
vk::Queue m_graphics_queue
Graphics queue handle.
bool initialize(vk::Instance instance, vk::SurfaceKHR temp_surface, const GraphicsBackendInfo &backend_info)
Initialize device (pick physical device and create logical device)
QueueFamilyIndices m_queue_families
Indices of required queue families.
Manages Vulkan physical device selection and logical device creation.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.
bool enable_compute_queue
Enable compute queue (separate from graphics)
std::vector< std::string > required_extensions
Backend-specific extensions to request.
bool enable_transfer_queue
Enable transfer queue (separate from graphics)
struct MayaFlux::Core::GraphicsBackendInfo::@0 required_features
Required device features (Vulkan-specific)
bool tessellation_shaders
Configuration for graphics API backend (Vulkan/OpenGL/etc.)
std::optional< uint32_t > transfer_family
std::optional< uint32_t > graphics_family
std::optional< uint32_t > present_family
std::optional< uint32_t > compute_family
Stores indices of queue families we need.