Mesa (staging/21.3): gallium/util: Add pixel->blocks box helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jan 11 20:34:39 UTC 2022


Module: Mesa
Branch: staging/21.3
Commit: ded1bca25a15989aca01bff4aca5e22a34afd8f1
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ded1bca25a15989aca01bff4aca5e22a34afd8f1

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Tue Jan  4 16:16:06 2022 -0500

gallium/util: Add pixel->blocks box helper

There is a lot of unit confusion in Gallium due to pixels versus blocks
matching only with uncompressed textures. Add a helper to do a common
pixels->blocks unit conversion required in multiple drivers.

v2: Rename dst->blocks, src->pixels to avoid confusion about the units
to casual readers (Mike).

Note to mesa-stable maintainers: this is marked as Cc: mesa-stable so
the next patch (a set of bug fixes for Lima and Panfrost) can be
backported. It's not a bug fix in its own right, of course.

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Reviewed-by: Emma Anholt <emma at anholt.net> [v1]
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14370>
(cherry picked from commit 26c533f16783aa7f01ea6f3b6f040de9c483cac7)

---

 .pick_status.json                  |  2 +-
 src/gallium/auxiliary/util/u_box.h | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index 4ec319f85bb..7793b3878a4 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -319,7 +319,7 @@
         "description": "gallium/util: Add pixel->blocks box helper",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/gallium/auxiliary/util/u_box.h b/src/gallium/auxiliary/util/u_box.h
index 764bf5037a5..c39e139646a 100644
--- a/src/gallium/auxiliary/util/u_box.h
+++ b/src/gallium/auxiliary/util/u_box.h
@@ -3,6 +3,7 @@
 
 #include "pipe/p_state.h"
 #include "util/u_math.h"
+#include "util/format/u_format.h"
 
 static inline void
 u_box_1d(unsigned x, unsigned w, struct pipe_box *box)
@@ -239,4 +240,22 @@ u_box_minify_3d(struct pipe_box *dst,
    dst->depth = MAX2(src->depth >> l, 1);
 }
 
+/* Converts a box specified in pixels to an equivalent box specified
+ * in blocks, where the boxes represent a region-of-interest of an image with
+ * the given format. This is trivial (a copy) for uncompressed formats.
+ */
+static inline void
+u_box_pixels_to_blocks(struct pipe_box *blocks,
+                       const struct pipe_box *pixels, enum pipe_format format)
+{
+   u_box_3d(
+         pixels->x / util_format_get_blockwidth(format),
+         pixels->y / util_format_get_blockheight(format),
+         pixels->z,
+         DIV_ROUND_UP(pixels->width, util_format_get_blockwidth(format)),
+         DIV_ROUND_UP(pixels->height, util_format_get_blockheight(format)),
+         pixels->depth,
+         blocks);
+}
+
 #endif



More information about the mesa-commit mailing list