Add test for implicit layer with 0.1 API version
authorCharles Giessen <charles@lunarg.com>
Wed, 26 Jan 2022 20:14:22 +0000 (13:14 -0700)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 28 Jan 2022 23:24:27 +0000 (16:24 -0700)
The loader disables implicit layers if their API version isn't the same or
greater than the application. Make sure this still works even with pre 1.0
versions.

tests/framework/test_environment.cpp
tests/framework/test_util.cpp
tests/framework/test_util.h
tests/loader_layer_tests.cpp

index 6dc74dd3bfb40c7aa193b24c962d7a363992de4d..e3818d8f58b0e1fc782f5f40e0f7d0d06ff13d29 100644 (file)
@@ -228,7 +228,6 @@ void FrameworkEnvironment::add_layer_impl(TestLayerDetails layer_details, fs::Fo
 
             // Don't load the layer binary if using any of the wrap objects layers, since it doesn't export the same interface
             // functions
-            std::cout << "stem: " << layer.lib_path.stem().str() << "\n";
             if (layer.lib_path.stem().str().find(fs::path(TEST_LAYER_WRAP_OBJECTS).stem().str()) == std::string::npos) {
                 layers.push_back(TestLayerHandle(new_layer_location));
                 layers.back().reset_layer();
index 9f0efa87dba6a987ee8c92c9a7276bb3f25a29b5..dd6f466e9d4c874427d869c513093bf578e4a863 100644 (file)
@@ -600,12 +600,14 @@ InstanceCreateInfo::InstanceCreateInfo() {
 }
 
 VkInstanceCreateInfo* InstanceCreateInfo::get() noexcept {
-    application_info.pApplicationName = app_name.c_str();
-    application_info.pEngineName = engine_name.c_str();
-    application_info.applicationVersion = app_version;
-    application_info.engineVersion = engine_version;
-    application_info.apiVersion = api_version;
-    instance_info.pApplicationInfo = &application_info;
+    if (fill_in_application_info) {
+        application_info.pApplicationName = app_name.c_str();
+        application_info.pEngineName = engine_name.c_str();
+        application_info.applicationVersion = app_version;
+        application_info.engineVersion = engine_version;
+        application_info.apiVersion = api_version;
+        instance_info.pApplicationInfo = &application_info;
+    }
     instance_info.enabledLayerCount = static_cast<uint32_t>(enabled_layers.size());
     instance_info.ppEnabledLayerNames = enabled_layers.data();
     instance_info.enabledExtensionCount = static_cast<uint32_t>(enabled_extensions.size());
index 5578edaa60bd4afdbc7de653e4670bc101d2781e..a6521b0ec65be23ea1f3228a20a7657145b2530d 100644 (file)
@@ -723,10 +723,13 @@ struct InstanceCreateInfo {
     BUILDER_VALUE(InstanceCreateInfo, uint32_t, api_version, VK_MAKE_VERSION(1, 0, 0))
     BUILDER_VECTOR(InstanceCreateInfo, const char*, enabled_layers, layer)
     BUILDER_VECTOR(InstanceCreateInfo, const char*, enabled_extensions, extension)
+    // tell the get() function to not provide `application_info`
+    BUILDER_VALUE(InstanceCreateInfo, bool, fill_in_application_info, true)
 
     InstanceCreateInfo();
 
     VkInstanceCreateInfo* get() noexcept;
+
     InstanceCreateInfo& set_api_version(uint32_t major, uint32_t minor, uint32_t patch);
 };
 
index ba9ff745b92302757355b4056929f9be3b04e636..9abb4cde112e09b1ce99c89f0dbc8f87e15ee137 100644 (file)
@@ -2169,7 +2169,7 @@ TEST(TestLayers, NewerInstanceVersionThanImplicitLayer) {
     EXPECT_EQ(layer_count, 1);
     EXPECT_TRUE(string_eq(layer_props[0].layerName, regular_layer_name));
 
-    {  // 1.1 instance -- instance layer should be found
+    {  // 1.1 instance - should find the implicit layer
         InstWrapper inst{env.vulkan_functions};
         inst.create_info.set_api_version(1, 1, 0);
         inst.CheckCreate();
@@ -2202,3 +2202,98 @@ TEST(TestLayers, NewerInstanceVersionThanImplicitLayer) {
         ASSERT_EQ(0, count);
     }
 }
+
+TEST(TestLayers, ImplicitLayerPre10APIVersion) {
+    FrameworkEnvironment env;
+    env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6, VK_MAKE_API_VERSION(0, 1, 2, 0)));
+    env.get_test_icd().icd_api_version = VK_MAKE_API_VERSION(0, 1, 2, 0);
+    VkPhysicalDeviceProperties properties{};
+    properties.apiVersion = VK_MAKE_API_VERSION(0, 1, 2, 0);
+    env.get_test_icd().add_physical_device({});
+    env.get_test_icd().physical_devices.back().set_properties(properties);
+
+    const char* regular_layer_name = "VK_LAYER_TestLayer1";
+    env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
+                                                         .set_name(regular_layer_name)
+                                                         .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
+                                                         .set_api_version(VK_MAKE_API_VERSION(0, 0, 1, 0))
+                                                         .set_disable_environment("DisableMeIfYouCan")),
+                           "regular_test_layer.json");
+
+    uint32_t layer_count = 0;
+    EXPECT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumerateInstanceLayerProperties(&layer_count, nullptr));
+    EXPECT_EQ(layer_count, 1);
+
+    std::array<VkLayerProperties, 1> layer_props;
+    EXPECT_EQ(VK_SUCCESS, env.vulkan_functions.vkEnumerateInstanceLayerProperties(&layer_count, layer_props.data()));
+    EXPECT_EQ(layer_count, 1);
+    EXPECT_TRUE(string_eq(layer_props[0].layerName, regular_layer_name));
+
+    {  // 1.0 instance -- instance layer should be found
+        DebugUtilsLogger log;
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 0, 0);
+        FillDebugUtilsCreateDetails(inst.create_info, log);
+        inst.CheckCreate();
+        ASSERT_TRUE(log.find(std::string("loader_add_implicit_layer: Disabling implicit layer ") + regular_layer_name +
+                             " for using an old API version 0.1 versus application requested 1.0"));
+        VkPhysicalDevice phys_dev = inst.GetPhysDev();
+
+        uint32_t count = 0;
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, nullptr);
+        ASSERT_EQ(0, count);
+        VkLayerProperties layer_props{};
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, &layer_props);
+        ASSERT_EQ(0, count);
+    }
+    {  // 1.1 instance -- instance layer should be found
+        DebugUtilsLogger log;
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 1, 0);
+        FillDebugUtilsCreateDetails(inst.create_info, log);
+        inst.CheckCreate();
+        ASSERT_TRUE(log.find(std::string("loader_add_implicit_layer: Disabling implicit layer ") + regular_layer_name +
+                             " for using an old API version 0.1 versus application requested 1.1"));
+        VkPhysicalDevice phys_dev = inst.GetPhysDev();
+        uint32_t count = 0;
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, nullptr);
+        ASSERT_EQ(0, count);
+        VkLayerProperties layer_props{};
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, &layer_props);
+        ASSERT_EQ(0, count);
+    }
+    {  // 1.2 instance -- instance layer shouldn't be found
+        DebugUtilsLogger log;
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_api_version(1, 2, 0);
+        FillDebugUtilsCreateDetails(inst.create_info, log);
+        inst.CheckCreate();
+        VkPhysicalDevice phys_dev = inst.GetPhysDev();
+        ASSERT_TRUE(log.find(std::string("loader_add_implicit_layer: Disabling implicit layer ") + regular_layer_name +
+                             " for using an old API version 0.1 versus application requested 1.2"));
+
+        uint32_t count = 0;
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, nullptr);
+        ASSERT_EQ(0, count);
+        VkLayerProperties layer_props{};
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, &layer_props);
+        ASSERT_EQ(0, count);
+    }
+    {  // application doesn't state its API version
+        DebugUtilsLogger log;
+        InstWrapper inst{env.vulkan_functions};
+        inst.create_info.set_fill_in_application_info(false);
+        FillDebugUtilsCreateDetails(inst.create_info, log);
+        inst.CheckCreate();
+        EXPECT_TRUE(log.find(std::string("loader_add_implicit_layer: Disabling implicit layer ") + regular_layer_name +
+                             " for using an old API version 0.1 versus application requested 1.0"));
+        VkPhysicalDevice phys_dev = inst.GetPhysDev();
+
+        uint32_t count = 0;
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, nullptr);
+        ASSERT_EQ(0, count);
+        VkLayerProperties layer_props{};
+        env.vulkan_functions.vkEnumerateDeviceLayerProperties(phys_dev, &count, &layer_props);
+        ASSERT_EQ(0, count);
+    }
+}