panfrost: XMLify MSAA writeout mode
[mesa.git] / src / panfrost / lib / decode.c
index 4126ec546506a273217e682fb5380f3fa83d9993..6538b47f8a3d75d45af535fdbf52b845cb74fec1 100644 (file)
@@ -453,22 +453,6 @@ static char *pandecode_format(enum mali_format format)
 
 #undef DEFINE_CASE
 
-#define DEFINE_CASE(name) case MALI_MSAA_ ## name: return "MALI_MSAA_" #name
-static char *
-pandecode_msaa_mode(enum mali_msaa_mode mode)
-{
-        switch (mode) {
-                DEFINE_CASE(SINGLE);
-                DEFINE_CASE(AVERAGE);
-                DEFINE_CASE(MULTIPLE);
-                DEFINE_CASE(LAYERED);
-        default:
-                unreachable("Impossible");
-                return "";
-        }
-}
-#undef DEFINE_CASE
-
 static char *pandecode_attr_mode_short(enum mali_attr_mode mode)
 {
         switch(mode) {
@@ -510,22 +494,6 @@ pandecode_special_record(uint64_t v, bool* attribute)
         }
 }
 
-#define DEFINE_CASE(name) case MALI_BLOCK_## name: return "MALI_BLOCK_" #name
-static char *
-pandecode_block_format(enum mali_block_format fmt)
-{
-        switch (fmt) {
-                DEFINE_CASE(TILED);
-                DEFINE_CASE(UNKNOWN);
-                DEFINE_CASE(LINEAR);
-                DEFINE_CASE(AFBC);
-
-        default:
-                unreachable("Invalid case");
-        }
-}
-#undef DEFINE_CASE
-
 #define DEFINE_CASE(name) case MALI_EXCEPTION_ACCESS_## name: return ""#name
 static char *
 pandecode_exception_access(unsigned access)
@@ -718,7 +686,7 @@ pandecode_sfbd_format(struct mali_sfbd_format format)
         pandecode_log_decoded_flags(sfbd_unk2_info, format.unk2);
         pandecode_log_cont(",\n");
 
-        pandecode_prop("block = %s", pandecode_block_format(format.block));
+        pandecode_prop("block = %s", mali_block_format_as_str(format.block));
 
         pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
 
@@ -1029,7 +997,7 @@ pandecode_rt_format(struct mali_rt_format format)
         pandecode_prop("unk3 = 0x%" PRIx32, format.unk3);
         pandecode_prop("unk4 = 0x%" PRIx32, format.unk4);
 
-        pandecode_prop("block = %s", pandecode_block_format(format.block));
+        pandecode_prop("block = %s", mali_block_format_as_str(format.block));
 
         /* TODO: Map formats so we can check swizzles and print nicely */
         pandecode_log("swizzle");
@@ -1043,7 +1011,7 @@ pandecode_rt_format(struct mali_rt_format format)
         pandecode_log_decoded_flags(mfbd_fmt_flag_info, format.flags);
         pandecode_log_cont(",\n");
 
-        pandecode_prop("msaa = %s", pandecode_msaa_mode(format.msaa));
+        pandecode_prop("msaa = %s", mali_msaa_as_str(format.msaa));
 
         /* In theory, the no_preload bit can be cleared to enable MFBD preload,
          * which is a faster hardware-based alternative to the wallpaper method
@@ -1080,7 +1048,7 @@ pandecode_render_target(uint64_t gpu_va, unsigned job_no, const struct mali_fram
 
                 pandecode_rt_format(rt->format);
 
-                if (rt->format.block == MALI_BLOCK_AFBC) {
+                if (rt->format.block == MALI_BLOCK_FORMAT_AFBC) {
                         pandecode_log(".afbc = {\n");
                         pandecode_indent++;
 
@@ -1261,10 +1229,10 @@ pandecode_mfbd_bfr(uint64_t gpu_va, int job_no, bool is_fragment, bool is_comput
                 pandecode_log_decoded_flags(mfbd_extra_flag_lo_info, fbx->flags_lo);
                 pandecode_log_cont(",\n");
 
-                pandecode_prop("zs_block = %s", pandecode_block_format(fbx->zs_block));
+                pandecode_prop("zs_block = %s", mali_block_format_as_str(fbx->zs_block));
                 pandecode_prop("zs_samples = MALI_POSITIVE(%u)", fbx->zs_samples + 1);
 
-                if (fbx->zs_block == MALI_BLOCK_AFBC) {
+                if (fbx->zs_block == MALI_BLOCK_FORMAT_AFBC) {
                         pandecode_log(".ds_afbc = {\n");
                         pandecode_indent++;
 
@@ -2034,7 +2002,7 @@ pandecode_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
 
 static void
 pandecode_texture_payload(mali_ptr payload,
-                          enum mali_texture_type type,
+                          enum mali_texture_dimension dim,
                           enum mali_texture_layout layout,
                           bool manual_stride,
                           uint8_t levels,
@@ -2054,14 +2022,14 @@ pandecode_texture_payload(mali_ptr payload,
         int bitmap_count = levels + 1;
 
         /* Miptree for each face */
