diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h index b3f478e7bfc..764bf5037a5 100644 --- a/src/gallium/auxiliary/util/u_box.h +++ b/src/gallium/auxiliary/util/u_box.h @@ -119,6 +119,45 @@ u_box_volume_3d(const struct pipe_box *box) return (int64_t)box->width * box->height * box->depth; } +/* Aliasing of @dst permitted. Supports empty width */ +static inline void +u_box_union_1d(struct pipe_box *dst, + const struct pipe_box *a, const struct pipe_box *b) +{ + int x, width; + + if (a->width == 0) { + x = b->x; + width = b->width; + } else if (b->width == 0) { + x = a->x; + width = a->width; + } else { + x = MIN2(a->x, b->x); + width = MAX2(a->x + a->width, b->x + b->width) - x; + } + + dst->x = x; + dst->width = width; +} + +/* Aliasing of @dst permitted. */ +static inline void +u_box_intersect_1d(struct pipe_box *dst, + const struct pipe_box *a, const struct pipe_box *b) +{ + int x; + + x = MAX2(a->x, b->x); + + dst->width = MIN2(a->x + a->width, b->x + b->width) - x; + dst->x = x; + if (dst->width <= 0) { + dst->x = 0; + dst->width = 0; + } +} + /* Aliasing of @dst permitted. */ static inline void u_box_union_2d(struct pipe_box *dst,