Graphics Reference
In-Depth Information
Once we have executed the shader function, we copy the result from the GPU
histogramResult buffer into the histogramCPU resource that is accessible from
the CPU. In order to be able to read the resource from the CPU, we have created the
resource with the following settings:
cpuReadDesc.CpuAccessFlags = CpuAccessFlags.Read;
cpuReadDesc.Usage = ResourceUsage.Staging;
Once the result has been copied to the CPU accessible resource, we can then map it to a
system memory location and read the data for whatever purpose we need. Transferring data
from the GPU to CPU is slow and mapping the subresource can stall until the GPU is ready.
C# can incur additional overhead if not careful, resulting in an extra memory copy operation.
If the resource is correctly protected from further use, the actual reading of the data once
mapped could potentially occur within another thread, but care must be taken, and the
unmapping of the resource must be done in a thread-safe manner for the device context.
There's moreā€¦
It might be tempting to try to use the group-shared memory for the histogram calculation;
however, our threads potentially need to write to any address and a thread is only allowed to
write to its own region of the group memory without synchronization. Any thread synchronization
would most likely defeat any potential performance gains. Reading from the same location in
shared memory across multiple threads is allowed.
 
Search WWH ::




Custom Search