From 912e203a534be8b70b3ef8bf00294e9c962e385a Mon Sep 17 00:00:00 2001 From: Lucas Fryzek Date: Tue, 19 Mar 2024 08:29:02 -0400 Subject: [PATCH] drisw: clamp damage region to texture bounds Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/frontends/dri/drisw.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gallium/frontends/dri/drisw.c b/src/gallium/frontends/dri/drisw.c index caf020d17f2..958660ffeba 100644 --- a/src/gallium/frontends/dri/drisw.c +++ b/src/gallium/frontends/dri/drisw.c @@ -246,7 +246,15 @@ drisw_swap_buffers_with_damage(struct dri_drawable *drawable, int nrects, const for (unsigned int i = 0; i < nrects; i++) { const int *rect = &rects[i * 4]; - u_box_2d(rect[0], ptex->height0 - rect[1] - rect[3], rect[2], rect[3], &stack_boxes[i]); + int w = MIN2(rect[2], ptex->width0); + int h = MIN2(rect[3], ptex->height0); + int x = CLAMP(rect[0], 0, ptex->width0); + int y = CLAMP(ptex->height0 - rect[1] - h, 0, ptex->height0); + + if (h > ptex->height0 - y) + h = ptex->height0 - y; + + u_box_2d(x, y, w, h, &stack_boxes[i]); } }