Looking how to utilize as much parallelization processing as possible for the following task:

A screen-sized texture is completely black except for blue pixels which are in close proximity to geometry edges (this is a game scene). So at a given time, a small percentage of the texture is blue. This texture represents a mask that only colors pixels near an edge. Each blue pixel can access four unique subsample values of the depth buffer. For each subsample, I need to calculate the difference between its own depth value and the depth value of all of its surrounding subsamples (up to two or three pixels away, not sure yet), check if the difference is greater than a threshold value, and if so, store the distance between those two subsamples. Finally, find the minimum distance stored. This generates an SDF value which describes how close that subsample is to an 'edge.' The image illustrates one of these groups of comparisons. This has to be performed again for every subsample.enter image description here

This is obviously a very large task which is why I am trying to utilize the parallel processing capabilities of a compute shader. I want to disperse the calculations to as many threads as possible, in order to avoid a small number of threads performing very large loops but I am challenged to find a way to organize the calculations so that only nearby subsamples are compared with each other.

I originally thought of having the blue pixels send out groups of values into an appendbuffer (where the element type would be an array), and then each thread could look-up the array in that appendbuffer that corresponds to its index (ie appendbuffer[(globalID.y * screenWidth) + globalID.x)]) and find the minimum distance for the values in that array. The trouble comes after this step though. I would need to then find the minimum of THOSE minimums to find the absolute minimum, and there doesn't seem to be an obvious way to keep arrays for the same subsample stored adjacently in the appendbuffer. Therefore there is not an obvious logic to ensure that the correct minimums are compared with each other. Adding values to an append buffer is never done in a predictable order. This approach might also be suboptimal in terms of cache coherency

I am not a graphics programmer (or any programmer for that matter) by profession. Hoping someone with a lot of experience can weigh in here and give a good recommendation. I am measuring the compute shader's performance in RenderDoc



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.