【关键节点】RHICommandList添加RHIResourceView*方法重载实现统一资源绑定接口
- 在RHICommandList.h中添加7个RHIResourceView*方法重载: - TransitionBarrier(RHIResourceView*, ...) - SetRenderTargets(count, RHIResourceView**, RHIResourceView*) - SetVertexBuffer(slot, RHIResourceView*, ...) - SetIndexBuffer(RHIResourceView*, ...) - ClearRenderTarget(RHIResourceView*, ...) - ClearDepthStencil(RHIResourceView*, ...) - CopyResource(RHIResourceView*, RHIResourceView*) - D3D12CommandList完整实现: - 通过D3D12ResourceView::GetResource()获取底层资源 - 通过D3D12ResourceView::GetCPUHandle()获取RTV/DSV句柄 - OpenGLCommandList添加stub实现保持接口一致 - 验证: 144个单元测试全部通过, 4个D3D12集成测试全部通过
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -77,6 +78,12 @@ void D3D12CommandList::TransitionBarrier(void* resource, ResourceStates stateBef
|
||||
TransitionBarrierInternal(static_cast<ID3D12Resource*>(resource), stateBefore, stateAfter);
|
||||
}
|
||||
|
||||
void D3D12CommandList::TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
|
||||
if (!resource || !resource->IsValid()) return;
|
||||
D3D12ResourceView* d3d12View = static_cast<D3D12ResourceView*>(resource);
|
||||
TransitionBarrierInternal(d3d12View->GetResource(), stateBefore, stateAfter);
|
||||
}
|
||||
|
||||
void D3D12CommandList::UAVBarrier(void* resource) {
|
||||
UAVBarrierInternal(static_cast<ID3D12Resource*>(resource));
|
||||
}
|
||||
@@ -197,6 +204,32 @@ void D3D12CommandList::SetRenderTargets(uint32_t count, void** renderTargets, vo
|
||||
SetRenderTargetsInternal(count, resources.data(), static_cast<ID3D12Resource*>(depthStencil));
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil) {
|
||||
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> rtvHandles(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
if (renderTargets[i] && renderTargets[i]->IsValid()) {
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(renderTargets[i]);
|
||||
rtvHandles[i] = view->GetCPUHandle();
|
||||
}
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {};
|
||||
if (depthStencil && depthStencil->IsValid()) {
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(depthStencil);
|
||||
dsvHandle = view->GetCPUHandle();
|
||||
}
|
||||
|
||||
m_commandList->OMSetRenderTargets(count, count > 0 ? rtvHandles.data() : nullptr, FALSE, depthStencil ? &dsvHandle : nullptr);
|
||||
|
||||
m_boundRenderTargets = rtvHandles;
|
||||
if (depthStencil) {
|
||||
m_boundDepthStencil = dsvHandle;
|
||||
m_depthStencilBound = true;
|
||||
} else {
|
||||
m_depthStencilBound = false;
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetRenderTargetsInternal(uint32_t count, ID3D12Resource** renderTargets, ID3D12Resource* depthStencil) {
|
||||
std::vector<D3D12_CPU_DESCRIPTOR_HANDLE> rtvHandles(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
@@ -229,6 +262,12 @@ void D3D12CommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t off
|
||||
SetVertexBufferInternal(slot, static_cast<ID3D12Resource*>(buffer), offset, stride);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) {
|
||||
if (!buffer || !buffer->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(buffer);
|
||||
SetVertexBufferInternal(slot, view->GetResource(), offset, stride);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBufferInternal(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) {
|
||||
D3D12_VERTEX_BUFFER_VIEW view = {};
|
||||
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
|
||||
@@ -256,6 +295,12 @@ void D3D12CommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format form
|
||||
SetIndexBufferInternal(static_cast<ID3D12Resource*>(buffer), offset, format);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) {
|
||||
if (!buffer || !buffer->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(buffer);
|
||||
SetIndexBufferInternal(view->GetResource(), offset, format);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBufferInternal(ID3D12Resource* buffer, uint64_t offset, Format indexFormat) {
|
||||
D3D12_INDEX_BUFFER_VIEW view = {};
|
||||
view.BufferLocation = buffer->GetGPUVirtualAddress() + offset;
|
||||
@@ -355,10 +400,22 @@ void D3D12CommandList::ClearRenderTarget(void* renderTarget, const float color[4
|
||||
ClearRenderTargetView(static_cast<ID3D12Resource*>(renderTarget), color, 0, nullptr);
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) {
|
||||
if (!renderTarget || !renderTarget->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(renderTarget);
|
||||
ClearRenderTargetView(view->GetCPUHandle(), color, 0, nullptr);
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) {
|
||||
ClearDepthStencilView(static_cast<ID3D12Resource*>(depthStencil), D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, depth, stencil, 0, nullptr);
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) {
|
||||
if (!depthStencil || !depthStencil->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(depthStencil);
|
||||
ClearDepthStencilView(view->GetCPUHandle(), D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, depth, stencil, 0, nullptr);
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearDepthStencilView(ID3D12Resource* depthStencil, uint32_t clearFlags, float depth, uint8_t stencil, uint32_t rectCount, const D3D12_RECT* rects) {
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = {};
|
||||
m_commandList->ClearDepthStencilView(dsvHandle, static_cast<D3D12_CLEAR_FLAGS>(clearFlags), depth, stencil, rectCount, rects);
|
||||
@@ -376,6 +433,13 @@ void D3D12CommandList::CopyResource(void* dst, void* src) {
|
||||
CopyResourceInternal(static_cast<ID3D12Resource*>(dst), static_cast<ID3D12Resource*>(src));
|
||||
}
|
||||
|
||||
void D3D12CommandList::CopyResource(RHIResourceView* dst, RHIResourceView* src) {
|
||||
if (!dst || !src || !dst->IsValid() || !src->IsValid()) return;
|
||||
D3D12ResourceView* dstView = static_cast<D3D12ResourceView*>(dst);
|
||||
D3D12ResourceView* srcView = static_cast<D3D12ResourceView*>(src);
|
||||
CopyResourceInternal(dstView->GetResource(), srcView->GetResource());
|
||||
}
|
||||
|
||||
void D3D12CommandList::CopyResourceInternal(ID3D12Resource* dst, ID3D12Resource* src) {
|
||||
m_commandList->CopyResource(dst, src);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user