From a532cabf9205142f94992a58c91be1484d1a7229 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 18 Mar 2026 01:46:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(RHI):=20=E6=B7=BB=E5=8A=A0=20RHIDescriptor?= =?UTF-8?q?Pool=20=E6=8A=BD=E8=B1=A1=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 RHIDescriptorPool 抽象基类,定义描述符池统一接口 - D3D12DescriptorHeap 现在继承自 RHIDescriptorPool - 添加 DescriptorPoolDesc 结构体,包含设备指针、类型、数量等信息 - 添加 Initialize(const DescriptorPoolDesc&) 统一初始化方法 --- engine/CMakeLists.txt | 1 + .../XCEngine/RHI/D3D12/D3D12DescriptorHeap.h | 15 ++++++---- .../include/XCEngine/RHI/RHIDescriptorPool.h | 30 +++++++++++++++++++ engine/src/RHI/D3D12/D3D12DescriptorHeap.cpp | 13 ++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 engine/include/XCEngine/RHI/RHIDescriptorPool.h diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index f2b046f2..85f62efc 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -84,6 +84,7 @@ add_library(XCEngine STATIC # RHI ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/RHIEnums.h ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/RHIFactory.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/RHIDescriptorPool.h ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12Enum.h ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12Device.h ${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12CommandQueue.h diff --git a/engine/include/XCEngine/RHI/D3D12/D3D12DescriptorHeap.h b/engine/include/XCEngine/RHI/D3D12/D3D12DescriptorHeap.h index 61058478..9f0ccead 100644 --- a/engine/include/XCEngine/RHI/D3D12/D3D12DescriptorHeap.h +++ b/engine/include/XCEngine/RHI/D3D12/D3D12DescriptorHeap.h @@ -5,6 +5,7 @@ #include "../RHIEnums.h" #include "../RHITypes.h" +#include "../RHIDescriptorPool.h" #include "D3D12Enum.h" using Microsoft::WRL::ComPtr; @@ -12,25 +13,29 @@ using Microsoft::WRL::ComPtr; namespace XCEngine { namespace RHI { -class D3D12DescriptorHeap { +class D3D12DescriptorHeap : public RHIDescriptorPool { public: D3D12DescriptorHeap(); - ~D3D12DescriptorHeap(); + ~D3D12DescriptorHeap() override; bool Initialize(ID3D12Device* device, DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible = false); - void Shutdown(); + void Shutdown() override; + + bool Initialize(const DescriptorPoolDesc& desc) override; ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptorHeap.Get(); } CPUDescriptorHandle GetCPUDescriptorHandle(uint32_t index); GPUDescriptorHandle GetGPUDescriptorHandle(uint32_t index); - uint32_t GetDescriptorCount() const; - DescriptorType GetType() const; + uint32_t GetDescriptorCount() const override; + DescriptorHeapType GetType() const override; uint32_t GetDescriptorSize() const { return m_descriptorSize; } D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandleForHeapStart() const; D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorHandleForHeapStart() const; + void* GetNativeHandle() override { return m_descriptorHeap.Get(); } + static D3D12_DESCRIPTOR_HEAP_DESC CreateDesc(DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible = false); private: diff --git a/engine/include/XCEngine/RHI/RHIDescriptorPool.h b/engine/include/XCEngine/RHI/RHIDescriptorPool.h new file mode 100644 index 00000000..f43bff9b --- /dev/null +++ b/engine/include/XCEngine/RHI/RHIDescriptorPool.h @@ -0,0 +1,30 @@ +#pragma once + +#include "RHIEnums.h" +#include + +namespace XCEngine { +namespace RHI { + +struct DescriptorPoolDesc { + void* device; + DescriptorHeapType type; + uint32_t descriptorCount; + bool shaderVisible; +}; + +class RHIDescriptorPool { +public: + virtual ~RHIDescriptorPool() = default; + + virtual bool Initialize(const DescriptorPoolDesc& desc) = 0; + virtual void Shutdown() = 0; + + virtual void* GetNativeHandle() = 0; + + virtual uint32_t GetDescriptorCount() const = 0; + virtual DescriptorHeapType GetType() const = 0; +}; + +} // namespace RHI +} // namespace XCEngine diff --git a/engine/src/RHI/D3D12/D3D12DescriptorHeap.cpp b/engine/src/RHI/D3D12/D3D12DescriptorHeap.cpp index 10b120fb..ea7ca049 100644 --- a/engine/src/RHI/D3D12/D3D12DescriptorHeap.cpp +++ b/engine/src/RHI/D3D12/D3D12DescriptorHeap.cpp @@ -14,6 +14,15 @@ D3D12DescriptorHeap::~D3D12DescriptorHeap() { Shutdown(); } +bool D3D12DescriptorHeap::Initialize(const DescriptorPoolDesc& desc) { + return Initialize( + static_cast(desc.device), + desc.type, + desc.descriptorCount, + desc.shaderVisible + ); +} + bool D3D12DescriptorHeap::Initialize(ID3D12Device* device, DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible) { D3D12_DESCRIPTOR_HEAP_DESC desc = {}; desc.Type = ToD3D12(type); @@ -62,8 +71,8 @@ GPUDescriptorHandle D3D12DescriptorHeap::GetGPUDescriptorHandle(uint32_t index) return result; } -DescriptorType D3D12DescriptorHeap::GetType() const { - return static_cast(m_type); +DescriptorHeapType D3D12DescriptorHeap::GetType() const { + return m_type; } uint32_t D3D12DescriptorHeap::GetDescriptorCount() const {