Graphics Reference
In-Depth Information
which is similar to the indirect rendering methods we have already seen in Chapter 3. The
Dispatch method is analogous to the many draw call calls from the rendering pipeline.
It takes three unsigned integer parameters as input: x, y, and z. These three parameters
indicate how many groups of threads we would like to "dispatch" to execute the desired
processing kernel. These three parameters provide the dimensions of a three-dimensional
array of thread groups that will be instantiated, and the size of each parameter can range
from 1 to 64k. For example, if an application calls Dispatch (4,6,2), a total of 4*6*2 = 48
thread groups will be created. Each group of threads would be identified by a unique set of
indices within the specified dispatch arguments, ranging from 0 to size-1 in each of the
three dimensions.
Notice that the dispatch call defines how many groups of threads are instantiated,
and not how many threads are instantiated. The number of threads instantiated is defined
by specifying how many threads will be created for each thread group with a numthreads
HLSL function attribute preceding the compute shader program in its source code file. As
in the dispatch call, this numthreads statement also defines the size of a three dimen-
sional array, except that this array is made up of threads instead of thread groups. The size
of each of these parameters is dependent on the shader model being used, but for cs_5_0
the x and y components must be greater than or equal to 1, the z component must be be-
tween 1 and 64, while the total number of threads (x*y*z) cannot exceed 1024. The state-
ment shown in Listing 5.1 is an example of how this numthreads statement must appear in
the HLSL shader program.
[numthreads( 10, 10, 2 )]
// Shader kernel definition follows...
Listing 5.1. The number of threads per thread group declaration.
With this example, a total of 10*10*2 = 200 threads will be instantiated for each
thread group. Each of these threads can also be uniquely identified by its integer indices,
ranging from 0 to size-1 in each of the three dimensions. If we use the dispatch call
example from above, we would have a total of 48*200 = 6,400 threads instantiated for this
dispatch call.
However, with the three dimensional method of specifying and identifying these
threads, we can think of their organization in a geometric way. Consider the visualization
of a thread group shown in Figure 5.1.
Instead of thinking of the threads in our dispatch call as a linear list of 6,400 threads,
we can instead use the thread group size to provide a spatial orientation for each thread.
Since each thread has a unique identifier, it is easy to reference one particular thread within
Search WWH ::




Custom Search