diff --git a/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h b/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h index 6db299ee..e5cac101 100644 --- a/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h +++ b/engine/include/XCEngine/RHI/D3D12/D3D12CommandList.h @@ -118,6 +118,10 @@ private: ID3D12PipelineState* m_currentPipelineState; ID3D12RootSignature* m_currentRootSignature; ID3D12DescriptorHeap* m_currentDescriptorHeap; + + std::vector m_boundRenderTargets; + D3D12_CPU_DESCRIPTOR_HANDLE m_boundDepthStencil; + bool m_depthStencilBound = false; }; } // namespace RHI diff --git a/engine/src/RHI/D3D12/D3D12CommandList.cpp b/engine/src/RHI/D3D12/D3D12CommandList.cpp index 61401d64..35a9f72c 100644 --- a/engine/src/RHI/D3D12/D3D12CommandList.cpp +++ b/engine/src/RHI/D3D12/D3D12CommandList.cpp @@ -65,6 +65,8 @@ void D3D12CommandList::Reset() { m_currentDescriptorHeap = nullptr; m_resourceStateMap.clear(); m_trackedResources.clear(); + m_boundRenderTargets.clear(); + m_depthStencilBound = false; } void D3D12CommandList::Close() { @@ -209,6 +211,18 @@ void D3D12CommandList::SetRenderTargetsInternal(uint32_t count, ID3D12Resource** void D3D12CommandList::SetRenderTargetsHandle(uint32_t count, const D3D12_CPU_DESCRIPTOR_HANDLE* renderTargetHandles, const D3D12_CPU_DESCRIPTOR_HANDLE* depthStencilHandle) { m_commandList->OMSetRenderTargets(count, renderTargetHandles, FALSE, depthStencilHandle); + + m_boundRenderTargets.clear(); + for (uint32_t i = 0; i < count; ++i) { + m_boundRenderTargets.push_back(renderTargetHandles[i]); + } + + if (depthStencilHandle) { + m_boundDepthStencil = *depthStencilHandle; + m_depthStencilBound = true; + } else { + m_depthStencilBound = false; + } } void D3D12CommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) { @@ -324,6 +338,9 @@ void D3D12CommandList::DrawIndexedInstancedIndirectInternal(ID3D12Resource* argB } void D3D12CommandList::ClearRenderTargetView(ID3D12Resource* renderTarget, const float color[4], uint32_t rectCount, const D3D12_RECT* rects) { + for (const auto& rtvHandle : m_boundRenderTargets) { + m_commandList->ClearRenderTargetView(rtvHandle, color, rectCount, rects); + } } void D3D12CommandList::ClearRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE renderTargetHandle, const float color[4], uint32_t rectCount, const D3D12_RECT* rects) {