agx: Add agx_format_shift routine
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 24 Jul 2021 21:45:38 +0000 (17:45 -0400)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 24 Jul 2021 21:45:38 +0000 (17:45 -0400)
Required to calculate alignments for vertex buffers correctly.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12053>

src/asahi/compiler/agx_compile.h

index fe5bc42..6e8b14a 100644 (file)
@@ -118,6 +118,39 @@ enum agx_format {
    AGX_NUM_FORMATS,
 };
 
+/* Returns the number of bits at the bottom of the address required to be zero.
+ * That is, returns the base-2 logarithm of the minimum alignment for an
+ * agx_format, where the minimum alignment is 2^n where n is the result of this
+ * function. The offset argument to device_load is left-shifted by this amount
+ * in the hardware */
+
+static inline unsigned
+agx_format_shift(enum agx_format format)
+{
+   switch (format) {
+   case AGX_FORMAT_I8:
+   case AGX_FORMAT_U8NORM:
+   case AGX_FORMAT_S8NORM:
+   case AGX_FORMAT_SRGBA8:
+      return 0;
+
+   case AGX_FORMAT_I16:
+   case AGX_FORMAT_F16:
+   case AGX_FORMAT_U16NORM:
+   case AGX_FORMAT_S16NORM:
+      return 1;
+
+   case AGX_FORMAT_I32:
+   case AGX_FORMAT_RGB10A2:
+   case AGX_FORMAT_RG11B10F:
+   case AGX_FORMAT_RGB9E5:
+      return 2;
+
+   default:
+      unreachable("invalid format");
+   }
+}
+
 struct agx_attribute {
    uint32_t divisor;