pan/decode: Drop legacy 32-bit job support
[mesa.git] / src / panfrost / lib / decode.c
index 06b381626dc15a91faa23b2da0ce3b6e56e34f95..f2f5df97dc687945a14dacab5fa78f82ef3009bb 100644 (file)
@@ -64,9 +64,15 @@ static void pandecode_swizzle(unsigned swizzle, enum mali_format format);
         MALI_ ## T ## _print(pandecode_dump_stream, &temp, indent * 2); \
 }
 
+#define MAP_ADDR(T, addr, cl) \
+        const uint8_t *cl = 0; \
+        { \
+                struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(addr); \
+                cl = pandecode_fetch_gpu_mem(mapped_mem, addr, MALI_ ## T ## _LENGTH); \
+        }
+
 #define DUMP_ADDR(title, T, addr, indent) {\
-        struct pandecode_mapped_memory *mapped_mem = pandecode_find_mapped_gpu_mem_containing(addr); \
-        const uint8_t *cl = pandecode_fetch_gpu_mem(mapped_mem, addr, MALI_ ## T ## _LENGTH); \
+        MAP_ADDR(T, addr, cl) \
         DUMP_CL(title, T, cl, indent); \
 }
 
@@ -334,48 +340,6 @@ static const struct pandecode_flag_info sfbd_unk2_info [] = {
 };
 #undef FLAG_INFO
 
-static char *pandecode_attr_mode_short(enum mali_attr_mode mode)
-{
-        switch(mode) {
-                /* TODO: Combine to just "instanced" once this can be done
-                 * unambiguously in all known cases */
-        case MALI_ATTR_POT_DIVIDE:
-                return "instanced_pot";
-        case MALI_ATTR_MODULO:
-                return "instanced_mod";
-        case MALI_ATTR_NPOT_DIVIDE:
-                return "instanced_npot";
-        case MALI_ATTR_IMAGE:
-                return "image";
-        default:
-                pandecode_msg("XXX: invalid attribute mode %X\n", mode);
-                return "";
-        }
-}
-
-static const char *
-pandecode_special_record(uint64_t v, bool* attribute)
-{
-        switch(v) {
-        case MALI_ATTR_VERTEXID:
-                *attribute = true;
-                return "gl_VertexID";
-        case MALI_ATTR_INSTANCEID:
-                *attribute = true;
-                return "gl_InstanceID";
-        case MALI_VARYING_FRAG_COORD:
-                return "gl_FragCoord";
-        case MALI_VARYING_FRONT_FACING:
-                return "gl_FrontFacing";
-        case MALI_VARYING_POINT_COORD:
-                return "gl_PointCoord";
-        default:
-                pandecode_msg("XXX: invalid special record %" PRIx64 "\n", v);
-                return "";
-        }
-}
-
-
 /* Midgard's tiler descriptor is embedded within the
  * larger FBD */
 
@@ -429,9 +393,6 @@ pandecode_midgard_tiler_descriptor(
         MEMORY_PROP(t, heap_start);
         assert(t->heap_end >= t->heap_start);
 
-        struct pandecode_mapped_memory *heap =
-                pandecode_find_mapped_gpu_mem_containing(t->heap_start);
-
         unsigned heap_size = t->heap_end - t->heap_start;
 
         /* Tiling is enabled with a special flag */
@@ -441,13 +402,6 @@ pandecode_midgard_tiler_descriptor(
         bool tiling_enabled = hierarchy_mask;
 
         if (tiling_enabled) {
-                /* When tiling is enabled, the heap should be a tight fit */
-                unsigned heap_offset = t->heap_start - heap->gpu_va;
-                if ((heap_offset + heap_size) != heap->length) {
-                        pandecode_msg("XXX: heap size %u (expected %zu)\n",
-                                        heap_size, heap->length - heap_offset);
-                }
-
                 /* We should also have no other flags */
                 if (tiler_flags)
                         pandecode_msg("XXX: unexpected tiler %X\n", tiler_flags);
@@ -756,12 +710,12 @@ static unsigned
 pandecode_access_mask_from_channel_swizzle(unsigned swizzle)
 {
         unsigned mask = 0;
-        assert(MALI_CHANNEL_RED == 0);
+        assert(MALI_CHANNEL_R == 0);
 
         for (unsigned c = 0; c < 4; ++c) {
                 enum mali_channel chan = (swizzle >> (3*c)) & 0x7;
 
-                if (chan <= MALI_CHANNEL_ALPHA)
+                if (chan <= MALI_CHANNEL_A)
                         mask |= (1 << chan);
         }
 
@@ -790,10 +744,10 @@ pandecode_validate_format_swizzle(enum mali_format fmt, unsigned swizzle)
          * useless printing for the defaults */
 
         unsigned default_swizzles[4] = {
-                MALI_CHANNEL_RED | (MALI_CHANNEL_ZERO  << 3) | (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE   << 9),
-                MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE   << 9),
-                MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE   << 9),
-                MALI_CHANNEL_RED | (MALI_CHANNEL_GREEN << 3) | (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9)
+                MALI_CHANNEL_R | (MALI_CHANNEL_0  << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1   << 9),
+                MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_0 << 6) | (MALI_CHANNEL_1   << 9),
+                MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_1   << 9),
+                MALI_CHANNEL_R | (MALI_CHANNEL_G << 3) | (MALI_CHANNEL_B << 6) | (MALI_CHANNEL_A << 9)
         };
 
         return (swizzle == default_swizzles[nr_comp - 1]);
@@ -817,7 +771,7 @@ pandecode_swizzle(unsigned swizzle, enum mali_format format)
         for (unsigned c = 0; c < 4; ++c) {
                 enum mali_channel chan = (swizzle >> (3 * c)) & 0x7;
 
-                if (chan >= MALI_CHANNEL_RESERVED_0) {
+                if (chan > MALI_CHANNEL_1) {
                         pandecode_log("XXX: invalid swizzle channel %d\n", chan);
                         continue;
                 }
@@ -1150,108 +1104,12 @@ pandecode_mfbd_bfr(uint64_t gpu_va, int job_no, bool is_fragment, bool is_comput
         return info;
 }
 
-/* Just add a comment decoding the shift/odd fields forming the padded vertices
- * count */
-
-static void
-pandecode_padded_vertices(unsigned shift, unsigned k)
-{
-        unsigned odd = 2*k + 1;
-        unsigned pot = 1 << shift;
-        pandecode_msg("padded_num_vertices = %d\n", odd * pot);
-}
-
-/* Given a magic divisor, recover what we were trying to divide by.
- *
- * Let m represent the magic divisor. By definition, m is an element on Z, whre
- * 0 <= m < 2^N, for N bits in m.
- *
- * Let q represent the number we would like to divide by.
- *
- * By definition of a magic divisor for N-bit unsigned integers (a number you
- * multiply by to magically get division), m is a number such that:
- *
- *      (m * x) & (2^N - 1) = floor(x/q).
- *      for all x on Z where 0 <= x < 2^N
- *
- * Ignore the case where any of the above values equals zero; it is irrelevant
- * for our purposes (instanced arrays).
- *
- * Choose x = q. Then:
- *
- *      (m * x) & (2^N - 1) = floor(x/q).
- *      (m * q) & (2^N - 1) = floor(q/q).
- *
- *      floor(q/q) = floor(1) = 1, therefore:
- *
- *      (m * q) & (2^N - 1) = 1
- *
- * Recall the identity that the bitwise AND of one less than a power-of-two
- * equals the modulo with that power of two, i.e. for all x:
- *
- *      x & (2^N - 1) = x % N
- *
- * Therefore:
- *
- *      mq % (2^N) = 1
- *
- * By definition, a modular multiplicative inverse of a number m is the number
- * q such that with respect to a modulos M:
- *
- *      mq % M = 1
- *
- * Therefore, q is the modular multiplicative inverse of m with modulus 2^N.
- *
- */
-
-static void
-pandecode_magic_divisor(uint32_t magic, unsigned shift, unsigned orig_divisor, unsigned extra)
-{
-#if 0
-        /* Compute the modular inverse of `magic` with respect to 2^(32 -
-         * shift) the most lame way possible... just repeatedly add.
-         * Asymptoptically slow but nobody cares in practice, unless you have
-         * massive numbers of vertices or high divisors. */
-
-        unsigned inverse = 0;
-
-        /* Magic implicitly has the highest bit set */
-        magic |= (1 << 31);
-
-        /* Depending on rounding direction */
-        if (extra)
-                magic++;
-
-        for (;;) {
-                uint32_t product = magic * inverse;
-
-                if (shift) {
-                        product >>= shift;
-                }
-
-                if (product == 1)
-                        break;
-
-                ++inverse;
-        }
-
-        pandecode_msg("dividing by %d (maybe off by two)\n", inverse);
-
-        /* Recall we're supposed to divide by (gl_level_divisor *
-         * padded_num_vertices) */
-
-        unsigned padded_num_vertices = inverse / orig_divisor;
-
-        pandecode_msg("padded_num_vertices = %d\n", padded_num_vertices);
-#endif
-}
-
 static void
 pandecode_attributes(const struct pandecode_mapped_memory *mem,
                             mali_ptr addr, int job_no, char *suffix,
                             int count, bool varying, enum mali_job_type job_type)
 {
-        char *prefix = varying ? "varying" : "attribute";
+        char *prefix = varying ? "Varying" : "Attribute";
         assert(addr);
 
         if (!count) {
@@ -1259,116 +1117,21 @@ pandecode_attributes(const struct pandecode_mapped_memory *mem,
                 return;
         }
 
-        union mali_attr *attr = pandecode_fetch_gpu_mem(mem, addr, sizeof(union mali_attr) * count);
+        MAP_ADDR(ATTRIBUTE_BUFFER, addr, cl);
 
         for (int i = 0; i < count; ++i) {
-                /* First, check for special records */
-                if (attr[i].elements < MALI_RECORD_SPECIAL) {
-                        if (attr[i].size)
-                                pandecode_msg("XXX: tripped size=%d\n", attr[i].size);
-
-                        if (attr[i].stride) {
-                                /* gl_InstanceID passes a magic divisor in the
-                                 * stride field to divide by the padded vertex
-                                 * count. No other records should do so, so
-                                 * stride should otherwise be zero. Note that
-                                 * stride in the usual attribute sense doesn't
-                                 * apply to special records. */
-
-                                bool has_divisor = attr[i].elements == MALI_ATTR_INSTANCEID;
-
-                                pandecode_log_cont("/* %smagic divisor = %X */ ",
-                                                has_divisor ? "" : "XXX: ", attr[i].stride);
-                        }
-
-                        if (attr[i].shift || attr[i].extra_flags) {
-                                /* Attributes use these fields for
-                                 * instancing/padding/etc type issues, but
-                                 * varyings don't */
-
-                                pandecode_log_cont("/* %sshift=%d, extra=%d */ ",
-                                                varying ? "XXX: " : "",
-                                                attr[i].shift, attr[i].extra_flags);
-                        }
-
-                        /* Print the special record name */
-                        bool attribute = false;
-                        pandecode_log("%s_%d = %s;\n", prefix, i, pandecode_special_record(attr[i].elements, &attribute));
-
-                        /* Sanity check */
-                        if (attribute == varying)
-                                pandecode_msg("XXX: mismatched special record\n");
-
-                        continue;
-        }
-
-                enum mali_attr_mode mode = attr[i].elements & 7;
-
-                if (mode == MALI_ATTR_UNUSED)
-                        pandecode_msg("XXX: unused attribute record\n");
-
-                /* For non-linear records, we need to print the type of record */
-                if (mode != MALI_ATTR_LINEAR)
-                        pandecode_log_cont("%s ", pandecode_attr_mode_short(mode));
-
-                /* Print the name to link with attr_meta */
-                pandecode_log_cont("%s_%d", prefix, i);
-
-                /* Print the stride and size */
-                pandecode_log_cont("<%u>[%u]", attr[i].stride, attr[i].size);
-
-                /* TODO: Sanity check the quotient itself. It must be equal to
-                 * (or be greater than, if the driver added padding) the padded
-                 * vertex count. */
-
-                /* Finally, print the pointer */
-                mali_ptr raw_elements = attr[i].elements & ~7;
-                char *a = pointer_as_memory_reference(raw_elements);
-                pandecode_log_cont(" = (%s);\n", a);
-                free(a);
-
-                /* Check the pointer */
-                pandecode_validate_buffer(raw_elements, attr[i].size);
+                fprintf(pandecode_dump_stream, "%s\n", prefix);
 
-                /* shift/extra_flags exist only for instanced */
-                if (attr[i].shift | attr[i].extra_flags) {
-                        /* These are set to random values by the blob for
-                         * varyings, most likely a symptom of uninitialized
-                         * memory where the hardware masked the bug. As such we
-                         * put this at a warning, not an error. */
+                struct MALI_ATTRIBUTE_BUFFER temp;
+                MALI_ATTRIBUTE_BUFFER_unpack(cl + i * MALI_ATTRIBUTE_BUFFER_LENGTH, &temp);
+                MALI_ATTRIBUTE_BUFFER_print(pandecode_dump_stream, &temp, 2);
 
-                        if (mode == MALI_ATTR_LINEAR)
-                                pandecode_msg("warn: instancing fields set for linear\n");
-
-                        pandecode_prop("shift = %d", attr[i].shift);
-                        pandecode_prop("extra_flags = %d", attr[i].extra_flags);
-                }
-
-                /* Decode further where possible */
-
-                if (mode == MALI_ATTR_MODULO) {
-                        pandecode_padded_vertices(
-                                attr[i].shift,
-                                attr[i].extra_flags);
+                if (temp.type == MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR) {
+                        struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT temp2;
+                        MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_unpack(cl + (i + 1) * MALI_ATTRIBUTE_BUFFER_LENGTH, &temp2);
+                        MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_print(pandecode_dump_stream, &temp2, 2);
                 }
-
-                if (mode == MALI_ATTR_NPOT_DIVIDE) {
-                        i++;
-                        pandecode_log("{\n");
-                        pandecode_indent++;
-                        pandecode_prop("unk = 0x%x", attr[i].unk);
-                        pandecode_prop("magic_divisor = 0x%08x", attr[i].magic_divisor);
-                        if (attr[i].zero != 0)
-                                pandecode_prop("XXX: zero tripped (0x%x)\n", attr[i].zero);
-                        pandecode_prop("divisor = %d", attr[i].divisor);
-                        pandecode_magic_divisor(attr[i].magic_divisor, attr[i - 1].shift, attr[i].divisor, attr[i - 1].extra_flags);
-                        pandecode_indent--;
-                        pandecode_log("}, \n");
-                }
-
         }
-
-        pandecode_log("\n");
 }
 
 static mali_ptr
@@ -1537,41 +1300,13 @@ pandecode_midgard_blend_mrt(void *descs, int job_no, int rt_no)
 static int
 pandecode_attribute_meta(int job_no, int count, const struct mali_vertex_tiler_postfix *v, bool varying, char *suffix)
 {
-        char base[128];
-        char *prefix = varying ? "varying" : "attribute";
-        unsigned max_index = 0;
-        snprintf(base, sizeof(base), "%s_meta", prefix);
-
-        struct mali_attr_meta *attr_meta;
+        const char *prefix = varying ? "Varying" : "Attribute";
         mali_ptr p = varying ? v->varying_meta : v->attribute_meta;
 
-        struct pandecode_mapped_memory *attr_mem = pandecode_find_mapped_gpu_mem_containing(p);
-
-        for (int i = 0; i < count; ++i, p += sizeof(struct mali_attr_meta)) {
-                attr_meta = pandecode_fetch_gpu_mem(attr_mem, p,
-                                                    sizeof(*attr_mem));
+        for (int i = 0; i < count; ++i, p += MALI_ATTRIBUTE_LENGTH)
+                DUMP_ADDR(prefix, ATTRIBUTE, p, 1);
 
-                if (attr_meta->index > max_index)
-                        max_index = attr_meta->index;
-
-                if (attr_meta->unknown1 != 0x2) {
-                        pandecode_msg("XXX: expected unknown1 = 0x2\n");
-                        pandecode_prop("unknown1 = 0x%" PRIx64, (u64) attr_meta->unknown1);
-                }
-
-                pandecode_log_cont("%s %s_%u", mali_format_as_str(attr_meta->format >> 12), prefix, attr_meta->index);
-
-                if (attr_meta->src_offset)
-                        pandecode_log_cont("[%u]", attr_meta->src_offset);
-
-                pandecode_swizzle(attr_meta->format & ((1 << 12) - 1), attr_meta->format >> 12);
-
-                pandecode_log_cont(";\n");
-        }
-
-        pandecode_log("\n");
-
-        return count ? (max_index + 1) : 0;
+        return count;
 }
 
 /* return bits [lo, hi) of word */
@@ -2634,14 +2369,7 @@ pandecode_jc(mali_ptr jc_gpu_va, bool bifrost, unsigned gpu_id, bool minimal)
 
                 h = PANDECODE_PTR(mem, jc_gpu_va, struct mali_job_descriptor_header);
 
-                /* On Midgard, for 32-bit jobs except for fragment jobs, the
-                 * high 32-bits of the 64-bit pointer are reused to store
-                 * something else.
-                 */
-                int offset = h->job_descriptor_size == MALI_JOB_32 &&
-                             h->job_type != MALI_JOB_TYPE_FRAGMENT ? 4 : 0;
-                mali_ptr payload_ptr = jc_gpu_va + sizeof(*h) - offset;
-
+                mali_ptr payload_ptr = jc_gpu_va + sizeof(*h);
                 payload = pandecode_fetch_gpu_mem(mem, payload_ptr, 256);
 
                 int job_no = job_descriptor_number++;