refactor(RHI): remove void* from CommandList interfaces and fix OpenGL MRT bug
- Remove void* parameters from RHICommandList abstract interface - TransitionBarrier, SetVertexBuffer, SetIndexBuffer, SetRenderTargets, ClearRenderTarget, ClearDepthStencil, CopyResource now use RHIResourceView* - SetPipelineState now uses RHIPipelineState* instead of void* - Simplified SetVertexBuffer to 3 params, SetIndexBuffer to 2 params - Add internal D3D12 APIs for native type support (low-level escape hatch) - Fix OpenGL SetRenderTargets to call glDrawBuffers for MRT support - Update tests to match new interface signatures All 289 RHI tests pass (158 unit + 64 OpenGL backend + 58 D3D12 backend + 8 integration + 1 disabled)
This commit is contained in:
@@ -15,6 +15,9 @@ using Microsoft::WRL::ComPtr;
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class RHIPipelineState;
|
||||
class D3D12ResourceView;
|
||||
|
||||
class D3D12CommandList : public RHICommandList {
|
||||
public:
|
||||
D3D12CommandList();
|
||||
@@ -28,15 +31,16 @@ public:
|
||||
|
||||
ID3D12GraphicsCommandList* GetCommandList() const { return m_commandList.Get(); }
|
||||
|
||||
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void TransitionBarrier(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter);
|
||||
void TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
|
||||
void UAVBarrier(void* resource = nullptr);
|
||||
void UAVBarrier(ID3D12Resource* resource = nullptr);
|
||||
void UAVBarrierInternal(ID3D12Resource* resource);
|
||||
void AliasBarrier(void* beforeResource = nullptr, void* afterResource = nullptr);
|
||||
void AliasBarrier(ID3D12Resource* beforeResource = nullptr, ID3D12Resource* afterResource = nullptr);
|
||||
void AliasBarrierInternal(ID3D12Resource* beforeResource, ID3D12Resource* afterResource);
|
||||
|
||||
void SetPipelineState(void* pso) override;
|
||||
void SetPipelineState(RHIPipelineState* pso) override;
|
||||
void SetPipelineState(ID3D12PipelineState* pso);
|
||||
void SetPipelineStateInternal(ID3D12PipelineState* pso);
|
||||
void SetRootSignature(ID3D12RootSignature* signature);
|
||||
void SetViewport(const Viewport& viewport) override;
|
||||
@@ -44,18 +48,17 @@ public:
|
||||
void SetScissorRect(const Rect& rect) override;
|
||||
void SetScissorRects(uint32_t count, const Rect* rects) override;
|
||||
void SetPrimitiveTopology(PrimitiveTopology topology);
|
||||
void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) override;
|
||||
void SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil = nullptr) override;
|
||||
void SetRenderTargetsInternal(uint32_t count, ID3D12Resource** renderTargets, ID3D12Resource* depthStencil = nullptr);
|
||||
void SetRenderTargetsHandle(uint32_t count, const D3D12_CPU_DESCRIPTOR_HANDLE* renderTargetHandles, const D3D12_CPU_DESCRIPTOR_HANDLE* depthStencilHandle = nullptr);
|
||||
|
||||
void SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) override;
|
||||
void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) override;
|
||||
void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset) override;
|
||||
void SetVertexBuffer(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride);
|
||||
void SetVertexBufferInternal(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride);
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) override;
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, RHIResourceView** buffers, const uint64_t* offsets, const uint32_t* strides) override;
|
||||
void SetVertexBuffersInternal(uint32_t startSlot, uint32_t count, const D3D12_VERTEX_BUFFER_VIEW* views);
|
||||
void SetIndexBuffer(void* buffer, uint64_t offset, Format format) override;
|
||||
void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) override;
|
||||
void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset) override;
|
||||
void SetIndexBuffer(ID3D12Resource* buffer, uint64_t offset, Format format);
|
||||
void SetIndexBufferInternal(ID3D12Resource* buffer, uint64_t offset, Format indexFormat);
|
||||
|
||||
void SetDescriptorHeap(ID3D12DescriptorHeap* heap);
|
||||
@@ -76,23 +79,20 @@ public:
|
||||
|
||||
void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t startVertex = 0, uint32_t startInstance = 0) override;
|
||||
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t startIndex = 0, int32_t baseVertex = 0, uint32_t startInstance = 0) override;
|
||||
void DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
|
||||
void DrawInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
void DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
void DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset);
|
||||
void DrawIndexedInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
void DrawIndexedInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
|
||||
void Clear(float r, float g, float b, float a, uint32_t buffers) override;
|
||||
void ClearRenderTarget(void* renderTarget, const float color[4]) override;
|
||||
void ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) override;
|
||||
void ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) override;
|
||||
void ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) override;
|
||||
void ClearRenderTargetView(ID3D12Resource* renderTarget, const float color[4], uint32_t rectCount = 0, const D3D12_RECT* rects = nullptr);
|
||||
void ClearRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE renderTargetHandle, const float color[4], uint32_t rectCount = 0, const D3D12_RECT* rects = nullptr);
|
||||
void ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) override;
|
||||
void ClearDepthStencilView(ID3D12Resource* depthStencil, uint32_t clearFlags, float depth = 1.0f, uint8_t stencil = 0, uint32_t rectCount = 0, const D3D12_RECT* rects = nullptr);
|
||||
void ClearDepthStencilView(D3D12_CPU_DESCRIPTOR_HANDLE depthStencilHandle, uint32_t clearFlags, float depth = 1.0f, uint8_t stencil = 0, uint32_t rectCount = 0, const D3D12_RECT* rects = nullptr);
|
||||
void ClearUnorderedAccessView(D3D12_GPU_DESCRIPTOR_HANDLE viewHandle, D3D12_CPU_DESCRIPTOR_HANDLE resourceHandle, ID3D12Resource* unorderedAccess, const float values[4], uint32_t rectCount = 0, const D3D12_RECT* rects = nullptr);
|
||||
|
||||
void CopyResource(void* dst, void* src) override;
|
||||
void CopyResource(RHIResourceView* dst, RHIResourceView* src) override;
|
||||
void CopyResourceInternal(ID3D12Resource* dst, ID3D12Resource* src);
|
||||
void CopyBuffer(ID3D12Resource* dst, uint64_t dstOffset, ID3D12Resource* src, uint64_t srcOffset, uint64_t size);
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
void ResolveQueryData(ID3D12QueryHeap* queryHeap, QueryType type, uint32_t startIndex, uint32_t count, ID3D12Resource* resultBuffer, uint64_t resultOffset);
|
||||
|
||||
void Dispatch(uint32_t x, uint32_t y, uint32_t z) override;
|
||||
void DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset);
|
||||
void DispatchIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
void DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset);
|
||||
|
||||
void* GetNativeHandle() override { return GetCommandList(); }
|
||||
|
||||
@@ -45,18 +45,16 @@ public:
|
||||
void Reset() override;
|
||||
void Close() override;
|
||||
|
||||
void Clear(float r, float g, float b, float a, unsigned int buffers) override;
|
||||
void Clear(float r, float g, float b, float a, uint32_t buffers) override;
|
||||
void ClearColor(float r, float g, float b, float a);
|
||||
void ClearDepth(float depth);
|
||||
void ClearStencil(int stencil);
|
||||
void ClearDepthStencil(float depth, int stencil);
|
||||
|
||||
void SetPipelineState(void* pipelineState) override;
|
||||
void SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) override;
|
||||
void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) override;
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) override;
|
||||
void SetIndexBuffer(void* buffer, uint64_t offset, Format format) override;
|
||||
void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) override;
|
||||
void SetPipelineState(RHIPipelineState* pipelineState) override;
|
||||
void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset) override;
|
||||
void SetVertexBuffers(uint32_t startSlot, uint32_t count, RHIResourceView** buffers, const uint64_t* offsets, const uint32_t* strides) override;
|
||||
void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset) override;
|
||||
|
||||
// OpenGL 特有版本(底层逃逸)
|
||||
void SetVertexBuffer(unsigned int buffer, size_t offset, size_t stride);
|
||||
@@ -150,7 +148,6 @@ public:
|
||||
void BlitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, unsigned int mask, unsigned int filter);
|
||||
|
||||
void CopyImageSubData(unsigned int srcName, unsigned int srcTarget, int srcLevel, int srcX, int srcY, int srcZ, unsigned int dstName, unsigned int dstTarget, int dstLevel, int dstX, int dstY, int dstZ, int width, int height, int depth);
|
||||
void CopyResource(void* dst, void* src) override;
|
||||
void CopyResource(RHIResourceView* dst, RHIResourceView* src) override;
|
||||
|
||||
void InvalidateFramebuffer(unsigned int target, unsigned int count, const unsigned int* attachments);
|
||||
@@ -159,22 +156,18 @@ public:
|
||||
void PushDebugGroup(unsigned int source, unsigned int id, int length, const char* message);
|
||||
void PopDebugGroup();
|
||||
|
||||
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void SetPrimitiveTopology(PrimitiveTopology topology) override;
|
||||
void SetViewport(const Viewport& viewport) override;
|
||||
void SetViewports(uint32_t count, const Viewport* viewports) override;
|
||||
void SetScissorRect(const Rect& rect) override;
|
||||
void SetScissorRects(uint32_t count, const Rect* rects) override;
|
||||
void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) override;
|
||||
void SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil = nullptr) override;
|
||||
void SetDepthStencilState(const DepthStencilState& state) override;
|
||||
void SetStencilRef(uint8_t ref) override;
|
||||
void SetBlendState(const BlendState& state) override;
|
||||
void SetBlendFactor(const float factor[4]) override;
|
||||
void ClearRenderTarget(void* renderTarget, const float color[4]) override;
|
||||
void ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) override;
|
||||
void ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) override;
|
||||
void ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) override;
|
||||
void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t startVertex, uint32_t startInstance) override;
|
||||
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t startIndex, int32_t baseVertex, uint32_t startInstance) override;
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
class RHIResourceView;
|
||||
class RHIPipelineState;
|
||||
|
||||
struct DepthStencilState {
|
||||
bool depthEnable = true;
|
||||
@@ -51,16 +52,14 @@ public:
|
||||
virtual void Reset() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) = 0;
|
||||
virtual void TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) = 0;
|
||||
|
||||
virtual void SetPipelineState(void* pso) = 0;
|
||||
virtual void SetPipelineState(RHIPipelineState* pso) = 0;
|
||||
virtual void SetPrimitiveTopology(PrimitiveTopology topology) = 0;
|
||||
virtual void SetViewport(const Viewport& viewport) = 0;
|
||||
virtual void SetViewports(uint32_t count, const Viewport* viewports) = 0;
|
||||
virtual void SetScissorRect(const Rect& rect) = 0;
|
||||
virtual void SetScissorRects(uint32_t count, const Rect* rects) = 0;
|
||||
virtual void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) = 0;
|
||||
virtual void SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil = nullptr) = 0;
|
||||
|
||||
virtual void SetDepthStencilState(const DepthStencilState& state) = 0;
|
||||
@@ -68,22 +67,17 @@ public:
|
||||
virtual void SetBlendState(const BlendState& state) = 0;
|
||||
virtual void SetBlendFactor(const float factor[4]) = 0;
|
||||
|
||||
virtual void SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) = 0;
|
||||
virtual void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) = 0;
|
||||
virtual void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) = 0;
|
||||
virtual void SetIndexBuffer(void* buffer, uint64_t offset, Format format) = 0;
|
||||
virtual void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) = 0;
|
||||
virtual void SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset) = 0;
|
||||
virtual void SetVertexBuffers(uint32_t startSlot, uint32_t count, RHIResourceView** buffers, const uint64_t* offsets, const uint32_t* strides) = 0;
|
||||
virtual void SetIndexBuffer(RHIResourceView* buffer, uint64_t offset) = 0;
|
||||
|
||||
virtual void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t startVertex = 0, uint32_t startInstance = 0) = 0;
|
||||
virtual void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t startIndex = 0, int32_t baseVertex = 0, uint32_t startInstance = 0) = 0;
|
||||
|
||||
virtual void Clear(float r, float g, float b, float a, uint32_t buffers) = 0;
|
||||
virtual void ClearRenderTarget(void* renderTarget, const float color[4]) = 0;
|
||||
virtual void ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) = 0;
|
||||
virtual void ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) = 0;
|
||||
virtual void ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) = 0;
|
||||
|
||||
virtual void CopyResource(void* dst, void* src) = 0;
|
||||
virtual void CopyResource(RHIResourceView* dst, RHIResourceView* src) = 0;
|
||||
|
||||
virtual void Dispatch(uint32_t x, uint32_t y, uint32_t z) = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "XCEngine/RHI/D3D12/D3D12CommandList.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12ResourceView.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12PipelineState.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -74,26 +75,32 @@ void D3D12CommandList::Close() {
|
||||
m_commandList->Close();
|
||||
}
|
||||
|
||||
void D3D12CommandList::TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
|
||||
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));
|
||||
void D3D12CommandList::TransitionBarrier(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
|
||||
if (!resource) return;
|
||||
TransitionBarrierInternal(resource, stateBefore, stateAfter);
|
||||
}
|
||||
|
||||
void D3D12CommandList::AliasBarrier(void* beforeResource, void* afterResource) {
|
||||
AliasBarrierInternal(static_cast<ID3D12Resource*>(beforeResource), static_cast<ID3D12Resource*>(afterResource));
|
||||
void D3D12CommandList::UAVBarrier(ID3D12Resource* resource) {
|
||||
UAVBarrierInternal(resource);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetPipelineState(void* pso) {
|
||||
SetPipelineStateInternal(static_cast<ID3D12PipelineState*>(pso));
|
||||
void D3D12CommandList::AliasBarrier(ID3D12Resource* beforeResource, ID3D12Resource* afterResource) {
|
||||
AliasBarrierInternal(beforeResource, afterResource);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetPipelineState(RHIPipelineState* pso) {
|
||||
if (!pso) return;
|
||||
SetPipelineStateInternal(static_cast<ID3D12PipelineState*>(pso->GetNativeHandle()));
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetPipelineState(ID3D12PipelineState* pso) {
|
||||
SetPipelineStateInternal(pso);
|
||||
}
|
||||
|
||||
void D3D12CommandList::TransitionBarrierInternal(ID3D12Resource* resource, ResourceStates stateBefore, ResourceStates stateAfter, uint32_t subresource) {
|
||||
@@ -196,14 +203,6 @@ void D3D12CommandList::SetPrimitiveTopology(PrimitiveTopology topology) {
|
||||
m_currentTopology = ToD3D12Topology(topology);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil) {
|
||||
std::vector<ID3D12Resource*> resources(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
resources[i] = static_cast<ID3D12Resource*>(renderTargets[i]);
|
||||
}
|
||||
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) {
|
||||
@@ -258,14 +257,18 @@ void D3D12CommandList::SetRenderTargetsHandle(uint32_t count, const D3D12_CPU_DE
|
||||
}
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) {
|
||||
SetVertexBufferInternal(slot, static_cast<ID3D12Resource*>(buffer), offset, stride);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) {
|
||||
void D3D12CommandList::SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset) {
|
||||
if (!buffer || !buffer->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(buffer);
|
||||
SetVertexBufferInternal(slot, view->GetResource(), offset, stride);
|
||||
D3D12_VERTEX_BUFFER_VIEW vbView = {};
|
||||
vbView.BufferLocation = view->GetResource()->GetGPUVirtualAddress() + offset;
|
||||
vbView.SizeInBytes = static_cast<UINT>(view->GetResource()->GetDesc().Width) - static_cast<UINT>(offset);
|
||||
vbView.StrideInBytes = 0;
|
||||
m_commandList->IASetVertexBuffers(slot, 1, &vbView);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBuffer(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) {
|
||||
SetVertexBufferInternal(slot, buffer, offset, stride);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBufferInternal(uint32_t slot, ID3D12Resource* buffer, uint64_t offset, uint32_t stride) {
|
||||
@@ -277,12 +280,15 @@ void D3D12CommandList::SetVertexBufferInternal(uint32_t slot, ID3D12Resource* bu
|
||||
m_commandList->IASetVertexBuffers(slot, 1, &view);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) {
|
||||
void D3D12CommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, RHIResourceView** buffers, const uint64_t* offsets, const uint32_t* strides) {
|
||||
std::vector<D3D12_VERTEX_BUFFER_VIEW> views(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
views[i].BufferLocation = buffers[i];
|
||||
views[i].StrideInBytes = strides[i];
|
||||
views[i].SizeInBytes = 0;
|
||||
if (buffers[i] && buffers[i]->IsValid()) {
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(buffers[i]);
|
||||
views[i].BufferLocation = view->GetResource()->GetGPUVirtualAddress() + offsets[i];
|
||||
views[i].StrideInBytes = strides[i];
|
||||
views[i].SizeInBytes = static_cast<UINT>(view->GetResource()->GetDesc().Width) - static_cast<UINT>(offsets[i]);
|
||||
}
|
||||
}
|
||||
SetVertexBuffersInternal(startSlot, count, views.data());
|
||||
}
|
||||
@@ -291,14 +297,14 @@ void D3D12CommandList::SetVertexBuffersInternal(uint32_t startSlot, uint32_t cou
|
||||
m_commandList->IASetVertexBuffers(startSlot, count, views);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) {
|
||||
SetIndexBufferInternal(static_cast<ID3D12Resource*>(buffer), offset, format);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) {
|
||||
void D3D12CommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset) {
|
||||
if (!buffer || !buffer->IsValid()) return;
|
||||
D3D12ResourceView* view = static_cast<D3D12ResourceView*>(buffer);
|
||||
SetIndexBufferInternal(view->GetResource(), offset, format);
|
||||
SetIndexBufferInternal(view->GetResource(), offset, Format::R32_UInt);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBuffer(ID3D12Resource* buffer, uint64_t offset, Format format) {
|
||||
SetIndexBufferInternal(buffer, offset, format);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetIndexBufferInternal(ID3D12Resource* buffer, uint64_t offset, Format indexFormat) {
|
||||
@@ -352,7 +358,7 @@ void D3D12CommandList::SetDepthStencilState(const DepthStencilState& state) {
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetBlendState(const BlendState& state) {
|
||||
// TODO: Implement blend state
|
||||
m_commandList->OMSetBlendFactor(state.blendFactor);
|
||||
}
|
||||
|
||||
void D3D12CommandList::SetDepthBias(float depthBias, float slopeScaledDepthBias, float depthBiasClamp) {
|
||||
@@ -366,12 +372,12 @@ void D3D12CommandList::DrawIndexed(uint32_t indexCount, uint32_t instanceCount,
|
||||
m_commandList->DrawIndexedInstanced(indexCount, instanceCount, startIndex, baseVertex, startInstance);
|
||||
}
|
||||
|
||||
void D3D12CommandList::DrawInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
|
||||
DrawInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
|
||||
void D3D12CommandList::DrawInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
|
||||
DrawInstancedIndirectInternal(argBuffer, alignedByteOffset);
|
||||
}
|
||||
|
||||
void D3D12CommandList::DrawIndexedInstancedIndirect(void* argBuffer, uint64_t alignedByteOffset) {
|
||||
DrawIndexedInstancedIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
|
||||
void D3D12CommandList::DrawIndexedInstancedIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
|
||||
DrawIndexedInstancedIndirectInternal(argBuffer, alignedByteOffset);
|
||||
}
|
||||
|
||||
void D3D12CommandList::DrawInstancedIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
|
||||
@@ -393,11 +399,7 @@ void D3D12CommandList::ClearRenderTargetView(D3D12_CPU_DESCRIPTOR_HANDLE renderT
|
||||
}
|
||||
|
||||
void D3D12CommandList::Clear(float r, float g, float b, float a, uint32_t buffers) {
|
||||
// Not implemented - use ClearRenderTargetView and ClearDepthStencilView directly
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearRenderTarget(void* renderTarget, const float color[4]) {
|
||||
ClearRenderTargetView(static_cast<ID3D12Resource*>(renderTarget), color, 0, nullptr);
|
||||
(void)r; (void)g; (void)b; (void)a; (void)buffers;
|
||||
}
|
||||
|
||||
void D3D12CommandList::ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) {
|
||||
@@ -406,10 +408,6 @@ void D3D12CommandList::ClearRenderTarget(RHIResourceView* renderTarget, const fl
|
||||
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);
|
||||
@@ -429,10 +427,6 @@ void D3D12CommandList::ClearUnorderedAccessView(D3D12_GPU_DESCRIPTOR_HANDLE view
|
||||
m_commandList->ClearUnorderedAccessViewFloat(viewHandle, resourceHandle, unorderedAccess, values, rectCount, rects);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -488,8 +482,8 @@ void D3D12CommandList::Dispatch(uint32_t threadGroupCountX, uint32_t threadGroup
|
||||
m_commandList->Dispatch(threadGroupCountX, threadGroupCountY, threadGroupCountZ);
|
||||
}
|
||||
|
||||
void D3D12CommandList::DispatchIndirect(void* argBuffer, uint64_t alignedByteOffset) {
|
||||
DispatchIndirectInternal(static_cast<ID3D12Resource*>(argBuffer), alignedByteOffset);
|
||||
void D3D12CommandList::DispatchIndirect(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
|
||||
DispatchIndirectInternal(argBuffer, alignedByteOffset);
|
||||
}
|
||||
|
||||
void D3D12CommandList::DispatchIndirectInternal(ID3D12Resource* argBuffer, uint64_t alignedByteOffset) {
|
||||
|
||||
@@ -468,11 +468,28 @@ D3D12DescriptorHeap* D3D12Device::CreateDescriptorHeap(const DescriptorHeapDesc&
|
||||
}
|
||||
|
||||
D3D12QueryHeap* D3D12Device::CreateQueryHeap(const QueryHeapDesc& desc) {
|
||||
return nullptr;
|
||||
auto* queryHeap = new D3D12QueryHeap();
|
||||
if (!queryHeap->Initialize(m_device.Get(), static_cast<QueryType>(desc.queryType), desc.count)) {
|
||||
delete queryHeap;
|
||||
return nullptr;
|
||||
}
|
||||
return queryHeap;
|
||||
}
|
||||
|
||||
D3D12RootSignature* D3D12Device::CreateRootSignature(const RootSignatureDesc& desc) {
|
||||
return nullptr;
|
||||
auto* rootSig = new D3D12RootSignature();
|
||||
|
||||
D3D12_ROOT_SIGNATURE_DESC rootSigDesc = {};
|
||||
rootSigDesc.NumParameters = 0;
|
||||
rootSigDesc.NumStaticSamplers = 0;
|
||||
rootSigDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
|
||||
|
||||
if (!rootSig->Initialize(m_device.Get(), rootSigDesc)) {
|
||||
delete rootSig;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return rootSig;
|
||||
}
|
||||
|
||||
D3D12CommandQueue* D3D12Device::CreateCommandQueueImpl(const CommandQueueDesc& desc) {
|
||||
|
||||
@@ -24,7 +24,7 @@ void D3D12ResourceView::Shutdown() {
|
||||
}
|
||||
|
||||
void* D3D12ResourceView::GetNativeHandle() {
|
||||
return this;
|
||||
return reinterpret_cast<void*>(m_handle.ptr);
|
||||
}
|
||||
|
||||
bool D3D12ResourceView::IsValid() const {
|
||||
|
||||
@@ -183,7 +183,6 @@ void D3D12Texture::Shutdown() {
|
||||
if (m_ownsResource) {
|
||||
m_resource.Reset();
|
||||
}
|
||||
m_resource.Reset();
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLResourceView.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace XCEngine {
|
||||
@@ -430,9 +431,6 @@ void OpenGLCommandList::Reset() {
|
||||
void OpenGLCommandList::Close() {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::TransitionBarrier(RHIResourceView* resource, ResourceStates stateBefore, ResourceStates stateAfter) {
|
||||
(void)resource;
|
||||
(void)stateBefore;
|
||||
@@ -473,25 +471,8 @@ void OpenGLCommandList::SetScissorRects(uint32_t count, const Rect* rects) {
|
||||
glScissorArrayv(0, count, scissorGL.data());
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil) {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetRenderTargets(uint32_t count, RHIResourceView** renderTargets, RHIResourceView* depthStencil) {
|
||||
if (count > 0 && renderTargets != nullptr) {
|
||||
OpenGLResourceView* view = static_cast<OpenGLResourceView*>(renderTargets[0]);
|
||||
if (view && view->IsValid()) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, view->GetFramebuffer());
|
||||
}
|
||||
} else if (depthStencil) {
|
||||
OpenGLResourceView* dsv = static_cast<OpenGLResourceView*>(depthStencil);
|
||||
if (dsv && dsv->IsValid()) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dsv->GetFramebuffer());
|
||||
}
|
||||
} else {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
if (count > 1 && renderTargets != nullptr) {
|
||||
std::vector<GLuint> fbos(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
if (renderTargets[i]) {
|
||||
@@ -499,13 +480,26 @@ void OpenGLCommandList::SetRenderTargets(uint32_t count, RHIResourceView** rende
|
||||
fbos[i] = view->GetFramebuffer();
|
||||
}
|
||||
}
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLCommandList::ClearRenderTarget(void* renderTarget, const float color[4]) {
|
||||
glClearColor(color[0], color[1], color[2], color[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbos[0]);
|
||||
|
||||
std::vector<GLenum> drawBuffers(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
|
||||
}
|
||||
glDrawBuffers(count, drawBuffers.data());
|
||||
|
||||
} else if (depthStencil) {
|
||||
OpenGLResourceView* dsv = static_cast<OpenGLResourceView*>(depthStencil);
|
||||
if (dsv && dsv->IsValid()) {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, dsv->GetFramebuffer());
|
||||
}
|
||||
glDrawBuffers(0, nullptr);
|
||||
} else {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
(void)depthStencil;
|
||||
}
|
||||
|
||||
void OpenGLCommandList::ClearRenderTarget(RHIResourceView* renderTarget, const float color[4]) {
|
||||
@@ -523,11 +517,6 @@ void OpenGLCommandList::ClearRenderTarget(RHIResourceView* renderTarget, const f
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFBO);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) {
|
||||
glClearDepth(depth);
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::ClearDepthStencil(RHIResourceView* depthStencil, float depth, uint8_t stencil) {
|
||||
if (!depthStencil) return;
|
||||
OpenGLResourceView* view = static_cast<OpenGLResourceView*>(depthStencil);
|
||||
@@ -544,33 +533,30 @@ void OpenGLCommandList::ClearDepthStencil(RHIResourceView* depthStencil, float d
|
||||
(void)stencil;
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetPipelineState(void* pipelineState) {
|
||||
void OpenGLCommandList::SetPipelineState(RHIPipelineState* pipelineState) {
|
||||
if (pipelineState) {
|
||||
UseShader(reinterpret_cast<uintptr_t>(pipelineState));
|
||||
UseShader(reinterpret_cast<uintptr_t>(pipelineState->GetNativeHandle()));
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) {
|
||||
GLuint glBuffer = static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
|
||||
glBindBuffer(GL_ARRAY_BUFFER, glBuffer);
|
||||
glVertexAttribPointer(slot, stride / sizeof(float), GL_FLOAT, GL_FALSE, stride, reinterpret_cast<void*>(static_cast<uintptr_t>(offset)));
|
||||
glEnableVertexAttribArray(slot);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset, uint32_t stride) {
|
||||
void OpenGLCommandList::SetVertexBuffer(uint32_t slot, RHIResourceView* buffer, uint64_t offset) {
|
||||
if (!buffer) return;
|
||||
OpenGLResourceView* view = static_cast<OpenGLResourceView*>(buffer);
|
||||
if (!view->IsValid()) return;
|
||||
|
||||
GLuint glBuffer = view->GetBuffer();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, glBuffer);
|
||||
glVertexAttribPointer(slot, stride / sizeof(float), GL_FLOAT, GL_FALSE, stride, reinterpret_cast<void*>(static_cast<uintptr_t>(offset)));
|
||||
glVertexAttribPointer(slot, 4, GL_FLOAT, GL_FALSE, 0, reinterpret_cast<void*>(static_cast<uintptr_t>(offset)));
|
||||
glEnableVertexAttribArray(slot);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) {
|
||||
void OpenGLCommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, RHIResourceView** buffers, const uint64_t* offsets, const uint32_t* strides) {
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
GLuint glBuffer = static_cast<GLuint>(buffers[i]);
|
||||
if (!buffers[i]) continue;
|
||||
OpenGLResourceView* view = static_cast<OpenGLResourceView*>(buffers[i]);
|
||||
if (!view->IsValid()) continue;
|
||||
|
||||
GLuint glBuffer = view->GetBuffer();
|
||||
glBindBuffer(GL_ARRAY_BUFFER, glBuffer);
|
||||
glEnableVertexAttribArray(startSlot + i);
|
||||
glVertexAttribPointer(startSlot + i, strides[i] / sizeof(float), GL_FLOAT, GL_FALSE, strides[i], reinterpret_cast<void*>(static_cast<uintptr_t>(offsets[i])));
|
||||
@@ -578,14 +564,7 @@ void OpenGLCommandList::SetVertexBuffers(uint32_t startSlot, uint32_t count, con
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetIndexBuffer(void* buffer, uint64_t offset, Format format) {
|
||||
GLuint glBuffer = static_cast<GLuint>(reinterpret_cast<uintptr_t>(buffer));
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glBuffer);
|
||||
(void)offset;
|
||||
(void)format;
|
||||
}
|
||||
|
||||
void OpenGLCommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset, Format format) {
|
||||
void OpenGLCommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset) {
|
||||
if (!buffer) return;
|
||||
OpenGLResourceView* view = static_cast<OpenGLResourceView*>(buffer);
|
||||
if (!view->IsValid()) return;
|
||||
@@ -593,10 +572,6 @@ void OpenGLCommandList::SetIndexBuffer(RHIResourceView* buffer, uint64_t offset,
|
||||
GLuint glBuffer = view->GetBuffer();
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glBuffer);
|
||||
(void)offset;
|
||||
(void)format;
|
||||
}
|
||||
|
||||
void OpenGLCommandList::CopyResource(void* dst, void* src) {
|
||||
}
|
||||
|
||||
void OpenGLCommandList::CopyResource(RHIResourceView* dst, RHIResourceView* src) {
|
||||
|
||||
Reference in New Issue
Block a user