From 99239dcdcd02a30bd1a63d12a3cf88cdd46b6608 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Thu, 16 Apr 2015 18:04:57 -0600 Subject: demos: Update demos and tests to use vkGetGlobalExtensionInfo to check extensions --- demos/cube.c | 31 ++++++++++++++++++++++--------- demos/tri.c | 30 ++++++++++++++++++++++-------- demos/vulkaninfo.c | 35 +++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/demos/cube.c b/demos/cube.c index 8927a0ad..3516e002 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -1651,7 +1651,25 @@ static void demo_create_window(struct demo *demo) static void demo_init_vk(struct demo *demo) { - // TODO : Should query count w/ GetGlobalExtensionInfo, then enable via CreateInstance + VkResult err; + // Extensions to enable + const char *ext_names[] = { + "VK_WSI_X11", + }; + size_t extSize = sizeof(uint32_t); + uint32_t extCount = 0; + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); + assert(!err); + + VkExtensionProperties extProp; + extSize = sizeof(VkExtensionProperties); + bool32_t extFound = 0; + for (uint32_t i = 0; i < extCount; i++) { + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &extSize, &extProp); + if (!strcmp(ext_names[0], extProp.extName)) + extFound = 1; + } + assert(extFound); const VkApplicationInfo app = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pNext = NULL, @@ -1666,8 +1684,8 @@ static void demo_init_vk(struct demo *demo) .pNext = NULL, .pAppInfo = &app, .pAllocCb = NULL, - .extensionCount = 0, - .ppEnabledExtensionNames = NULL, + .extensionCount = 1, + .ppEnabledExtensionNames = ext_names, }; const VK_WSI_X11_CONNECTION_INFO connection = { .pConnection = demo->connection, @@ -1679,20 +1697,15 @@ static void demo_init_vk(struct demo *demo) .queueCount = 1, }; - const char *ext_names[] = { - "VK_WSI_X11", - }; - const VkDeviceCreateInfo device = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = NULL, .queueRecordCount = 1, .pRequestedQueues = &queue, - .extensionCount = 1, // TODO : Should query count w/ GetGlobalExtensionInfo + .extensionCount = 1, .ppEnabledExtensionNames = ext_names, .flags = VK_DEVICE_CREATE_VALIDATION_BIT, }; - VkResult err; uint32_t gpu_count; uint32_t i; size_t data_size; diff --git a/demos/tri.c b/demos/tri.c index 847e273b..f8f3edde 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -1192,7 +1192,25 @@ static void demo_create_window(struct demo *demo) static void demo_init_vk(struct demo *demo) { - // TODO : Should query count w/ GetGlobalExtensionInfo, then enable via CreateInstance + VkResult err; + // Extensions to enable + const char *ext_names[] = { + "VK_WSI_X11", + }; + size_t extSize = sizeof(uint32_t); + uint32_t extCount = 0; + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); + assert(!err); + + VkExtensionProperties extProp; + extSize = sizeof(VkExtensionProperties); + bool32_t extFound = 0; + for (uint32_t i = 0; i < extCount; i++) { + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &extSize, &extProp); + if (!strcmp(ext_names[0], extProp.extName)) + extFound = 1; + } + assert(extFound); const VkApplicationInfo app = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pNext = NULL, @@ -1207,8 +1225,8 @@ static void demo_init_vk(struct demo *demo) .pNext = NULL, .pAppInfo = &app, .pAllocCb = NULL, - .extensionCount = 0, - .ppEnabledExtensionNames = NULL, + .extensionCount = 1, + .ppEnabledExtensionNames = ext_names, }; const VK_WSI_X11_CONNECTION_INFO connection = { .pConnection = demo->connection, @@ -1219,19 +1237,15 @@ static void demo_init_vk(struct demo *demo) .queueNodeIndex = 0, .queueCount = 1, }; - const char *ext_names[] = { - "VK_WSI_X11", - }; const VkDeviceCreateInfo device = { .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = NULL, .queueRecordCount = 1, .pRequestedQueues = &queue, - .extensionCount = 1, // TODO : Should query count w/ GetGlobalExtensionInfo + .extensionCount = 1, .ppEnabledExtensionNames = ext_names, .flags = VK_DEVICE_CREATE_VALIDATION_BIT, }; - VkResult err; uint32_t gpu_count; uint32_t i; size_t data_size; diff --git a/demos/vulkaninfo.c b/demos/vulkaninfo.c index 2fc76ebe..2353ff23 100644 --- a/demos/vulkaninfo.c +++ b/demos/vulkaninfo.c @@ -364,22 +364,27 @@ static void app_dev_destroy(struct app_dev *dev) static void app_gpu_init_extensions(struct app_gpu *gpu) { - //VkResult err; - uint32_t i; - // TODO : Should query count w/ GetGlobalExtensionInfo, - // Then dynamically set extensions based on returned count - + VkResult err; + // Extensions to enable static char *known_extensions[] = { "VK_WSI_X11", }; - - for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { -/* - err = vkGetExtensionSupport(gpu->obj, known_extensions[i]); - if (!err) -*/ - gpu->extension_count++; + size_t extSize = sizeof(uint32_t); + uint32_t extCount = 0; + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_COUNT, 0, &extSize, &extCount); + assert(!err); + + VkExtensionProperties extProp; + extSize = sizeof(VkExtensionProperties); + bool32_t extFound = 0; // TODO : Need to enhance this if/when we enable multiple extensions + for (uint32_t i = 0; i < extCount; i++) { + err = vkGetGlobalExtensionInfo(VK_EXTENSION_INFO_TYPE_PROPERTIES, i, &extSize, &extProp); + if (!strcmp(known_extensions[0], extProp.extName)) { + extFound = 1; + gpu->extension_count++; + } } + assert(extFound); gpu->extensions = malloc(sizeof(gpu->extensions[0]) * gpu->extension_count); @@ -387,11 +392,9 @@ static void app_gpu_init_extensions(struct app_gpu *gpu) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY); gpu->extension_count = 0; + uint32_t i; for (i = 0; i < ARRAY_SIZE(known_extensions); i++) { -/* - err = vkGetExtensionSupport(gpu->obj, known_extensions[i]); - if (!err) -*/ + // known_extensions were validated above so copy them over here gpu->extensions[gpu->extension_count++] = known_extensions[i]; } } -- cgit v1.2.3