Graphics Reference
In-Depth Information
Figure 10.6. Processing an image with a square tile sized thread group, with an example size of 8×8 tiles.
the size of the image to be filtered. If we are processing a 640×480 image, the dispatch
size would be [20,15,1]. This tile-based thread group size is demonstrated in Figure 10.6.
In general, choosing the thread group size to be a common factor of the available render
target sizes is a good initial choice, which will allow the filter shader program to be reused
for multiple image sizes.
For the purposes of our first sample, we will assume a 7×7 filter kernel size. The filter
is provided as static constants in the shader file, which can be accessed as a two dimen-
sional array of values. Within the shader program, we will use the dispatch thread ID to al-
low each thread to choose which pixel it will be processing. This is trivial to perform, since
the dispatch thread ID will span a range that exactly matches the size of image. Indeed,
this is done by design to ensure that we can use this thread addressing scheme! Once each
thread is aware of which pixel it should be processing, we can read the input image data
for each of the pixels that are needed in our filter kernel. Each pixel value is multiplied by
the corresponding filter kernel weight, and all of these products are summed to produce the
resultant pixel value for the output image. The output value is stored in the output texture at
Search WWH ::




Custom Search