DirectCompute Compute Shader Functions

Explore the essential functions that power your compute shaders within the DirectX ecosystem. These functions enable efficient parallel computation on the GPU for a wide range of applications, from physics simulations to image processing.

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.

void Dispatch(uint3 groupCountX, uint3 groupCountY, uint3 groupCountZ);

GetGroupThreadID()

Returns the unique thread ID within the current thread group.

uint3 GetGroupThreadID();

GetGroupID()

Returns the unique ID of the current thread group within the dispatch grid.

uint3 GetGroupID();

GetGroupSize()

Returns the dimensions (number of threads) of the current thread group.

uint3 GetGroupSize();

Load(address)

Loads data from a structured buffer or texture at a specific memory address.

T Load(StructuredBuffer buffer, uint index);

Store(address, value)

Stores data to a structured buffer or texture at a specific memory address.

void Store(StructuredBuffer buffer, uint index, T value);

InterlockedAdd()

Performs an atomic addition operation on a memory location.

uint InterlockedAdd(inout uint dest, uint value, out uint original_dest);

InterlockedExchange()

Performs an atomic exchange operation on a memory location.

uint InterlockedExchange(inout uint dest, uint value, out uint original_dest);

SyncThread()

Synchronizes threads within a thread group, ensuring all previous memory operations are visible to subsequent operations.

void SyncThreads();

WaveReadLaneFirst()

Reads a value from the first active lane in the current wavefront.

uint WaveReadLaneFirst(uint value);

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.

float4 Texture2D.Load(int2 location);

RWTexture2D.Write()

Writes a value to a read/write 2D texture at a specified coordinate.

void RWTexture2D.Write(float4 value, int2 location);

Buffer.Load()

Loads data from a raw buffer at a specific byte offset.

uint Buffer.Load(uint offset);

RWBuffer.Store()

Stores data to a read/write raw buffer at a specific byte offset.

void RWBuffer.Store(uint offset, uint value);

Mathematical Functions

Standard mathematical operations are also available for complex calculations within shaders.

dot(a, b)

Calculates the dot product of two vectors.

float dot(float2 a, float2 b);

length(v)

Calculates the magnitude (length) of a vector.

float length(float3 v);

normalize(v)

Returns a normalized version of a vector (length 1).

float3 normalize(float3 v);

lerp(a, b, t)

Performs linear interpolation between two values.

float lerp(float a, float b, float t);

sin(x), cos(x), tan(x)

Trigonometric functions.

float sin(float angle);