agx: Extract coordinate register size calculation
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 19 May 2023 17:07:25 +0000 (13:07 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 23 Jun 2023 17:37:41 +0000 (17:37 +0000)
It will be used for image writes too, not just reads.

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

src/asahi/compiler/agx_register_allocate.c

index 9f07416..7751ffe 100644 (file)
@@ -72,6 +72,38 @@ agx_split_width(const agx_instr *I)
    return width;
 }
 
+/*
+ * Return number of registers required for coordinates for a
+ * texture/image instruction. We handle layer + sample index as 32-bit even when
+ * only the lower 16-bits are present.
+ */
+static unsigned
+agx_coordinate_registers(const agx_instr *I)
+{
+   switch (I->dim) {
+   case AGX_DIM_1D:
+      return 2 * 1;
+   case AGX_DIM_1D_ARRAY:
+      return 2 * 2;
+   case AGX_DIM_2D:
+      return 2 * 2;
+   case AGX_DIM_2D_ARRAY:
+      return 2 * 3;
+   case AGX_DIM_2D_MS:
+      return 2 * 3;
+   case AGX_DIM_3D:
+      return 2 * 3;
+   case AGX_DIM_CUBE:
+      return 2 * 3;
+   case AGX_DIM_CUBE_ARRAY:
+      return 2 * 4;
+   case AGX_DIM_2D_MS_ARRAY:
+      return 2 * 3;
+   }
+
+   unreachable("Invalid texture dimension");
+}
+
 unsigned
 agx_read_registers(const agx_instr *I, unsigned s)
 {
@@ -106,31 +138,7 @@ agx_read_registers(const agx_instr *I, unsigned s)
    case AGX_OPCODE_TEXTURE_LOAD:
    case AGX_OPCODE_TEXTURE_SAMPLE:
       if (s == 0) {
-         /* Coordinates. We handle layer + sample index as 32-bit even when only
-          * the lower 16-bits are present.
-          */
-         switch (I->dim) {
-         case AGX_DIM_1D:
-            return 2 * 1;
-         case AGX_DIM_1D_ARRAY:
-            return 2 * 2;
-         case AGX_DIM_2D:
-            return 2 * 2;
-         case AGX_DIM_2D_ARRAY:
-            return 2 * 3;
-         case AGX_DIM_2D_MS:
-            return 2 * 3;
-         case AGX_DIM_3D:
-            return 2 * 3;
-         case AGX_DIM_CUBE:
-            return 2 * 3;
-         case AGX_DIM_CUBE_ARRAY:
-            return 2 * 4;
-         case AGX_DIM_2D_MS_ARRAY:
-            return 2 * 3;
-         }
-
-         unreachable("Invalid texture dimension");
+         return agx_coordinate_registers(I);
       } else if (s == 1) {
          /* LOD */
          if (I->lod_mode == AGX_LOD_MODE_LOD_GRAD) {