Remove RHI interface inheritance from all D3D12 backend classes

- D3D12Device, D3D12CommandQueue, D3D12CommandAllocator, D3D12Fence
- D3D12DescriptorHeap, D3D12QueryHeap, D3D12RootSignature
- D3D12PipelineState, D3D12Sampler, D3D12Shader
- D3D12Buffer, D3D12Texture, D3D12SwapChain

All D3D12 backend classes now directly use D3D12 APIs without
going through RHI interface abstraction. This decouples the
D3D12 backend from the RHI abstraction layer.

Test: D3D12 rendering test passed (screenshot comparison 100% match)
This commit is contained in:
2026-03-16 15:48:14 +08:00
parent 0014c32fa5
commit 0ce312e648
14 changed files with 492 additions and 69 deletions

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Buffer : public IBuffer {
class D3D12Buffer {
public:
D3D12Buffer();
~D3D12Buffer();
@@ -29,18 +29,18 @@ public:
void UpdateData(const void* data, uint64_t size);
void* GetNativeHandle() const override { return m_resource.Get(); }
ResourceStates GetState() const override { return m_state; }
void SetState(ResourceStates state) override { m_state = state; }
void* GetNativeHandle() const { return m_resource.Get(); }
ResourceStates GetState() const { return m_state; }
void SetState(ResourceStates state) { m_state = state; }
uint64_t GetGPUAddress() const override { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const override { return GetDesc().Width; }
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const { return GetDesc().Width; }
const std::string& GetName() const override { return m_name; }
void SetName(const std::string& name) override { m_name = name; }
const std::string& GetName() const { return m_name; }
void SetName(const std::string& name) { m_name = name; }
uint32_t GetStride() const override { return m_stride; }
BufferType GetBufferType() const override { return m_bufferType; }
uint32_t GetStride() const { return m_stride; }
BufferType GetBufferType() const { return m_bufferType; }
void SetStride(uint32_t stride) { m_stride = stride; }
void SetBufferType(BufferType type) { m_bufferType = type; }

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12CommandAllocator : public ICommandAllocator {
class D3D12CommandAllocator {
public:
D3D12CommandAllocator();
~D3D12CommandAllocator();
@@ -19,8 +19,8 @@ public:
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct);
void Shutdown();
void Reset() override;
bool IsReady() const override;
void Reset();
bool IsReady() const;
ID3D12CommandAllocator* GetCommandAllocator() const { return m_commandAllocator.Get(); }

View File

@@ -14,7 +14,7 @@ namespace RHI {
class D3D12Fence;
class D3D12CommandQueue : public ICommandQueue {
class D3D12CommandQueue {
public:
D3D12CommandQueue();
~D3D12CommandQueue();
@@ -22,17 +22,17 @@ public:
bool Initialize(ID3D12Device* device, CommandQueueType type = CommandQueueType::Direct);
void Shutdown();
void ExecuteCommandLists(uint32_t count, ICommandList** lists) override;
void ExecuteCommandLists(uint32_t count, ICommandList** lists);
void ExecuteCommandLists(uint32_t count, ID3D12CommandList** lists);
void Signal(IFence* fence, uint64_t value) override;
void Signal(IFence* fence, uint64_t value);
void Signal(ID3D12Fence* fence, uint64_t value);
void Wait(IFence* fence, uint64_t value) override;
void Wait(IFence* fence, uint64_t value);
void Wait(ID3D12Fence* fence, uint64_t value);
uint64_t GetCompletedValue() override;
void WaitForIdle() override;
uint64_t GetCompletedValue();
void WaitForIdle();
CommandQueueType GetType() const override { return m_type; }
uint64_t GetTimestampFrequency() const override { return m_timestampFrequency; }
CommandQueueType GetType() const { return m_type; }
uint64_t GetTimestampFrequency() const { return m_timestampFrequency; }
ID3D12CommandQueue* GetCommandQueue() const { return m_commandQueue.Get(); }

View File

@@ -13,7 +13,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12DescriptorHeap : public IDescriptorHeap {
class D3D12DescriptorHeap {
public:
D3D12DescriptorHeap();
~D3D12DescriptorHeap();
@@ -23,10 +23,10 @@ public:
ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptorHeap.Get(); }
CPUDescriptorHandle GetCPUDescriptorHandle(uint32_t index) override;
GPUDescriptorHandle GetGPUDescriptorHandle(uint32_t index) override;
uint32_t GetDescriptorCount() const override;
DescriptorType GetType() const override;
CPUDescriptorHandle GetCPUDescriptorHandle(uint32_t index);
GPUDescriptorHandle GetGPUDescriptorHandle(uint32_t index);
uint32_t GetDescriptorCount() const;
DescriptorType GetType() const;
uint32_t GetDescriptorSize() const { return m_descriptorSize; }
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandleForHeapStart() const;

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Fence : public IFence {
class D3D12Fence {
public:
D3D12Fence();
~D3D12Fence();
@@ -19,10 +19,10 @@ public:
bool Initialize(ID3D12Device* device, uint64_t initialValue = 0);
void Shutdown();
void Signal(uint64_t value) override;
void Wait(uint64_t value) override;
uint64_t GetCompletedValue() override;
void* GetEventHandle() override { return m_eventHandle; }
void Signal(uint64_t value);
void Wait(uint64_t value);
uint64_t GetCompletedValue();
void* GetEventHandle() { return m_eventHandle; }
ID3D12Fence* GetFence() const { return m_fence.Get(); }

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12PipelineState : public IPipelineState {
class D3D12PipelineState {
public:
D3D12PipelineState();
~D3D12PipelineState();
@@ -21,8 +21,8 @@ public:
ID3D12PipelineState* GetPipelineState() const { return m_pipelineState.Get(); }
void* GetNativeHandle() const override { return m_pipelineState.Get(); }
PipelineType GetType() const override { return PipelineType::Graphics; }
void* GetNativeHandle() const { return m_pipelineState.Get(); }
PipelineType GetType() const { return PipelineType::Graphics; }
private:
ComPtr<ID3D12PipelineState> m_pipelineState;

View File

@@ -12,7 +12,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12QueryHeap : public IQueryHeap {
class D3D12QueryHeap {
public:
D3D12QueryHeap();
~D3D12QueryHeap();
@@ -22,9 +22,9 @@ public:
ID3D12QueryHeap* GetQueryHeap() const { return m_queryHeap.Get(); }
void* GetNativeHandle() const override { return m_queryHeap.Get(); }
QueryType GetType() const override { return m_type; }
uint32_t GetCount() const override { return m_count; }
void* GetNativeHandle() const { return m_queryHeap.Get(); }
QueryType GetType() const { return m_type; }
uint32_t GetCount() const { return m_count; }
private:
ComPtr<ID3D12QueryHeap> m_queryHeap;

View File

@@ -12,7 +12,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12RootSignature : public IRootSignature {
class D3D12RootSignature {
public:
D3D12RootSignature();
~D3D12RootSignature();
@@ -22,8 +22,8 @@ public:
ID3D12RootSignature* GetRootSignature() const { return m_rootSignature.Get(); }
void* GetNativeHandle() const override { return m_rootSignature.Get(); }
uint32_t GetParameterCount() const override { return m_parameterCount; }
void* GetNativeHandle() const { return m_rootSignature.Get(); }
uint32_t GetParameterCount() const { return m_parameterCount; }
private:
ComPtr<ID3D12RootSignature> m_rootSignature;

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Sampler : public ISampler {
class D3D12Sampler {
public:
D3D12Sampler();
~D3D12Sampler();
@@ -21,7 +21,7 @@ public:
D3D12_SAMPLER_DESC GetDesc() const { return m_desc; }
void* GetNativeHandle() const override { return nullptr; }
void* GetNativeHandle() const { return nullptr; }
private:
D3D12_SAMPLER_DESC m_desc;

View File

@@ -13,7 +13,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Shader : public IShader {
class D3D12Shader {
public:
D3D12Shader();
~D3D12Shader();
@@ -23,10 +23,10 @@ public:
void Shutdown();
const D3D12_SHADER_BYTECODE GetD3D12Bytecode() const;
virtual const void* GetBytecode() const override;
virtual size_t GetBytecodeSize() const override;
virtual ShaderType GetType() const override;
virtual const InputLayoutDesc& GetInputLayout() const override;
const void* GetBytecode() const;
size_t GetBytecodeSize() const;
ShaderType GetType() const;
const InputLayoutDesc& GetInputLayout() const;
private:
ComPtr<ID3DBlob> m_bytecode;

View File

@@ -4,7 +4,6 @@
#include <dxgi1_4.h>
#include <wrl/client.h>
#include "../SwapChain.h"
#include "D3D12Enum.h"
#include "D3D12Texture.h"
@@ -13,7 +12,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12SwapChain : public ISwapChain {
class D3D12SwapChain {
public:
D3D12SwapChain();
~D3D12SwapChain();
@@ -22,13 +21,13 @@ public:
bool Initialize(IDXGISwapChain* swapChain, uint32_t width, uint32_t height);
void Shutdown();
uint32_t GetCurrentBackBufferIndex() const override;
IResource* GetBackBuffer(uint32_t index) const override;
void Present(uint32_t syncInterval, uint32_t flags) override;
void Resize(uint32_t width, uint32_t height) override;
void SetFullscreen(bool fullscreen) override;
bool IsFullscreen() const override;
void* GetNativeHandle() const override;
uint32_t GetCurrentBackBufferIndex() const;
D3D12Texture* GetBackBuffer(uint32_t index) const;
void Present(uint32_t syncInterval, uint32_t flags);
void Resize(uint32_t width, uint32_t height);
void SetFullscreen(bool fullscreen);
bool IsFullscreen() const;
void* GetNativeHandle() const;
IDXGISwapChain3* GetSwapChain() const { return m_swapChain.Get(); }

View File

@@ -11,7 +11,7 @@ using Microsoft::WRL::ComPtr;
namespace XCEngine {
namespace RHI {
class D3D12Texture : public ITexture {
class D3D12Texture {
public:
D3D12Texture();
~D3D12Texture();
@@ -31,19 +31,19 @@ public:
uint32_t GetDepth() const { return GetDesc().DepthOrArraySize; }
uint32_t GetMipLevels() const { return GetDesc().MipLevels; }
void* GetNativeHandle() const override { return m_resource.Get(); }
ResourceStates GetState() const override { return m_state; }
void SetState(ResourceStates state) override { m_state = state; }
void* GetNativeHandle() const { return m_resource.Get(); }
ResourceStates GetState() const { return m_state; }
void SetState(ResourceStates state) { m_state = state; }
uint64_t GetGPUAddress() const override { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const override { return GetDesc().Width * GetDesc().Height * GetDesc().DepthOrArraySize; }
uint64_t GetGPUAddress() const { return m_resource->GetGPUVirtualAddress(); }
size_t GetSize() const { return GetDesc().Width * GetDesc().Height * GetDesc().DepthOrArraySize; }
const std::string& GetName() const override { return m_name; }
void SetName(const std::string& name) override { m_name = name; }
const std::string& GetName() const { return m_name; }
void SetName(const std::string& name) { m_name = name; }
uint32_t GetArraySize() const override { return GetDesc().DepthOrArraySize; }
Format GetFormat() const override { return static_cast<Format>(GetDesc().Format); }
TextureType GetTextureType() const override { return TextureType::Texture2D; }
uint32_t GetArraySize() const { return GetDesc().DepthOrArraySize; }
Format GetFormat() const { return static_cast<Format>(GetDesc().Format); }
TextureType GetTextureType() const { return TextureType::Texture2D; }
private:
ComPtr<ID3D12Resource> m_resource;

View File

@@ -74,7 +74,7 @@ uint32_t D3D12SwapChain::GetCurrentBackBufferIndex() const {
return m_swapChain->GetCurrentBackBufferIndex();
}
IResource* D3D12SwapChain::GetBackBuffer(uint32_t index) const {
D3D12Texture* D3D12SwapChain::GetBackBuffer(uint32_t index) const {
if (index < m_backBuffers.size()) {
return const_cast<D3D12Texture*>(&m_backBuffers[index]);
}