From af8b08281b0fbeb03cd0e7a79ed0acbfc256613f Mon Sep 17 00:00:00 2001 From: Serdar Kocdemir Date: Mon, 13 Jan 2025 14:46:05 +0000 Subject: [PATCH] gfxstream: track pipeline layouts on decoder Track pipeline layout creation and destroy calls to cleanup them correctly on device teardown. Pipeline layouts require delayed delete operations for VulkanQueueSubmitWithCommands feature which modifies order of commands and they need to stay valid during recording. Reviewed-by: Aaron Ruby Part-of: --- .../codegen/scripts/cereal/api_log_decoder.py | 1 + .../codegen/scripts/cereal/decoder.py | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/gfxstream/codegen/scripts/cereal/api_log_decoder.py b/src/gfxstream/codegen/scripts/cereal/api_log_decoder.py index 859bb837e3a..bdbeecea727 100644 --- a/src/gfxstream/codegen/scripts/cereal/api_log_decoder.py +++ b/src/gfxstream/codegen/scripts/cereal/api_log_decoder.py @@ -50,6 +50,7 @@ class ApiLogDecoder(VulkanWrapperGenerator): "vkCreateImageView", "vkCreateImageWithRequirementsGOOGLE", "vkCreatePipelineCache", + "vkCreatePipelineLayout", "vkCreateRenderPass", "vkCreateSampler", "vkCreateSemaphore", diff --git a/src/gfxstream/codegen/scripts/cereal/decoder.py b/src/gfxstream/codegen/scripts/cereal/decoder.py index 17de79d5b6f..525501fb82c 100644 --- a/src/gfxstream/codegen/scripts/cereal/decoder.py +++ b/src/gfxstream/codegen/scripts/cereal/decoder.py @@ -287,7 +287,7 @@ def emit_decode_parameters(typeInfo: VulkanTypeInfo, api: VulkanAPI, cgen, globa lenAccess = cgen.generalLengthAccess(p) if p.dispatchHandle: - if api.name in DELAYED_DECODER_DELETE_DICT_ENTRIES: + if api.name in DELAYED_DECODER_DELETE_DICT_ENTRIES or api.name in DELAYED_DECODER_DELETES: emit_dispatch_unmarshal(typeInfo, p, cgen, False) else: emit_dispatch_unmarshal(typeInfo, p, cgen, globalWrapped) @@ -352,17 +352,26 @@ def emit_dispatch_call(api, cgen): cgen.line("};") def emit_global_state_wrapped_call(api, cgen, context): - if api.name in DELAYED_DECODER_DELETES: - print("Error: Cannot generate a global state wrapped call that is also a delayed delete (yet)"); - raise + # Delayed deletes will call wrapped call with a callback without pool or snapshot info + delay = api.name in DELAYED_DECODER_DELETES + coreCustomParams = list(map(lambda p: p.paramName, api.parameters)) + + if delay: + cgen.line("std::function delayed_remove_callback = [%s]() {" % ", ".join(coreCustomParams)) + cgen.stmt("auto m_state = VkDecoderGlobalState::get()") + customParams = ["nullptr", "nullptr"] + coreCustomParams + else: + customParams = ["&m_pool", SNAPSHOT_API_CALL_INFO_VARNAME] + coreCustomParams - customParams = ["&m_pool", SNAPSHOT_API_CALL_INFO_VARNAME] + list(map(lambda p: p.paramName, api.parameters)) if context: customParams += ["context"] cgen.vkApiCall(api, customPrefix=global_state_prefix, \ customParameters=customParams, globalStatePrefix=global_state_prefix, \ checkForDeviceLost=True, checkForOutOfMemory=True) + if delay: + cgen.line("};") + def emit_decode_parameters_writeback(typeInfo, api, cgen, autobox=True): decodingParams = DecodingParameters(api) @@ -685,6 +694,8 @@ custom_decodes = { "vkDestroyShaderModule": emit_global_state_wrapped_decoding, "vkCreatePipelineCache": emit_global_state_wrapped_decoding, "vkDestroyPipelineCache": emit_global_state_wrapped_decoding, + "vkCreatePipelineLayout": emit_global_state_wrapped_decoding, + "vkDestroyPipelineLayout": emit_global_state_wrapped_decoding, "vkCreateComputePipelines": emit_global_state_wrapped_decoding, "vkCreateGraphicsPipelines": emit_global_state_wrapped_decoding, "vkDestroyPipeline": emit_global_state_wrapped_decoding,