Skip to content

Commit

Permalink
Add Dummy Heap
Browse files Browse the repository at this point in the history
Problem:
--create-dummy-allocations not able to disturb PlacedResource allocation.
There is chance that replay recreate PlacedResource at same GPUVA as capture.

Solution:
Create a dummy heap before real heap and then release it immediately.
  • Loading branch information
JerryAMD authored and davidd-lunarg committed Jul 12, 2023
1 parent 0495c58 commit 4667bf3
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 19 deletions.
81 changes: 81 additions & 0 deletions framework/decode/dx12_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,87 @@ HRESULT Dx12ReplayConsumerBase::OverrideCreateCommittedResource(
return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateHeap(DxObjectInfo* replay_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_HEAP_DESC>* pDesc,
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap)
{
GFXRECON_ASSERT((replay_object_info != nullptr) && (replay_object_info->object != nullptr) &&
(ppvHeap != nullptr) && (pDesc != nullptr));

auto replay_object = static_cast<ID3D12Device*>(replay_object_info->object);
auto heap_desc = pDesc->GetPointer();

HRESULT dummy_result = E_FAIL;
ID3D12Heap* dummy_heap = nullptr;
if (options_.create_dummy_allocations)
{
dummy_result = replay_object->CreateHeap(heap_desc, IID_PPV_ARGS(&dummy_heap));

if (!SUCCEEDED(dummy_result))
{
GFXRECON_LOG_WARNING("Failed to create dummy heap");
}
}

auto replay_result = replay_object->CreateHeap(heap_desc, *riid.decoded_value, ppvHeap->GetHandlePointer());

if (options_.create_dummy_allocations)
{
if (SUCCEEDED(dummy_result))
{
dummy_heap->Release();
}
}

return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateHeap1(DxObjectInfo* replay_object_info,
HRESULT return_value,
StructPointerDecoder<Decoded_D3D12_HEAP_DESC>* pDesc,
DxObjectInfo* pProtectedSession,
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap)
{
GFXRECON_ASSERT((replay_object_info != nullptr) && (replay_object_info->object != nullptr) && (pDesc != nullptr) &&
(ppvHeap != nullptr));

auto replay_object = static_cast<ID3D12Device4*>(replay_object_info->object);
auto heap_desc = pDesc->GetPointer();
ID3D12ProtectedResourceSession* in_pProtectedSession = nullptr;
if (pProtectedSession != nullptr)
{
in_pProtectedSession = static_cast<ID3D12ProtectedResourceSession*>(pProtectedSession->object);
}

HRESULT dummy_result = E_FAIL;
ID3D12Heap1* dummy_heap = nullptr;
if (options_.create_dummy_allocations)
{
dummy_result = replay_object->CreateHeap1(heap_desc, in_pProtectedSession, IID_PPV_ARGS(&dummy_heap));

if (!SUCCEEDED(dummy_result))
{
GFXRECON_LOG_WARNING("Failed to create dummy heap");
}
}

auto replay_result =
replay_object->CreateHeap1(heap_desc, in_pProtectedSession, *riid.decoded_value, ppvHeap->GetHandlePointer());

if (options_.create_dummy_allocations)
{
if (SUCCEEDED(dummy_result))
{
dummy_heap->Release();
}
}

return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateCommittedResource1(
DxObjectInfo* replay_object_info,
HRESULT original_result,
Expand Down
13 changes: 13 additions & 0 deletions framework/decode/dx12_replay_consumer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ class Dx12ReplayConsumerBase : public Dx12Consumer
Decoded_GUID riid,
HandlePointerDecoder<void*>* fence);

HRESULT OverrideCreateHeap(DxObjectInfo* replay_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_HEAP_DESC>* pDesc,
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap);

HRESULT OverrideCreateHeap1(DxObjectInfo* replay_object_info,
HRESULT return_value,
StructPointerDecoder<Decoded_D3D12_HEAP_DESC>* pDesc,
DxObjectInfo* pProtectedSession,
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap);

UINT OverrideGetDescriptorHandleIncrementSize(DxObjectInfo* replay_object_info,
UINT original_result,
D3D12_DESCRIPTOR_HEAP_TYPE descriptor_heap_type);
Expand Down
4 changes: 3 additions & 1 deletion framework/generated/dx12_generators/replay_overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"CreateCommittedResource": "OverrideCreateCommittedResource",
"CreateFence": "OverrideCreateFence",
"GetDescriptorHandleIncrementSize": "OverrideGetDescriptorHandleIncrementSize",
"CreateHeap": "OverrideCreateHeap",
"CreateReservedResource": "OverrideCreateReservedResource",
"CreateGraphicsPipelineState": "OverrideCreateGraphicsPipelineState",
"CreateComputePipelineState": "OverrideCreateComputePipelineState",
Expand All @@ -41,7 +42,8 @@
"ID3D12Device4": {
"CreateReservedResource1": "OverrideCreateReservedResource1",
"CreateCommittedResource1": "OverrideCreateCommittedResource1",
"CreateCommandList1": "OverrideCreateCommandList1"
"CreateCommandList1": "OverrideCreateCommandList1",
"CreateHeap1": "OverrideCreateHeap1"
},
"ID3D12Device5": {
"CreateStateObject": "OverrideCreateStateObject",
Expand Down
40 changes: 22 additions & 18 deletions framework/generated/generated_dx12_replay_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4923,18 +4923,20 @@ void Dx12ReplayConsumer::Process_ID3D12Device_CreateHeap(
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap)
{
auto replay_object = MapObject<ID3D12Device>(object_id);
if (replay_object != nullptr)
auto replay_object = GetObjectInfo(object_id);
if ((replay_object != nullptr) && (replay_object->object != nullptr))
{
if(!ppvHeap->IsNull()) ppvHeap->SetHandleLength(1);
auto out_p_ppvHeap = ppvHeap->GetPointer();
auto out_hp_ppvHeap = ppvHeap->GetHandlePointer();
auto replay_result = replay_object->CreateHeap(pDesc->GetPointer(),
*riid.decoded_value,
out_hp_ppvHeap);
DxObjectInfo object_info{};
ppvHeap->SetConsumerData(0, &object_info);
auto replay_result = OverrideCreateHeap(replay_object,
return_value,
pDesc,
riid,
ppvHeap);
if (SUCCEEDED(replay_result))
{
AddObject(out_p_ppvHeap, out_hp_ppvHeap, format::ApiCall_ID3D12Device_CreateHeap);
AddObject(ppvHeap->GetPointer(), ppvHeap->GetHandlePointer(), std::move(object_info), format::ApiCall_ID3D12Device_CreateHeap);
}
CheckReplayResult("ID3D12Device_CreateHeap", return_value, replay_result);
}
Expand Down Expand Up @@ -5759,20 +5761,22 @@ void Dx12ReplayConsumer::Process_ID3D12Device4_CreateHeap1(
Decoded_GUID riid,
HandlePointerDecoder<void*>* ppvHeap)
{
auto replay_object = MapObject<ID3D12Device4>(object_id);
if (replay_object != nullptr)
auto replay_object = GetObjectInfo(object_id);
if ((replay_object != nullptr) && (replay_object->object != nullptr))
{
auto in_pProtectedSession = MapObject<ID3D12ProtectedResourceSession>(pProtectedSession);
auto in_pProtectedSession = GetObjectInfo(pProtectedSession);
if(!ppvHeap->IsNull()) ppvHeap->SetHandleLength(1);
auto out_p_ppvHeap = ppvHeap->GetPointer();
auto out_hp_ppvHeap = ppvHeap->GetHandlePointer();
auto replay_result = replay_object->CreateHeap1(pDesc->GetPointer(),
in_pProtectedSession,
*riid.decoded_value,
out_hp_ppvHeap);
DxObjectInfo object_info{};
ppvHeap->SetConsumerData(0, &object_info);
auto replay_result = OverrideCreateHeap1(replay_object,
return_value,
pDesc,
in_pProtectedSession,
riid,
ppvHeap);
if (SUCCEEDED(replay_result))
{
AddObject(out_p_ppvHeap, out_hp_ppvHeap, format::ApiCall_ID3D12Device4_CreateHeap1);
AddObject(ppvHeap->GetPointer(), ppvHeap->GetHandlePointer(), std::move(object_info), format::ApiCall_ID3D12Device4_CreateHeap1);
}
CheckReplayResult("ID3D12Device4_CreateHeap1", return_value, replay_result);
}
Expand Down

0 comments on commit 4667bf3

Please sign in to comment.