panfrost: XMLify bifrost1

It's so poorly understood there's not much to do in this commit, sadly.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6440>
diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index 6ab8090..c214dd6 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -322,10 +322,17 @@
         meta->sampler_count = ctx->sampler_count[st];
 
         if (dev->quirks & IS_BIFROST) {
-                meta->bifrost1.unk1 = 0x800000;
+                struct mali_bifrost_properties_packed prop;
+
+                pan_pack(&prop, BIFROST_PROPERTIES, cfg) {
+                        cfg.unknown = 0x800000; /* XXX */
+                        cfg.uniform_buffer_count = panfrost_ubo_count(ctx, st);
+                }
+
+                memcpy(&meta->bifrost_props, &prop, sizeof(prop));
+
                 meta->bifrost2.preload_regs = 0xC0;
                 meta->bifrost2.uniform_count = ss->uniform_count;
-                meta->bifrost1.uniform_buffer_count = panfrost_ubo_count(ctx, st);
         } else {
                 struct mali_midgard_properties_packed prop;
 
@@ -564,11 +571,21 @@
         fragmeta->sampler_count = ctx->sampler_count[PIPE_SHADER_FRAGMENT];
 
         if (dev->quirks & IS_BIFROST) {
-                /* First clause ATEST |= 0x4000000.
-                 * Lefs than 32 regs |= 0x200 */
-                fragmeta->bifrost1.unk1 = 0x950020;
+                struct mali_bifrost_properties_packed prop;
 
-                fragmeta->bifrost1.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT);
+                bool no_blend = true;
+
+                for (unsigned i = 0; i < rt_count; ++i)
+                        no_blend &= (!blend[i].load_dest | blend[i].no_colour);
+
+                pan_pack(&prop, BIFROST_PROPERTIES, cfg) {
+                        cfg.unknown = 0x950020; /* XXX */
+                        cfg.uniform_buffer_count = panfrost_ubo_count(ctx, PIPE_SHADER_FRAGMENT);
+                        cfg.early_z_enable = !fs->can_discard && !fs->writes_depth && no_blend;
+                }
+
+                memcpy(&fragmeta->bifrost_props, &prop, sizeof(prop));
+
                 fragmeta->bifrost2.preload_regs = 0x1;
                 SET_BIT(fragmeta->bifrost2.preload_regs, 0x10, fs->reads_frag_coord);
 
@@ -730,16 +747,6 @@
                         break;
                 }
         }
-
-        if (dev->quirks & IS_BIFROST) {
-                bool no_blend = true;
-
-                for (unsigned i = 0; i < rt_count; ++i)
-                        no_blend &= (!blend[i].load_dest | blend[i].no_colour);
-
-                SET_BIT(fragmeta->bifrost1.unk1, MALI_BIFROST_EARLY_Z,
-                        !fs->can_discard && !fs->writes_depth && no_blend);
-        }
 }
 
 void
diff --git a/src/panfrost/bifrost/test/bi_submit.c b/src/panfrost/bifrost/test/bi_submit.c
index 85837eb..3688e2b 100644
--- a/src/panfrost/bifrost/test/bi_submit.c
+++ b/src/panfrost/bifrost/test/bi_submit.c
@@ -175,10 +175,7 @@
                 .shader = shader->gpu,
                 .attribute_count = 1,
                 .varying_count = 1,
-                .bifrost1 = {
-                        .unk1 = 0x800200,
-                        .uniform_buffer_count = 1,
-                },
+                .bifrost_props = { .opaque = { 0x80020001 } },
                 .bifrost2 = {
                         .unk3 = 0x0,
                         .preload_regs = 0xc0,
diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h
index ae15785..af70f56 100644
--- a/src/panfrost/include/panfrost-job.h
+++ b/src/panfrost/include/panfrost-job.h
@@ -193,27 +193,6 @@
 #define MALI_CHANNEL_FLOAT 7
 #define MALI_EXTRACT_BITS(fmt) (fmt & 0x7)
 
-/* Flags for bifrost1.unk1 */
-
-/* Shader uses less than 32 registers, partitioned as [R0, R15] U [R48, R63],
- * allowing for full thread count. If clear, the full [R0, R63] register set is
- * available at half thread count */
-#define MALI_BIFROST_FULL_THREAD (1 << 9)
-
-/* Enable early-z testing (presumably). This flag may not be set if the shader:
- *
- *  - Uses blending
- *  - Uses discard
- *  - Writes gl_FragDepth
- *
- * This differs from Midgard which sets the MALI_EARLY_Z flag even with
- * blending, although I've begun to suspect that flag does not in fact enable
- * EARLY_Z alone. */
-#define MALI_BIFROST_EARLY_Z (1 << 15)
-
-/* First clause type is ATEST */
-#define MALI_BIFROST_FIRST_ATEST (1 << 26)
-
 /* The raw Midgard blend payload can either be an equation or a shader
  * address, depending on the context */
 
@@ -322,10 +301,7 @@
         u16 varying_count;
 
         union {
-                struct {
-                        u32 uniform_buffer_count : 4;
-                        u32 unk1 : 28; // = 0x800000 for vertex, 0x958020 for tiler
-                } bifrost1;
+                struct mali_bifrost_properties_packed bifrost_props;
                 struct mali_midgard_properties_packed midgard_props;
         };
 
diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c
index 53f6f30..6b2e71a 100644
--- a/src/panfrost/lib/decode.c
+++ b/src/panfrost/lib/decode.c
@@ -279,16 +279,6 @@
 };
 #undef FLAG_INFO
 
