summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-10-17 18:18:03 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-10-17 18:18:03 +0300
commit9990c8d617d84e0d86ad680c39f648b0fab0906c (patch)
treee833e3e9e625439ef0f6224eceeb8652b00bb0bb /src/device.c
parent2de6a8b665eda6ac50fe4c507e57e95315a0912b (diff)
fix unique queue family bug
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/device.c b/src/device.c
index d899062..9836db1 100644
--- a/src/device.c
+++ b/src/device.c
@@ -223,20 +223,34 @@ static int create_logical_device(device_t device, struct device_info *info)
find_queue_families(device->physical_device, device->surface, &indices);
// queue infos
- VkDeviceQueueCreateInfo *queue_infos = xcalloc(QUEUE_FAMILY_COUNT, sizeof(VkDeviceQueueCreateInfo));
- memset(queue_infos, 0, QUEUE_FAMILY_COUNT * sizeof(VkDeviceQueueCreateInfo));
-
- uint32_t *queue_indices = xcalloc(QUEUE_FAMILY_COUNT, sizeof(uint32_t));
- queue_indices[0] = indices.graphics_family;
- queue_indices[1] = indices.present_family;
+ VkDeviceQueueCreateInfo queue_infos[QUEUE_FAMILY_COUNT] = {0};
+ uint32_t queue_indices[QUEUE_FAMILY_COUNT] = {
+ indices.graphics_family, indices.present_family,
+ };
+
+ uint32_t unique_queue_family_count = 0;
float queue_priority = 1.0f;
+
+ // basically get add only the unique queue families
for(int i = 0; i < QUEUE_FAMILY_COUNT; i++)
{
- queue_infos[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- queue_infos[i].queueFamilyIndex = queue_indices[i];
- queue_infos[i].queueCount = 1;
- queue_infos[i].pQueuePriorities = &queue_priority;
+ int unique = 1;
+ for(int j = 0; j < i; j++) {
+ if(queue_indices[i] == queue_indices[j]) {
+ unique = 0;
+ break;
+ }
+ }
+
+ if(!unique) continue;
+
+ queue_infos[unique_queue_family_count].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
+ queue_infos[unique_queue_family_count].queueFamilyIndex = queue_indices[i];
+ queue_infos[unique_queue_family_count].queueCount = 1;
+ queue_infos[unique_queue_family_count].pQueuePriorities = &queue_priority;
+
+ unique_queue_family_count++;
}
// device features
@@ -247,7 +261,7 @@ static int create_logical_device(device_t device, struct device_info *info)
create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
create_info.pQueueCreateInfos = queue_infos;
- create_info.queueCreateInfoCount = QUEUE_FAMILY_COUNT;
+ create_info.queueCreateInfoCount = unique_queue_family_count;
create_info.pEnabledFeatures = &device_features;
@@ -265,9 +279,6 @@ static int create_logical_device(device_t device, struct device_info *info)
// vkGetDeviceQueue(device->logical_device, indices.graphics_family, 0, &device->graphics_queue);
- free(queue_infos);
- free(queue_indices);
-
return 0;
fail:
return 1;