-        if (type == MALI_TEX_CUBE)
+        if (dim == MALI_TEXTURE_DIMENSION_CUBE)
                 bitmap_count *= 6;
 
         /* Array of layers */
-        bitmap_count *= (depth + 1);
+        bitmap_count *= depth;
 
         /* Array of textures */
-        bitmap_count *= (array_size + 1);
+        bitmap_count *= array_size;
 
         /* Stride for each element */
         if (manual_stride)
@@ -2095,228 +2063,31 @@ pandecode_texture(mali_ptr u,
                 struct pandecode_mapped_memory *tmem,
                 unsigned job_no, unsigned tex)
 {
-        struct mali_texture_descriptor *PANDECODE_PTR_VAR(t, tmem, u);
-
-        pandecode_log("struct mali_texture_descriptor texture_descriptor_%"PRIx64"_%d_%d = {\n", u, job_no, tex);
-        pandecode_indent++;
-
-        pandecode_prop("width = %" PRId32, t->width);
-        pandecode_prop("height = %" PRId32, t->height);
-        pandecode_prop("depth = %" PRId32, t->depth);
-        pandecode_prop("array_size = %" PRId32, t->array_size);
-
-        pandecode_log("\n");
-        pandecode_prop("f.swizzle = 0x%" PRIx32, t->format.swizzle);
-        pandecode_prop("f.format = 0x%" PRIx32, t->format.format);
-        pandecode_prop("f.srgb = 0x%" PRIx32, t->format.srgb);
-        pandecode_prop("f.unknown1 = 0x%" PRIx32, t->format.unknown1);
-        pandecode_prop("f.type = %" PRId32, t->format.type);
-        pandecode_prop("f.layout = %" PRId32, t->format.layout);
-        pandecode_prop("f.unknown2 = 0x%" PRIx32, t->format.unknown2);
-        pandecode_prop("f.manual_stride = %" PRId32, t->format.manual_stride);
-        pandecode_prop("f.zero = 0x%" PRIx32, t->format.zero);
-        pandecode_log("\n");
-
-        pandecode_prop("unknown3 = 0x%" PRIx32, t->unknown3);
-        pandecode_prop("unknown3A = 0x%" PRIx32, t->unknown3A);
-        pandecode_prop("levels = %" PRId32, t->levels);
-        pandecode_prop("swizzle = 0x%" PRIx32, t->swizzle);
-        pandecode_prop("swizzle_zero = 0x%" PRIx32, t->swizzle_zero);
-
-        pandecode_prop("unknown5 = 0x%" PRIx32, t->unknown5);
-        pandecode_prop("unknown6 = 0x%" PRIx32, t->unknown6);
-        pandecode_prop("unknown7 = 0x%" PRIx32, t->unknown7);
-        pandecode_log("\n");
-
-        struct mali_texture_format f = t->format;
-
-        /* See the definiton of enum mali_texture_type */
-
-        bool is_cube = f.type == MALI_TEX_CUBE;
-        unsigned dimension = is_cube ? 2 : f.type;
-
-        pandecode_make_indent();
-
-        /* Print the layout. Default is linear; a modifier can denote AFBC or
-         * u-interleaved/tiled modes */
-
-        if (f.layout == MALI_TEXTURE_AFBC)
-                pandecode_log_cont("afbc");
-        else if (f.layout == MALI_TEXTURE_TILED)
-                pandecode_log_cont("tiled");
-        else if (f.layout == MALI_TEXTURE_LINEAR)
-                pandecode_log_cont("linear");
-        else
-                pandecode_msg("XXX: invalid texture layout 0x%X\n", f.layout);
-
-        pandecode_swizzle(t->swizzle, f.format);
-        pandecode_log_cont(" ");
-
-        /* Distinguish cube/2D with modifier */
-
-        if (is_cube)
-                pandecode_log_cont("cube ");
-
-        pandecode_format_short(f.format, f.srgb);
-        pandecode_swizzle(f.swizzle, f.format);
-
-        /* All four width/height/depth/array_size dimensions are present
-         * regardless of the type of texture, but it is an error to have
-         * non-zero dimensions for unused dimensions. Verify this. array_size
-         * can always be set, as can width. Depth used for MSAA. */
-
-        if (t->height && dimension < 2)
-                pandecode_msg("XXX: nonzero height for <2D texture\n");
-
-        /* Print only the dimensions that are actually there */
-
-        pandecode_log_cont(": %d", t->width + 1);
-
-        if (t->height || t->depth)
-                pandecode_log_cont("x%u", t->height + 1);
-
-        if (t->depth)
-                pandecode_log_cont("x%u", t->depth + 1);
-
-        if (t->array_size)
-                pandecode_log_cont("[%u]", t->array_size + 1);
-
-        if (t->levels)
-                pandecode_log_cont(" mip %u", t->levels);
-
-        pandecode_log_cont("\n");
-
-        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.unknown2);
-        }
-
-        if (t->swizzle_zero) {
-                pandecode_msg("XXX: swizzle zero tripped\n");
-                pandecode_prop("swizzle_zero = %d", t->swizzle_zero);
-        }
-
-        if (t->unknown3 | t->unknown3A | t->unknown5 | t->unknown6 | t->unknown7) {
-                pandecode_msg("XXX: texture zero tripped\n");
-                pandecode_prop("unknown3 = %" PRId16, t->unknown3);
-                pandecode_prop("unknown3A = %" PRId8, t->unknown3A);
-                pandecode_prop("unknown5 = 0x%" PRIx32, t->unknown5);
-                pandecode_prop("unknown6 = 0x%" PRIx32, t->unknown6);
-                pandecode_prop("unknown7 = 0x%" PRIx32, t->unknown7);
-        }
+        struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(u);
+        const uint8_t *cl = pandecode_fetch_gpu_mem(mapped_mem, u, MALI_MIDGARD_TEXTURE_LENGTH);
 
