demos: Update demos and tests to use vkGetGlobalExtensionInfo to check extensions
authorTobin Ehlis <tobin@lunarg.com>
Fri, 17 Apr 2015 00:04:57 +0000 (18:04 -0600)
committerTobin Ehlis <tobin@lunarg.com>
Fri, 17 Apr 2015 14:46:24 +0000 (08:46 -0600)
demos/cube.c
demos/tri.c
demos/vulkaninfo.c

index 8927a0a..3516e00 100644 (file)
@@ -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;
index 847e273..f8f3edd 100644 (file)
@@ -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;
index 2fc76eb..2353ff2 100644 (file)
@@ -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];
     }
 }