gfxstream: update sudbdecode snapshot code

Reviewed-by: Marcin Radomski <dextero@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35323>
This commit is contained in:
Bo Hu 2025-03-29 06:54:37 -07:00 committed by Marge Bot
parent 524d9b0647
commit 3df2a0c061
2 changed files with 65 additions and 12 deletions

View file

@ -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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(mReconstructionMutex)")
cgen.line("// %s modify" % p.paramName)
cgen.stmt("auto apiCallHandle = apiCallInfo->handle")

View file

@ -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