Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommandList Reset at Invalid CommandAllocator #1947

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions framework/encode/custom_dx12_wrapper_commands.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2021-2023 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2021-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -492,6 +492,16 @@ struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12GraphicsCommandLis
}
};

template <>
struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12GraphicsCommandList_Reset>
{
template <typename... Args>
static void Dispatch(D3D12CaptureManager* manager, Args... args)
{
manager->PostProcess_ID3D12GraphicsCommandList_Reset(args...);
}
};

template <>
struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device_CreateCommandList>
{
Expand Down Expand Up @@ -814,7 +824,6 @@ struct CustomWrapperPostCall<format::ApiCallId::ApiCall_IDXGISwapChain4_SetHDRMe
}
};


GFXRECON_END_NAMESPACE(encode)
GFXRECON_END_NAMESPACE(gfxrecon)

Expand Down
31 changes: 21 additions & 10 deletions framework/encode/d3d12_capture_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2021 LunarG, Inc.
** Copyright (c) 2021-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2021-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -2477,6 +2477,17 @@ void D3D12CaptureManager::PostProcess_ID3D12GraphicsCommandList_ResourceBarrier(
}
}

void D3D12CaptureManager::PostProcess_ID3D12GraphicsCommandList_Reset(ID3D12CommandList_Wrapper* list_wrapper,
HRESULT result,
ID3D12CommandAllocator* pAllocator,
ID3D12PipelineState* pInitialState)
{
if (IsCaptureModeTrack())
{
state_tracker_->TrackCommandList_Reset(list_wrapper, pAllocator, pInitialState);
}
}

void D3D12CaptureManager::PostProcess_ID3D12GraphicsCommandList4_BuildRaytracingAccelerationStructure(
ID3D12GraphicsCommandList4_Wrapper* list_wrapper,
const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc,
Expand Down Expand Up @@ -3368,11 +3379,11 @@ bool D3D12CaptureManager::TrimDrawCalls_ID3D12CommandQueue_ExecuteCommandLists(
if (target_info->find_target_draw_call_count !=
(trim_draw_calls.draw_call_indices.last - trim_draw_calls.draw_call_indices.first + 1))
{
GFXRECON_LOG_WARNING(
"CAPTURE_DRAW_CALLS didn't find the enough draw call count(%d). The indices(%d-%d) might be out of range.",
target_info->find_target_draw_call_count,
trim_draw_calls.draw_call_indices.first,
trim_draw_calls.draw_call_indices.last);
GFXRECON_LOG_WARNING("CAPTURE_DRAW_CALLS didn't find the enough draw call count(%d). The indices(%d-%d) "
"might be out of range.",
target_info->find_target_draw_call_count,
trim_draw_calls.draw_call_indices.first,
trim_draw_calls.draw_call_indices.last);
}

if (target_info->target_bundle_commandlist_info)
Expand Down Expand Up @@ -3678,10 +3689,10 @@ D3D12CaptureManager::GetCommandListsForTrimDrawCalls(ID3D12CommandList_Wrapper*
case graphics::dx12::Dx12DumpResourcePos::kDrawCall:
if (trim_draw_calls.draw_call_indices.first != trim_draw_calls.draw_call_indices.last)
{
GFXRECON_LOG_FATAL(
"The target draw call is a ExecuteBundle. The draw call indices must be not a range(%d-%d).",
trim_draw_calls.draw_call_indices.first,
trim_draw_calls.draw_call_indices.last);
GFXRECON_LOG_FATAL("The target draw call is a ExecuteBundle. The draw call indices must be not "
"a range(%d-%d).",
trim_draw_calls.draw_call_indices.first,
trim_draw_calls.draw_call_indices.last);
GFXRECON_ASSERT(trim_draw_calls.draw_call_indices.first ==
trim_draw_calls.draw_call_indices.last);
}
Expand Down
7 changes: 6 additions & 1 deletion framework/encode/d3d12_capture_manager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2021 LunarG, Inc.
** Copyright (c) 2019-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2019-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -497,6 +497,11 @@ class D3D12CaptureManager : public ApiCaptureManager
UINT num_barriers,
const D3D12_RESOURCE_BARRIER* barriers);

void PostProcess_ID3D12GraphicsCommandList_Reset(ID3D12CommandList_Wrapper* list_wrapper,
HRESULT result,
ID3D12CommandAllocator* pAllocator,
ID3D12PipelineState* pInitialState);

void PostProcess_ID3D12GraphicsCommandList4_BuildRaytracingAccelerationStructure(
ID3D12GraphicsCommandList4_Wrapper* list_wrapper,
const D3D12_BUILD_RAYTRACING_ACCELERATION_STRUCTURE_DESC* desc,
Expand Down
14 changes: 7 additions & 7 deletions framework/encode/dx12_object_wrapper_info.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -309,8 +309,7 @@ struct AccelerationStructureBuildTrackingObjects
graphics::dx12::ID3D12ResourceComPtr _resource,
graphics::dx12::ID3D12CommandAllocatorComPtr _post_build_copy_cmd_allocator,
graphics::dx12::ID3D12GraphicsCommandList4ComPtr _post_build_copy_cmd_list) :
resource(_resource),
post_build_copy_cmd_allocator(_post_build_copy_cmd_allocator),
resource(_resource), post_build_copy_cmd_allocator(_post_build_copy_cmd_allocator),
post_build_copy_cmd_list(_post_build_copy_cmd_list)
{}

Expand Down Expand Up @@ -477,11 +476,12 @@ struct ID3D12CommandListInfo : public DxWrapperInfo
D3D12_COMMAND_LIST_TYPE command_list_type{};

// Track command list dependencies.
format::HandleId create_command_allocator_id{ format::kNullHandleId };
format::HandleId create_command_allocator_id{ format::kNullHandleId };
std::shared_ptr<const ID3D12CommandAllocatorInfo> create_command_allocator_info;
std::unordered_set<format::HandleId> command_objects[D3D12GraphicsCommandObjectType::NumObjectTypes];
std::unordered_set<SIZE_T> command_cpu_descriptor_handles;
std::unordered_set<D3D12_GPU_VIRTUAL_ADDRESS> command_gpu_virtual_addresses;
format::HandleId reset_command_allocator_id{ format::kNullHandleId };
std::unordered_set<format::HandleId> command_objects[D3D12GraphicsCommandObjectType::NumObjectTypes];
std::unordered_set<SIZE_T> command_cpu_descriptor_handles;
std::unordered_set<D3D12_GPU_VIRTUAL_ADDRESS> command_gpu_virtual_addresses;

// Record for future. It's not used for now.
std::unordered_set<UINT64> command_gpu_descriptor_handles;
Expand Down
11 changes: 10 additions & 1 deletion framework/encode/dx12_state_tracker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -200,6 +200,14 @@ void Dx12StateTracker::TrackResourceBarriers(ID3D12CommandList_Wrapper* list_
}
}

void Dx12StateTracker::TrackCommandList_Reset(ID3D12CommandList_Wrapper* list_wrapper,
ID3D12CommandAllocator* pAllocator,
ID3D12PipelineState* pInitialState)
{
auto allocator = reinterpret_cast<ID3D12CommandAllocator_Wrapper*>(pAllocator);
list_wrapper->GetObjectInfo()->reset_command_allocator_id = allocator->GetCaptureId();
}

void Dx12StateTracker::TrackExecuteCommandLists(ID3D12CommandQueue_Wrapper* queue_wrapper,
UINT num_lists,
ID3D12CommandList* const* lists)
Expand Down Expand Up @@ -457,6 +465,7 @@ void Dx12StateTracker::TrackCommandListCreation(ID3D12CommandList_Wrapper* list_
{
auto cmd_alloc_wrapper = reinterpret_cast<ID3D12CommandAllocator_Wrapper*>(pCommandAllocator);
list_info->create_command_allocator_id = cmd_alloc_wrapper->GetCaptureId();
list_info->reset_command_allocator_id = list_info->create_command_allocator_id;
list_info->create_command_allocator_info = cmd_alloc_wrapper->GetObjectInfo();
}
}
Expand Down
6 changes: 5 additions & 1 deletion framework/encode/dx12_state_tracker.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -143,6 +143,10 @@ class Dx12StateTracker
UINT num_barriers,
const D3D12_RESOURCE_BARRIER* barriers);

