diff --git a/layersvt/common/README.md b/layersvt/common/README.md index ce32403dc8..b8a7bedebe 100644 --- a/layersvt/common/README.md +++ b/layersvt/common/README.md @@ -47,7 +47,7 @@ The `layersvt_common` library provides a modern, thread-safe C++ foundation for ### Key Components * **`LayerBase`** ([`layer_base.h`](layer_base.h), [`layer_base.cpp`](layer_base.cpp)): - Base class employing the **Template Method** design pattern. It implements static intercept entry points (`vkGetInstanceProcAddr`, `vkGetDeviceProcAddr`, `vkCreateInstance`, `vkDestroyInstance`, `vkCreateDevice`, `vkDestroyDevice`, `vkEnumerateInstanceExtensionProperties`, `vkEnumerateDeviceExtensionProperties`, `vkGetPhysicalDeviceToolProperties`), executes virtual lifecycle and extension/tooling hooks (`ProcessDeviceExtensions`, `ProcessInstanceExtensions`, `ProcessToolProperties`), and delegates custom functions to derived layer overrides. + Base class employing the **Template Method** design pattern. It provides overridable `protected virtual` built-in command implementations (`GetInstanceProcAddr`, `GetDeviceProcAddr`, `CreateInstance`, `DestroyInstance`, `CreateDevice`, `DestroyDevice`, `EnumerateInstanceLayerProperties`, `EnumerateInstanceExtensionProperties`, `EnumerateDeviceLayerProperties`, `EnumerateDeviceExtensionProperties`, `GetPhysicalDeviceToolProperties`), executes virtual lifecycle and extension/tooling hooks (`ProcessDeviceExtensions`, `ProcessInstanceExtensions`, `ProcessToolProperties`), and delegates custom functions to derived layer overrides. * **`LayerManifest`** ([`layer_manifest.h`](layer_manifest.h), [`layer_manifest.cpp`](layer_manifest.cpp)): Passive declarative data struct describing layer metadata, supported Vulkan versions, advertised instance/device extensions, and tooling properties (`VK_EXT_tooling_info` / `VK_VERSION_1_3`). Downstream Vulkan querying, buffer sizing, and capability merging are managed by `LayerBase`. * **`DispatchTableManager`** ([`dispatch_table_manager.h`](dispatch_table_manager.h), [`dispatch_table_manager.cpp`](dispatch_table_manager.cpp)): @@ -88,6 +88,9 @@ class MyCustomLayer : public LayerBase { PFN_vkVoidFunction GetLayerInstanceCommand(VkInstance instance, const char* command_name) override; PFN_vkVoidFunction GetLayerDeviceCommand(VkDevice device, const char* command_name) override; + // Built-in commands (CreateInstance, DestroyDevice, Enumerate*, etc.) can also be wrapped + // by overriding their virtual methods on LayerBase. + // Lifecycle hooks (override as needed) void PreCreateInstance(VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator) override; void PostCreateInstance(VkInstance instance, const VkInstanceCreateInfo* create_info, @@ -321,7 +324,7 @@ target_link_libraries(test_MyCustomLayer_layer layersvt_common) * `DispatchDownstreamOrSuccess` — optional commands returning `VkResult`; returns `VK_SUCCESS` if the entry point is unavailable. * `DispatchDownstreamOr` — optional commands needing a custom fallback value (or a callable producing it). 3. **Null Handle Destruction is Safe**: - `LayerBase::DestroyInstance` and `LayerBase::DestroyDevice` immediately return on `VK_NULL_HANDLE` per Vulkan specification (Section 2.7), bypassing downstream dispatch and virtual hooks. Virtual `PreDestroy*` hooks are guaranteed to receive only valid non-null handles. + The base `LayerBase::DestroyInstance` and `LayerBase::DestroyDevice` return at once on `VK_NULL_HANDLE` per Vulkan specification (Section 2.7), and skip downstream dispatch and the `PreDestroy*` hooks. Virtual `PreDestroy*` hooks receive only non-null handles. An override of `DestroyInstance` or `DestroyDevice` itself can receive `VK_NULL_HANDLE`. 4. **Tool Properties Downstream Initialization**: When querying downstream tooling properties in custom commands, always initialize `tool.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT` and `tool.pNext = nullptr` on each array element before passing buffers to downstream functions to satisfy Vulkan VUIDs. 5. **Thread Safety**: diff --git a/layersvt/common/layer_base.cpp b/layersvt/common/layer_base.cpp index da7433d6d4..e381d96916 100644 --- a/layersvt/common/layer_base.cpp +++ b/layersvt/common/layer_base.cpp @@ -108,14 +108,79 @@ PFN_vkSetDeviceLoaderData LayerBase::GetDeviceLoaderDataCallback(VkDevice device return layer_->dispatch_table_manager_.GetDeviceLoaderDataCallback(device); } +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL LayerBase::DispatchGetInstanceProcAddr(VkInstance instance, const char* command_name) { + AssertLayerInitialized(); + return Get()->GetInstanceProcAddr(instance, command_name); +} + +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL LayerBase::DispatchGetDeviceProcAddr(VkDevice device, const char* command_name) { + AssertLayerInitialized(); + return Get()->GetDeviceProcAddr(device, command_name); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchCreateInstance(const VkInstanceCreateInfo* create_info, + const VkAllocationCallbacks* allocator, VkInstance* instance) { + AssertLayerInitialized(); + return Get()->CreateInstance(create_info, allocator, instance); +} + +VKAPI_ATTR void VKAPI_CALL LayerBase::DispatchDestroyInstance(VkInstance instance, const VkAllocationCallbacks* allocator) { + AssertLayerInitialized(); + Get()->DestroyInstance(instance, allocator); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchCreateDevice(VkPhysicalDevice physical_device, + const VkDeviceCreateInfo* create_info, + const VkAllocationCallbacks* allocator, VkDevice* device) { + AssertLayerInitialized(); + return Get()->CreateDevice(physical_device, create_info, allocator, device); +} + +VKAPI_ATTR void VKAPI_CALL LayerBase::DispatchDestroyDevice(VkDevice device, const VkAllocationCallbacks* allocator) { + AssertLayerInitialized(); + Get()->DestroyDevice(device, allocator); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchEnumerateInstanceLayerProperties(uint32_t* property_count, + VkLayerProperties* properties) { + AssertLayerInitialized(); + return Get()->EnumerateInstanceLayerProperties(property_count, properties); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchEnumerateInstanceExtensionProperties(const char* layer_name, + uint32_t* property_count, + VkExtensionProperties* properties) { + AssertLayerInitialized(); + return Get()->EnumerateInstanceExtensionProperties(layer_name, property_count, properties); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchEnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, + uint32_t* property_count, + VkLayerProperties* properties) { + AssertLayerInitialized(); + return Get()->EnumerateDeviceLayerProperties(physical_device, property_count, properties); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchEnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, + const char* layer_name, + uint32_t* property_count, + VkExtensionProperties* properties) { + AssertLayerInitialized(); + return Get()->EnumerateDeviceExtensionProperties(physical_device, layer_name, property_count, properties); +} + +VKAPI_ATTR VkResult VKAPI_CALL LayerBase::DispatchGetPhysicalDeviceToolProperties( + VkPhysicalDevice physical_device, uint32_t* tool_count, VkPhysicalDeviceToolPropertiesEXT* tool_properties) { + AssertLayerInitialized(); + return Get()->GetPhysicalDeviceToolProperties(physical_device, tool_count, tool_properties); +} + VkResult LayerBase::CreateInstance(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* instance) { if (!create_info || !instance) { return VK_ERROR_INITIALIZATION_FAILED; } - AssertLayerInitialized(); - VkInstanceCreateInfo modified_create_info = *create_info; VkLayerInstanceCreateInfo* chain_info = GetChainInfo(modified_create_info, VK_LAYER_LINK_INFO); if (!chain_info || !chain_info->u.pLayerInfo || !chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr) { @@ -127,14 +192,13 @@ VkResult LayerBase::CreateInstance(const VkInstanceCreateInfo* create_info, cons return VK_ERROR_INITIALIZATION_FAILED; } - LayerBase* layer = Get(); - layer->PreCreateInstance(&modified_create_info, allocator); + PreCreateInstance(&modified_create_info, allocator); chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; VkResult result = create_instance(&modified_create_info, allocator, instance); if (result == VK_SUCCESS) { - layer->dispatch_table_manager_.InitInstanceTable(*instance, get_instance_proc_addr); - layer->PostCreateInstance(*instance, &modified_create_info, allocator); + dispatch_table_manager_.InitInstanceTable(*instance, get_instance_proc_addr); + PostCreateInstance(*instance, &modified_create_info, allocator); } return result; } @@ -144,13 +208,11 @@ void LayerBase::DestroyInstance(VkInstance instance, const VkAllocationCallbacks return; } - AssertLayerInitialized(); - LayerBase* layer = Get(); - layer->PreDestroyInstance(instance, allocator); + PreDestroyInstance(instance, allocator); auto key = DispatchTableManager::GetDispatchKey(instance); DispatchDownstream<&VkuInstanceDispatchTable::DestroyInstance>(instance, allocator); - layer->dispatch_table_manager_.DestroyInstanceTable(key); + dispatch_table_manager_.DestroyInstanceTable(key); } VkResult LayerBase::CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo* create_info, @@ -159,7 +221,7 @@ VkResult LayerBase::CreateDevice(VkPhysicalDevice physical_device, const VkDevic return VK_ERROR_INITIALIZATION_FAILED; } - VkInstance instance = GetVkInstance(physical_device); + VkInstance instance = dispatch_table_manager_.GetVkInstance(physical_device); if (instance == VK_NULL_HANDLE) { return VK_ERROR_INITIALIZATION_FAILED; } @@ -185,18 +247,17 @@ VkResult LayerBase::CreateDevice(VkPhysicalDevice physical_device, const VkDevic loader_callback = callback_info->u.pfnSetDeviceLoaderData; } - LayerBase* layer = Get(); - layer->PreCreateDevice(physical_device, &modified_create_info, allocator); + PreCreateDevice(physical_device, &modified_create_info, allocator); chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext; VkResult result = create_device(physical_device, &modified_create_info, allocator, device); if (result == VK_SUCCESS) { - layer->dispatch_table_manager_.InitDeviceTable(*device, get_device_proc_addr); + dispatch_table_manager_.InitDeviceTable(*device, get_device_proc_addr); if (loader_callback) { - layer->dispatch_table_manager_.SetDeviceLoaderDataCallback(*device, loader_callback); + dispatch_table_manager_.SetDeviceLoaderDataCallback(*device, loader_callback); } - layer->PostCreateDevice(*device, physical_device, &modified_create_info, allocator); + PostCreateDevice(*device, physical_device, &modified_create_info, allocator); } return result; } @@ -206,22 +267,18 @@ void LayerBase::DestroyDevice(VkDevice device, const VkAllocationCallbacks* allo return; } - AssertLayerInitialized(); - LayerBase* layer = Get(); - layer->PreDestroyDevice(device, allocator); + PreDestroyDevice(device, allocator); auto key = DispatchTableManager::GetDispatchKey(device); DispatchDownstream<&VkuDeviceDispatchTable::DestroyDevice>(device, allocator); - layer->dispatch_table_manager_.DestroyDeviceTable(key); + dispatch_table_manager_.DestroyDeviceTable(key); } VkResult LayerBase::EnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties) { assert(property_count != nullptr); - AssertLayerInitialized(); - LayerBase* layer = Get(); - const LayerManifest* manifest = layer->GetLayerManifest(); + const LayerManifest* manifest = GetLayerManifest(); if (!manifest) { return VK_ERROR_INITIALIZATION_FAILED; } @@ -233,17 +290,15 @@ VkResult LayerBase::EnumerateInstanceExtensionProperties(const char* layer_name, } std::vector extensions = manifest->instance_extensions; - layer->ProcessInstanceExtensions(layer_name, extensions); + ProcessInstanceExtensions(layer_name, extensions); return CopyEnumerationProperties(extensions, property_count, properties); } VkResult LayerBase::EnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties) { assert(property_count != nullptr); - AssertLayerInitialized(); - LayerBase* layer = Get(); - const LayerManifest* manifest = layer->GetLayerManifest(); + const LayerManifest* manifest = GetLayerManifest(); if (!manifest) { return VK_ERROR_INITIALIZATION_FAILED; } @@ -265,6 +320,7 @@ VkResult LayerBase::EnumerateInstanceLayerProperties(uint32_t* property_count, V VkResult LayerBase::EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, VkLayerProperties* properties) { (void)physical_device; + // Device layer properties mirror the instance list, including derived overrides. return EnumerateInstanceLayerProperties(property_count, properties); } @@ -279,16 +335,14 @@ VkResult LayerBase::EnumerateDeviceExtensionPropertiesWithDownstream( VkPhysicalDevice physical_device, const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties, PFN_vkEnumerateDeviceExtensionProperties downstream_function) { assert(property_count != nullptr); - AssertLayerInitialized(); - LayerBase* layer = Get(); - const LayerManifest* manifest = layer->GetLayerManifest(); + const LayerManifest* manifest = GetLayerManifest(); const char* my_layer_name = (manifest && manifest->layer_name) ? manifest->layer_name : ""; // When explicitly querying this layer's device extensions: if (layer_name != nullptr && my_layer_name[0] != '\0' && std::strcmp(layer_name, my_layer_name) == 0) { std::vector extensions = manifest->device_extensions; - layer->ProcessDeviceExtensions(physical_device, layer_name, extensions); + ProcessDeviceExtensions(physical_device, layer_name, extensions); return CopyEnumerationProperties(extensions, property_count, properties); } @@ -335,7 +389,7 @@ VkResult LayerBase::EnumerateDeviceExtensionPropertiesWithDownstream( } } - layer->ProcessDeviceExtensions(physical_device, layer_name, extensions); + ProcessDeviceExtensions(physical_device, layer_name, extensions); return CopyEnumerationProperties(extensions, property_count, properties); } @@ -354,10 +408,8 @@ VkResult LayerBase::GetPhysicalDeviceToolPropertiesWithDownstream( VkPhysicalDevice physical_device, uint32_t* tool_count, VkPhysicalDeviceToolPropertiesEXT* tool_properties, PFN_vkGetPhysicalDeviceToolPropertiesEXT downstream_function) { assert(tool_count != nullptr); - AssertLayerInitialized(); - LayerBase* layer = Get(); - const LayerManifest* manifest = layer->GetLayerManifest(); + const LayerManifest* manifest = GetLayerManifest(); std::vector tools; if (downstream_function) { @@ -385,7 +437,7 @@ VkResult LayerBase::GetPhysicalDeviceToolPropertiesWithDownstream( tools.push_back(*manifest->tool_properties); } - layer->ProcessToolProperties(physical_device, tools); + ProcessToolProperties(physical_device, tools); return CopyEnumerationProperties(tools, tool_count, tool_properties); } @@ -423,33 +475,33 @@ PFN_vkVoidFunction LayerBase::GetKnownInstanceCommand(VkInstance instance, const } if (std::strcmp(command_name, "vkGetInstanceProcAddr") == 0) { - return reinterpret_cast(GetInstanceProcAddr); + return reinterpret_cast(&LayerBase::DispatchGetInstanceProcAddr); } if (std::strcmp(command_name, "vkCreateInstance") == 0) { - return reinterpret_cast(CreateInstance); + return reinterpret_cast(&LayerBase::DispatchCreateInstance); } if (std::strcmp(command_name, "vkDestroyInstance") == 0) { - return reinterpret_cast(DestroyInstance); + return reinterpret_cast(&LayerBase::DispatchDestroyInstance); } if (std::strcmp(command_name, "vkCreateDevice") == 0) { - return reinterpret_cast(CreateDevice); + return reinterpret_cast(&LayerBase::DispatchCreateDevice); } if (std::strcmp(command_name, "vkEnumerateInstanceExtensionProperties") == 0) { - return reinterpret_cast(EnumerateInstanceExtensionProperties); + return reinterpret_cast(&LayerBase::DispatchEnumerateInstanceExtensionProperties); } if (std::strcmp(command_name, "vkEnumerateInstanceLayerProperties") == 0) { - return reinterpret_cast(EnumerateInstanceLayerProperties); + return reinterpret_cast(&LayerBase::DispatchEnumerateInstanceLayerProperties); } if (std::strcmp(command_name, "vkEnumerateDeviceLayerProperties") == 0) { - return reinterpret_cast(EnumerateDeviceLayerProperties); + return reinterpret_cast(&LayerBase::DispatchEnumerateDeviceLayerProperties); } if (std::strcmp(command_name, "vkEnumerateDeviceExtensionProperties") == 0) { - return reinterpret_cast(EnumerateDeviceExtensionProperties); + return reinterpret_cast(&LayerBase::DispatchEnumerateDeviceExtensionProperties); } if (std::strcmp(command_name, "vkGetPhysicalDeviceToolPropertiesEXT") == 0 || std::strcmp(command_name, "vkGetPhysicalDeviceToolProperties") == 0) { if (layer->HasToolProperties()) { - return reinterpret_cast(GetPhysicalDeviceToolProperties); + return reinterpret_cast(&LayerBase::DispatchGetPhysicalDeviceToolProperties); } } return nullptr; @@ -465,21 +517,19 @@ PFN_vkVoidFunction LayerBase::GetKnownDeviceCommand(VkDevice device, const char* } if (std::strcmp(command_name, "vkGetDeviceProcAddr") == 0) { - return reinterpret_cast(GetDeviceProcAddr); + return reinterpret_cast(&LayerBase::DispatchGetDeviceProcAddr); } if (std::strcmp(command_name, "vkDestroyDevice") == 0) { - return reinterpret_cast(DestroyDevice); + return reinterpret_cast(&LayerBase::DispatchDestroyDevice); } return nullptr; } -PFN_vkVoidFunction VKAPI_CALL LayerBase::GetInstanceProcAddr(VkInstance instance, const char* command_name) { +PFN_vkVoidFunction LayerBase::GetInstanceProcAddr(VkInstance instance, const char* command_name) { if (!command_name) { return nullptr; } - AssertLayerInitialized(); - if (instance == VK_NULL_HANDLE) { if (!IsGlobalCommand(command_name)) { return nullptr; @@ -500,16 +550,11 @@ PFN_vkVoidFunction VKAPI_CALL LayerBase::GetInstanceProcAddr(VkInstance instance return DispatchDownstreamOr<&VkuInstanceDispatchTable::GetInstanceProcAddr>(nullptr, instance, command_name); } -PFN_vkVoidFunction VKAPI_CALL LayerBase::GetDeviceProcAddr(VkDevice device, const char* command_name) { - if (!command_name) { +PFN_vkVoidFunction LayerBase::GetDeviceProcAddr(VkDevice device, const char* command_name) { + if (!command_name || device == VK_NULL_HANDLE) { return nullptr; } - if (device == VK_NULL_HANDLE) { - return nullptr; - } - - AssertLayerInitialized(); PFN_vkVoidFunction command = GetKnownDeviceCommand(device, command_name); if (command != nullptr) { return command; diff --git a/layersvt/common/layer_base.h b/layersvt/common/layer_base.h index 84072f95b8..51ac6ce662 100644 --- a/layersvt/common/layer_base.h +++ b/layersvt/common/layer_base.h @@ -25,6 +25,7 @@ namespace layersvt { struct LayerManifest; +struct LayerEntrypoints; class LayerBaseTestPeer; /** @@ -38,8 +39,10 @@ class LayerBaseTestPeer; * - Thread Safety: Internal registries (DispatchTableManager) are thread-safe. * Overridden hooks called concurrently by Vulkan applications must maintain their * own thread safety for layer-specific state. - * - Command Routing: Custom commands return function pointers via GetLayerInstanceCommand - * and GetLayerDeviceCommand; unhandled commands route to downstream dispatch tables. + * - Command Routing: Built-in lifecycle, proc-addr, and enumeration commands route to + * virtual methods on LayerBase via static C ABI thunks; custom commands return function + * pointers via GetLayerInstanceCommand and GetLayerDeviceCommand; unhandled commands + * route to downstream dispatch tables. * - Property Enumeration: Serves layer extensions and tool properties automatically * from GetLayerManifest(), merging layer properties with downstream capabilities. * - Lifecycle Hooks: PreCreate* / PostCreate* / PreDestroy* hooks bracket instance and @@ -114,6 +117,31 @@ class LayerBase { */ [[nodiscard]] virtual bool HasToolProperties() const; + // Override to wrap a built-in command. Arguments arrive unchecked from the loader: handles can be VK_NULL_HANDLE and + // pointers can be null. An override of Create*/Destroy* must call the LayerBase implementation, which registers and + // releases the dispatch tables and runs the Pre*/Post* hooks. + + virtual PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* command_name); + virtual PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* command_name); + + virtual VkResult CreateInstance(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, + VkInstance* instance); + virtual void DestroyInstance(VkInstance instance, const VkAllocationCallbacks* allocator); + + virtual VkResult CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo* create_info, + const VkAllocationCallbacks* allocator, VkDevice* device); + virtual void DestroyDevice(VkDevice device, const VkAllocationCallbacks* allocator); + + virtual VkResult EnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties); + virtual VkResult EnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, + VkExtensionProperties* properties); + virtual VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, + VkLayerProperties* properties); + virtual VkResult EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char* layer_name, + uint32_t* property_count, VkExtensionProperties* properties); + virtual VkResult GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t* tool_count, + VkPhysicalDeviceToolPropertiesEXT* tool_properties); + // Layer-specific command intercepts /** @@ -202,62 +230,41 @@ class LayerBase { static inline LayerBase* layer_ = nullptr; - // Exported Vulkan layer entry points (implemented in layer_entrypoints.cpp) -#if defined(_WIN32) - friend VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL ::vkGetInstanceProcAddr(VkInstance instance, const char* command_name); - friend VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL ::vkGetDeviceProcAddr(VkDevice device, const char* command_name); - friend VKAPI_ATTR VkResult VKAPI_CALL ::vkEnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL ::vkEnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, - VkExtensionProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL ::vkEnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, - VkLayerProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL ::vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char* layer_name, - uint32_t* property_count, - VkExtensionProperties* properties); -#else - friend VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL (::vkGetInstanceProcAddr)(VkInstance instance, const char* command_name); - friend VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL (::vkGetDeviceProcAddr)(VkDevice device, const char* command_name); - friend VKAPI_ATTR VkResult VKAPI_CALL (::vkEnumerateInstanceLayerProperties)(uint32_t* property_count, VkLayerProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL (::vkEnumerateInstanceExtensionProperties)(const char* layer_name, uint32_t* property_count, - VkExtensionProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL (::vkEnumerateDeviceLayerProperties)(VkPhysicalDevice physical_device, uint32_t* property_count, - VkLayerProperties* properties); - friend VKAPI_ATTR VkResult VKAPI_CALL (::vkEnumerateDeviceExtensionProperties)(VkPhysicalDevice physical_device, const char* layer_name, - uint32_t* property_count, - VkExtensionProperties* properties); -#endif - + friend struct LayerEntrypoints; friend class LayerBaseTestPeer; template friend auto GetDownstream(Handle handle); - // Vulkan intercept commands (static C-compatible functions) - - static PFN_vkVoidFunction VKAPI_CALL GetInstanceProcAddr(VkInstance instance, const char* command_name); - static PFN_vkVoidFunction VKAPI_CALL GetDeviceProcAddr(VkDevice device, const char* command_name); - - static VkResult VKAPI_CALL CreateInstance(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, - VkInstance* instance); - static void VKAPI_CALL DestroyInstance(VkInstance instance, const VkAllocationCallbacks* allocator); - - static VkResult VKAPI_CALL CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo* create_info, - const VkAllocationCallbacks* allocator, VkDevice* device); - static void VKAPI_CALL DestroyDevice(VkDevice device, const VkAllocationCallbacks* allocator); - - static VkResult VKAPI_CALL EnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, - VkExtensionProperties* properties); - static VkResult VKAPI_CALL EnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties); - static VkResult VKAPI_CALL EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, - VkLayerProperties* properties); - static VkResult VKAPI_CALL EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char* layer_name, - uint32_t* property_count, VkExtensionProperties* properties); - static VkResult EnumerateDeviceExtensionPropertiesWithDownstream( + // Static C ABI dispatch thunks forwarding to the active singleton's virtual methods + static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DispatchGetInstanceProcAddr(VkInstance instance, const char* command_name); + static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL DispatchGetDeviceProcAddr(VkDevice device, const char* command_name); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchCreateInstance(const VkInstanceCreateInfo* create_info, + const VkAllocationCallbacks* allocator, VkInstance* instance); + static VKAPI_ATTR void VKAPI_CALL DispatchDestroyInstance(VkInstance instance, const VkAllocationCallbacks* allocator); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchCreateDevice(VkPhysicalDevice physical_device, + const VkDeviceCreateInfo* create_info, + const VkAllocationCallbacks* allocator, VkDevice* device); + static VKAPI_ATTR void VKAPI_CALL DispatchDestroyDevice(VkDevice device, const VkAllocationCallbacks* allocator); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchEnumerateInstanceLayerProperties(uint32_t* property_count, + VkLayerProperties* properties); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchEnumerateInstanceExtensionProperties(const char* layer_name, + uint32_t* property_count, + VkExtensionProperties* properties); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchEnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, + uint32_t* property_count, + VkLayerProperties* properties); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchEnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, + const char* layer_name, + uint32_t* property_count, + VkExtensionProperties* properties); + static VKAPI_ATTR VkResult VKAPI_CALL DispatchGetPhysicalDeviceToolProperties( + VkPhysicalDevice physical_device, uint32_t* tool_count, VkPhysicalDeviceToolPropertiesEXT* tool_properties); + + VkResult EnumerateDeviceExtensionPropertiesWithDownstream( VkPhysicalDevice physical_device, const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties, PFN_vkEnumerateDeviceExtensionProperties downstream_function); - static VkResult VKAPI_CALL GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t* tool_count, - VkPhysicalDeviceToolPropertiesEXT* tool_properties); - static VkResult GetPhysicalDeviceToolPropertiesWithDownstream( + VkResult GetPhysicalDeviceToolPropertiesWithDownstream( VkPhysicalDevice physical_device, uint32_t* tool_count, VkPhysicalDeviceToolPropertiesEXT* tool_properties, PFN_vkGetPhysicalDeviceToolPropertiesEXT downstream_function); diff --git a/layersvt/common/layer_entrypoints.cpp b/layersvt/common/layer_entrypoints.cpp index a5dab26ab5..d518b77327 100644 --- a/layersvt/common/layer_entrypoints.cpp +++ b/layersvt/common/layer_entrypoints.cpp @@ -29,6 +29,34 @@ #endif #endif +namespace layersvt { + +struct LayerEntrypoints { + static PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* command_name) { + return LayerBase::DispatchGetInstanceProcAddr(instance, command_name); + } + static PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* command_name) { + return LayerBase::DispatchGetDeviceProcAddr(device, command_name); + } + static VkResult EnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties) { + return LayerBase::DispatchEnumerateInstanceLayerProperties(property_count, properties); + } + static VkResult EnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, + VkExtensionProperties* properties) { + return LayerBase::DispatchEnumerateInstanceExtensionProperties(layer_name, property_count, properties); + } + static VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, + VkLayerProperties* properties) { + return LayerBase::DispatchEnumerateDeviceLayerProperties(physical_device, property_count, properties); + } + static VkResult EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char* layer_name, + uint32_t* property_count, VkExtensionProperties* properties) { + return LayerBase::DispatchEnumerateDeviceExtensionProperties(physical_device, layer_name, property_count, properties); + } +}; + +} // namespace layersvt + extern "C" { VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVersion( @@ -52,38 +80,38 @@ VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkNegotiateLoaderLayerInterfaceVe return VK_ERROR_INITIALIZATION_FAILED; } +// The exported entry points forward through LayerEntrypoints to the LayerBase::Dispatch* thunks, +// which call the virtual methods of the active LayerBase instance. + VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr( VkInstance instance, const char* command_name) { - return layersvt::LayerBase::GetInstanceProcAddr(instance, command_name); + return layersvt::LayerEntrypoints::GetInstanceProcAddr(instance, command_name); } VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( VkDevice device, const char* command_name) { - return layersvt::LayerBase::GetDeviceProcAddr(device, command_name); + return layersvt::LayerEntrypoints::GetDeviceProcAddr(device, command_name); } VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( uint32_t* property_count, VkLayerProperties* properties) { - return layersvt::LayerBase::EnumerateInstanceLayerProperties(property_count, properties); + return layersvt::LayerEntrypoints::EnumerateInstanceLayerProperties(property_count, properties); } VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties) { - return layersvt::LayerBase::EnumerateInstanceExtensionProperties( - layer_name, property_count, properties); + return layersvt::LayerEntrypoints::EnumerateInstanceExtensionProperties(layer_name, property_count, properties); } VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties( VkPhysicalDevice physical_device, uint32_t* property_count, VkLayerProperties* properties) { - return layersvt::LayerBase::EnumerateDeviceLayerProperties( - physical_device, property_count, properties); + return layersvt::LayerEntrypoints::EnumerateDeviceLayerProperties(physical_device, property_count, properties); } VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties( VkPhysicalDevice physical_device, const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties) { - return layersvt::LayerBase::EnumerateDeviceExtensionProperties( - physical_device, layer_name, property_count, properties); + return layersvt::LayerEntrypoints::EnumerateDeviceExtensionProperties(physical_device, layer_name, property_count, properties); } } // extern "C" diff --git a/layersvt/test/common/layer_base_test_peer.h b/layersvt/test/common/layer_base_test_peer.h index 4544e94f85..e4cd291365 100644 --- a/layersvt/test/common/layer_base_test_peer.h +++ b/layersvt/test/common/layer_base_test_peer.h @@ -17,6 +17,7 @@ #include "common/layer_base.h" #include +#include #include namespace layersvt { @@ -32,33 +33,34 @@ class LayerBaseTestPeer { static VkResult CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkDevice* device) { - return LayerBase::CreateDevice(physical_device, create_info, allocator, device); + return LayerBase::DispatchCreateDevice(physical_device, create_info, allocator, device); } static void DestroyDevice(VkDevice device, const VkAllocationCallbacks* allocator) { - LayerBase::DestroyDevice(device, allocator); + LayerBase::DispatchDestroyDevice(device, allocator); } static VkResult EnumerateInstanceExtensionProperties(const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties) { - return LayerBase::EnumerateInstanceExtensionProperties(layer_name, property_count, properties); + return LayerBase::DispatchEnumerateInstanceExtensionProperties(layer_name, property_count, properties); } static VkResult EnumerateInstanceLayerProperties(uint32_t* property_count, VkLayerProperties* properties) { - return LayerBase::EnumerateInstanceLayerProperties(property_count, properties); + return LayerBase::DispatchEnumerateInstanceLayerProperties(property_count, properties); } static VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t* property_count, VkLayerProperties* properties) { - return LayerBase::EnumerateDeviceLayerProperties(physical_device, property_count, properties); + return LayerBase::DispatchEnumerateDeviceLayerProperties(physical_device, property_count, properties); } static VkResult EnumerateDeviceExtensionProperties( VkPhysicalDevice physical_device, const char* layer_name, uint32_t* property_count, VkExtensionProperties* properties, PFN_vkEnumerateDeviceExtensionProperties downstream_function = nullptr) { if (downstream_function != nullptr) { - return LayerBase::EnumerateDeviceExtensionPropertiesWithDownstream( + assert(LayerBase::Get() != nullptr); + return LayerBase::Get()->EnumerateDeviceExtensionPropertiesWithDownstream( physical_device, layer_name, property_count, properties, downstream_function); } - return LayerBase::EnumerateDeviceExtensionProperties( + return LayerBase::DispatchEnumerateDeviceExtensionProperties( physical_device, layer_name, property_count, properties); } static VkResult GetPhysicalDeviceToolProperties( @@ -66,10 +68,11 @@ class LayerBaseTestPeer { VkPhysicalDeviceToolPropertiesEXT* tool_properties, PFN_vkGetPhysicalDeviceToolPropertiesEXT downstream_function = nullptr) { if (downstream_function != nullptr) { - return LayerBase::GetPhysicalDeviceToolPropertiesWithDownstream( + assert(LayerBase::Get() != nullptr); + return LayerBase::Get()->GetPhysicalDeviceToolPropertiesWithDownstream( physical_device, tool_count, tool_properties, downstream_function); } - return LayerBase::GetPhysicalDeviceToolProperties( + return LayerBase::DispatchGetPhysicalDeviceToolProperties( physical_device, tool_count, tool_properties); } static const LayerManifest* GetLayerManifest(const LayerBase& layer) { return layer.GetLayerManifest(); } @@ -88,19 +91,19 @@ class LayerBaseTestPeer { static VkuDeviceDispatchTable* GetDeviceDispatchTable(const void* object) { return LayerBase::GetDeviceDispatchTable(object); } static PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* command_name) { - return LayerBase::GetInstanceProcAddr(instance, command_name); + return LayerBase::DispatchGetInstanceProcAddr(instance, command_name); } static PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* command_name) { - return LayerBase::GetDeviceProcAddr(device, command_name); + return LayerBase::DispatchGetDeviceProcAddr(device, command_name); } static VkResult CreateInstance(const VkInstanceCreateInfo* create_info, const VkAllocationCallbacks* allocator, VkInstance* instance) { - return LayerBase::CreateInstance(create_info, allocator, instance); + return LayerBase::DispatchCreateInstance(create_info, allocator, instance); } static void DestroyInstance(VkInstance instance, const VkAllocationCallbacks* allocator) { - LayerBase::DestroyInstance(instance, allocator); + LayerBase::DispatchDestroyInstance(instance, allocator); } }; diff --git a/layersvt/test/common/test_layer_entrypoints.cpp b/layersvt/test/common/test_layer_entrypoints.cpp index da36c7d69e..fceff3af73 100644 --- a/layersvt/test/common/test_layer_entrypoints.cpp +++ b/layersvt/test/common/test_layer_entrypoints.cpp @@ -19,6 +19,9 @@ #include #include +#include +#include + namespace layersvt { namespace { @@ -76,5 +79,211 @@ TEST(LayerEntrypointsTest, ForwardingCalls) { EXPECT_EQ(::vkNegotiateLoaderLayerInterfaceVersion(&unsupported_version_interface), VK_ERROR_INITIALIZATION_FAILED); } +class OverriddenEntrypointsTestLayer : public LayerBase { + public: + explicit OverriddenEntrypointsTestLayer(const LayerManifest* manifest) : manifest_(manifest) {} + ~OverriddenEntrypointsTestLayer() override = default; + + [[nodiscard]] const LayerManifest* GetLayerManifest() const override { return manifest_; } + + int override_calls = 0; + VkInstance last_instance = VK_NULL_HANDLE; + VkDevice last_device = VK_NULL_HANDLE; + VkPhysicalDevice last_physical_device = VK_NULL_HANDLE; + + protected: + PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* command_name) override { + ++override_calls; + last_instance = instance; + if (command_name && std::strcmp(command_name, "vkInterceptedGipaSentinel") == 0) { + return nullptr; + } + return LayerBase::GetInstanceProcAddr(instance, command_name); + } + + PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* command_name) override { + ++override_calls; + last_device = device; + if (command_name && std::strcmp(command_name, "vkInterceptedGdpaSentinel") == 0) { + return nullptr; + } + return LayerBase::GetDeviceProcAddr(device, command_name); + } + + VkResult CreateInstance(const VkInstanceCreateInfo*, const VkAllocationCallbacks*, VkInstance*) override { + ++override_calls; + return VK_EVENT_SET; + } + + void DestroyInstance(VkInstance instance, const VkAllocationCallbacks*) override { + ++override_calls; + last_instance = instance; + } + + VkResult CreateDevice(VkPhysicalDevice physical_device, const VkDeviceCreateInfo*, const VkAllocationCallbacks*, + VkDevice*) override { + ++override_calls; + last_physical_device = physical_device; + return VK_EVENT_SET; + } + + void DestroyDevice(VkDevice device, const VkAllocationCallbacks*) override { + ++override_calls; + last_device = device; + } + + VkResult EnumerateInstanceLayerProperties(uint32_t*, VkLayerProperties*) override { + ++override_calls; + return VK_INCOMPLETE; + } + + VkResult EnumerateInstanceExtensionProperties(const char*, uint32_t*, VkExtensionProperties*) override { + ++override_calls; + return VK_INCOMPLETE; + } + + VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physical_device, uint32_t*, VkLayerProperties*) override { + ++override_calls; + last_physical_device = physical_device; + return VK_INCOMPLETE; + } + + VkResult EnumerateDeviceExtensionProperties(VkPhysicalDevice physical_device, const char*, uint32_t*, + VkExtensionProperties*) override { + ++override_calls; + last_physical_device = physical_device; + return VK_INCOMPLETE; + } + + VkResult GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t*, + VkPhysicalDeviceToolPropertiesEXT*) override { + ++override_calls; + last_physical_device = physical_device; + return VK_INCOMPLETE; + } + + private: + const LayerManifest* manifest_; +}; + +TEST(LayerEntrypointsTest, ExportedSymbolsRouteThroughVirtualOverrides) { + LayerManifest manifest{ + .layer_name = "VK_LAYER_TEST_Entrypoints", + .tool_properties = VkPhysicalDeviceToolPropertiesEXT{ + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT, + }, + }; + OverriddenEntrypointsTestLayer test_layer(&manifest); + uint32_t count = 0; + + auto instance = reinterpret_cast(static_cast(0x1234)); + auto device = reinterpret_cast(static_cast(0x5678)); + // The physical device is not registered. The override must receive it unchanged. + auto physical_device = reinterpret_cast(static_cast(0x9ABC)); + + EXPECT_EQ(::vkGetInstanceProcAddr(instance, "vkInterceptedGipaSentinel"), nullptr); + EXPECT_EQ(test_layer.last_instance, instance); + EXPECT_EQ(::vkGetDeviceProcAddr(device, "vkInterceptedGdpaSentinel"), nullptr); + EXPECT_EQ(test_layer.last_device, device); + EXPECT_EQ(::vkEnumerateInstanceLayerProperties(&count, nullptr), VK_INCOMPLETE); + EXPECT_EQ(::vkEnumerateInstanceExtensionProperties(nullptr, &count, nullptr), VK_INCOMPLETE); + EXPECT_EQ(::vkEnumerateDeviceLayerProperties(physical_device, &count, nullptr), VK_INCOMPLETE); + EXPECT_EQ(test_layer.last_physical_device, physical_device); + test_layer.last_physical_device = VK_NULL_HANDLE; + EXPECT_EQ(::vkEnumerateDeviceExtensionProperties(physical_device, nullptr, &count, nullptr), VK_INCOMPLETE); + EXPECT_EQ(test_layer.last_physical_device, physical_device); + EXPECT_EQ(test_layer.override_calls, 6); +} + +// Built-in commands queried via GIPA return Dispatch* thunks and invoke the virtual overrides when called. +TEST(LayerEntrypointsTest, InstanceProcAddrThunksRouteThroughVirtualOverrides) { + LayerManifest manifest{ + .layer_name = "VK_LAYER_TEST_Entrypoints", + .tool_properties = VkPhysicalDeviceToolPropertiesEXT{ + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT, + }, + }; + OverriddenEntrypointsTestLayer test_layer(&manifest); + uint32_t count = 0; + + auto instance = reinterpret_cast(static_cast(0x1234)); + // The physical device is not registered. The override must receive it unchanged. + auto physical_device = reinterpret_cast(static_cast(0x9ABC)); + + auto pfn_create_instance = + reinterpret_cast(::vkGetInstanceProcAddr(VK_NULL_HANDLE, "vkCreateInstance")); + ASSERT_NE(pfn_create_instance, nullptr); + EXPECT_EQ(pfn_create_instance(nullptr, nullptr, nullptr), VK_EVENT_SET); + + auto pfn_destroy_instance = + reinterpret_cast(::vkGetInstanceProcAddr(instance, "vkDestroyInstance")); + ASSERT_NE(pfn_destroy_instance, nullptr); + test_layer.last_instance = VK_NULL_HANDLE; + pfn_destroy_instance(instance, nullptr); + EXPECT_EQ(test_layer.last_instance, instance); + + auto pfn_create_device = reinterpret_cast(::vkGetInstanceProcAddr(instance, "vkCreateDevice")); + ASSERT_NE(pfn_create_device, nullptr); + test_layer.last_physical_device = VK_NULL_HANDLE; + EXPECT_EQ(pfn_create_device(physical_device, nullptr, nullptr, nullptr), VK_EVENT_SET); + EXPECT_EQ(test_layer.last_physical_device, physical_device); + + auto pfn_tool_props = reinterpret_cast( + ::vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceToolPropertiesEXT")); + ASSERT_NE(pfn_tool_props, nullptr); + test_layer.last_physical_device = VK_NULL_HANDLE; + EXPECT_EQ(pfn_tool_props(physical_device, &count, nullptr), VK_INCOMPLETE); + EXPECT_EQ(test_layer.last_physical_device, physical_device); +} + +// Built-in commands queried via GDPA return Dispatch* thunks and invoke the virtual overrides when called. +TEST(LayerEntrypointsTest, DeviceProcAddrThunksRouteThroughVirtualOverrides) { + LayerManifest manifest{ + .layer_name = "VK_LAYER_TEST_Entrypoints", + .tool_properties = VkPhysicalDeviceToolPropertiesEXT{ + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TOOL_PROPERTIES_EXT, + }, + }; + OverriddenEntrypointsTestLayer test_layer(&manifest); + + auto device = reinterpret_cast(static_cast(0x5678)); + + auto pfn_gdpa = reinterpret_cast(::vkGetDeviceProcAddr(device, "vkGetDeviceProcAddr")); + ASSERT_NE(pfn_gdpa, nullptr); + test_layer.last_device = VK_NULL_HANDLE; + EXPECT_EQ(pfn_gdpa(device, "vkInterceptedGdpaSentinel"), nullptr); + EXPECT_EQ(test_layer.last_device, device); + + auto pfn_destroy_device = reinterpret_cast(::vkGetDeviceProcAddr(device, "vkDestroyDevice")); + ASSERT_NE(pfn_destroy_device, nullptr); + test_layer.last_device = VK_NULL_HANDLE; + pfn_destroy_device(device, nullptr); + EXPECT_EQ(test_layer.last_device, device); +} + +class InstanceLayerPropertiesOnlyTestLayer : public LayerBase { + public: + explicit InstanceLayerPropertiesOnlyTestLayer(const LayerManifest* manifest) : manifest_(manifest) {} + ~InstanceLayerPropertiesOnlyTestLayer() override = default; + + [[nodiscard]] const LayerManifest* GetLayerManifest() const override { return manifest_; } + + protected: + VkResult EnumerateInstanceLayerProperties(uint32_t*, VkLayerProperties*) override { return VK_INCOMPLETE; } + + private: + const LayerManifest* manifest_; +}; + +TEST(LayerEntrypointsTest, DeviceLayerPropertiesUseInstanceLayerPropertiesOverride) { + LayerManifest manifest{.layer_name = "VK_LAYER_TEST_Entrypoints"}; + InstanceLayerPropertiesOnlyTestLayer test_layer(&manifest); + uint32_t count = 0; + + auto physical_device = reinterpret_cast(static_cast(0x9ABC)); + + EXPECT_EQ(::vkEnumerateDeviceLayerProperties(physical_device, &count, nullptr), VK_INCOMPLETE); +} + } // namespace } // namespace layersvt