diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c index c1fa0106431..8433b5c62ef 100644 --- a/src/gallium/drivers/zink/zink_clear.c +++ b/src/gallium/drivers/zink/zink_clear.c @@ -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 */ diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp index dff057dc5c2..743531e4a1b 100644 --- a/src/gallium/drivers/zink/zink_draw.cpp +++ b/src/gallium/drivers/zink/zink_draw.cpp @@ -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; }