Stencil Test Useless and slower

Hello,

my Problem:

I render for the Vive using GL4.5.

Now I want to use the stencil to cull fragments.

I have a GL_DEPTH32F_STENCIL8 attachment, set the stencil once and then render.
My Fragment Shader is texturing only.

However using Stencil actually hurts: frame time drops from 3.8 to 4ms for simple views and from 13 to 15 ms in (depth) complex views.

That does not sound quite right.

(NVIDIA GTX970)

Some insight is appreciated.

What happens if you use GL_DEPTH24_STENCIL8?

GL_DEPTH32F_STENCIL8 is actually a 64-bit format, so will require twice the bandwidth for some operations. GL_DEPTH24_STENCIL8 on the other hand can be interleaved in a single 32-bit value.

Hello and thank you for your reply.
I was not aware about 64 bit formats but it sounds reasonable.

Nevertheless, the problem remains with GL_DEPTH24_STENCIL8 as well.

Another common problem is that you should normally clear both depth and stencil at the same time; i.e:

glClear (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

With an interleaved format this is a faster clear because it doesn’t need to preserve the contents of one of the buffers.

That sounds reasonable as well, but makes the entire notion of stencil culling in VR useless, as I would need to draw the stencil each frame (or without stencil direcly into depth).

Is there a separate format or are Stencil and Depth too intertwined on HW?

makes the entire notion of stencil culling in VR useless

The stencil test isn’t a feature that exists solely for VR use.

Also, how complex is your stencil pattern that redrawing it every frame is an expensive operation?

Is there a separate format or are Stencil and Depth too intertwined on HW?

Let’s put it this way.

The Vulkan specification does not require implementations to support any stencil-only format. They are however required to support at least one combined depth/stencil format.

And Vulkan as a specification doesn’t even allow you to use separate depth and stencil buffers in the framebuffer. Framebuffers and subpasses only have a single attachment location for combined depth/stencil. And therefore, you can only use one image, which contains either depth, stencil, or depth/stencil.

You’re not allowed to have separate depth and stencil images to be used for depth and stencil operations.

Another option: Try not using the stencil buffer at all. Just render the hidden area mesh into the depth buffer with depth=0 (assuming you’re using a standard depth buffer setup).

Thank you for your advices.

I would have ended with the depth buffer option as well.