Class GpuBuffer<T>

java.lang.Object
dev.engine.graphics.GpuBuffer<T>
Type Parameters:
T - the record type

public class GpuBuffer<T> extends Object
A typed GPU buffer backed by a Java record type.

Combines a GPU buffer handle with a StructLayout for automatic serialization, and a SlangStructGenerator for shader code generation. Single source of truth: the record defines CPU layout, GPU layout, and shader struct.

  • Method Details

    • create

      public static <T> GpuBuffer<T> create(RenderDevice device, Class<T> type, BufferUsage usage, AccessPattern access)
      Creates a single-element GPU buffer from a record type.
    • createArray

      public static <T> GpuBuffer<T> createArray(RenderDevice device, Class<T> type, int capacity, BufferUsage usage, AccessPattern access)
      Creates an array GPU buffer that can hold multiple elements.
    • write

      public void write(T value)
      Writes a single record to the buffer (for single-element buffers).
    • write

      public void write(int index, T value)
      Writes a record at the given index (for array buffers).
    • handle

      public Handle<BufferResource> handle()
      GPU buffer handle for binding.
    • type

      public Class<T> type()
      The record type this buffer holds.
    • layout

      public StructLayout layout()
      The struct layout used for serialization.
    • capacity

      public int capacity()
      Maximum number of elements.
    • elementSize

      public int elementSize()
      Size of a single element in bytes.
    • totalSize

      public long totalSize()
      Total buffer size in bytes.
    • slangStructSource

      public String slangStructSource()
      Generates the Slang struct definition for this buffer's type.
    • slangCbuffer

      public String slangCbuffer(String name, int binding)
      Generates a Slang cbuffer declaration for this buffer.
    • slangFullSource

      public String slangFullSource()
      Generates Slang source for this type and all dependencies.
    • destroy

      public void destroy()
      Destroys the GPU buffer.