Does Vulkan require a depth buffer attachment to perform a depth bounds test?

44 Views Asked by At

The behavior I'm hoping to achieve here is to have my fragment shader write to gl_FragDepth and for a depth bounds test to be performed on that value before going on to a stencil test.

There are a few reasons that I'm not sure if this is a valid approach, and the one I'm facing right now is that I'm not positive from the documentation that I'm allowed to use both a stencil buffer and a depth buffer for the same render pass, and if so, how to differentiate between them.

However, I'm not totally convinced that I even need a depth buffer if I'm only using a depth bounds test and no other depth operations. I tried it out and I'm not getting any warnings from the validation layer, but that could be because I have a stencil buffer.

So, to summarize, do I need a depth buffer to do a depth bounds check, and if so, how can I ensure that it's interacting appropriately with the stencil buffer? Or, is this a completely invalid approach?

1

There are 1 best solutions below

0
solidpixel On

I'm allowed to use both a stencil buffer and a depth buffer for the same render pass.

You can.

How to differentiate between them.

They are different attachment points in the render pass, one called depth and one called stencil, so what problem are you having differentiating them?

Fragments must survive both depth test and stencil test (and any other test you have enabled) to get rendered. Depth testing always completes first, because stencil testing requires the depth test result.

BUT "depth bounds test" is something else entirely, and isn't a "depth test", and doesn't interact with stencil testing at all. It's an additional test, on top of depth test and stencil test.

However, I'm not totally convinced that I even need a depth buffer if I'm only using a depth bounds test and no other depth operations.

Depth bounds is a check against the depth currently in the depth buffer (not the depth of the incoming primitive). If you think that you don't need a depth buffer, I don't think you understand what depth bounds testing does. Without a depth buffer it can't do anything useful ...

how can I ensure that it's interacting appropriately with the stencil buffer

See above. The depth of the current fragment is irrelevant to depth bounds testing, so I don't think the feature does what you think it does.