1
\$\begingroup\$

I've been trying to implement Valve's VR checkerboard rendering technique (original document) and was wondering which way would be the best to proceed.

The thing is that I need to "abort" the execution of 2x2 blocks of fragments in a checkerboard pattern considering how GPUs work in blocks of pixels.

I've thought of several approaches which are the following :

  • Discard fragments in the fragment shader using a condition like this one :
float mod2 = gl_FragCoord.x + gl_FragCoord.y;
float res = mod(mod2, 2.0f);
if (res == 0.0f)
   discard;
  • Use the stencil buffer and write a checkerboard pattern on it using an image or such.

  • Use some kind of clipping method where I have several quads in front of the camera forming a checkerboard pattern.

The first approach seems to be the worse because I have to branch and after, discard fragments. And considering the fact that GPUs work in blocks of 2x2 pixels, I need to find a way to abort block by block so that I don't get the fragment shader processed anyway (even with a discard). And I'm not even sure this would force a block to abort and skip the fragment shader.

The second method seems OK, but I'm not sure if there's a better way to do it. Would the fragment shader be processed anyway ?

The third seems to need to process more polygons which is not really a good idea I guess even though it does not require a lot of processing considering they would be simple quads.

What would be the most efficient method (listed here or not) for skipping these blocks ?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Can you olease add a link to the original resource? \$\endgroup\$ – Bálint Oct 12 '16 at 9:51
  • \$\begingroup\$ @Bálint: Well I only checked used the first link I provided. But I'll try to find the original and edit my question. EDIT: Done. \$\endgroup\$ – CpCd0y Oct 12 '16 at 10:04
1
\$\begingroup\$

The answer is in the source you linked:

Clip() 2x2 pixel quads as you render, or fill stencil or depth with a 2x2 checker pattern and render

and also

Skip rending a checker pattern of 2x2 pixel quads to match current GPU architectures

In other words, it should work, theoretically, but you better test there is an actual increase of performance. I'd also expect if + discard to work, but just like the other methods, I'd want to test and verify first if it actually results in a performance increase.

\$\endgroup\$
2
  • \$\begingroup\$ Well, I tried the if + discard, but I almost had worse performance because of the branching, I suppose. So, with the stencil method, would I have the guarantee that these fragments would be skipped ? Also, I'd try to avoid changing the depth buffer, to avoid not benefiting from early-z rejection :/ \$\endgroup\$ – CpCd0y Oct 12 '16 at 11:31
  • \$\begingroup\$ @CpCd0y Branching "should" be completely irrelevant if the entire quad takes the same branch, and the card is moderately new. My understanding is that the stencil method is more likely to work if conditional discard doesn't, but I haven't done something like this before, that's why I unfortunately need to defer to "test and verify". \$\endgroup\$ – Peter Oct 12 '16 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.