Skip to content

layersvt: Refactor DebugMarker to inherit from LayerBase - #32

Open
olehkuznetsov wants to merge 12 commits into
android-graphics:mainfrom
olehkuznetsov:pr-debugmarker
Open

olehkuznetsov wants to merge 12 commits into
android-graphics:mainfrom
olehkuznetsov:pr-debugmarker

Conversation

@olehkuznetsov

Copy link
Copy Markdown

Important

Dependent PR: This PR is stacked on top of #31 (layersvt_common foundation). Please review and merge #31 first.
The changes specific to this PR are in layersvt/debug_marker/ and layersvt/test/test_debugmarker.cpp.

Refactor the DebugMarker layer to inherit from LayerBase, replacing handwritten Vulkan lifecycle boilerplate and dispatch bookkeeping with shared layersvt_common infrastructure:

  • Inherit from LayerBase: inherit DebugMarker from LayerBase and configure LayerManifest with VK_EXT_debug_marker and VK_EXT_debug_utils extensions.
  • Dispatch & Instance Tracking: replace manual dispatch tables and physical device tracking maps with DispatchTableManager and DeviceInstanceTracker.
  • Boilerplate Elimination: remove handwritten vkCreateInstance, vkDestroyInstance, vkCreateDevice, vkDestroyDevice, and extension enumeration boilerplate from debug_marker_handwritten_dispatch.cpp.
  • Virtual Dispatch Hooks: implement GetLayerSpecificInstanceFunction and GetLayerSpecificDeviceFunction virtual hooks to dispatch debug marker and debug utils commands via DispatchDownstream.
  • Device Teardown Cleanup: override PostDestroyDevice to automatically clean up tracked debug objects associated with destroyed logical devices.
  • Cleanup: delete debug_marker_handwritten_functions.h header.
  • Unit Tests: add unit tests in test_debugmarker.cpp covering manifest queries, LayerBase lifecycle, object tracking cleanup, and dispatch fallback.

Bug:
Test: new tests - DebugMarkerTests

Introduce DispatchTableManager to provide thread-safe storage,
initialization, and lookup for Vulkan instance and device dispatch
tables.

Key components:
- Thread-safe storage with std::mutex
- GetDispatchKey() helper for dispatchable handles
- Loader callback tracking (VK_LOADER_DATA_CALLBACK)

Bug:
Test: new tests - DispatchTableManagerTest#GetDispatchKey, DispatchTableManagerTest#LoaderDataCallback, DispatchTableManagerTest#InstanceAndDeviceTableLifecycle, DispatchTableManagerTest#ConcurrentAccess
Change-Id: I73cf682789015e4d41ab6f42f03964f16a6a6964
Extend DispatchTableManager to maintain thread-safe associations between
VkPhysicalDevice handles and parent VkInstance handles alongside dispatch tables:

- Add SetVkInstance, RegisterPhysicalDevices, GetVkInstance,
  MapPhysicalDevices, and UnmapPhysicalDevices.
- Implement single-lock, atomic teardown in DestroyInstanceTable to
  clean up the instance dispatch table and unmap all associated
  physical devices under instance_mutex_ in one critical section.
- Add strongly-typed GetInstanceDispatchTable(VkPhysicalDevice)
  and GetInstanceDispatchTable(std::nullptr_t) overloads.
- Guard GetDeviceDispatchTable against null object handles.
- Add comprehensive physical device tracking and concurrency unit tests.

Bug:
Test: new tests - DispatchTableManagerTest#SetAndGetVkInstance, DispatchTableManagerTest#RegisterPhysicalDevices, DispatchTableManagerTest#MapPhysicalDevices, DispatchTableManagerTest#UnmapPhysicalDevices, DispatchTableManagerTest#GetInstanceDispatchTablePhysicalDevice, DispatchTableManagerTest#ConcurrentPhysicalDevices
Change-Id: I5b05dc0b42701d659485c3966c4ca6be6a6a6964
Link layer_keep_alive.cpp into layersvt_common OBJECT library on Android:

