Compute Shader Structures
This section details the structures used within DirectCompute shaders, providing the building blocks for data manipulation and configuration.
Buffer Structures
These structures are commonly used to define and interact with various types of buffers accessible by compute shaders.
StructuredBuffer<T>
Represents a buffer of elements of type T. The elements are accessible by index.
AppendConsumeBuffer<T>
A specialized buffer that allows for append and consume operations. Useful for dynamic data generation.
ByteAddressBuffer
A buffer accessible by byte address. Allows for arbitrary data access.
Shader Resource Views (SRVs) and Unordered Access Views (UAVs)
While not strictly structures defined within HLSL, the concepts of SRVs and UAVs are fundamental to how buffers and textures are accessed by compute shaders. They are typically bound to specific shader registers.
Common SRV Structures (Implicitly Bound)
Texture1D<T>,Texture2D<T>,Texture3D<T>,TextureCube<T>: For reading from texture resources.Buffer<T>: A generic buffer, often used for simple data arrays.ByteAddressBuffer: As described above, for byte-level access.StructuredBuffer<T>: As described above, for structured data.
Common UAV Structures (Implicitly Bound)
RWTexture1D<T>,RWTexture2D<T>,RWTexture3D<T>,RWTextureCube<T>: For read/write access to texture resources.RWBuffer<T>: For read/write access to generic buffers.RWByteAddressBuffer: For read/write access at the byte level.RWStructuredBuffer<T>: For read/write access to structured buffers.AppendConsumeBuffer<T>: As described above, for append/consume operations.
System-Defined Structures
These structures provide access to hardware and dispatch information within the shader.
Input data for Thread Group Shared Variables
While not a direct structure, shared memory is allocated and accessed using specific syntax.
[numthreads(X, Y, Z)]
void CSMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
// Shared memory is declared using static arrays
static float shared_data[1024];
// ... shader logic ...
}
SV_DispatchThreadID
A 3-component unsigned integer vector that identifies the current thread's dispatch ID.
Type: uint3
SV_GroupThreadID
A 3-component unsigned integer vector that identifies the current thread's ID within its thread group.
Type: uint3
SV_ThreadGroupID
A 3-component unsigned integer vector that identifies the current thread group's ID within the dispatch.
Type: uint3
SV_ThreadID
Deprecated. Use SV_DispatchThreadID instead.
SV_GroupSize
A 3-component unsigned integer vector that indicates the size of the thread group (defined by the [numthreads] attribute).
Type: uint3
SV_DispatchSize
A 3-component unsigned integer vector that indicates the total number of thread groups in the dispatch.
Type: uint3
SV_IsFrontFace
A boolean indicating if the current fragment is on the front face of a primitive. Primarily used in pixel shaders, but may be available in certain compute contexts.
Type: bool