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

Gurchetan Singh gurchetansingh at chromium.org
Wed Feb 27 18:34:26 UTC 2019


On Mon, Feb 25, 2019 at 12:35 AM Boris Brezillon
<boris.brezillon at collabora.com> wrote:
>
> 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.

Is there a reason for this change?  I only see this used in a warning
in the nine state tracker and virgl (where reporting adjacent
intersections is preferred).

>
> 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
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list