Make maintenance 5 require the feature to be enabled
authorCharles Giessen <charles@lunarg.com>
Wed, 2 Aug 2023 18:31:06 +0000 (12:31 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 2 Aug 2023 18:46:31 +0000 (12:46 -0600)
The maintenance 5 behavior should only apply when the feature is enabled in
addition to the extension being enabled.

loader/loader.c
tests/loader_get_proc_addr_tests.cpp

index 667efdde4564c8d15a9ec8f0eb8e3b03ff2c9443..e646b28b470a1465f73a82885b7505d717de35d4 100644 (file)
@@ -5837,6 +5837,30 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physical
         }
     }
 
+    VkBool32 maintenance5_feature_enabled = false;
+    // Look for the VkPhysicalDeviceMaintenance5FeaturesKHR struct to see if the feature was enabled
+    {
+        const void *pNext = localCreateInfo.pNext;
+        while (pNext != NULL) {
+            switch (*(VkStructureType *)pNext) {
+                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR: {
+                    const VkPhysicalDeviceMaintenance5FeaturesKHR *maintenance_features = pNext;
+                    if (maintenance_features->maintenance5 == VK_TRUE) {
+                        maintenance5_feature_enabled = true;
+                    }
+                    pNext = maintenance_features->pNext;
+                    break;
+                }
+
+                default: {
+                    const VkBaseInStructure *header = pNext;
+                    pNext = header->pNext;
+                    break;
+                }
+            }
+        }
+    }
+
     // Every extension that has a loader-defined terminator needs to be marked as enabled or disabled so that we know whether or
     // not to return that terminator when vkGetDeviceProcAddr is called
     for (uint32_t i = 0; i < localCreateInfo.enabledExtensionCount; ++i) {
@@ -5850,7 +5874,8 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDevice(VkPhysicalDevice physical
             dev->extensions.ext_debug_marker_enabled = true;
         } else if (!strcmp(localCreateInfo.ppEnabledExtensionNames[i], "VK_EXT_full_screen_exclusive")) {
             dev->extensions.ext_full_screen_exclusive_enabled = true;
-        } else if (!strcmp(localCreateInfo.ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE_5_EXTENSION_NAME)) {
+        } else if (!strcmp(localCreateInfo.ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE_5_EXTENSION_NAME) &&
+                   maintenance5_feature_enabled) {
             dev->should_ignore_device_commands_from_newer_version = true;
         }
     }
index 83d5a6ae9429d08be5d832cc99296f365d47ca43..6a167d160717d0cfcd9df4e14d611074fbd8f723 100644 (file)
@@ -318,7 +318,7 @@ TEST(GetDeviceProcAddr, AppQueries11FunctionsWhileOnlyEnabling10) {
     for (const auto& f : functions) {
         driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
     }
-    {
+    {  // doesn't enable the feature or extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 0, 0);
         inst.CheckCreate();
@@ -329,13 +329,30 @@ TEST(GetDeviceProcAddr, AppQueries11FunctionsWhileOnlyEnabling10) {
             ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
         }
     }
-    {
+    {  // doesn't enable the feature
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 0, 0);
+        inst.CheckCreate();
+
+        DeviceWrapper dev{inst};
+        dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.CheckCreate(inst.GetPhysDev());
+        for (const auto& f : functions) {
+            ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
+        }
+    }
+    {  // enables the feature and extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 0, 0);
         inst.CheckCreate();
 
+        VkPhysicalDeviceMaintenance5FeaturesKHR features{};
+        features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
+        features.maintenance5 = VK_TRUE;
+
         DeviceWrapper dev{inst};
         dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.create_info.dev.pNext = &features;
         dev.CheckCreate(inst.GetPhysDev());
         for (const auto& f : functions) {
             ASSERT_EQ(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
@@ -355,7 +372,7 @@ TEST(GetDeviceProcAddr, AppQueries12FunctionsWhileOnlyEnabling11) {
     for (const auto& f : functions) {
         driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
     }
-    {
+    {  // doesn't enable the feature or extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 1, 0);
         inst.CheckCreate();
@@ -367,13 +384,31 @@ TEST(GetDeviceProcAddr, AppQueries12FunctionsWhileOnlyEnabling11) {
             ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
         }
     }
-    {
+    {  // doesn't enable the feature
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 1, 0);
+        inst.CheckCreate();
+
+        DeviceWrapper dev{inst};
+        dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.CheckCreate(inst.GetPhysDev());
+
+        for (const auto& f : functions) {
+            ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
+        }
+    }
+    {  // enables the feature and extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 1, 0);
         inst.CheckCreate();
 
+        VkPhysicalDeviceMaintenance5FeaturesKHR features{};
+        features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
+        features.maintenance5 = VK_TRUE;
+
         DeviceWrapper dev{inst};
         dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.create_info.dev.pNext = &features;
         dev.CheckCreate(inst.GetPhysDev());
 
         for (const auto& f : functions) {
@@ -395,7 +430,7 @@ TEST(GetDeviceProcAddr, AppQueries13FunctionsWhileOnlyEnabling12) {
     for (const auto& f : functions) {
         driver.physical_devices.back().add_device_function(VulkanFunction{f, [] {}});
     }
-    {
+    {  // doesn't enable the feature or extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 2, 0);
         inst.CheckCreate();
@@ -407,13 +442,31 @@ TEST(GetDeviceProcAddr, AppQueries13FunctionsWhileOnlyEnabling12) {
             ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
         }
     }
-    {
+    {  // doesn't enable the feature
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 2, 0);
+        inst.CheckCreate();
+
+        DeviceWrapper dev{inst};
+        dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.CheckCreate(inst.GetPhysDev());
+
+        for (const auto& f : functions) {
+            ASSERT_NE(nullptr, dev->vkGetDeviceProcAddr(dev.dev, f));
+        }
+    }
+    {  // enables the feature and extension
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 2, 0);
         inst.CheckCreate();
 
+        VkPhysicalDeviceMaintenance5FeaturesKHR features{};
+        features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_5_FEATURES_KHR;
+        features.maintenance5 = VK_TRUE;
+
         DeviceWrapper dev{inst};
         dev.create_info.add_extension(VK_KHR_MAINTENANCE_5_EXTENSION_NAME);
+        dev.create_info.dev.pNext = &features;
         dev.CheckCreate(inst.GetPhysDev());
 
         for (const auto& f : functions) {