extension: remove duplicated extensions in vk_EnumerateDeviceExtensionProperties 91/84991/3
authordeasung.kim <deasung.kim@samsung.com>
Tue, 23 Aug 2016 07:30:37 +0000 (16:30 +0900)
committerGwan-gyeong Mun <kk.moon@samsung.com>
Fri, 26 Aug 2016 16:23:31 +0000 (09:23 -0700)
Khronos Vulkan loader removes duplicated extension.
on previous implementation, if vk_EnumerateDeviceExtensionProperties call twice, then returned count is not same between first and second when the extensions has duplicate entry.

this patch eliminates duplicated extensions in vk_EnumerateDeviceExtensionProperties on vulkan-wsi-tizen's internal data structure.
Change-Id: Ie8cb66c45a626f46af040866737359cc046b18dc

src/wsi/extensions.c

index e93ad78..921e786 100644 (file)
@@ -59,18 +59,47 @@ vk_EnumerateDeviceExtensionProperties(VkPhysicalDevice               pdev,
        vk_icd_t        *icd = vk_get_icd();
        uint32_t         max_ext_count, remaining, copied = 0;
        VkResult         result;
+       uint32_t i, j, copy_count = 0;
 
        result = icd->enum_dev_exts(pdev, layer_name, &max_ext_count, NULL);
        VK_CHECK(result == VK_SUCCESS, return VK_ERROR_OUT_OF_HOST_MEMORY,
                         "vkEnumerateDeviceExtensionProperties() failed.\n");
 
-       max_ext_count += ARRAY_LENGTH(wsi_device_extensions);
-
        if (!extensions) {
-               *count = max_ext_count;
+               /*
+                * for CTS fail return count
+                * loader remove duplicates extension
+                * second called count is not same when extensions has duplicate entry
+                */
+               VkExtensionProperties   *device_extensions =
+                       vk_alloc(vk_get_allocator(NULL, NULL),
+                                        max_ext_count * sizeof(VkExtensionProperties),
+                                        VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+               VK_CHECK(device_extensions, return VK_ERROR_OUT_OF_HOST_MEMORY, "malloc failed().\n");
+
+               result = icd->enum_dev_exts(pdev, layer_name, &max_ext_count, device_extensions);
+               VK_CHECK(result == VK_SUCCESS, return VK_ERROR_OUT_OF_HOST_MEMORY,
+                                "vkEnumerateDeviceExtensionProperties() failed.\n");
+
+               for (i = 0; i < ARRAY_LENGTH(wsi_device_extensions); i++) {
+                       for (j = 0; j < max_ext_count; j++) {
+                               if (strcmp(device_extensions[j].extensionName,
+                                                  wsi_device_extensions[i].extensionName) == 0) {
+                                       break;
+                               }
+                       }
+                       if (j == max_ext_count)
+                               copy_count++;
+               }
+               vk_free(vk_get_allocator(NULL, NULL), device_extensions);
+
+               *count = max_ext_count + copy_count;
+
                return VK_SUCCESS;
        }
 
+       max_ext_count += ARRAY_LENGTH(wsi_device_extensions);
+
        /* Copy ICD extensions and WSI extensions together into the given pointer. */
 
        /* Calculate the number of extensions we have to copy. */
@@ -84,8 +113,27 @@ vk_EnumerateDeviceExtensionProperties(VkPhysicalDevice               pdev,
 
        /* Calculate remaining extensions to copy. */
        remaining = MIN(remaining - copied, ARRAY_LENGTH(wsi_device_extensions));
-       memcpy(extensions + copied, wsi_device_extensions, remaining * sizeof(VkExtensionProperties));
-       copied += remaining;
+
+       /* Copy non duplicate entries */
+       for (i = 0; i < ARRAY_LENGTH(wsi_device_extensions); i++) {
+               for (j = 0; j < copied; j++) {
+                       if (strcmp(extensions[j].extensionName,
+                                          wsi_device_extensions[i].extensionName) == 0) {
+                               max_ext_count--;
+                               break;
+                       }
+               }
+               if (j == copied) {
+                       if (copy_count < remaining) {
+                               memcpy(extensions + copied + copy_count,
+                                          &wsi_device_extensions[i], sizeof(VkExtensionProperties));
+                               copy_count++;
+                       } else {
+                               break;
+                       }
+               }
+       }
+       copied += copy_count;
 
        /* Return the number of extensions copied. */
        *count = copied;