DirectCompute Compute Shader Functions
DirectCompute exposes a set of intrinsic functions that can be used directly within your HLSL compute shaders. These functions provide low-level access to GPU hardware capabilities, enabling optimized parallel processing.
Core Compute Shader Functions
Dispatch(x, y, z)
Dispatches a grid of thread groups for execution on the GPU.
GetGroupThreadID()
Returns the unique thread ID within the current thread group.
GetGroupID()
Returns the unique ID of the current thread group within the dispatch grid.
GetGroupSize()
Returns the dimensions (number of threads) of the current thread group.
Load(address)
Loads data from a structured buffer or texture at a specific memory address.
Store(address, value)
Stores data to a structured buffer or texture at a specific memory address.
InterlockedAdd()
Performs an atomic addition operation on a memory location.
InterlockedExchange()
Performs an atomic exchange operation on a memory location.
SyncThread()
Synchronizes threads within a thread group, ensuring all previous memory operations are visible to subsequent operations.
WaveReadLaneFirst()
Reads a value from the first active lane in the current wavefront.
Resource Access Functions
These functions are crucial for interacting with various GPU resources like buffers and textures.
Texture2D.Load()
Loads a texel from a 2D texture at a specified coordinate.
RWTexture2D.Write()
Writes a value to a read/write 2D texture at a specified coordinate.
Buffer.Load()
Loads data from a raw buffer at a specific byte offset.
RWBuffer.Store()
Stores data to a read/write raw buffer at a specific byte offset.
Mathematical Functions
Standard mathematical operations are also available for complex calculations within shaders.
dot(a, b)
Calculates the dot product of two vectors.
length(v)
Calculates the magnitude (length) of a vector.
normalize(v)
Returns a normalized version of a vector (length 1).
lerp(a, b, t)
Performs linear interpolation between two values.
sin(x), cos(x), tan(x)
Trigonometric functions.