[Mesa-dev] [PATCH] gallium/util: Fix off-by-one in box intersection

Boris Brezillon boris.brezillon at collabora.com
Fri Feb 22 13:19:55 UTC 2019


From: Daniel Stone <daniels at collabora.com>

pipe_boxes are x/y + width/height, rather than x0/y0 -> x1/y1. This
means that (x+width) is not included in the box.

The box intersection check was seemingly written for inclusive regions,
and would falsely assert that adjacent boxes would overlap.

Fix the off-by-one by being one pixel less greedy.

Signed-off-by: Daniel Stone <daniels at collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon at collabora.com>
---
 src/gallium/auxiliary/util/u_box.h | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h
index b3f478e7bfc4..ead7189ecaf8 100644
--- a/src/gallium/auxiliary/util/u_box.h
+++ b/src/gallium/auxiliary/util/u_box.h
@@ -161,15 +161,15 @@ u_box_test_intersection_2d(const struct pipe_box *a,
    unsigned i;
    int a_l[2], a_r[2], b_l[2], b_r[2];
 
-   a_l[0] = MIN2(a->x, a->x + a->width);
-   a_r[0] = MAX2(a->x, a->x + a->width);
-   a_l[1] = MIN2(a->y, a->y + a->height);
-   a_r[1] = MAX2(a->y, a->y + a->height);
+   a_l[0] = MIN2(a->x, a->x + a->width - 1);
+   a_r[0] = MAX2(a->x, a->x + a->width - 1);
+   a_l[1] = MIN2(a->y, a->y + a->height - 1);
+   a_r[1] = MAX2(a->y, a->y + a->height - 1);
 
-   b_l[0] = MIN2(b->x, b->x + b->width);
-   b_r[0] = MAX2(b->x, b->x + b->width);
-   b_l[1] = MIN2(b->y, b->y + b->height);
-   b_r[1] = MAX2(b->y, b->y + b->height);
+   b_l[0] = MIN2(b->x, b->x + b->width - 1);
+   b_r[0] = MAX2(b->x, b->x + b->width - 1);
+   b_l[1] = MIN2(b->y, b->y + b->height - 1);
+   b_r[1] = MAX2(b->y, b->y + b->height - 1);
 
    for (i = 0; i < 2; ++i) {
       if (a_l[i] > b_r[i] || a_r[i] < b_l[i])
-- 
2.20.1



More information about the mesa-dev mailing list