Can I prevent GPU fragment stalling with a stencil buffer?

293 views Asked by At

I have some heavy duty calculations on the fragment shader, and this in multiple passes. But on some fragments, the result is ready after one pass only, and for other fragments, it takes more passes.

Because of this, lots of fragments do discards after a while, but as we know, these are threads probably stalling until all the other fragments have completed.

I was wondering. Since some opengl version, it is possible to write to the stencil buffer from the fragment shader. When I know I don't need another pass on a specific fragment, I could possible write to the stencil buffer. In the next rendering pass, I could turn on stencil testing to prevent those fragment from calculating again.

My question: will this prevent the stalling-problem? Will these threads become available to perform more of the still-to-be-processed fragments so that each pass will be faster than the previous when each pass eliminates fragments for the next pass?

In other words, say that I have a 16x16 texture I need to calculate. In the first pass, I will have to calculate 256 fragments (say that I have 16 cores, this would mean 16 cycles). If for example after this first pass, I know that I only need to calculate further on 128 fragments, and I have marked the fragments that are done in the stencil buffer, will this second pass perform twice as fast (so: 128 fragments on 16 cores = 8 cycles instead of 16)?

0

There are 0 answers