Mesa (master): gallium/util: Add new u_box helpers
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sat Mar 13 21:39:03 UTC 2021
Module: Mesa
Branch: master
Commit: 26a9e2bb15aaac0957a0be493d9634c82a1fa6c5
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=26a9e2bb15aaac0957a0be493d9634c82a1fa6c5
Author: Axel Davy <davyaxel0 at gmail.com>
Date: Sat Mar 6 17:34:22 2021 +0100
gallium/util: Add new u_box helpers
Signed-off-by: Axel Davy <davyaxel0 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9451>
---
src/gallium/auxiliary/util/u_box.h | 39 ++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
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,
More information about the mesa-commit
mailing list