GPU Abstraction
EntropyPortal implements a robust GPU Abstraction Layer that sits between the engine and the low-level Slang RHI. This layer provides safety, simplified state management, and automated synchronization.
Design Philosophy
Section titled “Design Philosophy”The abstraction is built on three core pillars:
- Safety via RAII: All GPU resources follow strict ownership semantics using
RefObjectandmakeRef. - Automatic State Management: The system tracks resource states (e.g.,
PixelShaderResourcevsRenderTarget) and automatically inserts barriers. - Thread Safety: All resources are thread-safe by default, with internal locks guarding concurrent access.
Core Hierarchy
Section titled “Core Hierarchy”All GPU objects inherit from GpuResource<T>, which provides standard reference counting and handle management.
graph TD
Resource[GpuResource] --> Buffer[GpuBuffer]
Resource --> Texture[GpuTexture]
Resource --> Pipeline[GpuPipeline]
Resource --> Cmd[GpuCommandBuffer]
Buffer --> Usage{Usage Type}
Usage --> Vertex
Usage --> Index
Usage --> Uniform
Cmd --> Pool[Command Pool]
features
Section titled “features”1. Automatic Barriers
Section titled “1. Automatic Barriers”Developers rarely need to manually insert resource barriers. The GpuCommandBuffer tracks the current state of resources and transitions them lazily.
// Explicit transition (optional)cmd->transitionTexture(texture, ResourceState::ShaderResource);
// Implicit transition via usage// If texture is currently a RenderTarget, a barrier is inserted automatically.cmd->beginRenderPassForTexture(texture, ...);2. Descriptor Management
Section titled “2. Descriptor Management”The API hides the complexity of Descriptor Sets/Tables via Parameter Blocks.
- GpuParameterBlock: Represents a set of bound resources (textures, buffers, samplers).
- Root Binding: Bindings are set by name or index on the block, then the block is bound to the pipeline.
3. Command Buffer Pooling
Section titled “3. Command Buffer Pooling”GpuCommandQueue manages a thread-safe pool of GpuCommandBuffer instances. This minimizes allocation overhead during frame recording.
// Thread-safe allocation from the poolauto cmd = graphicsQueue->allocateCommandBuffer();
// Recording...cmd->beginRenderPass(...);cmd->endRenderPass();cmd->finish();
// SubmitgraphicsQueue->submit(cmd);4. Cross-Thread Validation (Debug)
Section titled “4. Cross-Thread Validation (Debug)”In Debug builds, the abstraction layer validates that:
- A resource is not written to by multiple threads simultaneously.
- Resources are in the correct state before being bound.
- Objects are not destroyed while in use by the GPU.