Skip to content

device_memory_report: publish object names from the memory layer - #38

Open
jimblacklercorp wants to merge 18 commits into
android-graphics:mainfrom
jimblacklercorp:publish-vulkan-debug-markers
Open

jimblacklercorp wants to merge 18 commits into
android-graphics:mainfrom
jimblacklercorp:publish-vulkan-debug-markers

Conversation

@jimblacklercorp

@jimblacklercorp jimblacklercorp commented Sep 21, 2026

Copy link
Copy Markdown

The memory view labels allocations with the debug names an application gives its objects. Those names were only available from VK_LAYER_GOOGLE_DebugMarker, so Sherlock had to load that layer whenever the memory report was enabled, paying for full API event tracing to get a handful of names.

Intercept vkSetDebugUtilsObjectNameEXT and vkDebugMarkerSetObjectNameEXT here instead and publish the names as VulkanObjectName instant events under the VulkanDeviceMemoryReport category, alongside the events they annotate. Names are replayed from DumpCurrentCountersAndAllocations so sessions that attach after the application named its objects still see them, and repeated naming of an unchanged name is dropped because applications re-apply names routinely.

Only buffers, images and device memory are tracked, since the memory view cannot attribute memory to anything else. Applications that need every object named, to label GPU render stages for example, are still served by the debug marker layer.

To allow the layer to operate standalone without VK_LAYER_GOOGLE_DebugMarker loaded, it advertises VK_EXT_debug_utils and VK_EXT_debug_marker in its manifest and extension enumeration entrypoints, strips VK_EXT_debug_marker from vkCreateDevice when the downstream driver does not natively support it, and provides no-op passthroughs for companion commands in both extensions when no lower layer or driver implements them.

BUG=b/559839199

The memory view labels allocations with the debug names an application
gives its objects. Those names were only available from
VK_LAYER_GOOGLE_DebugMarker, so Sherlock had to load that layer whenever
the memory report was enabled, paying for full API event tracing to get
a handful of names.

Intercept vkSetDebugUtilsObjectNameEXT and vkDebugMarkerSetObjectNameEXT
here instead and publish the names as VulkanObjectName instant events
under the VulkanDeviceMemoryReport category, alongside the events they
annotate. Names are replayed from DumpCurrentCountersAndAllocations so
sessions that attach after the application named its objects still see
them, and repeated naming of an unchanged name is dropped because
applications re-apply names routinely.

Only buffers, images and device memory are tracked, since the memory
view cannot attribute memory to anything else. Applications that need
every object named, to label GPU render stages for example, are still
served by the debug marker layer.

The layer does not advertise VK_EXT_debug_marker the way the debug
marker layer does, so it stays passive: vkGetDeviceProcAddr only hands
out these intercepts when the layer below implements them, and an
extension never appears available because this layer is loaded.

BUG=b/559839199
@jimblacklercorp
jimblacklercorp marked this pull request as draft September 22, 2026 00:31

@olehkuznetsov olehkuznetsov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview & Assessment

Thank you for adding Vulkan object debug name tracking and periodic snapshot replay to VK_LAYER_GOOGLE_DeviceMemoryReport! Keying names by (VkObjectType, uint64_t object_handle) and republishing them during DumpCurrentCountersAndAllocations() is well-structured and addresses b/559839199 cleanly.

The core implementation is solid. The inline comments focus on:

  1. Resolving the contradiction between the handwritten interceptor fallback branches (: VK_SUCCESS) and the dispatch table gates (down_func != nullptr).
  2. Enforcing non-null pointer contracts via assertions instead of silent success returns (pNameInfo == nullptr).
  3. Making object_type mandatory on OnDestroyObject at compile time to prevent silent name leaks.
  4. Removing redundant cleanup in RemoveAllocationTracking.
  5. Ensuring test hermeticity across --gtest_repeat and adding dispatch-level interceptor coverage.

Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report.cpp
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_dispatch.cpp Outdated
@jimblacklercorp
jimblacklercorp marked this pull request as ready for review September 22, 2026 11:59

@olehkuznetsov olehkuznetsov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview & Assessment

Thank you for continuing to refine the DeviceMemoryReport Vulkan object debug naming support! Following up on the latest commits in this PR, here is the consolidated consensus code review across the implementation.

The core naming mechanism and Perfetto event emission are well-structured, but there are a few important correctness and contract issues that need resolution:

  1. Commit Description vs. Implementation (F1 — P1): The commit message claims the layer "stays passive: vkGetDeviceProcAddr only hands out these intercepts when the layer below implements them, and an extension never appears available because this layer is loaded", whereas the implementation operates as an active standalone producer (advertising extensions in the manifest, injecting them in vkEnumerate*ExtensionProperties, and returning intercepts unconditionally). The author should explicitly decide between Option A (updating the description/headers to document the standalone producer model) and Option B (reverting to passive interception).
  2. Android Extension Enumeration (F2 — P2): vkEnumerateDeviceExtensionProperties has an asymmetry between the count query (+= 2) and the deduplicating fill query, returns VK_SUCCESS on zero count instead of VK_INCOMPLETE, uses defensive returns, and is restricted behind #ifdef __ANDROID__.
  3. vkCreateDebugUtilsMessengerEXT Stub (F3 — P2): The stub returns VK_SUCCESS without modifying *pMessenger, leaving caller handles uninitialized if downstream lacks the entry point.
  4. Minor Polish (P3s): Scope or explain ENABLE_EXPORTS on test binaries (F4), remove unreachable GDPA core table entry (F5), deduplicate DeviceMemoryReportTestPeer (F6), and emit an empty-name event when erasing on destroy/free to handle handle recycling (F7).

Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_dispatch.cpp Outdated
Comment thread layersvt/test/CMakeLists.txt Outdated
Comment thread layersvt/test/test_devicememoryreport_dispatch.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report.cpp

@olehkuznetsov olehkuznetsov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review comments on the latest changes (9f394248d119):

Comment thread layersvt/device_memory_report/device_memory_report.cpp
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_dispatch.cpp Outdated
Comment thread layersvt/device_memory_report/device_memory_report_handwritten_functions.h Outdated
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.

2 participants