Mesa (staging/22.1): zink: enforce viewport depth clamping

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 6 17:04:12 UTC 2022


Module: Mesa
Branch: staging/22.1
Commit: 040658cd26477892977f48a2dbf0469c780ce9ab
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=040658cd26477892977f48a2dbf0469c780ce9ab

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Thu Jun 30 13:54:42 2022 -0400

zink: enforce viewport depth clamping

VUID-VkViewport-minDepth-01234 specifies that depth must be in the range [0.0, 1.0],
so the viewport must always be clamped to this range

this affects texture clears using u_blitter, as this expects to be able
to use the GL range of [-1.0, 1.0], so pass the depth value as though it's
been de-converted back to a GL z coordinate to account for viewport transform

cc: mesa-stable

fixes #6757

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17319>
(cherry picked from commit 90c5eea22b69306e463decd405029944b4a0d53b)

---

 .pick_status.json                      |  2 +-
 src/gallium/drivers/zink/zink_clear.c  | 10 +++++++++-
 src/gallium/drivers/zink/zink_draw.cpp | 10 ++++++----
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index e4d19ab376b..aac27f7946a 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1237,7 +1237,7 @@
         "description": "zink: enforce viewport depth clamping",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c
index 3975447e292..bdb9efad8f7 100644
--- a/src/gallium/drivers/zink/zink_clear.c
+++ b/src/gallium/drivers/zink/zink_clear.c
@@ -443,7 +443,15 @@ zink_clear_texture(struct pipe_context *pctx,
             flags |= PIPE_CLEAR_STENCIL;
          surf = create_clear_surface(pctx, pres, level, box);
          zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS);
-         util_blitter_clear_depth_stencil(ctx->blitter, surf, flags, depth, stencil, box->x, box->y, box->width, box->height);
+         /* Vulkan requires depth to be in the range of [0.0, 1.0], while GL uses
+          * the viewport range of [-1.0, 1.0], creating a mismatch during u_blitter rendering;
+          * to account for this, de-convert depth back to GL for viewport transform:
+
+            depth = (depth * 2) - 1
+
+          * this yields the correct result after the viewport has been clamped
+          */
+         util_blitter_clear_depth_stencil(ctx->blitter, surf, flags, (depth * 2) - 1, stencil, box->x, box->y, box->width, box->height);
       }
    }
    /* this will never destroy the surface */
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 6f62d07a25b..ae48c0e8bcb 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -627,10 +627,12 @@ zink_draw(struct pipe_context *pctx,
             ctx->vp_state.viewport_states[i].translate[1] - ctx->vp_state.viewport_states[i].scale[1],
             MAX2(ctx->vp_state.viewport_states[i].scale[0] * 2, 1),
             ctx->vp_state.viewport_states[i].scale[1] * 2,
-            ctx->rast_state->base.clip_halfz ?
-               ctx->vp_state.viewport_states[i].translate[2] :
-               ctx->vp_state.viewport_states[i].translate[2] - ctx->vp_state.viewport_states[i].scale[2],
-            ctx->vp_state.viewport_states[i].translate[2] + ctx->vp_state.viewport_states[i].scale[2]
+            CLAMP(ctx->rast_state->base.clip_halfz ?
+                  ctx->vp_state.viewport_states[i].translate[2] :
+                  ctx->vp_state.viewport_states[i].translate[2] - ctx->vp_state.viewport_states[i].scale[2],
+                  0, 1),
+            CLAMP(ctx->vp_state.viewport_states[i].translate[2] + ctx->vp_state.viewport_states[i].scale[2],
+                  0, 1)
          };
          viewports[i] = viewport;
       }



More information about the mesa-commit mailing list