From 7b6317f4de6dc4f31064b0ed6e0d2647d0724f15 Mon Sep 17 00:00:00 2001 From: Warwick Date: Fri, 1 Nov 2024 16:58:35 +0000 Subject: [PATCH] Added code for finding suitable graphics family queue --- src/main.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 26e1a18..4e5d3e3 100644 --- a/src/main.c +++ b/src/main.c @@ -216,7 +216,38 @@ void DestroyDebugUtilsMessengerEXT(VkInstance instance, } } -bool isDeviceSuitable(VkPhysicalDevice device) { return true; } +struct QueueFamilyIndices_s { + bool graphicsFamilyExists; + uint32_t graphicsFamily; +} QueueFamilyIndices_default = {.graphicsFamilyExists = false, + .graphicsFamily = 0}; +typedef struct QueueFamilyIndices_s QueueFamilyIndices; + +QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device) { + QueueFamilyIndices indices = QueueFamilyIndices_default; + + uint32_t queueFamilyCount = 0; + vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, NULL); + VkQueueFamilyProperties queueFamilies[queueFamilyCount]; + vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, + queueFamilies); + + for (uint32_t i = 0; i < queueFamilyCount; i++) { + if (queueFamilies[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { + indices.graphicsFamily = i; + indices.graphicsFamilyExists = true; + break; // remove if we need additional checks in future + } + } + + return indices; +} + +bool isDeviceSuitable(VkPhysicalDevice device) { + QueueFamilyIndices indices = findQueueFamilies(device); + + return indices.graphicsFamilyExists; +} void pickPhysicalDevice(Application *app) { VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; @@ -231,13 +262,15 @@ void pickPhysicalDevice(Application *app) { vkEnumeratePhysicalDevices(app->instance, &physicalDeviceCount, physicalDevices); + // TODO: pick device off of more than if it's just suitable for (int i = 0; i < physicalDeviceCount; i++) { if (isDeviceSuitable(physicalDevices[i])) { physicalDevice = physicalDevices[i]; + break; } } - - if (physicalDevice == VK_NULL_HANDLE){ + + if (physicalDevice == VK_NULL_HANDLE) { fprintf(stderr, "Failed to find suitable GPU\n"); exit(EXIT_FAILURE); }