- Implement anonymous constructor calling dlopen(..., RTLD_NODELETE)
  to ensure the layer shared object stays resident in process memory
  across Vulkan loader queries.
- Linking as part of CMake OBJECT library ensures the constructor is
  preserved by the static linker without requiring explicit header
  declarations or runtime call sites.

Bug:
Test: n/a
Change-Id: I62267c72611916d0c28fdbec203d27b96a6a6964
…ting

Introduce DispatchDownstream template helpers in dispatch_downstream.h and
establish LayerBase command intercept routing and singleton tracking:

- Implement DispatchDownstream, DispatchDownstreamOr, and
  DispatchDownstreamOrSuccess to enable type-safe forwarding of Vulkan
  commands to downstream dispatch tables.
- Establish LayerBase singleton lifecycle (Get()) and accessor to
  DispatchTableManager.
- Implement GetInstanceProcAddr and GetDeviceProcAddr with
  GetKnownInstanceCommand and GetKnownDeviceCommand dispatch tables,
  supporting virtual layer hook overrides (GetLayerInstanceCommand and
  GetLayerDeviceCommand).

Bug:
Test: new tests - DispatchDownstreamTest#DispatchDownstream, LayerBaseTest#LayerTracking, LayerBaseTest#GetKnownCommandsCommonWithoutManifest, LayerBaseTest#LayerSpecificOverrideHooks, LayerBaseTest#ProcAddrDispatchChain
Change-Id: I47a06c52a0a410f498c86084855369896388f87d
Implement Vulkan loader chain traversal and Template Method lifecycle
hooks for instance and device creation and teardown:

- Implement GetChainInfo helper to inspect and unwrap
  VkLayerInstanceCreateInfo (VK_LAYER_LINK_INFO) and VkLayerDeviceCreateInfo
  (VK_LAYER_LINK_INFO and VK_LOADER_DATA_CALLBACK).
- Add extensible pre/post virtual lifecycle hooks (PreCreateInstance,
  PostCreateInstance, PreDestroyInstance, PreCreateDevice,
  PostCreateDevice, PreDestroyDevice).
- Implement CreateInstance, DestroyInstance, CreateDevice, and
  DestroyDevice intercepts managing dispatch table initialization,
  loader callback registration, and teardown ordering.

Bug:
Test: new tests - LayerBaseTest#HookInvocations, LayerBaseTest#CreateInstanceWithMockChain, LayerBaseTest#CreateInstanceNullHandling, LayerBaseTest#PreCreateNotInvokedOnMissingChain, LayerBaseTest#CreateInstanceNullSafetyInHook, LayerBaseTest#PreCreateInstanceMutation, LayerBaseTest#PreCreateDeviceMutation, LayerBaseTest#TeardownOrdering, LayerBaseTest#CreateDeviceWithMockChain, LayerBaseTest#CreateDeviceNullHandling, LayerBaseTest#CreateDeviceInvalidInputSafety, LayerBaseTest#CreateInstanceNullFpCreateInstance, LayerBaseTest#CreateDeviceNullFpCreateDevice, LayerBaseTest#DefaultHooksExecution, LayerBaseTest#DestroyNullHandles
Change-Id: Iefeb5682a4c19b9da9073e17145d0f506a6a6964
…Base

Integrate physical device enumeration and device group mapping into
LayerBase:

- Implement EnumeratePhysicalDevices and EnumeratePhysicalDeviceGroups
  (with Vulkan 1.0 VK_KHR_device_group fallback) intercepts to query
  downstream and populate DispatchTableManager mappings.
- Register enumeration commands in GetKnownInstanceCommand dispatch table.

Bug:
Test: new tests - LayerBaseTest#EnumeratePhysicalDevicesMapping, LayerBaseTest#EnumeratePhysicalDeviceGroupsMapping, LayerBaseTest#EnumeratePhysicalDevicesNullTable, LayerBaseTest#PhysicalDeviceResolvesInstanceTable, LayerBaseTest#EnumeratePhysicalDeviceGroupsKHRResolution
Change-Id: I4e94b8e21051b7f08b3e8c2536ca20956a6a6964
Introduce LayerManifest aggregate struct and integrate layer/extension
property enumeration into LayerBase.

