diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index f7350852e..4f2596034 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -248,6 +248,11 @@ bool WrappedID3D12GraphicsCommandList::Serialise_Reset(ID3D12CommandAllocator *p m_Cmd->m_BakedCmdListInfo[CommandList].drawCount = 0; m_Cmd->m_BakedCmdListInfo[CommandList].drawStack.push_back(draw); + + // reset state + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + state.m_ResourceManager = GetResourceManager(); + state.pipe = GetResID(pInitialState); } } @@ -528,6 +533,14 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetViewports(UINT NumViewport else if(m_State == READING) { GetList(CommandList)->RSSetViewports(num, views); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.views.size() < num) + state.views.resize(num); + + for(UINT i = 0; i < num; i++) + state.views[i] = views[i]; } SAFE_DELETE_ARRAY(views); @@ -575,6 +588,14 @@ bool WrappedID3D12GraphicsCommandList::Serialise_RSSetScissorRects(UINT NumRects else if(m_State == READING) { GetList(CommandList)->RSSetScissorRects(num, rects); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.scissors.size() < num) + state.scissors.resize(num); + + for(UINT i = 0; i < num; i++) + state.scissors[i] = rects[i]; } SAFE_DELETE_ARRAY(rects); @@ -621,6 +642,8 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetBlendFactor(const FLOAT Bl else if(m_State == READING) { GetList(CommandList)->OMSetBlendFactor(factor); + + memcpy(m_Cmd->m_BakedCmdListInfo[CommandList].state.blendFactor, factor, sizeof(factor)); } return true; @@ -659,6 +682,8 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetStencilRef(UINT StencilRef else if(m_State == READING) { GetList(CommandList)->OMSetStencilRef(ref); + + m_Cmd->m_BakedCmdListInfo[CommandList].state.stencilRef = ref; } return true; @@ -720,6 +745,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetDescriptorHeaps( heaps[i] = Unwrap(GetResourceManager()->GetLiveAs(DescriptorHeaps[i])); GetList(CommandList)->SetDescriptorHeaps((UINT)heaps.size(), &heaps[0]); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + state.heaps.resize(heaps.size()); + for(size_t i = 0; i < heaps.size(); i++) + state.heaps[i] = GetResourceManager()->GetLiveID(DescriptorHeaps[i]); } return true; @@ -783,21 +814,24 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetIndexBuffer(const D3D12_IN { ID3D12GraphicsCommandList *list = GetList(CommandList); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + if(HasView) { list->IASetIndexBuffer(&view); - m_Cmd->m_BakedCmdListInfo[CommandList].state.ibuffer = - WrappedID3D12Resource::GetResIDFromAddr(view.BufferLocation); - m_Cmd->m_BakedCmdListInfo[CommandList].state.idxWidth = - (view.Format == DXGI_FORMAT_R32_UINT ? 4 : 2); + WrappedID3D12Resource::GetResIDFromAddr(view.BufferLocation, state.ibuffer.buf, + state.ibuffer.offs); + state.ibuffer.bytewidth = (view.Format == DXGI_FORMAT_R32_UINT ? 4 : 2); + state.ibuffer.size = view.SizeInBytes; } else { list->IASetIndexBuffer(NULL); - m_Cmd->m_BakedCmdListInfo[CommandList].state.ibuffer = ResourceId(); - m_Cmd->m_BakedCmdListInfo[CommandList].state.idxWidth = 2; + state.ibuffer.buf = ResourceId(); + state.ibuffer.offs = 0; + state.ibuffer.bytewidth = 2; } } @@ -855,12 +889,19 @@ bool WrappedID3D12GraphicsCommandList::Serialise_IASetVertexBuffers( { GetList(CommandList)->IASetVertexBuffers(start, num, views); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.vbuffers.size() < start + num) - m_Cmd->m_BakedCmdListInfo[CommandList].state.vbuffers.resize(start + num); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.vbuffers.size() < start + num) + state.vbuffers.resize(start + num); for(UINT i = 0; i < num; i++) - m_Cmd->m_BakedCmdListInfo[CommandList].state.vbuffers[start + i] = - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation); + { + WrappedID3D12Resource::GetResIDFromAddr( + views[i].BufferLocation, state.vbuffers[start + i].buf, state.vbuffers[start + i].offs); + + state.vbuffers[start + i].stride = views[i].StrideInBytes; + state.vbuffers[start + i].size = views[i].SizeInBytes; + } } SAFE_DELETE_ARRAY(views); @@ -922,15 +963,21 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SOSetTargets( { GetList(CommandList)->SOSetTargets(start, num, views); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.sotargets.size() < start + num) - m_Cmd->m_BakedCmdListInfo[CommandList].state.sotargets.resize(start + num); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.streamouts.size() < start + num) + state.streamouts.resize(start + num); for(UINT i = 0; i < num; i++) { - m_Cmd->m_BakedCmdListInfo[CommandList].state.sotargets[start + i] = - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation); - m_Cmd->m_BakedCmdListInfo[CommandList].state.socounters[start + i] = - WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferFilledSizeLocation); + D3D12RenderState::StreamOut &so = state.streamouts[start + i]; + + WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferLocation, so.buf, so.offs); + + WrappedID3D12Resource::GetResIDFromAddr(views[i].BufferFilledSizeLocation, so.countbuf, + so.countoffs); + + so.size = views[i].SizeInBytes; } } @@ -978,6 +1025,8 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetPipelineState(ID3D12Pipeline { pPipelineState = GetResourceManager()->GetLiveAs(pipe); GetList(CommandList)->SetPipelineState(Unwrap(pPipelineState)); + + m_Cmd->m_BakedCmdListInfo[CommandList].state.pipe = GetResID(pPipelineState); } return true; @@ -1067,41 +1116,16 @@ bool WrappedID3D12GraphicsCommandList::Serialise_OMSetRenderTargets( ->OMSetRenderTargets(num, rtHandles, singlehandle ? TRUE : FALSE, dsv.heap != ResourceId() ? &dsvHandle : NULL); - RDCEraseEl(m_Cmd->m_BakedCmdListInfo[CommandList].state.dsv); - RDCEraseEl(m_Cmd->m_BakedCmdListInfo[CommandList].state.rts); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - if(singlehandle) - { - const D3D12Descriptor *descs = DescriptorFromPortableHandle(GetResourceManager(), rts[0]); + state.rts.resize(numHandles); - for(UINT i = 0; i < num; i++) - { - RDCASSERT(descs[i].GetType() == D3D12Descriptor::TypeRTV); - m_Cmd->m_BakedCmdListInfo[CommandList].state.rts[i] = GetResID(descs[i].nonsamp.resource); - } - } - else - { - for(UINT i = 0; i < num; i++) - { - WrappedID3D12DescriptorHeap *heap = - GetResourceManager()->GetLiveAs(rts[0].heap); + for(UINT i = 0; i < numHandles; i++) + state.rts[i] = rts[i]; - const D3D12Descriptor &desc = heap->GetDescriptors()[rts[i].index]; + state.rtSingle = singlehandle; - RDCASSERT(desc.GetType() == D3D12Descriptor::TypeRTV); - m_Cmd->m_BakedCmdListInfo[CommandList].state.rts[i] = GetResID(desc.nonsamp.resource); - } - } - - if(dsv.heap != ResourceId()) - { - const D3D12Descriptor *desc = DescriptorFromPortableHandle(GetResourceManager(), dsv); - - RDCASSERT(desc->GetType() == D3D12Descriptor::TypeDSV); - - m_Cmd->m_BakedCmdListInfo[CommandList].state.dsv = GetResID(desc->nonsamp.resource); - } + state.dsv = dsv; SAFE_DELETE_ARRAY(rtHandles); } @@ -1186,9 +1210,11 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootSignature( GetList(CommandList)->SetComputeRootSignature(Unwrap(pRootSignature)); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.rootsig != GetResID(pRootSignature)) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.clear(); - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.rootsig = GetResID(pRootSignature); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.compute.rootsig != GetResID(pRootSignature)) + state.compute.sigelems.clear(); + state.compute.rootsig = GetResID(pRootSignature); } return true; @@ -1245,13 +1271,15 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootDescriptorTable( ->SetComputeRootDescriptorTable( idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); WrappedID3D12DescriptorHeap *heap = GetResourceManager()->GetLiveAs(Descriptor.heap); - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems[idx] = + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); } @@ -1332,6 +1360,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstant( else if(m_State == READING) { GetList(CommandList)->SetComputeRoot32BitConstant(idx, val, offs); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); + + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(offs, val); } return true; @@ -1381,6 +1416,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRoot32BitConstants( else if(m_State == READING) { GetList(CommandList)->SetComputeRoot32BitConstants(idx, num, data, offs); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); + + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(num, data, offs); } SAFE_DELETE_ARRAY(data); @@ -1445,10 +1487,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootConstantBufferVie GetList(CommandList)->SetComputeRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems[idx] = + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); + + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); } @@ -1513,10 +1557,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootShaderResourceVie GetList(CommandList)->SetComputeRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems[idx] = + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); + + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); } @@ -1582,10 +1628,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetComputeRootUnorderedAccessVi GetList(CommandList) ->SetComputeRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems[idx] = + if(state.compute.sigelems.size() < idx + 1) + state.compute.sigelems.resize(idx + 1); + + state.compute.sigelems[idx] = D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); } @@ -1649,9 +1697,11 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootSignature( GetList(CommandList)->SetGraphicsRootSignature(Unwrap(pRootSignature)); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.rootsig != GetResID(pRootSignature)) - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.sigelems.clear(); - m_Cmd->m_BakedCmdListInfo[CommandList].state.compute.rootsig = GetResID(pRootSignature); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.graphics.rootsig != GetResID(pRootSignature)) + state.graphics.sigelems.clear(); + state.graphics.rootsig = GetResID(pRootSignature); } return true; @@ -1708,13 +1758,15 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootDescriptorTable( ->SetGraphicsRootDescriptorTable( idx, GPUHandleFromPortableHandle(GetResourceManager(), Descriptor)); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); WrappedID3D12DescriptorHeap *heap = GetResourceManager()->GetLiveAs(Descriptor.heap); - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems[idx] = + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(eRootTable, GetResID(heap), (UINT64)Descriptor.index); } @@ -1795,6 +1847,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstant( else if(m_State == READING) { GetList(CommandList)->SetGraphicsRoot32BitConstant(idx, val, offs); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); + + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(offs, val); } return true; @@ -1844,6 +1903,13 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRoot32BitConstants( else if(m_State == READING) { GetList(CommandList)->SetGraphicsRoot32BitConstants(idx, num, data, offs); + + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; + + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); + + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(num, data, offs); } SAFE_DELETE_ARRAY(data); @@ -1909,10 +1975,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootConstantBufferVi GetList(CommandList) ->SetGraphicsRootConstantBufferView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems[idx] = + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); + + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(eRootCBV, GetResID(pRes), byteOffset); } @@ -1978,10 +2046,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootShaderResourceVi GetList(CommandList) ->SetGraphicsRootShaderResourceView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems[idx] = + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); + + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(eRootSRV, GetResID(pRes), byteOffset); } @@ -2047,10 +2117,12 @@ bool WrappedID3D12GraphicsCommandList::Serialise_SetGraphicsRootUnorderedAccessV GetList(CommandList) ->SetGraphicsRootUnorderedAccessView(idx, pRes->GetGPUVirtualAddress() + byteOffset); - if(m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.size() < idx + 1) - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems.resize(idx + 1); + D3D12RenderState &state = m_Cmd->m_BakedCmdListInfo[CommandList].state; - m_Cmd->m_BakedCmdListInfo[CommandList].state.graphics.sigelems[idx] = + if(state.graphics.sigelems.size() < idx + 1) + state.graphics.sigelems.resize(idx + 1); + + state.graphics.sigelems[idx] = D3D12RenderState::SignatureElement(eRootUAV, GetResID(pRes), byteOffset); } @@ -2980,7 +3052,7 @@ void WrappedID3D12GraphicsCommandList::PatchedExecuteIndirect(ID3D12GraphicsComm if(cmdInfo.state.vbuffers.size() < arg.VertexBuffer.Slot + 1) cmdInfo.state.vbuffers.resize(arg.VertexBuffer.Slot + 1); - cmdInfo.state.vbuffers[arg.VertexBuffer.Slot] = id; + cmdInfo.state.vbuffers[arg.VertexBuffer.Slot].buf = id; } else if(executing) { @@ -3032,8 +3104,8 @@ void WrappedID3D12GraphicsCommandList::PatchedExecuteIndirect(ID3D12GraphicsComm if(m_State == READING) { - cmdInfo.state.ibuffer = id; - cmdInfo.state.idxWidth = (srcIB->Format == DXGI_FORMAT_R32_UINT ? 4 : 2); + cmdInfo.state.ibuffer.buf = id; + cmdInfo.state.ibuffer.bytewidth = (srcIB->Format == DXGI_FORMAT_R32_UINT ? 4 : 2); } else if(executing) { diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 1d60ee617..eeafbdc6c 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -849,13 +849,13 @@ void D3D12CommandData::AddUsage(D3D12DrawcallTreeNode &drawNode) { FetchDrawcall &d = drawNode.draw; - const BakedCmdListInfo::CmdListState &state = m_BakedCmdListInfo[m_LastCmdListID].state; + const D3D12RenderState &state = m_BakedCmdListInfo[m_LastCmdListID].state; uint32_t e = d.eventID; if((d.flags & (eDraw_Drawcall | eDraw_Dispatch)) == 0) return; - const BakedCmdListInfo::CmdListState::RootSignature *rootdata = NULL; + const D3D12RenderState::RootSignature *rootdata = NULL; if((d.flags & eDraw_Dispatch) && state.compute.rootsig != ResourceId()) { @@ -865,40 +865,38 @@ void D3D12CommandData::AddUsage(D3D12DrawcallTreeNode &drawNode) { rootdata = &state.graphics; - if(d.flags & eDraw_UseIBuffer && state.ibuffer != ResourceId()) + if(d.flags & eDraw_UseIBuffer && state.ibuffer.buf != ResourceId()) drawNode.resourceUsage.push_back( - std::make_pair(state.ibuffer, EventUsage(e, eUsage_IndexBuffer))); + std::make_pair(state.ibuffer.buf, EventUsage(e, eUsage_IndexBuffer))); for(size_t i = 0; i < state.vbuffers.size(); i++) { - if(state.vbuffers[i] != ResourceId()) + if(state.vbuffers[i].buf != ResourceId()) drawNode.resourceUsage.push_back( - std::make_pair(state.vbuffers[i], EventUsage(e, eUsage_VertexBuffer))); + std::make_pair(state.vbuffers[i].buf, EventUsage(e, eUsage_VertexBuffer))); } - for(size_t i = 0; i < state.sotargets.size(); i++) + for(size_t i = 0; i < state.streamouts.size(); i++) { - if(state.sotargets[i] != ResourceId()) - drawNode.resourceUsage.push_back(std::make_pair(state.sotargets[i], EventUsage(e, eUsage_SO))); - } - - for(size_t i = 0; i < state.socounters.size(); i++) - { - if(state.socounters[i] != ResourceId()) + if(state.streamouts[i].buf != ResourceId()) drawNode.resourceUsage.push_back( - std::make_pair(state.socounters[i], EventUsage(e, eUsage_SO))); - } - - for(size_t i = 0; i < ARRAY_COUNT(state.rts); i++) - { - if(state.rts[i] != ResourceId()) + std::make_pair(state.streamouts[i].buf, EventUsage(e, eUsage_SO))); + if(state.streamouts[i].countbuf != ResourceId()) drawNode.resourceUsage.push_back( - std::make_pair(state.rts[i], EventUsage(e, eUsage_ColourTarget))); + std::make_pair(state.streamouts[i].countbuf, EventUsage(e, eUsage_SO))); } - if(state.dsv != ResourceId()) - drawNode.resourceUsage.push_back( - std::make_pair(state.dsv, EventUsage(e, eUsage_DepthStencilTarget))); + vector rts = state.GetRTVIDs(); + + for(size_t i = 0; i < rts.size(); i++) + { + if(rts[i] != ResourceId()) + drawNode.resourceUsage.push_back(std::make_pair(rts[i], EventUsage(e, eUsage_ColourTarget))); + } + + ResourceId id = state.GetDSVID(); + if(id != ResourceId()) + drawNode.resourceUsage.push_back(std::make_pair(id, EventUsage(e, eUsage_DepthStencilTarget))); } if(rootdata) @@ -1026,10 +1024,19 @@ void D3D12CommandData::AddDrawcall(const FetchDrawcall &d, bool hasEvents) if(m_LastCmdListID != ResourceId()) { draw.topology = MakePrimitiveTopology(m_BakedCmdListInfo[m_LastCmdListID].state.topo); - draw.indexByteWidth = m_BakedCmdListInfo[m_LastCmdListID].state.idxWidth; + draw.indexByteWidth = m_BakedCmdListInfo[m_LastCmdListID].state.ibuffer.bytewidth; - memcpy(draw.outputs, m_BakedCmdListInfo[m_LastCmdListID].state.rts, sizeof(draw.outputs)); - draw.depthOut = m_BakedCmdListInfo[m_LastCmdListID].state.dsv; + vector rts = m_BakedCmdListInfo[m_LastCmdListID].state.GetRTVIDs(); + + for(size_t i = 0; i < ARRAY_COUNT(draw.outputs); i++) + { + if(i < rts.size()) + draw.outputs[i] = rts[i]; + else + draw.outputs[i] = ResourceId(); + } + + draw.depthOut = m_BakedCmdListInfo[m_LastCmdListID].state.GetDSVID(); } if(m_LastCmdListID != ResourceId()) diff --git a/renderdoc/driver/d3d12/d3d12_commands.h b/renderdoc/driver/d3d12/d3d12_commands.h index e9123e7ff..13871259f 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.h +++ b/renderdoc/driver/d3d12/d3d12_commands.h @@ -147,26 +147,7 @@ struct BakedCmdListInfo vector > resourceUsage; - struct CmdListState - { - D3D12_PRIMITIVE_TOPOLOGY topo; - - uint32_t idxWidth; - ResourceId ibuffer; - vector vbuffers; - - vector sotargets, socounters; - - struct RootSignature - { - ResourceId rootsig; - - vector sigelems; - } compute, graphics; - - ResourceId rts[8]; - ResourceId dsv; - } state; + D3D12RenderState state; vector barriers; diff --git a/renderdoc/driver/d3d12/d3d12_state.cpp b/renderdoc/driver/d3d12/d3d12_state.cpp index 517fe94f4..790529067 100644 --- a/renderdoc/driver/d3d12/d3d12_state.cpp +++ b/renderdoc/driver/d3d12/d3d12_state.cpp @@ -81,6 +81,51 @@ D3D12RenderState &D3D12RenderState::operator=(const D3D12RenderState &o) return *this; } +vector D3D12RenderState::GetRTVIDs() const +{ + vector ret; + + if(rtSingle) + { + const D3D12Descriptor *descs = DescriptorFromPortableHandle(GetResourceManager(), rts[0]); + + for(UINT i = 0; i < rts.size(); i++) + { + RDCASSERT(descs[i].GetType() == D3D12Descriptor::TypeRTV); + ret.push_back(GetResID(descs[i].nonsamp.resource)); + } + } + else + { + for(UINT i = 0; i < rts.size(); i++) + { + WrappedID3D12DescriptorHeap *heap = + GetResourceManager()->GetLiveAs(rts[0].heap); + + const D3D12Descriptor &desc = heap->GetDescriptors()[rts[i].index]; + + RDCASSERT(desc.GetType() == D3D12Descriptor::TypeRTV); + ret.push_back(GetResID(desc.nonsamp.resource)); + } + } + + return ret; +} + +ResourceId D3D12RenderState::GetDSVID() const +{ + if(dsv.heap != ResourceId()) + { + const D3D12Descriptor *desc = DescriptorFromPortableHandle(GetResourceManager(), dsv); + + RDCASSERT(desc->GetType() == D3D12Descriptor::TypeDSV); + + return GetResID(desc->nonsamp.resource); + } + + return ResourceId(); +} + void D3D12RenderState::ApplyState(ID3D12GraphicsCommandList *cmd) { if(pipe != ResourceId()) diff --git a/renderdoc/driver/d3d12/d3d12_state.h b/renderdoc/driver/d3d12/d3d12_state.h index 5ea0e3130..7d99c546c 100644 --- a/renderdoc/driver/d3d12/d3d12_state.h +++ b/renderdoc/driver/d3d12/d3d12_state.h @@ -54,6 +54,9 @@ struct D3D12RenderState bool rtSingle; PortableHandle dsv; + vector GetRTVIDs() const; + ResourceId GetDSVID() const; + struct SignatureElement { SignatureElement() : type(eRootUnknown), offset(0) {} @@ -190,6 +193,6 @@ struct D3D12RenderState }; vector vbuffers; - D3D12ResourceManager *GetResourceManager() { return m_ResourceManager; } + D3D12ResourceManager *GetResourceManager() const { return m_ResourceManager; } D3D12ResourceManager *m_ResourceManager; };