Graphics Reference
In-Depth Information
Figure 5.4. The threading structure for the sample compute shader program.
Notice that in the code listing, the size of the thread group is declared with the
numthreads function attribute. This is followed by the function definition that represents
the processing kernel for our compute shader. In the arguments to this function, we specify
which system values we would like to receive to use for our addressing scheme. Since
there is some redundancy in the system values (there is more than one way to identify each
thread), we have some freedom in choosing which ones would be the most efficient or
advantageous to use. Tn this case, we can simply use the SV_DispatchThreadID and use
its X -component to provide a linear index into our buffer resource. This thread addressing
structure can be visualized as shown in Figure 5.4.
With SV_DispatchThreadID, we can directly use its X -component as the index
when reading from the buffer resource. The buffer can be accessed with the normal square
bracket array syntax. We would bind the resource to the compute shader stage with an un-
ordered access view (UAV), which allows each thread to read the float value, double it, and
then write it back to the same resource. The dispatch thread ID provides a trivially simple
way to have each thread access the elements of a resource, only leaving the developer to
determine how large of a dispatch call to make.
Search WWH ::




Custom Search