Mesa (main): llvmpipe: adjust rounding for viewport scissoring

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 18 20:01:12 UTC 2021


Module: Mesa
Branch: main
Commit: b7e2214b3c89490181685dded4480f2bd04d1990
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b7e2214b3c89490181685dded4480f2bd04d1990

Author: Roland Scheidegger <sroland at vmware.com>
Date:   Mon Nov 15 18:27:44 2021 +0100

llvmpipe: adjust rounding for viewport scissoring

Some apps may try to use a viewport adjusted by 0.5 pixels (among other
things) to emulate d3d9 pixel center, and in this case we would end up
with incorrect "fake scissor" box (shifted by 1 pixel), hence pixels
being incorrectly scissored away when permit_linear_rasterizer is set
(this happens even if the linear rasterizer is not used in the end).

So adjust the offset so that the half-way points get rounded down instead
of up.
(This is all a bit iffy I think since we don't use fractional
boxes (with 8 subpixel bits) anywhere yet, but at least without msaa
it should work out.)

Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13794>

---

 src/gallium/drivers/llvmpipe/lp_setup.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index 50f3cea7b00..c2a4617c313 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -922,10 +922,10 @@ lp_setup_set_viewports(struct lp_setup_context *setup,
    half_height = fabsf(viewports[0].scale[1]);
    x0 = viewports[0].translate[0] - viewports[0].scale[0];
    y0 = viewports[0].translate[1] - half_height;
-   setup->vpwh.x0 = (int)(x0 + 0.5f);
-   setup->vpwh.x1 = (int)(viewports[0].scale[0] * 2.0f + x0 - 0.5f);
-   setup->vpwh.y0 = (int)(y0 + 0.5f);
-   setup->vpwh.y1 = (int)(half_height * 2.0f + y0 - 0.5f);
+   setup->vpwh.x0 = (int)(x0 + 0.499f);
+   setup->vpwh.x1 = (int)(viewports[0].scale[0] * 2.0f + x0 - 0.501f);
+   setup->vpwh.y0 = (int)(y0 + 0.499f);
+   setup->vpwh.y1 = (int)(half_height * 2.0f + y0 - 0.501f);
    setup->dirty |= LP_SETUP_NEW_SCISSOR;
 
    /*



More information about the mesa-commit mailing list