-        pandecode_texture_payload(u + sizeof(*t), f.type, f.layout, f.manual_stride, t->levels, t->depth, t->array_size, tmem);
+        struct MALI_MIDGARD_TEXTURE temp;
+        MALI_MIDGARD_TEXTURE_unpack(cl, &temp);
+        MALI_MIDGARD_TEXTURE_print(pandecode_dump_stream, &temp, 2);
 
-        pandecode_indent--;
-        pandecode_log("};\n");
+        pandecode_texture_payload(u + MALI_MIDGARD_TEXTURE_LENGTH,
+                        temp.dimension, temp.texel_ordering, temp.manual_stride,
+                        temp.levels, temp.depth, temp.array_size, mapped_mem);
 }
 
 static void
 pandecode_bifrost_texture(
-                const struct bifrost_texture_descriptor *t,
+                const void *cl,
                 unsigned job_no,
                 unsigned tex)
 {
-        pandecode_log("struct bifrost_texture_descriptor texture_descriptor_%d_%d = {\n", job_no, tex);
-        pandecode_indent++;
-
-        pandecode_prop("format_unk = 0x%" PRIx32, t->format_unk);
-        pandecode_prop("type = %" PRId32, t->type);
-
-        if (t->zero) {
-                pandecode_msg("XXX: zero tripped\n");
-                pandecode_prop("zero = 0x%" PRIx32, t->zero);
-        }
-
-        pandecode_prop("format_swizzle = 0x%" PRIx32, t->format_swizzle);
-        pandecode_prop("format = 0x%" PRIx32, t->format);
-        pandecode_prop("srgb = 0x%" PRIx32, t->srgb);
-        pandecode_prop("format_unk3 = 0x%" PRIx32, t->format_unk3);
-        pandecode_prop("width = %" PRId32, t->width);
-        pandecode_prop("height = %" PRId32, t->height);
-        pandecode_prop("swizzle = 0x%" PRIx32, t->swizzle);
-        pandecode_prop("levels = %" PRId32, t->levels);
-        pandecode_prop("unk1 = 0x%" PRIx32, t->unk1);
-        pandecode_prop("levels_unk = %" PRId32, t->levels_unk);
-        pandecode_prop("level_2 = %" PRId32, t->level_2);
-        pandecode_prop("payload = 0x%" PRIx64, t->payload);
-        pandecode_prop("array_size = %" PRId32, t->array_size);
-        pandecode_prop("unk4 = 0x%" PRIx32, t->unk4);
-        pandecode_prop("depth = %" PRId32, t->depth);
-        pandecode_prop("unk5 = 0x%" PRIx32, t->unk5);
-        pandecode_log("\n");
-
-        /* See the definiton of enum mali_texture_type */
-
-        bool is_cube = t->type == MALI_TEX_CUBE;
-        unsigned dimension = is_cube ? 2 : t->type;
-
-        /* Print the layout. Default is linear; a modifier can denote AFBC or
-         * u-interleaved/tiled modes */
-
-        if (t->layout == MALI_TEXTURE_AFBC)
-                pandecode_log_cont("afbc");
-        else if (t->layout == MALI_TEXTURE_TILED)
-                pandecode_log_cont("tiled");
-        else if (t->layout == MALI_TEXTURE_LINEAR)
-                pandecode_log_cont("linear");
-        else
-                pandecode_msg("XXX: invalid texture layout 0x%X\n", t->layout);
-
-        pandecode_swizzle(t->swizzle, t->format);
-        pandecode_log_cont(" ");
-
-        /* Distinguish cube/2D with modifier */
-
-        if (is_cube)
-                pandecode_log_cont("cube ");
-
-        pandecode_format_short(t->format, t->srgb);
-
-        /* All four width/height/depth/array_size dimensions are present
-         * regardless of the type of texture, but it is an error to have
-         * non-zero dimensions for unused dimensions. Verify this. array_size
-         * can always be set, as can width. */
-
-        if (t->height && dimension < 2)
-                pandecode_msg("XXX: nonzero height for <2D texture\n");
-
-        if (t->depth && dimension < 3)
-                pandecode_msg("XXX: nonzero depth for <2D texture\n");
+        struct MALI_BIFROST_TEXTURE temp;
+        MALI_BIFROST_TEXTURE_unpack(cl, &temp);
+        MALI_BIFROST_TEXTURE_print(pandecode_dump_stream, &temp, 2);
 
-        /* Print only the dimensions that are actually there */
-
-        pandecode_log_cont(": %d", t->width + 1);
-
-        if (dimension >= 2)
-                pandecode_log_cont("x%u", t->height + 1);
-
-        if (dimension >= 3)
-                pandecode_log_cont("x%u", t->depth + 1);
-
-        if (t->array_size)
-                pandecode_log_cont("[%u]", t->array_size + 1);
-
-        if (t->levels)
-                pandecode_log_cont(" mip %u", t->levels);
-
-        pandecode_log_cont("\n");
-
-        struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(t->payload);
-        if (t->payload) {
-                pandecode_texture_payload(t->payload, t->type, t->layout,
-                                          true, t->levels, t->depth,
-                                          t->array_size, tmem);
-        }
-
-        pandecode_indent--;
-        pandecode_log("};\n");
+        struct pandecode_mapped_memory *tmem = pandecode_find_mapped_gpu_mem_containing(temp.surfaces);
+        pandecode_texture_payload(temp.surfaces, temp.dimension, temp.texel_ordering,
+                                  true, temp.levels, 1, 1, tmem);
 }
 
 /* For shader properties like texture_count, we have a claimed property in the shader_meta, and the actual Truth from static analysis (this may just be an upper limit). We validate accordingly */