void TrackCommandList_Reset(ID3D12CommandList_Wrapper* list_wrapper,
ID3D12CommandAllocator* pAllocator,
ID3D12PipelineState* pInitialState);

void TrackExecuteCommandLists(ID3D12CommandQueue_Wrapper* queue_wrapper,
UINT num_lists,
ID3D12CommandList* const* lists);
Expand Down
16 changes: 10 additions & 6 deletions framework/encode/dx12_state_writer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2021 LunarG, Inc.
** Copyright (c) 2022-2024 Advanced Micro Devices, Inc. All rights reserved.
** Copyright (c) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -38,8 +38,7 @@ Dx12StateWriter::Dx12StateWriter(util::FileOutputStream* output_stream,
util::Compressor* compressor,
format::ThreadId thread_id,
util::FileOutputStream* asset_file_stream) :
output_stream_(output_stream),
compressor_(compressor), thread_id_(thread_id), encoder_(&parameter_stream_)
output_stream_(output_stream), compressor_(compressor), thread_id_(thread_id), encoder_(&parameter_stream_)
{
assert(output_stream != nullptr);
}
Expand Down Expand Up @@ -797,7 +796,7 @@ void Dx12StateWriter::WriteResourceSnapshot(graphics::Dx12ResourceDataUtil* reso
{
// Needs swapchain's queue to write its buffer.
auto swapchain_info = resource_info->swapchain_wrapper->GetObjectInfo();
queue = swapchain_info->command_queue;
queue = swapchain_info->command_queue;
}
// Read the data from the resource.
HRESULT result = resource_data_util->ReadFromResource(resource,
Expand Down Expand Up @@ -1089,8 +1088,13 @@ void Dx12StateWriter::WriteCommandListCommands(const ID3D12CommandList_Wrapper*
size_t data_size = list_info->command_data.GetDataSize();
const uint8_t* data = list_info->command_data.GetData();

// TODO: Don't write any commands, including the Reset or Close commands, if the command allocator used in the most
// recent Reset command no longer exists.
bool invalid_command_allocator =
(list_info->reset_command_allocator_id != format::kNullHandleId) &&
(state_table.GetID3D12CommandAllocator_Wrapper(list_info->reset_command_allocator_id) == nullptr);
if (invalid_command_allocator == true)
{
return;
}
JerryAMD marked this conversation as resolved.
Show resolved Hide resolved
while (offset < data_size)
{
const size_t* parameter_size = reinterpret_cast<const size_t*>(&data[offset]);
Expand Down
Loading