panfrost: Break up usage2 field

This is another bit field describing layout.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 689aeae..6392989 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -569,33 +569,23 @@
         }
 }
 
-static unsigned
-panfrost_layout_for_texture(struct panfrost_resource *rsrc, bool manual_stride)
+static enum mali_texture_layout
+panfrost_layout_for_texture(struct panfrost_resource *rsrc)
 {
         /* TODO: other linear depth textures */
         bool is_depth = rsrc->base.format == PIPE_FORMAT_Z32_UNORM;
 
-        unsigned usage2_layout = 0x10;
-
         switch (rsrc->layout) {
         case PAN_AFBC:
-                usage2_layout |= 0x8 | 0x4;
-                break;
+                return MALI_TEXTURE_AFBC;
         case PAN_TILED:
-                usage2_layout |= 0x1;
-                break;
+                assert(!is_depth);
+                return MALI_TEXTURE_TILED;
         case PAN_LINEAR:
-                usage2_layout |= is_depth ? 0x1 : 0x2;
-                break;
+                return is_depth ? MALI_TEXTURE_TILED : MALI_TEXTURE_LINEAR;
         default:
-                assert(0);
-                break;
+                unreachable("Invalid texture layout");
         }
-
-        if (manual_stride)
-                usage2_layout |= MALI_TEX_MANUAL_STRIDE;
-
-        return usage2_layout;
 }
 
 static mali_ptr
@@ -633,7 +623,8 @@
         /* Add the usage flags in, since they can change across the CSO
          * lifetime due to layout switches */
 
-        view->hw.format.usage2 = panfrost_layout_for_texture(rsrc, has_manual_stride);
+        view->hw.format.layout = panfrost_layout_for_texture(rsrc);
+        view->hw.format.manual_stride = has_manual_stride;
 
         /* Inject the addresses in, interleaving mip levels, cube faces, and
          * strides in that order */
@@ -2254,7 +2245,6 @@
          * (data) itself. So, we serialise the descriptor here and cache it for
          * later. */
 
-        /* TODO: Detect from format better */
         const struct util_format_description *desc = util_format_description(prsrc->base.format);
 
         unsigned char user_swizzle[4] = {
@@ -2309,6 +2299,7 @@
                         .format = format,
                         .srgb = desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB,
                         .type = panfrost_translate_texture_type(template->target),
+                        .unknown2 = 0x1,
                 },
 
                 .swizzle = panfrost_translate_swizzle_4(user_swizzle)
diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h
index 43c7c37..694680a 100644
--- a/src/panfrost/include/panfrost-job.h
+++ b/src/panfrost/include/panfrost-job.h
@@ -1179,10 +1179,21 @@
 /* For each pointer, there is an address and optionally also a stride */
 #define MAX_ELEMENTS (2)
 
-/* Corresponds to the type passed to glTexImage2D and so forth */
+/* It's not known why there are 4-bits allocated -- this enum is almost
+ * certainly incomplete */
 
-/* Flags for usage2 */
-#define MALI_TEX_MANUAL_STRIDE (0x20)
+enum mali_texture_layout {
+        /* For a Z/S texture, this is linear */
+        MALI_TEXTURE_TILED = 0x1,
+
+        /* Z/S textures cannot be tiled */
+        MALI_TEXTURE_LINEAR = 0x2,
+
+        /* 16x16 sparse */
+        MALI_TEXTURE_AFBC = 0xC
+};
+
+/* Corresponds to the type passed to glTexImage2D and so forth */
 
 struct mali_texture_format {
         unsigned swizzle : 12;
@@ -1192,8 +1203,15 @@
         unsigned unknown1 : 1;
 
         enum mali_texture_type type : 2;
+        enum mali_texture_layout layout : 4;
 
-        unsigned usage2 : 8;
+        /* Always set */
+        unsigned unknown2 : 1;
+
+        /* Set to allow packing an explicit stride */
+        unsigned manual_stride : 1;
+
+        unsigned zero : 2;
 } __attribute__((packed));
 
 struct mali_texture_descriptor {
diff --git a/src/panfrost/pandecode/decode.c b/src/panfrost/pandecode/decode.c
index f14cc80..9918ba6 100644
--- a/src/panfrost/pandecode/decode.c
+++ b/src/panfrost/pandecode/decode.c
@@ -1812,11 +1812,17 @@
         pandecode_log_cont(",\n");
 
         pandecode_prop("type = %s", pandecode_texture_type(f.type));
-        pandecode_prop("usage2 = 0x%" PRIx32, f.usage2);
+        pandecode_prop("layout = %" PRId32, f.layout);
 
-        if (f.unknown1) {
+        if (f.unknown1 | f.zero) {
                 pandecode_msg("XXX: texture format zero tripped\n");
                 pandecode_prop("unknown1 = %" PRId32, f.unknown1);
+                pandecode_prop("zero = %" PRId32, f.zero);
+        }
+
+        if (!f.unknown2) {
+                pandecode_msg("XXX: expected unknown texture bit set\n");
+                pandecode_prop("unknown2 = %" PRId32, f.unknown1);
         }
 
         pandecode_indent--;
@@ -1846,7 +1852,6 @@
          * possibilities to futureproof */
 
         int bitmap_count = MALI_NEGATIVE(t->levels);
-        bool manual_stride = f.usage2 & MALI_TEX_MANUAL_STRIDE;
 
         /* Miptree for each face */
         if (f.type == MALI_TEX_CUBE)
@@ -1856,7 +1861,7 @@
         bitmap_count *= MALI_NEGATIVE(t->array_size);
 
         /* Stride for each element */
-        if (manual_stride)
+        if (f.manual_stride)
                 bitmap_count *= 2;
 
         /* Sanity check the size */
@@ -1866,7 +1871,7 @@
         for (int i = 0; i < bitmap_count; ++i) {
                 /* How we dump depends if this is a stride or a pointer */
 
-                if ((f.usage2 & MALI_TEX_MANUAL_STRIDE) && (i & 1)) {
+                if (f.manual_stride && (i & 1)) {
                         /* signed 32-bit snuck in as a 64-bit pointer */
                         uint64_t stride_set = t->payload[i];
                         uint32_t clamped_stride = stride_set;