0

Is there any advantage to disabling depth test versus just setting the depth comparison operation to ALWAYS pass? What are the detailed differences between the two? Is disabling depth test more efficient in any way, and how?

Zebrafish
  • 11,682
  • 3
  • 43
  • 119

1 Answers1

1

In OpenGL and in Vulkan, disabling the depth test (as in glDisable(GL_DEPTH_TEST) or setting depthTestEnable = false in the VkPipelineDepthStencilStateCreateInfo) also disables depth writes. So, if you wanted to retain the depth values for later pipeline stages (with whatever depth comparison) you need to have depth test enabled.

httpdigest
  • 5,411
  • 2
  • 14
  • 28
  • Yes, I remember this little quirk when I was working with OpenGL. I'm working with Vulkan now, and the meaning is a little clearer, depth test is just depth test and depth write is just depth write. What I'm wondering is why would I disable the depth test when I can just set the depth comparison operation to ALWAYS pass, that way there's one less state to keep track of / make pipelines for. I want to know what the exact difference is. – Zebrafish Jun 16 '22 at 11:39
  • That answer makes sense for OpenGL where disabling GL_DEPTH_TEST also disables depth writes. In Vulkan, and possibly other APIs disabling depth test just disables depth test, doesn't affect the depth writing. So in essence if you want all pixels to pass, you have two options, 1) disable the depth test, 2) change the comparison operator to pass ALWAYS. Given that (2) does what (1) does (and more), what's the reason for changing the depth test at all if it means one less state to track and create pipelines for? – Zebrafish Jun 16 '22 at 11:49
  • Actually, come to think of it, setting the depth test in Vulkan to true or false probably does the same thing that OpenGL does. Then your answer makes sense. I better check. – Zebrafish Jun 16 '22 at 11:53
  • Hmm, I'd be interested in knowing what the difference is. Keeping track of all the state is a headache and I'd like to minimise it. I just realised I asked a similar question before about OpenGL, https://stackoverflow.com/questions/48658319/opengl-gl-depth-test-vs-gldepthfunc-and-gldepthmask , so now I'm wondering about the same thing for Vulkan. In other words, instead of disabling depth tests, set the comparison operator to ALWAYS and disable depth writes if you really want to disable both. I'm guessing just disabling depth test (which implicitly disables writes) has better performance. – Zebrafish Jun 16 '22 at 12:05
  • I guess the philosophy is you wanted to simplify, then you'd use only the comparison operation and depth writes, and keep depth test (which also writes) always on. That way you're only tracking two variables. But if going the depth test route is faster I'll probably include it. – Zebrafish Jun 16 '22 at 12:08