Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Use the following syntax to declare a buffer variable.
Buffer<Type> Name; |
---|
Parameters
-
Buffer
-
Required keyword.
-
Type
-
One of the scalar, vector, and some matrix HLSL types. You can declare a buffer variable with a matrix as long as it fits in 4 32-bit quantities. So, you can write
Buffer<float2x2>
. ButBuffer<float4x4>
is too large, and the compiler will generate an error. -
Name
-
An ASCII string that uniquely identifies the variable name.
Example
Here is an example of a buffer declaration.
Buffer<float4> g_Buffer;
Data is read from a buffer using an overloaded version of the Load HLSL intrinsic function that takes one input parameter (an integer index). A buffer is accessed like an array of elements; therefore, this example reads the second element.
float4 bufferData = g_Buffer.Load( 1 );
Use the stream-output stage to output data to a buffer.
Remarks
A compatible typed buffer shader resource view (SRV) is required to correctly load from the buffer. The load can optionally perform a type conversion, for example an RGBA8_UNORM buffer can be loaded into a float4
variable. For a buffer contaning structs, use a StructuredBuffer instead.