Graphics Reference
In-Depth Information
each of the threads of a dispatch call with a unique identifier from within a thread group,
or from within the entire dispatch call. It is also trivial to identify a thread group from
within a dispatch call. It turns out that this is the exact mechanism that is used in the com-
puter shader to inform each thread about what it should be working on.
When authoring the shader program, the developer can specify a number of system
value semantics as input parameters for the shader function, which provide an identifier for
that particular invocation. The list of available system value semantics is provided below,
with a short explanation of each of their meanings.
SV_GroupID: Defines the 3D identifier (uint3) for which thread group within a dis-
patch a thread belongs to.
SV_GroupThreadID: Defines the 3D identifier (uint3) for a thread within its own
thread group.
SV_DispatchThreadID: Defines the 3D identifier (uint3) for a thread within the en-
tire dispatch.
SV_GroupIndex: Defines a flattened 1D index (uint) for which thread group a thread
belongs to.
Once each thread invocation has this identifier information, the developer can use
that identifier to determine what portion of the input data set should be processed by each
thread. To see the utility of such a processing scheme, it is beneficial to consider an ex-
ample. One simple example would be a compute shader that doubles the value of every ele-
ment within a Buffer<float> resource. If the buffer contains 2,000 elements, then we could
define a thread group size of [20,1,1], which is dispatched with [100,1,1] thread groups.
Listing 5.2 shows what the compute shader would look like for this example.
Buffer<float> InputBuf : register( t0 );
RWBuffer<fIoat> OutputBuf : register( u0 );
// Group size
#define size_x 20
#define size_y 1
// Declare one thread for each texel of the input texture.
[numthreads(size_x, size_y, 1)]
void CSMAIN( uint3 DispatchThreadID : SV_DispatchThreadID )
{
float Value = InputBuf.Load( DispatchThreadID.x );
OutputBuf[DispatchThreadID.x] = 2.0f * Value;
}
Listing 5.2. A sample compute shader for doubling the contents of a buffer resource.
Search WWH ::




Custom Search