diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index e113c1a39..cde4fdb38 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -190,7 +190,7 @@ void WrappedID3D12GraphicsCommandList::CopyBufferRegion(ID3D12Resource *pDstBuff UINT64 DstOffset, ID3D12Resource *pSrcBuffer, UINT64 SrcOffset, UINT64 NumBytes) { - m_pReal->CopyBufferRegion(pDstBuffer, DstOffset, pSrcBuffer, SrcOffset, NumBytes); + m_pReal->CopyBufferRegion(Unwrap(pDstBuffer), DstOffset, Unwrap(pSrcBuffer), SrcOffset, NumBytes); if(m_State >= WRITING) { @@ -206,13 +206,19 @@ void WrappedID3D12GraphicsCommandList::CopyTextureRegion(const D3D12_TEXTURE_COP const D3D12_TEXTURE_COPY_LOCATION *pSrc, const D3D12_BOX *pSrcBox) { - m_pReal->CopyTextureRegion(pDst, DstX, DstY, DstZ, pSrc, pSrcBox); + D3D12_TEXTURE_COPY_LOCATION dst = *pDst; + dst.pResource = Unwrap(dst.pResource); + + D3D12_TEXTURE_COPY_LOCATION src = *pSrc; + src.pResource = Unwrap(src.pResource); + + m_pReal->CopyTextureRegion(&dst, DstX, DstY, DstZ, &src, pSrcBox); } void WrappedID3D12GraphicsCommandList::CopyResource(ID3D12Resource *pDstResource, ID3D12Resource *pSrcResource) { - m_pReal->CopyResource(pDstResource, pSrcResource); + m_pReal->CopyResource(Unwrap(pDstResource), Unwrap(pSrcResource)); } void WrappedID3D12GraphicsCommandList::CopyTiles( @@ -220,8 +226,8 @@ void WrappedID3D12GraphicsCommandList::CopyTiles( const D3D12_TILE_REGION_SIZE *pTileRegionSize, ID3D12Resource *pBuffer, UINT64 BufferStartOffsetInBytes, D3D12_TILE_COPY_FLAGS Flags) { - m_pReal->CopyTiles(pTiledResource, pTileRegionStartCoordinate, pTileRegionSize, pBuffer, - BufferStartOffsetInBytes, Flags); + m_pReal->CopyTiles(Unwrap(pTiledResource), pTileRegionStartCoordinate, pTileRegionSize, + Unwrap(pBuffer), BufferStartOffsetInBytes, Flags); } void WrappedID3D12GraphicsCommandList::ResolveSubresource(ID3D12Resource *pDstResource, @@ -229,7 +235,8 @@ void WrappedID3D12GraphicsCommandList::ResolveSubresource(ID3D12Resource *pDstRe ID3D12Resource *pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) { - m_pReal->ResolveSubresource(pDstResource, DstSubresource, pSrcResource, SrcSubresource, Format); + m_pReal->ResolveSubresource(Unwrap(pDstResource), DstSubresource, Unwrap(pSrcResource), + SrcSubresource, Format); } bool WrappedID3D12GraphicsCommandList::Serialise_IASetPrimitiveTopology( @@ -397,18 +404,19 @@ void WrappedID3D12GraphicsCommandList::ResourceBarrier(UINT NumBarriers, void WrappedID3D12GraphicsCommandList::ExecuteBundle(ID3D12GraphicsCommandList *pCommandList) { - m_pReal->ExecuteBundle(pCommandList); + m_pReal->ExecuteBundle(Unwrap(pCommandList)); } void WrappedID3D12GraphicsCommandList::SetDescriptorHeaps(UINT NumDescriptorHeaps, ID3D12DescriptorHeap *const *ppDescriptorHeaps) { + RDCUNIMPLEMENTED("SetDescriptorHeaps"); // need to unwrap heaps m_pReal->SetDescriptorHeaps(NumDescriptorHeaps, ppDescriptorHeaps); } void WrappedID3D12GraphicsCommandList::SetComputeRootSignature(ID3D12RootSignature *pRootSignature) { - m_pReal->SetComputeRootSignature(pRootSignature); + m_pReal->SetComputeRootSignature(Unwrap(pRootSignature)); } bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootSignature( @@ -427,7 +435,7 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootSignature( void WrappedID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignature *pRootSignature) { - m_pReal->SetGraphicsRootSignature(pRootSignature); + m_pReal->SetGraphicsRootSignature(Unwrap(pRootSignature)); if(m_State >= WRITING) { @@ -692,34 +700,34 @@ void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewUint( D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, const UINT Values[4], UINT NumRects, const D3D12_RECT *pRects) { - m_pReal->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, - Values, NumRects, pRects); + m_pReal->ClearUnorderedAccessViewUint(ViewGPUHandleInCurrentHeap, ViewCPUHandle, + Unwrap(pResource), Values, NumRects, pRects); } void WrappedID3D12GraphicsCommandList::ClearUnorderedAccessViewFloat( D3D12_GPU_DESCRIPTOR_HANDLE ViewGPUHandleInCurrentHeap, D3D12_CPU_DESCRIPTOR_HANDLE ViewCPUHandle, ID3D12Resource *pResource, const FLOAT Values[4], UINT NumRects, const D3D12_RECT *pRects) { - m_pReal->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, pResource, - Values, NumRects, pRects); + m_pReal->ClearUnorderedAccessViewFloat(ViewGPUHandleInCurrentHeap, ViewCPUHandle, + Unwrap(pResource), Values, NumRects, pRects); } void WrappedID3D12GraphicsCommandList::DiscardResource(ID3D12Resource *pResource, const D3D12_DISCARD_REGION *pRegion) { - m_pReal->DiscardResource(pResource, pRegion); + m_pReal->DiscardResource(Unwrap(pResource), pRegion); } void WrappedID3D12GraphicsCommandList::BeginQuery(ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index) { - m_pReal->BeginQuery(pQueryHeap, Type, Index); + m_pReal->BeginQuery(Unwrap(pQueryHeap), Type, Index); } void WrappedID3D12GraphicsCommandList::EndQuery(ID3D12QueryHeap *pQueryHeap, D3D12_QUERY_TYPE Type, UINT Index) { - m_pReal->EndQuery(pQueryHeap, Type, Index); + m_pReal->EndQuery(Unwrap(pQueryHeap), Type, Index); } void WrappedID3D12GraphicsCommandList::ResolveQueryData(ID3D12QueryHeap *pQueryHeap, @@ -728,15 +736,15 @@ void WrappedID3D12GraphicsCommandList::ResolveQueryData(ID3D12QueryHeap *pQueryH ID3D12Resource *pDestinationBuffer, UINT64 AlignedDestinationBufferOffset) { - m_pReal->ResolveQueryData(pQueryHeap, Type, StartIndex, NumQueries, pDestinationBuffer, - AlignedDestinationBufferOffset); + m_pReal->ResolveQueryData(Unwrap(pQueryHeap), Type, StartIndex, NumQueries, + Unwrap(pDestinationBuffer), AlignedDestinationBufferOffset); } void WrappedID3D12GraphicsCommandList::SetPredication(ID3D12Resource *pBuffer, UINT64 AlignedBufferOffset, D3D12_PREDICATION_OP Operation) { - m_pReal->SetPredication(pBuffer, AlignedBufferOffset, Operation); + m_pReal->SetPredication(Unwrap(pBuffer), AlignedBufferOffset, Operation); } void WrappedID3D12GraphicsCommandList::SetMarker(UINT Metadata, const void *pData, UINT Size) @@ -761,6 +769,6 @@ void WrappedID3D12GraphicsCommandList::ExecuteIndirect(ID3D12CommandSignature *p ID3D12Resource *pCountBuffer, UINT64 CountBufferOffset) { - m_pReal->ExecuteIndirect(pCommandSignature, MaxCommandCount, pArgumentBuffer, - ArgumentBufferOffset, pCountBuffer, CountBufferOffset); + m_pReal->ExecuteIndirect(Unwrap(pCommandSignature), MaxCommandCount, Unwrap(pArgumentBuffer), + ArgumentBufferOffset, Unwrap(pCountBuffer), CountBufferOffset); } \ No newline at end of file diff --git a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp index b0e617dcc..8e5d8204d 100644 --- a/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_queue_wrap.cpp @@ -33,8 +33,8 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::UpdateTileMappings( const D3D12_TILE_RANGE_FLAGS *pRangeFlags, const UINT *pHeapRangeStartOffsets, const UINT *pRangeTileCounts, D3D12_TILE_MAPPING_FLAGS Flags) { - m_pReal->UpdateTileMappings(pResource, NumResourceRegions, pResourceRegionStartCoordinates, - pResourceRegionSizes, pHeap, NumRanges, pRangeFlags, + m_pReal->UpdateTileMappings(Unwrap(pResource), NumResourceRegions, pResourceRegionStartCoordinates, + pResourceRegionSizes, Unwrap(pHeap), NumRanges, pRangeFlags, pHeapRangeStartOffsets, pRangeTileCounts, Flags); } @@ -43,7 +43,7 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::CopyTileMappings( ID3D12Resource *pSrcResource, const D3D12_TILED_RESOURCE_COORDINATE *pSrcRegionStartCoordinate, const D3D12_TILE_REGION_SIZE *pRegionSize, D3D12_TILE_MAPPING_FLAGS Flags) { - m_pReal->CopyTileMappings(pDstResource, pDstRegionStartCoordinate, pSrcResource, + m_pReal->CopyTileMappings(Unwrap(pDstResource), pDstRegionStartCoordinate, Unwrap(pSrcResource), pSrcRegionStartCoordinate, pRegionSize, Flags); } @@ -134,12 +134,12 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Signal(ID3D12Fence *pFence, m_QueueRecord->AddChunk(scope.Get()); } - return m_pReal->Signal(pFence, Value); + return m_pReal->Signal(Unwrap(pFence), Value); } HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::Wait(ID3D12Fence *pFence, UINT64 Value) { - return m_pReal->Wait(pFence, Value); + return m_pReal->Wait(Unwrap(pFence), Value); } HRESULT STDMETHODCALLTYPE WrappedID3D12CommandQueue::GetTimestampFrequency(UINT64 *pFrequency) diff --git a/renderdoc/driver/d3d12/d3d12_common.cpp b/renderdoc/driver/d3d12/d3d12_common.cpp index c7028b2f0..6a06d0929 100644 --- a/renderdoc/driver/d3d12/d3d12_common.cpp +++ b/renderdoc/driver/d3d12/d3d12_common.cpp @@ -23,6 +23,7 @@ ******************************************************************************/ #include "d3d12_common.h" +#include "driver/dxgi/dxgi_common.h" #include "driver/dxgi/dxgi_wrapped.h" #include "d3d12_manager.h" #include "d3d12_resources.h" @@ -374,12 +375,108 @@ void Serialiser::Serialise(const char *name, D3D12_RESOURCE_BARRIER &el) } } +template <> +void Serialiser::Serialise(const char *name, D3D12_HEAP_PROPERTIES &el) +{ + ScopedContext scope(this, name, "D3D12_HEAP_PROPERTIES", 0, true); + + Serialise("Type", el.Type); + Serialise("CPUPageProperty", el.CPUPageProperty); + Serialise("MemoryPoolPreference", el.MemoryPoolPreference); + Serialise("CreationNodeMask", el.CreationNodeMask); + Serialise("VisibleNodeMask", el.VisibleNodeMask); +} + +template <> +void Serialiser::Serialise(const char *name, D3D12_DESCRIPTOR_HEAP_DESC &el) +{ + ScopedContext scope(this, name, "D3D12_DESCRIPTOR_HEAP_DESC", 0, true); + + Serialise("Type", el.Type); + Serialise("NumDescriptors", el.NumDescriptors); + Serialise("Flags", el.Flags); + Serialise("NodeMask", el.NodeMask); +} + +template <> +void Serialiser::Serialise(const char *name, D3D12_CLEAR_VALUE &el) +{ + ScopedContext scope(this, name, "D3D12_CLEAR_VALUE", 0, true); + + Serialise("Format", el.Format); + + if(!IsDepthFormat(el.Format)) + { + SerialisePODArray<4>("Color", el.Color); + } + else + { + Serialise("Depth", el.DepthStencil.Depth); + Serialise("Stencil", el.DepthStencil.Stencil); + } +} + string ToStrHelper::Get(const D3D12_VIEWPORT &el) { return StringFormat::Fmt("Viewport<%.0fx%.0f+%.0f+%.0f z=%f->%f>", el.Width, el.Height, el.TopLeftX, el.TopLeftY, el.MinDepth, el.MaxDepth); } +string ToStrHelper::Get(const D3D12_HEAP_TYPE &el) +{ + switch(el) + { + TOSTR_CASE_STRINGIZE(D3D12_HEAP_TYPE_DEFAULT) + TOSTR_CASE_STRINGIZE(D3D12_HEAP_TYPE_UPLOAD) + TOSTR_CASE_STRINGIZE(D3D12_HEAP_TYPE_READBACK) + TOSTR_CASE_STRINGIZE(D3D12_HEAP_TYPE_CUSTOM) + default: break; + } + + return StringFormat::Fmt("D3D12_HEAP_TYPE<%d>", el); +} + +string ToStrHelper::Get(const D3D12_CPU_PAGE_PROPERTY &el) +{ + switch(el) + { + TOSTR_CASE_STRINGIZE(D3D12_CPU_PAGE_PROPERTY_UNKNOWN) + TOSTR_CASE_STRINGIZE(D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE) + TOSTR_CASE_STRINGIZE(D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE) + TOSTR_CASE_STRINGIZE(D3D12_CPU_PAGE_PROPERTY_WRITE_BACK) + default: break; + } + + return StringFormat::Fmt("D3D12_CPU_PAGE_PROPERTY<%d>", el); +} + +string ToStrHelper::Get(const D3D12_MEMORY_POOL &el) +{ + switch(el) + { + TOSTR_CASE_STRINGIZE(D3D12_MEMORY_POOL_UNKNOWN) + TOSTR_CASE_STRINGIZE(D3D12_MEMORY_POOL_L0) + TOSTR_CASE_STRINGIZE(D3D12_MEMORY_POOL_L1) + default: break; + } + + return StringFormat::Fmt("D3D12_MEMORY_POOL<%d>", el); +} + +string ToStrHelper::Get(const D3D12_DESCRIPTOR_HEAP_TYPE &el) +{ + switch(el) + { + TOSTR_CASE_STRINGIZE(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV) + TOSTR_CASE_STRINGIZE(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER) + TOSTR_CASE_STRINGIZE(D3D12_DESCRIPTOR_HEAP_TYPE_RTV) + TOSTR_CASE_STRINGIZE(D3D12_DESCRIPTOR_HEAP_TYPE_DSV) + default: break; + } + + return StringFormat::Fmt("D3D12_DESCRIPTOR_HEAP_TYPE<%d>", el); +} + string ToStrHelper::Get(const D3D12_RESOURCE_BARRIER_TYPE &el) { switch(el) @@ -631,10 +728,81 @@ string ToStrHelper::Get(const D3D12_TEXTURE_LAYOUT return StringFormat::Fmt("D3D12_TEXTURE_LAYOUT<%d>", el); } +string ToStrHelper::Get(const D3D12_HEAP_FLAGS &el) +{ + string ret; + + if(el == D3D12_HEAP_FLAG_NONE) + return "D3D12_HEAP_FLAG_NONE"; + + if(el & D3D12_HEAP_FLAG_SHARED) + ret += " | D3D12_HEAP_FLAG_SHARED"; + if(el & D3D12_HEAP_FLAG_DENY_BUFFERS) + ret += " | D3D12_HEAP_FLAG_DENY_BUFFERS"; + if(el & D3D12_HEAP_FLAG_ALLOW_DISPLAY) + ret += " | D3D12_HEAP_FLAG_ALLOW_DISPLAY"; + if(el & D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER) + ret += " | D3D12_HEAP_FLAG_SHARED_CROSS_ADAPTER"; + if(el & D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES) + ret += " | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES"; + if(el & D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES) + ret += " | D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES"; + if(el & D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES) + ret += " | D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES"; + if(el & D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS) + ret += " | D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS"; + if(el & D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES) + ret += " | D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES"; + if(el & D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) + ret += " | D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES"; + + if(!ret.empty()) + ret = ret.substr(3); + + return ret; +} + +string ToStrHelper::Get(const D3D12_FENCE_FLAGS &el) +{ + string ret; + + if(el == D3D12_FENCE_FLAG_NONE) + return "D3D12_FENCE_FLAG_NONE"; + + if(el & D3D12_FENCE_FLAG_SHARED) + ret += " | D3D12_FENCE_FLAG_SHARED"; + if(el & D3D12_FENCE_FLAG_SHARED_CROSS_ADAPTER) + ret += " | D3D12_FENCE_FLAG_SHARED_CROSS_ADAPTER"; + + if(!ret.empty()) + ret = ret.substr(3); + + return ret; +} + +string ToStrHelper::Get(const D3D12_DESCRIPTOR_HEAP_FLAGS &el) +{ + string ret; + + if(el == D3D12_DESCRIPTOR_HEAP_FLAG_NONE) + return "D3D12_DESCRIPTOR_HEAP_FLAG_NONE"; + + if(el & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) + ret += " | D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE"; + + if(!ret.empty()) + ret = ret.substr(3); + + return ret; +} + string ToStrHelper::Get(const D3D12_RESOURCE_BARRIER_FLAGS &el) { string ret; + if(el == D3D12_RESOURCE_BARRIER_FLAG_NONE) + return "D3D12_RESOURCE_BARRIER_FLAG_NONE"; + if(el & D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY) ret += " | D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY"; if(el & D3D12_RESOURCE_BARRIER_FLAG_END_ONLY) @@ -694,6 +862,9 @@ string ToStrHelper::Get(const D3D12_PIPELINE_ { string ret; + if(el == D3D12_PIPELINE_STATE_FLAG_NONE) + return "D3D12_PIPELINE_STATE_FLAG_NONE"; + if(el & D3D12_PIPELINE_STATE_FLAG_TOOL_DEBUG) ret += " | D3D12_PIPELINE_STATE_FLAG_TOOL_DEBUG"; @@ -707,6 +878,9 @@ string ToStrHelper::Get(const D3D12_RESOURCE_FLAGS { string ret; + if(el == D3D12_RESOURCE_FLAG_NONE) + return "D3D12_RESOURCE_FLAG_NONE"; + if(el & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ret += " | D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET"; if(el & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) @@ -730,6 +904,9 @@ string ToStrHelper::Get(const D3D12_COMMAND_QU { string ret; + if(el == D3D12_COMMAND_QUEUE_FLAG_NONE) + return "D3D12_COMMAND_QUEUE_FLAG_NONE"; + if(el & D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT) ret += " | D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT"; diff --git a/renderdoc/driver/d3d12/d3d12_common.h b/renderdoc/driver/d3d12/d3d12_common.h index aca2a59cc..50a022bea 100644 --- a/renderdoc/driver/d3d12/d3d12_common.h +++ b/renderdoc/driver/d3d12/d3d12_common.h @@ -124,6 +124,12 @@ template <> void Serialiser::Serialise(const char *name, D3D12_VERTEX_BUFFER_VIEW &el); template <> void Serialiser::Serialise(const char *name, D3D12_RESOURCE_BARRIER &el); +template <> +void Serialiser::Serialise(const char *name, D3D12_HEAP_PROPERTIES &el); +template <> +void Serialiser::Serialise(const char *name, D3D12_DESCRIPTOR_HEAP_DESC &el); +template <> +void Serialiser::Serialise(const char *name, D3D12_CLEAR_VALUE &el); #pragma region Chunks @@ -152,6 +158,12 @@ void Serialiser::Serialise(const char *name, D3D12_RESOURCE_BARRIER &el); \ D3D12_CHUNK_MACRO(CREATE_GRAPHICS_PIPE, "ID3D12Device::CreateGraphicsPipeline") \ D3D12_CHUNK_MACRO(CREATE_COMPUTE_PIPE, "ID3D12Device::CreateComputePipeline") \ + D3D12_CHUNK_MACRO(CREATE_DESCRIPTOR_HEAP, "ID3D12Device::CreateDescriptorHeap") \ + D3D12_CHUNK_MACRO(CREATE_ROOT_SIG, "ID3D12Device::CreateRootSignature") \ + \ + D3D12_CHUNK_MACRO(CREATE_COMMITTED_RESOURCE, "ID3D12Device::CreateCommittedResource") \ + \ + D3D12_CHUNK_MACRO(CREATE_FENCE, "ID3D12Device::CreateFence") \ \ D3D12_CHUNK_MACRO(CLOSE_LIST, "ID3D12GraphicsCommandList::Close") \ D3D12_CHUNK_MACRO(RESET_LIST, "ID3D12GraphicsCommandList::Reset") \ diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 3e5762ce1..512914f7e 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -166,8 +166,8 @@ bool WrappedID3D12Device::Serialise_CreateCommandList(UINT nodeMask, D3D12_COMMA pInitialState = GetResourceManager()->GetLiveAs(State); ID3D12GraphicsCommandList *ret = NULL; - HRESULT hr = m_pDevice->CreateCommandList(Mask, ListType, pCommandAllocator, pInitialState, - guid, (void **)&ret); + HRESULT hr = m_pDevice->CreateCommandList(Mask, ListType, Unwrap(pCommandAllocator), + Unwrap(pInitialState), guid, (void **)&ret); if(FAILED(hr)) { @@ -190,15 +190,15 @@ HRESULT WrappedID3D12Device::CreateCommandList(UINT nodeMask, D3D12_COMMAND_LIST void **ppCommandList) { if(ppCommandList == NULL) - return m_pDevice->CreateCommandList(nodeMask, type, Unwrap(pCommandAllocator), pInitialState, - riid, NULL); + return m_pDevice->CreateCommandList(nodeMask, type, Unwrap(pCommandAllocator), + Unwrap(pInitialState), riid, NULL); if(riid != __uuidof(ID3D12GraphicsCommandList)) return E_NOINTERFACE; ID3D12GraphicsCommandList *real = NULL; HRESULT ret = m_pDevice->CreateCommandList(nodeMask, type, Unwrap(pCommandAllocator), - pInitialState, riid, (void **)&real); + Unwrap(pInitialState), riid, (void **)&real); if(SUCCEEDED(ret)) { @@ -227,7 +227,7 @@ bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState( { SERIALISE_ELEMENT_PTR(D3D12_GRAPHICS_PIPELINE_STATE_DESC, Descriptor, pDesc); SERIALISE_ELEMENT(IID, guid, riid); - SERIALISE_ELEMENT(ResourceId, Queue, + SERIALISE_ELEMENT(ResourceId, Pipe, ((WrappedID3D12PipelineState *)*ppPipelineState)->GetResourceID()); if(m_State == READING) @@ -243,7 +243,7 @@ bool WrappedID3D12Device::Serialise_CreateGraphicsPipelineState( { ret = new WrappedID3D12PipelineState(ret, this); - GetResourceManager()->AddLiveResource(Queue, ret); + GetResourceManager()->AddLiveResource(Pipe, ret); } } @@ -259,8 +259,11 @@ HRESULT WrappedID3D12Device::CreateGraphicsPipelineState(const D3D12_GRAPHICS_PI if(riid != __uuidof(ID3D12PipelineState)) return E_NOINTERFACE; + D3D12_GRAPHICS_PIPELINE_STATE_DESC unwrappedDesc = *pDesc; + unwrappedDesc.pRootSignature = Unwrap(unwrappedDesc.pRootSignature); + ID3D12PipelineState *real = NULL; - HRESULT ret = m_pDevice->CreateGraphicsPipelineState(pDesc, riid, (void **)&real); + HRESULT ret = m_pDevice->CreateGraphicsPipelineState(&unwrappedDesc, riid, (void **)&real); if(SUCCEEDED(ret)) { @@ -287,7 +290,7 @@ bool WrappedID3D12Device::Serialise_CreateComputePipelineState( { SERIALISE_ELEMENT_PTR(D3D12_COMPUTE_PIPELINE_STATE_DESC, Descriptor, pDesc); SERIALISE_ELEMENT(IID, guid, riid); - SERIALISE_ELEMENT(ResourceId, Queue, + SERIALISE_ELEMENT(ResourceId, Pipe, ((WrappedID3D12PipelineState *)*ppPipelineState)->GetResourceID()); if(m_State == READING) @@ -303,7 +306,7 @@ bool WrappedID3D12Device::Serialise_CreateComputePipelineState( { ret = new WrappedID3D12PipelineState(ret, this); - GetResourceManager()->AddLiveResource(Queue, ret); + GetResourceManager()->AddLiveResource(Pipe, ret); } } @@ -342,18 +345,132 @@ HRESULT WrappedID3D12Device::CreateComputePipelineState(const D3D12_COMPUTE_PIPE return ret; } +bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( + const D3D12_DESCRIPTOR_HEAP_DESC *pDescriptorHeapDesc, REFIID riid, void **ppvHeap) +{ + SERIALISE_ELEMENT_PTR(D3D12_DESCRIPTOR_HEAP_DESC, Descriptor, pDescriptorHeapDesc); + SERIALISE_ELEMENT(IID, guid, riid); + SERIALISE_ELEMENT(ResourceId, Heap, ((WrappedID3D12DescriptorHeap *)*ppvHeap)->GetResourceID()); + + if(m_State == READING) + { + ID3D12DescriptorHeap *ret = NULL; + HRESULT hr = m_pDevice->CreateDescriptorHeap(&Descriptor, guid, (void **)&ret); + + if(FAILED(hr)) + { + RDCERR("Failed on resource serialise-creation, HRESULT: 0x%08x", hr); + } + else + { + ret = new WrappedID3D12DescriptorHeap(ret, this); + + GetResourceManager()->AddLiveResource(Heap, ret); + } + } + + return true; +} + HRESULT WrappedID3D12Device::CreateDescriptorHeap(const D3D12_DESCRIPTOR_HEAP_DESC *pDescriptorHeapDesc, REFIID riid, void **ppvHeap) { - return m_pDevice->CreateDescriptorHeap(pDescriptorHeapDesc, riid, ppvHeap); + if(ppvHeap == NULL) + return m_pDevice->CreateDescriptorHeap(pDescriptorHeapDesc, riid, NULL); + + if(riid != __uuidof(ID3D12DescriptorHeap)) + return E_NOINTERFACE; + + ID3D12DescriptorHeap *real = NULL; + HRESULT ret = m_pDevice->CreateDescriptorHeap(pDescriptorHeapDesc, riid, (void **)&real); + + if(SUCCEEDED(ret)) + { + SCOPED_LOCK(m_D3DLock); + + WrappedID3D12DescriptorHeap *wrapped = new WrappedID3D12DescriptorHeap(real, this); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(CREATE_DESCRIPTOR_HEAP); + Serialise_CreateDescriptorHeap(pDescriptorHeapDesc, riid, (void **)&wrapped); + + m_DeviceRecord->AddChunk(scope.Get()); + } + + *ppvHeap = (ID3D12DescriptorHeap *)wrapped; + } + + return ret; +} + +bool WrappedID3D12Device::Serialise_CreateRootSignature(UINT nodeMask, + const void *pBlobWithRootSignature, + SIZE_T blobLengthInBytes, REFIID riid, + void **ppvRootSignature) +{ + SERIALISE_ELEMENT(UINT, mask, nodeMask); + SERIALISE_ELEMENT(uint32_t, BytecodeLen, (uint32_t)blobLengthInBytes); + SERIALISE_ELEMENT_BUF(byte *, ShaderBytecode, pBlobWithRootSignature, BytecodeLen); + SERIALISE_ELEMENT(IID, guid, riid); + SERIALISE_ELEMENT(ResourceId, Sig, + ((WrappedID3D12RootSignature *)*ppvRootSignature)->GetResourceID()); + + if(m_State == READING) + { + ID3D12RootSignature *ret = NULL; + HRESULT hr = + m_pDevice->CreateRootSignature(mask, ShaderBytecode, BytecodeLen, guid, (void **)&ret); + + if(FAILED(hr)) + { + RDCERR("Failed on resource serialise-creation, HRESULT: 0x%08x", hr); + } + else + { + ret = new WrappedID3D12RootSignature(ret, this); + + GetResourceManager()->AddLiveResource(Sig, ret); + } + } + + return true; } HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlobWithRootSignature, SIZE_T blobLengthInBytes, REFIID riid, void **ppvRootSignature) { - return m_pDevice->CreateRootSignature(nodeMask, pBlobWithRootSignature, blobLengthInBytes, riid, - ppvRootSignature); + if(ppvRootSignature == NULL) + return m_pDevice->CreateRootSignature(nodeMask, pBlobWithRootSignature, blobLengthInBytes, riid, + NULL); + + if(riid != __uuidof(ID3D12RootSignature)) + return E_NOINTERFACE; + + ID3D12RootSignature *real = NULL; + HRESULT ret = m_pDevice->CreateRootSignature(nodeMask, pBlobWithRootSignature, blobLengthInBytes, + riid, (void **)&real); + + if(SUCCEEDED(ret)) + { + SCOPED_LOCK(m_D3DLock); + + WrappedID3D12RootSignature *wrapped = new WrappedID3D12RootSignature(real, this); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(CREATE_ROOT_SIG); + Serialise_CreateRootSignature(nodeMask, pBlobWithRootSignature, blobLengthInBytes, riid, + (void **)&wrapped); + + m_DeviceRecord->AddChunk(scope.Get()); + } + + *ppvRootSignature = (ID3D12RootSignature *)wrapped; + } + + return ret; } void WrappedID3D12Device::CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_VIEW_DESC *pDesc, @@ -366,7 +483,7 @@ void WrappedID3D12Device::CreateShaderResourceView(ID3D12Resource *pResource, const D3D12_SHADER_RESOURCE_VIEW_DESC *pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) { - return m_pDevice->CreateShaderResourceView(pResource, pDesc, DestDescriptor); + return m_pDevice->CreateShaderResourceView(Unwrap(pResource), pDesc, DestDescriptor); } void WrappedID3D12Device::CreateUnorderedAccessView(ID3D12Resource *pResource, @@ -374,13 +491,15 @@ void WrappedID3D12Device::CreateUnorderedAccessView(ID3D12Resource *pResource, const D3D12_UNORDERED_ACCESS_VIEW_DESC *pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) { - return m_pDevice->CreateUnorderedAccessView(pResource, pCounterResource, pDesc, DestDescriptor); + return m_pDevice->CreateUnorderedAccessView(Unwrap(pResource), Unwrap(pCounterResource), pDesc, + DestDescriptor); } void WrappedID3D12Device::CreateRenderTargetView(ID3D12Resource *pResource, const D3D12_RENDER_TARGET_VIEW_DESC *pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) { + D3D12NOTIMP(__FUNCSIG__); return m_pDevice->CreateRenderTargetView(Unwrap(pResource), pDesc, DestDescriptor); } @@ -388,7 +507,7 @@ void WrappedID3D12Device::CreateDepthStencilView(ID3D12Resource *pResource, const D3D12_DEPTH_STENCIL_VIEW_DESC *pDesc, D3D12_CPU_DESCRIPTOR_HANDLE DestDescriptor) { - return m_pDevice->CreateDepthStencilView(pResource, pDesc, DestDescriptor); + return m_pDevice->CreateDepthStencilView(Unwrap(pResource), pDesc, DestDescriptor); } void WrappedID3D12Device::CreateSampler(const D3D12_SAMPLER_DESC *pDesc, @@ -397,6 +516,45 @@ void WrappedID3D12Device::CreateSampler(const D3D12_SAMPLER_DESC *pDesc, return m_pDevice->CreateSampler(pDesc, DestDescriptor); } +bool WrappedID3D12Device::Serialise_CreateCommittedResource( + const D3D12_HEAP_PROPERTIES *pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, + const D3D12_RESOURCE_DESC *pResourceDesc, D3D12_RESOURCE_STATES InitialResourceState, + const D3D12_CLEAR_VALUE *pOptimizedClearValue, REFIID riidResource, void **ppvResource) +{ + SERIALISE_ELEMENT(D3D12_HEAP_PROPERTIES, props, *pHeapProperties); + SERIALISE_ELEMENT(D3D12_HEAP_FLAGS, flags, HeapFlags); + SERIALISE_ELEMENT(D3D12_RESOURCE_DESC, desc, *pResourceDesc); + SERIALISE_ELEMENT(D3D12_RESOURCE_STATES, state, InitialResourceState); + + SERIALISE_ELEMENT(bool, HasClearValue, pOptimizedClearValue != NULL); + SERIALISE_ELEMENT_OPT(D3D12_CLEAR_VALUE, clearVal, *pOptimizedClearValue, HasClearValue); + + SERIALISE_ELEMENT(IID, guid, riidResource); + SERIALISE_ELEMENT(ResourceId, Res, ((WrappedID3D12Resource *)*ppvResource)->GetResourceID()); + + if(m_State == READING) + { + pOptimizedClearValue = HasClearValue ? &clearVal : NULL; + + ID3D12Resource *ret = NULL; + HRESULT hr = m_pDevice->CreateCommittedResource(&props, flags, &desc, state, + pOptimizedClearValue, guid, (void **)&ret); + + if(FAILED(hr)) + { + RDCERR("Failed on resource serialise-creation, HRESULT: 0x%08x", hr); + } + else + { + ret = new WrappedID3D12Resource(ret, this); + + GetResourceManager()->AddLiveResource(Res, ret); + } + } + + return true; +} + HRESULT WrappedID3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES *pHeapProperties, D3D12_HEAP_FLAGS HeapFlags, const D3D12_RESOURCE_DESC *pResourceDesc, @@ -404,9 +562,39 @@ HRESULT WrappedID3D12Device::CreateCommittedResource(const D3D12_HEAP_PROPERTIES const D3D12_CLEAR_VALUE *pOptimizedClearValue, REFIID riidResource, void **ppvResource) { - return m_pDevice->CreateCommittedResource(pHeapProperties, HeapFlags, pResourceDesc, - InitialResourceState, pOptimizedClearValue, - riidResource, ppvResource); + if(ppvResource == NULL) + return m_pDevice->CreateCommittedResource(pHeapProperties, HeapFlags, pResourceDesc, + InitialResourceState, pOptimizedClearValue, + riidResource, NULL); + + if(riidResource != __uuidof(ID3D12Resource)) + return E_NOINTERFACE; + + ID3D12Resource *real = NULL; + HRESULT ret = m_pDevice->CreateCommittedResource(pHeapProperties, HeapFlags, pResourceDesc, + InitialResourceState, pOptimizedClearValue, + riidResource, (void **)&real); + + if(SUCCEEDED(ret)) + { + SCOPED_LOCK(m_D3DLock); + + WrappedID3D12Resource *wrapped = new WrappedID3D12Resource(real, this); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(CREATE_COMMITTED_RESOURCE); + Serialise_CreateCommittedResource(pHeapProperties, HeapFlags, pResourceDesc, + InitialResourceState, pOptimizedClearValue, riidResource, + (void **)&wrapped); + + m_DeviceRecord->AddChunk(scope.Get()); + } + + *ppvResource = (ID3D12Resource *)wrapped; + } + + return ret; } HRESULT WrappedID3D12Device::CreateHeap(const D3D12_HEAP_DESC *pDesc, REFIID riid, void **ppvHeap) @@ -420,7 +608,7 @@ HRESULT WrappedID3D12Device::CreatePlacedResource(ID3D12Heap *pHeap, UINT64 Heap const D3D12_CLEAR_VALUE *pOptimizedClearValue, REFIID riid, void **ppvResource) { - return m_pDevice->CreatePlacedResource(pHeap, HeapOffset, pDesc, InitialState, + return m_pDevice->CreatePlacedResource(Unwrap(pHeap), HeapOffset, pDesc, InitialState, pOptimizedClearValue, riid, ppvResource); } @@ -433,10 +621,64 @@ HRESULT WrappedID3D12Device::CreateReservedResource(const D3D12_RESOURCE_DESC *p ppvResource); } +bool WrappedID3D12Device::Serialise_CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS Flags, + REFIID riid, void **ppFence) +{ + SERIALISE_ELEMENT(UINT64, val, InitialValue); + SERIALISE_ELEMENT(D3D12_FENCE_FLAGS, flags, Flags); + SERIALISE_ELEMENT(IID, guid, riid); + SERIALISE_ELEMENT(ResourceId, Fence, ((WrappedID3D12Fence *)*ppFence)->GetResourceID()); + + if(m_State == READING) + { + ID3D12Fence *ret = NULL; + HRESULT hr = m_pDevice->CreateFence(val, flags, guid, (void **)&ret); + + if(FAILED(hr)) + { + RDCERR("Failed on resource serialise-creation, HRESULT: 0x%08x", hr); + } + else + { + ret = new WrappedID3D12Fence(ret, this); + + GetResourceManager()->AddLiveResource(Fence, ret); + } + } + + return true; +} + HRESULT WrappedID3D12Device::CreateFence(UINT64 InitialValue, D3D12_FENCE_FLAGS Flags, REFIID riid, void **ppFence) { - return m_pDevice->CreateFence(InitialValue, Flags, riid, ppFence); + if(ppFence == NULL) + return m_pDevice->CreateFence(InitialValue, Flags, riid, NULL); + + if(riid != __uuidof(ID3D12Fence)) + return E_NOINTERFACE; + + ID3D12Fence *real = NULL; + HRESULT ret = m_pDevice->CreateFence(InitialValue, Flags, riid, (void **)&real); + + if(SUCCEEDED(ret)) + { + SCOPED_LOCK(m_D3DLock); + + WrappedID3D12Fence *wrapped = new WrappedID3D12Fence(real, this); + + if(m_State >= WRITING) + { + SCOPED_SERIALISE_CONTEXT(CREATE_FENCE); + Serialise_CreateFence(InitialValue, Flags, riid, (void **)&wrapped); + + m_DeviceRecord->AddChunk(scope.Get()); + } + + *ppFence = (ID3D12Fence *)wrapped; + } + + return ret; } HRESULT WrappedID3D12Device::CreateQueryHeap(const D3D12_QUERY_HEAP_DESC *pDesc, REFIID riid, @@ -449,14 +691,14 @@ HRESULT WrappedID3D12Device::CreateCommandSignature(const D3D12_COMMAND_SIGNATUR ID3D12RootSignature *pRootSignature, REFIID riid, void **ppvCommandSignature) { - return m_pDevice->CreateCommandSignature(pDesc, pRootSignature, riid, ppvCommandSignature); + return m_pDevice->CreateCommandSignature(pDesc, Unwrap(pRootSignature), riid, ppvCommandSignature); } HRESULT WrappedID3D12Device::CreateSharedHandle(ID3D12DeviceChild *pObject, const SECURITY_ATTRIBUTES *pAttributes, DWORD Access, LPCWSTR Name, HANDLE *pHandle) { - return m_pDevice->CreateSharedHandle(pObject, pAttributes, Access, Name, pHandle); + return m_pDevice->CreateSharedHandle(Unwrap(pObject), pAttributes, Access, Name, pHandle); } void WrappedID3D12Device::CopyDescriptors( @@ -492,11 +734,13 @@ HRESULT WrappedID3D12Device::OpenSharedHandleByName(LPCWSTR Name, DWORD Access, HRESULT WrappedID3D12Device::MakeResident(UINT NumObjects, ID3D12Pageable *const *ppObjects) { + RDCUNIMPLEMENTED("MakeResident"); // need to unwrap objects return m_pDevice->MakeResident(NumObjects, ppObjects); } HRESULT WrappedID3D12Device::Evict(UINT NumObjects, ID3D12Pageable *const *ppObjects) { + RDCUNIMPLEMENTED("Evict"); // need to unwrap objects return m_pDevice->Evict(NumObjects, ppObjects); } diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index d536045c9..dc07aa8fc 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -75,6 +75,28 @@ TrackedResource *GetTracked(ID3D12DeviceChild *ptr) return NULL; } +ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr) +{ + if(ptr == NULL) + return NULL; + +#undef D3D12_TYPE_MACRO +#define D3D12_TYPE_MACRO(iface) \ + if(UnwrapHelper::IsAlloc(ptr)) \ + return (ID3D12DeviceChild *)GetWrapped((iface *)ptr)->GetReal(); + + ALL_D3D12_TYPES; + + if(WrappedID3D12GraphicsCommandList::IsAlloc(ptr)) + return (ID3D12DeviceChild *)(((WrappedID3D12GraphicsCommandList *)ptr)->GetReal()); + if(WrappedID3D12CommandQueue::IsAlloc(ptr)) + return (ID3D12DeviceChild *)(((WrappedID3D12CommandQueue *)ptr)->GetReal()); + + RDCERR("Unknown type of ptr 0x%p", ptr); + + return NULL; +} + template <> ResourceId GetResID(ID3D12DeviceChild *ptr) { diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index 9a550220d..e30722a1b 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -546,7 +546,7 @@ ALL_D3D12_TYPES; ResourceType IdentifyTypeByPtr(ID3D12DeviceChild *ptr); -#define WRAPPING_DEBUG 1 +#define WRAPPING_DEBUG 0 template typename UnwrapHelper::Outer *GetWrapped(iface *obj) @@ -559,7 +559,7 @@ typename UnwrapHelper::Outer *GetWrapped(iface *obj) #if WRAPPING_DEBUG if(obj != NULL && !wrapped->IsAlloc(wrapped)) { - RDCWARN("Trying to unwrap invalid type"); + RDCERR("Trying to unwrap invalid type"); return NULL; } #endif @@ -578,12 +578,7 @@ iface *Unwrap(iface *obj) if(obj == NULL) return NULL; - auto wrapped = GetWrapped(obj); - - if(wrapped) - return wrapped->GetReal(); - - return NULL; + return GetWrapped(obj)->GetReal(); } template @@ -592,12 +587,7 @@ ResourceId GetResID(iface *obj) if(obj == NULL) return ResourceId(); - auto wrapped = GetWrapped(obj); - - if(wrapped) - return wrapped->GetResourceID(); - - return ResourceId(); + return GetWrapped(obj)->GetResourceID(); } template @@ -606,16 +596,13 @@ D3D12ResourceRecord *GetRecord(iface *obj) if(obj == NULL) return NULL; - auto wrapped = GetWrapped(obj); - - if(wrapped) - return wrapped->GetResourceRecord(); - - return NULL; + return GetWrapped(obj)->GetResourceRecord(); } // specialisations that use the GetTracked() function to fetch the ID template <> ResourceId GetResID(ID3D12DeviceChild *ptr); template <> +ID3D12DeviceChild *Unwrap(ID3D12DeviceChild *ptr); +template <> D3D12ResourceRecord *GetRecord(ID3D12DeviceChild *ptr);