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
37
src/main.c
37
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) {
|
void pickPhysicalDevice(Application *app) {
|
||||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||||
|
|
@ -231,13 +262,15 @@ void pickPhysicalDevice(Application *app) {
|
||||||
vkEnumeratePhysicalDevices(app->instance, &physicalDeviceCount,
|
vkEnumeratePhysicalDevices(app->instance, &physicalDeviceCount,
|
||||||
physicalDevices);
|
physicalDevices);
|
||||||
|
|
||||||
|
// TODO: pick device off of more than if it's just suitable
|
||||||
for (int i = 0; i < physicalDeviceCount; i++) {
|
for (int i = 0; i < physicalDeviceCount; i++) {
|
||||||
if (isDeviceSuitable(physicalDevices[i])) {
|
if (isDeviceSuitable(physicalDevices[i])) {
|
||||||
physicalDevice = physicalDevices[i];
|
physicalDevice = physicalDevices[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (physicalDevice == VK_NULL_HANDLE){
|
if (physicalDevice == VK_NULL_HANDLE) {
|
||||||
fprintf(stderr, "Failed to find suitable GPU\n");
|
fprintf(stderr, "Failed to find suitable GPU\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue