Home | History | Annotate | Line # | Download | only in genxml
      1 
      2 /* Generated code, see midgard.xml and gen_pack_header.py
      3  *
      4  * Packets, enums and structures for Panfrost.
      5  *
      6  * This file has been generated, do not hand edit.
      7  */
      8 
      9 #ifndef PAN_PACK_H
     10 #define PAN_PACK_H
     11 
     12 #include <stdio.h>
     13 #include <stdint.h>
     14 #include <stdbool.h>
     15 #include <assert.h>
     16 #include <math.h>
     17 #include <inttypes.h>
     18 #include "util/macros.h"
     19 #include "util/u_math.h"
     20 
     21 #define __gen_unpack_float(x, y, z) uif(__gen_unpack_uint(x, y, z))
     22 
     23 static inline uint64_t
     24 __gen_uint(uint64_t v, uint32_t start, uint32_t end)
     25 {
     26 #ifndef NDEBUG
     27    const int width = end - start + 1;
     28    if (width < 64) {
     29       const uint64_t max = (1ull << width) - 1;
     30       assert(v <= max);
     31    }
     32 #endif
     33 
     34    return v << start;
     35 }
     36 
     37 static inline uint32_t
     38 __gen_sint(int32_t v, uint32_t start, uint32_t end)
     39 {
     40 #ifndef NDEBUG
     41    const int width = end - start + 1;
     42    if (width < 64) {
     43       const int64_t max = (1ll << (width - 1)) - 1;
     44       const int64_t min = -(1ll << (width - 1));
     45       assert(min <= v && v <= max);
     46    }
     47 #endif
     48 
     49    return (((uint32_t) v) << start) & ((2ll << end) - 1);
     50 }
     51 
     52 static inline uint32_t
     53 __gen_padded(uint32_t v, uint32_t start, uint32_t end)
     54 {
     55     unsigned shift = __builtin_ctz(v);
     56     unsigned odd = v >> (shift + 1);
     57 
     58 #ifndef NDEBUG
     59     assert((v >> shift) & 1);
     60     assert(shift <= 31);
     61     assert(odd <= 7);
     62     assert((end - start + 1) == 8);
     63 #endif
     64 
     65     return __gen_uint(shift | (odd << 5), start, end);
     66 }
     67 
     68 
     69 static inline uint64_t
     70 __gen_unpack_uint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
     71 {
     72    uint64_t val = 0;
     73    const int width = end - start + 1;
     74    const uint64_t mask = (width == 64 ? ~0 : (1ull << width) - 1 );
     75 
     76    for (uint32_t byte = start / 8; byte <= end / 8; byte++) {
     77       val |= ((uint64_t) cl[byte]) << ((byte - start / 8) * 8);
     78    }
     79 
     80    return (val >> (start % 8)) & mask;
     81 }
     82 
     83 static inline uint64_t
     84 __gen_unpack_sint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
     85 {
     86    int size = end - start + 1;
     87    int64_t val = __gen_unpack_uint(cl, start, end);
     88 
     89    /* Get the sign bit extended. */
     90    return (val << (64 - size)) >> (64 - size);
     91 }
     92 
     93 static inline uint64_t
     94 __gen_unpack_padded(const uint8_t *restrict cl, uint32_t start, uint32_t end)
     95 {
     96    unsigned val = __gen_unpack_uint(cl, start, end);
     97    unsigned shift = val & 0b11111;
     98    unsigned odd = val >> 5;
     99 
    100    return (2*odd + 1) << shift;
    101 }
    102 
    103 #define PREFIX1(A) MALI_ ## A
    104 #define PREFIX2(A, B) MALI_ ## A ## _ ## B
    105 #define PREFIX4(A, B, C, D) MALI_ ## A ## _ ## B ## _ ## C ## _ ## D
    106 
    107 #define pan_prepare(dst, T)                                 \
    108    *(dst) = (struct PREFIX1(T)){ PREFIX2(T, header) }
    109 
    110 #define pan_pack(dst, T, name)                              \
    111    for (struct PREFIX1(T) name = { PREFIX2(T, header) }, \
    112         *_loop_terminate = (void *) (dst);                  \
    113         __builtin_expect(_loop_terminate != NULL, 1);       \
    114         ({ PREFIX2(T, pack)((uint32_t *) (dst), &name);  \
    115            _loop_terminate = NULL; }))
    116 
    117 #define pan_unpack(src, T, name)                        \
    118         struct PREFIX1(T) name;                         \
    119         PREFIX2(T, unpack)((uint8_t *)(src), &name)
    120 
    121 #define pan_print(fp, T, var, indent)                   \
    122         PREFIX2(T, print)(fp, &(var), indent)
    123 
    124 #define pan_size(T) PREFIX2(T, LENGTH)
    125 #define pan_alignment(T) PREFIX2(T, ALIGN)
    126 
    127 #define pan_section_offset(A, S) \
    128         PREFIX4(A, SECTION, S, OFFSET)
    129 
    130 #define pan_section_ptr(base, A, S) \
    131         ((void *)((uint8_t *)(base) + pan_section_offset(A, S)))
    132 
    133 #define pan_section_pack(dst, A, S, name)                                                         \
    134    for (PREFIX4(A, SECTION, S, TYPE) name = { PREFIX4(A, SECTION, S, header) }, \
    135         *_loop_terminate = (void *) (dst);                                                        \
    136         __builtin_expect(_loop_terminate != NULL, 1);                                             \
    137         ({ PREFIX4(A, SECTION, S, pack) (pan_section_ptr(dst, A, S), &name);              \
    138            _loop_terminate = NULL; }))
    139 
    140 #define pan_section_unpack(src, A, S, name)                               \
    141         PREFIX4(A, SECTION, S, TYPE) name;                             \
    142         PREFIX4(A, SECTION, S, unpack)(pan_section_ptr(src, A, S), &name)
    143 
    144 #define pan_section_print(fp, A, S, var, indent)                          \
    145         PREFIX4(A, SECTION, S, print)(fp, &(var), indent)
    146 
    147 #define pan_merge(packed1, packed2, type)         do {                 for (unsigned i = 0; i < (PREFIX2(type, LENGTH) / 4); ++i)                         (packed1).opaque[i] |= (packed2).opaque[i];         } while(0)
    148 
    149 /* From presentations, 16x16 tiles externally. Use shift for fast computation
    150  * of tile numbers. */
    151 
    152 #define MALI_TILE_SHIFT 4
    153 #define MALI_TILE_LENGTH (1 << MALI_TILE_SHIFT)
    154 
    155 
    156 
    157 
    158 #define mali_pixel_format_print(fp, format) \
    159     fprintf(fp, "%*sFormat (v7): %s%s %s%s\n", indent, "", \
    160         mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \
    161         (format & (1 << 20)) ? " sRGB" : "", \
    162         mali_rgb_component_order_as_str((enum mali_rgb_component_order)(format & ((1 << 12) - 1))), \
    163         (format & (1 << 21)) ? " XXX BAD BIT" : "");
    164 
    165 
    166 enum mali_attribute_type {
    167         MALI_ATTRIBUTE_TYPE_1D               =      1,
    168         MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR   =      2,
    169         MALI_ATTRIBUTE_TYPE_1D_MODULUS       =      3,
    170         MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR  =      4,
    171         MALI_ATTRIBUTE_TYPE_3D_LINEAR        =      5,
    172         MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED   =      6,
    173         MALI_ATTRIBUTE_TYPE_1D_PRIMITIVE_INDEX_BUFFER =      7,
    174         MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR_WRITE_REDUCTION =     10,
    175         MALI_ATTRIBUTE_TYPE_1D_MODULUS_WRITE_REDUCTION =     11,
    176         MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR_WRITE_REDUCTION =     12,
    177         MALI_ATTRIBUTE_TYPE_CONTINUATION     =     32,
    178 };
    179 
    180 static inline const char *
    181 mali_attribute_type_as_str(enum mali_attribute_type imm)
    182 {
    183     switch (imm) {
    184     case MALI_ATTRIBUTE_TYPE_1D: return "1D";
    185     case MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR: return "1D POT Divisor";
    186     case MALI_ATTRIBUTE_TYPE_1D_MODULUS: return "1D Modulus";
    187     case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR: return "1D NPOT Divisor";
    188     case MALI_ATTRIBUTE_TYPE_3D_LINEAR: return "3D Linear";
    189     case MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED: return "3D Interleaved";
    190     case MALI_ATTRIBUTE_TYPE_1D_PRIMITIVE_INDEX_BUFFER: return "1D Primitive Index Buffer";
    191     case MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR_WRITE_REDUCTION: return "1D POT Divisor Write Reduction";
    192     case MALI_ATTRIBUTE_TYPE_1D_MODULUS_WRITE_REDUCTION: return "1D Modulus Write Reduction";
    193     case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR_WRITE_REDUCTION: return "1D NPOT Divisor Write Reduction";
    194     case MALI_ATTRIBUTE_TYPE_CONTINUATION: return "Continuation";
    195     default: return "XXX: INVALID";
    196     }
    197 }
    198 
    199 enum mali_channel {
    200         MALI_CHANNEL_R                       =      0,
    201         MALI_CHANNEL_G                       =      1,
    202         MALI_CHANNEL_B                       =      2,
    203         MALI_CHANNEL_A                       =      3,
    204         MALI_CHANNEL_0                       =      4,
    205         MALI_CHANNEL_1                       =      5,
    206 };
    207 
    208 static inline const char *
    209 mali_channel_as_str(enum mali_channel imm)
    210 {
    211     switch (imm) {
    212     case MALI_CHANNEL_R: return "R";
    213     case MALI_CHANNEL_G: return "G";
    214     case MALI_CHANNEL_B: return "B";
    215     case MALI_CHANNEL_A: return "A";
    216     case MALI_CHANNEL_0: return "0";
    217     case MALI_CHANNEL_1: return "1";
    218     default: return "XXX: INVALID";
    219     }
    220 }
    221 
    222 enum mali_depth_source {
    223         MALI_DEPTH_SOURCE_MINIMUM            =      0,
    224         MALI_DEPTH_SOURCE_MAXIMUM            =      1,
    225         MALI_DEPTH_SOURCE_FIXED_FUNCTION     =      2,
    226         MALI_DEPTH_SOURCE_SHADER             =      3,
    227 };
    228 
    229 static inline const char *
    230 mali_depth_source_as_str(enum mali_depth_source imm)
    231 {
    232     switch (imm) {
    233     case MALI_DEPTH_SOURCE_MINIMUM: return "Minimum";
    234     case MALI_DEPTH_SOURCE_MAXIMUM: return "Maximum";
    235     case MALI_DEPTH_SOURCE_FIXED_FUNCTION: return "Fixed function";
    236     case MALI_DEPTH_SOURCE_SHADER: return "Shader";
    237     default: return "XXX: INVALID";
    238     }
    239 }
    240 
    241 enum mali_job_type {
    242         MALI_JOB_TYPE_NOT_STARTED            =      0,
    243         MALI_JOB_TYPE_NULL                   =      1,
    244         MALI_JOB_TYPE_WRITE_VALUE            =      2,
    245         MALI_JOB_TYPE_CACHE_FLUSH            =      3,
    246         MALI_JOB_TYPE_COMPUTE                =      4,
    247         MALI_JOB_TYPE_VERTEX                 =      5,
    248         MALI_JOB_TYPE_GEOMETRY               =      6,
    249         MALI_JOB_TYPE_TILER                  =      7,
    250         MALI_JOB_TYPE_FUSED                  =      8,
    251         MALI_JOB_TYPE_FRAGMENT               =      9,
    252         MALI_JOB_TYPE_INDEXED_VERTEX         =     10,
    253 };
    254 
    255 static inline const char *
    256 mali_job_type_as_str(enum mali_job_type imm)
    257 {
    258     switch (imm) {
    259     case MALI_JOB_TYPE_NOT_STARTED: return "Not started";
    260     case MALI_JOB_TYPE_NULL: return "Null";
    261     case MALI_JOB_TYPE_WRITE_VALUE: return "Write value";
    262     case MALI_JOB_TYPE_CACHE_FLUSH: return "Cache flush";
    263     case MALI_JOB_TYPE_COMPUTE: return "Compute";
    264     case MALI_JOB_TYPE_VERTEX: return "Vertex";
    265     case MALI_JOB_TYPE_GEOMETRY: return "Geometry";
    266     case MALI_JOB_TYPE_TILER: return "Tiler";
    267     case MALI_JOB_TYPE_FUSED: return "Fused";
    268     case MALI_JOB_TYPE_FRAGMENT: return "Fragment";
    269     case MALI_JOB_TYPE_INDEXED_VERTEX: return "Indexed Vertex";
    270     default: return "XXX: INVALID";
    271     }
    272 }
    273 
    274 enum mali_draw_mode {
    275         MALI_DRAW_MODE_NONE                  =      0,
    276         MALI_DRAW_MODE_POINTS                =      1,
    277         MALI_DRAW_MODE_LINES                 =      2,
    278         MALI_DRAW_MODE_LINE_STRIP            =      4,
    279         MALI_DRAW_MODE_LINE_LOOP             =      6,
    280         MALI_DRAW_MODE_TRIANGLES             =      8,
    281         MALI_DRAW_MODE_TRIANGLE_STRIP        =     10,
    282         MALI_DRAW_MODE_TRIANGLE_FAN          =     12,
    283         MALI_DRAW_MODE_POLYGON               =     13,
    284         MALI_DRAW_MODE_QUADS                 =     14,
    285 };
    286 
    287 static inline const char *
    288 mali_draw_mode_as_str(enum mali_draw_mode imm)
    289 {
    290     switch (imm) {
    291     case MALI_DRAW_MODE_NONE: return "None";
    292     case MALI_DRAW_MODE_POINTS: return "Points";
    293     case MALI_DRAW_MODE_LINES: return "Lines";
    294     case MALI_DRAW_MODE_LINE_STRIP: return "Line strip";
    295     case MALI_DRAW_MODE_LINE_LOOP: return "Line loop";
    296     case MALI_DRAW_MODE_TRIANGLES: return "Triangles";
    297     case MALI_DRAW_MODE_TRIANGLE_STRIP: return "Triangle strip";
    298     case MALI_DRAW_MODE_TRIANGLE_FAN: return "Triangle fan";
    299     case MALI_DRAW_MODE_POLYGON: return "Polygon";
    300     case MALI_DRAW_MODE_QUADS: return "Quads";
    301     default: return "XXX: INVALID";
    302     }
    303 }
    304 
    305 enum mali_exception_access {
    306         MALI_EXCEPTION_ACCESS_NONE           =      0,
    307         MALI_EXCEPTION_ACCESS_EXECUTE        =      2,
    308         MALI_EXCEPTION_ACCESS_READ           =      1,
    309         MALI_EXCEPTION_ACCESS_WRITE          =      3,
    310 };
    311 
    312 static inline const char *
    313 mali_exception_access_as_str(enum mali_exception_access imm)
    314 {
    315     switch (imm) {
    316     case MALI_EXCEPTION_ACCESS_NONE: return "None";
    317     case MALI_EXCEPTION_ACCESS_EXECUTE: return "Execute";
    318     case MALI_EXCEPTION_ACCESS_READ: return "Read";
    319     case MALI_EXCEPTION_ACCESS_WRITE: return "Write";
    320     default: return "XXX: INVALID";
    321     }
    322 }
    323 
    324 enum mali_func {
    325         MALI_FUNC_NEVER                      =      0,
    326         MALI_FUNC_LESS                       =      1,
    327         MALI_FUNC_EQUAL                      =      2,
    328         MALI_FUNC_LEQUAL                     =      3,
    329         MALI_FUNC_GREATER                    =      4,
    330         MALI_FUNC_NOT_EQUAL                  =      5,
    331         MALI_FUNC_GEQUAL                     =      6,
    332         MALI_FUNC_ALWAYS                     =      7,
    333 };
    334 
    335 static inline const char *
    336 mali_func_as_str(enum mali_func imm)
    337 {
    338     switch (imm) {
    339     case MALI_FUNC_NEVER: return "Never";
    340     case MALI_FUNC_LESS: return "Less";
    341     case MALI_FUNC_EQUAL: return "Equal";
    342     case MALI_FUNC_LEQUAL: return "Lequal";
    343     case MALI_FUNC_GREATER: return "Greater";
    344     case MALI_FUNC_NOT_EQUAL: return "Not Equal";
    345     case MALI_FUNC_GEQUAL: return "Gequal";
    346     case MALI_FUNC_ALWAYS: return "Always";
    347     default: return "XXX: INVALID";
    348     }
    349 }
    350 
    351 enum mali_format {
    352         MALI_ETC2_RGB8                       =      1,
    353         MALI_ETC2_R11_UNORM                  =      2,
    354         MALI_ETC2_RGBA8                      =      3,
    355         MALI_ETC2_RG11_UNORM                 =      4,
    356         MALI_R4A4_UNORM                      =      5,
    357         MALI_A4R4_UNORM                      =      6,
    358         MALI_BC1_UNORM                       =      7,
    359         MALI_BC2_UNORM                       =      8,
    360         MALI_BC3_UNORM                       =      9,
    361         MALI_BC4_UNORM                       =     10,
    362         MALI_BC4_SNORM                       =     11,
    363         MALI_BC5_UNORM                       =     12,
    364         MALI_BC5_SNORM                       =     13,
    365         MALI_BC6H_UF16                       =     14,
    366         MALI_BC6H_SF16                       =     15,
    367         MALI_BC7_UNORM                       =     16,
    368         MALI_ETC2_R11_SNORM                  =     17,
    369         MALI_ETC2_RG11_SNORM                 =     18,
    370         MALI_ETC2_RGB8A1                     =     19,
    371         MALI_ASTC_3D_LDR                     =     20,
    372         MALI_ASTC_3D_HDR                     =     21,
    373         MALI_ASTC_2D_LDR                     =     22,
    374         MALI_ASTC_2D_HDR                     =     23,
    375         MALI_R8A8_UNORM                      =     24,
    376         MALI_A8R8_UNORM                      =     25,
    377         MALI_A8_UNORM                        =     26,
    378         MALI_RAW10                           =     28,
    379         MALI_RAW12                           =     29,
    380         MALI_R8G8B8G8                        =     30,
    381         MALI_G8R8G8B8                        =     31,
    382         MALI_YUV8                            =     32,
    383         MALI_YUVA8                           =     33,
    384         MALI_YUYV8                           =     34,
    385         MALI_VYUY8                           =     35,
    386         MALI_Y8_UV8_422                      =     36,
    387         MALI_Y8_U8_V8_422                    =     37,
    388         MALI_Y8_UV8_420                      =     38,
    389         MALI_Y8_U8_V8_420                    =     39,
    390         MALI_YUV10_A2                        =     40,
    391         MALI_A2_YUV10                        =     41,
    392         MALI_YUYAAYVYAA                      =     42,
    393         MALI_YUYV10                          =     44,
    394         MALI_VYUY10                          =     45,
    395         MALI_Y10_UV10_422                    =     46,
    396         MALI_Y10_UV10_420                    =     47,
    397         MALI_YUV16                           =     48,
    398         MALI_YUVA16                          =     49,
    399         MALI_YUYV16                          =     50,
    400         MALI_VYUY16                          =     51,
    401         MALI_Y10X6_U10X6V10X6_422            =     52,
    402         MALI_Y16_UV16_422                    =     53,
    403         MALI_Y10X6_U10X6V10X6_420            =     54,
    404         MALI_Y16_UV16_420                    =     55,
    405         MALI_Y8_UV8_BL_422                   =     56,
    406         MALI_Y8_UV8_BL_420                   =     57,
    407         MALI_CUSTOM_YUV_2                    =     58,
    408         MALI_CUSTOM_YUV_3                    =     59,
    409         MALI_CUSTOM_YUV_4                    =     60,
    410         MALI_CUSTOM_YUV_5                    =     61,
    411         MALI_ASTC_2D_NARROW                  =     62,
    412         MALI_ASTC_3D_NARROW                  =     63,
    413         MALI_RGB565                          =     64,
    414         MALI_RGB5_A1_UNORM                   =     65,
    415         MALI_A1_BGR5_UNORM                   =     66,
    416         MALI_RGB10_A2_UNORM                  =     67,
    417         MALI_A2_BGR10_UNORM                  =     68,
    418         MALI_RGB10_A2_SNORM                  =     69,
    419         MALI_A2_BGR10_SNORM                  =     70,
    420         MALI_RGB10_A2UI                      =     71,
    421         MALI_A2_BGR10UI                      =     72,
    422         MALI_RGB10_A2I                       =     73,
    423         MALI_A2_BGR10I                       =     74,
    424         MALI_Z16_UNORM                       =     75,
    425         MALI_Z32                             =     76,
    426         MALI_Z24X8_UNORM                     =     77,
    427         MALI_X8Z24                           =     78,
    428         MALI_X32_S8X24                       =     79,
    429         MALI_X24S8_X32                       =     80,
    430         MALI_R32_FIXED                       =     81,
    431         MALI_RG32_FIXED                      =     82,
    432         MALI_RGB32_FIXED                     =     83,
    433         MALI_RGBA32_FIXED                    =     84,
    434         MALI_X24S8                           =     85,
    435         MALI_S8X24                           =     86,
    436         MALI_Z32_X32                         =     87,
    437         MALI_X32_Z32                         =     88,
    438         MALI_R11F_G11F_B10F                  =     89,
    439         MALI_B10F_G11F_R11F                  =     90,
    440         MALI_R9F_G9F_B9F_E5F                 =     91,
    441         MALI_E5F_B9F_G9F_R9F                 =     92,
    442         MALI_S8                              =     93,
    443         MALI_SNAP_4                          =     94,
    444         MALI_CONSTANT                        =     95,
    445         MALI_R8_SNORM                        =     99,
    446         MALI_R16_SNORM                       =    100,
    447         MALI_R32_SNORM                       =    101,
    448         MALI_RG4_SNORM                       =    106,
    449         MALI_RG8_SNORM                       =    107,
    450         MALI_RG16_SNORM                      =    108,
    451         MALI_RG32_SNORM                      =    109,
    452         MALI_RGB8_SNORM                      =    115,
    453         MALI_RGB16_SNORM                     =    116,
    454         MALI_RGB32_SNORM                     =    117,
    455         MALI_RGBA2_SNORM                     =    121,
    456         MALI_RGBA4_SNORM                     =    122,
    457         MALI_RGBA8_SNORM                     =    123,
    458         MALI_RGBA16_SNORM                    =    124,
    459         MALI_RGBA32_SNORM                    =    125,
    460         MALI_R8UI                            =    131,
    461         MALI_R16UI                           =    132,
    462         MALI_R32UI                           =    133,
    463         MALI_RG4UI                           =    138,
    464         MALI_RG8UI                           =    139,
    465         MALI_RG16UI                          =    140,
    466         MALI_RG32UI                          =    141,
    467         MALI_RGB8UI                          =    147,
    468         MALI_RGB16UI                         =    148,
    469         MALI_RGB32UI                         =    149,
    470         MALI_RGBA2UI                         =    153,
    471         MALI_RGBA4UI                         =    154,
    472         MALI_RGBA8UI                         =    155,
    473         MALI_RGBA16UI                        =    156,
    474         MALI_RGBA32UI                        =    157,
    475         MALI_R8_UNORM                        =    163,
    476         MALI_R16_UNORM                       =    164,
    477         MALI_R32_UNORM                       =    165,
    478         MALI_R32F                            =    167,
    479         MALI_RG4_UNORM                       =    170,
    480         MALI_RG8_UNORM                       =    171,
    481         MALI_RG16_UNORM                      =    172,
    482         MALI_RG32_UNORM                      =    173,
    483         MALI_RG32F                           =    175,
    484         MALI_RGB8_UNORM                      =    179,
    485         MALI_RGB16_UNORM                     =    180,
    486         MALI_RGB32_UNORM                     =    181,
    487         MALI_RGB32F                          =    183,
    488         MALI_RGBA2_UNORM                     =    185,
    489         MALI_RGBA4_UNORM                     =    186,
    490         MALI_RGBA8_UNORM                     =    187,
    491         MALI_RGBA16_UNORM                    =    188,
    492         MALI_RGBA32_UNORM                    =    189,
    493         MALI_RGBA32F                         =    191,
    494         MALI_R8I                             =    195,
    495         MALI_R16I                            =    196,
    496         MALI_R32I                            =    197,
    497         MALI_R16F                            =    199,
    498         MALI_RG4I                            =    202,
    499         MALI_RG8I                            =    203,
    500         MALI_RG16I                           =    204,
    501         MALI_RG32I                           =    205,
    502         MALI_RG16F                           =    207,
    503         MALI_RGB8I                           =    211,
    504         MALI_RGB16I                          =    212,
    505         MALI_RGB32I                          =    213,
    506         MALI_RGB16F                          =    215,
    507         MALI_RGBA2I                          =    217,
    508         MALI_RGBA4I                          =    218,
    509         MALI_RGBA8I                          =    219,
    510         MALI_RGBA16I                         =    220,
    511         MALI_RGBA32I                         =    221,
    512         MALI_RGBA16F                         =    223,
    513         MALI_RGB5_A1_AU                      =    224,
    514         MALI_RGB5_A1_PU                      =    225,
    515         MALI_R5G6B5_AU                       =    226,
    516         MALI_R5G6B5_PU                       =    227,
    517         MALI_SNAP4_V                         =    230,
    518         MALI_R32F_RTZ                        =    231,
    519         MALI_RGBA4_AU                        =    232,
    520         MALI_RGBA4_PU                        =    233,
    521         MALI_RGBA8_TB                        =    237,
    522         MALI_RGB10_A2_TB                     =    238,
    523         MALI_RG32F_RTZ                       =    239,
    524         MALI_TESS_VERTEX_PACK                =    240,
    525         MALI_RGB8_A2_AU                      =    241,
    526         MALI_RGB8_A2_PU                      =    242,
    527         MALI_RGB32F_RTZ                      =    247,
    528         MALI_RGBA32F_RTZ                     =    255,
    529 };
    530 
    531 static inline const char *
    532 mali_format_as_str(enum mali_format imm)
    533 {
    534     switch (imm) {
    535     case MALI_ETC2_RGB8: return "ETC2 RGB8";
    536     case MALI_ETC2_R11_UNORM: return "ETC2 R11 UNORM";
    537     case MALI_ETC2_RGBA8: return "ETC2 RGBA8";
    538     case MALI_ETC2_RG11_UNORM: return "ETC2 RG11 UNORM";
    539     case MALI_R4A4_UNORM: return "R4A4 UNORM";
    540     case MALI_A4R4_UNORM: return "A4R4 UNORM";
    541     case MALI_BC1_UNORM: return "BC1 UNORM";
    542     case MALI_BC2_UNORM: return "BC2 UNORM";
    543     case MALI_BC3_UNORM: return "BC3 UNORM";
    544     case MALI_BC4_UNORM: return "BC4 UNORM";
    545     case MALI_BC4_SNORM: return "BC4 SNORM";
    546     case MALI_BC5_UNORM: return "BC5 UNORM";
    547     case MALI_BC5_SNORM: return "BC5 SNORM";
    548     case MALI_BC6H_UF16: return "BC6H UF16";
    549     case MALI_BC6H_SF16: return "BC6H SF16";
    550     case MALI_BC7_UNORM: return "BC7 UNORM";
    551     case MALI_ETC2_R11_SNORM: return "ETC2 R11 SNORM";
    552     case MALI_ETC2_RG11_SNORM: return "ETC2 RG11 SNORM";
    553     case MALI_ETC2_RGB8A1: return "ETC2 RGB8A1";
    554     case MALI_ASTC_3D_LDR: return "ASTC 3D LDR";
    555     case MALI_ASTC_3D_HDR: return "ASTC 3D HDR";
    556     case MALI_ASTC_2D_LDR: return "ASTC 2D LDR";
    557     case MALI_ASTC_2D_HDR: return "ASTC 2D HDR";
    558     case MALI_R8A8_UNORM: return "R8A8 UNORM";
    559     case MALI_A8R8_UNORM: return "A8R8 UNORM";
    560     case MALI_A8_UNORM: return "A8 UNORM";
    561     case MALI_RAW10: return "RAW10";
    562     case MALI_RAW12: return "RAW12";
    563     case MALI_R8G8B8G8: return "R8G8B8G8";
    564     case MALI_G8R8G8B8: return "G8R8G8B8";
    565     case MALI_YUV8: return "YUV8";
    566     case MALI_YUVA8: return "YUVA8";
    567     case MALI_YUYV8: return "YUYV8";
    568     case MALI_VYUY8: return "VYUY8";
    569     case MALI_Y8_UV8_422: return "Y8 UV8 422";
    570     case MALI_Y8_U8_V8_422: return "Y8 U8 V8 422";
    571     case MALI_Y8_UV8_420: return "Y8 UV8 420";
    572     case MALI_Y8_U8_V8_420: return "Y8 U8 V8 420";
    573     case MALI_YUV10_A2: return "YUV10 A2";
    574     case MALI_A2_YUV10: return "A2 YUV10";
    575     case MALI_YUYAAYVYAA: return "YUYAAYVYAA";
    576     case MALI_YUYV10: return "YUYV10";
    577     case MALI_VYUY10: return "VYUY10";
    578     case MALI_Y10_UV10_422: return "Y10 UV10 422";
    579     case MALI_Y10_UV10_420: return "Y10 UV10 420";
    580     case MALI_YUV16: return "YUV16";
    581     case MALI_YUVA16: return "YUVA16";
    582     case MALI_YUYV16: return "YUYV16";
    583     case MALI_VYUY16: return "VYUY16";
    584     case MALI_Y10X6_U10X6V10X6_422: return "Y10X6 U10X6V10X6 422";
    585     case MALI_Y16_UV16_422: return "Y16 UV16 422";
    586     case MALI_Y10X6_U10X6V10X6_420: return "Y10X6 U10X6V10X6 420";
    587     case MALI_Y16_UV16_420: return "Y16 UV16 420";
    588     case MALI_Y8_UV8_BL_422: return "Y8 UV8 BL 422";
    589     case MALI_Y8_UV8_BL_420: return "Y8 UV8 BL 420";
    590     case MALI_CUSTOM_YUV_2: return "CUSTOM YUV 2";
    591     case MALI_CUSTOM_YUV_3: return "CUSTOM YUV 3";
    592     case MALI_CUSTOM_YUV_4: return "CUSTOM YUV 4";
    593     case MALI_CUSTOM_YUV_5: return "CUSTOM YUV 5";
    594     case MALI_ASTC_2D_NARROW: return "ASTC 2D NARROW";
    595     case MALI_ASTC_3D_NARROW: return "ASTC 3D NARROW";
    596     case MALI_RGB565: return "RGB565";
    597     case MALI_RGB5_A1_UNORM: return "RGB5 A1 UNORM";
    598     case MALI_A1_BGR5_UNORM: return "A1 BGR5 UNORM";
    599     case MALI_RGB10_A2_UNORM: return "RGB10 A2 UNORM";
    600     case MALI_A2_BGR10_UNORM: return "A2 BGR10 UNORM";
    601     case MALI_RGB10_A2_SNORM: return "RGB10 A2 SNORM";
    602     case MALI_A2_BGR10_SNORM: return "A2 BGR10 SNORM";
    603     case MALI_RGB10_A2UI: return "RGB10 A2UI";
    604     case MALI_A2_BGR10UI: return "A2 BGR10UI";
    605     case MALI_RGB10_A2I: return "RGB10 A2I";
    606     case MALI_A2_BGR10I: return "A2 BGR10I";
    607     case MALI_Z16_UNORM: return "Z16 UNORM";
    608     case MALI_Z32: return "Z32";
    609     case MALI_Z24X8_UNORM: return "Z24X8 UNORM";
    610     case MALI_X8Z24: return "X8Z24";
    611     case MALI_X32_S8X24: return "X32 S8X24";
    612     case MALI_X24S8_X32: return "X24S8 X32";
    613     case MALI_R32_FIXED: return "R32 FIXED";
    614     case MALI_RG32_FIXED: return "RG32 FIXED";
    615     case MALI_RGB32_FIXED: return "RGB32 FIXED";
    616     case MALI_RGBA32_FIXED: return "RGBA32 FIXED";
    617     case MALI_X24S8: return "X24S8";
    618     case MALI_S8X24: return "S8X24";
    619     case MALI_Z32_X32: return "Z32 X32";
    620     case MALI_X32_Z32: return "X32 Z32";
    621     case MALI_R11F_G11F_B10F: return "R11F G11F B10F";
    622     case MALI_B10F_G11F_R11F: return "B10F G11F R11F";
    623     case MALI_R9F_G9F_B9F_E5F: return "R9F G9F B9F E5F";
    624     case MALI_E5F_B9F_G9F_R9F: return "E5F B9F G9F R9F";
    625     case MALI_S8: return "S8";
    626     case MALI_SNAP_4: return "Snap 4";
    627     case MALI_CONSTANT: return "Constant";
    628     case MALI_R8_SNORM: return "R8 SNORM";
    629     case MALI_R16_SNORM: return "R16 SNORM";
    630     case MALI_R32_SNORM: return "R32 SNORM";
    631     case MALI_RG4_SNORM: return "RG4 SNORM";
    632     case MALI_RG8_SNORM: return "RG8 SNORM";
    633     case MALI_RG16_SNORM: return "RG16 SNORM";
    634     case MALI_RG32_SNORM: return "RG32 SNORM";
    635     case MALI_RGB8_SNORM: return "RGB8 SNORM";
    636     case MALI_RGB16_SNORM: return "RGB16 SNORM";
    637     case MALI_RGB32_SNORM: return "RGB32 SNORM";
    638     case MALI_RGBA2_SNORM: return "RGBA2 SNORM";
    639     case MALI_RGBA4_SNORM: return "RGBA4 SNORM";
    640     case MALI_RGBA8_SNORM: return "RGBA8 SNORM";
    641     case MALI_RGBA16_SNORM: return "RGBA16 SNORM";
    642     case MALI_RGBA32_SNORM: return "RGBA32 SNORM";
    643     case MALI_R8UI: return "R8UI";
    644     case MALI_R16UI: return "R16UI";
    645     case MALI_R32UI: return "R32UI";
    646     case MALI_RG4UI: return "RG4UI";
    647     case MALI_RG8UI: return "RG8UI";
    648     case MALI_RG16UI: return "RG16UI";
    649     case MALI_RG32UI: return "RG32UI";
    650     case MALI_RGB8UI: return "RGB8UI";
    651     case MALI_RGB16UI: return "RGB16UI";
    652     case MALI_RGB32UI: return "RGB32UI";
    653     case MALI_RGBA2UI: return "RGBA2UI";
    654     case MALI_RGBA4UI: return "RGBA4UI";
    655     case MALI_RGBA8UI: return "RGBA8UI";
    656     case MALI_RGBA16UI: return "RGBA16UI";
    657     case MALI_RGBA32UI: return "RGBA32UI";
    658     case MALI_R8_UNORM: return "R8 UNORM";
    659     case MALI_R16_UNORM: return "R16 UNORM";
    660     case MALI_R32_UNORM: return "R32 UNORM";
    661     case MALI_R32F: return "R32F";
    662     case MALI_RG4_UNORM: return "RG4 UNORM";
    663     case MALI_RG8_UNORM: return "RG8 UNORM";
    664     case MALI_RG16_UNORM: return "RG16 UNORM";
    665     case MALI_RG32_UNORM: return "RG32 UNORM";
    666     case MALI_RG32F: return "RG32F";
    667     case MALI_RGB8_UNORM: return "RGB8 UNORM";
    668     case MALI_RGB16_UNORM: return "RGB16 UNORM";
    669     case MALI_RGB32_UNORM: return "RGB32 UNORM";
    670     case MALI_RGB32F: return "RGB32F";
    671     case MALI_RGBA2_UNORM: return "RGBA2 UNORM";
    672     case MALI_RGBA4_UNORM: return "RGBA4 UNORM";
    673     case MALI_RGBA8_UNORM: return "RGBA8 UNORM";
    674     case MALI_RGBA16_UNORM: return "RGBA16 UNORM";
    675     case MALI_RGBA32_UNORM: return "RGBA32 UNORM";
    676     case MALI_RGBA32F: return "RGBA32F";
    677     case MALI_R8I: return "R8I";
    678     case MALI_R16I: return "R16I";
    679     case MALI_R32I: return "R32I";
    680     case MALI_R16F: return "R16F";
    681     case MALI_RG4I: return "RG4I";
    682     case MALI_RG8I: return "RG8I";
    683     case MALI_RG16I: return "RG16I";
    684     case MALI_RG32I: return "RG32I";
    685     case MALI_RG16F: return "RG16F";
    686     case MALI_RGB8I: return "RGB8I";
    687     case MALI_RGB16I: return "RGB16I";
    688     case MALI_RGB32I: return "RGB32I";
    689     case MALI_RGB16F: return "RGB16F";
    690     case MALI_RGBA2I: return "RGBA2I";
    691     case MALI_RGBA4I: return "RGBA4I";
    692     case MALI_RGBA8I: return "RGBA8I";
    693     case MALI_RGBA16I: return "RGBA16I";
    694     case MALI_RGBA32I: return "RGBA32I";
    695     case MALI_RGBA16F: return "RGBA16F";
    696     case MALI_RGB5_A1_AU: return "RGB5 A1 AU";
    697     case MALI_RGB5_A1_PU: return "RGB5 A1 PU";
    698     case MALI_R5G6B5_AU: return "R5G6B5 AU";
    699     case MALI_R5G6B5_PU: return "R5G6B5 PU";
    700     case MALI_SNAP4_V: return "Snap4 V";
    701     case MALI_R32F_RTZ: return "R32F RTZ";
    702     case MALI_RGBA4_AU: return "RGBA4 AU";
    703     case MALI_RGBA4_PU: return "RGBA4 PU";
    704     case MALI_RGBA8_TB: return "RGBA8 TB";
    705     case MALI_RGB10_A2_TB: return "RGB10 A2 TB";
    706     case MALI_RG32F_RTZ: return "RG32F RTZ";
    707     case MALI_TESS_VERTEX_PACK: return "Tess Vertex Pack";
    708     case MALI_RGB8_A2_AU: return "RGB8 A2 AU";
    709     case MALI_RGB8_A2_PU: return "RGB8 A2 PU";
    710     case MALI_RGB32F_RTZ: return "RGB32F RTZ";
    711     case MALI_RGBA32F_RTZ: return "RGBA32F RTZ";
    712     default: return "XXX: INVALID";
    713     }
    714 }
    715 
    716 enum mali_rgb_component_order {
    717         MALI_RGB_COMPONENT_ORDER_RGBA        =      0,
    718         MALI_RGB_COMPONENT_ORDER_GRBA        =      2,
    719         MALI_RGB_COMPONENT_ORDER_BGRA        =      4,
    720         MALI_RGB_COMPONENT_ORDER_ARGB        =      8,
    721         MALI_RGB_COMPONENT_ORDER_AGRB        =     10,
    722         MALI_RGB_COMPONENT_ORDER_ABGR        =     12,
    723         MALI_RGB_COMPONENT_ORDER_RGB1        =     16,
    724         MALI_RGB_COMPONENT_ORDER_GRB1        =     18,
    725         MALI_RGB_COMPONENT_ORDER_BGR1        =     20,
    726         MALI_RGB_COMPONENT_ORDER_1RGB        =     24,
    727         MALI_RGB_COMPONENT_ORDER_1GRB        =     26,
    728         MALI_RGB_COMPONENT_ORDER_1BGR        =     28,
    729         MALI_RGB_COMPONENT_ORDER_RRRR        =    226,
    730         MALI_RGB_COMPONENT_ORDER_RRR1        =    227,
    731         MALI_RGB_COMPONENT_ORDER_RRRA        =    228,
    732         MALI_RGB_COMPONENT_ORDER_000A        =    229,
    733         MALI_RGB_COMPONENT_ORDER_0001        =    230,
    734         MALI_RGB_COMPONENT_ORDER_0000        =    231,
    735         MALI_RGB_COMPONENT_ORDER_SNAP4_V9    =    232,
    736         MALI_RGB_COMPONENT_ORDER_SNAP4_V10   =    233,
    737         MALI_RGB_COMPONENT_ORDER_SNAP4_V11   =    234,
    738         MALI_RGB_COMPONENT_ORDER_SNAP4_V12   =    235,
    739         MALI_RGB_COMPONENT_ORDER_SNAP4_V13   =    236,
    740         MALI_RGB_COMPONENT_ORDER_SNAP4_V14   =    237,
    741         MALI_RGB_COMPONENT_ORDER_SNAP4_V15   =    238,
    742         MALI_RGB_COMPONENT_ORDER_SNAP4_V16   =    239,
    743         MALI_RGB_COMPONENT_ORDER_R000        =    240,
    744         MALI_RGB_COMPONENT_ORDER_RBGA        =    242,
    745 };
    746 
    747 static inline const char *
    748 mali_rgb_component_order_as_str(enum mali_rgb_component_order imm)
    749 {
    750     switch (imm) {
    751     case MALI_RGB_COMPONENT_ORDER_RGBA: return "RGBA";
    752     case MALI_RGB_COMPONENT_ORDER_GRBA: return "GRBA";
    753     case MALI_RGB_COMPONENT_ORDER_BGRA: return "BGRA";
    754     case MALI_RGB_COMPONENT_ORDER_ARGB: return "ARGB";
    755     case MALI_RGB_COMPONENT_ORDER_AGRB: return "AGRB";
    756     case MALI_RGB_COMPONENT_ORDER_ABGR: return "ABGR";
    757     case MALI_RGB_COMPONENT_ORDER_RGB1: return "RGB1";
    758     case MALI_RGB_COMPONENT_ORDER_GRB1: return "GRB1";
    759     case MALI_RGB_COMPONENT_ORDER_BGR1: return "BGR1";
    760     case MALI_RGB_COMPONENT_ORDER_1RGB: return "1RGB";
    761     case MALI_RGB_COMPONENT_ORDER_1GRB: return "1GRB";
    762     case MALI_RGB_COMPONENT_ORDER_1BGR: return "1BGR";
    763     case MALI_RGB_COMPONENT_ORDER_RRRR: return "RRRR";
    764     case MALI_RGB_COMPONENT_ORDER_RRR1: return "RRR1";
    765     case MALI_RGB_COMPONENT_ORDER_RRRA: return "RRRA";
    766     case MALI_RGB_COMPONENT_ORDER_000A: return "000A";
    767     case MALI_RGB_COMPONENT_ORDER_0001: return "0001";
    768     case MALI_RGB_COMPONENT_ORDER_0000: return "0000";
    769     case MALI_RGB_COMPONENT_ORDER_SNAP4_V9: return "Snap4 v9";
    770     case MALI_RGB_COMPONENT_ORDER_SNAP4_V10: return "Snap4 v10";
    771     case MALI_RGB_COMPONENT_ORDER_SNAP4_V11: return "Snap4 v11";
    772     case MALI_RGB_COMPONENT_ORDER_SNAP4_V12: return "Snap4 v12";
    773     case MALI_RGB_COMPONENT_ORDER_SNAP4_V13: return "Snap4 v13";
    774     case MALI_RGB_COMPONENT_ORDER_SNAP4_V14: return "Snap4 v14";
    775     case MALI_RGB_COMPONENT_ORDER_SNAP4_V15: return "Snap4 v15";
    776     case MALI_RGB_COMPONENT_ORDER_SNAP4_V16: return "Snap4 v16";
    777     case MALI_RGB_COMPONENT_ORDER_R000: return "R000";
    778     case MALI_RGB_COMPONENT_ORDER_RBGA: return "RBGA";
    779     default: return "XXX: INVALID";
    780     }
    781 }
    782 
    783 enum mali_yuv_swizzle {
    784         MALI_YUV_SWIZZLE_YUVA                =      0,
    785         MALI_YUV_SWIZZLE_YVUA                =      1,
    786         MALI_YUV_SWIZZLE_UYVA                =      2,
    787         MALI_YUV_SWIZZLE_UVYA                =      3,
    788         MALI_YUV_SWIZZLE_VUYA                =      4,
    789         MALI_YUV_SWIZZLE_VYUA                =      5,
    790         MALI_YUV_SWIZZLE_Y00A                =      6,
    791         MALI_YUV_SWIZZLE_YXXA                =      7,
    792 };
    793 
    794 static inline const char *
    795 mali_yuv_swizzle_as_str(enum mali_yuv_swizzle imm)
    796 {
    797     switch (imm) {
    798     case MALI_YUV_SWIZZLE_YUVA: return "YUVA";
    799     case MALI_YUV_SWIZZLE_YVUA: return "YVUA";
    800     case MALI_YUV_SWIZZLE_UYVA: return "UYVA";
    801     case MALI_YUV_SWIZZLE_UVYA: return "UVYA";
    802     case MALI_YUV_SWIZZLE_VUYA: return "VUYA";
    803     case MALI_YUV_SWIZZLE_VYUA: return "VYUA";
    804     case MALI_YUV_SWIZZLE_Y00A: return "Y00A";
    805     case MALI_YUV_SWIZZLE_YXXA: return "YXXA";
    806     default: return "XXX: INVALID";
    807     }
    808 }
    809 
    810 enum mali_yuv_conversion_mode {
    811         MALI_YUV_CONVERSION_MODE_NO_CONVERSION =      0,
    812         MALI_YUV_CONVERSION_MODE_BT_601      =      3,
    813         MALI_YUV_CONVERSION_MODE_BT_709      =      4,
    814         MALI_YUV_CONVERSION_MODE_BT_2020     =      6,
    815 };
    816 
    817 static inline const char *
    818 mali_yuv_conversion_mode_as_str(enum mali_yuv_conversion_mode imm)
    819 {
    820     switch (imm) {
    821     case MALI_YUV_CONVERSION_MODE_NO_CONVERSION: return "No Conversion";
    822     case MALI_YUV_CONVERSION_MODE_BT_601: return "BT 601";
    823     case MALI_YUV_CONVERSION_MODE_BT_709: return "BT 709";
    824     case MALI_YUV_CONVERSION_MODE_BT_2020: return "BT 2020";
    825     default: return "XXX: INVALID";
    826     }
    827 }
    828 
    829 enum mali_yuv_cr_siting {
    830         MALI_YUV_CR_SITING_CO_SITED          =      0,
    831         MALI_YUV_CR_SITING_CENTER_Y          =      1,
    832         MALI_YUV_CR_SITING_CENTER_X          =      2,
    833         MALI_YUV_CR_SITING_CENTER            =      3,
    834         MALI_YUV_CR_SITING_ONE_QUARTER       =      4,
    835         MALI_YUV_CR_SITING_THREE_QUARTERS    =      5,
    836         MALI_YUV_CR_SITING_REPLICATED        =      7,
    837 };
    838 
    839 static inline const char *
    840 mali_yuv_cr_siting_as_str(enum mali_yuv_cr_siting imm)
    841 {
    842     switch (imm) {
    843     case MALI_YUV_CR_SITING_CO_SITED: return "Co-Sited";
    844     case MALI_YUV_CR_SITING_CENTER_Y: return "Center Y";
    845     case MALI_YUV_CR_SITING_CENTER_X: return "Center X";
    846     case MALI_YUV_CR_SITING_CENTER: return "Center";
    847     case MALI_YUV_CR_SITING_ONE_QUARTER: return "One Quarter";
    848     case MALI_YUV_CR_SITING_THREE_QUARTERS: return "Three Quarters";
    849     case MALI_YUV_CR_SITING_REPLICATED: return "Replicated";
    850     default: return "XXX: INVALID";
    851     }
    852 }
    853 
    854 enum mali_astc_2d_dimension {
    855         MALI_ASTC_2D_DIMENSION_4             =      0,
    856         MALI_ASTC_2D_DIMENSION_5             =      1,
    857         MALI_ASTC_2D_DIMENSION_6             =      2,
    858         MALI_ASTC_2D_DIMENSION_8             =      4,
    859         MALI_ASTC_2D_DIMENSION_10            =      6,
    860         MALI_ASTC_2D_DIMENSION_12            =      7,
    861 };
    862 
    863 static inline const char *
    864 mali_astc_2d_dimension_as_str(enum mali_astc_2d_dimension imm)
    865 {
    866     switch (imm) {
    867     case MALI_ASTC_2D_DIMENSION_4: return "4";
    868     case MALI_ASTC_2D_DIMENSION_5: return "5";
    869     case MALI_ASTC_2D_DIMENSION_6: return "6";
    870     case MALI_ASTC_2D_DIMENSION_8: return "8";
    871     case MALI_ASTC_2D_DIMENSION_10: return "10";
    872     case MALI_ASTC_2D_DIMENSION_12: return "12";
    873     default: return "XXX: INVALID";
    874     }
    875 }
    876 
    877 enum mali_astc_3d_dimension {
    878         MALI_ASTC_3D_DIMENSION_4             =      0,
    879         MALI_ASTC_3D_DIMENSION_5             =      1,
    880         MALI_ASTC_3D_DIMENSION_6             =      2,
    881         MALI_ASTC_3D_DIMENSION_3             =      3,
    882 };
    883 
    884 static inline const char *
    885 mali_astc_3d_dimension_as_str(enum mali_astc_3d_dimension imm)
    886 {
    887     switch (imm) {
    888     case MALI_ASTC_3D_DIMENSION_4: return "4";
    889     case MALI_ASTC_3D_DIMENSION_5: return "5";
    890     case MALI_ASTC_3D_DIMENSION_6: return "6";
    891     case MALI_ASTC_3D_DIMENSION_3: return "3";
    892     default: return "XXX: INVALID";
    893     }
    894 }
    895 
    896 enum mali_pixel_kill {
    897         MALI_PIXEL_KILL_FORCE_EARLY          =      0,
    898         MALI_PIXEL_KILL_STRONG_EARLY         =      1,
    899         MALI_PIXEL_KILL_WEAK_EARLY           =      2,
    900         MALI_PIXEL_KILL_FORCE_LATE           =      3,
    901 };
    902 
    903 static inline const char *
    904 mali_pixel_kill_as_str(enum mali_pixel_kill imm)
    905 {
    906     switch (imm) {
    907     case MALI_PIXEL_KILL_FORCE_EARLY: return "Force Early";
    908     case MALI_PIXEL_KILL_STRONG_EARLY: return "Strong Early";
    909     case MALI_PIXEL_KILL_WEAK_EARLY: return "Weak Early";
    910     case MALI_PIXEL_KILL_FORCE_LATE: return "Force Late";
    911     default: return "XXX: INVALID";
    912     }
    913 }
    914 
    915 enum mali_block_format {
    916         MALI_BLOCK_FORMAT_NO_WRITE           =      0,
    917         MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED =      1,
    918         MALI_BLOCK_FORMAT_LINEAR             =      2,
    919         MALI_BLOCK_FORMAT_AFBC               =     12,
    920         MALI_BLOCK_FORMAT_AFBC_TILED         =     13,
    921 };
    922 
    923 static inline const char *
    924 mali_block_format_as_str(enum mali_block_format imm)
    925 {
    926     switch (imm) {
    927     case MALI_BLOCK_FORMAT_NO_WRITE: return "No Write";
    928     case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: return "Tiled U-Interleaved";
    929     case MALI_BLOCK_FORMAT_LINEAR: return "Linear";
    930     case MALI_BLOCK_FORMAT_AFBC: return "AFBC";
    931     case MALI_BLOCK_FORMAT_AFBC_TILED: return "AFBC Tiled";
    932     default: return "XXX: INVALID";
    933     }
    934 }
    935 
    936 enum mali_mipmap_mode {
    937         MALI_MIPMAP_MODE_NEAREST             =      0,
    938         MALI_MIPMAP_MODE_NONE                =      1,
    939         MALI_MIPMAP_MODE_TRILINEAR           =      3,
    940 };
    941 
    942 static inline const char *
    943 mali_mipmap_mode_as_str(enum mali_mipmap_mode imm)
    944 {
    945     switch (imm) {
    946     case MALI_MIPMAP_MODE_NEAREST: return "Nearest";
    947     case MALI_MIPMAP_MODE_NONE: return "None";
    948     case MALI_MIPMAP_MODE_TRILINEAR: return "Trilinear";
    949     default: return "XXX: INVALID";
    950     }
    951 }
    952 
    953 enum mali_lod_algorithm {
    954         MALI_LOD_ALGORITHM_ISOTROPIC         =      0,
    955         MALI_LOD_ALGORITHM_ANISOTROPIC       =      3,
    956 };
    957 
    958 static inline const char *
    959 mali_lod_algorithm_as_str(enum mali_lod_algorithm imm)
    960 {
    961     switch (imm) {
    962     case MALI_LOD_ALGORITHM_ISOTROPIC: return "Isotropic";
    963     case MALI_LOD_ALGORITHM_ANISOTROPIC: return "Anisotropic";
    964     default: return "XXX: INVALID";
    965     }
    966 }
    967 
    968 enum mali_msaa {
    969         MALI_MSAA_SINGLE                     =      0,
    970         MALI_MSAA_AVERAGE                    =      1,
    971         MALI_MSAA_MULTIPLE                   =      2,
    972         MALI_MSAA_LAYERED                    =      3,
    973 };
    974 
    975 static inline const char *
    976 mali_msaa_as_str(enum mali_msaa imm)
    977 {
    978     switch (imm) {
    979     case MALI_MSAA_SINGLE: return "Single";
    980     case MALI_MSAA_AVERAGE: return "Average";
    981     case MALI_MSAA_MULTIPLE: return "Multiple";
    982     case MALI_MSAA_LAYERED: return "Layered";
    983     default: return "XXX: INVALID";
    984     }
    985 }
    986 
    987 enum mali_index_type {
    988         MALI_INDEX_TYPE_NONE                 =      0,
    989         MALI_INDEX_TYPE_UINT8                =      1,
    990         MALI_INDEX_TYPE_UINT16               =      2,
    991         MALI_INDEX_TYPE_UINT32               =      3,
    992 };
    993 
    994 static inline const char *
    995 mali_index_type_as_str(enum mali_index_type imm)
    996 {
    997     switch (imm) {
    998     case MALI_INDEX_TYPE_NONE: return "None";
    999     case MALI_INDEX_TYPE_UINT8: return "UINT8";
   1000     case MALI_INDEX_TYPE_UINT16: return "UINT16";
   1001     case MALI_INDEX_TYPE_UINT32: return "UINT32";
   1002     default: return "XXX: INVALID";
   1003     }
   1004 }
   1005 
   1006 enum mali_occlusion_mode {
   1007         MALI_OCCLUSION_MODE_DISABLED         =      0,
   1008         MALI_OCCLUSION_MODE_PREDICATE        =      1,
   1009         MALI_OCCLUSION_MODE_COUNTER          =      3,
   1010 };
   1011 
   1012 static inline const char *
   1013 mali_occlusion_mode_as_str(enum mali_occlusion_mode imm)
   1014 {
   1015     switch (imm) {
   1016     case MALI_OCCLUSION_MODE_DISABLED: return "Disabled";
   1017     case MALI_OCCLUSION_MODE_PREDICATE: return "Predicate";
   1018     case MALI_OCCLUSION_MODE_COUNTER: return "Counter";
   1019     default: return "XXX: INVALID";
   1020     }
   1021 }
   1022 
   1023 enum mali_stencil_op {
   1024         MALI_STENCIL_OP_KEEP                 =      0,
   1025         MALI_STENCIL_OP_REPLACE              =      1,
   1026         MALI_STENCIL_OP_ZERO                 =      2,
   1027         MALI_STENCIL_OP_INVERT               =      3,
   1028         MALI_STENCIL_OP_INCR_WRAP            =      4,
   1029         MALI_STENCIL_OP_DECR_WRAP            =      5,
   1030         MALI_STENCIL_OP_INCR_SAT             =      6,
   1031         MALI_STENCIL_OP_DECR_SAT             =      7,
   1032 };
   1033 
   1034 static inline const char *
   1035 mali_stencil_op_as_str(enum mali_stencil_op imm)
   1036 {
   1037     switch (imm) {
   1038     case MALI_STENCIL_OP_KEEP: return "Keep";
   1039     case MALI_STENCIL_OP_REPLACE: return "Replace";
   1040     case MALI_STENCIL_OP_ZERO: return "Zero";
   1041     case MALI_STENCIL_OP_INVERT: return "Invert";
   1042     case MALI_STENCIL_OP_INCR_WRAP: return "Incr Wrap";
   1043     case MALI_STENCIL_OP_DECR_WRAP: return "Decr Wrap";
   1044     case MALI_STENCIL_OP_INCR_SAT: return "Incr Sat";
   1045     case MALI_STENCIL_OP_DECR_SAT: return "Decr Sat";
   1046     default: return "XXX: INVALID";
   1047     }
   1048 }
   1049 
   1050 enum mali_texture_dimension {
   1051         MALI_TEXTURE_DIMENSION_CUBE          =      0,
   1052         MALI_TEXTURE_DIMENSION_1D            =      1,
   1053         MALI_TEXTURE_DIMENSION_2D            =      2,
   1054         MALI_TEXTURE_DIMENSION_3D            =      3,
   1055 };
   1056 
   1057 static inline const char *
   1058 mali_texture_dimension_as_str(enum mali_texture_dimension imm)
   1059 {
   1060     switch (imm) {
   1061     case MALI_TEXTURE_DIMENSION_CUBE: return "Cube";
   1062     case MALI_TEXTURE_DIMENSION_1D: return "1D";
   1063     case MALI_TEXTURE_DIMENSION_2D: return "2D";
   1064     case MALI_TEXTURE_DIMENSION_3D: return "3D";
   1065     default: return "XXX: INVALID";
   1066     }
   1067 }
   1068 
   1069 enum mali_texture_layout {
   1070         MALI_TEXTURE_LAYOUT_TILED            =      1,
   1071         MALI_TEXTURE_LAYOUT_LINEAR           =      2,
   1072         MALI_TEXTURE_LAYOUT_AFBC             =     12,
   1073 };
   1074 
   1075 static inline const char *
   1076 mali_texture_layout_as_str(enum mali_texture_layout imm)
   1077 {
   1078     switch (imm) {
   1079     case MALI_TEXTURE_LAYOUT_TILED: return "Tiled";
   1080     case MALI_TEXTURE_LAYOUT_LINEAR: return "Linear";
   1081     case MALI_TEXTURE_LAYOUT_AFBC: return "AFBC";
   1082     default: return "XXX: INVALID";
   1083     }
   1084 }
   1085 
   1086 enum mali_afbc_surface_flag {
   1087         MALI_AFBC_SURFACE_FLAG_YTR           =      1,
   1088         MALI_AFBC_SURFACE_FLAG_SPLIT_BLOCK   =      2,
   1089         MALI_AFBC_SURFACE_FLAG_WIDE_BLOCK    =      4,
   1090         MALI_AFBC_SURFACE_FLAG_TILED_HEADER  =      8,
   1091         MALI_AFBC_SURFACE_FLAG_PREFETCH      =     16,
   1092         MALI_AFBC_SURFACE_FLAG_CHECK_PAYLOAD_RANGE =     32,
   1093 };
   1094 
   1095 static inline const char *
   1096 mali_afbc_surface_flag_as_str(enum mali_afbc_surface_flag imm)
   1097 {
   1098     switch (imm) {
   1099     case MALI_AFBC_SURFACE_FLAG_YTR: return "YTR";
   1100     case MALI_AFBC_SURFACE_FLAG_SPLIT_BLOCK: return "Split Block";
   1101     case MALI_AFBC_SURFACE_FLAG_WIDE_BLOCK: return "Wide Block";
   1102     case MALI_AFBC_SURFACE_FLAG_TILED_HEADER: return "Tiled Header";
   1103     case MALI_AFBC_SURFACE_FLAG_PREFETCH: return "Prefetch";
   1104     case MALI_AFBC_SURFACE_FLAG_CHECK_PAYLOAD_RANGE: return "Check Payload Range";
   1105     default: return "XXX: INVALID";
   1106     }
   1107 }
   1108 
   1109 enum mali_wrap_mode {
   1110         MALI_WRAP_MODE_REPEAT                =      8,
   1111         MALI_WRAP_MODE_CLAMP_TO_EDGE         =      9,
   1112         MALI_WRAP_MODE_CLAMP_TO_BORDER       =     11,
   1113         MALI_WRAP_MODE_MIRRORED_REPEAT       =     12,
   1114         MALI_WRAP_MODE_MIRRORED_CLAMP_TO_EDGE =     13,
   1115         MALI_WRAP_MODE_MIRRORED_CLAMP_TO_BORDER =     15,
   1116 };
   1117 
   1118 static inline const char *
   1119 mali_wrap_mode_as_str(enum mali_wrap_mode imm)
   1120 {
   1121     switch (imm) {
   1122     case MALI_WRAP_MODE_REPEAT: return "Repeat";
   1123     case MALI_WRAP_MODE_CLAMP_TO_EDGE: return "Clamp to Edge";
   1124     case MALI_WRAP_MODE_CLAMP_TO_BORDER: return "Clamp to Border";
   1125     case MALI_WRAP_MODE_MIRRORED_REPEAT: return "Mirrored Repeat";
   1126     case MALI_WRAP_MODE_MIRRORED_CLAMP_TO_EDGE: return "Mirrored Clamp to Edge";
   1127     case MALI_WRAP_MODE_MIRRORED_CLAMP_TO_BORDER: return "Mirrored Clamp to Border";
   1128     default: return "XXX: INVALID";
   1129     }
   1130 }
   1131 
   1132 struct MALI_ATTRIBUTE {
   1133    uint32_t                             buffer_index;
   1134    bool                                 offset_enable;
   1135    uint32_t                             format;
   1136    int32_t                              offset;
   1137 };
   1138 
   1139 #define MALI_ATTRIBUTE_header                   \
   1140    .offset_enable = true
   1141 
   1142 static inline void
   1143 MALI_ATTRIBUTE_pack(uint32_t * restrict cl,
   1144                     const struct MALI_ATTRIBUTE * restrict values)
   1145 {
   1146    cl[ 0] = __gen_uint(values->buffer_index, 0, 8) |
   1147             __gen_uint(values->offset_enable, 9, 9) |
   1148             __gen_uint(values->format, 10, 31);
   1149    cl[ 1] = __gen_sint(values->offset, 0, 31);
   1150 }
   1151 
   1152 
   1153 #define MALI_ATTRIBUTE_LENGTH 8
   1154 #define MALI_ATTRIBUTE_ALIGN 8
   1155 struct mali_attribute_packed { uint32_t opaque[2]; };
   1156 static inline void
   1157 MALI_ATTRIBUTE_unpack(const uint8_t * restrict cl,
   1158                       struct MALI_ATTRIBUTE * restrict values)
   1159 {
   1160    values->buffer_index = __gen_unpack_uint(cl, 0, 8);
   1161    values->offset_enable = __gen_unpack_uint(cl, 9, 9);
   1162    values->format = __gen_unpack_uint(cl, 10, 31);
   1163    values->offset = __gen_unpack_sint(cl, 32, 63);
   1164 }
   1165 
   1166 static inline void
   1167 MALI_ATTRIBUTE_print(FILE *fp, const struct MALI_ATTRIBUTE * values, unsigned indent)
   1168 {
   1169    fprintf(fp, "%*sBuffer index: %u\n", indent, "", values->buffer_index);
   1170    fprintf(fp, "%*sOffset enable: %s\n", indent, "", values->offset_enable ? "true" : "false");
   1171    mali_pixel_format_print(fp, values->format);
   1172    fprintf(fp, "%*sOffset: %d\n", indent, "", values->offset);
   1173 }
   1174 
   1175 struct MALI_ATTRIBUTE_BUFFER {
   1176    enum mali_attribute_type             type;
   1177    uint64_t                             pointer;
   1178    uint32_t                             stride;
   1179    uint32_t                             size;
   1180    uint32_t                             divisor;
   1181    uint32_t                             divisor_r;
   1182    uint32_t                             divisor_p;
   1183    uint32_t                             divisor_e;
   1184 };
   1185 
   1186 #define MALI_ATTRIBUTE_BUFFER_header            \
   1187    .type = MALI_ATTRIBUTE_TYPE_1D,  \
   1188    .divisor = 1
   1189 
   1190 static inline void
   1191 MALI_ATTRIBUTE_BUFFER_pack(uint32_t * restrict cl,
   1192                            const struct MALI_ATTRIBUTE_BUFFER * restrict values)
   1193 {
   1194    assert((values->pointer & 0x3f) == 0);
   1195    cl[ 0] = __gen_uint(values->type, 0, 5) |
   1196             __gen_uint(values->pointer >> 6, 6, 55);
   1197    cl[ 1] = __gen_uint(values->pointer >> 6, 6, 55) >> 32 |
   1198             __gen_padded(values->divisor, 24, 31) |
   1199             __gen_uint(values->divisor_r, 24, 28) |
   1200             __gen_uint(values->divisor_p, 29, 31) |
   1201             __gen_uint(values->divisor_e, 29, 29);
   1202    cl[ 2] = __gen_uint(values->stride, 0, 31);
   1203    cl[ 3] = __gen_uint(values->size, 0, 31);
   1204 }
   1205 
   1206 
   1207 #define MALI_ATTRIBUTE_BUFFER_LENGTH 16
   1208 #define MALI_ATTRIBUTE_BUFFER_ALIGN 32
   1209 struct mali_attribute_buffer_packed { uint32_t opaque[4]; };
   1210 static inline void
   1211 MALI_ATTRIBUTE_BUFFER_unpack(const uint8_t * restrict cl,
   1212                              struct MALI_ATTRIBUTE_BUFFER * restrict values)
   1213 {
   1214    values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
   1215    values->pointer = __gen_unpack_uint(cl, 6, 55) << 6;
   1216    values->stride = __gen_unpack_uint(cl, 64, 95);
   1217    values->size = __gen_unpack_uint(cl, 96, 127);
   1218    values->divisor = __gen_unpack_padded(cl, 56, 63);
   1219    values->divisor_r = __gen_unpack_uint(cl, 56, 60);
   1220    values->divisor_p = __gen_unpack_uint(cl, 61, 63);
   1221    values->divisor_e = __gen_unpack_uint(cl, 61, 61);
   1222 }
   1223 
   1224 static inline void
   1225 MALI_ATTRIBUTE_BUFFER_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER * values, unsigned indent)
   1226 {
   1227    fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
   1228    fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
   1229    fprintf(fp, "%*sStride: %u\n", indent, "", values->stride);
   1230    fprintf(fp, "%*sSize: %u\n", indent, "", values->size);
   1231    fprintf(fp, "%*sDivisor: %u\n", indent, "", values->divisor);
   1232    fprintf(fp, "%*sDivisor R: %u\n", indent, "", values->divisor_r);
   1233    fprintf(fp, "%*sDivisor P: %u\n", indent, "", values->divisor_p);
   1234    fprintf(fp, "%*sDivisor E: %u\n", indent, "", values->divisor_e);
   1235 }
   1236 
   1237 struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT {
   1238    enum mali_attribute_type             type;
   1239    uint32_t                             divisor_numerator;
   1240    uint32_t                             divisor;
   1241 };
   1242 
   1243 #define MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_header\
   1244    .type = MALI_ATTRIBUTE_TYPE_CONTINUATION
   1245 
   1246 static inline void
   1247 MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_pack(uint32_t * restrict cl,
   1248                                              const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * restrict values)
   1249 {
   1250    cl[ 0] = __gen_uint(values->type, 0, 5);
   1251    cl[ 1] = __gen_uint(values->divisor_numerator, 0, 31);
   1252    cl[ 2] = 0;
   1253    cl[ 3] = __gen_uint(values->divisor, 0, 31);
   1254 }
   1255 
   1256 
   1257 #define MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_LENGTH 16
   1258 struct mali_attribute_buffer_continuation_npot_packed { uint32_t opaque[4]; };
   1259 static inline void
   1260 MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_unpack(const uint8_t * restrict cl,
   1261                                                struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * restrict values)
   1262 {
   1263    if (((const uint32_t *) cl)[0] & 0xffffffc0) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation NPOT unpacked at word 0\n");
   1264    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation NPOT unpacked at word 2\n");
   1265    values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
   1266    values->divisor_numerator = __gen_unpack_uint(cl, 32, 63);
   1267    values->divisor = __gen_unpack_uint(cl, 96, 127);
   1268 }
   1269 
   1270 static inline void
   1271 MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * values, unsigned indent)
   1272 {
   1273    fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
   1274    fprintf(fp, "%*sDivisor Numerator: %u\n", indent, "", values->divisor_numerator);
   1275    fprintf(fp, "%*sDivisor: %u\n", indent, "", values->divisor);
   1276 }
   1277 
   1278 struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D {
   1279    enum mali_attribute_type             type;
   1280    uint32_t                             s_dimension;
   1281    uint32_t                             t_dimension;
   1282    uint32_t                             r_dimension;
   1283    uint32_t                             row_stride;
   1284    uint32_t                             slice_stride;
   1285 };
   1286 
   1287 #define MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_header\
   1288    .type = MALI_ATTRIBUTE_TYPE_CONTINUATION
   1289 
   1290 static inline void
   1291 MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_pack(uint32_t * restrict cl,
   1292                                            const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * restrict values)
   1293 {
   1294    assert(values->s_dimension >= 1);
   1295    assert(values->t_dimension >= 1);
   1296    assert(values->r_dimension >= 1);
   1297    cl[ 0] = __gen_uint(values->type, 0, 5) |
   1298             __gen_uint(values->s_dimension - 1, 16, 31);
   1299    cl[ 1] = __gen_uint(values->t_dimension - 1, 0, 15) |
   1300             __gen_uint(values->r_dimension - 1, 16, 31);
   1301    cl[ 2] = __gen_uint(values->row_stride, 0, 31);
   1302    cl[ 3] = __gen_uint(values->slice_stride, 0, 31);
   1303 }
   1304 
   1305 
   1306 #define MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_LENGTH 16
   1307 struct mali_attribute_buffer_continuation_3d_packed { uint32_t opaque[4]; };
   1308 static inline void
   1309 MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_unpack(const uint8_t * restrict cl,
   1310                                              struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * restrict values)
   1311 {
   1312    if (((const uint32_t *) cl)[0] & 0xffc0) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation 3D unpacked at word 0\n");
   1313    values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
   1314    values->s_dimension = __gen_unpack_uint(cl, 16, 31) + 1;
   1315    values->t_dimension = __gen_unpack_uint(cl, 32, 47) + 1;
   1316    values->r_dimension = __gen_unpack_uint(cl, 48, 63) + 1;
   1317    values->row_stride = __gen_unpack_uint(cl, 64, 95);
   1318    values->slice_stride = __gen_unpack_uint(cl, 96, 127);
   1319 }
   1320 
   1321 static inline void
   1322 MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * values, unsigned indent)
   1323 {
   1324    fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
   1325    fprintf(fp, "%*sS dimension: %u\n", indent, "", values->s_dimension);
   1326    fprintf(fp, "%*sT dimension: %u\n", indent, "", values->t_dimension);
   1327    fprintf(fp, "%*sR dimension: %u\n", indent, "", values->r_dimension);
   1328    fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
   1329    fprintf(fp, "%*sSlice Stride: %u\n", indent, "", values->slice_stride);
   1330 }
   1331 
   1332 enum mali_blend_operand_a {
   1333         MALI_BLEND_OPERAND_A_ZERO            =      1,
   1334         MALI_BLEND_OPERAND_A_SRC             =      2,
   1335         MALI_BLEND_OPERAND_A_DEST            =      3,
   1336 };
   1337 
   1338 static inline const char *
   1339 mali_blend_operand_a_as_str(enum mali_blend_operand_a imm)
   1340 {
   1341     switch (imm) {
   1342     case MALI_BLEND_OPERAND_A_ZERO: return "Zero";
   1343     case MALI_BLEND_OPERAND_A_SRC: return "Src";
   1344     case MALI_BLEND_OPERAND_A_DEST: return "Dest";
   1345     default: return "XXX: INVALID";
   1346     }
   1347 }
   1348 
   1349 enum mali_blend_operand_b {
   1350         MALI_BLEND_OPERAND_B_SRC_MINUS_DEST  =      0,
   1351         MALI_BLEND_OPERAND_B_SRC_PLUS_DEST   =      1,
   1352         MALI_BLEND_OPERAND_B_SRC             =      2,
   1353         MALI_BLEND_OPERAND_B_DEST            =      3,
   1354 };
   1355 
   1356 static inline const char *
   1357 mali_blend_operand_b_as_str(enum mali_blend_operand_b imm)
   1358 {
   1359     switch (imm) {
   1360     case MALI_BLEND_OPERAND_B_SRC_MINUS_DEST: return "Src Minus Dest";
   1361     case MALI_BLEND_OPERAND_B_SRC_PLUS_DEST: return "Src Plus Dest";
   1362     case MALI_BLEND_OPERAND_B_SRC: return "Src";
   1363     case MALI_BLEND_OPERAND_B_DEST: return "Dest";
   1364     default: return "XXX: INVALID";
   1365     }
   1366 }
   1367 
   1368 enum mali_blend_operand_c {
   1369         MALI_BLEND_OPERAND_C_ZERO            =      1,
   1370         MALI_BLEND_OPERAND_C_SRC             =      2,
   1371         MALI_BLEND_OPERAND_C_DEST            =      3,
   1372         MALI_BLEND_OPERAND_C_SRC_X_2         =      4,
   1373         MALI_BLEND_OPERAND_C_SRC_ALPHA       =      5,
   1374         MALI_BLEND_OPERAND_C_DEST_ALPHA      =      6,
   1375         MALI_BLEND_OPERAND_C_CONSTANT        =      7,
   1376 };
   1377 
   1378 static inline const char *
   1379 mali_blend_operand_c_as_str(enum mali_blend_operand_c imm)
   1380 {
   1381     switch (imm) {
   1382     case MALI_BLEND_OPERAND_C_ZERO: return "Zero";
   1383     case MALI_BLEND_OPERAND_C_SRC: return "Src";
   1384     case MALI_BLEND_OPERAND_C_DEST: return "Dest";
   1385     case MALI_BLEND_OPERAND_C_SRC_X_2: return "Src x 2";
   1386     case MALI_BLEND_OPERAND_C_SRC_ALPHA: return "Src Alpha";
   1387     case MALI_BLEND_OPERAND_C_DEST_ALPHA: return "Dest Alpha";
   1388     case MALI_BLEND_OPERAND_C_CONSTANT: return "Constant";
   1389     default: return "XXX: INVALID";
   1390     }
   1391 }
   1392 
   1393 struct MALI_BLEND_FUNCTION {
   1394    enum mali_blend_operand_a            a;
   1395    bool                                 negate_a;
   1396    enum mali_blend_operand_b            b;
   1397    bool                                 negate_b;
   1398    enum mali_blend_operand_c            c;
   1399    bool                                 invert_c;
   1400 };
   1401 
   1402 #define MALI_BLEND_FUNCTION_header              \
   1403    0
   1404 
   1405 static inline void
   1406 MALI_BLEND_FUNCTION_print(FILE *fp, const struct MALI_BLEND_FUNCTION * values, unsigned indent)
   1407 {
   1408    fprintf(fp, "%*sA: %s\n", indent, "", mali_blend_operand_a_as_str(values->a));
   1409    fprintf(fp, "%*sNegate A: %s\n", indent, "", values->negate_a ? "true" : "false");
   1410    fprintf(fp, "%*sB: %s\n", indent, "", mali_blend_operand_b_as_str(values->b));
   1411    fprintf(fp, "%*sNegate B: %s\n", indent, "", values->negate_b ? "true" : "false");
   1412    fprintf(fp, "%*sC: %s\n", indent, "", mali_blend_operand_c_as_str(values->c));
   1413    fprintf(fp, "%*sInvert C: %s\n", indent, "", values->invert_c ? "true" : "false");
   1414 }
   1415 
   1416 struct MALI_BLEND_EQUATION {
   1417    struct MALI_BLEND_FUNCTION           rgb;
   1418    struct MALI_BLEND_FUNCTION           alpha;
   1419    uint32_t                             color_mask;
   1420 };
   1421 
   1422 #define MALI_BLEND_EQUATION_header              \
   1423    .rgb = { MALI_BLEND_FUNCTION_header },  \
   1424    .alpha = { MALI_BLEND_FUNCTION_header }
   1425 
   1426 static inline void
   1427 MALI_BLEND_EQUATION_pack(uint32_t * restrict cl,
   1428                          const struct MALI_BLEND_EQUATION * restrict values)
   1429 {
   1430    cl[ 0] = __gen_uint(values->rgb.a, 0, 1) |
   1431             __gen_uint(values->rgb.negate_a, 3, 3) |
   1432             __gen_uint(values->rgb.b, 4, 5) |
   1433             __gen_uint(values->rgb.negate_b, 7, 7) |
   1434             __gen_uint(values->rgb.c, 8, 10) |
   1435             __gen_uint(values->rgb.invert_c, 11, 11) |
   1436             __gen_uint(values->alpha.a, 12, 13) |
   1437             __gen_uint(values->alpha.negate_a, 15, 15) |
   1438             __gen_uint(values->alpha.b, 16, 17) |
   1439             __gen_uint(values->alpha.negate_b, 19, 19) |
   1440             __gen_uint(values->alpha.c, 20, 22) |
   1441             __gen_uint(values->alpha.invert_c, 23, 23) |
   1442             __gen_uint(values->color_mask, 28, 31);
   1443 }
   1444 
   1445 
   1446 #define MALI_BLEND_EQUATION_LENGTH 4
   1447 struct mali_blend_equation_packed { uint32_t opaque[1]; };
   1448 static inline void
   1449 MALI_BLEND_EQUATION_unpack(const uint8_t * restrict cl,
   1450                            struct MALI_BLEND_EQUATION * restrict values)
   1451 {
   1452    if (((const uint32_t *) cl)[0] & 0xf044044) fprintf(stderr, "XXX: Invalid field of Blend Equation unpacked at word 0\n");
   1453    values->rgb.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 0, 1);
   1454    values->rgb.negate_a = __gen_unpack_uint(cl, 3, 3);
   1455    values->rgb.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 4, 5);
   1456    values->rgb.negate_b = __gen_unpack_uint(cl, 7, 7);
   1457    values->rgb.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 8, 10);
   1458    values->rgb.invert_c = __gen_unpack_uint(cl, 11, 11);
   1459    values->alpha.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 12, 13);
   1460    values->alpha.negate_a = __gen_unpack_uint(cl, 15, 15);
   1461    values->alpha.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 16, 17);
   1462    values->alpha.negate_b = __gen_unpack_uint(cl, 19, 19);
   1463    values->alpha.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 20, 22);
   1464    values->alpha.invert_c = __gen_unpack_uint(cl, 23, 23);
   1465    values->color_mask = __gen_unpack_uint(cl, 28, 31);
   1466 }
   1467 
   1468 static inline void
   1469 MALI_BLEND_EQUATION_print(FILE *fp, const struct MALI_BLEND_EQUATION * values, unsigned indent)
   1470 {
   1471    fprintf(fp, "%*sRGB:\n", indent, "");
   1472    MALI_BLEND_FUNCTION_print(fp, &values->rgb, indent + 2);
   1473    fprintf(fp, "%*sAlpha:\n", indent, "");
   1474    MALI_BLEND_FUNCTION_print(fp, &values->alpha, indent + 2);
   1475    fprintf(fp, "%*sColor Mask: %u\n", indent, "", values->color_mask);
   1476 }
   1477 
   1478 enum mali_register_file_format {
   1479         MALI_REGISTER_FILE_FORMAT_F16        =      0,
   1480         MALI_REGISTER_FILE_FORMAT_F32        =      1,
   1481         MALI_REGISTER_FILE_FORMAT_I32        =      2,
   1482         MALI_REGISTER_FILE_FORMAT_U32        =      3,
   1483         MALI_REGISTER_FILE_FORMAT_I16        =      4,
   1484         MALI_REGISTER_FILE_FORMAT_U16        =      5,
   1485 };
   1486 
   1487 static inline const char *
   1488 mali_register_file_format_as_str(enum mali_register_file_format imm)
   1489 {
   1490     switch (imm) {
   1491     case MALI_REGISTER_FILE_FORMAT_F16: return "F16";
   1492     case MALI_REGISTER_FILE_FORMAT_F32: return "F32";
   1493     case MALI_REGISTER_FILE_FORMAT_I32: return "I32";
   1494     case MALI_REGISTER_FILE_FORMAT_U32: return "U32";
   1495     case MALI_REGISTER_FILE_FORMAT_I16: return "I16";
   1496     case MALI_REGISTER_FILE_FORMAT_U16: return "U16";
   1497     default: return "XXX: INVALID";
   1498     }
   1499 }
   1500 
   1501 enum mali_message_type {
   1502         MALI_MESSAGE_TYPE_DISABLED           =      0,
   1503         MALI_MESSAGE_TYPE_LD_VAR             =      1,
   1504         MALI_MESSAGE_TYPE_VAR_TEX            =      2,
   1505 };
   1506 
   1507 static inline const char *
   1508 mali_message_type_as_str(enum mali_message_type imm)
   1509 {
   1510     switch (imm) {
   1511     case MALI_MESSAGE_TYPE_DISABLED: return "Disabled";
   1512     case MALI_MESSAGE_TYPE_LD_VAR: return "LD_VAR";
   1513     case MALI_MESSAGE_TYPE_VAR_TEX: return "VAR_TEX";
   1514     default: return "XXX: INVALID";
   1515     }
   1516 }
   1517 
   1518 enum mali_message_preload_register_format {
   1519         MALI_MESSAGE_PRELOAD_REGISTER_FORMAT_F32 =      0,
   1520         MALI_MESSAGE_PRELOAD_REGISTER_FORMAT_F16 =      1,
   1521 };
   1522 
   1523 static inline const char *
   1524 mali_message_preload_register_format_as_str(enum mali_message_preload_register_format imm)
   1525 {
   1526     switch (imm) {
   1527     case MALI_MESSAGE_PRELOAD_REGISTER_FORMAT_F32: return "F32";
   1528     case MALI_MESSAGE_PRELOAD_REGISTER_FORMAT_F16: return "F16";
   1529     default: return "XXX: INVALID";
   1530     }
   1531 }
   1532 
   1533 enum mali_blend_mode {
   1534         MALI_BLEND_MODE_SHADER               =      0,
   1535         MALI_BLEND_MODE_OPAQUE               =      1,
   1536         MALI_BLEND_MODE_FIXED_FUNCTION       =      2,
   1537         MALI_BLEND_MODE_OFF                  =      3,
   1538 };
   1539 
   1540 static inline const char *
   1541 mali_blend_mode_as_str(enum mali_blend_mode imm)
   1542 {
   1543     switch (imm) {
   1544     case MALI_BLEND_MODE_SHADER: return "Shader";
   1545     case MALI_BLEND_MODE_OPAQUE: return "Opaque";
   1546     case MALI_BLEND_MODE_FIXED_FUNCTION: return "Fixed-Function";
   1547     case MALI_BLEND_MODE_OFF: return "Off";
   1548     default: return "XXX: INVALID";
   1549     }
   1550 }
   1551 
   1552 struct MALI_BLEND_SHADER {
   1553    uint32_t                             return_value;
   1554    uint32_t                             pc;
   1555 };
   1556 
   1557 #define MALI_BLEND_SHADER_header                \
   1558    0
   1559 
   1560 static inline void
   1561 MALI_BLEND_SHADER_pack(uint32_t * restrict cl,
   1562                        const struct MALI_BLEND_SHADER * restrict values)
   1563 {
   1564    assert((values->return_value & 0x7) == 0);
   1565    assert((values->pc & 0xf) == 0);
   1566    cl[ 0] = __gen_uint(values->return_value >> 3, 3, 31);
   1567    cl[ 1] = __gen_uint(values->pc >> 4, 4, 31);
   1568 }
   1569 
   1570 
   1571 #define MALI_BLEND_SHADER_LENGTH 8
   1572 struct mali_blend_shader_packed { uint32_t opaque[2]; };
   1573 static inline void
   1574 MALI_BLEND_SHADER_unpack(const uint8_t * restrict cl,
   1575                          struct MALI_BLEND_SHADER * restrict values)
   1576 {
   1577    if (((const uint32_t *) cl)[0] & 0x7) fprintf(stderr, "XXX: Invalid field of Blend Shader unpacked at word 0\n");
   1578    if (((const uint32_t *) cl)[1] & 0xf) fprintf(stderr, "XXX: Invalid field of Blend Shader unpacked at word 1\n");
   1579    values->return_value = __gen_unpack_uint(cl, 3, 31) << 3;
   1580    values->pc = __gen_unpack_uint(cl, 36, 63) << 4;
   1581 }
   1582 
   1583 static inline void
   1584 MALI_BLEND_SHADER_print(FILE *fp, const struct MALI_BLEND_SHADER * values, unsigned indent)
   1585 {
   1586    fprintf(fp, "%*sReturn Value: %u\n", indent, "", values->return_value);
   1587    fprintf(fp, "%*sPC: %u\n", indent, "", values->pc);
   1588 }
   1589 
   1590 struct MALI_INTERNAL_CONVERSION {
   1591    uint32_t                             memory_format;
   1592    bool                                 raw;
   1593    enum mali_register_file_format       register_format;
   1594 };
   1595 
   1596 #define MALI_INTERNAL_CONVERSION_header         \
   1597    0
   1598 
   1599 static inline void
   1600 MALI_INTERNAL_CONVERSION_pack(uint32_t * restrict cl,
   1601                               const struct MALI_INTERNAL_CONVERSION * restrict values)
   1602 {
   1603    cl[ 0] = __gen_uint(values->memory_format, 0, 21) |
   1604             __gen_uint(values->raw, 22, 22) |
   1605             __gen_uint(values->register_format, 24, 26);
   1606 }
   1607 
   1608 
   1609 #define MALI_INTERNAL_CONVERSION_LENGTH 4
   1610 struct mali_internal_conversion_packed { uint32_t opaque[1]; };
   1611 static inline void
   1612 MALI_INTERNAL_CONVERSION_unpack(const uint8_t * restrict cl,
   1613                                 struct MALI_INTERNAL_CONVERSION * restrict values)
   1614 {
   1615    if (((const uint32_t *) cl)[0] & 0xf8800000) fprintf(stderr, "XXX: Invalid field of Internal Conversion unpacked at word 0\n");
   1616    values->memory_format = __gen_unpack_uint(cl, 0, 21);
   1617    values->raw = __gen_unpack_uint(cl, 22, 22);
   1618    values->register_format = (enum mali_register_file_format)__gen_unpack_uint(cl, 24, 26);
   1619 }
   1620 
   1621 static inline void
   1622 MALI_INTERNAL_CONVERSION_print(FILE *fp, const struct MALI_INTERNAL_CONVERSION * values, unsigned indent)
   1623 {
   1624    mali_pixel_format_print(fp, values->memory_format);
   1625    fprintf(fp, "%*sRaw: %s\n", indent, "", values->raw ? "true" : "false");
   1626    fprintf(fp, "%*sRegister Format: %s\n", indent, "", mali_register_file_format_as_str(values->register_format));
   1627 }
   1628 
   1629 struct MALI_BLEND_FIXED_FUNCTION {
   1630    uint32_t                             num_comps;
   1631    bool                                 alpha_zero_nop;
   1632    bool                                 alpha_one_store;
   1633    uint32_t                             rt;
   1634 #define MALI_BIFROST_BLEND_MAX_RT                8
   1635    struct MALI_INTERNAL_CONVERSION      conversion;
   1636 };
   1637 
   1638 #define MALI_BLEND_FIXED_FUNCTION_header        \
   1639    .num_comps = 1,  \
   1640    .conversion = { MALI_INTERNAL_CONVERSION_header }
   1641 
   1642 static inline void
   1643 MALI_BLEND_FIXED_FUNCTION_pack(uint32_t * restrict cl,
   1644                                const struct MALI_BLEND_FIXED_FUNCTION * restrict values)
   1645 {
   1646    assert(values->num_comps >= 1);
   1647    cl[ 0] = __gen_uint(values->num_comps - 1, 3, 4) |
   1648             __gen_uint(values->alpha_zero_nop, 5, 5) |
   1649             __gen_uint(values->alpha_one_store, 6, 6) |
   1650             __gen_uint(values->rt, 16, 19);
   1651    cl[ 1] = __gen_uint(values->conversion.memory_format, 0, 21) |
   1652             __gen_uint(values->conversion.raw, 22, 22) |
   1653             __gen_uint(values->conversion.register_format, 24, 26);
   1654 }
   1655 
   1656 
   1657 #define MALI_BLEND_FIXED_FUNCTION_LENGTH 8
   1658 struct mali_blend_fixed_function_packed { uint32_t opaque[2]; };
   1659 static inline void
   1660 MALI_BLEND_FIXED_FUNCTION_unpack(const uint8_t * restrict cl,
   1661                                  struct MALI_BLEND_FIXED_FUNCTION * restrict values)
   1662 {
   1663    if (((const uint32_t *) cl)[0] & 0xfff0ff87) fprintf(stderr, "XXX: Invalid field of Blend Fixed-Function unpacked at word 0\n");
   1664    if (((const uint32_t *) cl)[1] & 0xf8800000) fprintf(stderr, "XXX: Invalid field of Blend Fixed-Function unpacked at word 1\n");
   1665    values->num_comps = __gen_unpack_uint(cl, 3, 4) + 1;
   1666    values->alpha_zero_nop = __gen_unpack_uint(cl, 5, 5);
   1667    values->alpha_one_store = __gen_unpack_uint(cl, 6, 6);
   1668    values->rt = __gen_unpack_uint(cl, 16, 19);
   1669    values->conversion.memory_format = __gen_unpack_uint(cl, 32, 53);
   1670    values->conversion.raw = __gen_unpack_uint(cl, 54, 54);
   1671    values->conversion.register_format = (enum mali_register_file_format)__gen_unpack_uint(cl, 56, 58);
   1672 }
   1673 
   1674 static inline void
   1675 MALI_BLEND_FIXED_FUNCTION_print(FILE *fp, const struct MALI_BLEND_FIXED_FUNCTION * values, unsigned indent)
   1676 {
   1677    fprintf(fp, "%*sNum Comps: %u\n", indent, "", values->num_comps);
   1678    fprintf(fp, "%*sAlpha Zero NOP: %s\n", indent, "", values->alpha_zero_nop ? "true" : "false");
   1679    fprintf(fp, "%*sAlpha One Store: %s\n", indent, "", values->alpha_one_store ? "true" : "false");
   1680    fprintf(fp, "%*sRT: %u\n", indent, "", values->rt);
   1681    fprintf(fp, "%*sConversion:\n", indent, "");
   1682    MALI_INTERNAL_CONVERSION_print(fp, &values->conversion, indent + 2);
   1683 }
   1684 
   1685 struct MALI_INTERNAL_BLEND {
   1686    enum mali_blend_mode                 mode;
   1687    struct MALI_BLEND_SHADER             shader;
   1688    struct MALI_BLEND_FIXED_FUNCTION     fixed_function;
   1689 };
   1690 
   1691 #define MALI_INTERNAL_BLEND_header              \
   1692    .shader = { MALI_BLEND_SHADER_header },  \
   1693    .fixed_function = { MALI_BLEND_FIXED_FUNCTION_header }
   1694 
   1695 static inline void
   1696 MALI_INTERNAL_BLEND_pack(uint32_t * restrict cl,
   1697                          const struct MALI_INTERNAL_BLEND * restrict values)
   1698 {
   1699    cl[ 0] = __gen_uint(values->mode, 0, 1) |
   1700             __gen_uint(values->shader.return_value >> 3, 3, 31) |
   1701             __gen_uint(values->fixed_function.num_comps - 1, 3, 4) |
   1702             __gen_uint(values->fixed_function.alpha_zero_nop, 5, 5) |
   1703             __gen_uint(values->fixed_function.alpha_one_store, 6, 6) |
   1704             __gen_uint(values->fixed_function.rt, 16, 19);
   1705    cl[ 1] = __gen_uint(values->shader.pc >> 4, 4, 31) |
   1706             __gen_uint(values->fixed_function.conversion.memory_format, 0, 21) |
   1707             __gen_uint(values->fixed_function.conversion.raw, 22, 22) |
   1708             __gen_uint(values->fixed_function.conversion.register_format, 24, 26);
   1709 }
   1710 
   1711 
   1712 #define MALI_INTERNAL_BLEND_LENGTH 8
   1713 struct mali_internal_blend_packed { uint32_t opaque[2]; };
   1714 static inline void
   1715 MALI_INTERNAL_BLEND_unpack(const uint8_t * restrict cl,
   1716                            struct MALI_INTERNAL_BLEND * restrict values)
   1717 {
   1718    if (((const uint32_t *) cl)[0] & 0x4) fprintf(stderr, "XXX: Invalid field of Internal Blend unpacked at word 0\n");
   1719    values->mode = (enum mali_blend_mode)__gen_unpack_uint(cl, 0, 1);
   1720    values->shader.return_value = __gen_unpack_uint(cl, 3, 31) << 3;
   1721    values->shader.pc = __gen_unpack_uint(cl, 36, 63) << 4;
   1722    values->fixed_function.num_comps = __gen_unpack_uint(cl, 3, 4) + 1;
   1723    values->fixed_function.alpha_zero_nop = __gen_unpack_uint(cl, 5, 5);
   1724    values->fixed_function.alpha_one_store = __gen_unpack_uint(cl, 6, 6);
   1725    values->fixed_function.rt = __gen_unpack_uint(cl, 16, 19);
   1726    values->fixed_function.conversion.memory_format = __gen_unpack_uint(cl, 32, 53);
   1727    values->fixed_function.conversion.raw = __gen_unpack_uint(cl, 54, 54);
   1728    values->fixed_function.conversion.register_format = (enum mali_register_file_format)__gen_unpack_uint(cl, 56, 58);
   1729 }
   1730 
   1731 static inline void
   1732 MALI_INTERNAL_BLEND_print(FILE *fp, const struct MALI_INTERNAL_BLEND * values, unsigned indent)
   1733 {
   1734    fprintf(fp, "%*sMode: %s\n", indent, "", mali_blend_mode_as_str(values->mode));
   1735    fprintf(fp, "%*sShader:\n", indent, "");
   1736    MALI_BLEND_SHADER_print(fp, &values->shader, indent + 2);
   1737    fprintf(fp, "%*sFixed-Function:\n", indent, "");
   1738    MALI_BLEND_FIXED_FUNCTION_print(fp, &values->fixed_function, indent + 2);
   1739 }
   1740 
   1741 struct MALI_BLEND {
   1742    bool                                 load_destination;
   1743    bool                                 alpha_to_one;
   1744    bool                                 enable;
   1745    bool                                 srgb;
   1746    bool                                 round_to_fb_precision;
   1747    uint32_t                             constant;
   1748    struct MALI_BLEND_EQUATION           equation;
   1749    struct MALI_INTERNAL_BLEND           internal;
   1750 };
   1751 
   1752 #define MALI_BLEND_header                       \
   1753    .load_destination = false,  \
   1754    .enable = true,  \
   1755    .srgb = false,  \
   1756    .round_to_fb_precision = false,  \
   1757    .equation = { MALI_BLEND_EQUATION_header },  \
   1758    .internal = { MALI_INTERNAL_BLEND_header }
   1759 
   1760 static inline void
   1761 MALI_BLEND_pack(uint32_t * restrict cl,
   1762                 const struct MALI_BLEND * restrict values)
   1763 {
   1764    cl[ 0] = __gen_uint(values->load_destination, 0, 0) |
   1765             __gen_uint(values->alpha_to_one, 8, 8) |
   1766             __gen_uint(values->enable, 9, 9) |
   1767             __gen_uint(values->srgb, 10, 10) |
   1768             __gen_uint(values->round_to_fb_precision, 11, 11) |
   1769             __gen_uint(values->constant, 16, 31);
   1770    cl[ 1] = __gen_uint(values->equation.rgb.a, 0, 1) |
   1771             __gen_uint(values->equation.rgb.negate_a, 3, 3) |
   1772             __gen_uint(values->equation.rgb.b, 4, 5) |
   1773             __gen_uint(values->equation.rgb.negate_b, 7, 7) |
   1774             __gen_uint(values->equation.rgb.c, 8, 10) |
   1775             __gen_uint(values->equation.rgb.invert_c, 11, 11) |
   1776             __gen_uint(values->equation.alpha.a, 12, 13) |
   1777             __gen_uint(values->equation.alpha.negate_a, 15, 15) |
   1778             __gen_uint(values->equation.alpha.b, 16, 17) |
   1779             __gen_uint(values->equation.alpha.negate_b, 19, 19) |
   1780             __gen_uint(values->equation.alpha.c, 20, 22) |
   1781             __gen_uint(values->equation.alpha.invert_c, 23, 23) |
   1782             __gen_uint(values->equation.color_mask, 28, 31);
   1783    cl[ 2] = __gen_uint(values->internal.mode, 0, 1) |
   1784             __gen_uint(values->internal.shader.return_value >> 3, 3, 31) |
   1785             __gen_uint(values->internal.fixed_function.num_comps - 1, 3, 4) |
   1786             __gen_uint(values->internal.fixed_function.alpha_zero_nop, 5, 5) |
   1787             __gen_uint(values->internal.fixed_function.alpha_one_store, 6, 6) |
   1788             __gen_uint(values->internal.fixed_function.rt, 16, 19);
   1789    cl[ 3] = __gen_uint(values->internal.shader.pc >> 4, 4, 31) |
   1790             __gen_uint(values->internal.fixed_function.conversion.memory_format, 0, 21) |
   1791             __gen_uint(values->internal.fixed_function.conversion.raw, 22, 22) |
   1792             __gen_uint(values->internal.fixed_function.conversion.register_format, 24, 26);
   1793 }
   1794 
   1795 
   1796 #define MALI_BLEND_LENGTH 16
   1797 #define MALI_BLEND_ALIGN 16
   1798 struct mali_blend_packed { uint32_t opaque[4]; };
   1799 static inline void
   1800 MALI_BLEND_unpack(const uint8_t * restrict cl,
   1801                   struct MALI_BLEND * restrict values)
   1802 {
   1803    if (((const uint32_t *) cl)[0] & 0xf0fe) fprintf(stderr, "XXX: Invalid field of Blend unpacked at word 0\n");
   1804    if (((const uint32_t *) cl)[1] & 0xf044044) fprintf(stderr, "XXX: Invalid field of Blend unpacked at word 1\n");
   1805    if (((const uint32_t *) cl)[2] & 0x4) fprintf(stderr, "XXX: Invalid field of Blend unpacked at word 2\n");
   1806    values->load_destination = __gen_unpack_uint(cl, 0, 0);
   1807    values->alpha_to_one = __gen_unpack_uint(cl, 8, 8);
   1808    values->enable = __gen_unpack_uint(cl, 9, 9);
   1809    values->srgb = __gen_unpack_uint(cl, 10, 10);
   1810    values->round_to_fb_precision = __gen_unpack_uint(cl, 11, 11);
   1811    values->constant = __gen_unpack_uint(cl, 16, 31);
   1812    values->equation.rgb.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 32, 33);
   1813    values->equation.rgb.negate_a = __gen_unpack_uint(cl, 35, 35);
   1814    values->equation.rgb.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 36, 37);
   1815    values->equation.rgb.negate_b = __gen_unpack_uint(cl, 39, 39);
   1816    values->equation.rgb.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 40, 42);
   1817    values->equation.rgb.invert_c = __gen_unpack_uint(cl, 43, 43);
   1818    values->equation.alpha.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 44, 45);
   1819    values->equation.alpha.negate_a = __gen_unpack_uint(cl, 47, 47);
   1820    values->equation.alpha.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 48, 49);
   1821    values->equation.alpha.negate_b = __gen_unpack_uint(cl, 51, 51);
   1822    values->equation.alpha.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 52, 54);
   1823    values->equation.alpha.invert_c = __gen_unpack_uint(cl, 55, 55);
   1824    values->equation.color_mask = __gen_unpack_uint(cl, 60, 63);
   1825    values->internal.mode = (enum mali_blend_mode)__gen_unpack_uint(cl, 64, 65);
   1826    values->internal.shader.return_value = __gen_unpack_uint(cl, 67, 95) << 3;
   1827    values->internal.shader.pc = __gen_unpack_uint(cl, 100, 127) << 4;
   1828    values->internal.fixed_function.num_comps = __gen_unpack_uint(cl, 67, 68) + 1;
   1829    values->internal.fixed_function.alpha_zero_nop = __gen_unpack_uint(cl, 69, 69);
   1830    values->internal.fixed_function.alpha_one_store = __gen_unpack_uint(cl, 70, 70);
   1831    values->internal.fixed_function.rt = __gen_unpack_uint(cl, 80, 83);
   1832    values->internal.fixed_function.conversion.memory_format = __gen_unpack_uint(cl, 96, 117);
   1833    values->internal.fixed_function.conversion.raw = __gen_unpack_uint(cl, 118, 118);
   1834    values->internal.fixed_function.conversion.register_format = (enum mali_register_file_format)__gen_unpack_uint(cl, 120, 122);
   1835 }
   1836 
   1837 static inline void
   1838 MALI_BLEND_print(FILE *fp, const struct MALI_BLEND * values, unsigned indent)
   1839 {
   1840    fprintf(fp, "%*sLoad Destination: %s\n", indent, "", values->load_destination ? "true" : "false");
   1841    fprintf(fp, "%*sAlpha To One: %s\n", indent, "", values->alpha_to_one ? "true" : "false");
   1842    fprintf(fp, "%*sEnable: %s\n", indent, "", values->enable ? "true" : "false");
   1843    fprintf(fp, "%*ssRGB: %s\n", indent, "", values->srgb ? "true" : "false");
   1844    fprintf(fp, "%*sRound to FB precision: %s\n", indent, "", values->round_to_fb_precision ? "true" : "false");
   1845    fprintf(fp, "%*sConstant: %u\n", indent, "", values->constant);
   1846    fprintf(fp, "%*sEquation:\n", indent, "");
   1847    MALI_BLEND_EQUATION_print(fp, &values->equation, indent + 2);
   1848    fprintf(fp, "%*sInternal:\n", indent, "");
   1849    MALI_INTERNAL_BLEND_print(fp, &values->internal, indent + 2);
   1850 }
   1851 
   1852 struct MALI_INVOCATION {
   1853    uint32_t                             invocations;
   1854    uint32_t                             size_y_shift;
   1855    uint32_t                             size_z_shift;
   1856    uint32_t                             workgroups_x_shift;
   1857    uint32_t                             workgroups_y_shift;
   1858    uint32_t                             workgroups_z_shift;
   1859    uint32_t                             thread_group_split;
   1860 #define MALI_SPLIT_MIN_EFFICIENT                 2
   1861 };
   1862 
   1863 #define MALI_INVOCATION_header                  \
   1864    0
   1865 
   1866 static inline void
   1867 MALI_INVOCATION_pack(uint32_t * restrict cl,
   1868                      const struct MALI_INVOCATION * restrict values)
   1869 {
   1870    cl[ 0] = __gen_uint(values->invocations, 0, 31);
   1871    cl[ 1] = __gen_uint(values->size_y_shift, 0, 4) |
   1872             __gen_uint(values->size_z_shift, 5, 9) |
   1873             __gen_uint(values->workgroups_x_shift, 10, 15) |
   1874             __gen_uint(values->workgroups_y_shift, 16, 21) |
   1875             __gen_uint(values->workgroups_z_shift, 22, 27) |
   1876             __gen_uint(values->thread_group_split, 28, 31);
   1877 }
   1878 
   1879 
   1880 #define MALI_INVOCATION_LENGTH 8
   1881 struct mali_invocation_packed { uint32_t opaque[2]; };
   1882 static inline void
   1883 MALI_INVOCATION_unpack(const uint8_t * restrict cl,
   1884                        struct MALI_INVOCATION * restrict values)
   1885 {
   1886    values->invocations = __gen_unpack_uint(cl, 0, 31);
   1887    values->size_y_shift = __gen_unpack_uint(cl, 32, 36);
   1888    values->size_z_shift = __gen_unpack_uint(cl, 37, 41);
   1889    values->workgroups_x_shift = __gen_unpack_uint(cl, 42, 47);
   1890    values->workgroups_y_shift = __gen_unpack_uint(cl, 48, 53);
   1891    values->workgroups_z_shift = __gen_unpack_uint(cl, 54, 59);
   1892    values->thread_group_split = __gen_unpack_uint(cl, 60, 63);
   1893 }
   1894 
   1895 static inline void
   1896 MALI_INVOCATION_print(FILE *fp, const struct MALI_INVOCATION * values, unsigned indent)
   1897 {
   1898    fprintf(fp, "%*sInvocations: %u\n", indent, "", values->invocations);
   1899    fprintf(fp, "%*sSize Y shift: %u\n", indent, "", values->size_y_shift);
   1900    fprintf(fp, "%*sSize Z shift: %u\n", indent, "", values->size_z_shift);
   1901    fprintf(fp, "%*sWorkgroups X shift: %u\n", indent, "", values->workgroups_x_shift);
   1902    fprintf(fp, "%*sWorkgroups Y shift: %u\n", indent, "", values->workgroups_y_shift);
   1903    fprintf(fp, "%*sWorkgroups Z shift: %u\n", indent, "", values->workgroups_z_shift);
   1904    fprintf(fp, "%*sThread group split: %u\n", indent, "", values->thread_group_split);
   1905 }
   1906 
   1907 enum mali_point_size_array_format {
   1908         MALI_POINT_SIZE_ARRAY_FORMAT_NONE    =      0,
   1909         MALI_POINT_SIZE_ARRAY_FORMAT_FP16    =      2,
   1910         MALI_POINT_SIZE_ARRAY_FORMAT_FP32    =      3,
   1911 };
   1912 
   1913 static inline const char *
   1914 mali_point_size_array_format_as_str(enum mali_point_size_array_format imm)
   1915 {
   1916     switch (imm) {
   1917     case MALI_POINT_SIZE_ARRAY_FORMAT_NONE: return "None";
   1918     case MALI_POINT_SIZE_ARRAY_FORMAT_FP16: return "FP16";
   1919     case MALI_POINT_SIZE_ARRAY_FORMAT_FP32: return "FP32";
   1920     default: return "XXX: INVALID";
   1921     }
   1922 }
   1923 
   1924 enum mali_primitive_restart {
   1925         MALI_PRIMITIVE_RESTART_NONE          =      0,
   1926         MALI_PRIMITIVE_RESTART_IMPLICIT      =      2,
   1927         MALI_PRIMITIVE_RESTART_EXPLICIT      =      3,
   1928 };
   1929 
   1930 static inline const char *
   1931 mali_primitive_restart_as_str(enum mali_primitive_restart imm)
   1932 {
   1933     switch (imm) {
   1934     case MALI_PRIMITIVE_RESTART_NONE: return "None";
   1935     case MALI_PRIMITIVE_RESTART_IMPLICIT: return "Implicit";
   1936     case MALI_PRIMITIVE_RESTART_EXPLICIT: return "Explicit";
   1937     default: return "XXX: INVALID";
   1938     }
   1939 }
   1940 
   1941 struct MALI_PRIMITIVE {
   1942    enum mali_draw_mode                  draw_mode;
   1943    enum mali_index_type                 index_type;
   1944    enum mali_point_size_array_format    point_size_array_format;
   1945    bool                                 primitive_index_enable;
   1946    bool                                 primitive_index_writeback;
   1947    bool                                 first_provoking_vertex;
   1948    bool                                 low_depth_cull;
   1949    bool                                 high_depth_cull;
   1950    bool                                 secondary_shader;
   1951    enum mali_primitive_restart          primitive_restart;
   1952    uint32_t                             job_task_split;
   1953    uint32_t                             base_vertex_offset;
   1954    uint32_t                             primitive_restart_index;
   1955    uint32_t                             index_count;
   1956    uint64_t                             indices;
   1957 };
   1958 
   1959 #define MALI_PRIMITIVE_header                   \
   1960    .draw_mode = MALI_DRAW_MODE_NONE,  \
   1961    .index_type = MALI_INDEX_TYPE_NONE,  \
   1962    .first_provoking_vertex = true,  \
   1963    .low_depth_cull = true,  \
   1964    .high_depth_cull = true
   1965 
   1966 static inline void
   1967 MALI_PRIMITIVE_pack(uint32_t * restrict cl,
   1968                     const struct MALI_PRIMITIVE * restrict values)
   1969 {
   1970    assert(values->index_count >= 1);
   1971    cl[ 0] = __gen_uint(values->draw_mode, 0, 7) |
   1972             __gen_uint(values->index_type, 8, 10) |
   1973             __gen_uint(values->point_size_array_format, 11, 12) |
   1974             __gen_uint(values->primitive_index_enable, 13, 13) |
   1975             __gen_uint(values->primitive_index_writeback, 14, 14) |
   1976             __gen_uint(values->first_provoking_vertex, 15, 15) |
   1977             __gen_uint(values->low_depth_cull, 16, 16) |
   1978             __gen_uint(values->high_depth_cull, 17, 17) |
   1979             __gen_uint(values->secondary_shader, 18, 18) |
   1980             __gen_uint(values->primitive_restart, 19, 20) |
   1981             __gen_uint(values->job_task_split, 26, 31);
   1982    cl[ 1] = __gen_uint(values->base_vertex_offset, 0, 31);
   1983    cl[ 2] = __gen_uint(values->primitive_restart_index, 0, 31);
   1984    cl[ 3] = __gen_uint(values->index_count - 1, 0, 31);
   1985    cl[ 4] = __gen_uint(values->indices, 0, 63);
   1986    cl[ 5] = __gen_uint(values->indices, 0, 63) >> 32;
   1987 }
   1988 
   1989 
   1990 #define MALI_PRIMITIVE_LENGTH 24
   1991 struct mali_primitive_packed { uint32_t opaque[6]; };
   1992 static inline void
   1993 MALI_PRIMITIVE_unpack(const uint8_t * restrict cl,
   1994                       struct MALI_PRIMITIVE * restrict values)
   1995 {
   1996    if (((const uint32_t *) cl)[0] & 0x3e00000) fprintf(stderr, "XXX: Invalid field of Primitive unpacked at word 0\n");
   1997    values->draw_mode = (enum mali_draw_mode)__gen_unpack_uint(cl, 0, 7);
   1998    values->index_type = (enum mali_index_type)__gen_unpack_uint(cl, 8, 10);
   1999    values->point_size_array_format = (enum mali_point_size_array_format)__gen_unpack_uint(cl, 11, 12);
   2000    values->primitive_index_enable = __gen_unpack_uint(cl, 13, 13);
   2001    values->primitive_index_writeback = __gen_unpack_uint(cl, 14, 14);
   2002    values->first_provoking_vertex = __gen_unpack_uint(cl, 15, 15);
   2003    values->low_depth_cull = __gen_unpack_uint(cl, 16, 16);
   2004    values->high_depth_cull = __gen_unpack_uint(cl, 17, 17);
   2005    values->secondary_shader = __gen_unpack_uint(cl, 18, 18);
   2006    values->primitive_restart = (enum mali_primitive_restart)__gen_unpack_uint(cl, 19, 20);
   2007    values->job_task_split = __gen_unpack_uint(cl, 26, 31);
   2008    values->base_vertex_offset = __gen_unpack_uint(cl, 32, 63);
   2009    values->primitive_restart_index = __gen_unpack_uint(cl, 64, 95);
   2010    values->index_count = __gen_unpack_uint(cl, 96, 127) + 1;
   2011    values->indices = __gen_unpack_uint(cl, 128, 191);
   2012 }
   2013 
   2014 static inline void
   2015 MALI_PRIMITIVE_print(FILE *fp, const struct MALI_PRIMITIVE * values, unsigned indent)
   2016 {
   2017    fprintf(fp, "%*sDraw mode: %s\n", indent, "", mali_draw_mode_as_str(values->draw_mode));
   2018    fprintf(fp, "%*sIndex type: %s\n", indent, "", mali_index_type_as_str(values->index_type));
   2019    fprintf(fp, "%*sPoint size array format: %s\n", indent, "", mali_point_size_array_format_as_str(values->point_size_array_format));
   2020    fprintf(fp, "%*sPrimitive Index Enable: %s\n", indent, "", values->primitive_index_enable ? "true" : "false");
   2021    fprintf(fp, "%*sPrimitive Index Writeback: %s\n", indent, "", values->primitive_index_writeback ? "true" : "false");
   2022    fprintf(fp, "%*sFirst provoking vertex: %s\n", indent, "", values->first_provoking_vertex ? "true" : "false");
   2023    fprintf(fp, "%*sLow Depth Cull: %s\n", indent, "", values->low_depth_cull ? "true" : "false");
   2024    fprintf(fp, "%*sHigh Depth Cull: %s\n", indent, "", values->high_depth_cull ? "true" : "false");
   2025    fprintf(fp, "%*sSecondary Shader: %s\n", indent, "", values->secondary_shader ? "true" : "false");
   2026    fprintf(fp, "%*sPrimitive restart: %s\n", indent, "", mali_primitive_restart_as_str(values->primitive_restart));
   2027    fprintf(fp, "%*sJob Task Split: %u\n", indent, "", values->job_task_split);
   2028    fprintf(fp, "%*sBase vertex offset: %u\n", indent, "", values->base_vertex_offset);
   2029    fprintf(fp, "%*sPrimitive Restart Index: %u\n", indent, "", values->primitive_restart_index);
   2030    fprintf(fp, "%*sIndex count: %u\n", indent, "", values->index_count);
   2031    fprintf(fp, "%*sIndices: 0x%" PRIx64 "\n", indent, "", values->indices);
   2032 }
   2033 
   2034 struct MALI_DRAW {
   2035    bool                                 four_components_per_vertex;
   2036    bool                                 draw_descriptor_is_64b;
   2037    enum mali_occlusion_mode             occlusion_query;
   2038    bool                                 front_face_ccw;
   2039    bool                                 cull_front_face;
   2040    bool                                 cull_back_face;
   2041    uint32_t                             flat_shading_vertex;
   2042    bool                                 exclude_filtered_perf_counters;
   2043    bool                                 primitive_barrier;
   2044    bool                                 clean_fragment_write;
   2045    uint32_t                             instance_size;
   2046    uint32_t                             instance_primitive_size;
   2047    uint32_t                             offset_start;
   2048    uint32_t                             primitive_index_base;
   2049    uint64_t                             position;
   2050    uint64_t                             uniform_buffers;
   2051    uint64_t                             textures;
   2052    uint64_t                             samplers;
   2053    uint64_t                             push_uniforms;
   2054    uint64_t                             state;
   2055    uint64_t                             attribute_buffers;
   2056    uint64_t                             attributes;
   2057    uint64_t                             varying_buffers;
   2058    uint64_t                             varyings;
   2059    uint64_t                             viewport;
   2060    uint64_t                             occlusion;
   2061    uint64_t                             thread_storage;
   2062    uint64_t                             fbd;
   2063 };
   2064 
   2065 #define MALI_DRAW_header                        \
   2066    .occlusion_query = MALI_OCCLUSION_MODE_DISABLED,  \
   2067    .instance_size = 1,  \
   2068    .instance_primitive_size = 1
   2069 
   2070 static inline void
   2071 MALI_DRAW_pack(uint32_t * restrict cl,
   2072                const struct MALI_DRAW * restrict values)
   2073 {
   2074    cl[ 0] = __gen_uint(values->four_components_per_vertex, 0, 0) |
   2075             __gen_uint(values->draw_descriptor_is_64b, 1, 1) |
   2076             __gen_uint(values->occlusion_query, 3, 4) |
   2077             __gen_uint(values->front_face_ccw, 5, 5) |
   2078             __gen_uint(values->cull_front_face, 6, 6) |
   2079             __gen_uint(values->cull_back_face, 7, 7) |
   2080             __gen_uint(values->flat_shading_vertex, 8, 8) |
   2081             __gen_uint(values->exclude_filtered_perf_counters, 9, 9) |
   2082             __gen_uint(values->primitive_barrier, 10, 10) |
   2083             __gen_uint(values->clean_fragment_write, 11, 11) |
   2084             __gen_padded(values->instance_size, 16, 23) |
   2085             __gen_padded(values->instance_primitive_size, 24, 31);
   2086    cl[ 1] = __gen_uint(values->offset_start, 0, 31);
   2087    cl[ 2] = __gen_uint(values->primitive_index_base, 0, 31);
   2088    cl[ 3] = 0;
   2089    cl[ 4] = __gen_uint(values->position, 0, 63);
   2090    cl[ 5] = __gen_uint(values->position, 0, 63) >> 32;
   2091    cl[ 6] = __gen_uint(values->uniform_buffers, 0, 63);
   2092    cl[ 7] = __gen_uint(values->uniform_buffers, 0, 63) >> 32;
   2093    cl[ 8] = __gen_uint(values->textures, 0, 63);
   2094    cl[ 9] = __gen_uint(values->textures, 0, 63) >> 32;
   2095    cl[10] = __gen_uint(values->samplers, 0, 63);
   2096    cl[11] = __gen_uint(values->samplers, 0, 63) >> 32;
   2097    cl[12] = __gen_uint(values->push_uniforms, 0, 63);
   2098    cl[13] = __gen_uint(values->push_uniforms, 0, 63) >> 32;
   2099    cl[14] = __gen_uint(values->state, 0, 63);
   2100    cl[15] = __gen_uint(values->state, 0, 63) >> 32;
   2101    cl[16] = __gen_uint(values->attribute_buffers, 0, 63);
   2102    cl[17] = __gen_uint(values->attribute_buffers, 0, 63) >> 32;
   2103    cl[18] = __gen_uint(values->attributes, 0, 63);
   2104    cl[19] = __gen_uint(values->attributes, 0, 63) >> 32;
   2105    cl[20] = __gen_uint(values->varying_buffers, 0, 63);
   2106    cl[21] = __gen_uint(values->varying_buffers, 0, 63) >> 32;
   2107    cl[22] = __gen_uint(values->varyings, 0, 63);
   2108    cl[23] = __gen_uint(values->varyings, 0, 63) >> 32;
   2109    cl[24] = __gen_uint(values->viewport, 0, 63);
   2110    cl[25] = __gen_uint(values->viewport, 0, 63) >> 32;
   2111    cl[26] = __gen_uint(values->occlusion, 0, 63);
   2112    cl[27] = __gen_uint(values->occlusion, 0, 63) >> 32;
   2113    cl[28] = __gen_uint(values->thread_storage, 0, 63) |
   2114             __gen_uint(values->fbd, 0, 63);
   2115    cl[29] = __gen_uint(values->thread_storage, 0, 63) >> 32 |
   2116             __gen_uint(values->fbd, 0, 63) >> 32;
   2117    cl[30] = 0;
   2118    cl[31] = 0;
   2119 }
   2120 
   2121 
   2122 #define MALI_DRAW_LENGTH 128
   2123 #define MALI_DRAW_ALIGN 64
   2124 struct mali_draw_packed { uint32_t opaque[32]; };
   2125 static inline void
   2126 MALI_DRAW_unpack(const uint8_t * restrict cl,
   2127                  struct MALI_DRAW * restrict values)
   2128 {
   2129    if (((const uint32_t *) cl)[0] & 0xf004) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 0\n");
   2130    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 3\n");
   2131    if (((const uint32_t *) cl)[30] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 30\n");
   2132    if (((const uint32_t *) cl)[31] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 31\n");
   2133    values->four_components_per_vertex = __gen_unpack_uint(cl, 0, 0);
   2134    values->draw_descriptor_is_64b = __gen_unpack_uint(cl, 1, 1);
   2135    values->occlusion_query = (enum mali_occlusion_mode)__gen_unpack_uint(cl, 3, 4);
   2136    values->front_face_ccw = __gen_unpack_uint(cl, 5, 5);
   2137    values->cull_front_face = __gen_unpack_uint(cl, 6, 6);
   2138    values->cull_back_face = __gen_unpack_uint(cl, 7, 7);
   2139    values->flat_shading_vertex = __gen_unpack_uint(cl, 8, 8);
   2140    values->exclude_filtered_perf_counters = __gen_unpack_uint(cl, 9, 9);
   2141    values->primitive_barrier = __gen_unpack_uint(cl, 10, 10);
   2142    values->clean_fragment_write = __gen_unpack_uint(cl, 11, 11);
   2143    values->instance_size = __gen_unpack_padded(cl, 16, 23);
   2144    values->instance_primitive_size = __gen_unpack_padded(cl, 24, 31);
   2145    values->offset_start = __gen_unpack_uint(cl, 32, 63);
   2146    values->primitive_index_base = __gen_unpack_uint(cl, 64, 95);
   2147    values->position = __gen_unpack_uint(cl, 128, 191);
   2148    values->uniform_buffers = __gen_unpack_uint(cl, 192, 255);
   2149    values->textures = __gen_unpack_uint(cl, 256, 319);
   2150    values->samplers = __gen_unpack_uint(cl, 320, 383);
   2151    values->push_uniforms = __gen_unpack_uint(cl, 384, 447);
   2152    values->state = __gen_unpack_uint(cl, 448, 511);
   2153    values->attribute_buffers = __gen_unpack_uint(cl, 512, 575);
   2154    values->attributes = __gen_unpack_uint(cl, 576, 639);
   2155    values->varying_buffers = __gen_unpack_uint(cl, 640, 703);
   2156    values->varyings = __gen_unpack_uint(cl, 704, 767);
   2157    values->viewport = __gen_unpack_uint(cl, 768, 831);
   2158    values->occlusion = __gen_unpack_uint(cl, 832, 895);
   2159    values->thread_storage = __gen_unpack_uint(cl, 896, 959);
   2160    values->fbd = __gen_unpack_uint(cl, 896, 959);
   2161 }
   2162 
   2163 static inline void
   2164 MALI_DRAW_print(FILE *fp, const struct MALI_DRAW * values, unsigned indent)
   2165 {
   2166    fprintf(fp, "%*sFour Components Per Vertex: %s\n", indent, "", values->four_components_per_vertex ? "true" : "false");
   2167    fprintf(fp, "%*sDraw Descriptor Is 64b: %s\n", indent, "", values->draw_descriptor_is_64b ? "true" : "false");
   2168    fprintf(fp, "%*sOcclusion query: %s\n", indent, "", mali_occlusion_mode_as_str(values->occlusion_query));
   2169    fprintf(fp, "%*sFront face CCW: %s\n", indent, "", values->front_face_ccw ? "true" : "false");
   2170    fprintf(fp, "%*sCull front face: %s\n", indent, "", values->cull_front_face ? "true" : "false");
   2171    fprintf(fp, "%*sCull back face: %s\n", indent, "", values->cull_back_face ? "true" : "false");
   2172    fprintf(fp, "%*sFlat Shading Vertex: %u\n", indent, "", values->flat_shading_vertex);
   2173    fprintf(fp, "%*sExclude Filtered Perf Counters: %s\n", indent, "", values->exclude_filtered_perf_counters ? "true" : "false");
   2174    fprintf(fp, "%*sPrimitive Barrier: %s\n", indent, "", values->primitive_barrier ? "true" : "false");
   2175    fprintf(fp, "%*sClean Fragment Write: %s\n", indent, "", values->clean_fragment_write ? "true" : "false");
   2176    fprintf(fp, "%*sInstance Size: %u\n", indent, "", values->instance_size);
   2177    fprintf(fp, "%*sInstance Primitive Size: %u\n", indent, "", values->instance_primitive_size);
   2178    fprintf(fp, "%*sOffset start: %u\n", indent, "", values->offset_start);
   2179    fprintf(fp, "%*sPrimitive Index Base: %u\n", indent, "", values->primitive_index_base);
   2180    fprintf(fp, "%*sPosition: 0x%" PRIx64 "\n", indent, "", values->position);
   2181    fprintf(fp, "%*sUniform buffers: 0x%" PRIx64 "\n", indent, "", values->uniform_buffers);
   2182    fprintf(fp, "%*sTextures: 0x%" PRIx64 "\n", indent, "", values->textures);
   2183    fprintf(fp, "%*sSamplers: 0x%" PRIx64 "\n", indent, "", values->samplers);
   2184    fprintf(fp, "%*sPush uniforms: 0x%" PRIx64 "\n", indent, "", values->push_uniforms);
   2185    fprintf(fp, "%*sState: 0x%" PRIx64 "\n", indent, "", values->state);
   2186    fprintf(fp, "%*sAttribute buffers: 0x%" PRIx64 "\n", indent, "", values->attribute_buffers);
   2187    fprintf(fp, "%*sAttributes: 0x%" PRIx64 "\n", indent, "", values->attributes);
   2188    fprintf(fp, "%*sVarying buffers: 0x%" PRIx64 "\n", indent, "", values->varying_buffers);
   2189    fprintf(fp, "%*sVaryings: 0x%" PRIx64 "\n", indent, "", values->varyings);
   2190    fprintf(fp, "%*sViewport: 0x%" PRIx64 "\n", indent, "", values->viewport);
   2191    fprintf(fp, "%*sOcclusion: 0x%" PRIx64 "\n", indent, "", values->occlusion);
   2192    fprintf(fp, "%*sThread Storage: 0x%" PRIx64 "\n", indent, "", values->thread_storage);
   2193    fprintf(fp, "%*sFBD: 0x%" PRIx64 "\n", indent, "", values->fbd);
   2194 }
   2195 
   2196 struct MALI_SURFACE {
   2197    uint64_t                             pointer;
   2198 };
   2199 
   2200 #define MALI_SURFACE_header                     \
   2201    0
   2202 
   2203 static inline void
   2204 MALI_SURFACE_pack(uint32_t * restrict cl,
   2205                   const struct MALI_SURFACE * restrict values)
   2206 {
   2207    cl[ 0] = __gen_uint(values->pointer, 0, 63);
   2208    cl[ 1] = __gen_uint(values->pointer, 0, 63) >> 32;
   2209 }
   2210 
   2211 
   2212 #define MALI_SURFACE_LENGTH 8
   2213 #define MALI_SURFACE_ALIGN 8
   2214 struct mali_surface_packed { uint32_t opaque[2]; };
   2215 static inline void
   2216 MALI_SURFACE_unpack(const uint8_t * restrict cl,
   2217                     struct MALI_SURFACE * restrict values)
   2218 {
   2219    values->pointer = __gen_unpack_uint(cl, 0, 63);
   2220 }
   2221 
   2222 static inline void
   2223 MALI_SURFACE_print(FILE *fp, const struct MALI_SURFACE * values, unsigned indent)
   2224 {
   2225    fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
   2226 }
   2227 
   2228 struct MALI_SURFACE_WITH_STRIDE {
   2229    uint64_t                             pointer;
   2230    int32_t                              row_stride;
   2231    int32_t                              surface_stride;
   2232 };
   2233 
   2234 #define MALI_SURFACE_WITH_STRIDE_header         \
   2235    0
   2236 
   2237 static inline void
   2238 MALI_SURFACE_WITH_STRIDE_pack(uint32_t * restrict cl,
   2239                               const struct MALI_SURFACE_WITH_STRIDE * restrict values)
   2240 {
   2241    cl[ 0] = __gen_uint(values->pointer, 0, 63);
   2242    cl[ 1] = __gen_uint(values->pointer, 0, 63) >> 32;
   2243    cl[ 2] = __gen_sint(values->row_stride, 0, 31);
   2244    cl[ 3] = __gen_sint(values->surface_stride, 0, 31);
   2245 }
   2246 
   2247 
   2248 #define MALI_SURFACE_WITH_STRIDE_LENGTH 16
   2249 #define MALI_SURFACE_WITH_STRIDE_ALIGN 8
   2250 struct mali_surface_with_stride_packed { uint32_t opaque[4]; };
   2251 static inline void
   2252 MALI_SURFACE_WITH_STRIDE_unpack(const uint8_t * restrict cl,
   2253                                 struct MALI_SURFACE_WITH_STRIDE * restrict values)
   2254 {
   2255    values->pointer = __gen_unpack_uint(cl, 0, 63);
   2256    values->row_stride = __gen_unpack_sint(cl, 64, 95);
   2257    values->surface_stride = __gen_unpack_sint(cl, 96, 127);
   2258 }
   2259 
   2260 static inline void
   2261 MALI_SURFACE_WITH_STRIDE_print(FILE *fp, const struct MALI_SURFACE_WITH_STRIDE * values, unsigned indent)
   2262 {
   2263    fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
   2264    fprintf(fp, "%*sRow stride: %d\n", indent, "", values->row_stride);
   2265    fprintf(fp, "%*sSurface stride: %d\n", indent, "", values->surface_stride);
   2266 }
   2267 
   2268 struct MALI_SAMPLER {
   2269    uint32_t                             type;
   2270    enum mali_wrap_mode                  wrap_mode_r;
   2271    enum mali_wrap_mode                  wrap_mode_t;
   2272    enum mali_wrap_mode                  wrap_mode_s;
   2273    bool                                 round_to_nearest_even;
   2274    bool                                 srgb_override;
   2275    bool                                 seamless_cube_map;
   2276    bool                                 clamp_integer_coordinates;
   2277    bool                                 normalized_coordinates;
   2278    bool                                 clamp_integer_array_indices;
   2279    bool                                 minify_nearest;
   2280    bool                                 magnify_nearest;
   2281    bool                                 magnify_cutoff;
   2282    enum mali_mipmap_mode                mipmap_mode;
   2283    uint32_t                             minimum_lod;
   2284    enum mali_func                       compare_function;
   2285    uint32_t                             maximum_lod;
   2286    int32_t                              lod_bias;
   2287    uint32_t                             maximum_anisotropy;
   2288    enum mali_lod_algorithm              lod_algorithm;
   2289    uint32_t                             border_color_r;
   2290    uint32_t                             border_color_g;
   2291    uint32_t                             border_color_b;
   2292    uint32_t                             border_color_a;
   2293 };
   2294 
   2295 #define MALI_SAMPLER_header                     \
   2296    .type = 1,  \
   2297    .wrap_mode_r = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
   2298    .wrap_mode_t = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
   2299    .wrap_mode_s = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
   2300    .round_to_nearest_even = false,  \
   2301    .srgb_override = false,  \
   2302    .seamless_cube_map = true,  \
   2303    .normalized_coordinates = true,  \
   2304    .clamp_integer_array_indices = true,  \
   2305    .minify_nearest = false,  \
   2306    .magnify_nearest = false,  \
   2307    .magnify_cutoff = false,  \
   2308    .mipmap_mode = MALI_MIPMAP_MODE_NEAREST,  \
   2309    .minimum_lod = 0,  \
   2310    .compare_function = MALI_FUNC_NEVER,  \
   2311    .maximum_lod = 0,  \
   2312    .lod_bias = 0,  \
   2313    .maximum_anisotropy = 1,  \
   2314    .lod_algorithm = MALI_LOD_ALGORITHM_ISOTROPIC,  \
   2315    .border_color_r = 0.0,  \
   2316    .border_color_g = 0.0,  \
   2317    .border_color_b = 0.0,  \
   2318    .border_color_a = 0.0
   2319 
   2320 static inline void
   2321 MALI_SAMPLER_pack(uint32_t * restrict cl,
   2322                   const struct MALI_SAMPLER * restrict values)
   2323 {
   2324    assert(values->maximum_anisotropy >= 1);
   2325    cl[ 0] = __gen_uint(values->type, 0, 3) |
   2326             __gen_uint(values->wrap_mode_r, 8, 11) |
   2327             __gen_uint(values->wrap_mode_t, 12, 15) |
   2328             __gen_uint(values->wrap_mode_s, 16, 19) |
   2329             __gen_uint(values->round_to_nearest_even, 21, 21) |
   2330             __gen_uint(values->srgb_override, 22, 22) |
   2331             __gen_uint(values->seamless_cube_map, 23, 23) |
   2332             __gen_uint(values->clamp_integer_coordinates, 24, 24) |
   2333             __gen_uint(values->normalized_coordinates, 25, 25) |
   2334             __gen_uint(values->clamp_integer_array_indices, 26, 26) |
   2335             __gen_uint(values->minify_nearest, 27, 27) |
   2336             __gen_uint(values->magnify_nearest, 28, 28) |
   2337             __gen_uint(values->magnify_cutoff, 29, 29) |
   2338             __gen_uint(values->mipmap_mode, 30, 31);
   2339    cl[ 1] = __gen_uint(values->minimum_lod, 0, 12) |
   2340             __gen_uint(values->compare_function, 13, 15) |
   2341             __gen_uint(values->maximum_lod, 16, 28);
   2342    cl[ 2] = __gen_sint(values->lod_bias, 0, 15) |
   2343             __gen_uint(values->maximum_anisotropy - 1, 16, 20) |
   2344             __gen_uint(values->lod_algorithm, 24, 25);
   2345    cl[ 3] = 0;
   2346    cl[ 4] = __gen_uint(values->border_color_r, 0, 31);
   2347    cl[ 5] = __gen_uint(values->border_color_g, 0, 31);
   2348    cl[ 6] = __gen_uint(values->border_color_b, 0, 31);
   2349    cl[ 7] = __gen_uint(values->border_color_a, 0, 31);
   2350 }
   2351 
   2352 
   2353 #define MALI_SAMPLER_LENGTH 32
   2354 #define MALI_SAMPLER_ALIGN 32
   2355 struct mali_sampler_packed { uint32_t opaque[8]; };
   2356 static inline void
   2357 MALI_SAMPLER_unpack(const uint8_t * restrict cl,
   2358                     struct MALI_SAMPLER * restrict values)
   2359 {
   2360    if (((const uint32_t *) cl)[0] & 0x1000f0) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 0\n");
   2361    if (((const uint32_t *) cl)[1] & 0xe0000000) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 1\n");
   2362    if (((const uint32_t *) cl)[2] & 0xfce00000) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 2\n");
   2363    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 3\n");
   2364    values->type = __gen_unpack_uint(cl, 0, 3);
   2365    values->wrap_mode_r = (enum mali_wrap_mode)__gen_unpack_uint(cl, 8, 11);
   2366    values->wrap_mode_t = (enum mali_wrap_mode)__gen_unpack_uint(cl, 12, 15);
   2367    values->wrap_mode_s = (enum mali_wrap_mode)__gen_unpack_uint(cl, 16, 19);
   2368    values->round_to_nearest_even = __gen_unpack_uint(cl, 21, 21);
   2369    values->srgb_override = __gen_unpack_uint(cl, 22, 22);
   2370    values->seamless_cube_map = __gen_unpack_uint(cl, 23, 23);
   2371    values->clamp_integer_coordinates = __gen_unpack_uint(cl, 24, 24);
   2372    values->normalized_coordinates = __gen_unpack_uint(cl, 25, 25);
   2373    values->clamp_integer_array_indices = __gen_unpack_uint(cl, 26, 26);
   2374    values->minify_nearest = __gen_unpack_uint(cl, 27, 27);
   2375    values->magnify_nearest = __gen_unpack_uint(cl, 28, 28);
   2376    values->magnify_cutoff = __gen_unpack_uint(cl, 29, 29);
   2377    values->mipmap_mode = (enum mali_mipmap_mode)__gen_unpack_uint(cl, 30, 31);
   2378    values->minimum_lod = __gen_unpack_uint(cl, 32, 44);
   2379    values->compare_function = (enum mali_func)__gen_unpack_uint(cl, 45, 47);
   2380    values->maximum_lod = __gen_unpack_uint(cl, 48, 60);
   2381    values->lod_bias = __gen_unpack_sint(cl, 64, 79);
   2382    values->maximum_anisotropy = __gen_unpack_uint(cl, 80, 84) + 1;
   2383    values->lod_algorithm = (enum mali_lod_algorithm)__gen_unpack_uint(cl, 88, 89);
   2384    values->border_color_r = __gen_unpack_uint(cl, 128, 159);
   2385    values->border_color_g = __gen_unpack_uint(cl, 160, 191);
   2386    values->border_color_b = __gen_unpack_uint(cl, 192, 223);
   2387    values->border_color_a = __gen_unpack_uint(cl, 224, 255);
   2388 }
   2389 
   2390 static inline void
   2391 MALI_SAMPLER_print(FILE *fp, const struct MALI_SAMPLER * values, unsigned indent)
   2392 {
   2393    fprintf(fp, "%*sType: %u\n", indent, "", values->type);
   2394    fprintf(fp, "%*sWrap Mode R: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_r));
   2395    fprintf(fp, "%*sWrap Mode T: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_t));
   2396    fprintf(fp, "%*sWrap Mode S: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_s));
   2397    fprintf(fp, "%*sRound to nearest even: %s\n", indent, "", values->round_to_nearest_even ? "true" : "false");
   2398    fprintf(fp, "%*ssRGB override: %s\n", indent, "", values->srgb_override ? "true" : "false");
   2399    fprintf(fp, "%*sSeamless Cube Map: %s\n", indent, "", values->seamless_cube_map ? "true" : "false");
   2400    fprintf(fp, "%*sClamp integer coordinates: %s\n", indent, "", values->clamp_integer_coordinates ? "true" : "false");
   2401    fprintf(fp, "%*sNormalized Coordinates: %s\n", indent, "", values->normalized_coordinates ? "true" : "false");
   2402    fprintf(fp, "%*sClamp integer array indices: %s\n", indent, "", values->clamp_integer_array_indices ? "true" : "false");
   2403    fprintf(fp, "%*sMinify nearest: %s\n", indent, "", values->minify_nearest ? "true" : "false");
   2404    fprintf(fp, "%*sMagnify nearest: %s\n", indent, "", values->magnify_nearest ? "true" : "false");
   2405    fprintf(fp, "%*sMagnify cutoff: %s\n", indent, "", values->magnify_cutoff ? "true" : "false");
   2406    fprintf(fp, "%*sMipmap Mode: %s\n", indent, "", mali_mipmap_mode_as_str(values->mipmap_mode));
   2407    fprintf(fp, "%*sMinimum LOD: %u\n", indent, "", values->minimum_lod);
   2408    fprintf(fp, "%*sCompare Function: %s\n", indent, "", mali_func_as_str(values->compare_function));
   2409    fprintf(fp, "%*sMaximum LOD: %u\n", indent, "", values->maximum_lod);
   2410    fprintf(fp, "%*sLOD bias: %d\n", indent, "", values->lod_bias);
   2411    fprintf(fp, "%*sMaximum anisotropy: %u\n", indent, "", values->maximum_anisotropy);
   2412    fprintf(fp, "%*sLOD algorithm: %s\n", indent, "", mali_lod_algorithm_as_str(values->lod_algorithm));
   2413    fprintf(fp, "%*sBorder Color R: 0x%X (%f)\n", indent, "", values->border_color_r, uif(values->border_color_r));
   2414    fprintf(fp, "%*sBorder Color G: 0x%X (%f)\n", indent, "", values->border_color_g, uif(values->border_color_g));
   2415    fprintf(fp, "%*sBorder Color B: 0x%X (%f)\n", indent, "", values->border_color_b, uif(values->border_color_b));
   2416    fprintf(fp, "%*sBorder Color A: 0x%X (%f)\n", indent, "", values->border_color_a, uif(values->border_color_a));
   2417 }
   2418 
   2419 struct MALI_TEXTURE {
   2420    uint32_t                             type;
   2421    enum mali_texture_dimension          dimension;
   2422    bool                                 sample_corner_position;
   2423    bool                                 normalize_coordinates;
   2424    uint32_t                             format;
   2425    uint32_t                             width;
   2426    uint32_t                             height;
   2427    uint32_t                             swizzle;
   2428    enum mali_texture_layout             texel_ordering;
   2429    uint32_t                             levels;
   2430    uint32_t                             minimum_level;
   2431    uint32_t                             minimum_lod;
   2432    uint32_t                             sample_count;
   2433    uint32_t                             maximum_lod;
   2434    uint64_t                             surfaces;
   2435    uint32_t                             array_size;
   2436    uint32_t                             depth;
   2437 };
   2438 
   2439 #define MALI_TEXTURE_header                     \
   2440    .type = 2,  \
   2441    .sample_corner_position = false,  \
   2442    .normalize_coordinates = false,  \
   2443    .levels = 1,  \
   2444    .minimum_lod = 0,  \
   2445    .sample_count = 1,  \
   2446    .maximum_lod = 0,  \
   2447    .array_size = 1,  \
   2448    .depth = 1
   2449 
   2450 static inline void
   2451 MALI_TEXTURE_pack(uint32_t * restrict cl,
   2452                   const struct MALI_TEXTURE * restrict values)
   2453 {
   2454    assert(values->width >= 1);
   2455    assert(values->height >= 1);
   2456    assert(values->levels >= 1);
   2457    assert(util_is_power_of_two_nonzero(values->sample_count));
   2458    assert(values->array_size >= 1);
   2459    assert(values->depth >= 1);
   2460    cl[ 0] = __gen_uint(values->type, 0, 3) |
   2461             __gen_uint(values->dimension, 4, 5) |
   2462             __gen_uint(values->sample_corner_position, 8, 8) |
   2463             __gen_uint(values->normalize_coordinates, 9, 9) |
   2464             __gen_uint(values->format, 10, 31);
   2465    cl[ 1] = __gen_uint(values->width - 1, 0, 15) |
   2466             __gen_uint(values->height - 1, 16, 31);
   2467    cl[ 2] = __gen_uint(values->swizzle, 0, 11) |
   2468             __gen_uint(values->texel_ordering, 12, 15) |
   2469             __gen_uint(values->levels - 1, 16, 20) |
   2470             __gen_uint(values->minimum_level, 24, 28);
   2471    cl[ 3] = __gen_uint(values->minimum_lod, 0, 12) |
   2472             __gen_uint(util_logbase2(values->sample_count), 13, 15) |
   2473             __gen_uint(values->maximum_lod, 16, 28);
   2474    cl[ 4] = __gen_uint(values->surfaces, 0, 63);
   2475    cl[ 5] = __gen_uint(values->surfaces, 0, 63) >> 32;
   2476    cl[ 6] = __gen_uint(values->array_size - 1, 0, 15);
   2477    cl[ 7] = __gen_uint(values->depth - 1, 0, 15);
   2478 }
   2479 
   2480 
   2481 #define MALI_TEXTURE_LENGTH 32
   2482 #define MALI_TEXTURE_ALIGN 32
   2483 struct mali_texture_packed { uint32_t opaque[8]; };
   2484 static inline void
   2485 MALI_TEXTURE_unpack(const uint8_t * restrict cl,
   2486                     struct MALI_TEXTURE * restrict values)
   2487 {
   2488    if (((const uint32_t *) cl)[0] & 0xc0) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 0\n");
   2489    if (((const uint32_t *) cl)[2] & 0xe0e00000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 2\n");
   2490    if (((const uint32_t *) cl)[3] & 0xe0000000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 3\n");
   2491    if (((const uint32_t *) cl)[6] & 0xffff0000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 6\n");
   2492    if (((const uint32_t *) cl)[7] & 0xffff0000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 7\n");
   2493    values->type = __gen_unpack_uint(cl, 0, 3);
   2494    values->dimension = (enum mali_texture_dimension)__gen_unpack_uint(cl, 4, 5);
   2495    values->sample_corner_position = __gen_unpack_uint(cl, 8, 8);
   2496    values->normalize_coordinates = __gen_unpack_uint(cl, 9, 9);
   2497    values->format = __gen_unpack_uint(cl, 10, 31);
   2498    values->width = __gen_unpack_uint(cl, 32, 47) + 1;
   2499    values->height = __gen_unpack_uint(cl, 48, 63) + 1;
   2500    values->swizzle = __gen_unpack_uint(cl, 64, 75);
   2501    values->texel_ordering = (enum mali_texture_layout)__gen_unpack_uint(cl, 76, 79);
   2502    values->levels = __gen_unpack_uint(cl, 80, 84) + 1;
   2503    values->minimum_level = __gen_unpack_uint(cl, 88, 92);
   2504    values->minimum_lod = __gen_unpack_uint(cl, 96, 108);
   2505    values->sample_count = 1U << __gen_unpack_uint(cl, 109, 111);
   2506    values->maximum_lod = __gen_unpack_uint(cl, 112, 124);
   2507    values->surfaces = __gen_unpack_uint(cl, 128, 191);
   2508    values->array_size = __gen_unpack_uint(cl, 192, 207) + 1;
   2509    values->depth = __gen_unpack_uint(cl, 224, 239) + 1;
   2510 }
   2511 
   2512 static inline void
   2513 MALI_TEXTURE_print(FILE *fp, const struct MALI_TEXTURE * values, unsigned indent)
   2514 {
   2515    fprintf(fp, "%*sType: %u\n", indent, "", values->type);
   2516    fprintf(fp, "%*sDimension: %s\n", indent, "", mali_texture_dimension_as_str(values->dimension));
   2517    fprintf(fp, "%*sSample corner position: %s\n", indent, "", values->sample_corner_position ? "true" : "false");
   2518    fprintf(fp, "%*sNormalize coordinates: %s\n", indent, "", values->normalize_coordinates ? "true" : "false");
   2519    mali_pixel_format_print(fp, values->format);
   2520    fprintf(fp, "%*sWidth: %u\n", indent, "", values->width);
   2521    fprintf(fp, "%*sHeight: %u\n", indent, "", values->height);
   2522    fprintf(fp, "%*sSwizzle: %u\n", indent, "", values->swizzle);
   2523    fprintf(fp, "%*sTexel ordering: %s\n", indent, "", mali_texture_layout_as_str(values->texel_ordering));
   2524    fprintf(fp, "%*sLevels: %u\n", indent, "", values->levels);
   2525    fprintf(fp, "%*sMinimum level: %u\n", indent, "", values->minimum_level);
   2526    fprintf(fp, "%*sMinimum LOD: %u\n", indent, "", values->minimum_lod);
   2527    fprintf(fp, "%*sSample count: %u\n", indent, "", values->sample_count);
   2528    fprintf(fp, "%*sMaximum LOD: %u\n", indent, "", values->maximum_lod);
   2529    fprintf(fp, "%*sSurfaces: 0x%" PRIx64 "\n", indent, "", values->surfaces);
   2530    fprintf(fp, "%*sArray size: %u\n", indent, "", values->array_size);
   2531    fprintf(fp, "%*sDepth: %u\n", indent, "", values->depth);
   2532 }
   2533 
   2534 enum mali_shader_register_allocation {
   2535         MALI_SHADER_REGISTER_ALLOCATION_64_PER_THREAD =      0,
   2536         MALI_SHADER_REGISTER_ALLOCATION_32_PER_THREAD =      2,
   2537 };
   2538 
   2539 static inline const char *
   2540 mali_shader_register_allocation_as_str(enum mali_shader_register_allocation imm)
   2541 {
   2542     switch (imm) {
   2543     case MALI_SHADER_REGISTER_ALLOCATION_64_PER_THREAD: return "64 Per Thread";
   2544     case MALI_SHADER_REGISTER_ALLOCATION_32_PER_THREAD: return "32 Per Thread";
   2545     default: return "XXX: INVALID";
   2546     }
   2547 }
   2548 
   2549 struct MALI_RENDERER_PROPERTIES {
   2550    uint32_t                             uniform_buffer_count;
   2551    enum mali_depth_source               depth_source;
   2552    bool                                 shader_contains_barrier;
   2553    enum mali_shader_register_allocation shader_register_allocation;
   2554    enum mali_shader_register_allocation secondary_shader_register_allocation;
   2555    bool                                 shader_modifies_coverage;
   2556    bool                                 allow_forward_pixel_to_kill;
   2557    bool                                 allow_forward_pixel_to_be_killed;
   2558    enum mali_pixel_kill                 pixel_kill_operation;
   2559    enum mali_pixel_kill                 zs_update_operation;
   2560    bool                                 point_sprite_coord_origin_max_y;
   2561    bool                                 stencil_from_shader;
   2562    bool                                 shader_wait_dependency_6;
   2563    bool                                 shader_wait_dependency_7;
   2564 };
   2565 
   2566 #define MALI_RENDERER_PROPERTIES_header         \
   2567    .depth_source = MALI_DEPTH_SOURCE_MINIMUM
   2568 
   2569 static inline void
   2570 MALI_RENDERER_PROPERTIES_pack(uint32_t * restrict cl,
   2571                               const struct MALI_RENDERER_PROPERTIES * restrict values)
   2572 {
   2573    cl[ 0] = __gen_uint(values->uniform_buffer_count, 0, 7) |
   2574             __gen_uint(values->depth_source, 8, 9) |
   2575             __gen_uint(values->shader_contains_barrier, 11, 11) |
   2576             __gen_uint(values->shader_register_allocation, 12, 13) |
   2577             __gen_uint(values->secondary_shader_register_allocation, 14, 15) |
   2578             __gen_uint(values->shader_modifies_coverage, 16, 16) |
   2579             __gen_uint(values->allow_forward_pixel_to_kill, 19, 19) |
   2580             __gen_uint(values->allow_forward_pixel_to_be_killed, 20, 20) |
   2581             __gen_uint(values->pixel_kill_operation, 21, 22) |
   2582             __gen_uint(values->zs_update_operation, 23, 24) |
   2583             __gen_uint(values->point_sprite_coord_origin_max_y, 27, 27) |
   2584             __gen_uint(values->stencil_from_shader, 28, 28) |
   2585             __gen_uint(values->shader_wait_dependency_6, 30, 30) |
   2586             __gen_uint(values->shader_wait_dependency_7, 31, 31);
   2587 }
   2588 
   2589 
   2590 #define MALI_RENDERER_PROPERTIES_LENGTH 4
   2591 struct mali_renderer_properties_packed { uint32_t opaque[1]; };
   2592 static inline void
   2593 MALI_RENDERER_PROPERTIES_unpack(const uint8_t * restrict cl,
   2594                                 struct MALI_RENDERER_PROPERTIES * restrict values)
   2595 {
   2596    if (((const uint32_t *) cl)[0] & 0x26060400) fprintf(stderr, "XXX: Invalid field of Renderer Properties unpacked at word 0\n");
   2597    values->uniform_buffer_count = __gen_unpack_uint(cl, 0, 7);
   2598    values->depth_source = (enum mali_depth_source)__gen_unpack_uint(cl, 8, 9);
   2599    values->shader_contains_barrier = __gen_unpack_uint(cl, 11, 11);
   2600    values->shader_register_allocation = (enum mali_shader_register_allocation)__gen_unpack_uint(cl, 12, 13);
   2601    values->secondary_shader_register_allocation = (enum mali_shader_register_allocation)__gen_unpack_uint(cl, 14, 15);
   2602    values->shader_modifies_coverage = __gen_unpack_uint(cl, 16, 16);
   2603    values->allow_forward_pixel_to_kill = __gen_unpack_uint(cl, 19, 19);
   2604    values->allow_forward_pixel_to_be_killed = __gen_unpack_uint(cl, 20, 20);
   2605    values->pixel_kill_operation = (enum mali_pixel_kill)__gen_unpack_uint(cl, 21, 22);
   2606    values->zs_update_operation = (enum mali_pixel_kill)__gen_unpack_uint(cl, 23, 24);
   2607    values->point_sprite_coord_origin_max_y = __gen_unpack_uint(cl, 27, 27);
   2608    values->stencil_from_shader = __gen_unpack_uint(cl, 28, 28);
   2609    values->shader_wait_dependency_6 = __gen_unpack_uint(cl, 30, 30);
   2610    values->shader_wait_dependency_7 = __gen_unpack_uint(cl, 31, 31);
   2611 }
   2612 
   2613 static inline void
   2614 MALI_RENDERER_PROPERTIES_print(FILE *fp, const struct MALI_RENDERER_PROPERTIES * values, unsigned indent)
   2615 {
   2616    fprintf(fp, "%*sUniform buffer count: %u\n", indent, "", values->uniform_buffer_count);
   2617    fprintf(fp, "%*sDepth source: %s\n", indent, "", mali_depth_source_as_str(values->depth_source));
   2618    fprintf(fp, "%*sShader contains barrier: %s\n", indent, "", values->shader_contains_barrier ? "true" : "false");
   2619    fprintf(fp, "%*sShader register allocation: %s\n", indent, "", mali_shader_register_allocation_as_str(values->shader_register_allocation));
   2620    fprintf(fp, "%*sSecondary shader register allocation: %s\n", indent, "", mali_shader_register_allocation_as_str(values->secondary_shader_register_allocation));
   2621    fprintf(fp, "%*sShader modifies coverage: %s\n", indent, "", values->shader_modifies_coverage ? "true" : "false");
   2622    fprintf(fp, "%*sAllow forward pixel to kill: %s\n", indent, "", values->allow_forward_pixel_to_kill ? "true" : "false");
   2623    fprintf(fp, "%*sAllow forward pixel to be killed: %s\n", indent, "", values->allow_forward_pixel_to_be_killed ? "true" : "false");
   2624    fprintf(fp, "%*sPixel kill operation: %s\n", indent, "", mali_pixel_kill_as_str(values->pixel_kill_operation));
   2625    fprintf(fp, "%*sZS update operation: %s\n", indent, "", mali_pixel_kill_as_str(values->zs_update_operation));
   2626    fprintf(fp, "%*sPoint sprite coord origin max Y: %s\n", indent, "", values->point_sprite_coord_origin_max_y ? "true" : "false");
   2627    fprintf(fp, "%*sStencil from shader: %s\n", indent, "", values->stencil_from_shader ? "true" : "false");
   2628    fprintf(fp, "%*sShader wait dependency 6: %s\n", indent, "", values->shader_wait_dependency_6 ? "true" : "false");
   2629    fprintf(fp, "%*sShader wait dependency 7: %s\n", indent, "", values->shader_wait_dependency_7 ? "true" : "false");
   2630 }
   2631 
   2632 struct MALI_COMPUTE_PRELOAD {
   2633    bool                                 pc;
   2634    bool                                 local_invocation_xy;
   2635    bool                                 local_invocation_z;
   2636    bool                                 work_group_x;
   2637    bool                                 work_group_y;
   2638    bool                                 work_group_z;
   2639    bool                                 global_invocation_x;
   2640    bool                                 global_invocation_y;
   2641    bool                                 global_invocation_z;
   2642 };
   2643 
   2644 #define MALI_COMPUTE_PRELOAD_header             \
   2645    0
   2646 
   2647 static inline void
   2648 MALI_COMPUTE_PRELOAD_print(FILE *fp, const struct MALI_COMPUTE_PRELOAD * values, unsigned indent)
   2649 {
   2650    fprintf(fp, "%*sPC: %s\n", indent, "", values->pc ? "true" : "false");
   2651    fprintf(fp, "%*sLocal Invocation XY: %s\n", indent, "", values->local_invocation_xy ? "true" : "false");
   2652    fprintf(fp, "%*sLocal Invocation Z: %s\n", indent, "", values->local_invocation_z ? "true" : "false");
   2653    fprintf(fp, "%*sWork group X: %s\n", indent, "", values->work_group_x ? "true" : "false");
   2654    fprintf(fp, "%*sWork group Y: %s\n", indent, "", values->work_group_y ? "true" : "false");
   2655    fprintf(fp, "%*sWork group Z: %s\n", indent, "", values->work_group_z ? "true" : "false");
   2656    fprintf(fp, "%*sGlobal Invocation X: %s\n", indent, "", values->global_invocation_x ? "true" : "false");
   2657    fprintf(fp, "%*sGlobal Invocation Y: %s\n", indent, "", values->global_invocation_y ? "true" : "false");
   2658    fprintf(fp, "%*sGlobal Invocation Z: %s\n", indent, "", values->global_invocation_z ? "true" : "false");
   2659 }
   2660 
   2661 enum mali_warp_limit {
   2662         MALI_WARP_LIMIT_NONE                 =      0,
   2663         MALI_WARP_LIMIT_2                    =      1,
   2664         MALI_WARP_LIMIT_4                    =      2,
   2665         MALI_WARP_LIMIT_8                    =      3,
   2666 };
   2667 
   2668 static inline const char *
   2669 mali_warp_limit_as_str(enum mali_warp_limit imm)
   2670 {
   2671     switch (imm) {
   2672     case MALI_WARP_LIMIT_NONE: return "None";
   2673     case MALI_WARP_LIMIT_2: return "2";
   2674     case MALI_WARP_LIMIT_4: return "4";
   2675     case MALI_WARP_LIMIT_8: return "8";
   2676     default: return "XXX: INVALID";
   2677     }
   2678 }
   2679 
   2680 struct MALI_VERTEX_PRELOAD {
   2681    enum mali_warp_limit                 warp_limit;
   2682    bool                                 pc;
   2683    bool                                 position_result_address_lo;
   2684    bool                                 position_result_address_hi;
   2685    bool                                 vertex_id;
   2686    bool                                 instance_id;
   2687 };
   2688 
   2689 #define MALI_VERTEX_PRELOAD_header              \
   2690    0
   2691 
   2692 static inline void
   2693 MALI_VERTEX_PRELOAD_print(FILE *fp, const struct MALI_VERTEX_PRELOAD * values, unsigned indent)
   2694 {
   2695    fprintf(fp, "%*sWarp limit: %s\n", indent, "", mali_warp_limit_as_str(values->warp_limit));
   2696    fprintf(fp, "%*sPC: %s\n", indent, "", values->pc ? "true" : "false");
   2697    fprintf(fp, "%*sPosition result address lo: %s\n", indent, "", values->position_result_address_lo ? "true" : "false");
   2698    fprintf(fp, "%*sPosition result address hi: %s\n", indent, "", values->position_result_address_hi ? "true" : "false");
   2699    fprintf(fp, "%*sVertex ID: %s\n", indent, "", values->vertex_id ? "true" : "false");
   2700    fprintf(fp, "%*sInstance ID: %s\n", indent, "", values->instance_id ? "true" : "false");
   2701 }
   2702 
   2703 struct MALI_FRAGMENT_PRELOAD {
   2704    bool                                 pc;
   2705    bool                                 coverage;
   2706    bool                                 primitive_id;
   2707    bool                                 primitive_flags;
   2708    bool                                 fragment_position;
   2709    bool                                 sample_mask_id;
   2710 };
   2711 
   2712 #define MALI_FRAGMENT_PRELOAD_header            \
   2713    0
   2714 
   2715 static inline void
   2716 MALI_FRAGMENT_PRELOAD_print(FILE *fp, const struct MALI_FRAGMENT_PRELOAD * values, unsigned indent)
   2717 {
   2718    fprintf(fp, "%*sPC: %s\n", indent, "", values->pc ? "true" : "false");
   2719    fprintf(fp, "%*sCoverage: %s\n", indent, "", values->coverage ? "true" : "false");
   2720    fprintf(fp, "%*sPrimitive ID: %s\n", indent, "", values->primitive_id ? "true" : "false");
   2721    fprintf(fp, "%*sPrimitive flags: %s\n", indent, "", values->primitive_flags ? "true" : "false");
   2722    fprintf(fp, "%*sFragment position: %s\n", indent, "", values->fragment_position ? "true" : "false");
   2723    fprintf(fp, "%*sSample mask/ID: %s\n", indent, "", values->sample_mask_id ? "true" : "false");
   2724 }
   2725 
   2726 struct MALI_PRELOAD {
   2727    struct MALI_COMPUTE_PRELOAD          compute;
   2728    struct MALI_VERTEX_PRELOAD           vertex;
   2729    struct MALI_FRAGMENT_PRELOAD         fragment;
   2730    uint32_t                             uniform_count;
   2731 };
   2732 
   2733 #define MALI_PRELOAD_header                     \
   2734    .compute = { MALI_COMPUTE_PRELOAD_header },  \
   2735    .vertex = { MALI_VERTEX_PRELOAD_header },  \
   2736    .fragment = { MALI_FRAGMENT_PRELOAD_header }
   2737 
   2738 static inline void
   2739 MALI_PRELOAD_pack(uint32_t * restrict cl,
   2740                   const struct MALI_PRELOAD * restrict values)
   2741 {
   2742    cl[ 0] = __gen_uint(values->compute.pc, 6, 6) |
   2743             __gen_uint(values->compute.local_invocation_xy, 7, 7) |
   2744             __gen_uint(values->compute.local_invocation_z, 8, 8) |
   2745             __gen_uint(values->compute.work_group_x, 9, 9) |
   2746             __gen_uint(values->compute.work_group_y, 10, 10) |
   2747             __gen_uint(values->compute.work_group_z, 11, 11) |
   2748             __gen_uint(values->compute.global_invocation_x, 12, 12) |
   2749             __gen_uint(values->compute.global_invocation_y, 13, 13) |
   2750             __gen_uint(values->compute.global_invocation_z, 14, 14) |
   2751             __gen_uint(values->vertex.warp_limit, 0, 1) |
   2752             __gen_uint(values->vertex.pc, 6, 6) |
   2753             __gen_uint(values->vertex.position_result_address_lo, 10, 10) |
   2754             __gen_uint(values->vertex.position_result_address_hi, 11, 11) |
   2755             __gen_uint(values->vertex.vertex_id, 13, 13) |
   2756             __gen_uint(values->vertex.instance_id, 14, 14) |
   2757             __gen_uint(values->fragment.pc, 6, 6) |
   2758             __gen_uint(values->fragment.coverage, 7, 7) |
   2759             __gen_uint(values->fragment.primitive_id, 9, 9) |
   2760             __gen_uint(values->fragment.primitive_flags, 10, 10) |
   2761             __gen_uint(values->fragment.fragment_position, 11, 11) |
   2762             __gen_uint(values->fragment.sample_mask_id, 13, 13) |
   2763             __gen_uint(values->uniform_count, 15, 21);
   2764 }
   2765 
   2766 
   2767 #define MALI_PRELOAD_LENGTH 4
   2768 struct mali_preload_packed { uint32_t opaque[1]; };
   2769 static inline void
   2770 MALI_PRELOAD_unpack(const uint8_t * restrict cl,
   2771                     struct MALI_PRELOAD * restrict values)
   2772 {
   2773    if (((const uint32_t *) cl)[0] & 0xffc0003c) fprintf(stderr, "XXX: Invalid field of Preload unpacked at word 0\n");
   2774    values->compute.pc = __gen_unpack_uint(cl, 6, 6);
   2775    values->compute.local_invocation_xy = __gen_unpack_uint(cl, 7, 7);
   2776    values->compute.local_invocation_z = __gen_unpack_uint(cl, 8, 8);
   2777    values->compute.work_group_x = __gen_unpack_uint(cl, 9, 9);
   2778    values->compute.work_group_y = __gen_unpack_uint(cl, 10, 10);
   2779    values->compute.work_group_z = __gen_unpack_uint(cl, 11, 11);
   2780    values->compute.global_invocation_x = __gen_unpack_uint(cl, 12, 12);
   2781    values->compute.global_invocation_y = __gen_unpack_uint(cl, 13, 13);
   2782    values->compute.global_invocation_z = __gen_unpack_uint(cl, 14, 14);
   2783    values->vertex.warp_limit = (enum mali_warp_limit)__gen_unpack_uint(cl, 0, 1);
   2784    values->vertex.pc = __gen_unpack_uint(cl, 6, 6);
   2785    values->vertex.position_result_address_lo = __gen_unpack_uint(cl, 10, 10);
   2786    values->vertex.position_result_address_hi = __gen_unpack_uint(cl, 11, 11);
   2787    values->vertex.vertex_id = __gen_unpack_uint(cl, 13, 13);
   2788    values->vertex.instance_id = __gen_unpack_uint(cl, 14, 14);
   2789    values->fragment.pc = __gen_unpack_uint(cl, 6, 6);
   2790    values->fragment.coverage = __gen_unpack_uint(cl, 7, 7);
   2791    values->fragment.primitive_id = __gen_unpack_uint(cl, 9, 9);
   2792    values->fragment.primitive_flags = __gen_unpack_uint(cl, 10, 10);
   2793    values->fragment.fragment_position = __gen_unpack_uint(cl, 11, 11);
   2794    values->fragment.sample_mask_id = __gen_unpack_uint(cl, 13, 13);
   2795    values->uniform_count = __gen_unpack_uint(cl, 15, 21);
   2796 }
   2797 
   2798 static inline void
   2799 MALI_PRELOAD_print(FILE *fp, const struct MALI_PRELOAD * values, unsigned indent)
   2800 {
   2801    fprintf(fp, "%*sCompute:\n", indent, "");
   2802    MALI_COMPUTE_PRELOAD_print(fp, &values->compute, indent + 2);
   2803    fprintf(fp, "%*sVertex:\n", indent, "");
   2804    MALI_VERTEX_PRELOAD_print(fp, &values->vertex, indent + 2);
   2805    fprintf(fp, "%*sFragment:\n", indent, "");
   2806    MALI_FRAGMENT_PRELOAD_print(fp, &values->fragment, indent + 2);
   2807    fprintf(fp, "%*sUniform count: %u\n", indent, "", values->uniform_count);
   2808 }
   2809 
   2810 struct MALI_SHADER {
   2811    uint64_t                             shader;
   2812    uint32_t                             sampler_count;
   2813    uint32_t                             texture_count;
   2814    uint32_t                             attribute_count;
   2815    uint32_t                             varying_count;
   2816 };
   2817 
   2818 #define MALI_SHADER_header                      \
   2819    0
   2820 
   2821 static inline void
   2822 MALI_SHADER_pack(uint32_t * restrict cl,
   2823                  const struct MALI_SHADER * restrict values)
   2824 {
   2825    cl[ 0] = __gen_uint(values->shader, 0, 63);
   2826    cl[ 1] = __gen_uint(values->shader, 0, 63) >> 32;
   2827    cl[ 2] = __gen_uint(values->sampler_count, 0, 15) |
   2828             __gen_uint(values->texture_count, 16, 31);
   2829    cl[ 3] = __gen_uint(values->attribute_count, 0, 15) |
   2830             __gen_uint(values->varying_count, 16, 31);
   2831 }
   2832 
   2833 
   2834 #define MALI_SHADER_LENGTH 16
   2835 struct mali_shader_packed { uint32_t opaque[4]; };
   2836 static inline void
   2837 MALI_SHADER_unpack(const uint8_t * restrict cl,
   2838                    struct MALI_SHADER * restrict values)
   2839 {
   2840    values->shader = __gen_unpack_uint(cl, 0, 63);
   2841    values->sampler_count = __gen_unpack_uint(cl, 64, 79);
   2842    values->texture_count = __gen_unpack_uint(cl, 80, 95);
   2843    values->attribute_count = __gen_unpack_uint(cl, 96, 111);
   2844    values->varying_count = __gen_unpack_uint(cl, 112, 127);
   2845 }
   2846 
   2847 static inline void
   2848 MALI_SHADER_print(FILE *fp, const struct MALI_SHADER * values, unsigned indent)
   2849 {
   2850    fprintf(fp, "%*sShader: 0x%" PRIx64 "\n", indent, "", values->shader);
   2851    fprintf(fp, "%*sSampler count: %u\n", indent, "", values->sampler_count);
   2852    fprintf(fp, "%*sTexture count: %u\n", indent, "", values->texture_count);
   2853    fprintf(fp, "%*sAttribute count: %u\n", indent, "", values->attribute_count);
   2854    fprintf(fp, "%*sVarying count: %u\n", indent, "", values->varying_count);
   2855 }
   2856 
   2857 struct MALI_MULTISAMPLE_MISC {
   2858    uint32_t                             sample_mask;
   2859    bool                                 multisample_enable;
   2860    bool                                 multisample_late_coverage;
   2861    bool                                 evaluate_per_sample;
   2862    bool                                 fixed_function_depth_range_fixed;
   2863    bool                                 shader_depth_range_fixed;
   2864    bool                                 overdraw_alpha1;
   2865    bool                                 overdraw_alpha0;
   2866    enum mali_func                       depth_function;
   2867    bool                                 depth_write_mask;
   2868    bool                                 fixed_function_near_discard;
   2869    bool                                 fixed_function_far_discard;
   2870    bool                                 fragment_near_discard;
   2871    bool                                 fragment_far_discard;
   2872 };
   2873 
   2874 #define MALI_MULTISAMPLE_MISC_header            \
   2875    0
   2876 
   2877 static inline void
   2878 MALI_MULTISAMPLE_MISC_pack(uint32_t * restrict cl,
   2879                            const struct MALI_MULTISAMPLE_MISC * restrict values)
   2880 {
   2881    cl[ 0] = __gen_uint(values->sample_mask, 0, 15) |
   2882             __gen_uint(values->multisample_enable, 16, 16) |
   2883             __gen_uint(values->multisample_late_coverage, 17, 17) |
   2884             __gen_uint(values->evaluate_per_sample, 18, 18) |
   2885             __gen_uint(values->fixed_function_depth_range_fixed, 19, 19) |
   2886             __gen_uint(values->shader_depth_range_fixed, 20, 20) |
   2887             __gen_uint(values->overdraw_alpha1, 22, 22) |
   2888             __gen_uint(values->overdraw_alpha0, 23, 23) |
   2889             __gen_uint(values->depth_function, 24, 26) |
   2890             __gen_uint(values->depth_write_mask, 27, 27) |
   2891             __gen_uint(values->fixed_function_near_discard, 28, 28) |
   2892             __gen_uint(values->fixed_function_far_discard, 29, 29) |
   2893             __gen_uint(values->fragment_near_discard, 30, 30) |
   2894             __gen_uint(values->fragment_far_discard, 31, 31);
   2895 }
   2896 
   2897 
   2898 #define MALI_MULTISAMPLE_MISC_LENGTH 4
   2899 struct mali_multisample_misc_packed { uint32_t opaque[1]; };
   2900 static inline void
   2901 MALI_MULTISAMPLE_MISC_unpack(const uint8_t * restrict cl,
   2902                              struct MALI_MULTISAMPLE_MISC * restrict values)
   2903 {
   2904    if (((const uint32_t *) cl)[0] & 0x200000) fprintf(stderr, "XXX: Invalid field of Multisample, Misc unpacked at word 0\n");
   2905    values->sample_mask = __gen_unpack_uint(cl, 0, 15);
   2906    values->multisample_enable = __gen_unpack_uint(cl, 16, 16);
   2907    values->multisample_late_coverage = __gen_unpack_uint(cl, 17, 17);
   2908    values->evaluate_per_sample = __gen_unpack_uint(cl, 18, 18);
   2909    values->fixed_function_depth_range_fixed = __gen_unpack_uint(cl, 19, 19);
   2910    values->shader_depth_range_fixed = __gen_unpack_uint(cl, 20, 20);
   2911    values->overdraw_alpha1 = __gen_unpack_uint(cl, 22, 22);
   2912    values->overdraw_alpha0 = __gen_unpack_uint(cl, 23, 23);
   2913    values->depth_function = (enum mali_func)__gen_unpack_uint(cl, 24, 26);
   2914    values->depth_write_mask = __gen_unpack_uint(cl, 27, 27);
   2915    values->fixed_function_near_discard = __gen_unpack_uint(cl, 28, 28);
   2916    values->fixed_function_far_discard = __gen_unpack_uint(cl, 29, 29);
   2917    values->fragment_near_discard = __gen_unpack_uint(cl, 30, 30);
   2918    values->fragment_far_discard = __gen_unpack_uint(cl, 31, 31);
   2919 }
   2920 
   2921 static inline void
   2922 MALI_MULTISAMPLE_MISC_print(FILE *fp, const struct MALI_MULTISAMPLE_MISC * values, unsigned indent)
   2923 {
   2924    fprintf(fp, "%*sSample mask: %u\n", indent, "", values->sample_mask);
   2925    fprintf(fp, "%*sMultisample enable: %s\n", indent, "", values->multisample_enable ? "true" : "false");
   2926    fprintf(fp, "%*sMultisample late coverage: %s\n", indent, "", values->multisample_late_coverage ? "true" : "false");
   2927    fprintf(fp, "%*sEvaluate per-sample: %s\n", indent, "", values->evaluate_per_sample ? "true" : "false");
   2928    fprintf(fp, "%*sFixed-function depth range fixed: %s\n", indent, "", values->fixed_function_depth_range_fixed ? "true" : "false");
   2929    fprintf(fp, "%*sShader depth range fixed: %s\n", indent, "", values->shader_depth_range_fixed ? "true" : "false");
   2930    fprintf(fp, "%*sOverdraw alpha1: %s\n", indent, "", values->overdraw_alpha1 ? "true" : "false");
   2931    fprintf(fp, "%*sOverdraw alpha0: %s\n", indent, "", values->overdraw_alpha0 ? "true" : "false");
   2932    fprintf(fp, "%*sDepth function: %s\n", indent, "", mali_func_as_str(values->depth_function));
   2933    fprintf(fp, "%*sDepth write mask: %s\n", indent, "", values->depth_write_mask ? "true" : "false");
   2934    fprintf(fp, "%*sFixed-function near discard: %s\n", indent, "", values->fixed_function_near_discard ? "true" : "false");
   2935    fprintf(fp, "%*sFixed-function far discard: %s\n", indent, "", values->fixed_function_far_discard ? "true" : "false");
   2936    fprintf(fp, "%*sFragment near discard: %s\n", indent, "", values->fragment_near_discard ? "true" : "false");
   2937    fprintf(fp, "%*sFragment far discard: %s\n", indent, "", values->fragment_far_discard ? "true" : "false");
   2938 }
   2939 
   2940 struct MALI_STENCIL_MASK_MISC {
   2941    uint32_t                             stencil_mask_front;
   2942    uint32_t                             stencil_mask_back;
   2943    bool                                 stencil_enable;
   2944    bool                                 alpha_to_coverage;
   2945    bool                                 alpha_to_coverage_invert;
   2946    enum mali_func                       alpha_test_compare_function;
   2947    bool                                 force_seamless_cubemaps;
   2948    bool                                 depth_range_1;
   2949    bool                                 depth_range_2;
   2950    bool                                 single_sampled_lines;
   2951    bool                                 point_snap;
   2952 };
   2953 
   2954 #define MALI_STENCIL_MASK_MISC_header           \
   2955    0
   2956 
   2957 static inline void
   2958 MALI_STENCIL_MASK_MISC_pack(uint32_t * restrict cl,
   2959                             const struct MALI_STENCIL_MASK_MISC * restrict values)
   2960 {
   2961    cl[ 0] = __gen_uint(values->stencil_mask_front, 0, 7) |
   2962             __gen_uint(values->stencil_mask_back, 8, 15) |
   2963             __gen_uint(values->stencil_enable, 16, 16) |
   2964             __gen_uint(values->alpha_to_coverage, 17, 17) |
   2965             __gen_uint(values->alpha_to_coverage_invert, 18, 18) |
   2966             __gen_uint(values->alpha_test_compare_function, 21, 23) |
   2967             __gen_uint(values->force_seamless_cubemaps, 26, 26) |
   2968             __gen_uint(values->depth_range_1, 28, 28) |
   2969             __gen_uint(values->depth_range_2, 29, 29) |
   2970             __gen_uint(values->single_sampled_lines, 30, 30) |
   2971             __gen_uint(values->point_snap, 31, 31);
   2972 }
   2973 
   2974 
   2975 #define MALI_STENCIL_MASK_MISC_LENGTH 4
   2976 struct mali_stencil_mask_misc_packed { uint32_t opaque[1]; };
   2977 static inline void
   2978 MALI_STENCIL_MASK_MISC_unpack(const uint8_t * restrict cl,
   2979                               struct MALI_STENCIL_MASK_MISC * restrict values)
   2980 {
   2981    if (((const uint32_t *) cl)[0] & 0xb180000) fprintf(stderr, "XXX: Invalid field of Stencil Mask, Misc unpacked at word 0\n");
   2982    values->stencil_mask_front = __gen_unpack_uint(cl, 0, 7);
   2983    values->stencil_mask_back = __gen_unpack_uint(cl, 8, 15);
   2984    values->stencil_enable = __gen_unpack_uint(cl, 16, 16);
   2985    values->alpha_to_coverage = __gen_unpack_uint(cl, 17, 17);
   2986    values->alpha_to_coverage_invert = __gen_unpack_uint(cl, 18, 18);
   2987    values->alpha_test_compare_function = (enum mali_func)__gen_unpack_uint(cl, 21, 23);
   2988    values->force_seamless_cubemaps = __gen_unpack_uint(cl, 26, 26);
   2989    values->depth_range_1 = __gen_unpack_uint(cl, 28, 28);
   2990    values->depth_range_2 = __gen_unpack_uint(cl, 29, 29);
   2991    values->single_sampled_lines = __gen_unpack_uint(cl, 30, 30);
   2992    values->point_snap = __gen_unpack_uint(cl, 31, 31);
   2993 }
   2994 
   2995 static inline void
   2996 MALI_STENCIL_MASK_MISC_print(FILE *fp, const struct MALI_STENCIL_MASK_MISC * values, unsigned indent)
   2997 {
   2998    fprintf(fp, "%*sStencil mask front: %u\n", indent, "", values->stencil_mask_front);
   2999    fprintf(fp, "%*sStencil mask back: %u\n", indent, "", values->stencil_mask_back);
   3000    fprintf(fp, "%*sStencil enable: %s\n", indent, "", values->stencil_enable ? "true" : "false");
   3001    fprintf(fp, "%*sAlpha-to-coverage: %s\n", indent, "", values->alpha_to_coverage ? "true" : "false");
   3002    fprintf(fp, "%*sAlpha-to-coverage Invert: %s\n", indent, "", values->alpha_to_coverage_invert ? "true" : "false");
   3003    fprintf(fp, "%*sAlpha test compare function: %s\n", indent, "", mali_func_as_str(values->alpha_test_compare_function));
   3004    fprintf(fp, "%*sForce seamless cubemaps: %s\n", indent, "", values->force_seamless_cubemaps ? "true" : "false");
   3005    fprintf(fp, "%*sDepth Range 1: %s\n", indent, "", values->depth_range_1 ? "true" : "false");
   3006    fprintf(fp, "%*sDepth Range 2: %s\n", indent, "", values->depth_range_2 ? "true" : "false");
   3007    fprintf(fp, "%*sSingle-sampled lines: %s\n", indent, "", values->single_sampled_lines ? "true" : "false");
   3008    fprintf(fp, "%*sPoint snap: %s\n", indent, "", values->point_snap ? "true" : "false");
   3009 }
   3010 
   3011 struct MALI_STENCIL {
   3012    uint32_t                             reference_value;
   3013    uint32_t                             mask;
   3014    enum mali_func                       compare_function;
   3015    enum mali_stencil_op                 stencil_fail;
   3016    enum mali_stencil_op                 depth_fail;
   3017    enum mali_stencil_op                 depth_pass;
   3018 };
   3019 
   3020 #define MALI_STENCIL_header                     \
   3021    0
   3022 
   3023 static inline void
   3024 MALI_STENCIL_pack(uint32_t * restrict cl,
   3025                   const struct MALI_STENCIL * restrict values)
   3026 {
   3027    cl[ 0] = __gen_uint(values->reference_value, 0, 7) |
   3028             __gen_uint(values->mask, 8, 15) |
   3029             __gen_uint(values->compare_function, 16, 18) |
   3030             __gen_uint(values->stencil_fail, 19, 21) |
   3031             __gen_uint(values->depth_fail, 22, 24) |
   3032             __gen_uint(values->depth_pass, 25, 27);
   3033 }
   3034 
   3035 
   3036 #define MALI_STENCIL_LENGTH 4
   3037 struct mali_stencil_packed { uint32_t opaque[1]; };
   3038 static inline void
   3039 MALI_STENCIL_unpack(const uint8_t * restrict cl,
   3040                     struct MALI_STENCIL * restrict values)
   3041 {
   3042    if (((const uint32_t *) cl)[0] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Stencil unpacked at word 0\n");
   3043    values->reference_value = __gen_unpack_uint(cl, 0, 7);
   3044    values->mask = __gen_unpack_uint(cl, 8, 15);
   3045    values->compare_function = (enum mali_func)__gen_unpack_uint(cl, 16, 18);
   3046    values->stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 19, 21);
   3047    values->depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 22, 24);
   3048    values->depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 25, 27);
   3049 }
   3050 
   3051 static inline void
   3052 MALI_STENCIL_print(FILE *fp, const struct MALI_STENCIL * values, unsigned indent)
   3053 {
   3054    fprintf(fp, "%*sReference Value: %u\n", indent, "", values->reference_value);
   3055    fprintf(fp, "%*sMask: %u\n", indent, "", values->mask);
   3056    fprintf(fp, "%*sCompare Function: %s\n", indent, "", mali_func_as_str(values->compare_function));
   3057    fprintf(fp, "%*sStencil Fail: %s\n", indent, "", mali_stencil_op_as_str(values->stencil_fail));
   3058    fprintf(fp, "%*sDepth Fail: %s\n", indent, "", mali_stencil_op_as_str(values->depth_fail));
   3059    fprintf(fp, "%*sDepth Pass: %s\n", indent, "", mali_stencil_op_as_str(values->depth_pass));
   3060 }
   3061 
   3062 struct MALI_LD_VAR_PRELOAD {
   3063    uint32_t                             varying_index;
   3064    enum mali_message_preload_register_format register_format;
   3065    uint32_t                             num_components;
   3066 };
   3067 
   3068 #define MALI_LD_VAR_PRELOAD_header              \
   3069    .num_components = 1
   3070 
   3071 static inline void
   3072 MALI_LD_VAR_PRELOAD_print(FILE *fp, const struct MALI_LD_VAR_PRELOAD * values, unsigned indent)
   3073 {
   3074    fprintf(fp, "%*sVarying Index: %u\n", indent, "", values->varying_index);
   3075    fprintf(fp, "%*sRegister Format: %s\n", indent, "", mali_message_preload_register_format_as_str(values->register_format));
   3076    fprintf(fp, "%*sNum Components: %u\n", indent, "", values->num_components);
   3077 }
   3078 
   3079 struct MALI_VAR_TEX_PRELOAD {
   3080    uint32_t                             varying_index;
   3081    uint32_t                             sampler_index;
   3082    enum mali_message_preload_register_format register_format;
   3083    bool                                 skip;
   3084    bool                                 zero_lod;
   3085 };
   3086 
   3087 #define MALI_VAR_TEX_PRELOAD_header             \
   3088    0
   3089 
   3090 static inline void
   3091 MALI_VAR_TEX_PRELOAD_print(FILE *fp, const struct MALI_VAR_TEX_PRELOAD * values, unsigned indent)
   3092 {
   3093    fprintf(fp, "%*sVarying Index: %u\n", indent, "", values->varying_index);
   3094    fprintf(fp, "%*sSampler Index: %u\n", indent, "", values->sampler_index);
   3095    fprintf(fp, "%*sRegister Format: %s\n", indent, "", mali_message_preload_register_format_as_str(values->register_format));
   3096    fprintf(fp, "%*sSkip: %s\n", indent, "", values->skip ? "true" : "false");
   3097    fprintf(fp, "%*sZero LOD: %s\n", indent, "", values->zero_lod ? "true" : "false");
   3098 }
   3099 
   3100 struct MALI_MESSAGE_PRELOAD {
   3101    enum mali_message_type               type;
   3102    struct MALI_LD_VAR_PRELOAD           ld_var;
   3103    struct MALI_VAR_TEX_PRELOAD          var_tex;
   3104 };
   3105 
   3106 #define MALI_MESSAGE_PRELOAD_header             \
   3107    .ld_var = { MALI_LD_VAR_PRELOAD_header },  \
   3108    .var_tex = { MALI_VAR_TEX_PRELOAD_header }
   3109 
   3110 static inline void
   3111 MALI_MESSAGE_PRELOAD_pack(uint32_t * restrict cl,
   3112                           const struct MALI_MESSAGE_PRELOAD * restrict values)
   3113 {
   3114    cl[ 0] = __gen_uint(values->type, 0, 3) |
   3115             __gen_uint(values->ld_var.varying_index, 4, 8) |
   3116             __gen_uint(values->ld_var.register_format, 9, 10) |
   3117             __gen_uint(values->ld_var.num_components - 1, 11, 12) |
   3118             __gen_uint(values->var_tex.varying_index, 4, 6) |
   3119             __gen_uint(values->var_tex.sampler_index, 7, 8) |
   3120             __gen_uint(values->var_tex.register_format, 9, 10) |
   3121             __gen_uint(values->var_tex.skip, 14, 14) |
   3122             __gen_uint(values->var_tex.zero_lod, 15, 15);
   3123 }
   3124 
   3125 
   3126 #define MALI_MESSAGE_PRELOAD_LENGTH 4
   3127 struct mali_message_preload_packed { uint32_t opaque[1]; };
   3128 static inline void
   3129 MALI_MESSAGE_PRELOAD_unpack(const uint8_t * restrict cl,
   3130                             struct MALI_MESSAGE_PRELOAD * restrict values)
   3131 {
   3132    if (((const uint32_t *) cl)[0] & 0xffff2000) fprintf(stderr, "XXX: Invalid field of Message Preload unpacked at word 0\n");
   3133    values->type = (enum mali_message_type)__gen_unpack_uint(cl, 0, 3);
   3134    values->ld_var.varying_index = __gen_unpack_uint(cl, 4, 8);
   3135    values->ld_var.register_format = (enum mali_message_preload_register_format)__gen_unpack_uint(cl, 9, 10);
   3136    values->ld_var.num_components = __gen_unpack_uint(cl, 11, 12) + 1;
   3137    values->var_tex.varying_index = __gen_unpack_uint(cl, 4, 6);
   3138    values->var_tex.sampler_index = __gen_unpack_uint(cl, 7, 8);
   3139    values->var_tex.register_format = (enum mali_message_preload_register_format)__gen_unpack_uint(cl, 9, 10);
   3140    values->var_tex.skip = __gen_unpack_uint(cl, 14, 14);
   3141    values->var_tex.zero_lod = __gen_unpack_uint(cl, 15, 15);
   3142 }
   3143 
   3144 static inline void
   3145 MALI_MESSAGE_PRELOAD_print(FILE *fp, const struct MALI_MESSAGE_PRELOAD * values, unsigned indent)
   3146 {
   3147    fprintf(fp, "%*sType: %s\n", indent, "", mali_message_type_as_str(values->type));
   3148    fprintf(fp, "%*sLD_VAR:\n", indent, "");
   3149    MALI_LD_VAR_PRELOAD_print(fp, &values->ld_var, indent + 2);
   3150    fprintf(fp, "%*sVAR_TEX:\n", indent, "");
   3151    MALI_VAR_TEX_PRELOAD_print(fp, &values->var_tex, indent + 2);
   3152 }
   3153 
   3154 struct MALI_RENDERER_STATE {
   3155    struct MALI_SHADER                   shader;
   3156    struct MALI_RENDERER_PROPERTIES      properties;
   3157    float                                depth_units;
   3158    float                                depth_factor;
   3159    float                                depth_bias_clamp;
   3160    struct MALI_MULTISAMPLE_MISC         multisample_misc;
   3161    struct MALI_STENCIL_MASK_MISC        stencil_mask_misc;
   3162    struct MALI_STENCIL                  stencil_front;
   3163    struct MALI_STENCIL                  stencil_back;
   3164    struct MALI_PRELOAD                  preload;
   3165    float                                alpha_reference;
   3166    uint32_t                             thread_balancing;
   3167    struct MALI_PRELOAD                  secondary_preload;
   3168    uint64_t                             secondary_shader;
   3169    uint32_t                             message_preload_1;
   3170    uint32_t                             message_preload_2;
   3171 };
   3172 
   3173 #define MALI_RENDERER_STATE_header              \
   3174    .shader = { MALI_SHADER_header },  \
   3175    .properties = { MALI_RENDERER_PROPERTIES_header },  \
   3176    .multisample_misc = { MALI_MULTISAMPLE_MISC_header },  \
   3177    .stencil_mask_misc = { MALI_STENCIL_MASK_MISC_header },  \
   3178    .stencil_front = { MALI_STENCIL_header },  \
   3179    .stencil_back = { MALI_STENCIL_header },  \
   3180    .preload = { MALI_PRELOAD_header },  \
   3181    .secondary_preload = { MALI_PRELOAD_header }
   3182 
   3183 static inline void
   3184 MALI_RENDERER_STATE_pack(uint32_t * restrict cl,
   3185                          const struct MALI_RENDERER_STATE * restrict values)
   3186 {
   3187    cl[ 0] = __gen_uint(values->shader.shader, 0, 63);
   3188    cl[ 1] = __gen_uint(values->shader.shader, 0, 63) >> 32;
   3189    cl[ 2] = __gen_uint(values->shader.sampler_count, 0, 15) |
   3190             __gen_uint(values->shader.texture_count, 16, 31);
   3191    cl[ 3] = __gen_uint(values->shader.attribute_count, 0, 15) |
   3192             __gen_uint(values->shader.varying_count, 16, 31);
   3193    cl[ 4] = __gen_uint(values->properties.uniform_buffer_count, 0, 7) |
   3194             __gen_uint(values->properties.depth_source, 8, 9) |
   3195             __gen_uint(values->properties.shader_contains_barrier, 11, 11) |
   3196             __gen_uint(values->properties.shader_register_allocation, 12, 13) |
   3197             __gen_uint(values->properties.secondary_shader_register_allocation, 14, 15) |
   3198             __gen_uint(values->properties.shader_modifies_coverage, 16, 16) |
   3199             __gen_uint(values->properties.allow_forward_pixel_to_kill, 19, 19) |
   3200             __gen_uint(values->properties.allow_forward_pixel_to_be_killed, 20, 20) |
   3201             __gen_uint(values->properties.pixel_kill_operation, 21, 22) |
   3202             __gen_uint(values->properties.zs_update_operation, 23, 24) |
   3203             __gen_uint(values->properties.point_sprite_coord_origin_max_y, 27, 27) |
   3204             __gen_uint(values->properties.stencil_from_shader, 28, 28) |
   3205             __gen_uint(values->properties.shader_wait_dependency_6, 30, 30) |
   3206             __gen_uint(values->properties.shader_wait_dependency_7, 31, 31);
   3207    cl[ 5] = __gen_uint(fui(values->depth_units), 0, 32);
   3208    cl[ 6] = __gen_uint(fui(values->depth_factor), 0, 32);
   3209    cl[ 7] = __gen_uint(fui(values->depth_bias_clamp), 0, 32);
   3210    cl[ 8] = __gen_uint(values->multisample_misc.sample_mask, 0, 15) |
   3211             __gen_uint(values->multisample_misc.multisample_enable, 16, 16) |
   3212             __gen_uint(values->multisample_misc.multisample_late_coverage, 17, 17) |
   3213             __gen_uint(values->multisample_misc.evaluate_per_sample, 18, 18) |
   3214             __gen_uint(values->multisample_misc.fixed_function_depth_range_fixed, 19, 19) |
   3215             __gen_uint(values->multisample_misc.shader_depth_range_fixed, 20, 20) |
   3216             __gen_uint(values->multisample_misc.overdraw_alpha1, 22, 22) |
   3217             __gen_uint(values->multisample_misc.overdraw_alpha0, 23, 23) |
   3218             __gen_uint(values->multisample_misc.depth_function, 24, 26) |
   3219             __gen_uint(values->multisample_misc.depth_write_mask, 27, 27) |
   3220             __gen_uint(values->multisample_misc.fixed_function_near_discard, 28, 28) |
   3221             __gen_uint(values->multisample_misc.fixed_function_far_discard, 29, 29) |
   3222             __gen_uint(values->multisample_misc.fragment_near_discard, 30, 30) |
   3223             __gen_uint(values->multisample_misc.fragment_far_discard, 31, 31);
   3224    cl[ 9] = __gen_uint(values->stencil_mask_misc.stencil_mask_front, 0, 7) |
   3225             __gen_uint(values->stencil_mask_misc.stencil_mask_back, 8, 15) |
   3226             __gen_uint(values->stencil_mask_misc.stencil_enable, 16, 16) |
   3227             __gen_uint(values->stencil_mask_misc.alpha_to_coverage, 17, 17) |
   3228             __gen_uint(values->stencil_mask_misc.alpha_to_coverage_invert, 18, 18) |
   3229             __gen_uint(values->stencil_mask_misc.alpha_test_compare_function, 21, 23) |
   3230             __gen_uint(values->stencil_mask_misc.force_seamless_cubemaps, 26, 26) |
   3231             __gen_uint(values->stencil_mask_misc.depth_range_1, 28, 28) |
   3232             __gen_uint(values->stencil_mask_misc.depth_range_2, 29, 29) |
   3233             __gen_uint(values->stencil_mask_misc.single_sampled_lines, 30, 30) |
   3234             __gen_uint(values->stencil_mask_misc.point_snap, 31, 31);
   3235    cl[10] = __gen_uint(values->stencil_front.reference_value, 0, 7) |
   3236             __gen_uint(values->stencil_front.mask, 8, 15) |
   3237             __gen_uint(values->stencil_front.compare_function, 16, 18) |
   3238             __gen_uint(values->stencil_front.stencil_fail, 19, 21) |
   3239             __gen_uint(values->stencil_front.depth_fail, 22, 24) |
   3240             __gen_uint(values->stencil_front.depth_pass, 25, 27);
   3241    cl[11] = __gen_uint(values->stencil_back.reference_value, 0, 7) |
   3242             __gen_uint(values->stencil_back.mask, 8, 15) |
   3243             __gen_uint(values->stencil_back.compare_function, 16, 18) |
   3244             __gen_uint(values->stencil_back.stencil_fail, 19, 21) |
   3245             __gen_uint(values->stencil_back.depth_fail, 22, 24) |
   3246             __gen_uint(values->stencil_back.depth_pass, 25, 27);
   3247    cl[12] = __gen_uint(values->preload.compute.pc, 6, 6) |
   3248             __gen_uint(values->preload.compute.local_invocation_xy, 7, 7) |
   3249             __gen_uint(values->preload.compute.local_invocation_z, 8, 8) |
   3250             __gen_uint(values->preload.compute.work_group_x, 9, 9) |
   3251             __gen_uint(values->preload.compute.work_group_y, 10, 10) |
   3252             __gen_uint(values->preload.compute.work_group_z, 11, 11) |
   3253             __gen_uint(values->preload.compute.global_invocation_x, 12, 12) |
   3254             __gen_uint(values->preload.compute.global_invocation_y, 13, 13) |
   3255             __gen_uint(values->preload.compute.global_invocation_z, 14, 14) |
   3256             __gen_uint(values->preload.vertex.warp_limit, 0, 1) |
   3257             __gen_uint(values->preload.vertex.pc, 6, 6) |
   3258             __gen_uint(values->preload.vertex.position_result_address_lo, 10, 10) |
   3259             __gen_uint(values->preload.vertex.position_result_address_hi, 11, 11) |
   3260             __gen_uint(values->preload.vertex.vertex_id, 13, 13) |
   3261             __gen_uint(values->preload.vertex.instance_id, 14, 14) |
   3262             __gen_uint(values->preload.fragment.pc, 6, 6) |
   3263             __gen_uint(values->preload.fragment.coverage, 7, 7) |
   3264             __gen_uint(values->preload.fragment.primitive_id, 9, 9) |
   3265             __gen_uint(values->preload.fragment.primitive_flags, 10, 10) |
   3266             __gen_uint(values->preload.fragment.fragment_position, 11, 11) |
   3267             __gen_uint(values->preload.fragment.sample_mask_id, 13, 13) |
   3268             __gen_uint(values->preload.uniform_count, 15, 21) |
   3269             __gen_uint(fui(values->alpha_reference), 0, 32);
   3270    cl[13] = __gen_uint(values->thread_balancing, 0, 15) |
   3271             __gen_uint(values->secondary_preload.compute.pc, 6, 6) |
   3272             __gen_uint(values->secondary_preload.compute.local_invocation_xy, 7, 7) |
   3273             __gen_uint(values->secondary_preload.compute.local_invocation_z, 8, 8) |
   3274             __gen_uint(values->secondary_preload.compute.work_group_x, 9, 9) |
   3275             __gen_uint(values->secondary_preload.compute.work_group_y, 10, 10) |
   3276             __gen_uint(values->secondary_preload.compute.work_group_z, 11, 11) |
   3277             __gen_uint(values->secondary_preload.compute.global_invocation_x, 12, 12) |
   3278             __gen_uint(values->secondary_preload.compute.global_invocation_y, 13, 13) |
   3279             __gen_uint(values->secondary_preload.compute.global_invocation_z, 14, 14) |
   3280             __gen_uint(values->secondary_preload.vertex.warp_limit, 0, 1) |
   3281             __gen_uint(values->secondary_preload.vertex.pc, 6, 6) |
   3282             __gen_uint(values->secondary_preload.vertex.position_result_address_lo, 10, 10) |
   3283             __gen_uint(values->secondary_preload.vertex.position_result_address_hi, 11, 11) |
   3284             __gen_uint(values->secondary_preload.vertex.vertex_id, 13, 13) |
   3285             __gen_uint(values->secondary_preload.vertex.instance_id, 14, 14) |
   3286             __gen_uint(values->secondary_preload.fragment.pc, 6, 6) |
   3287             __gen_uint(values->secondary_preload.fragment.coverage, 7, 7) |
   3288             __gen_uint(values->secondary_preload.fragment.primitive_id, 9, 9) |
   3289             __gen_uint(values->secondary_preload.fragment.primitive_flags, 10, 10) |
   3290             __gen_uint(values->secondary_preload.fragment.fragment_position, 11, 11) |
   3291             __gen_uint(values->secondary_preload.fragment.sample_mask_id, 13, 13) |
   3292             __gen_uint(values->secondary_preload.uniform_count, 15, 21);
   3293    cl[14] = __gen_uint(values->secondary_shader, 0, 63);
   3294    cl[15] = __gen_uint(values->secondary_shader, 0, 63) >> 32 |
   3295             __gen_uint(values->message_preload_1, 0, 15) |
   3296             __gen_uint(values->message_preload_2, 16, 31);
   3297 }
   3298 
   3299 
   3300 #define MALI_RENDERER_STATE_LENGTH 64
   3301 #define MALI_RENDERER_STATE_ALIGN 64
   3302 struct mali_renderer_state_packed { uint32_t opaque[16]; };
   3303 static inline void
   3304 MALI_RENDERER_STATE_unpack(const uint8_t * restrict cl,
   3305                            struct MALI_RENDERER_STATE * restrict values)
   3306 {
   3307    if (((const uint32_t *) cl)[4] & 0x26060400) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 4\n");
   3308    if (((const uint32_t *) cl)[8] & 0x200000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 8\n");
   3309    if (((const uint32_t *) cl)[9] & 0xb180000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 9\n");
   3310    if (((const uint32_t *) cl)[10] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 10\n");
   3311    if (((const uint32_t *) cl)[11] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 11\n");
   3312    if (((const uint32_t *) cl)[13] & 0xffc00000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 13\n");
   3313    values->shader.shader = __gen_unpack_uint(cl, 0, 63);
   3314    values->shader.sampler_count = __gen_unpack_uint(cl, 64, 79);
   3315    values->shader.texture_count = __gen_unpack_uint(cl, 80, 95);
   3316    values->shader.attribute_count = __gen_unpack_uint(cl, 96, 111);
   3317    values->shader.varying_count = __gen_unpack_uint(cl, 112, 127);
   3318    values->properties.uniform_buffer_count = __gen_unpack_uint(cl, 128, 135);
   3319    values->properties.depth_source = (enum mali_depth_source)__gen_unpack_uint(cl, 136, 137);
   3320    values->properties.shader_contains_barrier = __gen_unpack_uint(cl, 139, 139);
   3321    values->properties.shader_register_allocation = (enum mali_shader_register_allocation)__gen_unpack_uint(cl, 140, 141);
   3322    values->properties.secondary_shader_register_allocation = (enum mali_shader_register_allocation)__gen_unpack_uint(cl, 142, 143);
   3323    values->properties.shader_modifies_coverage = __gen_unpack_uint(cl, 144, 144);
   3324    values->properties.allow_forward_pixel_to_kill = __gen_unpack_uint(cl, 147, 147);
   3325    values->properties.allow_forward_pixel_to_be_killed = __gen_unpack_uint(cl, 148, 148);
   3326    values->properties.pixel_kill_operation = (enum mali_pixel_kill)__gen_unpack_uint(cl, 149, 150);
   3327    values->properties.zs_update_operation = (enum mali_pixel_kill)__gen_unpack_uint(cl, 151, 152);
   3328    values->properties.point_sprite_coord_origin_max_y = __gen_unpack_uint(cl, 155, 155);
   3329    values->properties.stencil_from_shader = __gen_unpack_uint(cl, 156, 156);
   3330    values->properties.shader_wait_dependency_6 = __gen_unpack_uint(cl, 158, 158);
   3331    values->properties.shader_wait_dependency_7 = __gen_unpack_uint(cl, 159, 159);
   3332    values->depth_units = __gen_unpack_float(cl, 160, 191);
   3333    values->depth_factor = __gen_unpack_float(cl, 192, 223);
   3334    values->depth_bias_clamp = __gen_unpack_float(cl, 224, 255);
   3335    values->multisample_misc.sample_mask = __gen_unpack_uint(cl, 256, 271);
   3336    values->multisample_misc.multisample_enable = __gen_unpack_uint(cl, 272, 272);
   3337    values->multisample_misc.multisample_late_coverage = __gen_unpack_uint(cl, 273, 273);
   3338    values->multisample_misc.evaluate_per_sample = __gen_unpack_uint(cl, 274, 274);
   3339    values->multisample_misc.fixed_function_depth_range_fixed = __gen_unpack_uint(cl, 275, 275);
   3340    values->multisample_misc.shader_depth_range_fixed = __gen_unpack_uint(cl, 276, 276);
   3341    values->multisample_misc.overdraw_alpha1 = __gen_unpack_uint(cl, 278, 278);
   3342    values->multisample_misc.overdraw_alpha0 = __gen_unpack_uint(cl, 279, 279);
   3343    values->multisample_misc.depth_function = (enum mali_func)__gen_unpack_uint(cl, 280, 282);
   3344    values->multisample_misc.depth_write_mask = __gen_unpack_uint(cl, 283, 283);
   3345    values->multisample_misc.fixed_function_near_discard = __gen_unpack_uint(cl, 284, 284);
   3346    values->multisample_misc.fixed_function_far_discard = __gen_unpack_uint(cl, 285, 285);
   3347    values->multisample_misc.fragment_near_discard = __gen_unpack_uint(cl, 286, 286);
   3348    values->multisample_misc.fragment_far_discard = __gen_unpack_uint(cl, 287, 287);
   3349    values->stencil_mask_misc.stencil_mask_front = __gen_unpack_uint(cl, 288, 295);
   3350    values->stencil_mask_misc.stencil_mask_back = __gen_unpack_uint(cl, 296, 303);
   3351    values->stencil_mask_misc.stencil_enable = __gen_unpack_uint(cl, 304, 304);
   3352    values->stencil_mask_misc.alpha_to_coverage = __gen_unpack_uint(cl, 305, 305);
   3353    values->stencil_mask_misc.alpha_to_coverage_invert = __gen_unpack_uint(cl, 306, 306);
   3354    values->stencil_mask_misc.alpha_test_compare_function = (enum mali_func)__gen_unpack_uint(cl, 309, 311);
   3355    values->stencil_mask_misc.force_seamless_cubemaps = __gen_unpack_uint(cl, 314, 314);
   3356    values->stencil_mask_misc.depth_range_1 = __gen_unpack_uint(cl, 316, 316);
   3357    values->stencil_mask_misc.depth_range_2 = __gen_unpack_uint(cl, 317, 317);
   3358    values->stencil_mask_misc.single_sampled_lines = __gen_unpack_uint(cl, 318, 318);
   3359    values->stencil_mask_misc.point_snap = __gen_unpack_uint(cl, 319, 319);
   3360    values->stencil_front.reference_value = __gen_unpack_uint(cl, 320, 327);
   3361    values->stencil_front.mask = __gen_unpack_uint(cl, 328, 335);
   3362    values->stencil_front.compare_function = (enum mali_func)__gen_unpack_uint(cl, 336, 338);
   3363    values->stencil_front.stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 339, 341);
   3364    values->stencil_front.depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 342, 344);
   3365    values->stencil_front.depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 345, 347);
   3366    values->stencil_back.reference_value = __gen_unpack_uint(cl, 352, 359);
   3367    values->stencil_back.mask = __gen_unpack_uint(cl, 360, 367);
   3368    values->stencil_back.compare_function = (enum mali_func)__gen_unpack_uint(cl, 368, 370);
   3369    values->stencil_back.stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 371, 373);
   3370    values->stencil_back.depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 374, 376);
   3371    values->stencil_back.depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 377, 379);
   3372    values->preload.compute.pc = __gen_unpack_uint(cl, 390, 390);
   3373    values->preload.compute.local_invocation_xy = __gen_unpack_uint(cl, 391, 391);
   3374    values->preload.compute.local_invocation_z = __gen_unpack_uint(cl, 392, 392);
   3375    values->preload.compute.work_group_x = __gen_unpack_uint(cl, 393, 393);
   3376    values->preload.compute.work_group_y = __gen_unpack_uint(cl, 394, 394);
   3377    values->preload.compute.work_group_z = __gen_unpack_uint(cl, 395, 395);
   3378    values->preload.compute.global_invocation_x = __gen_unpack_uint(cl, 396, 396);
   3379    values->preload.compute.global_invocation_y = __gen_unpack_uint(cl, 397, 397);
   3380    values->preload.compute.global_invocation_z = __gen_unpack_uint(cl, 398, 398);
   3381    values->preload.vertex.warp_limit = (enum mali_warp_limit)__gen_unpack_uint(cl, 384, 385);
   3382    values->preload.vertex.pc = __gen_unpack_uint(cl, 390, 390);
   3383    values->preload.vertex.position_result_address_lo = __gen_unpack_uint(cl, 394, 394);
   3384    values->preload.vertex.position_result_address_hi = __gen_unpack_uint(cl, 395, 395);
   3385    values->preload.vertex.vertex_id = __gen_unpack_uint(cl, 397, 397);
   3386    values->preload.vertex.instance_id = __gen_unpack_uint(cl, 398, 398);
   3387    values->preload.fragment.pc = __gen_unpack_uint(cl, 390, 390);
   3388    values->preload.fragment.coverage = __gen_unpack_uint(cl, 391, 391);
   3389    values->preload.fragment.primitive_id = __gen_unpack_uint(cl, 393, 393);
   3390    values->preload.fragment.primitive_flags = __gen_unpack_uint(cl, 394, 394);
   3391    values->preload.fragment.fragment_position = __gen_unpack_uint(cl, 395, 395);
   3392    values->preload.fragment.sample_mask_id = __gen_unpack_uint(cl, 397, 397);
   3393    values->preload.uniform_count = __gen_unpack_uint(cl, 399, 405);
   3394    values->alpha_reference = __gen_unpack_float(cl, 384, 415);
   3395    values->thread_balancing = __gen_unpack_uint(cl, 416, 431);
   3396    values->secondary_preload.compute.pc = __gen_unpack_uint(cl, 422, 422);
   3397    values->secondary_preload.compute.local_invocation_xy = __gen_unpack_uint(cl, 423, 423);
   3398    values->secondary_preload.compute.local_invocation_z = __gen_unpack_uint(cl, 424, 424);
   3399    values->secondary_preload.compute.work_group_x = __gen_unpack_uint(cl, 425, 425);
   3400    values->secondary_preload.compute.work_group_y = __gen_unpack_uint(cl, 426, 426);
   3401    values->secondary_preload.compute.work_group_z = __gen_unpack_uint(cl, 427, 427);
   3402    values->secondary_preload.compute.global_invocation_x = __gen_unpack_uint(cl, 428, 428);
   3403    values->secondary_preload.compute.global_invocation_y = __gen_unpack_uint(cl, 429, 429);
   3404    values->secondary_preload.compute.global_invocation_z = __gen_unpack_uint(cl, 430, 430);
   3405    values->secondary_preload.vertex.warp_limit = (enum mali_warp_limit)__gen_unpack_uint(cl, 416, 417);
   3406    values->secondary_preload.vertex.pc = __gen_unpack_uint(cl, 422, 422);
   3407    values->secondary_preload.vertex.position_result_address_lo = __gen_unpack_uint(cl, 426, 426);
   3408    values->secondary_preload.vertex.position_result_address_hi = __gen_unpack_uint(cl, 427, 427);
   3409    values->secondary_preload.vertex.vertex_id = __gen_unpack_uint(cl, 429, 429);
   3410    values->secondary_preload.vertex.instance_id = __gen_unpack_uint(cl, 430, 430);
   3411    values->secondary_preload.fragment.pc = __gen_unpack_uint(cl, 422, 422);
   3412    values->secondary_preload.fragment.coverage = __gen_unpack_uint(cl, 423, 423);
   3413    values->secondary_preload.fragment.primitive_id = __gen_unpack_uint(cl, 425, 425);
   3414    values->secondary_preload.fragment.primitive_flags = __gen_unpack_uint(cl, 426, 426);
   3415    values->secondary_preload.fragment.fragment_position = __gen_unpack_uint(cl, 427, 427);
   3416    values->secondary_preload.fragment.sample_mask_id = __gen_unpack_uint(cl, 429, 429);
   3417    values->secondary_preload.uniform_count = __gen_unpack_uint(cl, 431, 437);
   3418    values->secondary_shader = __gen_unpack_uint(cl, 448, 511);
   3419    values->message_preload_1 = __gen_unpack_uint(cl, 480, 495);
   3420    values->message_preload_2 = __gen_unpack_uint(cl, 496, 511);
   3421 }
   3422 
   3423 static inline void
   3424 MALI_RENDERER_STATE_print(FILE *fp, const struct MALI_RENDERER_STATE * values, unsigned indent)
   3425 {
   3426    fprintf(fp, "%*sShader:\n", indent, "");
   3427    MALI_SHADER_print(fp, &values->shader, indent + 2);
   3428    fprintf(fp, "%*sProperties:\n", indent, "");
   3429    MALI_RENDERER_PROPERTIES_print(fp, &values->properties, indent + 2);
   3430    fprintf(fp, "%*sDepth units: %f\n", indent, "", values->depth_units);
   3431    fprintf(fp, "%*sDepth factor: %f\n", indent, "", values->depth_factor);
   3432    fprintf(fp, "%*sDepth bias clamp: %f\n", indent, "", values->depth_bias_clamp);
   3433    fprintf(fp, "%*sMultisample, Misc:\n", indent, "");
   3434    MALI_MULTISAMPLE_MISC_print(fp, &values->multisample_misc, indent + 2);
   3435    fprintf(fp, "%*sStencil Mask, Misc:\n", indent, "");
   3436    MALI_STENCIL_MASK_MISC_print(fp, &values->stencil_mask_misc, indent + 2);
   3437    fprintf(fp, "%*sStencil front:\n", indent, "");
   3438    MALI_STENCIL_print(fp, &values->stencil_front, indent + 2);
   3439    fprintf(fp, "%*sStencil back:\n", indent, "");
   3440    MALI_STENCIL_print(fp, &values->stencil_back, indent + 2);
   3441    fprintf(fp, "%*sPreload:\n", indent, "");
   3442    MALI_PRELOAD_print(fp, &values->preload, indent + 2);
   3443    fprintf(fp, "%*sAlpha reference: %f\n", indent, "", values->alpha_reference);
   3444    fprintf(fp, "%*sThread Balancing: %u\n", indent, "", values->thread_balancing);
   3445    fprintf(fp, "%*sSecondary preload:\n", indent, "");
   3446    MALI_PRELOAD_print(fp, &values->secondary_preload, indent + 2);
   3447    fprintf(fp, "%*sSecondary shader: 0x%" PRIx64 "\n", indent, "", values->secondary_shader);
   3448    fprintf(fp, "%*sMessage Preload 1: %u\n", indent, "", values->message_preload_1);
   3449    fprintf(fp, "%*sMessage Preload 2: %u\n", indent, "", values->message_preload_2);
   3450 }
   3451 
   3452 struct MALI_UNIFORM_BUFFER {
   3453    uint32_t                             entries;
   3454    uint64_t                             pointer;
   3455 };
   3456 
   3457 #define MALI_UNIFORM_BUFFER_header              \
   3458    0
   3459 
   3460 static inline void
   3461 MALI_UNIFORM_BUFFER_pack(uint32_t * restrict cl,
   3462                          const struct MALI_UNIFORM_BUFFER * restrict values)
   3463 {
   3464    assert(values->entries >= 1);
   3465    assert((values->pointer & 0xf) == 0);
   3466    cl[ 0] = __gen_uint(values->entries - 1, 0, 11) |
   3467             __gen_uint(values->pointer >> 4, 12, 63);
   3468    cl[ 1] = __gen_uint(values->pointer >> 4, 12, 63) >> 32;
   3469 }
   3470 
   3471 
   3472 #define MALI_UNIFORM_BUFFER_LENGTH 8
   3473 #define MALI_UNIFORM_BUFFER_ALIGN 8
   3474 struct mali_uniform_buffer_packed { uint32_t opaque[2]; };
   3475 static inline void
   3476 MALI_UNIFORM_BUFFER_unpack(const uint8_t * restrict cl,
   3477                            struct MALI_UNIFORM_BUFFER * restrict values)
   3478 {
   3479    values->entries = __gen_unpack_uint(cl, 0, 11) + 1;
   3480    values->pointer = __gen_unpack_uint(cl, 12, 63) << 4;
   3481 }
   3482 
   3483 static inline void
   3484 MALI_UNIFORM_BUFFER_print(FILE *fp, const struct MALI_UNIFORM_BUFFER * values, unsigned indent)
   3485 {
   3486    fprintf(fp, "%*sEntries: %u\n", indent, "", values->entries);
   3487    fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
   3488 }
   3489 
   3490 struct MALI_VIEWPORT {
   3491    float                                minimum_x;
   3492    float                                minimum_y;
   3493    float                                maximum_x;
   3494    float                                maximum_y;
   3495    float                                minimum_z;
   3496    float                                maximum_z;
   3497    uint32_t                             scissor_minimum_x;
   3498    uint32_t                             scissor_minimum_y;
   3499    uint32_t                             scissor_maximum_x;
   3500    uint32_t                             scissor_maximum_y;
   3501 };
   3502 
   3503 #define MALI_VIEWPORT_header                    \
   3504    .minimum_x = -INFINITY,  \
   3505    .minimum_y = -INFINITY,  \
   3506    .maximum_x = +INFINITY,  \
   3507    .maximum_y = +INFINITY,  \
   3508    .minimum_z = 0.0,  \
   3509    .maximum_z = 1.0,  \
   3510    .scissor_minimum_x = 0,  \
   3511    .scissor_minimum_y = 0
   3512 
   3513 static inline void
   3514 MALI_VIEWPORT_pack(uint32_t * restrict cl,
   3515                    const struct MALI_VIEWPORT * restrict values)
   3516 {
   3517    cl[ 0] = __gen_uint(fui(values->minimum_x), 0, 32);
   3518    cl[ 1] = __gen_uint(fui(values->minimum_y), 0, 32);
   3519    cl[ 2] = __gen_uint(fui(values->maximum_x), 0, 32);
   3520    cl[ 3] = __gen_uint(fui(values->maximum_y), 0, 32);
   3521    cl[ 4] = __gen_uint(fui(values->minimum_z), 0, 32);
   3522    cl[ 5] = __gen_uint(fui(values->maximum_z), 0, 32);
   3523    cl[ 6] = __gen_uint(values->scissor_minimum_x, 0, 15) |
   3524             __gen_uint(values->scissor_minimum_y, 16, 31);
   3525    cl[ 7] = __gen_uint(values->scissor_maximum_x, 0, 15) |
   3526             __gen_uint(values->scissor_maximum_y, 16, 31);
   3527 }
   3528 
   3529 
   3530 #define MALI_VIEWPORT_LENGTH 32
   3531 #define MALI_VIEWPORT_ALIGN 32
   3532 struct mali_viewport_packed { uint32_t opaque[8]; };
   3533 static inline void
   3534 MALI_VIEWPORT_unpack(const uint8_t * restrict cl,
   3535                      struct MALI_VIEWPORT * restrict values)
   3536 {
   3537    values->minimum_x = __gen_unpack_float(cl, 0, 31);
   3538    values->minimum_y = __gen_unpack_float(cl, 32, 63);
   3539    values->maximum_x = __gen_unpack_float(cl, 64, 95);
   3540    values->maximum_y = __gen_unpack_float(cl, 96, 127);
   3541    values->minimum_z = __gen_unpack_float(cl, 128, 159);
   3542    values->maximum_z = __gen_unpack_float(cl, 160, 191);
   3543    values->scissor_minimum_x = __gen_unpack_uint(cl, 192, 207);
   3544    values->scissor_minimum_y = __gen_unpack_uint(cl, 208, 223);
   3545    values->scissor_maximum_x = __gen_unpack_uint(cl, 224, 239);
   3546    values->scissor_maximum_y = __gen_unpack_uint(cl, 240, 255);
   3547 }
   3548 
   3549 static inline void
   3550 MALI_VIEWPORT_print(FILE *fp, const struct MALI_VIEWPORT * values, unsigned indent)
   3551 {
   3552    fprintf(fp, "%*sMinimum X: %f\n", indent, "", values->minimum_x);
   3553    fprintf(fp, "%*sMinimum Y: %f\n", indent, "", values->minimum_y);
   3554    fprintf(fp, "%*sMaximum X: %f\n", indent, "", values->maximum_x);
   3555    fprintf(fp, "%*sMaximum Y: %f\n", indent, "", values->maximum_y);
   3556    fprintf(fp, "%*sMinimum Z: %f\n", indent, "", values->minimum_z);
   3557    fprintf(fp, "%*sMaximum Z: %f\n", indent, "", values->maximum_z);
   3558    fprintf(fp, "%*sScissor Minimum X: %u\n", indent, "", values->scissor_minimum_x);
   3559    fprintf(fp, "%*sScissor Minimum Y: %u\n", indent, "", values->scissor_minimum_y);
   3560    fprintf(fp, "%*sScissor Maximum X: %u\n", indent, "", values->scissor_maximum_x);
   3561    fprintf(fp, "%*sScissor Maximum Y: %u\n", indent, "", values->scissor_maximum_y);
   3562 }
   3563 
   3564 struct MALI_LOCAL_STORAGE {
   3565    uint32_t                             tls_size;
   3566    uint32_t                             tls_initial_stack_pointer_offset;
   3567    uint32_t                             wls_instances;
   3568 #define MALI_LOCAL_STORAGE_NO_WORKGROUP_MEM      2147483648
   3569    uint32_t                             wls_size_base;
   3570    uint32_t                             wls_size_scale;
   3571    uint64_t                             tls_base_pointer;
   3572    uint64_t                             wls_base_pointer;
   3573 };
   3574 
   3575 #define MALI_LOCAL_STORAGE_header               \
   3576    .wls_instances = MALI_LOCAL_STORAGE_NO_WORKGROUP_MEM
   3577 
   3578 static inline void
   3579 MALI_LOCAL_STORAGE_pack(uint32_t * restrict cl,
   3580                         const struct MALI_LOCAL_STORAGE * restrict values)
   3581 {
   3582    assert(util_is_power_of_two_nonzero(values->wls_instances));
   3583    cl[ 0] = __gen_uint(values->tls_size, 0, 4) |
   3584             __gen_uint(values->tls_initial_stack_pointer_offset, 5, 31);
   3585    cl[ 1] = __gen_uint(util_logbase2(values->wls_instances), 0, 4) |
   3586             __gen_uint(values->wls_size_base, 5, 6) |
   3587             __gen_uint(values->wls_size_scale, 8, 12);
   3588    cl[ 2] = __gen_uint(values->tls_base_pointer, 0, 63);
   3589    cl[ 3] = __gen_uint(values->tls_base_pointer, 0, 63) >> 32;
   3590    cl[ 4] = __gen_uint(values->wls_base_pointer, 0, 63);
   3591    cl[ 5] = __gen_uint(values->wls_base_pointer, 0, 63) >> 32;
   3592    cl[ 6] = 0;
   3593    cl[ 7] = 0;
   3594 }
   3595 
   3596 
   3597 #define MALI_LOCAL_STORAGE_LENGTH 32
   3598 #define MALI_LOCAL_STORAGE_ALIGN 64
   3599 struct mali_local_storage_packed { uint32_t opaque[8]; };
   3600 static inline void
   3601 MALI_LOCAL_STORAGE_unpack(const uint8_t * restrict cl,
   3602                           struct MALI_LOCAL_STORAGE * restrict values)
   3603 {
   3604    if (((const uint32_t *) cl)[1] & 0xffffe080) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 1\n");
   3605    if (((const uint32_t *) cl)[6] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 6\n");
   3606    if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 7\n");
   3607    values->tls_size = __gen_unpack_uint(cl, 0, 4);
   3608    values->tls_initial_stack_pointer_offset = __gen_unpack_uint(cl, 5, 31);
   3609    values->wls_instances = 1U << __gen_unpack_uint(cl, 32, 36);
   3610    values->wls_size_base = __gen_unpack_uint(cl, 37, 38);
   3611    values->wls_size_scale = __gen_unpack_uint(cl, 40, 44);
   3612    values->tls_base_pointer = __gen_unpack_uint(cl, 64, 127);
   3613    values->wls_base_pointer = __gen_unpack_uint(cl, 128, 191);
   3614 }
   3615 
   3616 static inline void
   3617 MALI_LOCAL_STORAGE_print(FILE *fp, const struct MALI_LOCAL_STORAGE * values, unsigned indent)
   3618 {
   3619    fprintf(fp, "%*sTLS Size: %u\n", indent, "", values->tls_size);
   3620    fprintf(fp, "%*sTLS Initial Stack Pointer Offset: %u\n", indent, "", values->tls_initial_stack_pointer_offset);
   3621    fprintf(fp, "%*sWLS Instances: %u\n", indent, "", values->wls_instances);
   3622    fprintf(fp, "%*sWLS Size Base: %u\n", indent, "", values->wls_size_base);
   3623    fprintf(fp, "%*sWLS Size Scale: %u\n", indent, "", values->wls_size_scale);
   3624    fprintf(fp, "%*sTLS Base Pointer: 0x%" PRIx64 "\n", indent, "", values->tls_base_pointer);
   3625    fprintf(fp, "%*sWLS Base Pointer: 0x%" PRIx64 "\n", indent, "", values->wls_base_pointer);
   3626 }
   3627 
   3628 enum mali_color_buffer_internal_format {
   3629         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE =      0,
   3630         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8 =      1,
   3631         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2 =      2,
   3632         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2 =      3,
   3633         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4 =      4,
   3634         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0 =      5,
   3635         MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1 =      6,
   3636         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8 =     32,
   3637         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16 =     33,
   3638         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32 =     34,
   3639         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64 =     35,
   3640         MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128 =     36,
   3641 };
   3642 
   3643 static inline const char *
   3644 mali_color_buffer_internal_format_as_str(enum mali_color_buffer_internal_format imm)
   3645 {
   3646     switch (imm) {
   3647     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE: return "Raw Value";
   3648     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8: return "R8G8B8A8";
   3649     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2: return "R10G10B10A2";
   3650     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2: return "R8G8B8A2";
   3651     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4: return "R4G4B4A4";
   3652     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0: return "R5G6B5A0";
   3653     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1: return "R5G5B5A1";
   3654     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8: return "RAW8";
   3655     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16: return "RAW16";
   3656     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32: return "RAW32";
   3657     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64: return "RAW64";
   3658     case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128: return "RAW128";
   3659     default: return "XXX: INVALID";
   3660     }
   3661 }
   3662 
   3663 enum mali_color_format {
   3664         MALI_COLOR_FORMAT_RAW8               =      0,
   3665         MALI_COLOR_FORMAT_RAW16              =      1,
   3666         MALI_COLOR_FORMAT_RAW24              =      2,
   3667         MALI_COLOR_FORMAT_RAW32              =      3,
   3668         MALI_COLOR_FORMAT_RAW48              =      4,
   3669         MALI_COLOR_FORMAT_RAW64              =      5,
   3670         MALI_COLOR_FORMAT_RAW96              =      6,
   3671         MALI_COLOR_FORMAT_RAW128             =      7,
   3672         MALI_COLOR_FORMAT_RAW192             =      8,
   3673         MALI_COLOR_FORMAT_RAW256             =      9,
   3674         MALI_COLOR_FORMAT_RAW384             =     10,
   3675         MALI_COLOR_FORMAT_RAW512             =     11,
   3676         MALI_COLOR_FORMAT_RAW768             =     12,
   3677         MALI_COLOR_FORMAT_RAW1024            =     13,
   3678         MALI_COLOR_FORMAT_RAW1536            =     14,
   3679         MALI_COLOR_FORMAT_RAW2048            =     15,
   3680         MALI_COLOR_FORMAT_R8                 =     16,
   3681         MALI_COLOR_FORMAT_R8G8               =     17,
   3682         MALI_COLOR_FORMAT_R8G8B8             =     18,
   3683         MALI_COLOR_FORMAT_R8G8B8A8           =     19,
   3684         MALI_COLOR_FORMAT_R4G4B4A4           =     20,
   3685         MALI_COLOR_FORMAT_R5G6B5             =     21,
   3686         MALI_COLOR_FORMAT_R8G8B8_FROM_R8G8B8A2 =     22,
   3687         MALI_COLOR_FORMAT_R10G10B10A2        =     24,
   3688         MALI_COLOR_FORMAT_A2B10G10R10        =     25,
   3689         MALI_COLOR_FORMAT_R5G5B5A1           =     28,
   3690         MALI_COLOR_FORMAT_A1B5G5R5           =     29,
   3691         MALI_COLOR_FORMAT_NATIVE             =     31,
   3692 };
   3693 
   3694 static inline const char *
   3695 mali_color_format_as_str(enum mali_color_format imm)
   3696 {
   3697     switch (imm) {
   3698     case MALI_COLOR_FORMAT_RAW8: return "RAW8";
   3699     case MALI_COLOR_FORMAT_RAW16: return "RAW16";
   3700     case MALI_COLOR_FORMAT_RAW24: return "RAW24";
   3701     case MALI_COLOR_FORMAT_RAW32: return "RAW32";
   3702     case MALI_COLOR_FORMAT_RAW48: return "RAW48";
   3703     case MALI_COLOR_FORMAT_RAW64: return "RAW64";
   3704     case MALI_COLOR_FORMAT_RAW96: return "RAW96";
   3705     case MALI_COLOR_FORMAT_RAW128: return "RAW128";
   3706     case MALI_COLOR_FORMAT_RAW192: return "RAW192";
   3707     case MALI_COLOR_FORMAT_RAW256: return "RAW256";
   3708     case MALI_COLOR_FORMAT_RAW384: return "RAW384";
   3709     case MALI_COLOR_FORMAT_RAW512: return "RAW512";
   3710     case MALI_COLOR_FORMAT_RAW768: return "RAW768";
   3711     case MALI_COLOR_FORMAT_RAW1024: return "RAW1024";
   3712     case MALI_COLOR_FORMAT_RAW1536: return "RAW1536";
   3713     case MALI_COLOR_FORMAT_RAW2048: return "RAW2048";
   3714     case MALI_COLOR_FORMAT_R8: return "R8";
   3715     case MALI_COLOR_FORMAT_R8G8: return "R8G8";
   3716     case MALI_COLOR_FORMAT_R8G8B8: return "R8G8B8";
   3717     case MALI_COLOR_FORMAT_R8G8B8A8: return "R8G8B8A8";
   3718     case MALI_COLOR_FORMAT_R4G4B4A4: return "R4G4B4A4";
   3719     case MALI_COLOR_FORMAT_R5G6B5: return "R5G6B5";
   3720     case MALI_COLOR_FORMAT_R8G8B8_FROM_R8G8B8A2: return "R8G8B8_FROM_R8G8B8A2";
   3721     case MALI_COLOR_FORMAT_R10G10B10A2: return "R10G10B10A2";
   3722     case MALI_COLOR_FORMAT_A2B10G10R10: return "A2B10G10R10";
   3723     case MALI_COLOR_FORMAT_R5G5B5A1: return "R5G5B5A1";
   3724     case MALI_COLOR_FORMAT_A1B5G5R5: return "A1B5G5R5";
   3725     case MALI_COLOR_FORMAT_NATIVE: return "NATIVE";
   3726     default: return "XXX: INVALID";
   3727     }
   3728 }
   3729 
   3730 enum mali_downsampling_accumulation_mode {
   3731         MALI_DOWNSAMPLING_ACCUMULATION_MODE_UNSIGNED_NORMALIZED_INTEGER =      0,
   3732         MALI_DOWNSAMPLING_ACCUMULATION_MODE_SIGNED_NORMALIZED_INTEGER =      1,
   3733 };
   3734 
   3735 static inline const char *
   3736 mali_downsampling_accumulation_mode_as_str(enum mali_downsampling_accumulation_mode imm)
   3737 {
   3738     switch (imm) {
   3739     case MALI_DOWNSAMPLING_ACCUMULATION_MODE_UNSIGNED_NORMALIZED_INTEGER: return "Unsigned normalized integer";
   3740     case MALI_DOWNSAMPLING_ACCUMULATION_MODE_SIGNED_NORMALIZED_INTEGER: return "Signed normalized integer";
   3741     default: return "XXX: INVALID";
   3742     }
   3743 }
   3744 
   3745 enum mali_sample_layout {
   3746         MALI_SAMPLE_LAYOUT_ORDERED_4X_GRID   =      0,
   3747         MALI_SAMPLE_LAYOUT_ROTATED_4X_GRID   =      1,
   3748         MALI_SAMPLE_LAYOUT_D3D_8X_GRID       =      2,
   3749         MALI_SAMPLE_LAYOUT_D3D_16X_GRID      =      3,
   3750 };
   3751 
   3752 static inline const char *
   3753 mali_sample_layout_as_str(enum mali_sample_layout imm)
   3754 {
   3755     switch (imm) {
   3756     case MALI_SAMPLE_LAYOUT_ORDERED_4X_GRID: return "Ordered 4x Grid";
   3757     case MALI_SAMPLE_LAYOUT_ROTATED_4X_GRID: return "Rotated 4x Grid";
   3758     case MALI_SAMPLE_LAYOUT_D3D_8X_GRID: return "D3D 8x Grid";
   3759     case MALI_SAMPLE_LAYOUT_D3D_16X_GRID: return "D3D 16x Grid";
   3760     default: return "XXX: INVALID";
   3761     }
   3762 }
   3763 
   3764 enum mali_zs_format {
   3765         MALI_ZS_FORMAT_D16                   =      1,
   3766         MALI_ZS_FORMAT_D24                   =      2,
   3767         MALI_ZS_FORMAT_D24X8                 =      4,
   3768         MALI_ZS_FORMAT_D24S8                 =      5,
   3769         MALI_ZS_FORMAT_X8D24                 =      6,
   3770         MALI_ZS_FORMAT_S8D24                 =      7,
   3771         MALI_ZS_FORMAT_D32_X8X24             =     13,
   3772         MALI_ZS_FORMAT_D32                   =     14,
   3773         MALI_ZS_FORMAT_D32_S8X24             =     15,
   3774 };
   3775 
   3776 static inline const char *
   3777 mali_zs_format_as_str(enum mali_zs_format imm)
   3778 {
   3779     switch (imm) {
   3780     case MALI_ZS_FORMAT_D16: return "D16";
   3781     case MALI_ZS_FORMAT_D24: return "D24";
   3782     case MALI_ZS_FORMAT_D24X8: return "D24X8";
   3783     case MALI_ZS_FORMAT_D24S8: return "D24S8";
   3784     case MALI_ZS_FORMAT_X8D24: return "X8D24";
   3785     case MALI_ZS_FORMAT_S8D24: return "S8D24";
   3786     case MALI_ZS_FORMAT_D32_X8X24: return "D32_X8X24";
   3787     case MALI_ZS_FORMAT_D32: return "D32";
   3788     case MALI_ZS_FORMAT_D32_S8X24: return "D32_S8X24";
   3789     default: return "XXX: INVALID";
   3790     }
   3791 }
   3792 
   3793 enum mali_zs_preload_format {
   3794         MALI_ZS_PRELOAD_FORMAT_D32_S8X24     =      4,
   3795 };
   3796 
   3797 static inline const char *
   3798 mali_zs_preload_format_as_str(enum mali_zs_preload_format imm)
   3799 {
   3800     switch (imm) {
   3801     case MALI_ZS_PRELOAD_FORMAT_D32_S8X24: return "D32_S8X24";
   3802     default: return "XXX: INVALID";
   3803     }
   3804 }
   3805 
   3806 enum mali_s_format {
   3807         MALI_S_FORMAT_S8                     =      1,
   3808         MALI_S_FORMAT_S8X8                   =      2,
   3809         MALI_S_FORMAT_S8X24                  =      3,
   3810         MALI_S_FORMAT_X24S8                  =      4,
   3811         MALI_S_FORMAT_X8S8                   =      5,
   3812         MALI_S_FORMAT_X32_S8X24              =      6,
   3813 };
   3814 
   3815 static inline const char *
   3816 mali_s_format_as_str(enum mali_s_format imm)
   3817 {
   3818     switch (imm) {
   3819     case MALI_S_FORMAT_S8: return "S8";
   3820     case MALI_S_FORMAT_S8X8: return "S8X8";
   3821     case MALI_S_FORMAT_S8X24: return "S8X24";
   3822     case MALI_S_FORMAT_X24S8: return "X24S8";
   3823     case MALI_S_FORMAT_X8S8: return "X8S8";
   3824     case MALI_S_FORMAT_X32_S8X24: return "X32_S8X24";
   3825     default: return "XXX: INVALID";
   3826     }
   3827 }
   3828 
   3829 enum mali_tie_break_rule {
   3830         MALI_TIE_BREAK_RULE_0_IN_180_OUT     =      0,
   3831         MALI_TIE_BREAK_RULE_0_OUT_180_IN     =      1,
   3832         MALI_TIE_BREAK_RULE_MINUS_180_IN_0_OUT =      2,
   3833         MALI_TIE_BREAK_RULE_MINUS_180_OUT_0_IN =      3,
   3834         MALI_TIE_BREAK_RULE_90_IN_270_OUT    =      4,
   3835         MALI_TIE_BREAK_RULE_90_OUT_270_IN    =      5,
   3836         MALI_TIE_BREAK_RULE_MINUS_90_IN_90_OUT =      6,
   3837         MALI_TIE_BREAK_RULE_MINUS_90_OUT_90_IN =      7,
   3838 };
   3839 
   3840 static inline const char *
   3841 mali_tie_break_rule_as_str(enum mali_tie_break_rule imm)
   3842 {
   3843     switch (imm) {
   3844     case MALI_TIE_BREAK_RULE_0_IN_180_OUT: return "0_IN_180_OUT";
   3845     case MALI_TIE_BREAK_RULE_0_OUT_180_IN: return "0_OUT_180_IN";
   3846     case MALI_TIE_BREAK_RULE_MINUS_180_IN_0_OUT: return "MINUS_180_IN_0_OUT";
   3847     case MALI_TIE_BREAK_RULE_MINUS_180_OUT_0_IN: return "MINUS_180_OUT_0_IN";
   3848     case MALI_TIE_BREAK_RULE_90_IN_270_OUT: return "90_IN_270_OUT";
   3849     case MALI_TIE_BREAK_RULE_90_OUT_270_IN: return "90_OUT_270_IN";
   3850     case MALI_TIE_BREAK_RULE_MINUS_90_IN_90_OUT: return "MINUS_90_IN_90_OUT";
   3851     case MALI_TIE_BREAK_RULE_MINUS_90_OUT_90_IN: return "MINUS_90_OUT_90_IN";
   3852     default: return "XXX: INVALID";
   3853     }
   3854 }
   3855 
   3856 struct MALI_RT_BUFFER {
   3857    uint64_t                             base;
   3858    uint32_t                             row_stride;
   3859    uint32_t                             surface_stride;
   3860 };
   3861 
   3862 #define MALI_RT_BUFFER_header                   \
   3863    0
   3864 
   3865 static inline void
   3866 MALI_RT_BUFFER_pack(uint32_t * restrict cl,
   3867                     const struct MALI_RT_BUFFER * restrict values)
   3868 {
   3869    cl[ 0] = __gen_uint(values->base, 0, 63);
   3870    cl[ 1] = __gen_uint(values->base, 0, 63) >> 32;
   3871    cl[ 2] = __gen_uint(values->row_stride, 0, 31);
   3872    cl[ 3] = __gen_uint(values->surface_stride, 0, 31);
   3873 }
   3874 
   3875 
   3876 #define MALI_RT_BUFFER_LENGTH 16
   3877 struct mali_rt_buffer_packed { uint32_t opaque[4]; };
   3878 static inline void
   3879 MALI_RT_BUFFER_unpack(const uint8_t * restrict cl,
   3880                       struct MALI_RT_BUFFER * restrict values)
   3881 {
   3882    values->base = __gen_unpack_uint(cl, 0, 63);
   3883    values->row_stride = __gen_unpack_uint(cl, 64, 95);
   3884    values->surface_stride = __gen_unpack_uint(cl, 96, 127);
   3885 }
   3886 
   3887 static inline void
   3888 MALI_RT_BUFFER_print(FILE *fp, const struct MALI_RT_BUFFER * values, unsigned indent)
   3889 {
   3890    fprintf(fp, "%*sBase: 0x%" PRIx64 "\n", indent, "", values->base);
   3891    fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
   3892    fprintf(fp, "%*sSurface Stride: %u\n", indent, "", values->surface_stride);
   3893 }
   3894 
   3895 enum mali_sample_pattern {
   3896         MALI_SAMPLE_PATTERN_SINGLE_SAMPLED   =      0,
   3897         MALI_SAMPLE_PATTERN_ORDERED_4X_GRID  =      1,
   3898         MALI_SAMPLE_PATTERN_ROTATED_4X_GRID  =      2,
   3899         MALI_SAMPLE_PATTERN_D3D_8X_GRID      =      3,
   3900         MALI_SAMPLE_PATTERN_D3D_16X_GRID     =      4,
   3901 };
   3902 
   3903 static inline const char *
   3904 mali_sample_pattern_as_str(enum mali_sample_pattern imm)
   3905 {
   3906     switch (imm) {
   3907     case MALI_SAMPLE_PATTERN_SINGLE_SAMPLED: return "Single-sampled";
   3908     case MALI_SAMPLE_PATTERN_ORDERED_4X_GRID: return "Ordered 4x Grid";
   3909     case MALI_SAMPLE_PATTERN_ROTATED_4X_GRID: return "Rotated 4x Grid";
   3910     case MALI_SAMPLE_PATTERN_D3D_8X_GRID: return "D3D 8x Grid";
   3911     case MALI_SAMPLE_PATTERN_D3D_16X_GRID: return "D3D 16x Grid";
   3912     default: return "XXX: INVALID";
   3913     }
   3914 }
   3915 
   3916 enum mali_z_internal_format {
   3917         MALI_Z_INTERNAL_FORMAT_D16           =      0,
   3918         MALI_Z_INTERNAL_FORMAT_D24           =      1,
   3919         MALI_Z_INTERNAL_FORMAT_D32           =      2,
   3920 };
   3921 
   3922 static inline const char *
   3923 mali_z_internal_format_as_str(enum mali_z_internal_format imm)
   3924 {
   3925     switch (imm) {
   3926     case MALI_Z_INTERNAL_FORMAT_D16: return "D16";
   3927     case MALI_Z_INTERNAL_FORMAT_D24: return "D24";
   3928     case MALI_Z_INTERNAL_FORMAT_D32: return "D32";
   3929     default: return "XXX: INVALID";
   3930     }
   3931 }
   3932 
   3933 enum mali_fbd_tag {
   3934         MALI_FBD_TAG_IS_MFBD                 =      1,
   3935         MALI_FBD_TAG_HAS_ZS_RT               =      2,
   3936         MALI_FBD_TAG_MASK                    =     63,
   3937 };
   3938 
   3939 static inline const char *
   3940 mali_fbd_tag_as_str(enum mali_fbd_tag imm)
   3941 {
   3942     switch (imm) {
   3943     case MALI_FBD_TAG_IS_MFBD: return "IS_MFBD";
   3944     case MALI_FBD_TAG_HAS_ZS_RT: return "HAS_ZS_RT";
   3945     case MALI_FBD_TAG_MASK: return "MASK";
   3946     default: return "XXX: INVALID";
   3947     }
   3948 }
   3949 
   3950 enum mali_pre_post_frame_shader_mode {
   3951         MALI_PRE_POST_FRAME_SHADER_MODE_NEVER =      0,
   3952         MALI_PRE_POST_FRAME_SHADER_MODE_ALWAYS =      1,
   3953         MALI_PRE_POST_FRAME_SHADER_MODE_INTERSECT =      2,
   3954         MALI_PRE_POST_FRAME_SHADER_MODE_EARLY_ZS_ALWAYS =      3,
   3955 };
   3956 
   3957 static inline const char *
   3958 mali_pre_post_frame_shader_mode_as_str(enum mali_pre_post_frame_shader_mode imm)
   3959 {
   3960     switch (imm) {
   3961     case MALI_PRE_POST_FRAME_SHADER_MODE_NEVER: return "Never";
   3962     case MALI_PRE_POST_FRAME_SHADER_MODE_ALWAYS: return "Always";
   3963     case MALI_PRE_POST_FRAME_SHADER_MODE_INTERSECT: return "Intersect";
   3964     case MALI_PRE_POST_FRAME_SHADER_MODE_EARLY_ZS_ALWAYS: return "Early ZS always";
   3965     default: return "XXX: INVALID";
   3966     }
   3967 }
   3968 
   3969 struct MALI_FRAMEBUFFER_PARAMETERS {
   3970    enum mali_pre_post_frame_shader_mode pre_frame_0;
   3971    enum mali_pre_post_frame_shader_mode pre_frame_1;
   3972    enum mali_pre_post_frame_shader_mode post_frame;
   3973    uint64_t                             sample_locations;
   3974    uint64_t                             frame_shader_dcds;
   3975    uint32_t                             width;
   3976    uint32_t                             height;
   3977    uint32_t                             bound_min_x;
   3978    uint32_t                             bound_min_y;
   3979    uint32_t                             bound_max_x;
   3980    uint32_t                             bound_max_y;
   3981    uint32_t                             sample_count;
   3982    enum mali_sample_pattern             sample_pattern;
   3983    enum mali_tie_break_rule             tie_break_rule;
   3984    uint32_t                             effective_tile_size;
   3985    uint32_t                             x_downsampling_scale;
   3986    uint32_t                             y_downsampling_scale;
   3987    uint32_t                             render_target_count;
   3988    uint32_t                             color_buffer_allocation;
   3989    uint32_t                             s_clear;
   3990    bool                                 s_write_enable;
   3991    bool                                 s_preload_enable;
   3992    bool                                 s_unload_enable;
   3993    enum mali_z_internal_format          z_internal_format;
   3994    bool                                 z_write_enable;
   3995    bool                                 z_preload_enable;
   3996    bool                                 z_unload_enable;
   3997    bool                                 has_zs_crc_extension;
   3998    bool                                 crc_read_enable;
   3999    bool                                 crc_write_enable;
   4000    float                                z_clear;
   4001    uint64_t                             tiler;
   4002 };
   4003 
   4004 #define MALI_FRAMEBUFFER_PARAMETERS_header      \
   4005    .sample_count = 1
   4006 
   4007 static inline void
   4008 MALI_FRAMEBUFFER_PARAMETERS_pack(uint32_t * restrict cl,
   4009                                  const struct MALI_FRAMEBUFFER_PARAMETERS * restrict values)
   4010 {
   4011    assert(values->width >= 1);
   4012    assert(values->height >= 1);
   4013    assert(util_is_power_of_two_nonzero(values->sample_count));
   4014    assert(util_is_power_of_two_nonzero(values->effective_tile_size));
   4015    assert(values->render_target_count >= 1);
   4016    assert((values->color_buffer_allocation & 0x3ff) == 0);
   4017    cl[ 0] = __gen_uint(values->pre_frame_0, 0, 2) |
   4018             __gen_uint(values->pre_frame_1, 3, 5) |
   4019             __gen_uint(values->post_frame, 6, 8);
   4020    cl[ 1] = 0;
   4021    cl[ 2] = 0;
   4022    cl[ 3] = 0;
   4023    cl[ 4] = __gen_uint(values->sample_locations, 0, 63);
   4024    cl[ 5] = __gen_uint(values->sample_locations, 0, 63) >> 32;
   4025    cl[ 6] = __gen_uint(values->frame_shader_dcds, 0, 63);
   4026    cl[ 7] = __gen_uint(values->frame_shader_dcds, 0, 63) >> 32;
   4027    cl[ 8] = __gen_uint(values->width - 1, 0, 15) |
   4028             __gen_uint(values->height - 1, 16, 31);
   4029    cl[ 9] = __gen_uint(values->bound_min_x, 0, 15) |
   4030             __gen_uint(values->bound_min_y, 16, 31);
   4031    cl[10] = __gen_uint(values->bound_max_x, 0, 15) |
   4032             __gen_uint(values->bound_max_y, 16, 31);
   4033    cl[11] = __gen_uint(util_logbase2(values->sample_count), 0, 2) |
   4034             __gen_uint(values->sample_pattern, 3, 5) |
   4035             __gen_uint(values->tie_break_rule, 6, 8) |
   4036             __gen_uint(util_logbase2(values->effective_tile_size), 9, 12) |
   4037             __gen_uint(values->x_downsampling_scale, 13, 15) |
   4038             __gen_uint(values->y_downsampling_scale, 16, 18) |
   4039             __gen_uint(values->render_target_count - 1, 19, 22) |
   4040             __gen_uint(values->color_buffer_allocation >> 10, 24, 31);
   4041    cl[12] = __gen_uint(values->s_clear, 0, 7) |
   4042             __gen_uint(values->s_write_enable, 8, 8) |
   4043             __gen_uint(values->s_preload_enable, 9, 9) |
   4044             __gen_uint(values->s_unload_enable, 10, 10) |
   4045             __gen_uint(values->z_internal_format, 16, 17) |
   4046             __gen_uint(values->z_write_enable, 18, 18) |
   4047             __gen_uint(values->z_preload_enable, 19, 19) |
   4048             __gen_uint(values->z_unload_enable, 20, 20) |
   4049             __gen_uint(values->has_zs_crc_extension, 21, 21) |
   4050             __gen_uint(values->crc_read_enable, 30, 30) |
   4051             __gen_uint(values->crc_write_enable, 31, 31);
   4052    cl[13] = __gen_uint(fui(values->z_clear), 0, 32);
   4053    cl[14] = __gen_uint(values->tiler, 0, 63);
   4054    cl[15] = __gen_uint(values->tiler, 0, 63) >> 32;
   4055 }
   4056 
   4057 
   4058 #define MALI_FRAMEBUFFER_PARAMETERS_LENGTH 64
   4059 struct mali_framebuffer_parameters_packed { uint32_t opaque[16]; };
   4060 static inline void
   4061 MALI_FRAMEBUFFER_PARAMETERS_unpack(const uint8_t * restrict cl,
   4062                                    struct MALI_FRAMEBUFFER_PARAMETERS * restrict values)
   4063 {
   4064    if (((const uint32_t *) cl)[0] & 0xfffffe00) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 0\n");
   4065    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 1\n");
   4066    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 2\n");
   4067    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 3\n");
   4068    if (((const uint32_t *) cl)[11] & 0x800000) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 11\n");
   4069    if (((const uint32_t *) cl)[12] & 0x3fc0f800) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 12\n");
   4070    values->pre_frame_0 = (enum mali_pre_post_frame_shader_mode)__gen_unpack_uint(cl, 0, 2);
   4071    values->pre_frame_1 = (enum mali_pre_post_frame_shader_mode)__gen_unpack_uint(cl, 3, 5);
   4072    values->post_frame = (enum mali_pre_post_frame_shader_mode)__gen_unpack_uint(cl, 6, 8);
   4073    values->sample_locations = __gen_unpack_uint(cl, 128, 191);
   4074    values->frame_shader_dcds = __gen_unpack_uint(cl, 192, 255);
   4075    values->width = __gen_unpack_uint(cl, 256, 271) + 1;
   4076    values->height = __gen_unpack_uint(cl, 272, 287) + 1;
   4077    values->bound_min_x = __gen_unpack_uint(cl, 288, 303);
   4078    values->bound_min_y = __gen_unpack_uint(cl, 304, 319);
   4079    values->bound_max_x = __gen_unpack_uint(cl, 320, 335);
   4080    values->bound_max_y = __gen_unpack_uint(cl, 336, 351);
   4081    values->sample_count = 1U << __gen_unpack_uint(cl, 352, 354);
   4082    values->sample_pattern = (enum mali_sample_pattern)__gen_unpack_uint(cl, 355, 357);
   4083    values->tie_break_rule = (enum mali_tie_break_rule)__gen_unpack_uint(cl, 358, 360);
   4084    values->effective_tile_size = 1U << __gen_unpack_uint(cl, 361, 364);
   4085    values->x_downsampling_scale = __gen_unpack_uint(cl, 365, 367);
   4086    values->y_downsampling_scale = __gen_unpack_uint(cl, 368, 370);
   4087    values->render_target_count = __gen_unpack_uint(cl, 371, 374) + 1;
   4088    values->color_buffer_allocation = __gen_unpack_uint(cl, 376, 383) << 10;
   4089    values->s_clear = __gen_unpack_uint(cl, 384, 391);
   4090    values->s_write_enable = __gen_unpack_uint(cl, 392, 392);
   4091    values->s_preload_enable = __gen_unpack_uint(cl, 393, 393);
   4092    values->s_unload_enable = __gen_unpack_uint(cl, 394, 394);
   4093    values->z_internal_format = (enum mali_z_internal_format)__gen_unpack_uint(cl, 400, 401);
   4094    values->z_write_enable = __gen_unpack_uint(cl, 402, 402);
   4095    values->z_preload_enable = __gen_unpack_uint(cl, 403, 403);
   4096    values->z_unload_enable = __gen_unpack_uint(cl, 404, 404);
   4097    values->has_zs_crc_extension = __gen_unpack_uint(cl, 405, 405);
   4098    values->crc_read_enable = __gen_unpack_uint(cl, 414, 414);
   4099    values->crc_write_enable = __gen_unpack_uint(cl, 415, 415);
   4100    values->z_clear = __gen_unpack_float(cl, 416, 447);
   4101    values->tiler = __gen_unpack_uint(cl, 448, 511);
   4102 }
   4103 
   4104 static inline void
   4105 MALI_FRAMEBUFFER_PARAMETERS_print(FILE *fp, const struct MALI_FRAMEBUFFER_PARAMETERS * values, unsigned indent)
   4106 {
   4107    fprintf(fp, "%*sPre Frame 0: %s\n", indent, "", mali_pre_post_frame_shader_mode_as_str(values->pre_frame_0));
   4108    fprintf(fp, "%*sPre Frame 1: %s\n", indent, "", mali_pre_post_frame_shader_mode_as_str(values->pre_frame_1));
   4109    fprintf(fp, "%*sPost Frame: %s\n", indent, "", mali_pre_post_frame_shader_mode_as_str(values->post_frame));
   4110    fprintf(fp, "%*sSample Locations: 0x%" PRIx64 "\n", indent, "", values->sample_locations);
   4111    fprintf(fp, "%*sFrame Shader DCDs: 0x%" PRIx64 "\n", indent, "", values->frame_shader_dcds);
   4112    fprintf(fp, "%*sWidth: %u\n", indent, "", values->width);
   4113    fprintf(fp, "%*sHeight: %u\n", indent, "", values->height);
   4114    fprintf(fp, "%*sBound Min X: %u\n", indent, "", values->bound_min_x);
   4115    fprintf(fp, "%*sBound Min Y: %u\n", indent, "", values->bound_min_y);
   4116    fprintf(fp, "%*sBound Max X: %u\n", indent, "", values->bound_max_x);
   4117    fprintf(fp, "%*sBound Max Y: %u\n", indent, "", values->bound_max_y);
   4118    fprintf(fp, "%*sSample Count: %u\n", indent, "", values->sample_count);
   4119    fprintf(fp, "%*sSample Pattern: %s\n", indent, "", mali_sample_pattern_as_str(values->sample_pattern));
   4120    fprintf(fp, "%*sTie-Break Rule: %s\n", indent, "", mali_tie_break_rule_as_str(values->tie_break_rule));
   4121    fprintf(fp, "%*sEffective Tile Size: %u\n", indent, "", values->effective_tile_size);
   4122    fprintf(fp, "%*sX Downsampling Scale: %u\n", indent, "", values->x_downsampling_scale);
   4123    fprintf(fp, "%*sY Downsampling Scale: %u\n", indent, "", values->y_downsampling_scale);
   4124    fprintf(fp, "%*sRender Target Count: %u\n", indent, "", values->render_target_count);
   4125    fprintf(fp, "%*sColor Buffer Allocation: %u\n", indent, "", values->color_buffer_allocation);
   4126    fprintf(fp, "%*sS Clear: %u\n", indent, "", values->s_clear);
   4127    fprintf(fp, "%*sS Write Enable: %s\n", indent, "", values->s_write_enable ? "true" : "false");
   4128    fprintf(fp, "%*sS Preload Enable: %s\n", indent, "", values->s_preload_enable ? "true" : "false");
   4129    fprintf(fp, "%*sS Unload Enable: %s\n", indent, "", values->s_unload_enable ? "true" : "false");
   4130    fprintf(fp, "%*sZ Internal Format: %s\n", indent, "", mali_z_internal_format_as_str(values->z_internal_format));
   4131    fprintf(fp, "%*sZ Write Enable: %s\n", indent, "", values->z_write_enable ? "true" : "false");
   4132    fprintf(fp, "%*sZ Preload Enable: %s\n", indent, "", values->z_preload_enable ? "true" : "false");
   4133    fprintf(fp, "%*sZ Unload Enable: %s\n", indent, "", values->z_unload_enable ? "true" : "false");
   4134    fprintf(fp, "%*sHas ZS CRC Extension: %s\n", indent, "", values->has_zs_crc_extension ? "true" : "false");
   4135    fprintf(fp, "%*sCRC Read Enable: %s\n", indent, "", values->crc_read_enable ? "true" : "false");
   4136    fprintf(fp, "%*sCRC Write Enable: %s\n", indent, "", values->crc_write_enable ? "true" : "false");
   4137    fprintf(fp, "%*sZ Clear: %f\n", indent, "", values->z_clear);
   4138    fprintf(fp, "%*sTiler: 0x%" PRIx64 "\n", indent, "", values->tiler);
   4139 }
   4140 
   4141 struct MALI_ZS_CRC_EXTENSION {
   4142    uint64_t                             crc_base;
   4143    uint32_t                             crc_row_stride;
   4144    enum mali_zs_format                  zs_write_format;
   4145    enum mali_block_format               zs_block_format;
   4146    enum mali_msaa                       zs_msaa;
   4147    bool                                 zs_clean_pixel_write_enable;
   4148    uint32_t                             crc_render_target;
   4149    enum mali_s_format                   s_write_format;
   4150    enum mali_block_format               s_block_format;
   4151    enum mali_msaa                       s_msaa;
   4152    uint64_t                             zs_writeback_base;
   4153    uint32_t                             zs_writeback_row_stride;
   4154    uint32_t                             zs_writeback_surface_stride;
   4155    uint64_t                             s_writeback_base;
   4156    uint32_t                             s_writeback_row_stride;
   4157    uint32_t                             s_writeback_surface_stride;
   4158    uint64_t                             zs_afbc_header;
   4159    uint32_t                             zs_afbc_row_stride;
   4160    uint64_t                             zs_afbc_body;
   4161    uint64_t                             crc_clear_color;
   4162 };
   4163 
   4164 #define MALI_ZS_CRC_EXTENSION_header            \
   4165    .zs_msaa = MALI_MSAA_SINGLE,  \
   4166    .s_msaa = MALI_MSAA_SINGLE
   4167 
   4168 static inline void
   4169 MALI_ZS_CRC_EXTENSION_pack(uint32_t * restrict cl,
   4170                            const struct MALI_ZS_CRC_EXTENSION * restrict values)
   4171 {
   4172    cl[ 0] = __gen_uint(values->crc_base, 0, 63);
   4173    cl[ 1] = __gen_uint(values->crc_base, 0, 63) >> 32;
   4174    cl[ 2] = __gen_uint(values->crc_row_stride, 0, 31);
   4175    cl[ 3] = __gen_uint(values->zs_write_format, 0, 3) |
   4176             __gen_uint(values->zs_block_format, 4, 7) |
   4177             __gen_uint(values->zs_msaa, 8, 9) |
   4178             __gen_uint(values->zs_clean_pixel_write_enable, 10, 10) |
   4179             __gen_uint(values->crc_render_target, 11, 14) |
   4180             __gen_uint(values->s_write_format, 16, 19) |
   4181             __gen_uint(values->s_block_format, 20, 23) |
   4182             __gen_uint(values->s_msaa, 24, 25);
   4183    cl[ 4] = __gen_uint(values->zs_writeback_base, 0, 63) |
   4184             __gen_uint(values->zs_afbc_header, 0, 63);
   4185    cl[ 5] = __gen_uint(values->zs_writeback_base, 0, 63) >> 32 |
   4186             __gen_uint(values->zs_afbc_header, 0, 63) >> 32;
   4187    cl[ 6] = __gen_uint(values->zs_writeback_row_stride, 0, 31) |
   4188             __gen_uint(values->zs_afbc_row_stride, 0, 12);
   4189    cl[ 7] = __gen_uint(values->zs_writeback_surface_stride, 0, 31);
   4190    cl[ 8] = __gen_uint(values->s_writeback_base, 0, 63) |
   4191             __gen_uint(values->zs_afbc_body, 0, 63);
   4192    cl[ 9] = __gen_uint(values->s_writeback_base, 0, 63) >> 32 |
   4193             __gen_uint(values->zs_afbc_body, 0, 63) >> 32;
   4194    cl[10] = __gen_uint(values->s_writeback_row_stride, 0, 31);
   4195    cl[11] = __gen_uint(values->s_writeback_surface_stride, 0, 31);
   4196    cl[12] = __gen_uint(values->crc_clear_color, 0, 63);
   4197    cl[13] = __gen_uint(values->crc_clear_color, 0, 63) >> 32;
   4198    cl[14] = 0;
   4199    cl[15] = 0;
   4200 }
   4201 
   4202 
   4203 #define MALI_ZS_CRC_EXTENSION_LENGTH 64
   4204 #define MALI_ZS_CRC_EXTENSION_ALIGN 64
   4205 struct mali_zs_crc_extension_packed { uint32_t opaque[16]; };
   4206 static inline void
   4207 MALI_ZS_CRC_EXTENSION_unpack(const uint8_t * restrict cl,
   4208                              struct MALI_ZS_CRC_EXTENSION * restrict values)
   4209 {
   4210    if (((const uint32_t *) cl)[3] & 0xfc008000) fprintf(stderr, "XXX: Invalid field of ZS CRC Extension unpacked at word 3\n");
   4211    if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of ZS CRC Extension unpacked at word 14\n");
   4212    if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of ZS CRC Extension unpacked at word 15\n");
   4213    values->crc_base = __gen_unpack_uint(cl, 0, 63);
   4214    values->crc_row_stride = __gen_unpack_uint(cl, 64, 95);
   4215    values->zs_write_format = (enum mali_zs_format)__gen_unpack_uint(cl, 96, 99);
   4216    values->zs_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 100, 103);
   4217    values->zs_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 104, 105);
   4218    values->zs_clean_pixel_write_enable = __gen_unpack_uint(cl, 106, 106);
   4219    values->crc_render_target = __gen_unpack_uint(cl, 107, 110);
   4220    values->s_write_format = (enum mali_s_format)__gen_unpack_uint(cl, 112, 115);
   4221    values->s_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 116, 119);
   4222    values->s_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 120, 121);
   4223    values->zs_writeback_base = __gen_unpack_uint(cl, 128, 191);
   4224    values->zs_writeback_row_stride = __gen_unpack_uint(cl, 192, 223);
   4225    values->zs_writeback_surface_stride = __gen_unpack_uint(cl, 224, 255);
   4226    values->s_writeback_base = __gen_unpack_uint(cl, 256, 319);
   4227    values->s_writeback_row_stride = __gen_unpack_uint(cl, 320, 351);
   4228    values->s_writeback_surface_stride = __gen_unpack_uint(cl, 352, 383);
   4229    values->zs_afbc_header = __gen_unpack_uint(cl, 128, 191);
   4230    values->zs_afbc_row_stride = __gen_unpack_uint(cl, 192, 204);
   4231    values->zs_afbc_body = __gen_unpack_uint(cl, 256, 319);
   4232    values->crc_clear_color = __gen_unpack_uint(cl, 384, 447);
   4233 }
   4234 
   4235 static inline void
   4236 MALI_ZS_CRC_EXTENSION_print(FILE *fp, const struct MALI_ZS_CRC_EXTENSION * values, unsigned indent)
   4237 {
   4238    fprintf(fp, "%*sCRC Base: 0x%" PRIx64 "\n", indent, "", values->crc_base);
   4239    fprintf(fp, "%*sCRC Row Stride: %u\n", indent, "", values->crc_row_stride);
   4240    fprintf(fp, "%*sZS Write Format: %s\n", indent, "", mali_zs_format_as_str(values->zs_write_format));
   4241    fprintf(fp, "%*sZS Block Format: %s\n", indent, "", mali_block_format_as_str(values->zs_block_format));
   4242    fprintf(fp, "%*sZS MSAA: %s\n", indent, "", mali_msaa_as_str(values->zs_msaa));
   4243    fprintf(fp, "%*sZS Clean Pixel Write Enable: %s\n", indent, "", values->zs_clean_pixel_write_enable ? "true" : "false");
   4244    fprintf(fp, "%*sCRC Render Target: %u\n", indent, "", values->crc_render_target);
   4245    fprintf(fp, "%*sS Write Format: %s\n", indent, "", mali_s_format_as_str(values->s_write_format));
   4246    fprintf(fp, "%*sS Block Format: %s\n", indent, "", mali_block_format_as_str(values->s_block_format));
   4247    fprintf(fp, "%*sS MSAA: %s\n", indent, "", mali_msaa_as_str(values->s_msaa));
   4248    fprintf(fp, "%*sZS Writeback Base: 0x%" PRIx64 "\n", indent, "", values->zs_writeback_base);
   4249    fprintf(fp, "%*sZS Writeback Row Stride: %u\n", indent, "", values->zs_writeback_row_stride);
   4250    fprintf(fp, "%*sZS Writeback Surface Stride: %u\n", indent, "", values->zs_writeback_surface_stride);
   4251    fprintf(fp, "%*sS Writeback Base: 0x%" PRIx64 "\n", indent, "", values->s_writeback_base);
   4252    fprintf(fp, "%*sS Writeback Row Stride: %u\n", indent, "", values->s_writeback_row_stride);
   4253    fprintf(fp, "%*sS Writeback Surface Stride: %u\n", indent, "", values->s_writeback_surface_stride);
   4254    fprintf(fp, "%*sZS AFBC Header: 0x%" PRIx64 "\n", indent, "", values->zs_afbc_header);
   4255    fprintf(fp, "%*sZS AFBC Row Stride: %u\n", indent, "", values->zs_afbc_row_stride);
   4256    fprintf(fp, "%*sZS AFBC Body: 0x%" PRIx64 "\n", indent, "", values->zs_afbc_body);
   4257    fprintf(fp, "%*sCRC Clear Color: 0x%" PRIx64 "\n", indent, "", values->crc_clear_color);
   4258 }
   4259 
   4260 enum mali_yuv_conv_k6 {
   4261         MALI_YUV_CONV_K6_0                   =      0,
   4262         MALI_YUV_CONV_K6_16                  =      1,
   4263 };
   4264 
   4265 static inline const char *
   4266 mali_yuv_conv_k6_as_str(enum mali_yuv_conv_k6 imm)
   4267 {
   4268     switch (imm) {
   4269     case MALI_YUV_CONV_K6_0: return "0";
   4270     case MALI_YUV_CONV_K6_16: return "16";
   4271     default: return "XXX: INVALID";
   4272     }
   4273 }
   4274 
   4275 enum mali_yuv_conv_k7_clamp {
   4276         MALI_YUV_CONV_K7_CLAMP_MINUS_128_TO_127 =      0,
   4277         MALI_YUV_CONV_K7_CLAMP_MINUS_112_TO_111 =      1,
   4278         MALI_YUV_CONV_K7_CLAMP_0_TO_255      =      2,
   4279         MALI_YUV_CONV_K7_CLAMP_16_TO_239     =      3,
   4280 };
   4281 
   4282 static inline const char *
   4283 mali_yuv_conv_k7_clamp_as_str(enum mali_yuv_conv_k7_clamp imm)
   4284 {
   4285     switch (imm) {
   4286     case MALI_YUV_CONV_K7_CLAMP_MINUS_128_TO_127: return "MINUS_128_TO_127";
   4287     case MALI_YUV_CONV_K7_CLAMP_MINUS_112_TO_111: return "MINUS_112_TO_111";
   4288     case MALI_YUV_CONV_K7_CLAMP_0_TO_255: return "0_TO_255";
   4289     case MALI_YUV_CONV_K7_CLAMP_16_TO_239: return "16_TO_239";
   4290     default: return "XXX: INVALID";
   4291     }
   4292 }
   4293 
   4294 enum mali_yuv_conv_k8 {
   4295         MALI_YUV_CONV_K8_220                 =      0,
   4296         MALI_YUV_CONV_K8_256                 =      1,
   4297 };
   4298 
   4299 static inline const char *
   4300 mali_yuv_conv_k8_as_str(enum mali_yuv_conv_k8 imm)
   4301 {
   4302     switch (imm) {
   4303     case MALI_YUV_CONV_K8_220: return "220";
   4304     case MALI_YUV_CONV_K8_256: return "256";
   4305     default: return "XXX: INVALID";
   4306     }
   4307 }
   4308 
   4309 struct MALI_RENDER_TARGET_YUV_OVERLAY {
   4310    enum mali_yuv_swizzle                swizzle;
   4311    bool                                 full_range;
   4312    enum mali_yuv_conversion_mode        conversion_mode;
   4313    enum mali_yuv_cr_siting              cr_siting;
   4314    bool                                 unsigned_cr_range;
   4315    uint64_t                             plane_0_base;
   4316    uint64_t                             plane_1_base;
   4317    uint64_t                             plane_2_base;
   4318    uint32_t                             plane_0_stride;
   4319    uint32_t                             plane_1_2_stride;
   4320 };
   4321 
   4322 #define MALI_RENDER_TARGET_YUV_OVERLAY_header   \
   4323    0
   4324 
   4325 static inline void
   4326 MALI_RENDER_TARGET_YUV_OVERLAY_pack(uint32_t * restrict cl,
   4327                                     const struct MALI_RENDER_TARGET_YUV_OVERLAY * restrict values)
   4328 {
   4329    cl[ 0] = 0;
   4330    cl[ 1] = 0;
   4331    cl[ 2] = __gen_uint(values->swizzle, 16, 18) |
   4332             __gen_uint(values->full_range, 20, 20) |
   4333             __gen_uint(values->conversion_mode, 21, 24) |
   4334             __gen_uint(values->cr_siting, 25, 27) |
   4335             __gen_uint(values->unsigned_cr_range, 28, 28);
   4336    cl[ 3] = 0;
   4337    cl[ 4] = __gen_uint(values->plane_0_base, 0, 63);
   4338    cl[ 5] = __gen_uint(values->plane_0_base, 0, 63) >> 32;
   4339    cl[ 6] = __gen_uint(values->plane_1_base, 0, 63);
   4340    cl[ 7] = __gen_uint(values->plane_1_base, 0, 63) >> 32;
   4341    cl[ 8] = __gen_uint(values->plane_2_base, 0, 63);
   4342    cl[ 9] = __gen_uint(values->plane_2_base, 0, 63) >> 32;
   4343    cl[10] = __gen_uint(values->plane_0_stride, 0, 31);
   4344    cl[11] = __gen_uint(values->plane_1_2_stride, 0, 31);
   4345    cl[12] = 0;
   4346    cl[13] = 0;
   4347    cl[14] = 0;
   4348    cl[15] = 0;
   4349 }
   4350 
   4351 
   4352 #define MALI_RENDER_TARGET_YUV_OVERLAY_LENGTH 64
   4353 struct mali_render_target_yuv_overlay_packed { uint32_t opaque[16]; };
   4354 static inline void
   4355 MALI_RENDER_TARGET_YUV_OVERLAY_unpack(const uint8_t * restrict cl,
   4356                                       struct MALI_RENDER_TARGET_YUV_OVERLAY * restrict values)
   4357 {
   4358    if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 0\n");
   4359    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 1\n");
   4360    if (((const uint32_t *) cl)[2] & 0xe008ffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 2\n");
   4361    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 3\n");
   4362    if (((const uint32_t *) cl)[12] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 12\n");
   4363    if (((const uint32_t *) cl)[13] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 13\n");
   4364    if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 14\n");
   4365    if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 15\n");
   4366    values->swizzle = (enum mali_yuv_swizzle)__gen_unpack_uint(cl, 80, 82);
   4367    values->full_range = __gen_unpack_uint(cl, 84, 84);
   4368    values->conversion_mode = (enum mali_yuv_conversion_mode)__gen_unpack_uint(cl, 85, 88);
   4369    values->cr_siting = (enum mali_yuv_cr_siting)__gen_unpack_uint(cl, 89, 91);
   4370    values->unsigned_cr_range = __gen_unpack_uint(cl, 92, 92);
   4371    values->plane_0_base = __gen_unpack_uint(cl, 128, 191);
   4372    values->plane_1_base = __gen_unpack_uint(cl, 192, 255);
   4373    values->plane_2_base = __gen_unpack_uint(cl, 256, 319);
   4374    values->plane_0_stride = __gen_unpack_uint(cl, 320, 351);
   4375    values->plane_1_2_stride = __gen_unpack_uint(cl, 352, 383);
   4376 }
   4377 
   4378 static inline void
   4379 MALI_RENDER_TARGET_YUV_OVERLAY_print(FILE *fp, const struct MALI_RENDER_TARGET_YUV_OVERLAY * values, unsigned indent)
   4380 {
   4381    fprintf(fp, "%*sSwizzle: %s\n", indent, "", mali_yuv_swizzle_as_str(values->swizzle));
   4382    fprintf(fp, "%*sFull Range: %s\n", indent, "", values->full_range ? "true" : "false");
   4383    fprintf(fp, "%*sConversion Mode: %s\n", indent, "", mali_yuv_conversion_mode_as_str(values->conversion_mode));
   4384    fprintf(fp, "%*sCr Siting: %s\n", indent, "", mali_yuv_cr_siting_as_str(values->cr_siting));
   4385    fprintf(fp, "%*sUnsigned Cr Range: %s\n", indent, "", values->unsigned_cr_range ? "true" : "false");
   4386    fprintf(fp, "%*sPlane 0 Base: 0x%" PRIx64 "\n", indent, "", values->plane_0_base);
   4387    fprintf(fp, "%*sPlane 1 Base: 0x%" PRIx64 "\n", indent, "", values->plane_1_base);
   4388    fprintf(fp, "%*sPlane 2 Base: 0x%" PRIx64 "\n", indent, "", values->plane_2_base);
   4389    fprintf(fp, "%*sPlane 0 Stride: %u\n", indent, "", values->plane_0_stride);
   4390    fprintf(fp, "%*sPlane 1 2 Stride: %u\n", indent, "", values->plane_1_2_stride);
   4391 }
   4392 
   4393 struct MALI_RENDER_TARGET_AFBC_OVERLAY {
   4394    uint64_t                             header;
   4395    uint32_t                             row_stride;
   4396    uint32_t                             chunk_size;
   4397    bool                                 afbc_split_block_enable;
   4398    bool                                 afbc_wide_block_enable;
   4399    bool                                 reverse_issue_order;
   4400    bool                                 yuv_transform_enable;
   4401    uint64_t                             body;
   4402    uint32_t                             body_size;
   4403 };
   4404 
   4405 #define MALI_RENDER_TARGET_AFBC_OVERLAY_header  \
   4406    0
   4407 
   4408 static inline void
   4409 MALI_RENDER_TARGET_AFBC_OVERLAY_pack(uint32_t * restrict cl,
   4410                                      const struct MALI_RENDER_TARGET_AFBC_OVERLAY * restrict values)
   4411 {
   4412    cl[ 0] = 0;
   4413    cl[ 1] = 0;
   4414    cl[ 2] = 0;
   4415    cl[ 3] = 0;
   4416    cl[ 4] = __gen_uint(values->header, 0, 63);
   4417    cl[ 5] = __gen_uint(values->header, 0, 63) >> 32;
   4418    cl[ 6] = __gen_uint(values->row_stride, 0, 12);
   4419    cl[ 7] = __gen_uint(values->chunk_size, 0, 11) |
   4420             __gen_uint(values->afbc_split_block_enable, 18, 18) |
   4421             __gen_uint(values->afbc_wide_block_enable, 19, 19) |
   4422             __gen_uint(values->reverse_issue_order, 20, 20) |
   4423             __gen_uint(values->yuv_transform_enable, 17, 17);
   4424    cl[ 8] = __gen_uint(values->body, 0, 63);
   4425    cl[ 9] = __gen_uint(values->body, 0, 63) >> 32;
   4426    cl[10] = __gen_uint(values->body_size, 0, 31);
   4427    cl[11] = 0;
   4428    cl[12] = 0;
   4429    cl[13] = 0;
   4430    cl[14] = 0;
   4431    cl[15] = 0;
   4432 }
   4433 
   4434 
   4435 #define MALI_RENDER_TARGET_AFBC_OVERLAY_LENGTH 64
   4436 struct mali_render_target_afbc_overlay_packed { uint32_t opaque[16]; };
   4437 static inline void
   4438 MALI_RENDER_TARGET_AFBC_OVERLAY_unpack(const uint8_t * restrict cl,
   4439                                        struct MALI_RENDER_TARGET_AFBC_OVERLAY * restrict values)
   4440 {
   4441    if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 0\n");
   4442    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 1\n");
   4443    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 2\n");
   4444    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 3\n");
   4445    if (((const uint32_t *) cl)[6] & 0xffffe000) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 6\n");
   4446    if (((const uint32_t *) cl)[7] & 0xffe1f000) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 7\n");
   4447    if (((const uint32_t *) cl)[11] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 11\n");
   4448    if (((const uint32_t *) cl)[12] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 12\n");
   4449    if (((const uint32_t *) cl)[13] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 13\n");
   4450    if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 14\n");
   4451    if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 15\n");
   4452    values->header = __gen_unpack_uint(cl, 128, 191);
   4453    values->row_stride = __gen_unpack_uint(cl, 192, 204);
   4454    values->chunk_size = __gen_unpack_uint(cl, 224, 235);
   4455    values->afbc_split_block_enable = __gen_unpack_uint(cl, 242, 242);
   4456    values->afbc_wide_block_enable = __gen_unpack_uint(cl, 243, 243);
   4457    values->reverse_issue_order = __gen_unpack_uint(cl, 244, 244);
   4458    values->yuv_transform_enable = __gen_unpack_uint(cl, 241, 241);
   4459    values->body = __gen_unpack_uint(cl, 256, 319);
   4460    values->body_size = __gen_unpack_uint(cl, 320, 351);
   4461 }
   4462 
   4463 static inline void
   4464 MALI_RENDER_TARGET_AFBC_OVERLAY_print(FILE *fp, const struct MALI_RENDER_TARGET_AFBC_OVERLAY * values, unsigned indent)
   4465 {
   4466    fprintf(fp, "%*sHeader: 0x%" PRIx64 "\n", indent, "", values->header);
   4467    fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
   4468    fprintf(fp, "%*sChunk Size: %u\n", indent, "", values->chunk_size);
   4469    fprintf(fp, "%*sAFBC Split Block Enable: %s\n", indent, "", values->afbc_split_block_enable ? "true" : "false");
   4470    fprintf(fp, "%*sAFBC Wide Block Enable: %s\n", indent, "", values->afbc_wide_block_enable ? "true" : "false");
   4471    fprintf(fp, "%*sReverse Issue Order: %s\n", indent, "", values->reverse_issue_order ? "true" : "false");
   4472    fprintf(fp, "%*sYUV Transform Enable: %s\n", indent, "", values->yuv_transform_enable ? "true" : "false");
   4473    fprintf(fp, "%*sBody: 0x%" PRIx64 "\n", indent, "", values->body);
   4474    fprintf(fp, "%*sBody Size: %u\n", indent, "", values->body_size);
   4475 }
   4476 
   4477 struct MALI_RT_CLEAR {
   4478    uint32_t                             color_0;
   4479    uint32_t                             color_1;
   4480    uint32_t                             color_2;
   4481    uint32_t                             color_3;
   4482 };
   4483 
   4484 #define MALI_RT_CLEAR_header                    \
   4485    0
   4486 
   4487 static inline void
   4488 MALI_RT_CLEAR_pack(uint32_t * restrict cl,
   4489                    const struct MALI_RT_CLEAR * restrict values)
   4490 {
   4491    cl[ 0] = __gen_uint(values->color_0, 0, 31);
   4492    cl[ 1] = __gen_uint(values->color_1, 0, 31);
   4493    cl[ 2] = __gen_uint(values->color_2, 0, 31);
   4494    cl[ 3] = __gen_uint(values->color_3, 0, 31);
   4495 }
   4496 
   4497 
   4498 #define MALI_RT_CLEAR_LENGTH 16
   4499 struct mali_rt_clear_packed { uint32_t opaque[4]; };
   4500 static inline void
   4501 MALI_RT_CLEAR_unpack(const uint8_t * restrict cl,
   4502                      struct MALI_RT_CLEAR * restrict values)
   4503 {
   4504    values->color_0 = __gen_unpack_uint(cl, 0, 31);
   4505    values->color_1 = __gen_unpack_uint(cl, 32, 63);
   4506    values->color_2 = __gen_unpack_uint(cl, 64, 95);
   4507    values->color_3 = __gen_unpack_uint(cl, 96, 127);
   4508 }
   4509 
   4510 static inline void
   4511 MALI_RT_CLEAR_print(FILE *fp, const struct MALI_RT_CLEAR * values, unsigned indent)
   4512 {
   4513    fprintf(fp, "%*sColor 0: %u\n", indent, "", values->color_0);
   4514    fprintf(fp, "%*sColor 1: %u\n", indent, "", values->color_1);
   4515    fprintf(fp, "%*sColor 2: %u\n", indent, "", values->color_2);
   4516    fprintf(fp, "%*sColor 3: %u\n", indent, "", values->color_3);
   4517 }
   4518 
   4519 struct MALI_RENDER_TARGET {
   4520    struct MALI_RENDER_TARGET_YUV_OVERLAY yuv;
   4521    struct MALI_RENDER_TARGET_AFBC_OVERLAY afbc;
   4522    uint32_t                             internal_buffer_offset;
   4523    bool                                 yuv_enable;
   4524    bool                                 dithered_clear;
   4525    enum mali_color_buffer_internal_format internal_format;
   4526    bool                                 write_enable;
   4527    enum mali_color_format               writeback_format;
   4528    enum mali_block_format               writeback_block_format;
   4529    enum mali_msaa                       writeback_msaa;
   4530    bool                                 srgb;
   4531    bool                                 dithering_enable;
   4532    uint32_t                             swizzle;
   4533    bool                                 clean_pixel_write_enable;
   4534    struct MALI_RT_BUFFER                rgb;
   4535    struct MALI_RT_CLEAR                 clear;
   4536 };
   4537 
   4538 #define MALI_RENDER_TARGET_header               \
   4539    .yuv = { MALI_RENDER_TARGET_YUV_OVERLAY_header },  \
   4540    .afbc = { MALI_RENDER_TARGET_AFBC_OVERLAY_header },  \
   4541    .rgb = { MALI_RT_BUFFER_header },  \
   4542    .clear = { MALI_RT_CLEAR_header }
   4543 
   4544 static inline void
   4545 MALI_RENDER_TARGET_pack(uint32_t * restrict cl,
   4546                         const struct MALI_RENDER_TARGET * restrict values)
   4547 {
   4548    assert((values->internal_buffer_offset & 0xf) == 0);
   4549    cl[ 0] = __gen_uint(values->internal_buffer_offset >> 4, 4, 15) |
   4550             __gen_uint(values->yuv_enable, 24, 24) |
   4551             __gen_uint(values->dithered_clear, 25, 25) |
   4552             __gen_uint(values->internal_format, 26, 31);
   4553    cl[ 1] = __gen_uint(values->write_enable, 0, 0) |
   4554             __gen_uint(values->writeback_format, 3, 7) |
   4555             __gen_uint(values->writeback_block_format, 8, 11) |
   4556             __gen_uint(values->writeback_msaa, 12, 13) |
   4557             __gen_uint(values->srgb, 14, 14) |
   4558             __gen_uint(values->dithering_enable, 15, 15) |
   4559             __gen_uint(values->swizzle, 16, 27) |
   4560             __gen_uint(values->clean_pixel_write_enable, 31, 31);
   4561    cl[ 2] = __gen_uint(values->yuv.swizzle, 16, 18) |
   4562             __gen_uint(values->yuv.full_range, 20, 20) |
   4563             __gen_uint(values->yuv.conversion_mode, 21, 24) |
   4564             __gen_uint(values->yuv.cr_siting, 25, 27) |
   4565             __gen_uint(values->yuv.unsigned_cr_range, 28, 28);
   4566    cl[ 3] = 0;
   4567    cl[ 4] = __gen_uint(values->yuv.plane_0_base, 0, 63) |
   4568             __gen_uint(values->afbc.header, 0, 63);
   4569    cl[ 5] = __gen_uint(values->yuv.plane_0_base, 0, 63) >> 32 |
   4570             __gen_uint(values->afbc.header, 0, 63) >> 32;
   4571    cl[ 6] = __gen_uint(values->yuv.plane_1_base, 0, 63) |
   4572             __gen_uint(values->afbc.row_stride, 0, 12);
   4573    cl[ 7] = __gen_uint(values->yuv.plane_1_base, 0, 63) >> 32 |
   4574             __gen_uint(values->afbc.chunk_size, 0, 11) |
   4575             __gen_uint(values->afbc.afbc_split_block_enable, 18, 18) |
   4576             __gen_uint(values->afbc.afbc_wide_block_enable, 19, 19) |
   4577             __gen_uint(values->afbc.reverse_issue_order, 20, 20) |
   4578             __gen_uint(values->afbc.yuv_transform_enable, 17, 17);
   4579    cl[ 8] = __gen_uint(values->yuv.plane_2_base, 0, 63) |
   4580             __gen_uint(values->afbc.body, 0, 63) |
   4581             __gen_uint(values->rgb.base, 0, 63);
   4582    cl[ 9] = __gen_uint(values->yuv.plane_2_base, 0, 63) >> 32 |
   4583             __gen_uint(values->afbc.body, 0, 63) >> 32 |
   4584             __gen_uint(values->rgb.base, 0, 63) >> 32;
   4585    cl[10] = __gen_uint(values->yuv.plane_0_stride, 0, 31) |
   4586             __gen_uint(values->afbc.body_size, 0, 31) |
   4587             __gen_uint(values->rgb.row_stride, 0, 31);
   4588    cl[11] = __gen_uint(values->yuv.plane_1_2_stride, 0, 31) |
   4589             __gen_uint(values->rgb.surface_stride, 0, 31);
   4590    cl[12] = __gen_uint(values->clear.color_0, 0, 31);
   4591    cl[13] = __gen_uint(values->clear.color_1, 0, 31);
   4592    cl[14] = __gen_uint(values->clear.color_2, 0, 31);
   4593    cl[15] = __gen_uint(values->clear.color_3, 0, 31);
   4594 }
   4595 
   4596 
   4597 #define MALI_RENDER_TARGET_LENGTH 64
   4598 #define MALI_RENDER_TARGET_ALIGN 64
   4599 struct mali_render_target_packed { uint32_t opaque[16]; };
   4600 static inline void
   4601 MALI_RENDER_TARGET_unpack(const uint8_t * restrict cl,
   4602                           struct MALI_RENDER_TARGET * restrict values)
   4603 {
   4604    if (((const uint32_t *) cl)[0] & 0xff000f) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 0\n");
   4605    if (((const uint32_t *) cl)[1] & 0x70000006) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 1\n");
   4606    if (((const uint32_t *) cl)[2] & 0xe008ffff) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 2\n");
   4607    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 3\n");
   4608    values->yuv.swizzle = (enum mali_yuv_swizzle)__gen_unpack_uint(cl, 80, 82);
   4609    values->yuv.full_range = __gen_unpack_uint(cl, 84, 84);
   4610    values->yuv.conversion_mode = (enum mali_yuv_conversion_mode)__gen_unpack_uint(cl, 85, 88);
   4611    values->yuv.cr_siting = (enum mali_yuv_cr_siting)__gen_unpack_uint(cl, 89, 91);
   4612    values->yuv.unsigned_cr_range = __gen_unpack_uint(cl, 92, 92);
   4613    values->yuv.plane_0_base = __gen_unpack_uint(cl, 128, 191);
   4614    values->yuv.plane_1_base = __gen_unpack_uint(cl, 192, 255);
   4615    values->yuv.plane_2_base = __gen_unpack_uint(cl, 256, 319);
   4616    values->yuv.plane_0_stride = __gen_unpack_uint(cl, 320, 351);
   4617    values->yuv.plane_1_2_stride = __gen_unpack_uint(cl, 352, 383);
   4618    values->afbc.header = __gen_unpack_uint(cl, 128, 191);
   4619    values->afbc.row_stride = __gen_unpack_uint(cl, 192, 204);
   4620    values->afbc.chunk_size = __gen_unpack_uint(cl, 224, 235);
   4621    values->afbc.afbc_split_block_enable = __gen_unpack_uint(cl, 242, 242);
   4622    values->afbc.afbc_wide_block_enable = __gen_unpack_uint(cl, 243, 243);
   4623    values->afbc.reverse_issue_order = __gen_unpack_uint(cl, 244, 244);
   4624    values->afbc.yuv_transform_enable = __gen_unpack_uint(cl, 241, 241);
   4625    values->afbc.body = __gen_unpack_uint(cl, 256, 319);
   4626    values->afbc.body_size = __gen_unpack_uint(cl, 320, 351);
   4627    values->internal_buffer_offset = __gen_unpack_uint(cl, 4, 15) << 4;
   4628    values->yuv_enable = __gen_unpack_uint(cl, 24, 24);
   4629    values->dithered_clear = __gen_unpack_uint(cl, 25, 25);
   4630    values->internal_format = (enum mali_color_buffer_internal_format)__gen_unpack_uint(cl, 26, 31);
   4631    values->write_enable = __gen_unpack_uint(cl, 32, 32);
   4632    values->writeback_format = (enum mali_color_format)__gen_unpack_uint(cl, 35, 39);
   4633    values->writeback_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 40, 43);
   4634    values->writeback_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 44, 45);
   4635    values->srgb = __gen_unpack_uint(cl, 46, 46);
   4636    values->dithering_enable = __gen_unpack_uint(cl, 47, 47);
   4637    values->swizzle = __gen_unpack_uint(cl, 48, 59);
   4638    values->clean_pixel_write_enable = __gen_unpack_uint(cl, 63, 63);
   4639    values->rgb.base = __gen_unpack_uint(cl, 256, 319);
   4640    values->rgb.row_stride = __gen_unpack_uint(cl, 320, 351);
   4641    values->rgb.surface_stride = __gen_unpack_uint(cl, 352, 383);
   4642    values->clear.color_0 = __gen_unpack_uint(cl, 384, 415);
   4643    values->clear.color_1 = __gen_unpack_uint(cl, 416, 447);
   4644    values->clear.color_2 = __gen_unpack_uint(cl, 448, 479);
   4645    values->clear.color_3 = __gen_unpack_uint(cl, 480, 511);
   4646 }
   4647 
   4648 static inline void
   4649 MALI_RENDER_TARGET_print(FILE *fp, const struct MALI_RENDER_TARGET * values, unsigned indent)
   4650 {
   4651    fprintf(fp, "%*sYUV:\n", indent, "");
   4652    MALI_RENDER_TARGET_YUV_OVERLAY_print(fp, &values->yuv, indent + 2);
   4653    fprintf(fp, "%*sAFBC:\n", indent, "");
   4654    MALI_RENDER_TARGET_AFBC_OVERLAY_print(fp, &values->afbc, indent + 2);
   4655    fprintf(fp, "%*sInternal Buffer Offset: %u\n", indent, "", values->internal_buffer_offset);
   4656    fprintf(fp, "%*sYUV Enable: %s\n", indent, "", values->yuv_enable ? "true" : "false");
   4657    fprintf(fp, "%*sDithered Clear: %s\n", indent, "", values->dithered_clear ? "true" : "false");
   4658    fprintf(fp, "%*sInternal Format: %s\n", indent, "", mali_color_buffer_internal_format_as_str(values->internal_format));
   4659    fprintf(fp, "%*sWrite Enable: %s\n", indent, "", values->write_enable ? "true" : "false");
   4660    fprintf(fp, "%*sWriteback Format: %s\n", indent, "", mali_color_format_as_str(values->writeback_format));
   4661    fprintf(fp, "%*sWriteback Block Format: %s\n", indent, "", mali_block_format_as_str(values->writeback_block_format));
   4662    fprintf(fp, "%*sWriteback MSAA: %s\n", indent, "", mali_msaa_as_str(values->writeback_msaa));
   4663    fprintf(fp, "%*ssRGB: %s\n", indent, "", values->srgb ? "true" : "false");
   4664    fprintf(fp, "%*sDithering Enable: %s\n", indent, "", values->dithering_enable ? "true" : "false");
   4665    fprintf(fp, "%*sSwizzle: %u\n", indent, "", values->swizzle);
   4666    fprintf(fp, "%*sClean Pixel Write Enable: %s\n", indent, "", values->clean_pixel_write_enable ? "true" : "false");
   4667    fprintf(fp, "%*sRGB:\n", indent, "");
   4668    MALI_RT_BUFFER_print(fp, &values->rgb, indent + 2);
   4669    fprintf(fp, "%*sClear:\n", indent, "");
   4670    MALI_RT_CLEAR_print(fp, &values->clear, indent + 2);
   4671 }
   4672 
   4673 struct MALI_TILER_HEAP {
   4674    uint32_t                             size;
   4675    uint64_t                             base;
   4676    uint64_t                             bottom;
   4677    uint64_t                             top;
   4678 };
   4679 
   4680 #define MALI_TILER_HEAP_header                  \
   4681    0
   4682 
   4683 static inline void
   4684 MALI_TILER_HEAP_pack(uint32_t * restrict cl,
   4685                      const struct MALI_TILER_HEAP * restrict values)
   4686 {
   4687    cl[ 0] = 0;
   4688    cl[ 1] = __gen_uint(ALIGN_POT(values->size, 4096), 0, 31);
   4689    cl[ 2] = __gen_uint(values->base, 0, 63);
   4690    cl[ 3] = __gen_uint(values->base, 0, 63) >> 32;
   4691    cl[ 4] = __gen_uint(values->bottom, 0, 63);
   4692    cl[ 5] = __gen_uint(values->bottom, 0, 63) >> 32;
   4693    cl[ 6] = __gen_uint(values->top, 0, 63);
   4694    cl[ 7] = __gen_uint(values->top, 0, 63) >> 32;
   4695 }
   4696 
   4697 
   4698 #define MALI_TILER_HEAP_LENGTH 32
   4699 #define MALI_TILER_HEAP_ALIGN 64
   4700 struct mali_tiler_heap_packed { uint32_t opaque[8]; };
   4701 static inline void
   4702 MALI_TILER_HEAP_unpack(const uint8_t * restrict cl,
   4703                        struct MALI_TILER_HEAP * restrict values)
   4704 {
   4705    if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Heap unpacked at word 0\n");
   4706    values->size = __gen_unpack_uint(cl, 32, 63);
   4707    assert(!(values->size & 0xfff));
   4708    values->base = __gen_unpack_uint(cl, 64, 127);
   4709    values->bottom = __gen_unpack_uint(cl, 128, 191);
   4710    values->top = __gen_unpack_uint(cl, 192, 255);
   4711 }
   4712 
   4713 static inline void
   4714 MALI_TILER_HEAP_print(FILE *fp, const struct MALI_TILER_HEAP * values, unsigned indent)
   4715 {
   4716    fprintf(fp, "%*sSize: %u\n", indent, "", values->size);
   4717    fprintf(fp, "%*sBase: 0x%" PRIx64 "\n", indent, "", values->base);
   4718    fprintf(fp, "%*sBottom: 0x%" PRIx64 "\n", indent, "", values->bottom);
   4719    fprintf(fp, "%*sTop: 0x%" PRIx64 "\n", indent, "", values->top);
   4720 }
   4721 
   4722 struct MALI_TILER_WEIGHTS {
   4723    uint32_t                             weight0;
   4724    uint32_t                             weight1;
   4725    uint32_t                             weight2;
   4726    uint32_t                             weight3;
   4727    uint32_t                             weight4;
   4728    uint32_t                             weight5;
   4729    uint32_t                             weight6;
   4730    uint32_t                             weight7;
   4731 };
   4732 
   4733 #define MALI_TILER_WEIGHTS_header               \
   4734    0
   4735 
   4736 static inline void
   4737 MALI_TILER_WEIGHTS_pack(uint32_t * restrict cl,
   4738                         const struct MALI_TILER_WEIGHTS * restrict values)
   4739 {
   4740    cl[ 0] = __gen_uint(values->weight0, 16, 31);
   4741    cl[ 1] = __gen_uint(values->weight1, 16, 31);
   4742    cl[ 2] = __gen_uint(values->weight2, 16, 31);
   4743    cl[ 3] = __gen_uint(values->weight3, 16, 31);
   4744    cl[ 4] = __gen_uint(values->weight4, 16, 31);
   4745    cl[ 5] = __gen_uint(values->weight5, 16, 31);
   4746    cl[ 6] = __gen_uint(values->weight6, 16, 31);
   4747    cl[ 7] = __gen_uint(values->weight7, 16, 31);
   4748 }
   4749 
   4750 
   4751 #define MALI_TILER_WEIGHTS_LENGTH 32
   4752 struct mali_tiler_weights_packed { uint32_t opaque[8]; };
   4753 static inline void
   4754 MALI_TILER_WEIGHTS_unpack(const uint8_t * restrict cl,
   4755                           struct MALI_TILER_WEIGHTS * restrict values)
   4756 {
   4757    if (((const uint32_t *) cl)[0] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 0\n");
   4758    if (((const uint32_t *) cl)[1] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 1\n");
   4759    if (((const uint32_t *) cl)[2] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 2\n");
   4760    if (((const uint32_t *) cl)[3] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 3\n");
   4761    if (((const uint32_t *) cl)[4] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 4\n");
   4762    if (((const uint32_t *) cl)[5] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 5\n");
   4763    if (((const uint32_t *) cl)[6] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 6\n");
   4764    if (((const uint32_t *) cl)[7] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Weights unpacked at word 7\n");
   4765    values->weight0 = __gen_unpack_uint(cl, 16, 31);
   4766    values->weight1 = __gen_unpack_uint(cl, 48, 63);
   4767    values->weight2 = __gen_unpack_uint(cl, 80, 95);
   4768    values->weight3 = __gen_unpack_uint(cl, 112, 127);
   4769    values->weight4 = __gen_unpack_uint(cl, 144, 159);
   4770    values->weight5 = __gen_unpack_uint(cl, 176, 191);
   4771    values->weight6 = __gen_unpack_uint(cl, 208, 223);
   4772    values->weight7 = __gen_unpack_uint(cl, 240, 255);
   4773 }
   4774 
   4775 static inline void
   4776 MALI_TILER_WEIGHTS_print(FILE *fp, const struct MALI_TILER_WEIGHTS * values, unsigned indent)
   4777 {
   4778    fprintf(fp, "%*sWeight0: %u\n", indent, "", values->weight0);
   4779    fprintf(fp, "%*sWeight1: %u\n", indent, "", values->weight1);
   4780    fprintf(fp, "%*sWeight2: %u\n", indent, "", values->weight2);
   4781    fprintf(fp, "%*sWeight3: %u\n", indent, "", values->weight3);
   4782    fprintf(fp, "%*sWeight4: %u\n", indent, "", values->weight4);
   4783    fprintf(fp, "%*sWeight5: %u\n", indent, "", values->weight5);
   4784    fprintf(fp, "%*sWeight6: %u\n", indent, "", values->weight6);
   4785    fprintf(fp, "%*sWeight7: %u\n", indent, "", values->weight7);
   4786 }
   4787 
   4788 struct MALI_TILER_STATE {
   4789    uint32_t                             word0;
   4790    uint32_t                             word1;
   4791    uint32_t                             word2;
   4792    uint32_t                             word3;
   4793    uint32_t                             word4;
   4794    uint32_t                             word5;
   4795    uint32_t                             word6;
   4796    uint32_t                             word7;
   4797    uint32_t                             word8;
   4798    uint32_t                             word9;
   4799    uint32_t                             word10;
   4800    uint32_t                             word11;
   4801    uint32_t                             word12;
   4802    uint32_t                             word13;
   4803    uint32_t                             word14;
   4804    uint32_t                             word15;
   4805 };
   4806 
   4807 #define MALI_TILER_STATE_header                 \
   4808    0
   4809 
   4810 static inline void
   4811 MALI_TILER_STATE_pack(uint32_t * restrict cl,
   4812                       const struct MALI_TILER_STATE * restrict values)
   4813 {
   4814    cl[ 0] = __gen_uint(values->word0, 0, 31);
   4815    cl[ 1] = __gen_uint(values->word1, 0, 31);
   4816    cl[ 2] = __gen_uint(values->word2, 0, 31);
   4817    cl[ 3] = __gen_uint(values->word3, 0, 31);
   4818    cl[ 4] = __gen_uint(values->word4, 0, 31);
   4819    cl[ 5] = __gen_uint(values->word5, 0, 31);
   4820    cl[ 6] = __gen_uint(values->word6, 0, 31);
   4821    cl[ 7] = __gen_uint(values->word7, 0, 31);
   4822    cl[ 8] = __gen_uint(values->word8, 0, 31);
   4823    cl[ 9] = __gen_uint(values->word9, 0, 31);
   4824    cl[10] = __gen_uint(values->word10, 0, 31);
   4825    cl[11] = __gen_uint(values->word11, 0, 31);
   4826    cl[12] = __gen_uint(values->word12, 0, 31);
   4827    cl[13] = __gen_uint(values->word13, 0, 31);
   4828    cl[14] = __gen_uint(values->word14, 0, 31);
   4829    cl[15] = __gen_uint(values->word15, 0, 31);
   4830 }
   4831 
   4832 
   4833 #define MALI_TILER_STATE_LENGTH 64
   4834 struct mali_tiler_state_packed { uint32_t opaque[16]; };
   4835 static inline void
   4836 MALI_TILER_STATE_unpack(const uint8_t * restrict cl,
   4837                         struct MALI_TILER_STATE * restrict values)
   4838 {
   4839    values->word0 = __gen_unpack_uint(cl, 0, 31);
   4840    values->word1 = __gen_unpack_uint(cl, 32, 63);
   4841    values->word2 = __gen_unpack_uint(cl, 64, 95);
   4842    values->word3 = __gen_unpack_uint(cl, 96, 127);
   4843    values->word4 = __gen_unpack_uint(cl, 128, 159);
   4844    values->word5 = __gen_unpack_uint(cl, 160, 191);
   4845    values->word6 = __gen_unpack_uint(cl, 192, 223);
   4846    values->word7 = __gen_unpack_uint(cl, 224, 255);
   4847    values->word8 = __gen_unpack_uint(cl, 256, 287);
   4848    values->word9 = __gen_unpack_uint(cl, 288, 319);
   4849    values->word10 = __gen_unpack_uint(cl, 320, 351);
   4850    values->word11 = __gen_unpack_uint(cl, 352, 383);
   4851    values->word12 = __gen_unpack_uint(cl, 384, 415);
   4852    values->word13 = __gen_unpack_uint(cl, 416, 447);
   4853    values->word14 = __gen_unpack_uint(cl, 448, 479);
   4854    values->word15 = __gen_unpack_uint(cl, 480, 511);
   4855 }
   4856 
   4857 static inline void
   4858 MALI_TILER_STATE_print(FILE *fp, const struct MALI_TILER_STATE * values, unsigned indent)
   4859 {
   4860    fprintf(fp, "%*sWord0: %u\n", indent, "", values->word0);
   4861    fprintf(fp, "%*sWord1: %u\n", indent, "", values->word1);
   4862    fprintf(fp, "%*sWord2: %u\n", indent, "", values->word2);
   4863    fprintf(fp, "%*sWord3: %u\n", indent, "", values->word3);
   4864    fprintf(fp, "%*sWord4: %u\n", indent, "", values->word4);
   4865    fprintf(fp, "%*sWord5: %u\n", indent, "", values->word5);
   4866    fprintf(fp, "%*sWord6: %u\n", indent, "", values->word6);
   4867    fprintf(fp, "%*sWord7: %u\n", indent, "", values->word7);
   4868    fprintf(fp, "%*sWord8: %u\n", indent, "", values->word8);
   4869    fprintf(fp, "%*sWord9: %u\n", indent, "", values->word9);
   4870    fprintf(fp, "%*sWord10: %u\n", indent, "", values->word10);
   4871    fprintf(fp, "%*sWord11: %u\n", indent, "", values->word11);
   4872    fprintf(fp, "%*sWord12: %u\n", indent, "", values->word12);
   4873    fprintf(fp, "%*sWord13: %u\n", indent, "", values->word13);
   4874    fprintf(fp, "%*sWord14: %u\n", indent, "", values->word14);
   4875    fprintf(fp, "%*sWord15: %u\n", indent, "", values->word15);
   4876 }
   4877 
   4878 struct MALI_TILER_CONTEXT {
   4879    uint64_t                             polygon_list;
   4880    uint32_t                             hierarchy_mask;
   4881    enum mali_sample_pattern             sample_pattern;
   4882    bool                                 update_cost_table;
   4883    uint32_t                             fb_width;
   4884    uint32_t                             fb_height;
   4885    uint64_t                             heap;
   4886    struct MALI_TILER_WEIGHTS            weights;
   4887    struct MALI_TILER_STATE              state;
   4888 };
   4889 
   4890 #define MALI_TILER_CONTEXT_header               \
   4891    .weights = { MALI_TILER_WEIGHTS_header },  \
   4892    .state = { MALI_TILER_STATE_header }
   4893 
   4894 static inline void
   4895 MALI_TILER_CONTEXT_pack(uint32_t * restrict cl,
   4896                         const struct MALI_TILER_CONTEXT * restrict values)
   4897 {
   4898    assert(values->fb_width >= 1);
   4899    assert(values->fb_height >= 1);
   4900    cl[ 0] = __gen_uint(values->polygon_list, 0, 63);
   4901    cl[ 1] = __gen_uint(values->polygon_list, 0, 63) >> 32;
   4902    cl[ 2] = __gen_uint(values->hierarchy_mask, 0, 12) |
   4903             __gen_uint(values->sample_pattern, 13, 15) |
   4904             __gen_uint(values->update_cost_table, 16, 16);
   4905    cl[ 3] = __gen_uint(values->fb_width - 1, 0, 15) |
   4906             __gen_uint(values->fb_height - 1, 16, 31);
   4907    cl[ 4] = 0;
   4908    cl[ 5] = 0;
   4909    cl[ 6] = __gen_uint(values->heap, 0, 63);
   4910    cl[ 7] = __gen_uint(values->heap, 0, 63) >> 32;
   4911    cl[ 8] = __gen_uint(values->weights.weight0, 16, 31);
   4912    cl[ 9] = __gen_uint(values->weights.weight1, 16, 31);
   4913    cl[10] = __gen_uint(values->weights.weight2, 16, 31);
   4914    cl[11] = __gen_uint(values->weights.weight3, 16, 31);
   4915    cl[12] = __gen_uint(values->weights.weight4, 16, 31);
   4916    cl[13] = __gen_uint(values->weights.weight5, 16, 31);
   4917    cl[14] = __gen_uint(values->weights.weight6, 16, 31);
   4918    cl[15] = __gen_uint(values->weights.weight7, 16, 31);
   4919    cl[16] = 0;
   4920    cl[17] = 0;
   4921    cl[18] = 0;
   4922    cl[19] = 0;
   4923    cl[20] = 0;
   4924    cl[21] = 0;
   4925    cl[22] = 0;
   4926    cl[23] = 0;
   4927    cl[24] = 0;
   4928    cl[25] = 0;
   4929    cl[26] = 0;
   4930    cl[27] = 0;
   4931    cl[28] = 0;
   4932    cl[29] = 0;
   4933    cl[30] = 0;
   4934    cl[31] = 0;
   4935    cl[32] = __gen_uint(values->state.word0, 0, 31);
   4936    cl[33] = __gen_uint(values->state.word1, 0, 31);
   4937    cl[34] = __gen_uint(values->state.word2, 0, 31);
   4938    cl[35] = __gen_uint(values->state.word3, 0, 31);
   4939    cl[36] = __gen_uint(values->state.word4, 0, 31);
   4940    cl[37] = __gen_uint(values->state.word5, 0, 31);
   4941    cl[38] = __gen_uint(values->state.word6, 0, 31);
   4942    cl[39] = __gen_uint(values->state.word7, 0, 31);
   4943    cl[40] = __gen_uint(values->state.word8, 0, 31);
   4944    cl[41] = __gen_uint(values->state.word9, 0, 31);
   4945    cl[42] = __gen_uint(values->state.word10, 0, 31);
   4946    cl[43] = __gen_uint(values->state.word11, 0, 31);
   4947    cl[44] = __gen_uint(values->state.word12, 0, 31);
   4948    cl[45] = __gen_uint(values->state.word13, 0, 31);
   4949    cl[46] = __gen_uint(values->state.word14, 0, 31);
   4950    cl[47] = __gen_uint(values->state.word15, 0, 31);
   4951 }
   4952 
   4953 
   4954 #define MALI_TILER_CONTEXT_LENGTH 192
   4955 #define MALI_TILER_CONTEXT_ALIGN 64
   4956 struct mali_tiler_context_packed { uint32_t opaque[48]; };
   4957 static inline void
   4958 MALI_TILER_CONTEXT_unpack(const uint8_t * restrict cl,
   4959                           struct MALI_TILER_CONTEXT * restrict values)
   4960 {
   4961    if (((const uint32_t *) cl)[2] & 0xfffe0000) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 2\n");
   4962    if (((const uint32_t *) cl)[4] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 4\n");
   4963    if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 5\n");
   4964    if (((const uint32_t *) cl)[8] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 8\n");
   4965    if (((const uint32_t *) cl)[9] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 9\n");
   4966    if (((const uint32_t *) cl)[10] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 10\n");
   4967    if (((const uint32_t *) cl)[11] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 11\n");
   4968    if (((const uint32_t *) cl)[12] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 12\n");
   4969    if (((const uint32_t *) cl)[13] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 13\n");
   4970    if (((const uint32_t *) cl)[14] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 14\n");
   4971    if (((const uint32_t *) cl)[15] & 0xffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 15\n");
   4972    if (((const uint32_t *) cl)[16] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 16\n");
   4973    if (((const uint32_t *) cl)[17] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 17\n");
   4974    if (((const uint32_t *) cl)[18] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 18\n");
   4975    if (((const uint32_t *) cl)[19] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 19\n");
   4976    if (((const uint32_t *) cl)[20] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 20\n");
   4977    if (((const uint32_t *) cl)[21] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 21\n");
   4978    if (((const uint32_t *) cl)[22] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 22\n");
   4979    if (((const uint32_t *) cl)[23] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 23\n");
   4980    if (((const uint32_t *) cl)[24] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 24\n");
   4981    if (((const uint32_t *) cl)[25] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 25\n");
   4982    if (((const uint32_t *) cl)[26] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 26\n");
   4983    if (((const uint32_t *) cl)[27] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 27\n");
   4984    if (((const uint32_t *) cl)[28] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 28\n");
   4985    if (((const uint32_t *) cl)[29] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 29\n");
   4986    if (((const uint32_t *) cl)[30] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 30\n");
   4987    if (((const uint32_t *) cl)[31] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 31\n");
   4988    values->polygon_list = __gen_unpack_uint(cl, 0, 63);
   4989    values->hierarchy_mask = __gen_unpack_uint(cl, 64, 76);
   4990    values->sample_pattern = (enum mali_sample_pattern)__gen_unpack_uint(cl, 77, 79);
   4991    values->update_cost_table = __gen_unpack_uint(cl, 80, 80);
   4992    values->fb_width = __gen_unpack_uint(cl, 96, 111) + 1;
   4993    values->fb_height = __gen_unpack_uint(cl, 112, 127) + 1;
   4994    values->heap = __gen_unpack_uint(cl, 192, 255);
   4995    values->weights.weight0 = __gen_unpack_uint(cl, 272, 287);
   4996    values->weights.weight1 = __gen_unpack_uint(cl, 304, 319);
   4997    values->weights.weight2 = __gen_unpack_uint(cl, 336, 351);
   4998    values->weights.weight3 = __gen_unpack_uint(cl, 368, 383);
   4999    values->weights.weight4 = __gen_unpack_uint(cl, 400, 415);
   5000    values->weights.weight5 = __gen_unpack_uint(cl, 432, 447);
   5001    values->weights.weight6 = __gen_unpack_uint(cl, 464, 479);
   5002    values->weights.weight7 = __gen_unpack_uint(cl, 496, 511);
   5003    values->state.word0 = __gen_unpack_uint(cl, 1024, 1055);
   5004    values->state.word1 = __gen_unpack_uint(cl, 1056, 1087);
   5005    values->state.word2 = __gen_unpack_uint(cl, 1088, 1119);
   5006    values->state.word3 = __gen_unpack_uint(cl, 1120, 1151);
   5007    values->state.word4 = __gen_unpack_uint(cl, 1152, 1183);
   5008    values->state.word5 = __gen_unpack_uint(cl, 1184, 1215);
   5009    values->state.word6 = __gen_unpack_uint(cl, 1216, 1247);
   5010    values->state.word7 = __gen_unpack_uint(cl, 1248, 1279);
   5011    values->state.word8 = __gen_unpack_uint(cl, 1280, 1311);
   5012    values->state.word9 = __gen_unpack_uint(cl, 1312, 1343);
   5013    values->state.word10 = __gen_unpack_uint(cl, 1344, 1375);
   5014    values->state.word11 = __gen_unpack_uint(cl, 1376, 1407);
   5015    values->state.word12 = __gen_unpack_uint(cl, 1408, 1439);
   5016    values->state.word13 = __gen_unpack_uint(cl, 1440, 1471);
   5017    values->state.word14 = __gen_unpack_uint(cl, 1472, 1503);
   5018    values->state.word15 = __gen_unpack_uint(cl, 1504, 1535);
   5019 }
   5020 
   5021 static inline void
   5022 MALI_TILER_CONTEXT_print(FILE *fp, const struct MALI_TILER_CONTEXT * values, unsigned indent)
   5023 {
   5024    fprintf(fp, "%*sPolygon List: 0x%" PRIx64 "\n", indent, "", values->polygon_list);
   5025    fprintf(fp, "%*sHierarchy Mask: %u\n", indent, "", values->hierarchy_mask);
   5026    fprintf(fp, "%*sSample Pattern: %s\n", indent, "", mali_sample_pattern_as_str(values->sample_pattern));
   5027    fprintf(fp, "%*sUpdate Cost Table: %s\n", indent, "", values->update_cost_table ? "true" : "false");
   5028    fprintf(fp, "%*sFB Width: %u\n", indent, "", values->fb_width);
   5029    fprintf(fp, "%*sFB Height: %u\n", indent, "", values->fb_height);
   5030    fprintf(fp, "%*sHeap: 0x%" PRIx64 "\n", indent, "", values->heap);
   5031    fprintf(fp, "%*sWeights:\n", indent, "");
   5032    MALI_TILER_WEIGHTS_print(fp, &values->weights, indent + 2);
   5033    fprintf(fp, "%*sState:\n", indent, "");
   5034    MALI_TILER_STATE_print(fp, &values->state, indent + 2);
   5035 }
   5036 
   5037 struct MALI_FRAMEBUFFER_PADDING {
   5038    int dummy;
   5039 };
   5040 
   5041 #define MALI_FRAMEBUFFER_PADDING_header         \
   5042    0
   5043 
   5044 static inline void
   5045 MALI_FRAMEBUFFER_PADDING_pack(uint32_t * restrict cl,
   5046                               const struct MALI_FRAMEBUFFER_PADDING * restrict values)
   5047 {
   5048    cl[ 0] = 0;
   5049    cl[ 1] = 0;
   5050    cl[ 2] = 0;
   5051    cl[ 3] = 0;
   5052    cl[ 4] = 0;
   5053    cl[ 5] = 0;
   5054    cl[ 6] = 0;
   5055    cl[ 7] = 0;
   5056    cl[ 8] = 0;
   5057    cl[ 9] = 0;
   5058    cl[10] = 0;
   5059    cl[11] = 0;
   5060    cl[12] = 0;
   5061    cl[13] = 0;
   5062    cl[14] = 0;
   5063    cl[15] = 0;
   5064 }
   5065 
   5066 
   5067 #define MALI_FRAMEBUFFER_PADDING_LENGTH 64
   5068 struct mali_framebuffer_padding_packed { uint32_t opaque[16]; };
   5069 static inline void
   5070 MALI_FRAMEBUFFER_PADDING_unpack(const uint8_t * restrict cl,
   5071                                 struct MALI_FRAMEBUFFER_PADDING * restrict values)
   5072 {
   5073    if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 0\n");
   5074    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 1\n");
   5075    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 2\n");
   5076    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 3\n");
   5077    if (((const uint32_t *) cl)[4] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 4\n");
   5078    if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 5\n");
   5079    if (((const uint32_t *) cl)[6] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 6\n");
   5080    if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 7\n");
   5081    if (((const uint32_t *) cl)[8] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 8\n");
   5082    if (((const uint32_t *) cl)[9] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 9\n");
   5083    if (((const uint32_t *) cl)[10] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 10\n");
   5084    if (((const uint32_t *) cl)[11] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 11\n");
   5085    if (((const uint32_t *) cl)[12] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 12\n");
   5086    if (((const uint32_t *) cl)[13] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 13\n");
   5087    if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 14\n");
   5088    if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Framebuffer Padding unpacked at word 15\n");
   5089 }
   5090 
   5091 static inline void
   5092 MALI_FRAMEBUFFER_PADDING_print(FILE *fp, const struct MALI_FRAMEBUFFER_PADDING * values, unsigned indent)
   5093 {
   5094 }
   5095 
   5096 struct mali_framebuffer_packed {
   5097    uint32_t opaque[32];
   5098 };
   5099 
   5100 #define MALI_FRAMEBUFFER_LENGTH 128
   5101 #define MALI_FRAMEBUFFER_ALIGN 64
   5102 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_TYPE struct MALI_FRAMEBUFFER_PARAMETERS
   5103 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_header MALI_FRAMEBUFFER_PARAMETERS_header
   5104 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_pack MALI_FRAMEBUFFER_PARAMETERS_pack
   5105 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_unpack MALI_FRAMEBUFFER_PARAMETERS_unpack
   5106 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_print MALI_FRAMEBUFFER_PARAMETERS_print
   5107 #define MALI_FRAMEBUFFER_SECTION_PARAMETERS_OFFSET 0
   5108 #define MALI_FRAMEBUFFER_SECTION_PADDING_TYPE struct MALI_FRAMEBUFFER_PADDING
   5109 #define MALI_FRAMEBUFFER_SECTION_PADDING_header MALI_FRAMEBUFFER_PADDING_header
   5110 #define MALI_FRAMEBUFFER_SECTION_PADDING_pack MALI_FRAMEBUFFER_PADDING_pack
   5111 #define MALI_FRAMEBUFFER_SECTION_PADDING_unpack MALI_FRAMEBUFFER_PADDING_unpack
   5112 #define MALI_FRAMEBUFFER_SECTION_PADDING_print MALI_FRAMEBUFFER_PADDING_print
   5113 #define MALI_FRAMEBUFFER_SECTION_PADDING_OFFSET 64
   5114 
   5115 struct MALI_JOB_HEADER {
   5116    uint32_t                             exception_status;
   5117    uint32_t                             first_incomplete_task;
   5118    uint64_t                             fault_pointer;
   5119    bool                                 is_64b;
   5120    enum mali_job_type                   type;
   5121    bool                                 barrier;
   5122    bool                                 invalidate_cache;
   5123    bool                                 suppress_prefetch;
   5124    bool                                 enable_texture_mapper;
   5125    bool                                 relax_dependency_1;
   5126    bool                                 relax_dependency_2;
   5127    uint32_t                             index;
   5128    uint32_t                             dependency_1;
   5129    uint32_t                             dependency_2;
   5130    uint64_t                             next;
   5131 };
   5132 
   5133 #define MALI_JOB_HEADER_header                  \
   5134    .is_64b = true
   5135 
   5136 static inline void
   5137 MALI_JOB_HEADER_pack(uint32_t * restrict cl,
   5138                      const struct MALI_JOB_HEADER * restrict values)
   5139 {
   5140    cl[ 0] = __gen_uint(values->exception_status, 0, 31);
   5141    cl[ 1] = __gen_uint(values->first_incomplete_task, 0, 31);
   5142    cl[ 2] = __gen_uint(values->fault_pointer, 0, 63);
   5143    cl[ 3] = __gen_uint(values->fault_pointer, 0, 63) >> 32;
   5144    cl[ 4] = __gen_uint(values->is_64b, 0, 0) |
   5145             __gen_uint(values->type, 1, 7) |
   5146             __gen_uint(values->barrier, 8, 8) |
   5147             __gen_uint(values->invalidate_cache, 9, 9) |
   5148             __gen_uint(values->suppress_prefetch, 11, 11) |
   5149             __gen_uint(values->enable_texture_mapper, 12, 12) |
   5150             __gen_uint(values->relax_dependency_1, 14, 14) |
   5151             __gen_uint(values->relax_dependency_2, 15, 15) |
   5152             __gen_uint(values->index, 16, 31);
   5153    cl[ 5] = __gen_uint(values->dependency_1, 0, 15) |
   5154             __gen_uint(values->dependency_2, 16, 31);
   5155    cl[ 6] = __gen_uint(values->next, 0, 63);
   5156    cl[ 7] = __gen_uint(values->next, 0, 63) >> 32;
   5157 }
   5158 
   5159 
   5160 #define MALI_JOB_HEADER_LENGTH 32
   5161 #define MALI_JOB_HEADER_ALIGN 64
   5162 struct mali_job_header_packed { uint32_t opaque[8]; };
   5163 static inline void
   5164 MALI_JOB_HEADER_unpack(const uint8_t * restrict cl,
   5165                        struct MALI_JOB_HEADER * restrict values)
   5166 {
   5167    if (((const uint32_t *) cl)[4] & 0x2400) fprintf(stderr, "XXX: Invalid field of Job Header unpacked at word 4\n");
   5168    values->exception_status = __gen_unpack_uint(cl, 0, 31);
   5169    values->first_incomplete_task = __gen_unpack_uint(cl, 32, 63);
   5170    values->fault_pointer = __gen_unpack_uint(cl, 64, 127);
   5171    values->is_64b = __gen_unpack_uint(cl, 128, 128);
   5172    values->type = (enum mali_job_type)__gen_unpack_uint(cl, 129, 135);
   5173    values->barrier = __gen_unpack_uint(cl, 136, 136);
   5174    values->invalidate_cache = __gen_unpack_uint(cl, 137, 137);
   5175    values->suppress_prefetch = __gen_unpack_uint(cl, 139, 139);
   5176    values->enable_texture_mapper = __gen_unpack_uint(cl, 140, 140);
   5177    values->relax_dependency_1 = __gen_unpack_uint(cl, 142, 142);
   5178    values->relax_dependency_2 = __gen_unpack_uint(cl, 143, 143);
   5179    values->index = __gen_unpack_uint(cl, 144, 159);
   5180    values->dependency_1 = __gen_unpack_uint(cl, 160, 175);
   5181    values->dependency_2 = __gen_unpack_uint(cl, 176, 191);
   5182    values->next = __gen_unpack_uint(cl, 192, 255);
   5183 }
   5184 
   5185 static inline void
   5186 MALI_JOB_HEADER_print(FILE *fp, const struct MALI_JOB_HEADER * values, unsigned indent)
   5187 {
   5188    fprintf(fp, "%*sException Status: %u\n", indent, "", values->exception_status);
   5189    fprintf(fp, "%*sFirst Incomplete Task: %u\n", indent, "", values->first_incomplete_task);
   5190    fprintf(fp, "%*sFault Pointer: 0x%" PRIx64 "\n", indent, "", values->fault_pointer);
   5191    fprintf(fp, "%*sIs 64b: %s\n", indent, "", values->is_64b ? "true" : "false");
   5192    fprintf(fp, "%*sType: %s\n", indent, "", mali_job_type_as_str(values->type));
   5193    fprintf(fp, "%*sBarrier: %s\n", indent, "", values->barrier ? "true" : "false");
   5194    fprintf(fp, "%*sInvalidate Cache: %s\n", indent, "", values->invalidate_cache ? "true" : "false");
   5195    fprintf(fp, "%*sSuppress Prefetch: %s\n", indent, "", values->suppress_prefetch ? "true" : "false");
   5196    fprintf(fp, "%*sEnable Texture Mapper: %s\n", indent, "", values->enable_texture_mapper ? "true" : "false");
   5197    fprintf(fp, "%*sRelax Dependency 1: %s\n", indent, "", values->relax_dependency_1 ? "true" : "false");
   5198    fprintf(fp, "%*sRelax Dependency 2: %s\n", indent, "", values->relax_dependency_2 ? "true" : "false");
   5199    fprintf(fp, "%*sIndex: %u\n", indent, "", values->index);
   5200    fprintf(fp, "%*sDependency 1: %u\n", indent, "", values->dependency_1);
   5201    fprintf(fp, "%*sDependency 2: %u\n", indent, "", values->dependency_2);
   5202    fprintf(fp, "%*sNext: 0x%" PRIx64 "\n", indent, "", values->next);
   5203 }
   5204 
   5205 struct MALI_FRAGMENT_JOB_PAYLOAD {
   5206    uint32_t                             bound_min_x;
   5207    uint32_t                             bound_min_y;
   5208    uint32_t                             bound_max_x;
   5209    uint32_t                             bound_max_y;
   5210    bool                                 has_tile_enable_map;
   5211    uint64_t                             framebuffer;
   5212    uint64_t                             tile_enable_map;
   5213    uint32_t                             tile_enable_map_row_stride;
   5214 };
   5215 
   5216 #define MALI_FRAGMENT_JOB_PAYLOAD_header        \
   5217    0
   5218 
   5219 static inline void
   5220 MALI_FRAGMENT_JOB_PAYLOAD_pack(uint32_t * restrict cl,
   5221                                const struct MALI_FRAGMENT_JOB_PAYLOAD * restrict values)
   5222 {
   5223    cl[ 0] = __gen_uint(values->bound_min_x, 0, 11) |
   5224             __gen_uint(values->bound_min_y, 16, 27);
   5225    cl[ 1] = __gen_uint(values->bound_max_x, 0, 11) |
   5226             __gen_uint(values->bound_max_y, 16, 27) |
   5227             __gen_uint(values->has_tile_enable_map, 31, 31);
   5228    cl[ 2] = __gen_uint(values->framebuffer, 0, 63);
   5229    cl[ 3] = __gen_uint(values->framebuffer, 0, 63) >> 32;
   5230    cl[ 4] = __gen_uint(values->tile_enable_map, 0, 63);
   5231    cl[ 5] = __gen_uint(values->tile_enable_map, 0, 63) >> 32;
   5232    cl[ 6] = __gen_uint(values->tile_enable_map_row_stride, 0, 7);
   5233    cl[ 7] = 0;
   5234 }
   5235 
   5236 
   5237 #define MALI_FRAGMENT_JOB_PAYLOAD_LENGTH 32
   5238 struct mali_fragment_job_payload_packed { uint32_t opaque[8]; };
   5239 static inline void
   5240 MALI_FRAGMENT_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
   5241                                  struct MALI_FRAGMENT_JOB_PAYLOAD * restrict values)
   5242 {
   5243    if (((const uint32_t *) cl)[0] & 0xf000f000) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 0\n");
   5244    if (((const uint32_t *) cl)[1] & 0x7000f000) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 1\n");
   5245    if (((const uint32_t *) cl)[6] & 0xffffff00) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 6\n");
   5246    if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 7\n");
   5247    values->bound_min_x = __gen_unpack_uint(cl, 0, 11);
   5248    values->bound_min_y = __gen_unpack_uint(cl, 16, 27);
   5249    values->bound_max_x = __gen_unpack_uint(cl, 32, 43);
   5250    values->bound_max_y = __gen_unpack_uint(cl, 48, 59);
   5251    values->has_tile_enable_map = __gen_unpack_uint(cl, 63, 63);
   5252    values->framebuffer = __gen_unpack_uint(cl, 64, 127);
   5253    values->tile_enable_map = __gen_unpack_uint(cl, 128, 191);
   5254    values->tile_enable_map_row_stride = __gen_unpack_uint(cl, 192, 199);
   5255 }
   5256 
   5257 static inline void
   5258 MALI_FRAGMENT_JOB_PAYLOAD_print(FILE *fp, const struct MALI_FRAGMENT_JOB_PAYLOAD * values, unsigned indent)
   5259 {
   5260    fprintf(fp, "%*sBound Min X: %u\n", indent, "", values->bound_min_x);
   5261    fprintf(fp, "%*sBound Min Y: %u\n", indent, "", values->bound_min_y);
   5262    fprintf(fp, "%*sBound Max X: %u\n", indent, "", values->bound_max_x);
   5263    fprintf(fp, "%*sBound Max Y: %u\n", indent, "", values->bound_max_y);
   5264    fprintf(fp, "%*sHas Tile Enable Map: %s\n", indent, "", values->has_tile_enable_map ? "true" : "false");
   5265    fprintf(fp, "%*sFramebuffer: 0x%" PRIx64 "\n", indent, "", values->framebuffer);
   5266    fprintf(fp, "%*sTile Enable Map: 0x%" PRIx64 "\n", indent, "", values->tile_enable_map);
   5267    fprintf(fp, "%*sTile Enable Map Row Stride: %u\n", indent, "", values->tile_enable_map_row_stride);
   5268 }
   5269 
   5270 struct mali_fragment_job_packed {
   5271    uint32_t opaque[16];
   5272 };
   5273 
   5274 #define MALI_FRAGMENT_JOB_LENGTH 64
   5275 #define MALI_FRAGMENT_JOB_ALIGN 64
   5276 #define MALI_FRAGMENT_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5277 #define MALI_FRAGMENT_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5278 #define MALI_FRAGMENT_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5279 #define MALI_FRAGMENT_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5280 #define MALI_FRAGMENT_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5281 #define MALI_FRAGMENT_JOB_SECTION_HEADER_OFFSET 0
   5282 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_TYPE struct MALI_FRAGMENT_JOB_PAYLOAD
   5283 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_header MALI_FRAGMENT_JOB_PAYLOAD_header
   5284 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_pack MALI_FRAGMENT_JOB_PAYLOAD_pack
   5285 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_unpack MALI_FRAGMENT_JOB_PAYLOAD_unpack
   5286 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_print MALI_FRAGMENT_JOB_PAYLOAD_print
   5287 #define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_OFFSET 32
   5288 
   5289 enum mali_write_value_type {
   5290         MALI_WRITE_VALUE_TYPE_CYCLE_COUNTER  =      1,
   5291         MALI_WRITE_VALUE_TYPE_SYSTEM_TIMESTAMP =      2,
   5292         MALI_WRITE_VALUE_TYPE_ZERO           =      3,
   5293         MALI_WRITE_VALUE_TYPE_IMMEDIATE_8    =      4,
   5294         MALI_WRITE_VALUE_TYPE_IMMEDIATE_16   =      5,
   5295         MALI_WRITE_VALUE_TYPE_IMMEDIATE_32   =      6,
   5296         MALI_WRITE_VALUE_TYPE_IMMEDIATE_64   =      7,
   5297 };
   5298 
   5299 static inline const char *
   5300 mali_write_value_type_as_str(enum mali_write_value_type imm)
   5301 {
   5302     switch (imm) {
   5303     case MALI_WRITE_VALUE_TYPE_CYCLE_COUNTER: return "Cycle Counter";
   5304     case MALI_WRITE_VALUE_TYPE_SYSTEM_TIMESTAMP: return "System Timestamp";
   5305     case MALI_WRITE_VALUE_TYPE_ZERO: return "Zero";
   5306     case MALI_WRITE_VALUE_TYPE_IMMEDIATE_8: return "Immediate 8";
   5307     case MALI_WRITE_VALUE_TYPE_IMMEDIATE_16: return "Immediate 16";
   5308     case MALI_WRITE_VALUE_TYPE_IMMEDIATE_32: return "Immediate 32";
   5309     case MALI_WRITE_VALUE_TYPE_IMMEDIATE_64: return "Immediate 64";
   5310     default: return "XXX: INVALID";
   5311     }
   5312 }
   5313 
   5314 struct MALI_WRITE_VALUE_JOB_PAYLOAD {
   5315    uint64_t                             address;
   5316    enum mali_write_value_type           type;
   5317    uint64_t                             immediate_value;
   5318 };
   5319 
   5320 #define MALI_WRITE_VALUE_JOB_PAYLOAD_header     \
   5321    0
   5322 
   5323 static inline void
   5324 MALI_WRITE_VALUE_JOB_PAYLOAD_pack(uint32_t * restrict cl,
   5325                                   const struct MALI_WRITE_VALUE_JOB_PAYLOAD * restrict values)
   5326 {
   5327    cl[ 0] = __gen_uint(values->address, 0, 63);
   5328    cl[ 1] = __gen_uint(values->address, 0, 63) >> 32;
   5329    cl[ 2] = __gen_uint(values->type, 0, 31);
   5330    cl[ 3] = 0;
   5331    cl[ 4] = __gen_uint(values->immediate_value, 0, 63);
   5332    cl[ 5] = __gen_uint(values->immediate_value, 0, 63) >> 32;
   5333 }
   5334 
   5335 
   5336 #define MALI_WRITE_VALUE_JOB_PAYLOAD_LENGTH 24
   5337 struct mali_write_value_job_payload_packed { uint32_t opaque[6]; };
   5338 static inline void
   5339 MALI_WRITE_VALUE_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
   5340                                     struct MALI_WRITE_VALUE_JOB_PAYLOAD * restrict values)
   5341 {
   5342    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Write Value Job Payload unpacked at word 3\n");
   5343    values->address = __gen_unpack_uint(cl, 0, 63);
   5344    values->type = (enum mali_write_value_type)__gen_unpack_uint(cl, 64, 95);
   5345    values->immediate_value = __gen_unpack_uint(cl, 128, 191);
   5346 }
   5347 
   5348 static inline void
   5349 MALI_WRITE_VALUE_JOB_PAYLOAD_print(FILE *fp, const struct MALI_WRITE_VALUE_JOB_PAYLOAD * values, unsigned indent)
   5350 {
   5351    fprintf(fp, "%*sAddress: 0x%" PRIx64 "\n", indent, "", values->address);
   5352    fprintf(fp, "%*sType: %s\n", indent, "", mali_write_value_type_as_str(values->type));
   5353    fprintf(fp, "%*sImmediate Value: 0x%" PRIx64 "\n", indent, "", values->immediate_value);
   5354 }
   5355 
   5356 struct MALI_CACHE_FLUSH_JOB_PAYLOAD {
   5357    bool                                 clean_shader_core_ls;
   5358    bool                                 invalidate_shader_core_ls;
   5359    bool                                 invalidate_shader_core_other;
   5360    bool                                 job_manager_clean;
   5361    bool                                 job_manager_invalidate;
   5362    bool                                 tiler_clean;
   5363    bool                                 tiler_invalidate;
   5364    bool                                 l2_clean;
   5365    bool                                 l2_invalidate;
   5366 };
   5367 
   5368 #define MALI_CACHE_FLUSH_JOB_PAYLOAD_header     \
   5369    0
   5370 
   5371 static inline void
   5372 MALI_CACHE_FLUSH_JOB_PAYLOAD_pack(uint32_t * restrict cl,
   5373                                   const struct MALI_CACHE_FLUSH_JOB_PAYLOAD * restrict values)
   5374 {
   5375    cl[ 0] = __gen_uint(values->clean_shader_core_ls, 0, 0) |
   5376             __gen_uint(values->invalidate_shader_core_ls, 1, 1) |
   5377             __gen_uint(values->invalidate_shader_core_other, 2, 2) |
   5378             __gen_uint(values->job_manager_clean, 16, 16) |
   5379             __gen_uint(values->job_manager_invalidate, 17, 17) |
   5380             __gen_uint(values->tiler_clean, 24, 24) |
   5381             __gen_uint(values->tiler_invalidate, 25, 25);
   5382    cl[ 1] = __gen_uint(values->l2_clean, 0, 0) |
   5383             __gen_uint(values->l2_invalidate, 1, 1);
   5384 }
   5385 
   5386 
   5387 #define MALI_CACHE_FLUSH_JOB_PAYLOAD_LENGTH 8
   5388 struct mali_cache_flush_job_payload_packed { uint32_t opaque[2]; };
   5389 static inline void
   5390 MALI_CACHE_FLUSH_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
   5391                                     struct MALI_CACHE_FLUSH_JOB_PAYLOAD * restrict values)
   5392 {
   5393    if (((const uint32_t *) cl)[0] & 0xfcfcfff8) fprintf(stderr, "XXX: Invalid field of Cache Flush Job Payload unpacked at word 0\n");
   5394    if (((const uint32_t *) cl)[1] & 0xfffffffc) fprintf(stderr, "XXX: Invalid field of Cache Flush Job Payload unpacked at word 1\n");
   5395    values->clean_shader_core_ls = __gen_unpack_uint(cl, 0, 0);
   5396    values->invalidate_shader_core_ls = __gen_unpack_uint(cl, 1, 1);
   5397    values->invalidate_shader_core_other = __gen_unpack_uint(cl, 2, 2);
   5398    values->job_manager_clean = __gen_unpack_uint(cl, 16, 16);
   5399    values->job_manager_invalidate = __gen_unpack_uint(cl, 17, 17);
   5400    values->tiler_clean = __gen_unpack_uint(cl, 24, 24);
   5401    values->tiler_invalidate = __gen_unpack_uint(cl, 25, 25);
   5402    values->l2_clean = __gen_unpack_uint(cl, 32, 32);
   5403    values->l2_invalidate = __gen_unpack_uint(cl, 33, 33);
   5404 }
   5405 
   5406 static inline void
   5407 MALI_CACHE_FLUSH_JOB_PAYLOAD_print(FILE *fp, const struct MALI_CACHE_FLUSH_JOB_PAYLOAD * values, unsigned indent)
   5408 {
   5409    fprintf(fp, "%*sClean Shader Core LS: %s\n", indent, "", values->clean_shader_core_ls ? "true" : "false");
   5410    fprintf(fp, "%*sInvalidate Shader Core LS: %s\n", indent, "", values->invalidate_shader_core_ls ? "true" : "false");
   5411    fprintf(fp, "%*sInvalidate Shader Core Other: %s\n", indent, "", values->invalidate_shader_core_other ? "true" : "false");
   5412    fprintf(fp, "%*sJob Manager Clean: %s\n", indent, "", values->job_manager_clean ? "true" : "false");
   5413    fprintf(fp, "%*sJob Manager Invalidate: %s\n", indent, "", values->job_manager_invalidate ? "true" : "false");
   5414    fprintf(fp, "%*sTiler Clean: %s\n", indent, "", values->tiler_clean ? "true" : "false");
   5415    fprintf(fp, "%*sTiler Invalidate: %s\n", indent, "", values->tiler_invalidate ? "true" : "false");
   5416    fprintf(fp, "%*sL2 Clean: %s\n", indent, "", values->l2_clean ? "true" : "false");
   5417    fprintf(fp, "%*sL2 Invalidate: %s\n", indent, "", values->l2_invalidate ? "true" : "false");
   5418 }
   5419 
   5420 struct mali_write_value_job_packed {
   5421    uint32_t opaque[14];
   5422 };
   5423 
   5424 #define MALI_WRITE_VALUE_JOB_LENGTH 56
   5425 #define MALI_WRITE_VALUE_JOB_ALIGN 64
   5426 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5427 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5428 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5429 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5430 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5431 #define MALI_WRITE_VALUE_JOB_SECTION_HEADER_OFFSET 0
   5432 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_TYPE struct MALI_WRITE_VALUE_JOB_PAYLOAD
   5433 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_header MALI_WRITE_VALUE_JOB_PAYLOAD_header
   5434 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_pack MALI_WRITE_VALUE_JOB_PAYLOAD_pack
   5435 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_unpack MALI_WRITE_VALUE_JOB_PAYLOAD_unpack
   5436 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_print MALI_WRITE_VALUE_JOB_PAYLOAD_print
   5437 #define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_OFFSET 32
   5438 
   5439 struct mali_cache_flush_job_packed {
   5440    uint32_t opaque[10];
   5441 };
   5442 
   5443 #define MALI_CACHE_FLUSH_JOB_LENGTH 40
   5444 #define MALI_CACHE_FLUSH_JOB_ALIGN 64
   5445 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5446 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5447 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5448 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5449 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5450 #define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_OFFSET 0
   5451 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_TYPE struct MALI_CACHE_FLUSH_JOB_PAYLOAD
   5452 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_header MALI_CACHE_FLUSH_JOB_PAYLOAD_header
   5453 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_pack MALI_CACHE_FLUSH_JOB_PAYLOAD_pack
   5454 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_unpack MALI_CACHE_FLUSH_JOB_PAYLOAD_unpack
   5455 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_print MALI_CACHE_FLUSH_JOB_PAYLOAD_print
   5456 #define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_OFFSET 32
   5457 
   5458 struct MALI_COMPUTE_JOB_PARAMETERS {
   5459    uint32_t                             job_task_split;
   5460 };
   5461 
   5462 #define MALI_COMPUTE_JOB_PARAMETERS_header      \
   5463    0
   5464 
   5465 static inline void
   5466 MALI_COMPUTE_JOB_PARAMETERS_pack(uint32_t * restrict cl,
   5467                                  const struct MALI_COMPUTE_JOB_PARAMETERS * restrict values)
   5468 {
   5469    cl[ 0] = __gen_uint(values->job_task_split, 26, 29);
   5470    cl[ 1] = 0;
   5471    cl[ 2] = 0;
   5472    cl[ 3] = 0;
   5473    cl[ 4] = 0;
   5474    cl[ 5] = 0;
   5475 }
   5476 
   5477 
   5478 #define MALI_COMPUTE_JOB_PARAMETERS_LENGTH 24
   5479 struct mali_compute_job_parameters_packed { uint32_t opaque[6]; };
   5480 static inline void
   5481 MALI_COMPUTE_JOB_PARAMETERS_unpack(const uint8_t * restrict cl,
   5482                                    struct MALI_COMPUTE_JOB_PARAMETERS * restrict values)
   5483 {
   5484    if (((const uint32_t *) cl)[0] & 0xc3ffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 0\n");
   5485    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 1\n");
   5486    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 2\n");
   5487    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 3\n");
   5488    if (((const uint32_t *) cl)[4] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 4\n");
   5489    if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 5\n");
   5490    values->job_task_split = __gen_unpack_uint(cl, 26, 29);
   5491 }
   5492 
   5493 static inline void
   5494 MALI_COMPUTE_JOB_PARAMETERS_print(FILE *fp, const struct MALI_COMPUTE_JOB_PARAMETERS * values, unsigned indent)
   5495 {
   5496    fprintf(fp, "%*sJob Task Split: %u\n", indent, "", values->job_task_split);
   5497 }
   5498 
   5499 struct mali_compute_job_packed {
   5500    uint32_t opaque[48];
   5501 };
   5502 
   5503 #define MALI_COMPUTE_JOB_LENGTH 192
   5504 #define MALI_COMPUTE_JOB_ALIGN 64
   5505 #define MALI_COMPUTE_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5506 #define MALI_COMPUTE_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5507 #define MALI_COMPUTE_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5508 #define MALI_COMPUTE_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5509 #define MALI_COMPUTE_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5510 #define MALI_COMPUTE_JOB_SECTION_HEADER_OFFSET 0
   5511 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_TYPE struct MALI_INVOCATION
   5512 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_header MALI_INVOCATION_header
   5513 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_pack MALI_INVOCATION_pack
   5514 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_unpack MALI_INVOCATION_unpack
   5515 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_print MALI_INVOCATION_print
   5516 #define MALI_COMPUTE_JOB_SECTION_INVOCATION_OFFSET 32
   5517 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_TYPE struct MALI_COMPUTE_JOB_PARAMETERS
   5518 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_header MALI_COMPUTE_JOB_PARAMETERS_header
   5519 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_pack MALI_COMPUTE_JOB_PARAMETERS_pack
   5520 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_unpack MALI_COMPUTE_JOB_PARAMETERS_unpack
   5521 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_print MALI_COMPUTE_JOB_PARAMETERS_print
   5522 #define MALI_COMPUTE_JOB_SECTION_PARAMETERS_OFFSET 40
   5523 #define MALI_COMPUTE_JOB_SECTION_DRAW_TYPE struct MALI_DRAW
   5524 #define MALI_COMPUTE_JOB_SECTION_DRAW_header MALI_DRAW_header
   5525 #define MALI_COMPUTE_JOB_SECTION_DRAW_pack MALI_DRAW_pack
   5526 #define MALI_COMPUTE_JOB_SECTION_DRAW_unpack MALI_DRAW_unpack
   5527 #define MALI_COMPUTE_JOB_SECTION_DRAW_print MALI_DRAW_print
   5528 #define MALI_COMPUTE_JOB_SECTION_DRAW_OFFSET 64
   5529 
   5530 struct MALI_PRIMITIVE_SIZE {
   5531    float                                constant;
   5532    uint64_t                             size_array;
   5533 };
   5534 
   5535 #define MALI_PRIMITIVE_SIZE_header              \
   5536    0
   5537 
   5538 static inline void
   5539 MALI_PRIMITIVE_SIZE_pack(uint32_t * restrict cl,
   5540                          const struct MALI_PRIMITIVE_SIZE * restrict values)
   5541 {
   5542    cl[ 0] = __gen_uint(fui(values->constant), 0, 32) |
   5543             __gen_uint(values->size_array, 0, 63);
   5544    cl[ 1] = __gen_uint(values->size_array, 0, 63) >> 32;
   5545 }
   5546 
   5547 
   5548 #define MALI_PRIMITIVE_SIZE_LENGTH 8
   5549 struct mali_primitive_size_packed { uint32_t opaque[2]; };
   5550 static inline void
   5551 MALI_PRIMITIVE_SIZE_unpack(const uint8_t * restrict cl,
   5552                            struct MALI_PRIMITIVE_SIZE * restrict values)
   5553 {
   5554    values->constant = __gen_unpack_float(cl, 0, 31);
   5555    values->size_array = __gen_unpack_uint(cl, 0, 63);
   5556 }
   5557 
   5558 static inline void
   5559 MALI_PRIMITIVE_SIZE_print(FILE *fp, const struct MALI_PRIMITIVE_SIZE * values, unsigned indent)
   5560 {
   5561    fprintf(fp, "%*sConstant: %f\n", indent, "", values->constant);
   5562    fprintf(fp, "%*sSize Array: 0x%" PRIx64 "\n", indent, "", values->size_array);
   5563 }
   5564 
   5565 struct MALI_TILER_POINTER {
   5566    uint64_t                             address;
   5567 };
   5568 
   5569 #define MALI_TILER_POINTER_header               \
   5570    0
   5571 
   5572 static inline void
   5573 MALI_TILER_POINTER_pack(uint32_t * restrict cl,
   5574                         const struct MALI_TILER_POINTER * restrict values)
   5575 {
   5576    cl[ 0] = __gen_uint(values->address, 0, 63);
   5577    cl[ 1] = __gen_uint(values->address, 0, 63) >> 32;
   5578 }
   5579 
   5580 
   5581 #define MALI_TILER_POINTER_LENGTH 8
   5582 struct mali_tiler_pointer_packed { uint32_t opaque[2]; };
   5583 static inline void
   5584 MALI_TILER_POINTER_unpack(const uint8_t * restrict cl,
   5585                           struct MALI_TILER_POINTER * restrict values)
   5586 {
   5587    values->address = __gen_unpack_uint(cl, 0, 63);
   5588 }
   5589 
   5590 static inline void
   5591 MALI_TILER_POINTER_print(FILE *fp, const struct MALI_TILER_POINTER * values, unsigned indent)
   5592 {
   5593    fprintf(fp, "%*sAddress: 0x%" PRIx64 "\n", indent, "", values->address);
   5594 }
   5595 
   5596 struct MALI_TILER_JOB_PADDING {
   5597    int dummy;
   5598 };
   5599 
   5600 #define MALI_TILER_JOB_PADDING_header           \
   5601    0
   5602 
   5603 static inline void
   5604 MALI_TILER_JOB_PADDING_pack(uint32_t * restrict cl,
   5605                             const struct MALI_TILER_JOB_PADDING * restrict values)
   5606 {
   5607    cl[ 0] = 0;
   5608    cl[ 1] = 0;
   5609    cl[ 2] = 0;
   5610    cl[ 3] = 0;
   5611    cl[ 4] = 0;
   5612    cl[ 5] = 0;
   5613    cl[ 6] = 0;
   5614    cl[ 7] = 0;
   5615    cl[ 8] = 0;
   5616    cl[ 9] = 0;
   5617    cl[10] = 0;
   5618    cl[11] = 0;
   5619 }
   5620 
   5621 
   5622 #define MALI_TILER_JOB_PADDING_LENGTH 48
   5623 struct mali_tiler_job_padding_packed { uint32_t opaque[12]; };
   5624 static inline void
   5625 MALI_TILER_JOB_PADDING_unpack(const uint8_t * restrict cl,
   5626                               struct MALI_TILER_JOB_PADDING * restrict values)
   5627 {
   5628    if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 0\n");
   5629    if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 1\n");
   5630    if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 2\n");
   5631    if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 3\n");
   5632    if (((const uint32_t *) cl)[4] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 4\n");
   5633    if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 5\n");
   5634    if (((const uint32_t *) cl)[6] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 6\n");
   5635    if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 7\n");
   5636    if (((const uint32_t *) cl)[8] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 8\n");
   5637    if (((const uint32_t *) cl)[9] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 9\n");
   5638    if (((const uint32_t *) cl)[10] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 10\n");
   5639    if (((const uint32_t *) cl)[11] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Tiler Job Padding unpacked at word 11\n");
   5640 }
   5641 
   5642 static inline void
   5643 MALI_TILER_JOB_PADDING_print(FILE *fp, const struct MALI_TILER_JOB_PADDING * values, unsigned indent)
   5644 {
   5645 }
   5646 
   5647 struct mali_tiler_job_packed {
   5648    uint32_t opaque[64];
   5649 };
   5650 
   5651 #define MALI_TILER_JOB_LENGTH 256
   5652 #define MALI_TILER_JOB_ALIGN 64
   5653 #define MALI_TILER_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5654 #define MALI_TILER_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5655 #define MALI_TILER_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5656 #define MALI_TILER_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5657 #define MALI_TILER_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5658 #define MALI_TILER_JOB_SECTION_HEADER_OFFSET 0
   5659 #define MALI_TILER_JOB_SECTION_INVOCATION_TYPE struct MALI_INVOCATION
   5660 #define MALI_TILER_JOB_SECTION_INVOCATION_header MALI_INVOCATION_header
   5661 #define MALI_TILER_JOB_SECTION_INVOCATION_pack MALI_INVOCATION_pack
   5662 #define MALI_TILER_JOB_SECTION_INVOCATION_unpack MALI_INVOCATION_unpack
   5663 #define MALI_TILER_JOB_SECTION_INVOCATION_print MALI_INVOCATION_print
   5664 #define MALI_TILER_JOB_SECTION_INVOCATION_OFFSET 32
   5665 #define MALI_TILER_JOB_SECTION_PRIMITIVE_TYPE struct MALI_PRIMITIVE
   5666 #define MALI_TILER_JOB_SECTION_PRIMITIVE_header MALI_PRIMITIVE_header
   5667 #define MALI_TILER_JOB_SECTION_PRIMITIVE_pack MALI_PRIMITIVE_pack
   5668 #define MALI_TILER_JOB_SECTION_PRIMITIVE_unpack MALI_PRIMITIVE_unpack
   5669 #define MALI_TILER_JOB_SECTION_PRIMITIVE_print MALI_PRIMITIVE_print
   5670 #define MALI_TILER_JOB_SECTION_PRIMITIVE_OFFSET 40
   5671 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_TYPE struct MALI_PRIMITIVE_SIZE
   5672 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_header MALI_PRIMITIVE_SIZE_header
   5673 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_pack MALI_PRIMITIVE_SIZE_pack
   5674 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_unpack MALI_PRIMITIVE_SIZE_unpack
   5675 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_print MALI_PRIMITIVE_SIZE_print
   5676 #define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_OFFSET 64
   5677 #define MALI_TILER_JOB_SECTION_TILER_TYPE struct MALI_TILER_POINTER
   5678 #define MALI_TILER_JOB_SECTION_TILER_header MALI_TILER_POINTER_header
   5679 #define MALI_TILER_JOB_SECTION_TILER_pack MALI_TILER_POINTER_pack
   5680 #define MALI_TILER_JOB_SECTION_TILER_unpack MALI_TILER_POINTER_unpack
   5681 #define MALI_TILER_JOB_SECTION_TILER_print MALI_TILER_POINTER_print
   5682 #define MALI_TILER_JOB_SECTION_TILER_OFFSET 72
   5683 #define MALI_TILER_JOB_SECTION_PADDING_TYPE struct MALI_TILER_JOB_PADDING
   5684 #define MALI_TILER_JOB_SECTION_PADDING_header MALI_TILER_JOB_PADDING_header
   5685 #define MALI_TILER_JOB_SECTION_PADDING_pack MALI_TILER_JOB_PADDING_pack
   5686 #define MALI_TILER_JOB_SECTION_PADDING_unpack MALI_TILER_JOB_PADDING_unpack
   5687 #define MALI_TILER_JOB_SECTION_PADDING_print MALI_TILER_JOB_PADDING_print
   5688 #define MALI_TILER_JOB_SECTION_PADDING_OFFSET 80
   5689 #define MALI_TILER_JOB_SECTION_DRAW_TYPE struct MALI_DRAW
   5690 #define MALI_TILER_JOB_SECTION_DRAW_header MALI_DRAW_header
   5691 #define MALI_TILER_JOB_SECTION_DRAW_pack MALI_DRAW_pack
   5692 #define MALI_TILER_JOB_SECTION_DRAW_unpack MALI_DRAW_unpack
   5693 #define MALI_TILER_JOB_SECTION_DRAW_print MALI_DRAW_print
   5694 #define MALI_TILER_JOB_SECTION_DRAW_OFFSET 128
   5695 
   5696 struct mali_indexed_vertex_job_packed {
   5697    uint32_t opaque[96];
   5698 };
   5699 
   5700 #define MALI_INDEXED_VERTEX_JOB_LENGTH 384
   5701 #define MALI_INDEXED_VERTEX_JOB_ALIGN 64
   5702 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
   5703 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
   5704 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
   5705 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
   5706 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
   5707 #define MALI_INDEXED_VERTEX_JOB_SECTION_HEADER_OFFSET 0
   5708 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_TYPE struct MALI_INVOCATION
   5709 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_header MALI_INVOCATION_header
   5710 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_pack MALI_INVOCATION_pack
   5711 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_unpack MALI_INVOCATION_unpack
   5712 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_print MALI_INVOCATION_print
   5713 #define MALI_INDEXED_VERTEX_JOB_SECTION_INVOCATION_OFFSET 32
   5714 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_TYPE struct MALI_PRIMITIVE
   5715 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_header MALI_PRIMITIVE_header
   5716 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_pack MALI_PRIMITIVE_pack
   5717 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_unpack MALI_PRIMITIVE_unpack
   5718 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_print MALI_PRIMITIVE_print
   5719 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_OFFSET 40
   5720 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_TYPE struct MALI_PRIMITIVE_SIZE
   5721 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_header MALI_PRIMITIVE_SIZE_header
   5722 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_pack MALI_PRIMITIVE_SIZE_pack
   5723 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_unpack MALI_PRIMITIVE_SIZE_unpack
   5724 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_print MALI_PRIMITIVE_SIZE_print
   5725 #define MALI_INDEXED_VERTEX_JOB_SECTION_PRIMITIVE_SIZE_OFFSET 64
   5726 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_TYPE struct MALI_TILER_POINTER
   5727 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_header MALI_TILER_POINTER_header
   5728 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_pack MALI_TILER_POINTER_pack
   5729 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_unpack MALI_TILER_POINTER_unpack
   5730 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_print MALI_TILER_POINTER_print
   5731 #define MALI_INDEXED_VERTEX_JOB_SECTION_TILER_OFFSET 72
   5732 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_TYPE struct MALI_TILER_JOB_PADDING
   5733 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_header MALI_TILER_JOB_PADDING_header
   5734 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_pack MALI_TILER_JOB_PADDING_pack
   5735 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_unpack MALI_TILER_JOB_PADDING_unpack
   5736 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_print MALI_TILER_JOB_PADDING_print
   5737 #define MALI_INDEXED_VERTEX_JOB_SECTION_PADDING_OFFSET 80
   5738 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_TYPE struct MALI_DRAW
   5739 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_header MALI_DRAW_header
   5740 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_pack MALI_DRAW_pack
   5741 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_unpack MALI_DRAW_unpack
   5742 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_print MALI_DRAW_print
   5743 #define MALI_INDEXED_VERTEX_JOB_SECTION_FRAGMENT_DRAW_OFFSET 128
   5744 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_TYPE struct MALI_DRAW
   5745 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_header MALI_DRAW_header
   5746 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_pack MALI_DRAW_pack
   5747 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_unpack MALI_DRAW_unpack
   5748 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_print MALI_DRAW_print
   5749 #define MALI_INDEXED_VERTEX_JOB_SECTION_VERTEX_DRAW_OFFSET 256
   5750 
   5751 #include "panfrost-job.h"
   5752 #endif
   5753