From 3df2a0c061c9e50e8622bbf6a41940fd51f1af9b Mon Sep 17 00:00:00 2001 From: Bo Hu Date: Sat, 29 Mar 2025 06:54:37 -0700 Subject: [PATCH] gfxstream: update sudbdecode snapshot code Reviewed-by: Marcin Radomski Part-of: --- .../codegen/scripts/cereal/decodersnapshot.py | 56 +++++++++++++++---- .../codegen/scripts/cereal/subdecode.py | 21 ++++++- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py b/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py index fea29686cd5..860d563d942 100644 --- a/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py +++ b/src/gfxstream/codegen/scripts/cereal/decodersnapshot.py @@ -260,6 +260,15 @@ def api_special_implementation_common(api, cgen, tag_vk): cgen.stmt("mReconstruction.setCreatedHandlesForApi(apiCallHandle, (const uint64_t*)(&handle), 1)") cgen.stmt("mReconstruction.setApiTrace(apiCallInfo, apiCallPacket, apiCallPacketSize)") +def api_special_implementation_vkCmdPipelineBarrier(api, cgen): + cgen.stmt("std::lock_guard lock(mReconstructionMutex)") + cgen.beginFor("uint32_t i = 0", "i < bufferMemoryBarrierCount", "++i") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkBuffer( pBufferMemoryBarriers[i].buffer))") + cgen.endFor() + cgen.beginFor("uint32_t i = 0", "i < imageMemoryBarrierCount", "++i") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkImage( pImageMemoryBarriers[i].image))") + cgen.endFor() + def api_special_implementation_vkMapMemoryIntoAddressSpaceGOOGLE(api, cgen): cgen.stmt("std::lock_guard lock(mReconstructionMutex)") cgen.stmt("VkDecoderGlobalState* m_state = VkDecoderGlobalState::get()") @@ -271,6 +280,35 @@ def api_special_implementation_vkMapMemoryIntoAddressSpaceGOOGLE(api, cgen): cgen.stmt("mReconstruction.setCreatedHandlesForApi(apiCallHandle, (const uint64_t*)(&handle), 1)") cgen.stmt("mReconstruction.setApiTrace(apiCallInfo, apiCallPacket, apiCallPacketSize)") +def api_special_implementation_vkCmdBeginRenderPass(api, cgen): + cgen.stmt("std::lock_guard lock(mReconstructionMutex)") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkFramebuffer( pRenderPassBegin->framebuffer))") + +def api_special_implementation_vkCmdCopyBufferToImage(api, cgen): + cgen.stmt("std::lock_guard lock(mReconstructionMutex)") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkBuffer(srcBuffer))") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkImage(dstImage))") + +def api_special_implementation_vkCmdBindVertexBuffers(api, cgen): + cgen.stmt("std::lock_guard lock(mReconstructionMutex)") + cgen.beginFor("uint32_t i = 0", "i < bindingCount", "++i") + cgen.stmt("apiCallInfo->depends.push_back( (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkBuffer(pBuffers[i]))") + cgen.endFor() + + +def api_special_implementation_vkResetCommandBuffer(api, cgen): + cgen.line("// Note: special implementation"); + cgen.stmt("std::lock_guard lock(mReconstructionMutex)") + cgen.stmt("mReconstruction.removeDescendantsOfHandle((uint64_t)(uintptr_t)commandBuffer)") + +def api_special_implementation_vkQueueFlushCommandsGOOGLE(api, cgen): + api_special_implementation_common(api, cgen, "Tag_VkCmdOp") + cgen.stmt("mReconstruction.addHandleDependency((const uint64_t*)(&handle), 1, (uint64_t)(uintptr_t)commandBuffer)") + cgen.beginFor("uint32_t i = 0", "i < apiCallInfo->depends.size()", "++i") + cgen.stmt("auto parent = apiCallInfo->depends[i]") + cgen.stmt("mReconstruction.addHandleDependency((const uint64_t*)(&handle), 1, (uint64_t)(uintptr_t)parent)") + cgen.endFor() + def api_special_implementation_vkBindBufferMemory(api, cgen): api_special_implementation_common(api, cgen, "Tag_VkBindMemory") cgen.stmt("mReconstruction.addHandleDependency( (const uint64_t*)(&handle), 1, (uint64_t)(uintptr_t)unboxed_to_boxed_non_dispatchable_VkDeviceMemory(memory))") @@ -295,6 +333,13 @@ apiSpecialImplementation = { "vkBindImageMemory2KHR": api_special_implementation_vkBindImageMemory2, "vkMapMemoryIntoAddressSpaceGOOGLE": api_special_implementation_vkMapMemoryIntoAddressSpaceGOOGLE, "vkGetBlobGOOGLE": api_special_implementation_vkMapMemoryIntoAddressSpaceGOOGLE, + "vkQueueFlushCommandsGOOGLE": api_special_implementation_vkQueueFlushCommandsGOOGLE, + "vkResetCommandBuffer": api_special_implementation_vkResetCommandBuffer, + "vkCmdBindVertexBuffers": api_special_implementation_vkCmdBindVertexBuffers, + "vkCmdCopyBufferToImage": api_special_implementation_vkCmdCopyBufferToImage, + "vkCmdPipelineBarrier": api_special_implementation_vkCmdPipelineBarrier, + "vkCmdBeginRenderPass": api_special_implementation_vkCmdBeginRenderPass, + "vkCmdBeginRenderPass2": api_special_implementation_vkCmdBeginRenderPass, } apiModifies = { @@ -311,7 +356,6 @@ apiActionsTag = { } apiClearModifiers = { - "vkResetCommandBuffer" : ["commandBuffer"], } delayedDestroys = [ @@ -352,16 +396,8 @@ def is_modify_operation(api, param): if api.name in apiModifies: if param.paramName in apiModifies[api.name]: return True - if api.name.startswith('vkCmd') and param.paramName == 'commandBuffer': - return True return False -def is_clear_modifier_operation(api, param): - if api.name in apiClearModifiers: - if param.paramName in apiClearModifiers[api.name]: - return True - - def emit_impl(typeInfo, api, cgen): if api.name in apiSpecialImplementation: apiSpecialImplementation[api.name](api, cgen) @@ -440,7 +476,7 @@ def emit_impl(typeInfo, api, cgen): cgen.stmt(f"mReconstruction.forEachHandleAddApi((const uint64_t*)(&handle), 1, apiCallHandle, {get_target_state(api, p)})") cgen.stmt("mReconstruction.setCreatedHandlesForApi(apiCallHandle, (const uint64_t*)(&handle), 1)") - elif is_modify_operation(api, p) or is_clear_modifier_operation(api, p): + elif is_modify_operation(api, p): cgen.stmt("std::lock_guard lock(mReconstructionMutex)") cgen.line("// %s modify" % p.paramName) cgen.stmt("auto apiCallHandle = apiCallInfo->handle") diff --git a/src/gfxstream/codegen/scripts/cereal/subdecode.py b/src/gfxstream/codegen/scripts/cereal/subdecode.py index fdc5668bbed..1bd1ef1f677 100644 --- a/src/gfxstream/codegen/scripts/cereal/subdecode.py +++ b/src/gfxstream/codegen/scripts/cereal/subdecode.py @@ -1,7 +1,8 @@ # Copyright 2018 Google LLC # SPDX-License-Identifier: MIT from .common.codegen import CodeGen, VulkanWrapperGenerator -from .common.vulkantypes import VulkanAPI, iterateVulkanType, VulkanType +from .common.vulkantypes import VulkanAPI, makeVulkanTypeSimple, iterateVulkanType, VulkanTypeInfo,\ + VulkanType from .reservedmarshaling import VulkanReservedMarshalingCodegen from .transform import TransformCodegen @@ -243,6 +244,19 @@ def emit_decode_parameters(typeInfo, api, cgen, globalWrapped=False): emit_call_log(api, cgen) +def emit_snapshot_call(api, cgen): + apiForSnapshot = \ + api.withCustomReturnType(makeVulkanTypeSimple(False, "void", 0, "void")) + customParamsSnapshot = ["pool", "snapshotApiCallInfo", "nullptr", "0"] + retTypeName = api.getRetTypeExpr() + if retTypeName != "void": + retVar = api.getRetVarExpr() + customParamsSnapshot.append(retVar) + customParamsSnapshot.append("(VkCommandBuffer)(boxed_dispatchHandle)") + customParamsSnapshot = customParamsSnapshot + list(map(lambda p: p.paramName, api.parameters[1:])) + cgen.beginIf("snapshotsEnabled()") + cgen.vkApiCall(apiForSnapshot, customPrefix="this->snapshot()->", customParameters=customParamsSnapshot) + cgen.endIf() def emit_dispatch_call(api, cgen): @@ -263,6 +277,8 @@ def emit_dispatch_call(api, cgen): checkForDeviceLost=True, globalStatePrefix=global_state_prefix, checkForOutOfMemory=True, checkDispatcher="CC_LIKELY(vk)") + emit_snapshot_call(api, cgen) + if api.name in driver_workarounds_global_lock_apis: cgen.stmt("unlock()") @@ -275,6 +291,7 @@ def emit_global_state_wrapped_call(api, cgen, context=False): cgen.vkApiCall(api, customPrefix=global_state_prefix, customParameters=customParams, checkForDeviceLost=True, checkForOutOfMemory=True, globalStatePrefix=global_state_prefix, checkDispatcher="CC_LIKELY(vk)") + emit_snapshot_call(api, cgen) def emit_default_decoding(typeInfo, api, cgen): @@ -337,7 +354,7 @@ class VulkanSubDecoder(VulkanWrapperGenerator): "#define CC_UNLIKELY(exp) (__builtin_expect( !!(exp), false ))\n") self.module.appendImpl( - "size_t subDecode(VulkanMemReadingStream* readStream, VulkanDispatch* vk, void* boxed_dispatchHandle, void* dispatchHandle, VkDeviceSize subDecodeDataSize, const void* pSubDecodeData, const VkDecoderContext& context)\n") + "size_t subDecode(VulkanMemReadingStream* readStream, VulkanDispatch* vk, VkSnapshotApiCallInfo* snapshotApiCallInfo, void* boxed_dispatchHandle, void* dispatchHandle, VkDeviceSize subDecodeDataSize, const void* pSubDecodeData, const VkDecoderContext& context)\n") self.cgen.beginBlock() # function body