The sample shows how to calculate average luminance of an image using parallel reduction, and then apply it to tone mapping. Additionally, blur and bloom effects can be calculated both on compute and pixel shaders (for comparison) and then rendered.
It also demonstrates how to setup and run image post-processing on a compute shader, it modifies a skybox texture by applying to it bloom and blur and toning it. It is based on SDK application by the same name. The program requires Windows 8 and DirectX 11.
The application computes luminance of a skybox texture, which in technical terms is a luminous flux incident on a surface per unit area or a measurement of perceived brightness, before applying it to the final rendered output. The formula to compute luminance is to add up luminance of all individual pixels in the image and divide the sum by the number of pixels.
Mathematically the algorithm is termed as convolution, or an integral that expresses the amount of overlap of one function as it is shifted over another one. When implementing convolution in pixel shader, we read all adjacent pixels for each pixel, multiply values by weight and add them together to derive the result. Compute shader eliminates redundant reads by allowing to load as many pixels as there are threads in each thread group, and then to cache the pixels in shared memory on the device, where each group of threads can work in parallel on a different block of pixels thus significantly improving performance of the algorithm. Shared memory is usually implemented as on-chip registers or a part of on-chip cache and is very fast to access.
In this example, each pixel in shared memory is loaded only once from input image using texture read.
Please find the code and better documentation on the MSDN Code Gallery.