Enhance warning messages for portability enumeration
authorCharles Giessen <charles@lunarg.com>
Mon, 24 Jul 2023 16:37:25 +0000 (10:37 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 24 Jul 2023 18:07:44 +0000 (12:07 -0600)
There are three different ways for applications to fail to enumerate
portability drivers, not enabling the flag bit, not enabling the extension,
and both. These were all reported as the same error, which isn't as helpful
as it printing a separate message for each case.

This also makes it possible to emit a VUID for the case of setting the flag
bit but not the extension.

loader/loader_common.h
loader/trampoline.c
tests/loader_regression_tests.cpp

index 249d96faa18bc036e60a1a090f21edac90ba9355..7d05e17e8972068c9025d6507140089c2b0b6799 100644 (file)
@@ -311,6 +311,8 @@ struct loader_instance {
     loader_settings settings;
 
     bool portability_enumeration_enabled;
+    bool portability_enumeration_flag_bit_set;
+    bool portability_enumeration_extension_enabled;
 
     bool wsi_surface_enabled;
 #if defined(VK_USE_PLATFORM_WIN32_KHR)
index 51cd17f0bfa496c7f40068f57b857dc9f583bfc1..bae33ff0336d4add03ece855dc22baba06c1539a 100644 (file)
@@ -517,12 +517,18 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
 
     // Check the VkInstanceCreateInfoFlags wether to allow the portability enumeration flag
     if ((pCreateInfo->flags & VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR) == 1) {
-        // Make sure the extension has been enabled
+        ptr_instance->portability_enumeration_flag_bit_set = true;
+    }
+    // Make sure the extension has been enabled
+    if (pCreateInfo->ppEnabledExtensionNames) {
         for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
             if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0) {
-                ptr_instance->portability_enumeration_enabled = true;
-                loader_log(ptr_instance, VULKAN_LOADER_INFO_BIT, 0,
-                           "Portability enumeration bit was set, enumerating portability drivers.");
+                ptr_instance->portability_enumeration_extension_enabled = true;
+                if (ptr_instance->portability_enumeration_flag_bit_set) {
+                    ptr_instance->portability_enumeration_enabled = true;
+                    loader_log(ptr_instance, VULKAN_LOADER_INFO_BIT, 0,
+                               "Portability enumeration bit was set, enumerating portability drivers.");
+                }
             }
         }
     }
@@ -566,12 +572,27 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCr
     if (ptr_instance->icd_tramp_list.count == 0) {
         // No drivers found
         if (skipped_portability_drivers) {
-            loader_log(
-                ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
-                "vkCreateInstance: Found drivers that contain devices which support the portability subset, but the "
-                "portability enumeration bit was not set! Applications that wish to enumerate portability drivers must set the "
-                "VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags and "
-                "enable the VK_KHR_portability_enumeration instance extension.");
+            if (ptr_instance->portability_enumeration_extension_enabled && !ptr_instance->portability_enumeration_flag_bit_set) {
+                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
+                           "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
+                           "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
+                           "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
+                           "flags.");
+            } else if (ptr_instance->portability_enumeration_flag_bit_set &&
+                       !ptr_instance->portability_enumeration_extension_enabled) {
+                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
+                           "VkInstanceCreateInfo: If flags has the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit set, the "
+                           "list of enabled extensions in ppEnabledExtensionNames must contain VK_KHR_portability_enumeration "
+                           "[VUID-VkInstanceCreateInfo-flags-06559 ]"
+                           "Applications that wish to enumerate portability drivers must enable the VK_KHR_portability_enumeration "
+                           "instance extension.");
+            } else {
+                loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0,
+                           "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
+                           "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
+                           "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
+                           "flags and enable the VK_KHR_portability_enumeration instance extension.");
+            }
         }
         loader_log(ptr_instance, VULKAN_LOADER_ERROR_BIT | VULKAN_LOADER_DRIVER_BIT, 0, "vkCreateInstance: Found no drivers!");
         res = VK_ERROR_INCOMPATIBLE_DRIVER;
index 39fa0d4a7333d067a69eb4058ae948d3592e97b0..dd6a6301f83efb34bf62b06210e2a58d17854ab2 100644 (file)
@@ -3532,10 +3532,23 @@ TEST(SortedPhysicalDevices, DeviceGroupsSortedDisabled) {
 #endif  // __linux__ || __FreeBSD__ || __OpenBSD__ || __GNU__
 
 const char* portability_driver_warning =
-    "vkCreateInstance: Found drivers that contain devices which support the portability subset, but the "
-    "portability enumeration bit was not set! Applications that wish to enumerate portability drivers must set the "
-    "VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags and "
-    "enable the VK_KHR_portability_enumeration instance extension.";
+    "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
+    "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
+    "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
+    "flags and enable the VK_KHR_portability_enumeration instance extension.";
+
+const char* portability_flag_missing =
+    "vkCreateInstance: Found drivers that contain devices which support the portability subset, but "
+    "the instance does not enumerate portability drivers! Applications that wish to enumerate portability "
+    "drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo "
+    "flags.";
+
+const char* portability_extension_missing =
+    "VkInstanceCreateInfo: If flags has the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit set, the "
+    "list of enabled extensions in ppEnabledExtensionNames must contain VK_KHR_portability_enumeration "
+    "[VUID-VkInstanceCreateInfo-flags-06559 ]"
+    "Applications that wish to enumerate portability drivers must enable the VK_KHR_portability_enumeration "
+    "instance extension.";
 
 TEST(PortabilityICDConfiguration, PortabilityICDOnly) {
     FrameworkEnvironment env{};
@@ -3561,6 +3574,8 @@ TEST(PortabilityICDConfiguration, PortabilityICDOnly) {
         DeviceWrapper dev_info{inst};
         dev_info.CheckCreate(phys_dev);
         ASSERT_FALSE(log.find(portability_driver_warning));
+        ASSERT_FALSE(log.find(portability_flag_missing));
+        ASSERT_FALSE(log.find(portability_extension_missing));
     }
     {  // enable portability flag but not extension - shouldn't be able to create an instance when filtering is enabled
         InstWrapper inst{env.vulkan_functions};
@@ -3568,7 +3583,7 @@ TEST(PortabilityICDConfiguration, PortabilityICDOnly) {
         inst.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
         FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
         inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
-        ASSERT_TRUE(env.debug_log.find(portability_driver_warning));
+        ASSERT_TRUE(env.debug_log.find(portability_extension_missing));
     }
     {  // enable portability extension but not flag - shouldn't be able to create an instance when filtering is enabled
         InstWrapper inst{env.vulkan_functions};
@@ -3576,7 +3591,7 @@ TEST(PortabilityICDConfiguration, PortabilityICDOnly) {
         inst.create_info.add_extension(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
         FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
         inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
-        ASSERT_TRUE(env.debug_log.find(portability_driver_warning));
+        ASSERT_TRUE(env.debug_log.find(portability_flag_missing));
     }
     {  // enable neither the portability extension or the flag - shouldn't be able to create an instance when filtering is enabled
         InstWrapper inst{env.vulkan_functions};