From 61e7de29a12f36b441ac15d8f8b8620f35ea5655 Mon Sep 17 00:00:00 2001 From: Locke Lin Date: Thu, 26 Sep 2024 13:57:59 -0600 Subject: [PATCH] Move before extra ExecuteCommandLists Move before extra ExecuteCommandLists from PreProcess_ID3D12CommandQueue_ExecuteCommandLists to OverrideID3D12CommandQueue_ExecuteCommandLists. All three extra ExecuteCommandLists are in OverrideID3D12CommandQueue_ExecuteCommandLists to make the code simpler. --- framework/encode/d3d12_capture_manager.cpp | 146 +++++++++------------ 1 file changed, 64 insertions(+), 82 deletions(-) diff --git a/framework/encode/d3d12_capture_manager.cpp b/framework/encode/d3d12_capture_manager.cpp index 67557b02a..c66e5a59d 100644 --- a/framework/encode/d3d12_capture_manager.cpp +++ b/framework/encode/d3d12_capture_manager.cpp @@ -1740,82 +1740,6 @@ void D3D12CaptureManager::PreProcess_ID3D12CommandQueue_ExecuteCommandLists(ID3D GFXRECON_UNREFERENCED_PARAMETER(num_lists); GFXRECON_UNREFERENCED_PARAMETER(lists); - bool is_split_commandlist = false; - for (uint32_t i = 0; i < num_lists; ++i) - { - auto cmd_wrapper = reinterpret_cast(lists[i]); - GFXRECON_ASSERT(cmd_wrapper); - - auto cmd_info = cmd_wrapper->GetObjectInfo(); - GFXRECON_ASSERT(cmd_info); - - if (cmd_info->is_split_commandlist) - { - is_split_commandlist = true; - break; - } - } - - if (!is_split_commandlist && IsTrimEnabled() && GetTrimBoundary() == CaptureSettings::TrimBoundary::kDrawCalls) - { - auto trim_draw_calls = GetTrimDrawCalls(); - if (common_manager_->GetQueueSubmitCount() == trim_draw_calls.submit_index) - { - DecrementCallScope(); - - auto target_cmdlist = lists[trim_draw_calls.command_index]; - auto target_wrapper = reinterpret_cast(target_cmdlist); - GFXRECON_ASSERT(target_wrapper); - - auto target_info = target_wrapper->GetObjectInfo(); - GFXRECON_ASSERT(target_info); - - if (num_lists <= trim_draw_calls.command_index) - { - GFXRECON_LOG_FATAL( - "CAPTURE_DRAW_CALLS can't find the commandlist index(%d). It might be out of range(%d).", - trim_draw_calls.command_index, - num_lists); - GFXRECON_ASSERT(num_lists > trim_draw_calls.command_index); - } - - // before of lists and splitted - std::vector cmdlists; - for (uint32_t i = 0; i < trim_draw_calls.command_index; ++i) - { - cmdlists.emplace_back(lists[i]); - } - - if (!target_info->find_target_draw_calls) - { - GFXRECON_LOG_FATAL( - "CAPTURE_DRAW_CALLS can't find the draw call indices(%d-%d). It might be out of range.", - trim_draw_calls.draw_call_indices.first, - trim_draw_calls.draw_call_indices.last); - GFXRECON_ASSERT(target_info->find_target_draw_calls); - } - - if (target_info->target_bundle_commandlist_info && - !target_info->target_bundle_commandlist_info->find_target_draw_calls) - { - GFXRECON_LOG_FATAL( - "CAPTURE_DRAW_CALLS can't find the bundle draw call indices(%d-%d). It might be out of range.", - trim_draw_calls.bundle_draw_call_indices.first, - trim_draw_calls.bundle_draw_call_indices.last); - GFXRECON_ASSERT(target_info->target_bundle_commandlist_info->find_target_draw_calls); - } - - auto before_draw_call_cmd = target_info->split_command_sets[graphics::dx12::kBeforeDrawCallArrayIndex].list; - GFXRECON_ASSERT(before_draw_call_cmd); - cmdlists.emplace_back(before_draw_call_cmd); - - wrapper->ExecuteCommandLists(cmdlists.size(), cmdlists.data()); - auto queue = reinterpret_cast(wrapper->GetWrappedObject()); - graphics::dx12::WaitForQueue(queue); - IncrementCallScope(); - } - } - if (GetMemoryTrackingMode() == CaptureSettings::MemoryTrackingMode::kPageGuard) { util::PageGuardManager* manager = util::PageGuardManager::Get(); @@ -1861,6 +1785,22 @@ void D3D12CaptureManager::PreProcess_ID3D12CommandQueue_ExecuteCommandLists(ID3D } } + bool is_split_commandlist = false; + for (uint32_t i = 0; i < num_lists; ++i) + { + auto cmd_wrapper = reinterpret_cast(lists[i]); + GFXRECON_ASSERT(cmd_wrapper); + + auto cmd_info = cmd_wrapper->GetObjectInfo(); + GFXRECON_ASSERT(cmd_info); + + if (cmd_info->is_split_commandlist) + { + is_split_commandlist = true; + break; + } + } + // Split commandlist is for trim drawcalls. It means that this is a extra ExecuteCommandLists. It shouldn't count // queue_submit_count_. if (!is_split_commandlist) @@ -1896,8 +1836,16 @@ void D3D12CaptureManager::OverrideID3D12CommandQueue_ExecuteCommandLists(ID3D12C // TODO: When queue_submit_count_ becomes 0-based, remove "-1". if ((common_manager_->GetQueueSubmitCount() - 1) == trim_draw_calls.submit_index) { + if (num_lists <= trim_draw_calls.command_index) + { + GFXRECON_LOG_FATAL( + "CAPTURE_DRAW_CALLS can't find the commandlist index(%d). It might be out of range(%d).", + trim_draw_calls.command_index, + num_lists); + GFXRECON_ASSERT(num_lists > trim_draw_calls.command_index); + } + DecrementCallScope(); - common_manager_->ActivateTrimmingDrawCalls(format::ApiFamilyId::ApiFamily_D3D12); auto target_cmdlist = lists[trim_draw_calls.command_index]; auto target_wrapper = reinterpret_cast(target_cmdlist); @@ -1906,22 +1854,56 @@ void D3D12CaptureManager::OverrideID3D12CommandQueue_ExecuteCommandLists(ID3D12C auto target_info = target_wrapper->GetObjectInfo(); GFXRECON_ASSERT(target_info); + if (!target_info->find_target_draw_calls) + { + GFXRECON_LOG_FATAL( + "CAPTURE_DRAW_CALLS can't find the draw call indices(%d-%d). It might be out of range.", + trim_draw_calls.draw_call_indices.first, + trim_draw_calls.draw_call_indices.last); + GFXRECON_ASSERT(target_info->find_target_draw_calls); + } + + if (target_info->target_bundle_commandlist_info && + !target_info->target_bundle_commandlist_info->find_target_draw_calls) + { + GFXRECON_LOG_FATAL( + "CAPTURE_DRAW_CALLS can't find the bundle draw call indices(%d-%d). It might be out of range.", + trim_draw_calls.bundle_draw_call_indices.first, + trim_draw_calls.bundle_draw_call_indices.last); + GFXRECON_ASSERT(target_info->target_bundle_commandlist_info->find_target_draw_calls); + } + std::vector cmdlists; + // before of lists and before of splitted + for (uint32_t i = 0; i < trim_draw_calls.command_index; ++i) + { + cmdlists.emplace_back(lists[i]); + } + + auto before_draw_call_cmd = target_info->split_command_sets[graphics::dx12::kBeforeDrawCallArrayIndex].list; + GFXRECON_ASSERT(before_draw_call_cmd); + cmdlists.emplace_back(before_draw_call_cmd); + + wrapper->ExecuteCommandLists(cmdlists.size(), cmdlists.data()); + auto queue = reinterpret_cast(wrapper->GetWrappedObject()); + graphics::dx12::WaitForQueue(queue); + cmdlists.clear(); + + // target of splitted + common_manager_->ActivateTrimmingDrawCalls(format::ApiFamilyId::ApiFamily_D3D12); + auto target_draw_call_cmd = target_info->split_command_sets[graphics::dx12::kDrawCallArrayIndex].list; GFXRECON_ASSERT(target_draw_call_cmd); cmdlists.emplace_back(target_draw_call_cmd); - // target of splitted wrapper->ExecuteCommandLists(cmdlists.size(), cmdlists.data()); - cmdlists.clear(); common_manager_->DeactivateTrimmingDrawCalls(); - // after of splitted and lists - auto after_draw_call_cmd = - target_info->split_command_sets[graphics::dx12::kAfterDrawCallArrayIndex].list; + // after of splitted and after of lists + auto after_draw_call_cmd = target_info->split_command_sets[graphics::dx12::kAfterDrawCallArrayIndex].list; GFXRECON_ASSERT(after_draw_call_cmd); cmdlists.emplace_back(after_draw_call_cmd);