D3D12: Implement ClearRenderTarget by tracking bound RTV handles
- Add m_boundRenderTargets and m_boundDepthStencil members to D3D12CommandList - SetRenderTargetsHandle now saves bound RTV handles for later clear operations - ClearRenderTargetView(ID3D12Resource*, ...) clears all bound render targets - Reset() clears bound targets list - Follows D3D12 best practice: RTV is bound via OMSetRenderTargets, then cleared
This commit is contained in:
@@ -118,6 +118,10 @@ private:
|
||||
ID3D12PipelineState* m_currentPipelineState;
|
||||
ID3D12RootSignature* m_currentRootSignature;
|
||||
ID3D12DescriptorHeap* m_currentDescriptorHeap;
|
||||
|
||||
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> m_boundRenderTargets;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE m_boundDepthStencil;
|
||||
bool m_depthStencilBound = false;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user