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

Add capture and replay handling for new DX12 resource creation functions #1387

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
117 changes: 117 additions & 0 deletions framework/decode/dx12_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,82 @@ HRESULT Dx12ReplayConsumerBase::OverrideCreateCommittedResource2(
return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateCommittedResource3(
DxObjectInfo* replay_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_HEAP_PROPERTIES>* pHeapProperties,
D3D12_HEAP_FLAGS HeapFlags,
StructPointerDecoder<Decoded_D3D12_RESOURCE_DESC1>* pDesc,
D3D12_BARRIER_LAYOUT InitialLayout,
StructPointerDecoder<Decoded_D3D12_CLEAR_VALUE>* pOptimizedClearValue,
DxObjectInfo* protected_session_object_info,
UINT32 NumCastableFormats,
PointerDecoder<DXGI_FORMAT>* pCastableFormats,
Decoded_GUID riid,
HandlePointerDecoder<void*>* resource)
{
GFXRECON_ASSERT((replay_object_info != nullptr) && (replay_object_info->object != nullptr) && (pDesc != nullptr));

auto replay_object = static_cast<ID3D12Device10*>(replay_object_info->object);

ID3D12ProtectedResourceSession* protected_session = nullptr;
if (protected_session_object_info != nullptr)
{
protected_session = static_cast<ID3D12ProtectedResourceSession*>(protected_session_object_info->object);
}

auto heap_properties_pointer = pHeapProperties->GetPointer();

auto desc_pointer = pDesc->GetPointer();

auto clear_value_pointer = pOptimizedClearValue->GetPointer();

// Create an equivalent but temporary dummy resource
// This allows us to further validate GFXR, since playback will now use a resource located at a different address
HRESULT dummy_result = E_FAIL;
ID3D12Resource* dummy_resource = nullptr;
if (options_.create_dummy_allocations)
{
dummy_result = replay_object->CreateCommittedResource3(heap_properties_pointer,
HeapFlags,
desc_pointer,
InitialLayout,
clear_value_pointer,
protected_session,
NumCastableFormats,
pCastableFormats->GetPointer(),
IID_PPV_ARGS(&dummy_resource));

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

// Playback will use this resource
auto replay_result = replay_object->CreateCommittedResource3(heap_properties_pointer,
HeapFlags,
desc_pointer,
InitialLayout,
clear_value_pointer,
protected_session,
NumCastableFormats,
pCastableFormats->GetPointer(),
*riid.decoded_value,
resource->GetHandlePointer());

// Release the temporary dummy resource
if (options_.create_dummy_allocations)
{
if (SUCCEEDED(dummy_result))
{
dummy_resource->Release();
}
}

return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateFence(DxObjectInfo* replay_object_info,
HRESULT original_result,
UINT64 initial_value,
Expand Down Expand Up @@ -3092,6 +3168,47 @@ HRESULT Dx12ReplayConsumerBase::OverrideCreateReservedResource1(
return replay_result;
}

HRESULT Dx12ReplayConsumerBase::OverrideCreateReservedResource2(
DxObjectInfo* device_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_RESOURCE_DESC>* desc,
D3D12_BARRIER_LAYOUT initial_layout,
StructPointerDecoder<Decoded_D3D12_CLEAR_VALUE>* optimized_clear_value,
DxObjectInfo* protected_session_object_info,
UINT32 num_castable_formats,
PointerDecoder<DXGI_FORMAT>* castable_formats,
Decoded_GUID riid,
HandlePointerDecoder<void*>* resource)
{
GFXRECON_UNREFERENCED_PARAMETER(original_result);

GFXRECON_ASSERT(device_object_info != nullptr);
GFXRECON_ASSERT(device_object_info->object != nullptr);

auto device10 = static_cast<ID3D12Device10*>(device_object_info->object);
ID3D12ProtectedResourceSession* protected_session = nullptr;
if (protected_session_object_info != nullptr)
{
protected_session = static_cast<ID3D12ProtectedResourceSession*>(protected_session_object_info->object);
}

HRESULT replay_result = device10->CreateReservedResource2(desc->GetPointer(),
initial_layout,
optimized_clear_value->GetPointer(),
protected_session,
num_castable_formats,
castable_formats->GetPointer(),
*riid.decoded_value,
resource->GetHandlePointer());

if (SUCCEEDED(replay_result))
{
SetIsReservedResource(resource);
}

return replay_result;
}

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

HRESULT OverrideCreateCommittedResource3(DxObjectInfo* replay_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_HEAP_PROPERTIES>* pHeapProperties,
D3D12_HEAP_FLAGS HeapFlags,
StructPointerDecoder<Decoded_D3D12_RESOURCE_DESC1>* pDesc,
D3D12_BARRIER_LAYOUT InitialLayout,
StructPointerDecoder<Decoded_D3D12_CLEAR_VALUE>* pOptimizedClearValue,
DxObjectInfo* protected_session_object_info,
UINT32 NumCastableFormats,
PointerDecoder<DXGI_FORMAT>* pCastableFormats,
Decoded_GUID riid,
HandlePointerDecoder<void*>* resource);

HRESULT OverrideCreateFence(DxObjectInfo* replay_object_info,
HRESULT original_result,
UINT64 initial_value,
Expand Down Expand Up @@ -568,6 +581,17 @@ class Dx12ReplayConsumerBase : public Dx12Consumer
Decoded_GUID riid,
HandlePointerDecoder<void*>* resource);

HRESULT OverrideCreateReservedResource2(DxObjectInfo* device_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_RESOURCE_DESC>* desc,
D3D12_BARRIER_LAYOUT initial_layout,
StructPointerDecoder<Decoded_D3D12_CLEAR_VALUE>* optimized_clear_value,
DxObjectInfo* protected_session_object_info,
UINT32 num_castable_formats,
PointerDecoder<DXGI_FORMAT>* castable_formats,
Decoded_GUID riid,
HandlePointerDecoder<void*>* resource);

HRESULT OverrideCreateGraphicsPipelineState(DxObjectInfo* device_object_info,
HRESULT original_result,
StructPointerDecoder<Decoded_D3D12_GRAPHICS_PIPELINE_STATE_DESC>* pDesc,
Expand Down
30 changes: 30 additions & 0 deletions framework/encode/custom_dx12_wrapper_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device4_CreateRese
}
};

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

template <>
struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device4_CreateHeap1>
{
Expand Down Expand Up @@ -268,6 +278,16 @@ struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device8_CreateComm
}
};

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

template <>
struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device8_CreatePlacedResource1>
{
Expand All @@ -278,6 +298,16 @@ struct CustomWrapperPostCall<format::ApiCallId::ApiCall_ID3D12Device8_CreatePlac
}
};

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

template <>
struct CustomWrapperPreCall<format::ApiCallId::ApiCall_ID3D12Device3_OpenExistingHeapFromAddress>
{
Expand Down
Loading