-#define FLAG_INFO(flag) { MALI_BIFROST_##flag, "MALI_BIFROST_" #flag }
-static const struct pandecode_flag_info shader_bifrost_info [] = {
-        FLAG_INFO(FULL_THREAD),
-        FLAG_INFO(EARLY_Z),
-        FLAG_INFO(FIRST_ATEST),
-        {}
-};
-
-#undef FLAG_INFO
-
 #define FLAG_INFO(flag) { MALI_MFBD_##flag, "MALI_MFBD_" #flag }
 static const struct pandecode_flag_info mfbd_flag_info [] = {
         FLAG_INFO(DEPTH_WRITE),
@@ -1740,6 +1730,7 @@
                         info = pandecode_shader_disassemble(s->shader & ~0xF, job_no, job_type, is_bifrost, gpu_id);
 
                 struct MALI_MIDGARD_PROPERTIES midg_props;
+                struct MALI_BIFROST_PROPERTIES bi_props;
 
                 pandecode_log("struct mali_shader_meta shader_meta_%"PRIx64"_%d%s = {\n", p->shader, job_no, suffix);
                 pandecode_indent++;
@@ -1751,8 +1742,11 @@
                 sampler_count = s->sampler_count;
 
                 if (is_bifrost) {
+                        uint32_t opaque = s->bifrost_props.opaque[0];
+                        MALI_BIFROST_PROPERTIES_unpack((const uint8_t *) &opaque, &bi_props);
+
                         uniform_count = s->bifrost2.uniform_count;
-                        uniform_buffer_count = s->bifrost1.uniform_buffer_count;
+                        uniform_buffer_count = bi_props.uniform_buffer_count;
                 } else {
                         uint32_t opaque = s->midgard_props.opaque[0];
                         MALI_MIDGARD_PROPERTIES_unpack((const uint8_t *) &opaque, &midg_props);
@@ -1768,13 +1762,10 @@
                 pandecode_shader_prop("attribute_count", s->attribute_count, info.attribute_count, false);
                 pandecode_shader_prop("varying_count", s->varying_count, info.varying_count, false);
 
-                if (is_bifrost) {
-                        pandecode_log("bifrost1.unk1 = ");
-                        pandecode_log_decoded_flags(shader_bifrost_info, s->bifrost1.unk1);
-                        pandecode_log_cont(",\n");
-                } else {
+                if (is_bifrost)
+                        MALI_BIFROST_PROPERTIES_print(pandecode_dump_stream, &bi_props, 2);
+                else
                         MALI_MIDGARD_PROPERTIES_print(pandecode_dump_stream, &midg_props, 2);
-                }
 
                 if (s->depth_units || s->depth_factor) {
                         pandecode_prop("depth_factor = %f", s->depth_factor);
diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml
index 42e2623..352398b 100644
--- a/src/panfrost/lib/midgard.xml
+++ b/src/panfrost/lib/midgard.xml
@@ -353,6 +353,16 @@
     <field name="Suppress Inf/NaN" size="1" start="29" type="bool"/>
   </struct>
 
+  <struct name="Bifrost Properties" size="1">
+    <field name="Uniform buffer count" size="8" start="0" type="uint"/>
+    <!--- If set, disables registers [R16, R47] for full thread count -->
+    <field name="Full thread" size="1" start="13" type="bool" default="false"/>
+    <field name="Early-z enable" size="1" start="19" type="bool" default="false"/>
+    <field name="First ATEST" size="1" start="30" type="bool" default="false"/>
+    <!-- XXX: This is awful -->
+    <field name="Unknown" size="32" start="0" type="uint"/>
+  </struct>
+
   <struct name="Stencil">
     <field name="Reference Value" size="8" start="0" type="uint"/>
     <field name="Mask" size="8" start="8" type="uint" default="0xFF"/>