From 55a4a6b8dcc8b068d24cc1b1c2e1500369c14485 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 28 Jul 2022 12:20:54 -0400 Subject: [PATCH] zink: handle !half_pixel_center the shader is already getting a -0.5,-0.5 bias, but the viewport also needs to be shifted by 0.5 to match cc: mesa-stable Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_draw.cpp | 9 +++++++++ src/gallium/drivers/zink/zink_state.c | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp index 8e50838..95f108d 100644 --- a/src/gallium/drivers/zink/zink_draw.cpp +++ b/src/gallium/drivers/zink/zink_draw.cpp @@ -585,6 +585,15 @@ zink_draw(struct pipe_context *pctx, CLAMP(ctx->vp_state.viewport_states[i].translate[2] + ctx->vp_state.viewport_states[i].scale[2], 0, 1) }; + if (!ctx->rast_state->base.half_pixel_center) { + /* magic constant value from dxvk */ + float cf = 0.5f - (1.0f / 128.0f); + viewport.x += cf; + if (viewport.height < 0) + viewport.y += cf; + else + viewport.y -= cf; + } viewports[i] = viewport; } if (DYNAMIC_STATE != ZINK_NO_DYNAMIC_STATE) diff --git a/src/gallium/drivers/zink/zink_state.c b/src/gallium/drivers/zink/zink_state.c index ed21b4c..e6783eb 100644 --- a/src/gallium/drivers/zink/zink_state.c +++ b/src/gallium/drivers/zink/zink_state.c @@ -635,6 +635,7 @@ zink_bind_rasterizer_state(struct pipe_context *pctx, void *cso) bool force_persample_interp = ctx->rast_state ? ctx->rast_state->hw_state.force_persample_interp : false; bool clip_halfz = ctx->rast_state ? ctx->rast_state->hw_state.clip_halfz : false; bool rasterizer_discard = ctx->rast_state ? ctx->rast_state->base.rasterizer_discard : false; + bool half_pixel_center = ctx->rast_state ? ctx->rast_state->base.half_pixel_center : true; ctx->rast_state = cso; if (ctx->rast_state) { @@ -679,6 +680,9 @@ zink_bind_rasterizer_state(struct pipe_context *pctx, void *cso) if (ctx->rast_state->base.force_persample_interp != force_persample_interp) zink_set_fs_key(ctx)->force_persample_interp = ctx->rast_state->base.force_persample_interp; ctx->gfx_pipeline_state.force_persample_interp = ctx->rast_state->base.force_persample_interp; + + if (ctx->rast_state->base.half_pixel_center != half_pixel_center) + ctx->vp_state_changed = true; } } -- 2.7.4