feat(RHI): 添加 RHIDescriptorPool 抽象类
- 新增 RHIDescriptorPool 抽象基类,定义描述符池统一接口 - D3D12DescriptorHeap 现在继承自 RHIDescriptorPool - 添加 DescriptorPoolDesc 结构体,包含设备指针、类型、数量等信息 - 添加 Initialize(const DescriptorPoolDesc&) 统一初始化方法
This commit is contained in:
@@ -84,6 +84,7 @@ add_library(XCEngine STATIC
|
|||||||
# RHI
|
# RHI
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/RHIEnums.h
|
${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/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/D3D12Enum.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12Device.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12Device.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12CommandQueue.h
|
${CMAKE_CURRENT_SOURCE_DIR}/include/XCEngine/RHI/D3D12/D3D12CommandQueue.h
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "../RHIEnums.h"
|
#include "../RHIEnums.h"
|
||||||
#include "../RHITypes.h"
|
#include "../RHITypes.h"
|
||||||
|
#include "../RHIDescriptorPool.h"
|
||||||
#include "D3D12Enum.h"
|
#include "D3D12Enum.h"
|
||||||
|
|
||||||
using Microsoft::WRL::ComPtr;
|
using Microsoft::WRL::ComPtr;
|
||||||
@@ -12,25 +13,29 @@ using Microsoft::WRL::ComPtr;
|
|||||||
namespace XCEngine {
|
namespace XCEngine {
|
||||||
namespace RHI {
|
namespace RHI {
|
||||||
|
|
||||||
class D3D12DescriptorHeap {
|
class D3D12DescriptorHeap : public RHIDescriptorPool {
|
||||||
public:
|
public:
|
||||||
D3D12DescriptorHeap();
|
D3D12DescriptorHeap();
|
||||||
~D3D12DescriptorHeap();
|
~D3D12DescriptorHeap() override;
|
||||||
|
|
||||||
bool Initialize(ID3D12Device* device, DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible = false);
|
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(); }
|
ID3D12DescriptorHeap* GetDescriptorHeap() const { return m_descriptorHeap.Get(); }
|
||||||
|
|
||||||
CPUDescriptorHandle GetCPUDescriptorHandle(uint32_t index);
|
CPUDescriptorHandle GetCPUDescriptorHandle(uint32_t index);
|
||||||
GPUDescriptorHandle GetGPUDescriptorHandle(uint32_t index);
|
GPUDescriptorHandle GetGPUDescriptorHandle(uint32_t index);
|
||||||
uint32_t GetDescriptorCount() const;
|
uint32_t GetDescriptorCount() const override;
|
||||||
DescriptorType GetType() const;
|
DescriptorHeapType GetType() const override;
|
||||||
|
|
||||||
uint32_t GetDescriptorSize() const { return m_descriptorSize; }
|
uint32_t GetDescriptorSize() const { return m_descriptorSize; }
|
||||||
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandleForHeapStart() const;
|
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandleForHeapStart() const;
|
||||||
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorHandleForHeapStart() 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);
|
static D3D12_DESCRIPTOR_HEAP_DESC CreateDesc(DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
30
engine/include/XCEngine/RHI/RHIDescriptorPool.h
Normal file
30
engine/include/XCEngine/RHI/RHIDescriptorPool.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "RHIEnums.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -14,6 +14,15 @@ D3D12DescriptorHeap::~D3D12DescriptorHeap() {
|
|||||||
Shutdown();
|
Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool D3D12DescriptorHeap::Initialize(const DescriptorPoolDesc& desc) {
|
||||||
|
return Initialize(
|
||||||
|
static_cast<ID3D12Device*>(desc.device),
|
||||||
|
desc.type,
|
||||||
|
desc.descriptorCount,
|
||||||
|
desc.shaderVisible
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
bool D3D12DescriptorHeap::Initialize(ID3D12Device* device, DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible) {
|
bool D3D12DescriptorHeap::Initialize(ID3D12Device* device, DescriptorHeapType type, uint32_t numDescriptors, bool shaderVisible) {
|
||||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||||
desc.Type = ToD3D12(type);
|
desc.Type = ToD3D12(type);
|
||||||
@@ -62,8 +71,8 @@ GPUDescriptorHandle D3D12DescriptorHeap::GetGPUDescriptorHandle(uint32_t index)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorType D3D12DescriptorHeap::GetType() const {
|
DescriptorHeapType D3D12DescriptorHeap::GetType() const {
|
||||||
return static_cast<DescriptorType>(m_type);
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t D3D12DescriptorHeap::GetDescriptorCount() const {
|
uint32_t D3D12DescriptorHeap::GetDescriptorCount() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user