RHI: Add DescriptorSet abstraction for D3D12 and OpenGL backends
- Add RHIDescriptorSet base class with Update/UpdateSampler/GetNativeHandle - Add RHIDescriptorPool with AllocateSet/FreeSet methods - Add SetGraphicsDescriptorSets/SetComputeDescriptorSets to RHICommandList - Implement D3D12DescriptorSet using descriptor heap allocation - Implement OpenGLDescriptorSet using TextureUnitAllocator - Add CreateDescriptorPool/CreateDescriptorSet factory methods to RHIDevice - Fix unit test SetVertexBuffer -> SetVertexBuffers API - Add SetVertexBuffer convenience method for D3D12 backward compatibility - Update CMakeLists.txt with new source files
This commit is contained in:
62
engine/src/RHI/OpenGL/OpenGLDescriptorPool.cpp
Normal file
62
engine/src/RHI/OpenGL/OpenGLDescriptorPool.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLTextureUnitAllocator.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
OpenGLDescriptorPool::OpenGLDescriptorPool()
|
||||
: m_type(DescriptorHeapType::CBV_SRV_UAV)
|
||||
, m_maxSets(0)
|
||||
, m_textureUnitAllocator(nullptr) {
|
||||
}
|
||||
|
||||
OpenGLDescriptorPool::~OpenGLDescriptorPool() {
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
bool OpenGLDescriptorPool::Initialize(const DescriptorPoolDesc& desc) {
|
||||
m_type = desc.type;
|
||||
m_maxSets = desc.descriptorCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenGLDescriptorPool::Shutdown() {
|
||||
for (auto* set : m_allocatedSets) {
|
||||
delete set;
|
||||
}
|
||||
m_allocatedSets.clear();
|
||||
m_textureUnitAllocator = nullptr;
|
||||
}
|
||||
|
||||
RHIDescriptorSet* OpenGLDescriptorPool::AllocateSet(const DescriptorSetLayoutDesc& layout) {
|
||||
if (m_allocatedSets.size() >= m_maxSets) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OpenGLDescriptorSet* newSet = new OpenGLDescriptorSet();
|
||||
if (!newSet->Initialize(m_textureUnitAllocator, layout.bindingCount, layout)) {
|
||||
delete newSet;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_allocatedSets.push_back(newSet);
|
||||
return newSet;
|
||||
}
|
||||
|
||||
void OpenGLDescriptorPool::FreeSet(RHIDescriptorSet* set) {
|
||||
if (set == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto it = m_allocatedSets.begin(); it != m_allocatedSets.end(); ++it) {
|
||||
if (*it == set) {
|
||||
m_allocatedSets.erase(it);
|
||||
delete set;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user