From 2e56f34952df2d18f622fa283703ddcecfc6d6c3 Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Thu, 21 Aug 2025 19:34:30 +0000 Subject: [PATCH] gfxstream: hide vkTraceAsyncGOOGLE behind new capset flag ... to make it forward compatible / to make it not crash older Gfxstream host builds. Test: Capture guest and host trace and inspect in perfetto UI Reviewed-by: Aaron Ruby Part-of: --- .../guest/vulkan_enc/ResourceTracker.cpp | 34 ++++++++++--------- .../guest/vulkan_enc/ResourceTracker.h | 2 ++ .../virtio-gpu/virtgpu_gfxstream_protocol.h | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp index 1a279cea2d5..c03be1514f8 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp @@ -104,22 +104,6 @@ uint64_t GeneratePseudoUniqueId() { } #endif -void EmitGuestAndHostTraceMarker(VkEncoder* encoder) { -#ifdef HAVE_PERFETTO - const uint64_t flowId = GeneratePseudoUniqueId(); - - TRACE_EVENT_INSTANT( - GFXSTREAM_TRACE_DEFAULT_CATEGORY, - "vkTraceAsyncGOOGLE", - perfetto::Flow::Global(flowId), - "flow id", flowId); - - encoder->vkTraceAsyncGOOGLE(flowId, true /* do lock */); -#else - (void)encoder; -#endif // HAVE_PERFETTO -} - } // namespace #define MAKE_HANDLE_MAPPING_FOREACH(type_name, map_impl, map_to_u64_impl, map_from_u64_impl) \ @@ -802,6 +786,24 @@ CoherentMemoryPtr ResourceTracker::freeCoherentMemoryLocked(VkDeviceMemory memor return nullptr; } +void ResourceTracker::EmitGuestAndHostTraceMarker(VkEncoder* encoder) { +#ifdef HAVE_PERFETTO + const uint64_t flowId = GeneratePseudoUniqueId(); + + TRACE_EVENT_INSTANT( + GFXSTREAM_TRACE_DEFAULT_CATEGORY, + "vkTraceAsyncGOOGLE", + perfetto::Flow::Global(flowId), + "flow id", flowId); + + if (mCaps.vulkanCapset.hasTraceAsyncCommand) { + encoder->vkTraceAsyncGOOGLE(flowId, true /* do lock */); + } +#else + (void)encoder; +#endif // HAVE_PERFETTO +} + VkResult acquireSync(uint64_t syncId, int64_t& osHandle) { struct VirtGpuExecBuffer exec = {}; struct gfxstreamAcquireSync acquireSync = {}; diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.h b/src/gfxstream/guest/vulkan_enc/ResourceTracker.h index ad59b42a571..faa55a481f3 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.h +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.h @@ -885,6 +885,8 @@ class ResourceTracker { void transformImageMemoryRequirementsForGuestLocked(VkImage image, VkMemoryRequirements* reqs); CoherentMemoryPtr freeCoherentMemoryLocked(VkDeviceMemory memory, VkDeviceMemory_Info& info); + void EmitGuestAndHostTraceMarker(VkEncoder* encoder); + std::recursive_mutex mLock; std::optional mCachedPhysicalDeviceMemoryProps; diff --git a/src/virtio/virtio-gpu/virtgpu_gfxstream_protocol.h b/src/virtio/virtio-gpu/virtgpu_gfxstream_protocol.h index 74d817d8a03..247fd4bb900 100644 --- a/src/virtio/virtio-gpu/virtgpu_gfxstream_protocol.h +++ b/src/virtio/virtio-gpu/virtgpu_gfxstream_protocol.h @@ -106,6 +106,7 @@ struct vulkanCapset { uint32_t externalSync; uint32_t virglSupportedFormats[16]; uint32_t vulkanBatchedDescriptorSetUpdate; + uint32_t hasTraceAsyncCommand; }; struct magmaCapset {