Skip to content

zink: Fix depth.

Timur Kristóf requested to merge Venemo/mesa:zink_depth into main

Fixes some depth related test failures listed here: #6243 (closed)

Details of the problem:

  • Vulkan spec chapter 28.10.1. Depth Clamping and Range Adjustment says that the driver should ignore minDepth / maxDepth when depthClampEnable == false. Zink mixes up depth clipping and depth clamping. It doesn't always enable depth clamping which means that the depth range in the viewport was not actually respected.
  • Also, when gl_FragmentDepth is not in the [0; 1] range and depthClampEnable == false then the depth value is undefined according to the VK spec. Some of the failing tests hit this undefined behaviour here.
  • Note that the undefined behaviour allows the Vulkan driver to clamp the depth to [0; 1] (and some drivers do), which make it appear as if Zink were working properly. However, if there were any OpenGL tests which set a different depth range than [0; 1] using glDepthRange then these would still fail.

The solution I propose here is this:

  • Set depthClampEnable to always true in Zink, to ensure the Vulkan driver always respects the viewport minDepth/maxDepth settings.
  • Make depth clipping independent of depth clamping, use VK_EXT_depth_clip_enable for depth clipping.
  • Finally, there is also a fix to the Gallium blitter to make sure that the viewport transform it sets doesn't disturb the depth range. (Previously, maxDepth was 0.0 in some blits, which was again at the mercy of Vulkan undefined behaviour and would be borken now that depth clamping is always enabled.)

Merge request reports