PDA

View Full Version : Stencil Test Useless and slower



Christoph.LGDV
06-23-2016, 09:15 AM
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.

mhagain
06-23-2016, 09:43 AM
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.

Christoph.LGDV
06-23-2016, 11:51 AM
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.

mhagain
06-24-2016, 02:43 AM
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.

Christoph.LGDV
06-24-2016, 08:41 AM
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?

Alfonse Reinheart
06-24-2016, 09:14 AM
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.

skynet
06-25-2016, 10:39 PM
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).

Christoph.LGDV
06-28-2016, 03:01 AM
Thank you for your advices.

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