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@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17319>
This commit is contained in:
Mike Blumenkrantz 2022-06-30 13:54:42 -04:00 committed by Marge Bot
parent 1334d39b36
commit 90c5eea22b
2 changed files with 15 additions and 5 deletions

View File

@ -444,7 +444,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 */

View File

@ -569,10 +569,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;
}