radv: Track enabled extensions.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 10 Feb 2018 23:32:34 +0000 (00:32 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Thu, 22 Feb 2018 23:39:02 +0000 (00:39 +0100)
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_private.h

index 9ee8ae2beb08a23daaa5ce923a5b45edf92b5e0e..79534fbd5fc4c9f744a9bdf4a7b99aa025b23483 100644 (file)
@@ -414,6 +414,16 @@ radv_handle_per_app_options(struct radv_instance *instance,
        }
 }
 
+static int radv_get_instance_extension_index(const char *name)
+{
+       for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) {
+               if (strcmp(name, radv_instance_extensions[i].extensionName) == 0)
+                       return i;
+       }
+       return -1;
+}
+
+
 VkResult radv_CreateInstance(
        const VkInstanceCreateInfo*                 pCreateInfo,
        const VkAllocationCallbacks*                pAllocator,
@@ -441,12 +451,6 @@ VkResult radv_CreateInstance(
                                 VK_VERSION_PATCH(client_version));
        }
 
-       for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-               const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
-               if (!radv_instance_extension_supported(ext_name))
-                       return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
-       }
-
        instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
                              VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
        if (!instance)
@@ -462,6 +466,18 @@ VkResult radv_CreateInstance(
        instance->apiVersion = client_version;
        instance->physicalDeviceCount = -1;
 
+       for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
+               const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
+               int index = radv_get_instance_extension_index(ext_name);
+
+               if (index < 0 || !radv_supported_instance_extensions.extensions[index]) {
+                       vk_free2(&default_alloc, pAllocator, instance);
+                       return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+               }
+
+               instance->enabled_extensions.extensions[index] = true;
+       }
+
        result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
        if (result != VK_SUCCESS) {
                vk_free2(&default_alloc, pAllocator, instance);
@@ -1091,6 +1107,15 @@ radv_device_init_gs_info(struct radv_device *device)
        }
 }
 
+static int radv_get_device_extension_index(const char *name)
+{
+       for (unsigned i = 0; i < RADV_DEVICE_EXTENSION_COUNT; ++i) {
+               if (strcmp(name, radv_device_extensions[i].extensionName) == 0)
+                       return i;
+       }
+       return -1;
+}
+
 VkResult radv_CreateDevice(
        VkPhysicalDevice                            physicalDevice,
        const VkDeviceCreateInfo*                   pCreateInfo,
@@ -1103,15 +1128,6 @@ VkResult radv_CreateDevice(
 
        bool keep_shader_info = false;
 
-       for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
-               const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
-               if (!radv_physical_device_extension_supported(physical_device, ext_name))
-                       return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
-
-               if (strcmp(ext_name, VK_AMD_SHADER_INFO_EXTENSION_NAME) == 0)
-                       keep_shader_info = true;
-       }
-
        /* Check enabled features */
        if (pCreateInfo->pEnabledFeatures) {
                VkPhysicalDeviceFeatures supported_features;
@@ -1141,6 +1157,19 @@ VkResult radv_CreateDevice(
        else
                device->alloc = physical_device->instance->alloc;
 
+       for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
+               const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
+               int index = radv_get_device_extension_index(ext_name);
+               if (index < 0 || !physical_device->supported_extensions.extensions[index]) {
+                       vk_free(&device->alloc, device);
+                       return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT);
+               }
+
+               device->enabled_extensions.extensions[index] = true;
+       }
+
+       keep_shader_info = device->enabled_extensions.AMD_shader_info;
+
        mtx_init(&device->shader_slab_mutex, mtx_plain);
        list_inithead(&device->shader_slabs);
 
@@ -2243,16 +2272,6 @@ VkResult radv_DeviceWaitIdle(
        return VK_SUCCESS;
 }
 
-bool
-radv_instance_extension_supported(const char *name)
-{
-       for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) {
-               if (strcmp(name, radv_instance_extensions[i].extensionName) == 0)
-                       return radv_supported_instance_extensions.extensions[i];
-       }
-       return false;
-}
-
 VkResult radv_EnumerateInstanceExtensionProperties(
     const char*                                 pLayerName,
     uint32_t*                                   pPropertyCount,
@@ -2271,17 +2290,6 @@ VkResult radv_EnumerateInstanceExtensionProperties(
        return vk_outarray_status(&out);
 }
 
-bool
-radv_physical_device_extension_supported(struct radv_physical_device *device,
-                                        const char *name)
-{
-       for (unsigned i = 0; i < RADV_DEVICE_EXTENSION_COUNT; ++i) {
-               if (strcmp(name, radv_device_extensions[i].extensionName) == 0)
-                       return device->supported_extensions.extensions[i];
-       }
-       return false;
-}
-
 VkResult radv_EnumerateDeviceExtensionProperties(
     VkPhysicalDevice                            physicalDevice,
     const char*                                 pLayerName,
index 335c8417e77134567c1c7b1f8372bd489036f6e7..18665557eda30fc5c1f92dc957be36beca39a78b 100644 (file)
@@ -303,6 +303,8 @@ struct radv_instance {
        uint64_t perftest_flags;
 
        struct vk_debug_report_instance             debug_report_callbacks;
+
+       struct radv_instance_extension_table enabled_extensions;
 };
 
 VkResult radv_init_wsi(struct radv_physical_device *physical_device);
@@ -639,6 +641,8 @@ struct radv_device {
 
        /* For detecting VM faults reported by dmesg. */
        uint64_t dmesg_timestamp;
+
+       struct radv_device_extension_table enabled_extensions;
 };
 
 struct radv_device_memory {