Added code for finding suitable graphics family queue
This commit is contained in:
parent
15dde5dc91
commit
7b6317f4de
1 changed files with 36 additions and 3 deletions
35
src/main.c
35
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,9 +262,11 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue