Repository navigation
layersvt: Make LayerBase built-in commands virtual behind Dispatch thunks - #58
olehkuznetsov wants to merge 1 commit into
Conversation
…unks Convert the 11 LayerBase built-in proc-addr, lifecycle, enumeration, and tooling entry points from protected static C functions into protected virtual member methods backed by private static C ABI Dispatch* thunks and friend struct LayerEntrypoints. Route layer_entrypoints.cpp and LayerBaseTestPeer through Dispatch* and add unit tests for virtual overrides. Test: ctest --test-dir build --output-on-failure Change-Id: I706b3eb696edaf65203cc85ae62d42386a6a6964
| 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, |
There was a problem hiding this comment.
This override is only reachable if HasToolProperties() returns true. GetKnownInstanceCommand returns DispatchGetPhysicalDeviceToolProperties only in that case. If a layer overrides GetPhysicalDeviceToolProperties but has no tool_properties in its manifest (and does not override HasToolProperties()), the override is never called, and nothing tells the author why.
Can we state this in the comment block above, and in the README note? For example: "Overriding GetPhysicalDeviceToolProperties takes effect only when HasToolProperties() returns true."
|
|
||
| // 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. |
There was a problem hiding this comment.
Two small points about this comment:
- Every other protected virtual in this class has its own
/** ... */doc block. This one floating//block covers 11 methods. Per-method docs (or a doc block on the group) would be easier to find from an IDE hover. - Overriding
GetInstanceProcAddr/GetDeviceProcAddrnow overlaps withGetLayerInstanceCommand/GetLayerDeviceCommand. Can you add one sentence on which one to use? For example: "Prefer GetLayerCommand to add intercepts; override GetProcAddr only to change lookup behavior itself." Without it, authors will use both styles.
| static VkResult VKAPI_CALL GetPhysicalDeviceToolProperties(VkPhysicalDevice physical_device, uint32_t* tool_count, | ||
| VkPhysicalDeviceToolPropertiesEXT* tool_properties); | ||
| static VkResult GetPhysicalDeviceToolPropertiesWithDownstream( | ||
| VkResult GetPhysicalDeviceToolPropertiesWithDownstream( |
There was a problem hiding this comment.
Just below this, GetKnownInstanceCommand / GetKnownDeviceCommand are still static and look up the layer with Get(). But their only callers are now the non-static GetInstanceProcAddr / GetDeviceProcAddr. That gives two paths in one call: this for the outer method and Get() for the inner lookup (GetLayerInstanceCommand, HasToolProperties). They are the same object in production, but a test that constructs a second layer could see them differ.
Suggest making both helpers non-static members that use this, and removing the AssertLayerInitialized() / Get() lines in them. That matches what this PR already does for EnumerateDeviceExtensionPropertiesWithDownstream and GetPhysicalDeviceToolPropertiesWithDownstream.
| 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. |
There was a problem hiding this comment.
Can you copy the contract from layer_base.h into this example? An override of Create* / Destroy* must call the LayerBase:: implementation, or the dispatch tables are not registered or released and the Pre*/Post* hooks do not run. This README is the main authoring guide, so a short example of an override that calls the base method would be useful here:
VkResult CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* ci,
const VkAllocationCallbacks* alloc, VkDevice* device) override {
// ... custom logic ...
return LayerBase::CreateDevice(gpu, ci, alloc, device);
}| } | ||
|
|
||
| // Built-in commands queried via GIPA return Dispatch* thunks and invoke the virtual overrides when called. | ||
| TEST(LayerEntrypointsTest, InstanceProcAddrThunksRouteThroughVirtualOverrides) { |
There was a problem hiding this comment.
Coverage gaps (non-blocking):
- No test covers the documented contract: an override that calls
LayerBase::CreateInstance/CreateDevice/Destroy*still registers and releases the dispatch tables and runs thePre*/Post*hooks. All the overrides here short-circuit and never call the base methods. One test that wraps and calls the base method (with the existingtest_layer_base.cppchain-info helpers) would protect the main use case of this PR. - The GIPA-returned thunks for
vkGetInstanceProcAddr,vkEnumerateInstance*PropertiesandvkEnumerateDevice*Propertiesare not called here. Only the exported symbols are tested for those commands.
| TEST(LayerEntrypointsTest, ExportedSymbolsRouteThroughVirtualOverrides) { | ||
| LayerManifest manifest{ | ||
| .layer_name = "VK_LAYER_TEST_Entrypoints", | ||
| .tool_properties = VkPhysicalDeviceToolPropertiesEXT{ |
There was a problem hiding this comment.
nit: tool_properties is not used in this test because tool properties are not queried here. Also, the same manifest and layer setup is copied into three tests. A small TEST_F fixture (or a helper that returns the manifest) would reduce the repetition.
Convert the 11 LayerBase built-in proc-addr, lifecycle, enumeration, and
tooling entry points from protected static C functions into protected
virtual member methods backed by private static C ABI Dispatch* thunks
and friend struct LayerEntrypoints. Route layer_entrypoints.cpp and
LayerBaseTestPeer through Dispatch* and add unit tests for virtual
overrides.
Test: ctest --test-dir build --output-on-failure
Change-Id: I706b3eb696edaf65203cc85ae62d42386a6a6964