Files
XCEngine/docs/api/XCEngine/RHI/OpenGL/OpenGLDescriptorPool/OpenGLDescriptorPool.md

2.8 KiB
Raw Blame History

OpenGLDescriptorPool

命名空间: XCEngine::RHI

类型: class

头文件: XCEngine/RHI/OpenGL/OpenGLDescriptorPool.h

描述: OpenGL 后端的 descriptor pool 抽象,但当前实现本质上是 OpenGLDescriptorSet 的拥有容器和 texture unit 分配入口。

概览

OpenGL 没有 D3D12/Vulkan 那种原生 descriptor pool / descriptor set 体系,所以 OpenGLDescriptorPool 是一个纯引擎侧抽象。

它当前主要承担这些职责:

  • 记录 pool 类型
  • 限制最多可分配多少个 descriptor set
  • 为新建的 OpenGLDescriptorSet 注入 OpenGLTextureUnitAllocator
  • 跟踪当前由自己分配出去的 set 指针

设计定位

这里最容易误解的一点是 DescriptorPoolDesc.descriptorCount

在 D3D12 里,它更像 heap 容量;在当前 OpenGL 实现里,它被当成:

  • m_maxSets
  • 也就是“最多允许创建多少个 set”

而不是“总 descriptor 数量”。

生命周期

  • 构造后默认类型为 CBV_SRV_UAVm_maxSets = 0
  • Initialize 记录类型和 set 上限
  • AllocateSet 创建并跟踪新的 OpenGLDescriptorSet
  • FreeSet 删除被跟踪的 set
  • Shutdown 只清空跟踪信息,不负责 delete 仍在表中的 set

当前实现的真实行为

  • GetNativeHandle 返回 this
  • GetDescriptorCount 返回 m_maxSets
  • Initialize 忽略 shaderVisible
  • AllocateSet 只有在 m_allocatedSets.size() < m_maxSets 时才允许分配
  • 如果 layout 包含 SRV / Sampler / UAV,创建 set 时依赖 OpenGLTextureUnitAllocator
  • Shutdown 不 delete 仍然存活的 set只是 clear() 指针列表并置空 allocator

为什么这样设计

OpenGL 后端没有必要模拟一份沉重的 descriptor heap 系统。当前实现选的是更实用的一条路线:

  • 把 descriptor set 继续保留为跨后端统一抽象
  • 用 pool 负责 set 的创建和数量管理
  • 用 texture unit allocator 负责真正的纹理单元资源

这种设计简单、够用,而且和当前 OpenGLDescriptorSet 的绑定实现配合自然。

当前限制

  • descriptorCount 语义和其他后端不同
  • 不是 descriptor 级资源池,而是 set 数量上限
  • Shutdown() 不会 delete 已分配 set
  • 没有线程安全
  • 没有碎片、复用策略或更细粒度配额

关键方法

相关文档