@@ -2382,23 +2153,21 @@ pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool i
         if (!mmem)
                 return;
 
-        if (is_bifrost) {
-                const struct bifrost_texture_descriptor *PANDECODE_PTR_VAR(t, mmem, textures);
-
-                pandecode_log("uint64_t textures_%"PRIx64"_%d[] = {\n", textures, job_no);
-                pandecode_indent++;
+        pandecode_log("Textures (%"PRIx64"):\n", textures);
 
-                for (unsigned tex = 0; tex < texture_count; ++tex)
-                        pandecode_bifrost_texture(&t[tex], job_no, tex);
+        if (is_bifrost) {
+                const void *cl = pandecode_fetch_gpu_mem(mmem,
+                                textures, MALI_BIFROST_TEXTURE_LENGTH *
+                                texture_count);
 
-                pandecode_indent--;
-                pandecode_log("};\n");
+                for (unsigned tex = 0; tex < texture_count; ++tex) {
+                        pandecode_bifrost_texture(cl +
+                                        MALI_BIFROST_TEXTURE_LENGTH * tex,
+                                        job_no, tex);
+                }
         } else {
                 mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures);
 
-                pandecode_log("uint64_t textures_%"PRIx64"_%d[] = {\n", textures, job_no);
-                pandecode_indent++;
-
                 for (int tex = 0; tex < texture_count; ++tex) {
                         mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));
                         char *a = pointer_as_memory_reference(*u);
@@ -2406,9 +2175,6 @@ pandecode_textures(mali_ptr textures, unsigned texture_count, int job_no, bool i
                         free(a);
                 }
 
-                pandecode_indent--;
-                pandecode_log("};\n");
-
                 /* Now, finally, descend down into the texture descriptor */
                 for (unsigned tex = 0; tex < texture_count; ++tex) {
                         mali_ptr *PANDECODE_PTR_VAR(u, mmem, textures + tex * sizeof(mali_ptr));