Key capabilities:
- Static layer and extension property definitions via LayerManifest
- Downstream extension query and merging in LayerBase
- Virtual extension and tooling filtering/augmentation hooks
- Tool properties querying with Vulkan 1.3+ / VK_EXT_tooling_info support

Bug:
Test: new tests - LayerManifestTest, LayerBaseEnumerationTest, LayerBaseHooksTest, LayerBaseTest
Change-Id: I96c027dad43270617323b2a61fe206196a6a6964
Implement layersvt_entrypoints OBJECT library for shared layer export:

- Export standard C ABI entry points (vkGetInstanceProcAddr,
  vkGetDeviceProcAddr, and enumeration functions) delegating directly to
  LayerBase static methods.
- Package as an OBJECT library target in CMake so Vulkan layer shared
  libraries can include $<TARGET_OBJECTS:layersvt_entrypoints> without
  duplicate symbol conflicts in test executables.

Bug:
Test: new tests - LayerEntrypointsTest#ForwardingCalls
Change-Id: I0081acc9edf66f54efafe68639637ac66a6a6964
Document LayerBase architectural patterns and class contract:

- Add class contract documentation to layer_base.h covering singleton
  lifecycle, thread-safety invariants, command routing, and lifecycle
  hooks, referencing common README.md for authoring tutorials.
- Include vk_dispatch_table.h directly in layer_base.h.
- Promote GetVkInstance and GetDeviceLoaderDataCallback to public
  methods so namespace-scope hook functions in derived layers can
  access them without boilerplate wrappers.
- Document HasToolProperties contract and clean up redundant comments.

Bug:
Test: n/a
Change-Id: I837a28e1837acb68903c02e196238b16a6a6964
Document layersvt_common foundation library and new layer authoring:

- Add comprehensive guide in layersvt/common/README.md covering
  LayerBase subclassing, declarative LayerManifest configuration,
  downstream command interception via DispatchDownstream, CMake
  integration via layersvt_entrypoints, and unit testing conventions.
- Update layersvt/README.md to reference layersvt_common documentation.

Bug:
Test: n/a
Change-Id: Ic951a67b73e3321a7cbe8be4d9fa41c46a6a6964
Refactor the DebugMarker layer to inherit from LayerBase, replacing
handwritten Vulkan lifecycle boilerplate and dispatch bookkeeping with
shared layersvt_common infrastructure:

- Inherit DebugMarker from LayerBase and configure LayerManifest with
  VK_EXT_debug_marker and VK_EXT_debug_utils extensions.
- Replace manual instance and device dispatch tables and physical
  device tracking with DispatchTableManager and DeviceInstanceTracker.
- Remove handwritten vkCreateInstance, vkDestroyInstance,
  vkCreateDevice, vkDestroyDevice, and extension enumeration
  boilerplate from debug_marker_handwritten_dispatch.cpp.
- Implement GetLayerSpecificInstanceFunction and
  GetLayerSpecificDeviceFunction virtual hooks to dispatch
  debug marker and debug utils commands via DispatchDownstream.
- Delete debug_marker_handwritten_functions.h header.
- Add unit tests in test_debugmarker.cpp covering manifest queries,
  LayerBase lifecycle, and dispatch fallback.

Bug:
Test: new tests - DebugMarkerTests
Change-Id: I5ad00681e85f15d0779ad5dcea806b8e6a6a6964
Override PreDestroyDevice in DebugMarker to remove tracked object
names associated with a destroyed VkDevice, preventing unbounded
memory growth when devices are repeatedly created and destroyed.

Add PreDestroyDeviceCleanupTest in test_debugmarker.cpp to verify
that tracked objects for destroyed devices are cleaned up while
preserving objects on remaining active devices.

Bug:
Test: new tests - DebugMarkerTests#PreDestroyDeviceCleanupTest
Change-Id: I9a3624e7bf3fd05d6447adb46df887dd6a6a6964
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant