Skip to content

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.

The abstraction is built on three core pillars:

  1. Safety via RAII: All GPU resources follow strict ownership semantics using RefObject and makeRef.
  2. Automatic State Management: The system tracks resource states (e.g., PixelShaderResource vs RenderTarget) and automatically inserts barriers.
  3. Thread Safety: All resources are thread-safe by default, with internal locks guarding concurrent access.

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]

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, ...);

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.

GpuCommandQueue manages a thread-safe pool of GpuCommandBuffer instances. This minimizes allocation overhead during frame recording.

// Thread-safe allocation from the pool
auto cmd = graphicsQueue->allocateCommandBuffer();
// Recording...
cmd->beginRenderPass(...);
cmd->endRenderPass();
cmd->finish();
// Submit
graphicsQueue->submit(cmd);

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.