From f5f759cff8a1b24336596974f1c5f1b4e02b726c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 27 May 2021 22:51:09 -0400 Subject: [PATCH] asahi: Fix off-by-one in viewport scissoring As discovered during the stream. Typo pointed out by someone in the Twitch chat. Fixes: f285a1220ea ("asahi: Implement scissors and scissor to viewport") Signed-off-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/asahi/agx_state.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 4ca466a..b978803 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -465,16 +465,23 @@ agx_upload_viewport_scissor(struct agx_pool *pool, { struct agx_ptr T = agx_pool_alloc_aligned(pool, AGX_VIEWPORT_LENGTH, 64); - unsigned minx = CLAMP((int) vp->translate[0] - fabsf(vp->scale[0]), 0, batch->width); - unsigned maxx = CLAMP((int) vp->translate[0] + fabsf(vp->scale[0]), 0, batch->width); - unsigned miny = CLAMP((int) vp->translate[1] - fabsf(vp->scale[1]), 0, batch->height); - unsigned maxy = CLAMP((int) vp->translate[1] + fabsf(vp->scale[1]), 0, batch->height); + float trans_x = vp->translate[0], trans_y = vp->translate[1]; + float abs_scale_x = fabsf(vp->scale[0]), abs_scale_y = fabsf(vp->scale[1]); + + /* Calculate the extent of the viewport. Note if a particular dimension of + * the viewport is an odd number of pixels, both the translate and the scale + * will have a fractional part of 0.5, so adding and subtracting them yields + * an integer. Therefore we don't need to round explicitly */ + unsigned minx = CLAMP((int) (trans_x - abs_scale_x), 0, batch->width); + unsigned miny = CLAMP((int) (trans_y - abs_scale_y), 0, batch->height); + unsigned maxx = CLAMP((int) (trans_x + abs_scale_x), 0, batch->width); + unsigned maxy = CLAMP((int) (trans_y + abs_scale_y), 0, batch->height); if (ss) { - minx = MAX2(ss->minx, minx); - miny = MAX2(ss->miny, miny); - maxx = MIN2(ss->maxx, maxx); - maxy = MIN2(ss->maxy, maxy); + minx = MAX2(ss->minx, minx); + miny = MAX2(ss->miny, miny); + maxx = MIN2(ss->maxx, maxx); + maxy = MIN2(ss->maxy, maxy); } assert(maxx > minx && maxy > miny); -- 2.7.4