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 {