Table of Contents

Class Buffer<T>

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

All-in-one GPU buffer that is able to represent many types of Buffers (shader Constant Buffers, Structured Buffers, Raw Buffers, Argument Buffers, etc.), but with typed information.

public class Buffer<T> : Buffer, IDisposable, IComponent, IReferencable, ICollectorHolder where T : unmanaged

Type Parameters

T

The type of the elements of the Buffer.

Inheritance
object
Buffer<T>
Implements
Inherited Members
Extension Methods

Remarks

Buffer<T> constains static methods for creating new Buffers with typed information by specifying all their characteristics.

Also look for the following static methods that aid in the creation of specific kinds of Buffers: Buffer.Argument (for Argument Buffers), Buffer.Constant (for Constant Buffers), Buffer.Index (for Index Buffers), Buffer.Raw (for Raw Buffers), Buffer.Structured (for Structured Buffers), Buffer.Typed (for Typed Buffers), and Buffer.Vertex (for Vertex Buffers).

You can also check the methods of Buffer for creating Buffers with the maximum flexibility.

Consult the documentation of your graphics API for more information on each kind of Buffer.

Constructors

Buffer(GraphicsDevice, BufferDescription, BufferFlags, PixelFormat, nint, string?)

Initializes a new instance of typed Buffer<T>.

protected Buffer(GraphicsDevice device, BufferDescription description, BufferFlags bufferFlags, PixelFormat viewFormat, nint dataPointer, string? name = null)

Parameters

device GraphicsDevice

The GraphicsDevice.

description BufferDescription

The description of the Buffer's characteristics.

bufferFlags BufferFlags

The buffer flags to specify the type of Buffer.

viewFormat PixelFormat

View format used if the Buffer is used as a Shader Resource View, or None if not.

dataPointer nint

The data pointer to the initial data the Buffer will contain.

name string

A name for the Buffer, used for debugging purposes. Specify null to not set a name and use the name of the type instead.

Fields

ElementSize

The size of the elements in this Buffer<T> (i.e. the size of T).

public readonly int ElementSize

Field Value

int

Methods

GetData(CommandList)

Gets the contents of the Buffer as an array of data.

public T[] GetData(CommandList commandList)

Parameters

commandList CommandList

The CommandList.

Returns

T[]

An array of data with the contents of the Buffer.

Remarks

This method only works when called from the main thread that is accessing the main GraphicsDevice.

This method creates internally a staging resource (if this Buffer is not already a staging resource), copies to it and map it to memory. Use a method that allows to specify an explicit staging resource for optimal performance.

SetData(CommandList, ref readonly T, int)

Copies the contents an array of data on CPU memory into the Buffer in GPU memory.

public void SetData(CommandList commandList, ref readonly T fromData, int offsetInBytes = 0)

Parameters

commandList CommandList

The CommandList.

fromData T

The data to copy from.

offsetInBytes int

The offset in bytes to write to.

Remarks

Exceptions

ArgumentException

offsetInBytes is only supported for Buffers declared with Default.

SetData(CommandList, T[], int)

Copies the contents of an array of data on CPU memory into the Buffer in GPU memory.

public void SetData(CommandList commandList, T[] fromData, int offsetInBytes = 0)

Parameters

commandList CommandList

The CommandList.

fromData T[]

The array of data to copy from.

offsetInBytes int

The offset in bytes from the start of the Buffer where data is to be written.

Remarks

Exceptions

ArgumentException

offsetInBytes is only supported for Buffers declared with Default.

See Also