nil: Add an offset4d struct and some helpers
authorFaith Ekstrand <faith.ekstrand@collabora.com>
Tue, 31 Jan 2023 02:12:02 +0000 (20:12 -0600)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:32:01 +0000 (21:32 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/nil/nil_image.c
src/nouveau/nil/nil_image.h

index bdc517d..b5dee00 100644 (file)
@@ -40,6 +40,28 @@ nil_extent4d_mul(struct nil_extent4d a, struct nil_extent4d b)
    };
 }
 
+static struct nil_offset4d
+nil_offset4d_div_round_down(struct nil_offset4d num, struct nil_extent4d denom)
+{
+   return (struct nil_offset4d) {
+      .x = num.x / denom.w,
+      .y = num.y / denom.h,
+      .z = num.z / denom.d,
+      .a = num.a / denom.a,
+   };
+}
+
+static struct nil_offset4d
+nil_offset4d_mul(struct nil_offset4d a, struct nil_extent4d b)
+{
+   return (struct nil_offset4d) {
+      .x = a.x * b.w,
+      .y = a.y * b.h,
+      .z = a.z * b.d,
+      .a = a.a * b.a,
+   };
+}
+
 static struct nil_extent4d
 nil_extent4d_align(struct nil_extent4d ext, struct nil_extent4d align)
 {
@@ -96,6 +118,17 @@ nil_extent4d_px_to_el(struct nil_extent4d extent_px,
    return nil_extent4d_div_round_up(extent_sa, nil_el_extent_sa(format));
 }
 
+struct nil_offset4d
+nil_offset4d_px_to_el(struct nil_offset4d offset_px,
+                      enum pipe_format format,
+                      enum nil_sample_layout sample_layout)
+{
+   const struct nil_offset4d offset_sa =
+      nil_offset4d_mul(offset_px, nil_px_extent_sa(sample_layout));
+
+   return nil_offset4d_div_round_down(offset_sa, nil_el_extent_sa(format));
+}
+
 static struct nil_extent4d
 nil_extent4d_el_to_B(struct nil_extent4d extent_el,
                      uint32_t B_per_el)
index cf92f05..0171b47 100644 (file)
@@ -71,6 +71,29 @@ nil_extent4d_px_to_el(struct nil_extent4d extent_px,
                       enum pipe_format format,
                       enum nil_sample_layout sample_layout);
 
+struct nil_offset4d {
+   uint32_t x;
+   uint32_t y;
+   uint32_t z;
+   uint32_t a;
+};
+
+static inline struct nil_offset4d
+nil_offset4d(uint32_t x, uint32_t y, uint32_t z, uint32_t a)
+{
+   struct nil_offset4d o;
+   o.x = x;
+   o.y = y;
+   o.z = z;
+   o.a = a;
+   return o;
+}
+
+struct nil_offset4d
+nil_offset4d_px_to_el(struct nil_offset4d offset_px,
+                      enum pipe_format format,
+                      enum nil_sample_layout sample_layout);
+
 #define NIL_GOB_WIDTH_B 64
 #define NIL_GOB_HEIGHT(gob_height_8) ((gob_height_8) ? 8 : 4)
 #define NIL_GOB_DEPTH 1