From cfe07e3648fe89ef5d909ab92b562419db5369f0 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Tue, 5 Sep 2023 16:44:38 -0600 Subject: [PATCH] Add Debug extension support to test layer Debug utils, debug report, and debug marker are now supported directly in the test layer, allowing easy testing of the behavior of layers which support these debug extensions. This allows testing the matrix of combinations between drivers, layers, and loader support for these debug extensions. This commit also adds a 'injected_extension' concept into the test_layer, which allows recreating the behavior of layers which modify the extension list returned by the driver. --- tests/framework/layer/test_layer.cpp | 248 ++++++++++++++++++++++++++++++++++- tests/framework/layer/test_layer.h | 8 ++ tests/loader_debug_ext_tests.cpp | 150 ++++++++++++++------- 3 files changed, 356 insertions(+), 50 deletions(-) diff --git a/tests/framework/layer/test_layer.cpp b/tests/framework/layer/test_layer.cpp index 72d5162..c2747c8 100644 --- a/tests/framework/layer/test_layer.cpp +++ b/tests/framework/layer/test_layer.cpp @@ -87,6 +87,30 @@ FRAMEWORK_EXPORT TestLayer* reset_layer_func() { } } +bool IsInstanceExtensionSupported(const char* extension_name) { + return layer.instance_extensions.end() != + std::find_if(layer.instance_extensions.begin(), layer.instance_extensions.end(), + [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); }); +} + +bool IsInstanceExtensionEnabled(const char* extension_name) { + return layer.enabled_instance_extensions.end() != + std::find_if(layer.enabled_instance_extensions.begin(), layer.enabled_instance_extensions.end(), + [extension_name](Extension const& ext) { return string_eq(&ext.extensionName[0], extension_name); }); +} + +bool IsDeviceExtensionAvailable(VkDevice dev, const char* extension_name) { + for (auto& device : layer.created_devices) { + if ((dev == VK_NULL_HANDLE || device.device_handle == dev) && + device.enabled_extensions.end() != + std::find_if(device.enabled_extensions.begin(), device.enabled_extensions.end(), + [extension_name](Extension const& ext) { return ext.extensionName == extension_name; })) { + return true; + } + } + return false; +} + VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_instance_func(VkInstance instance, const char* pName); VkLayerInstanceCreateInfo* get_chain_info(const VkInstanceCreateInfo* pCreateInfo, VkLayerFunction func) { @@ -111,11 +135,48 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceLayerProperties(uint32_t* VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceExtensionProperties(const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties) { + if (pPropertyCount == nullptr) { + return VK_INCOMPLETE; + } if (pLayerName && string_eq(pLayerName, TEST_LAYER_NAME)) { - *pPropertyCount = 0; + if (pProperties) { + if (*pPropertyCount < layer.injected_instance_extensions.size()) { + return VK_INCOMPLETE; + } + for (size_t i = 0; i < layer.injected_instance_extensions.size(); i++) { + pProperties[i] = layer.injected_instance_extensions.at(i).get(); + } + *pPropertyCount = static_cast(layer.injected_instance_extensions.size()); + } else { + *pPropertyCount = static_cast(layer.injected_instance_extensions.size()); + } return VK_SUCCESS; } - return layer.instance_dispatch_table.EnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties); + + uint32_t hardware_prop_count = 0; + if (pProperties) { + hardware_prop_count = *pPropertyCount - static_cast(layer.injected_instance_extensions.size()); + } + + VkResult res = + layer.instance_dispatch_table.EnumerateInstanceExtensionProperties(pLayerName, &hardware_prop_count, pProperties); + if (res < 0) { + return res; + } + + if (pProperties == nullptr) { + *pPropertyCount = hardware_prop_count + static_cast(layer.injected_instance_extensions.size()); + } else { + if (hardware_prop_count + layer.injected_instance_extensions.size() > *pPropertyCount) { + *pPropertyCount = hardware_prop_count; + return VK_INCOMPLETE; + } + for (size_t i = 0; i < layer.injected_instance_extensions.size(); i++) { + pProperties[hardware_prop_count + i] = layer.injected_instance_extensions.at(i).get(); + } + *pPropertyCount = hardware_prop_count + static_cast(layer.injected_instance_extensions.size()); + } + return res; } VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceLayerProperties(VkPhysicalDevice, uint32_t*, VkLayerProperties*) { @@ -125,12 +186,49 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceLayerProperties(VkPhysicalD VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char* pLayerName, uint32_t* pPropertyCount, VkExtensionProperties* pProperties) { + if (pPropertyCount == nullptr) { + return VK_INCOMPLETE; + } + if (pLayerName && string_eq(pLayerName, TEST_LAYER_NAME)) { - *pPropertyCount = 0; + if (pProperties) { + if (*pPropertyCount < static_cast(layer.injected_device_extensions.size())) { + return VK_INCOMPLETE; + } + for (size_t i = 0; i < layer.injected_device_extensions.size(); i++) { + pProperties[i] = layer.injected_device_extensions.at(i).get(); + } + *pPropertyCount = static_cast(layer.injected_device_extensions.size()); + } else { + *pPropertyCount = static_cast(layer.injected_device_extensions.size()); + } return VK_SUCCESS; } - return layer.instance_dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pPropertyCount, - pProperties); + + uint32_t hardware_prop_count = 0; + if (pProperties) { + hardware_prop_count = *pPropertyCount - static_cast(layer.injected_device_extensions.size()); + } + + VkResult res = layer.instance_dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, pLayerName, + &hardware_prop_count, pProperties); + if (res < 0) { + return res; + } + + if (pProperties == nullptr) { + *pPropertyCount = hardware_prop_count + static_cast(layer.injected_device_extensions.size()); + } else { + if (hardware_prop_count + layer.injected_device_extensions.size() > *pPropertyCount) { + *pPropertyCount = hardware_prop_count; + return VK_INCOMPLETE; + } + for (size_t i = 0; i < layer.injected_device_extensions.size(); i++) { + pProperties[hardware_prop_count + i] = layer.injected_device_extensions.at(i).get(); + } + *pPropertyCount = hardware_prop_count + static_cast(layer.injected_device_extensions.size()); + } + return res; } VKAPI_ATTR VkResult VKAPI_CALL test_vkEnumerateInstanceVersion(uint32_t* pApiVersion) { @@ -195,6 +293,10 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateInstance(const VkInstanceCreateInfo* // next layer in the chain. layer_init_instance_dispatch_table(layer.instance_handle, &layer.instance_dispatch_table, fpGetInstanceProcAddr); + for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { + layer.enabled_instance_extensions.push_back({pCreateInfo->ppEnabledExtensionNames[i]}); + } + if (layer.create_instance_callback) result = layer.create_instance_callback(layer); for (auto& func : layer.custom_physical_device_interception_functions) { @@ -309,6 +411,10 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDevice(VkPhysicalDevice physicalDevi // initialize layer's dispatch table layer_init_device_dispatch_table(device.device_handle, &device.dispatch_table, fpGetDeviceProcAddr); + for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { + device.enabled_extensions.push_back({pCreateInfo->ppEnabledExtensionNames[i]}); + } + for (auto& func : layer.custom_device_interception_functions) { auto next_func = layer.next_vkGetDeviceProcAddr(*pDevice, func.name.c_str()); layer.custom_dispatch_functions.at(func.name.c_str()) = next_func; @@ -555,6 +661,120 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocat } } } + +VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateDebugUtilsMessengerEXT(VkInstance instance, + const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDebugUtilsMessengerEXT* pMessenger) { + if (layer.instance_dispatch_table.CreateDebugUtilsMessengerEXT) { + return layer.instance_dispatch_table.CreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger); + } else { + return VK_SUCCESS; + } +} + +VKAPI_ATTR void VKAPI_CALL test_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, + const VkAllocationCallbacks* pAllocator) { + if (layer.instance_dispatch_table.DestroyDebugUtilsMessengerEXT) + return layer.instance_dispatch_table.DestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator); +} + +// Debug utils & debug marker ext stubs +VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectTagEXT(VkDevice dev, const VkDebugMarkerObjectTagInfoEXT* pTagInfo) { + for (const auto& d : layer.created_devices) { + if (d.device_handle == dev) { + if (d.dispatch_table.DebugMarkerSetObjectTagEXT) { + return d.dispatch_table.DebugMarkerSetObjectTagEXT(dev, pTagInfo); + } else { + return VK_SUCCESS; + } + } + } + return VK_SUCCESS; +} +VKAPI_ATTR VkResult VKAPI_CALL test_vkDebugMarkerSetObjectNameEXT(VkDevice dev, const VkDebugMarkerObjectNameInfoEXT* pNameInfo) { + for (const auto& d : layer.created_devices) { + if (d.device_handle == dev) { + if (d.dispatch_table.DebugMarkerSetObjectNameEXT) { + return d.dispatch_table.DebugMarkerSetObjectNameEXT(dev, pNameInfo); + } else { + return VK_SUCCESS; + } + } + } + return VK_SUCCESS; +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerBeginEXT(VkCommandBuffer cmd_buf, const VkDebugMarkerMarkerInfoEXT* marker_info) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdDebugMarkerBeginEXT) + layer.created_devices[0].dispatch_table.CmdDebugMarkerBeginEXT(cmd_buf, marker_info); +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerEndEXT(VkCommandBuffer cmd_buf) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdDebugMarkerEndEXT) + layer.created_devices[0].dispatch_table.CmdDebugMarkerEndEXT(cmd_buf); +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdDebugMarkerInsertEXT(VkCommandBuffer cmd_buf, const VkDebugMarkerMarkerInfoEXT* marker_info) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdDebugMarkerInsertEXT) + layer.created_devices[0].dispatch_table.CmdDebugMarkerInsertEXT(cmd_buf, marker_info); +} + +VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectNameEXT(VkDevice dev, const VkDebugUtilsObjectNameInfoEXT* pNameInfo) { + for (const auto& d : layer.created_devices) { + if (d.device_handle == dev) { + if (d.dispatch_table.SetDebugUtilsObjectNameEXT) { + return d.dispatch_table.SetDebugUtilsObjectNameEXT(dev, pNameInfo); + } else { + return VK_SUCCESS; + } + } + } + return VK_SUCCESS; +} +VKAPI_ATTR VkResult VKAPI_CALL test_vkSetDebugUtilsObjectTagEXT(VkDevice dev, const VkDebugUtilsObjectTagInfoEXT* pTagInfo) { + for (const auto& d : layer.created_devices) { + if (d.device_handle == dev) { + if (d.dispatch_table.SetDebugUtilsObjectTagEXT) { + return d.dispatch_table.SetDebugUtilsObjectTagEXT(dev, pTagInfo); + } else { + return VK_SUCCESS; + } + } + } + return VK_SUCCESS; +} +VKAPI_ATTR void VKAPI_CALL test_vkQueueBeginDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT* label) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.QueueBeginDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.QueueBeginDebugUtilsLabelEXT(queue, label); +} +VKAPI_ATTR void VKAPI_CALL test_vkQueueEndDebugUtilsLabelEXT(VkQueue queue) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.QueueEndDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.QueueEndDebugUtilsLabelEXT(queue); +} +VKAPI_ATTR void VKAPI_CALL test_vkQueueInsertDebugUtilsLabelEXT(VkQueue queue, const VkDebugUtilsLabelEXT* label) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.QueueInsertDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.QueueInsertDebugUtilsLabelEXT(queue, label); +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer cmd_buf, const VkDebugUtilsLabelEXT* label) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdBeginDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.CmdBeginDebugUtilsLabelEXT(cmd_buf, label); +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer cmd_buf) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdEndDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.CmdEndDebugUtilsLabelEXT(cmd_buf); +} +VKAPI_ATTR void VKAPI_CALL test_vkCmdInsertDebugUtilsLabelEXT(VkCommandBuffer cmd_buf, const VkDebugUtilsLabelEXT* label) { + // Just call the first device - + if (layer.created_devices[0].dispatch_table.CmdInsertDebugUtilsLabelEXT) + layer.created_devices[0].dispatch_table.CmdInsertDebugUtilsLabelEXT(cmd_buf, label); +} + // forward declarations needed for trampolines #if TEST_LAYER_EXPORT_GET_PHYSICAL_DEVICE_PROC_ADDR extern "C" { @@ -568,6 +788,24 @@ VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL get_device_func_impl([[maybe_unused]] V if (string_eq(pName, "vkGetDeviceProcAddr")) return to_vkVoidFunction(get_device_func); if (string_eq(pName, "vkDestroyDevice")) return to_vkVoidFunction(test_vkDestroyDevice); + if (IsDeviceExtensionAvailable(device, VK_EXT_DEBUG_MARKER_EXTENSION_NAME)) { + if (string_eq(pName, "vkDebugMarkerSetObjectTagEXT")) return to_vkVoidFunction(test_vkDebugMarkerSetObjectTagEXT); + if (string_eq(pName, "vkDebugMarkerSetObjectNameEXT")) return to_vkVoidFunction(test_vkDebugMarkerSetObjectNameEXT); + if (string_eq(pName, "vkCmdDebugMarkerBeginEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerBeginEXT); + if (string_eq(pName, "vkCmdDebugMarkerEndEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerEndEXT); + if (string_eq(pName, "vkCmdDebugMarkerInsertEXT")) return to_vkVoidFunction(test_vkCmdDebugMarkerInsertEXT); + } + if (IsInstanceExtensionEnabled(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { + if (string_eq(pName, "vkSetDebugUtilsObjectNameEXT")) return to_vkVoidFunction(test_vkSetDebugUtilsObjectNameEXT); + if (string_eq(pName, "vkSetDebugUtilsObjectTagEXT")) return to_vkVoidFunction(test_vkSetDebugUtilsObjectTagEXT); + if (string_eq(pName, "vkQueueBeginDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueBeginDebugUtilsLabelEXT); + if (string_eq(pName, "vkQueueEndDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueEndDebugUtilsLabelEXT); + if (string_eq(pName, "vkQueueInsertDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkQueueInsertDebugUtilsLabelEXT); + if (string_eq(pName, "vkCmdBeginDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdBeginDebugUtilsLabelEXT); + if (string_eq(pName, "vkCmdEndDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdEndDebugUtilsLabelEXT); + if (string_eq(pName, "vkCmdInsertDebugUtilsLabelEXT")) return to_vkVoidFunction(test_vkCmdInsertDebugUtilsLabelEXT); + } + for (auto& func : layer.custom_device_interception_functions) { if (func.name == pName) { return to_vkVoidFunction(func.function); diff --git a/tests/framework/layer/test_layer.h b/tests/framework/layer/test_layer.h index 4a0b115..856f713 100644 --- a/tests/framework/layer/test_layer.h +++ b/tests/framework/layer/test_layer.h @@ -108,11 +108,18 @@ struct TestLayer { BUILDER_VECTOR(TestLayer, std::string, alternative_function_names, alternative_function_name) BUILDER_VECTOR(TestLayer, Extension, instance_extensions, instance_extension) + std::vector enabled_instance_extensions; + BUILDER_VECTOR(TestLayer, Extension, device_extensions, device_extension) BUILDER_VALUE(TestLayer, std::string, enable_environment, {}); BUILDER_VALUE(TestLayer, std::string, disable_environment, {}); + // Modifies the extension list returned by vkEnumerateInstanceExtensionProperties to include what is in this vector + BUILDER_VECTOR(TestLayer, Extension, injected_instance_extensions, injected_instance_extension) + // Modifies the extension list returned by vkEnumerateDeviceExtensionProperties to include what is in this vector + BUILDER_VECTOR(TestLayer, Extension, injected_device_extensions, injected_device_extension) + BUILDER_VECTOR(TestLayer, LayerDefinition, meta_component_layers, meta_component_layer); BUILDER_VALUE(TestLayer, bool, intercept_vkEnumerateInstanceExtensionProperties, false) @@ -193,6 +200,7 @@ struct TestLayer { struct Device { VkDevice device_handle = VK_NULL_HANDLE; VkLayerDispatchTable dispatch_table{}; + std::vector enabled_extensions; }; std::vector created_devices; diff --git a/tests/loader_debug_ext_tests.cpp b/tests/loader_debug_ext_tests.cpp index a15cb72..e5472e4 100644 --- a/tests/loader_debug_ext_tests.cpp +++ b/tests/loader_debug_ext_tests.cpp @@ -851,10 +851,12 @@ TEST_F(ManualMessage, InfoMessage) { ASSERT_EQ(true, message_found); } -void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_debug_extensions) { +void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_debug_extensions, + bool hardware_supports_debug_exts) { InstWrapper inst(env.vulkan_functions); if (enable_debug_extensions) { inst.create_info.add_extension("VK_EXT_debug_utils"); + inst.create_info.add_extension("VK_EXT_debug_report"); } inst.create_info.setup_WSI(); ASSERT_NO_FATAL_FAILURE(inst.CheckCreate()); @@ -867,14 +869,16 @@ void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_ if (enable_debug_extensions) { dev.create_info.add_extension("VK_EXT_debug_marker"); } - // if the hardware doesn't support VK_EXT_debug_marker and we are trying to enable it, then we should exit since that will fail - // to create a device - if (enable_debug_extensions && - env.get_test_icd().physical_devices.at(0).extensions.size() == 1 /*only swapchain should be available*/) { + + if (enable_debug_extensions && !hardware_supports_debug_exts) { + // if the hardware doesn't support VK_EXT_debug_marker and we are trying to enable it, then we should exit since that will + // fail to create a device + dev.CheckCreate(phys_dev, VK_ERROR_EXTENSION_NOT_PRESENT); return; + } else { + ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev)); } - ASSERT_NO_FATAL_FAILURE(dev.CheckCreate(phys_dev)); DeviceFunctions dev_funcs{env.vulkan_functions, dev}; VkSurfaceKHR surface{}; @@ -887,37 +891,25 @@ void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_ VkSwapchainKHR swapchain{}; ASSERT_EQ(VK_SUCCESS, dev_funcs.vkCreateSwapchainKHR(dev.dev, &info, nullptr, &swapchain)); - // Debug marker - PFN_vkDebugMarkerSetObjectTagEXT DebugMarkerSetObjectTagEXT; - DebugMarkerSetObjectTagEXT = use_GIPA ? inst.load("vkDebugMarkerSetObjectTagEXT") : dev.load("vkDebugMarkerSetObjectTagEXT"); - PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerSetObjectNameEXT; - DebugMarkerSetObjectNameEXT = use_GIPA ? inst.load("vkDebugMarkerSetObjectNameEXT") : dev.load("vkDebugMarkerSetObjectNameEXT"); - PFN_vkCmdDebugMarkerBeginEXT CmdDebugMarkerBeginEXT = - use_GIPA ? inst.load("vkCmdDebugMarkerBeginEXT") : dev.load("vkCmdDebugMarkerBeginEXT"); - PFN_vkCmdDebugMarkerEndEXT CmdDebugMarkerEndEXT = - use_GIPA ? inst.load("vkCmdDebugMarkerEndEXT") : dev.load("vkCmdDebugMarkerEndEXT"); - PFN_vkCmdDebugMarkerInsertEXT CmdDebugMarkerInsertEXT = - use_GIPA ? inst.load("vkCmdDebugMarkerInsertEXT") : dev.load("vkCmdDebugMarkerInsertEXT"); + auto load_function = [&inst, &dev, use_GIPA](const char* func_name) { + return use_GIPA ? inst.load(func_name) : dev.load(func_name); + }; + // Debug marker + PFN_vkDebugMarkerSetObjectTagEXT DebugMarkerSetObjectTagEXT = load_function("vkDebugMarkerSetObjectTagEXT"); + PFN_vkDebugMarkerSetObjectNameEXT DebugMarkerSetObjectNameEXT = load_function("vkDebugMarkerSetObjectNameEXT"); + PFN_vkCmdDebugMarkerBeginEXT CmdDebugMarkerBeginEXT = load_function("vkCmdDebugMarkerBeginEXT"); + PFN_vkCmdDebugMarkerEndEXT CmdDebugMarkerEndEXT = load_function("vkCmdDebugMarkerEndEXT"); + PFN_vkCmdDebugMarkerInsertEXT CmdDebugMarkerInsertEXT = load_function("vkCmdDebugMarkerInsertEXT"); // Debug utils - PFN_vkSetDebugUtilsObjectNameEXT SetDebugUtilsObjectNameEXT; - SetDebugUtilsObjectNameEXT = use_GIPA ? inst.load("vkSetDebugUtilsObjectNameEXT") : dev.load("vkSetDebugUtilsObjectNameEXT"); - PFN_vkSetDebugUtilsObjectTagEXT SetDebugUtilsObjectTagEXT; - SetDebugUtilsObjectTagEXT = use_GIPA ? inst.load("vkSetDebugUtilsObjectTagEXT") : dev.load("vkSetDebugUtilsObjectTagEXT"); - PFN_vkQueueBeginDebugUtilsLabelEXT QueueBeginDebugUtilsLabelEXT; - QueueBeginDebugUtilsLabelEXT = - use_GIPA ? inst.load("vkQueueBeginDebugUtilsLabelEXT") : dev.load("vkQueueBeginDebugUtilsLabelEXT"); - PFN_vkQueueEndDebugUtilsLabelEXT QueueEndDebugUtilsLabelEXT; - QueueEndDebugUtilsLabelEXT = use_GIPA ? inst.load("vkQueueEndDebugUtilsLabelEXT") : dev.load("vkQueueEndDebugUtilsLabelEXT"); - PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsertDebugUtilsLabelEXT; - QueueInsertDebugUtilsLabelEXT = - use_GIPA ? inst.load("vkQueueInsertDebugUtilsLabelEXT") : dev.load("vkQueueInsertDebugUtilsLabelEXT"); - PFN_vkCmdBeginDebugUtilsLabelEXT CmdBeginDebugUtilsLabelEXT; - CmdBeginDebugUtilsLabelEXT = use_GIPA ? inst.load("vkCmdBeginDebugUtilsLabelEXT") : dev.load("vkCmdBeginDebugUtilsLabelEXT"); - PFN_vkCmdEndDebugUtilsLabelEXT CmdEndDebugUtilsLabelEXT; - CmdEndDebugUtilsLabelEXT = use_GIPA ? inst.load("vkCmdEndDebugUtilsLabelEXT") : dev.load("vkCmdEndDebugUtilsLabelEXT"); - PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsertDebugUtilsLabelEXT; - CmdInsertDebugUtilsLabelEXT = use_GIPA ? inst.load("vkCmdInsertDebugUtilsLabelEXT") : dev.load("vkCmdInsertDebugUtilsLabelEXT"); + PFN_vkSetDebugUtilsObjectNameEXT SetDebugUtilsObjectNameEXT = load_function("vkSetDebugUtilsObjectNameEXT"); + PFN_vkSetDebugUtilsObjectTagEXT SetDebugUtilsObjectTagEXT = load_function("vkSetDebugUtilsObjectTagEXT"); + PFN_vkQueueBeginDebugUtilsLabelEXT QueueBeginDebugUtilsLabelEXT = load_function("vkQueueBeginDebugUtilsLabelEXT"); + PFN_vkQueueEndDebugUtilsLabelEXT QueueEndDebugUtilsLabelEXT = load_function("vkQueueEndDebugUtilsLabelEXT"); + PFN_vkQueueInsertDebugUtilsLabelEXT QueueInsertDebugUtilsLabelEXT = load_function("vkQueueInsertDebugUtilsLabelEXT"); + PFN_vkCmdBeginDebugUtilsLabelEXT CmdBeginDebugUtilsLabelEXT = load_function("vkCmdBeginDebugUtilsLabelEXT"); + PFN_vkCmdEndDebugUtilsLabelEXT CmdEndDebugUtilsLabelEXT = load_function("vkCmdEndDebugUtilsLabelEXT"); + PFN_vkCmdInsertDebugUtilsLabelEXT CmdInsertDebugUtilsLabelEXT = load_function("vkCmdInsertDebugUtilsLabelEXT"); // Debug marker functions - should always be found when using GIPA but when using GDPA found only when the extension is enabled if (use_GIPA) { @@ -1047,7 +1039,7 @@ void CheckDeviceFunctions(FrameworkEnvironment& env, bool use_GIPA, bool enable_ env.vulkan_functions.vkDestroySurfaceKHR(inst.inst, surface, nullptr); } -TEST(GetDeviceProcAddr, DebugFuncsWithTerminator) { +TEST(GetProcAddr, DebugFuncsWithTerminator) { FrameworkEnvironment env{}; auto& driver = env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0"); @@ -1055,24 +1047,92 @@ TEST(GetDeviceProcAddr, DebugFuncsWithTerminator) { // Hardware doesn't support the debug extensions // Use getDeviceProcAddr & vary enabling the debug extensions - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false)); - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, false)); // Use getInstanceProcAddr & vary enabling the debug extensions - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false)); - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, false)); // Now set the hardware to support the extensions and run the situations again - driver.add_instance_extension("VK_EXT_debug_utils"); + driver.add_instance_extensions({"VK_EXT_debug_utils", "VK_EXT_debug_report"}); driver.physical_devices.at(0).add_extensions({"VK_EXT_debug_marker"}); // Use getDeviceProcAddr & vary enabling the debug extensions - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false)); - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, true)); + + // Use getInstanceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, true)); +} + +TEST(GetProcAddr, DebugFuncsWithTrampoline) { + FrameworkEnvironment env{}; + auto& driver = + env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0"); + driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"}); + // Hardware doesn't support the debug extensions + + // // Use getDeviceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, false)); + + // // Use getInstanceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, false)); + + // Now add a layer that supports the extensions and run the situations again + env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} + .set_name("VK_LAYER_test_layer") + .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) + .set_disable_environment("DISABLE_ME") + .add_instance_extensions({{VK_EXT_DEBUG_REPORT_EXTENSION_NAME}, + {VK_EXT_DEBUG_UTILS_EXTENSION_NAME}}) + .add_device_extension({VK_EXT_DEBUG_MARKER_EXTENSION_NAME})), + "test_layer.json"); + + // // Use getDeviceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, true)); + + // Use getInstanceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, true)); +} + +TEST(GetProcAddr, DebugFuncsWithDebugExtsForceAdded) { + FrameworkEnvironment env{}; + auto& driver = + env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).setup_WSI().add_physical_device("physical_device_0"); + driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"}); + // Hardware doesn't support the debug extensions + + // // Use getDeviceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, false)); + + // // Use getInstanceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, false)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, false)); + + // Now add a layer that supports the extensions and run the situations again + env.add_implicit_layer(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{} + .set_name("VK_LAYER_test_layer") + .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2) + .set_disable_environment("DISABLE_ME")), + "test_layer.json"); + env.get_test_layer() + .add_injected_instance_extensions({{VK_EXT_DEBUG_REPORT_EXTENSION_NAME}, {VK_EXT_DEBUG_UTILS_EXTENSION_NAME}}) + .add_injected_device_extension({VK_EXT_DEBUG_MARKER_EXTENSION_NAME}); + + // // Use getDeviceProcAddr & vary enabling the debug extensions + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, true)); // Use getInstanceProcAddr & vary enabling the debug extensions - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false)); - ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, true)); + ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, true)); } TEST(DebugUtils, WrappingLayer) { -- 2.7.4