From 3d0ae7a9dab839823a47da228c40935667e05ca0 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Wed, 23 Sep 2020 21:35:03 +1200 Subject: [PATCH] panfrost: Handle non-positive viewport positions It's possible for viewport positions to be negative, so add a lower bound of zero and avoid wraparound when maximum values are zero. Fixes the menu blur effect in the OpenGL 3.3 render of GZDoom. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 45ce9897f50..5a8cbde773e 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -605,10 +605,10 @@ panfrost_emit_viewport(struct panfrost_batch *batch) /* Scissor to the intersection of viewport and to the scissor, clamped * to the framebuffer */ - unsigned minx = MIN2(fb->width, vp_minx); - unsigned maxx = MIN2(fb->width, vp_maxx); - unsigned miny = MIN2(fb->height, vp_miny); - unsigned maxy = MIN2(fb->height, vp_maxy); + unsigned minx = MIN2(fb->width, MAX2((int) vp_minx, 0)); + unsigned maxx = MIN2(fb->width, MAX2((int) vp_maxx, 0)); + unsigned miny = MIN2(fb->height, MAX2((int) vp_miny, 0)); + unsigned maxy = MIN2(fb->height, MAX2((int) vp_maxy, 0)); if (ss && rast->scissor) { minx = MAX2(ss->minx, minx); @@ -617,9 +617,15 @@ panfrost_emit_viewport(struct panfrost_batch *batch) maxy = MIN2(ss->maxy, maxy); } + /* Set the range to [1, 1) so max values don't wrap round */ + if (maxx == 0 || maxy == 0) + maxx = maxy = minx = miny = 1; + struct panfrost_transfer T = panfrost_pool_alloc(&batch->pool, MALI_VIEWPORT_LENGTH); pan_pack(T.cpu, VIEWPORT, cfg) { + /* [minx, maxx) and [miny, maxy) are exclusive ranges, but + * these are inclusive */ cfg.scissor_minimum_x = minx; cfg.scissor_minimum_y = miny; cfg.scissor_maximum_x = maxx - 1;