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
23static 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
37static 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
52static 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
69static 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
83static 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
93static 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 (v6): %s%s%s %s%s%s%s\n", indent, "", \
160        mali_format_as_str((enum mali_format)((format >> 12) & 0xFF)), \
161        (format & (1 << 20)) ? " sRGB" : "", \
162        (format & (1 << 21)) ? " big-endian" : "", \
163        mali_channel_as_str((enum mali_channel)((format >> 0) & 0x7)), \
164        mali_channel_as_str((enum mali_channel)((format >> 3) & 0x7)), \
165        mali_channel_as_str((enum mali_channel)((format >> 6) & 0x7)), \
166        mali_channel_as_str((enum mali_channel)((format >> 9) & 0x7)));
167
168
169enum mali_attribute_type {
170        MALI_ATTRIBUTE_TYPE_1D               =      1,
171        MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR   =      2,
172        MALI_ATTRIBUTE_TYPE_1D_MODULUS       =      3,
173        MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR  =      4,
174        MALI_ATTRIBUTE_TYPE_3D_LINEAR        =      5,
175        MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED   =      6,
176        MALI_ATTRIBUTE_TYPE_1D_PRIMITIVE_INDEX_BUFFER =      7,
177        MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR_WRITE_REDUCTION =     10,
178        MALI_ATTRIBUTE_TYPE_1D_MODULUS_WRITE_REDUCTION =     11,
179        MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR_WRITE_REDUCTION =     12,
180        MALI_ATTRIBUTE_TYPE_CONTINUATION     =     32,
181};
182
183static inline const char *
184mali_attribute_type_as_str(enum mali_attribute_type imm)
185{
186    switch (imm) {
187    case MALI_ATTRIBUTE_TYPE_1D: return "1D";
188    case MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR: return "1D POT Divisor";
189    case MALI_ATTRIBUTE_TYPE_1D_MODULUS: return "1D Modulus";
190    case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR: return "1D NPOT Divisor";
191    case MALI_ATTRIBUTE_TYPE_3D_LINEAR: return "3D Linear";
192    case MALI_ATTRIBUTE_TYPE_3D_INTERLEAVED: return "3D Interleaved";
193    case MALI_ATTRIBUTE_TYPE_1D_PRIMITIVE_INDEX_BUFFER: return "1D Primitive Index Buffer";
194    case MALI_ATTRIBUTE_TYPE_1D_POT_DIVISOR_WRITE_REDUCTION: return "1D POT Divisor Write Reduction";
195    case MALI_ATTRIBUTE_TYPE_1D_MODULUS_WRITE_REDUCTION: return "1D Modulus Write Reduction";
196    case MALI_ATTRIBUTE_TYPE_1D_NPOT_DIVISOR_WRITE_REDUCTION: return "1D NPOT Divisor Write Reduction";
197    case MALI_ATTRIBUTE_TYPE_CONTINUATION: return "Continuation";
198    default: return "XXX: INVALID";
199    }
200}
201
202enum mali_attribute_special {
203        MALI_ATTRIBUTE_SPECIAL_VERTEX_ID     =     34,
204        MALI_ATTRIBUTE_SPECIAL_INSTANCE_ID   =     36,
205        MALI_ATTRIBUTE_SPECIAL_FRAG_COORD    =     37,
206        MALI_ATTRIBUTE_SPECIAL_FRONT_FACING  =     38,
207        MALI_ATTRIBUTE_SPECIAL_POINT_COORD   =     97,
208};
209
210static inline const char *
211mali_attribute_special_as_str(enum mali_attribute_special imm)
212{
213    switch (imm) {
214    case MALI_ATTRIBUTE_SPECIAL_VERTEX_ID: return "Vertex ID";
215    case MALI_ATTRIBUTE_SPECIAL_INSTANCE_ID: return "Instance ID";
216    case MALI_ATTRIBUTE_SPECIAL_FRAG_COORD: return "Frag Coord";
217    case MALI_ATTRIBUTE_SPECIAL_FRONT_FACING: return "Front Facing";
218    case MALI_ATTRIBUTE_SPECIAL_POINT_COORD: return "Point Coord";
219    default: return "XXX: INVALID";
220    }
221}
222
223enum mali_channel {
224        MALI_CHANNEL_R                       =      0,
225        MALI_CHANNEL_G                       =      1,
226        MALI_CHANNEL_B                       =      2,
227        MALI_CHANNEL_A                       =      3,
228        MALI_CHANNEL_0                       =      4,
229        MALI_CHANNEL_1                       =      5,
230};
231
232static inline const char *
233mali_channel_as_str(enum mali_channel imm)
234{
235    switch (imm) {
236    case MALI_CHANNEL_R: return "R";
237    case MALI_CHANNEL_G: return "G";
238    case MALI_CHANNEL_B: return "B";
239    case MALI_CHANNEL_A: return "A";
240    case MALI_CHANNEL_0: return "0";
241    case MALI_CHANNEL_1: return "1";
242    default: return "XXX: INVALID";
243    }
244}
245
246enum mali_depth_source {
247        MALI_DEPTH_SOURCE_MINIMUM            =      0,
248        MALI_DEPTH_SOURCE_MAXIMUM            =      1,
249        MALI_DEPTH_SOURCE_FIXED_FUNCTION     =      2,
250        MALI_DEPTH_SOURCE_SHADER             =      3,
251};
252
253static inline const char *
254mali_depth_source_as_str(enum mali_depth_source imm)
255{
256    switch (imm) {
257    case MALI_DEPTH_SOURCE_MINIMUM: return "Minimum";
258    case MALI_DEPTH_SOURCE_MAXIMUM: return "Maximum";
259    case MALI_DEPTH_SOURCE_FIXED_FUNCTION: return "Fixed function";
260    case MALI_DEPTH_SOURCE_SHADER: return "Shader";
261    default: return "XXX: INVALID";
262    }
263}
264
265enum mali_job_type {
266        MALI_JOB_TYPE_NOT_STARTED            =      0,
267        MALI_JOB_TYPE_NULL                   =      1,
268        MALI_JOB_TYPE_WRITE_VALUE            =      2,
269        MALI_JOB_TYPE_CACHE_FLUSH            =      3,
270        MALI_JOB_TYPE_COMPUTE                =      4,
271        MALI_JOB_TYPE_VERTEX                 =      5,
272        MALI_JOB_TYPE_GEOMETRY               =      6,
273        MALI_JOB_TYPE_TILER                  =      7,
274        MALI_JOB_TYPE_FUSED                  =      8,
275        MALI_JOB_TYPE_FRAGMENT               =      9,
276};
277
278static inline const char *
279mali_job_type_as_str(enum mali_job_type imm)
280{
281    switch (imm) {
282    case MALI_JOB_TYPE_NOT_STARTED: return "Not started";
283    case MALI_JOB_TYPE_NULL: return "Null";
284    case MALI_JOB_TYPE_WRITE_VALUE: return "Write value";
285    case MALI_JOB_TYPE_CACHE_FLUSH: return "Cache flush";
286    case MALI_JOB_TYPE_COMPUTE: return "Compute";
287    case MALI_JOB_TYPE_VERTEX: return "Vertex";
288    case MALI_JOB_TYPE_GEOMETRY: return "Geometry";
289    case MALI_JOB_TYPE_TILER: return "Tiler";
290    case MALI_JOB_TYPE_FUSED: return "Fused";
291    case MALI_JOB_TYPE_FRAGMENT: return "Fragment";
292    default: return "XXX: INVALID";
293    }
294}
295
296enum mali_draw_mode {
297        MALI_DRAW_MODE_POINTS                =      1,
298        MALI_DRAW_MODE_LINES                 =      2,
299        MALI_DRAW_MODE_LINES_WITH_ADJACENCY  =      3,
300        MALI_DRAW_MODE_LINE_STRIP            =      4,
301        MALI_DRAW_MODE_LINE_STRIP_WITH_ADJACENCY =      5,
302        MALI_DRAW_MODE_LINE_LOOP             =      6,
303        MALI_DRAW_MODE_TRIANGLES             =      8,
304        MALI_DRAW_MODE_TRIANGLES_WITH_ADJACENCY =      9,
305        MALI_DRAW_MODE_TRIANGLE_STRIP        =     10,
306        MALI_DRAW_MODE_TRIANGLE_STRIP_WITH_ADJACENCY =     11,
307        MALI_DRAW_MODE_TRIANGLE_FAN          =     12,
308        MALI_DRAW_MODE_POLYGON               =     13,
309        MALI_DRAW_MODE_QUADS                 =     14,
310        MALI_DRAW_MODE_QUAD_STRIP            =     15,
311        MALI_DRAW_MODE_PARALLELOGRAM         =     16,
312};
313
314static inline const char *
315mali_draw_mode_as_str(enum mali_draw_mode imm)
316{
317    switch (imm) {
318    case MALI_DRAW_MODE_POINTS: return "Points";
319    case MALI_DRAW_MODE_LINES: return "Lines";
320    case MALI_DRAW_MODE_LINES_WITH_ADJACENCY: return "Lines with adjacency";
321    case MALI_DRAW_MODE_LINE_STRIP: return "Line strip";
322    case MALI_DRAW_MODE_LINE_STRIP_WITH_ADJACENCY: return "Line strip with adjacency";
323    case MALI_DRAW_MODE_LINE_LOOP: return "Line loop";
324    case MALI_DRAW_MODE_TRIANGLES: return "Triangles";
325    case MALI_DRAW_MODE_TRIANGLES_WITH_ADJACENCY: return "Triangles with adjacency";
326    case MALI_DRAW_MODE_TRIANGLE_STRIP: return "Triangle strip";
327    case MALI_DRAW_MODE_TRIANGLE_STRIP_WITH_ADJACENCY: return "Triangle strip with adjacency";
328    case MALI_DRAW_MODE_TRIANGLE_FAN: return "Triangle fan";
329    case MALI_DRAW_MODE_POLYGON: return "Polygon";
330    case MALI_DRAW_MODE_QUADS: return "Quads";
331    case MALI_DRAW_MODE_QUAD_STRIP: return "Quad strip";
332    case MALI_DRAW_MODE_PARALLELOGRAM: return "Parallelogram";
333    default: return "XXX: INVALID";
334    }
335}
336
337enum mali_exception_access {
338        MALI_EXCEPTION_ACCESS_NONE           =      0,
339        MALI_EXCEPTION_ACCESS_EXECUTE        =      2,
340        MALI_EXCEPTION_ACCESS_READ           =      1,
341        MALI_EXCEPTION_ACCESS_WRITE          =      3,
342};
343
344static inline const char *
345mali_exception_access_as_str(enum mali_exception_access imm)
346{
347    switch (imm) {
348    case MALI_EXCEPTION_ACCESS_NONE: return "None";
349    case MALI_EXCEPTION_ACCESS_EXECUTE: return "Execute";
350    case MALI_EXCEPTION_ACCESS_READ: return "Read";
351    case MALI_EXCEPTION_ACCESS_WRITE: return "Write";
352    default: return "XXX: INVALID";
353    }
354}
355
356enum mali_func {
357        MALI_FUNC_NEVER                      =      0,
358        MALI_FUNC_LESS                       =      1,
359        MALI_FUNC_EQUAL                      =      2,
360        MALI_FUNC_LEQUAL                     =      3,
361        MALI_FUNC_GREATER                    =      4,
362        MALI_FUNC_NOT_EQUAL                  =      5,
363        MALI_FUNC_GEQUAL                     =      6,
364        MALI_FUNC_ALWAYS                     =      7,
365};
366
367static inline const char *
368mali_func_as_str(enum mali_func imm)
369{
370    switch (imm) {
371    case MALI_FUNC_NEVER: return "Never";
372    case MALI_FUNC_LESS: return "Less";
373    case MALI_FUNC_EQUAL: return "Equal";
374    case MALI_FUNC_LEQUAL: return "Lequal";
375    case MALI_FUNC_GREATER: return "Greater";
376    case MALI_FUNC_NOT_EQUAL: return "Not Equal";
377    case MALI_FUNC_GEQUAL: return "Gequal";
378    case MALI_FUNC_ALWAYS: return "Always";
379    default: return "XXX: INVALID";
380    }
381}
382
383enum mali_format {
384        MALI_ETC2_RGB8                       =      1,
385        MALI_ETC2_R11_UNORM                  =      2,
386        MALI_ETC2_RGBA8                      =      3,
387        MALI_ETC2_RG11_UNORM                 =      4,
388        MALI_NXR                             =      6,
389        MALI_BC1_UNORM                       =      7,
390        MALI_BC2_UNORM                       =      8,
391        MALI_BC3_UNORM                       =      9,
392        MALI_BC4_UNORM                       =     10,
393        MALI_BC4_SNORM                       =     11,
394        MALI_BC5_UNORM                       =     12,
395        MALI_BC5_SNORM                       =     13,
396        MALI_BC6H_UF16                       =     14,
397        MALI_BC6H_SF16                       =     15,
398        MALI_BC7_UNORM                       =     16,
399        MALI_ETC2_R11_SNORM                  =     17,
400        MALI_ETC2_RG11_SNORM                 =     18,
401        MALI_ETC2_RGB8A1                     =     19,
402        MALI_ASTC_3D_LDR                     =     20,
403        MALI_ASTC_3D_HDR                     =     21,
404        MALI_ASTC_2D_LDR                     =     22,
405        MALI_ASTC_2D_HDR                     =     23,
406        MALI_RGB565                          =     64,
407        MALI_RGB5_A1_UNORM                   =     65,
408        MALI_A1_BGR5_UNORM                   =     66,
409        MALI_RGB10_A2_UNORM                  =     67,
410        MALI_A2_BGR10_UNORM                  =     68,
411        MALI_RGB10_A2_SNORM                  =     69,
412        MALI_A2_BGR10_SNORM                  =     70,
413        MALI_RGB10_A2UI                      =     71,
414        MALI_A2_BGR10UI                      =     72,
415        MALI_RGB10_A2I                       =     73,
416        MALI_A2_BGR10I                       =     74,
417        MALI_RGB332_UNORM                    =     75,
418        MALI_BGR233_UNORM                    =     76,
419        MALI_Z24X8_UNORM                     =     77,
420        MALI_X8Z24                           =     78,
421        MALI_X32_S8X24                       =     79,
422        MALI_X24S8_X32                       =     80,
423        MALI_R32_FIXED                       =     81,
424        MALI_RG32_FIXED                      =     82,
425        MALI_RGB32_FIXED                     =     83,
426        MALI_RGBA32_FIXED                    =     84,
427        MALI_TILEBUFFER_NATIVE               =     85,
428        MALI_R11F_G11F_B10F                  =     89,
429        MALI_B10F_G11F_R11F                  =     90,
430        MALI_R9F_G9F_B9F_E5F                 =     91,
431        MALI_E5F_B9F_G9F_R9F                 =     92,
432        MALI_SNAP_2                          =     93,
433        MALI_SNAP_4                          =     94,
434        MALI_CONSTANT                        =     95,
435        MALI_R1_SNORM                        =     96,
436        MALI_R2_SNORM                        =     97,
437        MALI_R4_SNORM                        =     98,
438        MALI_R8_SNORM                        =     99,
439        MALI_R16_SNORM                       =    100,
440        MALI_R32_SNORM                       =    101,
441        MALI_R64_SNORM                       =    102,
442        MALI_RG1_SNORM                       =    104,
443        MALI_RG2_SNORM                       =    105,
444        MALI_RG4_SNORM                       =    106,
445        MALI_RG8_SNORM                       =    107,
446        MALI_RG16_SNORM                      =    108,
447        MALI_RG32_SNORM                      =    109,
448        MALI_RG64_SNORM                      =    110,
449        MALI_RGB1_SNORM                      =    112,
450        MALI_RGB2_SNORM                      =    113,
451        MALI_RGB4_SNORM                      =    114,
452        MALI_RGB8_SNORM                      =    115,
453        MALI_RGB16_SNORM                     =    116,
454        MALI_RGB32_SNORM                     =    117,
455        MALI_RGB64_SNORM                     =    118,
456        MALI_RGBA1_SNORM                     =    120,
457        MALI_RGBA2_SNORM                     =    121,
458        MALI_RGBA4_SNORM                     =    122,
459        MALI_RGBA8_SNORM                     =    123,
460        MALI_RGBA16_SNORM                    =    124,
461        MALI_RGBA32_SNORM                    =    125,
462        MALI_RGBA64_SNORM                    =    126,
463        MALI_R1UI                            =    128,
464        MALI_R2UI                            =    129,
465        MALI_R4UI                            =    130,
466        MALI_R8UI                            =    131,
467        MALI_R16UI                           =    132,
468        MALI_R32UI                           =    133,
469        MALI_R64UI                           =    134,
470        MALI_R64F                            =    135,
471        MALI_RG1UI                           =    136,
472        MALI_RG2UI                           =    137,
473        MALI_RG4UI                           =    138,
474        MALI_RG8UI                           =    139,
475        MALI_RG16UI                          =    140,
476        MALI_RG32UI                          =    141,
477        MALI_RG64UI                          =    142,
478        MALI_RG64F                           =    143,
479        MALI_RGB1UI                          =    144,
480        MALI_RGB2UI                          =    145,
481        MALI_RGB4UI                          =    146,
482        MALI_RGB8UI                          =    147,
483        MALI_RGB16UI                         =    148,
484        MALI_RGB32UI                         =    149,
485        MALI_RGB64UI                         =    150,
486        MALI_RGB64F                          =    151,
487        MALI_RGBA1UI                         =    152,
488        MALI_RGBA2UI                         =    153,
489        MALI_RGBA4UI                         =    154,
490        MALI_RGBA8UI                         =    155,
491        MALI_RGBA16UI                        =    156,
492        MALI_RGBA32UI                        =    157,
493        MALI_RGBA64UI                        =    158,
494        MALI_RGBA64F                         =    159,
495        MALI_R1_UNORM                        =    160,
496        MALI_R2_UNORM                        =    161,
497        MALI_R4_UNORM                        =    162,
498        MALI_R8_UNORM                        =    163,
499        MALI_R16_UNORM                       =    164,
500        MALI_R32_UNORM                       =    165,
501        MALI_R64_UNORM                       =    166,
502        MALI_R32F                            =    167,
503        MALI_RG1_UNORM                       =    168,
504        MALI_RG2_UNORM                       =    169,
505        MALI_RG4_UNORM                       =    170,
506        MALI_RG8_UNORM                       =    171,
507        MALI_RG16_UNORM                      =    172,
508        MALI_RG32_UNORM                      =    173,
509        MALI_RG64_UNORM                      =    174,
510        MALI_RG32F                           =    175,
511        MALI_RGB1_UNORM                      =    176,
512        MALI_RGB2_UNORM                      =    177,
513        MALI_RGB4_UNORM                      =    178,
514        MALI_RGB8_UNORM                      =    179,
515        MALI_RGB16_UNORM                     =    180,
516        MALI_RGB32_UNORM                     =    181,
517        MALI_RGB64_UNORM                     =    182,
518        MALI_RGB32F                          =    183,
519        MALI_RGBA1_UNORM                     =    184,
520        MALI_RGBA2_UNORM                     =    185,
521        MALI_RGBA4_UNORM                     =    186,
522        MALI_RGBA8_UNORM                     =    187,
523        MALI_RGBA16_UNORM                    =    188,
524        MALI_RGBA32_UNORM                    =    189,
525        MALI_RGBA64_UNORM                    =    190,
526        MALI_RGBA32F                         =    191,
527        MALI_R1I                             =    192,
528        MALI_R2I                             =    193,
529        MALI_R4I                             =    194,
530        MALI_R8I                             =    195,
531        MALI_R16I                            =    196,
532        MALI_R32I                            =    197,
533        MALI_R64I                            =    198,
534        MALI_R16F                            =    199,
535        MALI_RG1I                            =    200,
536        MALI_RG2I                            =    201,
537        MALI_RG4I                            =    202,
538        MALI_RG8I                            =    203,
539        MALI_RG16I                           =    204,
540        MALI_RG32I                           =    205,
541        MALI_RG64I                           =    206,
542        MALI_RG16F                           =    207,
543        MALI_RGB1I                           =    208,
544        MALI_RGB2I                           =    209,
545        MALI_RGB4I                           =    210,
546        MALI_RGB8I                           =    211,
547        MALI_RGB16I                          =    212,
548        MALI_RGB32I                          =    213,
549        MALI_RGB64I                          =    214,
550        MALI_RGB16F                          =    215,
551        MALI_RGBA1I                          =    216,
552        MALI_RGBA2I                          =    217,
553        MALI_RGBA4I                          =    218,
554        MALI_RGBA8I                          =    219,
555        MALI_RGBA16I                         =    220,
556        MALI_RGBA32I                         =    221,
557        MALI_RGBA64I                         =    222,
558        MALI_RGBA16F                         =    223,
559};
560
561static inline const char *
562mali_format_as_str(enum mali_format imm)
563{
564    switch (imm) {
565    case MALI_ETC2_RGB8: return "ETC2 RGB8";
566    case MALI_ETC2_R11_UNORM: return "ETC2 R11 UNORM";
567    case MALI_ETC2_RGBA8: return "ETC2 RGBA8";
568    case MALI_ETC2_RG11_UNORM: return "ETC2 RG11 UNORM";
569    case MALI_NXR: return "NXR";
570    case MALI_BC1_UNORM: return "BC1 UNORM";
571    case MALI_BC2_UNORM: return "BC2 UNORM";
572    case MALI_BC3_UNORM: return "BC3 UNORM";
573    case MALI_BC4_UNORM: return "BC4 UNORM";
574    case MALI_BC4_SNORM: return "BC4 SNORM";
575    case MALI_BC5_UNORM: return "BC5 UNORM";
576    case MALI_BC5_SNORM: return "BC5 SNORM";
577    case MALI_BC6H_UF16: return "BC6H UF16";
578    case MALI_BC6H_SF16: return "BC6H SF16";
579    case MALI_BC7_UNORM: return "BC7 UNORM";
580    case MALI_ETC2_R11_SNORM: return "ETC2 R11 SNORM";
581    case MALI_ETC2_RG11_SNORM: return "ETC2 RG11 SNORM";
582    case MALI_ETC2_RGB8A1: return "ETC2 RGB8A1";
583    case MALI_ASTC_3D_LDR: return "ASTC 3D LDR";
584    case MALI_ASTC_3D_HDR: return "ASTC 3D HDR";
585    case MALI_ASTC_2D_LDR: return "ASTC 2D LDR";
586    case MALI_ASTC_2D_HDR: return "ASTC 2D HDR";
587    case MALI_RGB565: return "RGB565";
588    case MALI_RGB5_A1_UNORM: return "RGB5 A1 UNORM";
589    case MALI_A1_BGR5_UNORM: return "A1 BGR5 UNORM";
590    case MALI_RGB10_A2_UNORM: return "RGB10 A2 UNORM";
591    case MALI_A2_BGR10_UNORM: return "A2 BGR10 UNORM";
592    case MALI_RGB10_A2_SNORM: return "RGB10 A2 SNORM";
593    case MALI_A2_BGR10_SNORM: return "A2 BGR10 SNORM";
594    case MALI_RGB10_A2UI: return "RGB10 A2UI";
595    case MALI_A2_BGR10UI: return "A2 BGR10UI";
596    case MALI_RGB10_A2I: return "RGB10 A2I";
597    case MALI_A2_BGR10I: return "A2 BGR10I";
598    case MALI_RGB332_UNORM: return "RGB332 UNORM";
599    case MALI_BGR233_UNORM: return "BGR233 UNORM";
600    case MALI_Z24X8_UNORM: return "Z24X8 UNORM";
601    case MALI_X8Z24: return "X8Z24";
602    case MALI_X32_S8X24: return "X32 S8X24";
603    case MALI_X24S8_X32: return "X24S8 X32";
604    case MALI_R32_FIXED: return "R32 FIXED";
605    case MALI_RG32_FIXED: return "RG32 FIXED";
606    case MALI_RGB32_FIXED: return "RGB32 FIXED";
607    case MALI_RGBA32_FIXED: return "RGBA32 FIXED";
608    case MALI_TILEBUFFER_NATIVE: return "Tilebuffer Native";
609    case MALI_R11F_G11F_B10F: return "R11F G11F B10F";
610    case MALI_B10F_G11F_R11F: return "B10F G11F R11F";
611    case MALI_R9F_G9F_B9F_E5F: return "R9F G9F B9F E5F";
612    case MALI_E5F_B9F_G9F_R9F: return "E5F B9F G9F R9F";
613    case MALI_SNAP_2: return "Snap 2";
614    case MALI_SNAP_4: return "Snap 4";
615    case MALI_CONSTANT: return "Constant";
616    case MALI_R1_SNORM: return "R1 SNORM";
617    case MALI_R2_SNORM: return "R2 SNORM";
618    case MALI_R4_SNORM: return "R4 SNORM";
619    case MALI_R8_SNORM: return "R8 SNORM";
620    case MALI_R16_SNORM: return "R16 SNORM";
621    case MALI_R32_SNORM: return "R32 SNORM";
622    case MALI_R64_SNORM: return "R64 SNORM";
623    case MALI_RG1_SNORM: return "RG1 SNORM";
624    case MALI_RG2_SNORM: return "RG2 SNORM";
625    case MALI_RG4_SNORM: return "RG4 SNORM";
626    case MALI_RG8_SNORM: return "RG8 SNORM";
627    case MALI_RG16_SNORM: return "RG16 SNORM";
628    case MALI_RG32_SNORM: return "RG32 SNORM";
629    case MALI_RG64_SNORM: return "RG64 SNORM";
630    case MALI_RGB1_SNORM: return "RGB1 SNORM";
631    case MALI_RGB2_SNORM: return "RGB2 SNORM";
632    case MALI_RGB4_SNORM: return "RGB4 SNORM";
633    case MALI_RGB8_SNORM: return "RGB8 SNORM";
634    case MALI_RGB16_SNORM: return "RGB16 SNORM";
635    case MALI_RGB32_SNORM: return "RGB32 SNORM";
636    case MALI_RGB64_SNORM: return "RGB64 SNORM";
637    case MALI_RGBA1_SNORM: return "RGBA1 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_RGBA64_SNORM: return "RGBA64 SNORM";
644    case MALI_R1UI: return "R1UI";
645    case MALI_R2UI: return "R2UI";
646    case MALI_R4UI: return "R4UI";
647    case MALI_R8UI: return "R8UI";
648    case MALI_R16UI: return "R16UI";
649    case MALI_R32UI: return "R32UI";
650    case MALI_R64UI: return "R64UI";
651    case MALI_R64F: return "R64F";
652    case MALI_RG1UI: return "RG1UI";
653    case MALI_RG2UI: return "RG2UI";
654    case MALI_RG4UI: return "RG4UI";
655    case MALI_RG8UI: return "RG8UI";
656    case MALI_RG16UI: return "RG16UI";
657    case MALI_RG32UI: return "RG32UI";
658    case MALI_RG64UI: return "RG64UI";
659    case MALI_RG64F: return "RG64F";
660    case MALI_RGB1UI: return "RGB1UI";
661    case MALI_RGB2UI: return "RGB2UI";
662    case MALI_RGB4UI: return "RGB4UI";
663    case MALI_RGB8UI: return "RGB8UI";
664    case MALI_RGB16UI: return "RGB16UI";
665    case MALI_RGB32UI: return "RGB32UI";
666    case MALI_RGB64UI: return "RGB64UI";
667    case MALI_RGB64F: return "RGB64F";
668    case MALI_RGBA1UI: return "RGBA1UI";
669    case MALI_RGBA2UI: return "RGBA2UI";
670    case MALI_RGBA4UI: return "RGBA4UI";
671    case MALI_RGBA8UI: return "RGBA8UI";
672    case MALI_RGBA16UI: return "RGBA16UI";
673    case MALI_RGBA32UI: return "RGBA32UI";
674    case MALI_RGBA64UI: return "RGBA64UI";
675    case MALI_RGBA64F: return "RGBA64F";
676    case MALI_R1_UNORM: return "R1 UNORM";
677    case MALI_R2_UNORM: return "R2 UNORM";
678    case MALI_R4_UNORM: return "R4 UNORM";
679    case MALI_R8_UNORM: return "R8 UNORM";
680    case MALI_R16_UNORM: return "R16 UNORM";
681    case MALI_R32_UNORM: return "R32 UNORM";
682    case MALI_R64_UNORM: return "R64 UNORM";
683    case MALI_R32F: return "R32F";
684    case MALI_RG1_UNORM: return "RG1 UNORM";
685    case MALI_RG2_UNORM: return "RG2 UNORM";
686    case MALI_RG4_UNORM: return "RG4 UNORM";
687    case MALI_RG8_UNORM: return "RG8 UNORM";
688    case MALI_RG16_UNORM: return "RG16 UNORM";
689    case MALI_RG32_UNORM: return "RG32 UNORM";
690    case MALI_RG64_UNORM: return "RG64 UNORM";
691    case MALI_RG32F: return "RG32F";
692    case MALI_RGB1_UNORM: return "RGB1 UNORM";
693    case MALI_RGB2_UNORM: return "RGB2 UNORM";
694    case MALI_RGB4_UNORM: return "RGB4 UNORM";
695    case MALI_RGB8_UNORM: return "RGB8 UNORM";
696    case MALI_RGB16_UNORM: return "RGB16 UNORM";
697    case MALI_RGB32_UNORM: return "RGB32 UNORM";
698    case MALI_RGB64_UNORM: return "RGB64 UNORM";
699    case MALI_RGB32F: return "RGB32F";
700    case MALI_RGBA1_UNORM: return "RGBA1 UNORM";
701    case MALI_RGBA2_UNORM: return "RGBA2 UNORM";
702    case MALI_RGBA4_UNORM: return "RGBA4 UNORM";
703    case MALI_RGBA8_UNORM: return "RGBA8 UNORM";
704    case MALI_RGBA16_UNORM: return "RGBA16 UNORM";
705    case MALI_RGBA32_UNORM: return "RGBA32 UNORM";
706    case MALI_RGBA64_UNORM: return "RGBA64 UNORM";
707    case MALI_RGBA32F: return "RGBA32F";
708    case MALI_R1I: return "R1I";
709    case MALI_R2I: return "R2I";
710    case MALI_R4I: return "R4I";
711    case MALI_R8I: return "R8I";
712    case MALI_R16I: return "R16I";
713    case MALI_R32I: return "R32I";
714    case MALI_R64I: return "R64I";
715    case MALI_R16F: return "R16F";
716    case MALI_RG1I: return "RG1I";
717    case MALI_RG2I: return "RG2I";
718    case MALI_RG4I: return "RG4I";
719    case MALI_RG8I: return "RG8I";
720    case MALI_RG16I: return "RG16I";
721    case MALI_RG32I: return "RG32I";
722    case MALI_RG64I: return "RG64I";
723    case MALI_RG16F: return "RG16F";
724    case MALI_RGB1I: return "RGB1I";
725    case MALI_RGB2I: return "RGB2I";
726    case MALI_RGB4I: return "RGB4I";
727    case MALI_RGB8I: return "RGB8I";
728    case MALI_RGB16I: return "RGB16I";
729    case MALI_RGB32I: return "RGB32I";
730    case MALI_RGB64I: return "RGB64I";
731    case MALI_RGB16F: return "RGB16F";
732    case MALI_RGBA1I: return "RGBA1I";
733    case MALI_RGBA2I: return "RGBA2I";
734    case MALI_RGBA4I: return "RGBA4I";
735    case MALI_RGBA8I: return "RGBA8I";
736    case MALI_RGBA16I: return "RGBA16I";
737    case MALI_RGBA32I: return "RGBA32I";
738    case MALI_RGBA64I: return "RGBA64I";
739    case MALI_RGBA16F: return "RGBA16F";
740    default: return "XXX: INVALID";
741    }
742}
743
744enum mali_yuv_swizzle {
745        MALI_YUV_SWIZZLE_YUVA                =      0,
746        MALI_YUV_SWIZZLE_YVUA                =      1,
747        MALI_YUV_SWIZZLE_UYVA                =      2,
748        MALI_YUV_SWIZZLE_UVYA                =      3,
749        MALI_YUV_SWIZZLE_VUYA                =      4,
750        MALI_YUV_SWIZZLE_VYUA                =      5,
751        MALI_YUV_SWIZZLE_Y00A                =      6,
752        MALI_YUV_SWIZZLE_YXXA                =      7,
753};
754
755static inline const char *
756mali_yuv_swizzle_as_str(enum mali_yuv_swizzle imm)
757{
758    switch (imm) {
759    case MALI_YUV_SWIZZLE_YUVA: return "YUVA";
760    case MALI_YUV_SWIZZLE_YVUA: return "YVUA";
761    case MALI_YUV_SWIZZLE_UYVA: return "UYVA";
762    case MALI_YUV_SWIZZLE_UVYA: return "UVYA";
763    case MALI_YUV_SWIZZLE_VUYA: return "VUYA";
764    case MALI_YUV_SWIZZLE_VYUA: return "VYUA";
765    case MALI_YUV_SWIZZLE_Y00A: return "Y00A";
766    case MALI_YUV_SWIZZLE_YXXA: return "YXXA";
767    default: return "XXX: INVALID";
768    }
769}
770
771enum mali_yuv_conversion_mode {
772        MALI_YUV_CONVERSION_MODE_NO_CONVERSION =      0,
773        MALI_YUV_CONVERSION_MODE_BT_601      =      3,
774        MALI_YUV_CONVERSION_MODE_BT_709      =      4,
775        MALI_YUV_CONVERSION_MODE_BT_2020     =      6,
776};
777
778static inline const char *
779mali_yuv_conversion_mode_as_str(enum mali_yuv_conversion_mode imm)
780{
781    switch (imm) {
782    case MALI_YUV_CONVERSION_MODE_NO_CONVERSION: return "No Conversion";
783    case MALI_YUV_CONVERSION_MODE_BT_601: return "BT 601";
784    case MALI_YUV_CONVERSION_MODE_BT_709: return "BT 709";
785    case MALI_YUV_CONVERSION_MODE_BT_2020: return "BT 2020";
786    default: return "XXX: INVALID";
787    }
788}
789
790enum mali_yuv_cr_siting {
791        MALI_YUV_CR_SITING_CO_SITED          =      0,
792        MALI_YUV_CR_SITING_CENTER_Y          =      1,
793        MALI_YUV_CR_SITING_CENTER_X          =      2,
794        MALI_YUV_CR_SITING_CENTER            =      3,
795        MALI_YUV_CR_SITING_ONE_QUARTER       =      4,
796        MALI_YUV_CR_SITING_THREE_QUARTERS    =      5,
797        MALI_YUV_CR_SITING_REPLICATED        =      7,
798};
799
800static inline const char *
801mali_yuv_cr_siting_as_str(enum mali_yuv_cr_siting imm)
802{
803    switch (imm) {
804    case MALI_YUV_CR_SITING_CO_SITED: return "Co-Sited";
805    case MALI_YUV_CR_SITING_CENTER_Y: return "Center Y";
806    case MALI_YUV_CR_SITING_CENTER_X: return "Center X";
807    case MALI_YUV_CR_SITING_CENTER: return "Center";
808    case MALI_YUV_CR_SITING_ONE_QUARTER: return "One Quarter";
809    case MALI_YUV_CR_SITING_THREE_QUARTERS: return "Three Quarters";
810    case MALI_YUV_CR_SITING_REPLICATED: return "Replicated";
811    default: return "XXX: INVALID";
812    }
813}
814
815enum mali_astc_2d_dimension {
816        MALI_ASTC_2D_DIMENSION_4             =      0,
817        MALI_ASTC_2D_DIMENSION_5             =      1,
818        MALI_ASTC_2D_DIMENSION_6             =      2,
819        MALI_ASTC_2D_DIMENSION_8             =      4,
820        MALI_ASTC_2D_DIMENSION_10            =      6,
821        MALI_ASTC_2D_DIMENSION_12            =      7,
822};
823
824static inline const char *
825mali_astc_2d_dimension_as_str(enum mali_astc_2d_dimension imm)
826{
827    switch (imm) {
828    case MALI_ASTC_2D_DIMENSION_4: return "4";
829    case MALI_ASTC_2D_DIMENSION_5: return "5";
830    case MALI_ASTC_2D_DIMENSION_6: return "6";
831    case MALI_ASTC_2D_DIMENSION_8: return "8";
832    case MALI_ASTC_2D_DIMENSION_10: return "10";
833    case MALI_ASTC_2D_DIMENSION_12: return "12";
834    default: return "XXX: INVALID";
835    }
836}
837
838enum mali_astc_3d_dimension {
839        MALI_ASTC_3D_DIMENSION_4             =      0,
840        MALI_ASTC_3D_DIMENSION_5             =      1,
841        MALI_ASTC_3D_DIMENSION_6             =      2,
842        MALI_ASTC_3D_DIMENSION_3             =      3,
843};
844
845static inline const char *
846mali_astc_3d_dimension_as_str(enum mali_astc_3d_dimension imm)
847{
848    switch (imm) {
849    case MALI_ASTC_3D_DIMENSION_4: return "4";
850    case MALI_ASTC_3D_DIMENSION_5: return "5";
851    case MALI_ASTC_3D_DIMENSION_6: return "6";
852    case MALI_ASTC_3D_DIMENSION_3: return "3";
853    default: return "XXX: INVALID";
854    }
855}
856
857enum mali_block_format {
858        MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED =      0,
859        MALI_BLOCK_FORMAT_TILED_LINEAR       =      1,
860        MALI_BLOCK_FORMAT_LINEAR             =      2,
861        MALI_BLOCK_FORMAT_AFBC               =      3,
862};
863
864static inline const char *
865mali_block_format_as_str(enum mali_block_format imm)
866{
867    switch (imm) {
868    case MALI_BLOCK_FORMAT_TILED_U_INTERLEAVED: return "Tiled U-Interleaved";
869    case MALI_BLOCK_FORMAT_TILED_LINEAR: return "Tiled Linear";
870    case MALI_BLOCK_FORMAT_LINEAR: return "Linear";
871    case MALI_BLOCK_FORMAT_AFBC: return "AFBC";
872    default: return "XXX: INVALID";
873    }
874}
875
876enum mali_mipmap_mode {
877        MALI_MIPMAP_MODE_NEAREST             =      0,
878        MALI_MIPMAP_MODE_PERFORMANCE_TRILINEAR =      2,
879        MALI_MIPMAP_MODE_TRILINEAR           =      3,
880};
881
882static inline const char *
883mali_mipmap_mode_as_str(enum mali_mipmap_mode imm)
884{
885    switch (imm) {
886    case MALI_MIPMAP_MODE_NEAREST: return "Nearest";
887    case MALI_MIPMAP_MODE_PERFORMANCE_TRILINEAR: return "Performance Trilinear";
888    case MALI_MIPMAP_MODE_TRILINEAR: return "Trilinear";
889    default: return "XXX: INVALID";
890    }
891}
892
893enum mali_msaa {
894        MALI_MSAA_SINGLE                     =      0,
895        MALI_MSAA_AVERAGE                    =      1,
896        MALI_MSAA_MULTIPLE                   =      2,
897        MALI_MSAA_LAYERED                    =      3,
898};
899
900static inline const char *
901mali_msaa_as_str(enum mali_msaa imm)
902{
903    switch (imm) {
904    case MALI_MSAA_SINGLE: return "Single";
905    case MALI_MSAA_AVERAGE: return "Average";
906    case MALI_MSAA_MULTIPLE: return "Multiple";
907    case MALI_MSAA_LAYERED: return "Layered";
908    default: return "XXX: INVALID";
909    }
910}
911
912enum mali_index_type {
913        MALI_INDEX_TYPE_NONE                 =      0,
914        MALI_INDEX_TYPE_UINT8                =      1,
915        MALI_INDEX_TYPE_UINT16               =      2,
916        MALI_INDEX_TYPE_UINT32               =      3,
917};
918
919static inline const char *
920mali_index_type_as_str(enum mali_index_type imm)
921{
922    switch (imm) {
923    case MALI_INDEX_TYPE_NONE: return "None";
924    case MALI_INDEX_TYPE_UINT8: return "UINT8";
925    case MALI_INDEX_TYPE_UINT16: return "UINT16";
926    case MALI_INDEX_TYPE_UINT32: return "UINT32";
927    default: return "XXX: INVALID";
928    }
929}
930
931enum mali_occlusion_mode {
932        MALI_OCCLUSION_MODE_DISABLED         =      0,
933        MALI_OCCLUSION_MODE_PREDICATE        =      1,
934        MALI_OCCLUSION_MODE_COUNTER          =      3,
935};
936
937static inline const char *
938mali_occlusion_mode_as_str(enum mali_occlusion_mode imm)
939{
940    switch (imm) {
941    case MALI_OCCLUSION_MODE_DISABLED: return "Disabled";
942    case MALI_OCCLUSION_MODE_PREDICATE: return "Predicate";
943    case MALI_OCCLUSION_MODE_COUNTER: return "Counter";
944    default: return "XXX: INVALID";
945    }
946}
947
948enum mali_stencil_op {
949        MALI_STENCIL_OP_KEEP                 =      0,
950        MALI_STENCIL_OP_REPLACE              =      1,
951        MALI_STENCIL_OP_ZERO                 =      2,
952        MALI_STENCIL_OP_INVERT               =      3,
953        MALI_STENCIL_OP_INCR_WRAP            =      4,
954        MALI_STENCIL_OP_DECR_WRAP            =      5,
955        MALI_STENCIL_OP_INCR_SAT             =      6,
956        MALI_STENCIL_OP_DECR_SAT             =      7,
957};
958
959static inline const char *
960mali_stencil_op_as_str(enum mali_stencil_op imm)
961{
962    switch (imm) {
963    case MALI_STENCIL_OP_KEEP: return "Keep";
964    case MALI_STENCIL_OP_REPLACE: return "Replace";
965    case MALI_STENCIL_OP_ZERO: return "Zero";
966    case MALI_STENCIL_OP_INVERT: return "Invert";
967    case MALI_STENCIL_OP_INCR_WRAP: return "Incr Wrap";
968    case MALI_STENCIL_OP_DECR_WRAP: return "Decr Wrap";
969    case MALI_STENCIL_OP_INCR_SAT: return "Incr Sat";
970    case MALI_STENCIL_OP_DECR_SAT: return "Decr Sat";
971    default: return "XXX: INVALID";
972    }
973}
974
975enum mali_texture_dimension {
976        MALI_TEXTURE_DIMENSION_CUBE          =      0,
977        MALI_TEXTURE_DIMENSION_1D            =      1,
978        MALI_TEXTURE_DIMENSION_2D            =      2,
979        MALI_TEXTURE_DIMENSION_3D            =      3,
980};
981
982static inline const char *
983mali_texture_dimension_as_str(enum mali_texture_dimension imm)
984{
985    switch (imm) {
986    case MALI_TEXTURE_DIMENSION_CUBE: return "Cube";
987    case MALI_TEXTURE_DIMENSION_1D: return "1D";
988    case MALI_TEXTURE_DIMENSION_2D: return "2D";
989    case MALI_TEXTURE_DIMENSION_3D: return "3D";
990    default: return "XXX: INVALID";
991    }
992}
993
994enum mali_texture_layout {
995        MALI_TEXTURE_LAYOUT_TILED            =      1,
996        MALI_TEXTURE_LAYOUT_LINEAR           =      2,
997        MALI_TEXTURE_LAYOUT_AFBC             =     12,
998};
999
1000static inline const char *
1001mali_texture_layout_as_str(enum mali_texture_layout imm)
1002{
1003    switch (imm) {
1004    case MALI_TEXTURE_LAYOUT_TILED: return "Tiled";
1005    case MALI_TEXTURE_LAYOUT_LINEAR: return "Linear";
1006    case MALI_TEXTURE_LAYOUT_AFBC: return "AFBC";
1007    default: return "XXX: INVALID";
1008    }
1009}
1010
1011enum mali_afbc_surface_flag {
1012        MALI_AFBC_SURFACE_FLAG_YTR           =      1,
1013};
1014
1015static inline const char *
1016mali_afbc_surface_flag_as_str(enum mali_afbc_surface_flag imm)
1017{
1018    switch (imm) {
1019    case MALI_AFBC_SURFACE_FLAG_YTR: return "YTR";
1020    default: return "XXX: INVALID";
1021    }
1022}
1023
1024enum mali_wrap_mode {
1025        MALI_WRAP_MODE_REPEAT                =      8,
1026        MALI_WRAP_MODE_CLAMP_TO_EDGE         =      9,
1027        MALI_WRAP_MODE_CLAMP                 =     10,
1028        MALI_WRAP_MODE_CLAMP_TO_BORDER       =     11,
1029        MALI_WRAP_MODE_MIRRORED_REPEAT       =     12,
1030        MALI_WRAP_MODE_MIRRORED_CLAMP_TO_EDGE =     13,
1031        MALI_WRAP_MODE_MIRRORED_CLAMP        =     14,
1032        MALI_WRAP_MODE_MIRRORED_CLAMP_TO_BORDER =     15,
1033};
1034
1035static inline const char *
1036mali_wrap_mode_as_str(enum mali_wrap_mode imm)
1037{
1038    switch (imm) {
1039    case MALI_WRAP_MODE_REPEAT: return "Repeat";
1040    case MALI_WRAP_MODE_CLAMP_TO_EDGE: return "Clamp to Edge";
1041    case MALI_WRAP_MODE_CLAMP: return "Clamp";
1042    case MALI_WRAP_MODE_CLAMP_TO_BORDER: return "Clamp to Border";
1043    case MALI_WRAP_MODE_MIRRORED_REPEAT: return "Mirrored Repeat";
1044    case MALI_WRAP_MODE_MIRRORED_CLAMP_TO_EDGE: return "Mirrored Clamp to Edge";
1045    case MALI_WRAP_MODE_MIRRORED_CLAMP: return "Mirrored Clamp";
1046    case MALI_WRAP_MODE_MIRRORED_CLAMP_TO_BORDER: return "Mirrored Clamp to Border";
1047    default: return "XXX: INVALID";
1048    }
1049}
1050
1051struct MALI_ATTRIBUTE {
1052   uint32_t                             buffer_index;
1053   bool                                 offset_enable;
1054   uint32_t                             format;
1055   int32_t                              offset;
1056};
1057
1058#define MALI_ATTRIBUTE_header                   \
1059   .offset_enable = true
1060
1061static inline void
1062MALI_ATTRIBUTE_pack(uint32_t * restrict cl,
1063                    const struct MALI_ATTRIBUTE * restrict values)
1064{
1065   cl[ 0] = __gen_uint(values->buffer_index, 0, 8) |
1066            __gen_uint(values->offset_enable, 9, 9) |
1067            __gen_uint(values->format, 10, 31);
1068   cl[ 1] = __gen_sint(values->offset, 0, 31);
1069}
1070
1071
1072#define MALI_ATTRIBUTE_LENGTH 8
1073#define MALI_ATTRIBUTE_ALIGN 8
1074struct mali_attribute_packed { uint32_t opaque[2]; };
1075static inline void
1076MALI_ATTRIBUTE_unpack(const uint8_t * restrict cl,
1077                      struct MALI_ATTRIBUTE * restrict values)
1078{
1079   values->buffer_index = __gen_unpack_uint(cl, 0, 8);
1080   values->offset_enable = __gen_unpack_uint(cl, 9, 9);
1081   values->format = __gen_unpack_uint(cl, 10, 31);
1082   values->offset = __gen_unpack_sint(cl, 32, 63);
1083}
1084
1085static inline void
1086MALI_ATTRIBUTE_print(FILE *fp, const struct MALI_ATTRIBUTE * values, unsigned indent)
1087{
1088   fprintf(fp, "%*sBuffer index: %u\n", indent, "", values->buffer_index);
1089   fprintf(fp, "%*sOffset enable: %s\n", indent, "", values->offset_enable ? "true" : "false");
1090   mali_pixel_format_print(fp, values->format);
1091   fprintf(fp, "%*sOffset: %d\n", indent, "", values->offset);
1092}
1093
1094struct MALI_ATTRIBUTE_VERTEX_ID {
1095   enum mali_attribute_special          type;
1096   uint32_t                             divisor_r;
1097   uint32_t                             divisor_p;
1098   int32_t                              offset;
1099};
1100
1101#define MALI_ATTRIBUTE_VERTEX_ID_header         \
1102   .type = MALI_ATTRIBUTE_SPECIAL_VERTEX_ID
1103
1104static inline void
1105MALI_ATTRIBUTE_VERTEX_ID_pack(uint32_t * restrict cl,
1106                              const struct MALI_ATTRIBUTE_VERTEX_ID * restrict values)
1107{
1108   cl[ 0] = __gen_uint(values->type, 0, 7);
1109   cl[ 1] = __gen_uint(values->divisor_r, 24, 28) |
1110            __gen_uint(values->divisor_p, 29, 31);
1111   cl[ 2] = 0;
1112   cl[ 3] = __gen_sint(values->offset, 0, 31);
1113}
1114
1115
1116#define MALI_ATTRIBUTE_VERTEX_ID_LENGTH 16
1117#define MALI_ATTRIBUTE_VERTEX_ID_ALIGN 32
1118struct mali_attribute_vertex_id_packed { uint32_t opaque[4]; };
1119static inline void
1120MALI_ATTRIBUTE_VERTEX_ID_unpack(const uint8_t * restrict cl,
1121                                struct MALI_ATTRIBUTE_VERTEX_ID * restrict values)
1122{
1123   if (((const uint32_t *) cl)[0] & 0xffffff00) fprintf(stderr, "XXX: Invalid field of Attribute Vertex ID unpacked at word 0\n");
1124   if (((const uint32_t *) cl)[1] & 0xffffff) fprintf(stderr, "XXX: Invalid field of Attribute Vertex ID unpacked at word 1\n");
1125   if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Attribute Vertex ID unpacked at word 2\n");
1126   values->type = (enum mali_attribute_special)__gen_unpack_uint(cl, 0, 7);
1127   values->divisor_r = __gen_unpack_uint(cl, 56, 60);
1128   values->divisor_p = __gen_unpack_uint(cl, 61, 63);
1129   values->offset = __gen_unpack_sint(cl, 96, 127);
1130}
1131
1132static inline void
1133MALI_ATTRIBUTE_VERTEX_ID_print(FILE *fp, const struct MALI_ATTRIBUTE_VERTEX_ID * values, unsigned indent)
1134{
1135   fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_special_as_str(values->type));
1136   fprintf(fp, "%*sDivisor R: %u\n", indent, "", values->divisor_r);
1137   fprintf(fp, "%*sDivisor P: %u\n", indent, "", values->divisor_p);
1138   fprintf(fp, "%*sOffset: %d\n", indent, "", values->offset);
1139}
1140
1141struct MALI_ATTRIBUTE_INSTANCE_ID {
1142   enum mali_attribute_special          type;
1143   uint32_t                             divisor_r;
1144   uint32_t                             divisor_e;
1145   uint32_t                             divisor_p;
1146   int32_t                              offset;
1147};
1148
1149#define MALI_ATTRIBUTE_INSTANCE_ID_header       \
1150   .type = MALI_ATTRIBUTE_SPECIAL_INSTANCE_ID
1151
1152static inline void
1153MALI_ATTRIBUTE_INSTANCE_ID_pack(uint32_t * restrict cl,
1154                                const struct MALI_ATTRIBUTE_INSTANCE_ID * restrict values)
1155{
1156   cl[ 0] = __gen_uint(values->type, 0, 7);
1157   cl[ 1] = __gen_uint(values->divisor_r, 24, 28) |
1158            __gen_uint(values->divisor_e, 29, 29);
1159   cl[ 2] = __gen_uint(values->divisor_p, 0, 31);
1160   cl[ 3] = __gen_sint(values->offset, 0, 31);
1161}
1162
1163
1164#define MALI_ATTRIBUTE_INSTANCE_ID_LENGTH 16
1165#define MALI_ATTRIBUTE_INSTANCE_ID_ALIGN 32
1166struct mali_attribute_instance_id_packed { uint32_t opaque[4]; };
1167static inline void
1168MALI_ATTRIBUTE_INSTANCE_ID_unpack(const uint8_t * restrict cl,
1169                                  struct MALI_ATTRIBUTE_INSTANCE_ID * restrict values)
1170{
1171   if (((const uint32_t *) cl)[0] & 0xffffff00) fprintf(stderr, "XXX: Invalid field of Attribute Instance ID unpacked at word 0\n");
1172   if (((const uint32_t *) cl)[1] & 0xc0ffffff) fprintf(stderr, "XXX: Invalid field of Attribute Instance ID unpacked at word 1\n");
1173   values->type = (enum mali_attribute_special)__gen_unpack_uint(cl, 0, 7);
1174   values->divisor_r = __gen_unpack_uint(cl, 56, 60);
1175   values->divisor_e = __gen_unpack_uint(cl, 61, 61);
1176   values->divisor_p = __gen_unpack_uint(cl, 64, 95);
1177   values->offset = __gen_unpack_sint(cl, 96, 127);
1178}
1179
1180static inline void
1181MALI_ATTRIBUTE_INSTANCE_ID_print(FILE *fp, const struct MALI_ATTRIBUTE_INSTANCE_ID * values, unsigned indent)
1182{
1183   fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_special_as_str(values->type));
1184   fprintf(fp, "%*sDivisor R: %u\n", indent, "", values->divisor_r);
1185   fprintf(fp, "%*sDivisor E: %u\n", indent, "", values->divisor_e);
1186   fprintf(fp, "%*sDivisor P: %u\n", indent, "", values->divisor_p);
1187   fprintf(fp, "%*sOffset: %d\n", indent, "", values->offset);
1188}
1189
1190struct MALI_ATTRIBUTE_BUFFER {
1191   enum mali_attribute_special          special;
1192   enum mali_attribute_type             type;
1193   uint64_t                             pointer;
1194   uint32_t                             stride;
1195   uint32_t                             size;
1196   uint32_t                             divisor;
1197   uint32_t                             divisor_r;
1198   uint32_t                             divisor_p;
1199   uint32_t                             divisor_e;
1200};
1201
1202#define MALI_ATTRIBUTE_BUFFER_header            \
1203   .type = MALI_ATTRIBUTE_TYPE_1D,  \
1204   .divisor = 1
1205
1206static inline void
1207MALI_ATTRIBUTE_BUFFER_pack(uint32_t * restrict cl,
1208                           const struct MALI_ATTRIBUTE_BUFFER * restrict values)
1209{
1210   assert((values->pointer & 0x3f) == 0);
1211   cl[ 0] = __gen_uint(values->special, 0, 7) |
1212            __gen_uint(values->type, 0, 5) |
1213            __gen_uint(values->pointer >> 6, 6, 55);
1214   cl[ 1] = __gen_uint(values->pointer >> 6, 6, 55) >> 32 |
1215            __gen_padded(values->divisor, 24, 31) |
1216            __gen_uint(values->divisor_r, 24, 28) |
1217            __gen_uint(values->divisor_p, 29, 31) |
1218            __gen_uint(values->divisor_e, 29, 29);
1219   cl[ 2] = __gen_uint(values->stride, 0, 31);
1220   cl[ 3] = __gen_uint(values->size, 0, 31);
1221}
1222
1223
1224#define MALI_ATTRIBUTE_BUFFER_LENGTH 16
1225#define MALI_ATTRIBUTE_BUFFER_ALIGN 32
1226struct mali_attribute_buffer_packed { uint32_t opaque[4]; };
1227static inline void
1228MALI_ATTRIBUTE_BUFFER_unpack(const uint8_t * restrict cl,
1229                             struct MALI_ATTRIBUTE_BUFFER * restrict values)
1230{
1231   values->special = (enum mali_attribute_special)__gen_unpack_uint(cl, 0, 7);
1232   values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
1233   values->pointer = __gen_unpack_uint(cl, 6, 55) << 6;
1234   values->stride = __gen_unpack_uint(cl, 64, 95);
1235   values->size = __gen_unpack_uint(cl, 96, 127);
1236   values->divisor = __gen_unpack_padded(cl, 56, 63);
1237   values->divisor_r = __gen_unpack_uint(cl, 56, 60);
1238   values->divisor_p = __gen_unpack_uint(cl, 61, 63);
1239   values->divisor_e = __gen_unpack_uint(cl, 61, 61);
1240}
1241
1242static inline void
1243MALI_ATTRIBUTE_BUFFER_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER * values, unsigned indent)
1244{
1245   fprintf(fp, "%*sSpecial: %s\n", indent, "", mali_attribute_special_as_str(values->special));
1246   fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
1247   fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
1248   fprintf(fp, "%*sStride: %u\n", indent, "", values->stride);
1249   fprintf(fp, "%*sSize: %u\n", indent, "", values->size);
1250   fprintf(fp, "%*sDivisor: %u\n", indent, "", values->divisor);
1251   fprintf(fp, "%*sDivisor R: %u\n", indent, "", values->divisor_r);
1252   fprintf(fp, "%*sDivisor P: %u\n", indent, "", values->divisor_p);
1253   fprintf(fp, "%*sDivisor E: %u\n", indent, "", values->divisor_e);
1254}
1255
1256struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT {
1257   enum mali_attribute_type             type;
1258   uint32_t                             divisor_numerator;
1259   uint32_t                             divisor;
1260};
1261
1262#define MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_header\
1263   .type = MALI_ATTRIBUTE_TYPE_CONTINUATION
1264
1265static inline void
1266MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_pack(uint32_t * restrict cl,
1267                                             const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * restrict values)
1268{
1269   cl[ 0] = __gen_uint(values->type, 0, 5);
1270   cl[ 1] = __gen_uint(values->divisor_numerator, 0, 31);
1271   cl[ 2] = 0;
1272   cl[ 3] = __gen_uint(values->divisor, 0, 31);
1273}
1274
1275
1276#define MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_LENGTH 16
1277struct mali_attribute_buffer_continuation_npot_packed { uint32_t opaque[4]; };
1278static inline void
1279MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_unpack(const uint8_t * restrict cl,
1280                                               struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * restrict values)
1281{
1282   if (((const uint32_t *) cl)[0] & 0xffffffc0) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation NPOT unpacked at word 0\n");
1283   if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation NPOT unpacked at word 2\n");
1284   values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
1285   values->divisor_numerator = __gen_unpack_uint(cl, 32, 63);
1286   values->divisor = __gen_unpack_uint(cl, 96, 127);
1287}
1288
1289static inline void
1290MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_NPOT * values, unsigned indent)
1291{
1292   fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
1293   fprintf(fp, "%*sDivisor Numerator: %u\n", indent, "", values->divisor_numerator);
1294   fprintf(fp, "%*sDivisor: %u\n", indent, "", values->divisor);
1295}
1296
1297struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D {
1298   enum mali_attribute_type             type;
1299   uint32_t                             s_dimension;
1300   uint32_t                             t_dimension;
1301   uint32_t                             r_dimension;
1302   uint32_t                             row_stride;
1303   uint32_t                             slice_stride;
1304};
1305
1306#define MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_header\
1307   .type = MALI_ATTRIBUTE_TYPE_CONTINUATION
1308
1309static inline void
1310MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_pack(uint32_t * restrict cl,
1311                                           const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * restrict values)
1312{
1313   assert(values->s_dimension >= 1);
1314   assert(values->t_dimension >= 1);
1315   assert(values->r_dimension >= 1);
1316   cl[ 0] = __gen_uint(values->type, 0, 5) |
1317            __gen_uint(values->s_dimension - 1, 16, 31);
1318   cl[ 1] = __gen_uint(values->t_dimension - 1, 0, 15) |
1319            __gen_uint(values->r_dimension - 1, 16, 31);
1320   cl[ 2] = __gen_uint(values->row_stride, 0, 31);
1321   cl[ 3] = __gen_uint(values->slice_stride, 0, 31);
1322}
1323
1324
1325#define MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_LENGTH 16
1326struct mali_attribute_buffer_continuation_3d_packed { uint32_t opaque[4]; };
1327static inline void
1328MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_unpack(const uint8_t * restrict cl,
1329                                             struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * restrict values)
1330{
1331   if (((const uint32_t *) cl)[0] & 0xffc0) fprintf(stderr, "XXX: Invalid field of Attribute Buffer Continuation 3D unpacked at word 0\n");
1332   values->type = (enum mali_attribute_type)__gen_unpack_uint(cl, 0, 5);
1333   values->s_dimension = __gen_unpack_uint(cl, 16, 31) + 1;
1334   values->t_dimension = __gen_unpack_uint(cl, 32, 47) + 1;
1335   values->r_dimension = __gen_unpack_uint(cl, 48, 63) + 1;
1336   values->row_stride = __gen_unpack_uint(cl, 64, 95);
1337   values->slice_stride = __gen_unpack_uint(cl, 96, 127);
1338}
1339
1340static inline void
1341MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D_print(FILE *fp, const struct MALI_ATTRIBUTE_BUFFER_CONTINUATION_3D * values, unsigned indent)
1342{
1343   fprintf(fp, "%*sType: %s\n", indent, "", mali_attribute_type_as_str(values->type));
1344   fprintf(fp, "%*sS dimension: %u\n", indent, "", values->s_dimension);
1345   fprintf(fp, "%*sT dimension: %u\n", indent, "", values->t_dimension);
1346   fprintf(fp, "%*sR dimension: %u\n", indent, "", values->r_dimension);
1347   fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
1348   fprintf(fp, "%*sSlice Stride: %u\n", indent, "", values->slice_stride);
1349}
1350
1351enum mali_blend_operand_a {
1352        MALI_BLEND_OPERAND_A_ZERO            =      1,
1353        MALI_BLEND_OPERAND_A_SRC             =      2,
1354        MALI_BLEND_OPERAND_A_DEST            =      3,
1355};
1356
1357static inline const char *
1358mali_blend_operand_a_as_str(enum mali_blend_operand_a imm)
1359{
1360    switch (imm) {
1361    case MALI_BLEND_OPERAND_A_ZERO: return "Zero";
1362    case MALI_BLEND_OPERAND_A_SRC: return "Src";
1363    case MALI_BLEND_OPERAND_A_DEST: return "Dest";
1364    default: return "XXX: INVALID";
1365    }
1366}
1367
1368enum mali_blend_operand_b {
1369        MALI_BLEND_OPERAND_B_SRC_MINUS_DEST  =      0,
1370        MALI_BLEND_OPERAND_B_SRC_PLUS_DEST   =      1,
1371        MALI_BLEND_OPERAND_B_SRC             =      2,
1372        MALI_BLEND_OPERAND_B_DEST            =      3,
1373};
1374
1375static inline const char *
1376mali_blend_operand_b_as_str(enum mali_blend_operand_b imm)
1377{
1378    switch (imm) {
1379    case MALI_BLEND_OPERAND_B_SRC_MINUS_DEST: return "Src Minus Dest";
1380    case MALI_BLEND_OPERAND_B_SRC_PLUS_DEST: return "Src Plus Dest";
1381    case MALI_BLEND_OPERAND_B_SRC: return "Src";
1382    case MALI_BLEND_OPERAND_B_DEST: return "Dest";
1383    default: return "XXX: INVALID";
1384    }
1385}
1386
1387enum mali_blend_operand_c {
1388        MALI_BLEND_OPERAND_C_ZERO            =      1,
1389        MALI_BLEND_OPERAND_C_SRC             =      2,
1390        MALI_BLEND_OPERAND_C_DEST            =      3,
1391        MALI_BLEND_OPERAND_C_SRC_X_2         =      4,
1392        MALI_BLEND_OPERAND_C_SRC_ALPHA       =      5,
1393        MALI_BLEND_OPERAND_C_DEST_ALPHA      =      6,
1394        MALI_BLEND_OPERAND_C_CONSTANT        =      7,
1395};
1396
1397static inline const char *
1398mali_blend_operand_c_as_str(enum mali_blend_operand_c imm)
1399{
1400    switch (imm) {
1401    case MALI_BLEND_OPERAND_C_ZERO: return "Zero";
1402    case MALI_BLEND_OPERAND_C_SRC: return "Src";
1403    case MALI_BLEND_OPERAND_C_DEST: return "Dest";
1404    case MALI_BLEND_OPERAND_C_SRC_X_2: return "Src x 2";
1405    case MALI_BLEND_OPERAND_C_SRC_ALPHA: return "Src Alpha";
1406    case MALI_BLEND_OPERAND_C_DEST_ALPHA: return "Dest Alpha";
1407    case MALI_BLEND_OPERAND_C_CONSTANT: return "Constant";
1408    default: return "XXX: INVALID";
1409    }
1410}
1411
1412struct MALI_BLEND_FUNCTION {
1413   enum mali_blend_operand_a            a;
1414   bool                                 negate_a;
1415   enum mali_blend_operand_b            b;
1416   bool                                 negate_b;
1417   enum mali_blend_operand_c            c;
1418   bool                                 invert_c;
1419};
1420
1421#define MALI_BLEND_FUNCTION_header              \
1422   0
1423
1424static inline void
1425MALI_BLEND_FUNCTION_print(FILE *fp, const struct MALI_BLEND_FUNCTION * values, unsigned indent)
1426{
1427   fprintf(fp, "%*sA: %s\n", indent, "", mali_blend_operand_a_as_str(values->a));
1428   fprintf(fp, "%*sNegate A: %s\n", indent, "", values->negate_a ? "true" : "false");
1429   fprintf(fp, "%*sB: %s\n", indent, "", mali_blend_operand_b_as_str(values->b));
1430   fprintf(fp, "%*sNegate B: %s\n", indent, "", values->negate_b ? "true" : "false");
1431   fprintf(fp, "%*sC: %s\n", indent, "", mali_blend_operand_c_as_str(values->c));
1432   fprintf(fp, "%*sInvert C: %s\n", indent, "", values->invert_c ? "true" : "false");
1433}
1434
1435struct MALI_BLEND_EQUATION {
1436   struct MALI_BLEND_FUNCTION           rgb;
1437   struct MALI_BLEND_FUNCTION           alpha;
1438   uint32_t                             color_mask;
1439};
1440
1441#define MALI_BLEND_EQUATION_header              \
1442   .rgb = { MALI_BLEND_FUNCTION_header },  \
1443   .alpha = { MALI_BLEND_FUNCTION_header }
1444
1445static inline void
1446MALI_BLEND_EQUATION_pack(uint32_t * restrict cl,
1447                         const struct MALI_BLEND_EQUATION * restrict values)
1448{
1449   cl[ 0] = __gen_uint(values->rgb.a, 0, 1) |
1450            __gen_uint(values->rgb.negate_a, 3, 3) |
1451            __gen_uint(values->rgb.b, 4, 5) |
1452            __gen_uint(values->rgb.negate_b, 7, 7) |
1453            __gen_uint(values->rgb.c, 8, 10) |
1454            __gen_uint(values->rgb.invert_c, 11, 11) |
1455            __gen_uint(values->alpha.a, 12, 13) |
1456            __gen_uint(values->alpha.negate_a, 15, 15) |
1457            __gen_uint(values->alpha.b, 16, 17) |
1458            __gen_uint(values->alpha.negate_b, 19, 19) |
1459            __gen_uint(values->alpha.c, 20, 22) |
1460            __gen_uint(values->alpha.invert_c, 23, 23) |
1461            __gen_uint(values->color_mask, 28, 31);
1462}
1463
1464
1465#define MALI_BLEND_EQUATION_LENGTH 4
1466struct mali_blend_equation_packed { uint32_t opaque[1]; };
1467static inline void
1468MALI_BLEND_EQUATION_unpack(const uint8_t * restrict cl,
1469                           struct MALI_BLEND_EQUATION * restrict values)
1470{
1471   if (((const uint32_t *) cl)[0] & 0xf044044) fprintf(stderr, "XXX: Invalid field of Blend Equation unpacked at word 0\n");
1472   values->rgb.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 0, 1);
1473   values->rgb.negate_a = __gen_unpack_uint(cl, 3, 3);
1474   values->rgb.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 4, 5);
1475   values->rgb.negate_b = __gen_unpack_uint(cl, 7, 7);
1476   values->rgb.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 8, 10);
1477   values->rgb.invert_c = __gen_unpack_uint(cl, 11, 11);
1478   values->alpha.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 12, 13);
1479   values->alpha.negate_a = __gen_unpack_uint(cl, 15, 15);
1480   values->alpha.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 16, 17);
1481   values->alpha.negate_b = __gen_unpack_uint(cl, 19, 19);
1482   values->alpha.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 20, 22);
1483   values->alpha.invert_c = __gen_unpack_uint(cl, 23, 23);
1484   values->color_mask = __gen_unpack_uint(cl, 28, 31);
1485}
1486
1487static inline void
1488MALI_BLEND_EQUATION_print(FILE *fp, const struct MALI_BLEND_EQUATION * values, unsigned indent)
1489{
1490   fprintf(fp, "%*sRGB:\n", indent, "");
1491   MALI_BLEND_FUNCTION_print(fp, &values->rgb, indent + 2);
1492   fprintf(fp, "%*sAlpha:\n", indent, "");
1493   MALI_BLEND_FUNCTION_print(fp, &values->alpha, indent + 2);
1494   fprintf(fp, "%*sColor Mask: %u\n", indent, "", values->color_mask);
1495}
1496
1497struct MALI_BLEND {
1498   bool                                 load_destination;
1499   bool                                 blend_shader;
1500   bool                                 blend_shader_contains_discard;
1501   bool                                 alpha_to_one;
1502   bool                                 enable;
1503   bool                                 srgb;
1504   bool                                 round_to_fb_precision;
1505   uint64_t                             shader_pc;
1506   struct MALI_BLEND_EQUATION           equation;
1507   float                                constant;
1508};
1509
1510#define MALI_BLEND_header                       \
1511   .load_destination = false,  \
1512   .blend_shader = false,  \
1513   .blend_shader_contains_discard = false,  \
1514   .enable = true,  \
1515   .srgb = false,  \
1516   .round_to_fb_precision = false,  \
1517   .equation = { MALI_BLEND_EQUATION_header }
1518
1519static inline void
1520MALI_BLEND_pack(uint32_t * restrict cl,
1521                const struct MALI_BLEND * restrict values)
1522{
1523   cl[ 0] = __gen_uint(values->load_destination, 0, 0) |
1524            __gen_uint(values->blend_shader, 1, 1) |
1525            __gen_uint(values->blend_shader_contains_discard, 2, 2) |
1526            __gen_uint(values->alpha_to_one, 8, 8) |
1527            __gen_uint(values->enable, 9, 9) |
1528            __gen_uint(values->srgb, 10, 10) |
1529            __gen_uint(values->round_to_fb_precision, 11, 11);
1530   cl[ 1] = 0;
1531   cl[ 2] = __gen_uint(values->shader_pc, 0, 63) |
1532            __gen_uint(values->equation.rgb.a, 0, 1) |
1533            __gen_uint(values->equation.rgb.negate_a, 3, 3) |
1534            __gen_uint(values->equation.rgb.b, 4, 5) |
1535            __gen_uint(values->equation.rgb.negate_b, 7, 7) |
1536            __gen_uint(values->equation.rgb.c, 8, 10) |
1537            __gen_uint(values->equation.rgb.invert_c, 11, 11) |
1538            __gen_uint(values->equation.alpha.a, 12, 13) |
1539            __gen_uint(values->equation.alpha.negate_a, 15, 15) |
1540            __gen_uint(values->equation.alpha.b, 16, 17) |
1541            __gen_uint(values->equation.alpha.negate_b, 19, 19) |
1542            __gen_uint(values->equation.alpha.c, 20, 22) |
1543            __gen_uint(values->equation.alpha.invert_c, 23, 23) |
1544            __gen_uint(values->equation.color_mask, 28, 31);
1545   cl[ 3] = __gen_uint(values->shader_pc, 0, 63) >> 32 |
1546            __gen_uint(fui(values->constant), 0, 32);
1547}
1548
1549
1550#define MALI_BLEND_LENGTH 16
1551#define MALI_BLEND_ALIGN 16
1552struct mali_blend_packed { uint32_t opaque[4]; };
1553static inline void
1554MALI_BLEND_unpack(const uint8_t * restrict cl,
1555                  struct MALI_BLEND * restrict values)
1556{
1557   if (((const uint32_t *) cl)[0] & 0xfffff0f8) fprintf(stderr, "XXX: Invalid field of Blend unpacked at word 0\n");
1558   if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Blend unpacked at word 1\n");
1559   values->load_destination = __gen_unpack_uint(cl, 0, 0);
1560   values->blend_shader = __gen_unpack_uint(cl, 1, 1);
1561   values->blend_shader_contains_discard = __gen_unpack_uint(cl, 2, 2);
1562   values->alpha_to_one = __gen_unpack_uint(cl, 8, 8);
1563   values->enable = __gen_unpack_uint(cl, 9, 9);
1564   values->srgb = __gen_unpack_uint(cl, 10, 10);
1565   values->round_to_fb_precision = __gen_unpack_uint(cl, 11, 11);
1566   values->shader_pc = __gen_unpack_uint(cl, 64, 127);
1567   values->equation.rgb.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 64, 65);
1568   values->equation.rgb.negate_a = __gen_unpack_uint(cl, 67, 67);
1569   values->equation.rgb.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 68, 69);
1570   values->equation.rgb.negate_b = __gen_unpack_uint(cl, 71, 71);
1571   values->equation.rgb.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 72, 74);
1572   values->equation.rgb.invert_c = __gen_unpack_uint(cl, 75, 75);
1573   values->equation.alpha.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 76, 77);
1574   values->equation.alpha.negate_a = __gen_unpack_uint(cl, 79, 79);
1575   values->equation.alpha.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 80, 81);
1576   values->equation.alpha.negate_b = __gen_unpack_uint(cl, 83, 83);
1577   values->equation.alpha.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 84, 86);
1578   values->equation.alpha.invert_c = __gen_unpack_uint(cl, 87, 87);
1579   values->equation.color_mask = __gen_unpack_uint(cl, 92, 95);
1580   values->constant = __gen_unpack_float(cl, 96, 127);
1581}
1582
1583static inline void
1584MALI_BLEND_print(FILE *fp, const struct MALI_BLEND * values, unsigned indent)
1585{
1586   fprintf(fp, "%*sLoad Destination: %s\n", indent, "", values->load_destination ? "true" : "false");
1587   fprintf(fp, "%*sBlend Shader: %s\n", indent, "", values->blend_shader ? "true" : "false");
1588   fprintf(fp, "%*sBlend Shader Contains Discard: %s\n", indent, "", values->blend_shader_contains_discard ? "true" : "false");
1589   fprintf(fp, "%*sAlpha To One: %s\n", indent, "", values->alpha_to_one ? "true" : "false");
1590   fprintf(fp, "%*sEnable: %s\n", indent, "", values->enable ? "true" : "false");
1591   fprintf(fp, "%*ssRGB: %s\n", indent, "", values->srgb ? "true" : "false");
1592   fprintf(fp, "%*sRound to FB precision: %s\n", indent, "", values->round_to_fb_precision ? "true" : "false");
1593   fprintf(fp, "%*sShader PC: 0x%" PRIx64 "\n", indent, "", values->shader_pc);
1594   fprintf(fp, "%*sEquation:\n", indent, "");
1595   MALI_BLEND_EQUATION_print(fp, &values->equation, indent + 2);
1596   fprintf(fp, "%*sConstant: %f\n", indent, "", values->constant);
1597}
1598
1599struct MALI_INVOCATION {
1600   uint32_t                             invocations;
1601   uint32_t                             size_y_shift;
1602   uint32_t                             size_z_shift;
1603   uint32_t                             workgroups_x_shift;
1604   uint32_t                             workgroups_y_shift;
1605   uint32_t                             workgroups_z_shift;
1606   uint32_t                             thread_group_split;
1607#define MALI_SPLIT_MIN_EFFICIENT                 2
1608};
1609
1610#define MALI_INVOCATION_header                  \
1611   0
1612
1613static inline void
1614MALI_INVOCATION_pack(uint32_t * restrict cl,
1615                     const struct MALI_INVOCATION * restrict values)
1616{
1617   cl[ 0] = __gen_uint(values->invocations, 0, 31);
1618   cl[ 1] = __gen_uint(values->size_y_shift, 0, 4) |
1619            __gen_uint(values->size_z_shift, 5, 9) |
1620            __gen_uint(values->workgroups_x_shift, 10, 15) |
1621            __gen_uint(values->workgroups_y_shift, 16, 21) |
1622            __gen_uint(values->workgroups_z_shift, 22, 27) |
1623            __gen_uint(values->thread_group_split, 28, 31);
1624}
1625
1626
1627#define MALI_INVOCATION_LENGTH 8
1628struct mali_invocation_packed { uint32_t opaque[2]; };
1629static inline void
1630MALI_INVOCATION_unpack(const uint8_t * restrict cl,
1631                       struct MALI_INVOCATION * restrict values)
1632{
1633   values->invocations = __gen_unpack_uint(cl, 0, 31);
1634   values->size_y_shift = __gen_unpack_uint(cl, 32, 36);
1635   values->size_z_shift = __gen_unpack_uint(cl, 37, 41);
1636   values->workgroups_x_shift = __gen_unpack_uint(cl, 42, 47);
1637   values->workgroups_y_shift = __gen_unpack_uint(cl, 48, 53);
1638   values->workgroups_z_shift = __gen_unpack_uint(cl, 54, 59);
1639   values->thread_group_split = __gen_unpack_uint(cl, 60, 63);
1640}
1641
1642static inline void
1643MALI_INVOCATION_print(FILE *fp, const struct MALI_INVOCATION * values, unsigned indent)
1644{
1645   fprintf(fp, "%*sInvocations: %u\n", indent, "", values->invocations);
1646   fprintf(fp, "%*sSize Y shift: %u\n", indent, "", values->size_y_shift);
1647   fprintf(fp, "%*sSize Z shift: %u\n", indent, "", values->size_z_shift);
1648   fprintf(fp, "%*sWorkgroups X shift: %u\n", indent, "", values->workgroups_x_shift);
1649   fprintf(fp, "%*sWorkgroups Y shift: %u\n", indent, "", values->workgroups_y_shift);
1650   fprintf(fp, "%*sWorkgroups Z shift: %u\n", indent, "", values->workgroups_z_shift);
1651   fprintf(fp, "%*sThread group split: %u\n", indent, "", values->thread_group_split);
1652}
1653
1654enum mali_point_size_array_format {
1655        MALI_POINT_SIZE_ARRAY_FORMAT_NONE    =      0,
1656        MALI_POINT_SIZE_ARRAY_FORMAT_FP16    =      2,
1657        MALI_POINT_SIZE_ARRAY_FORMAT_FP32    =      3,
1658};
1659
1660static inline const char *
1661mali_point_size_array_format_as_str(enum mali_point_size_array_format imm)
1662{
1663    switch (imm) {
1664    case MALI_POINT_SIZE_ARRAY_FORMAT_NONE: return "None";
1665    case MALI_POINT_SIZE_ARRAY_FORMAT_FP16: return "FP16";
1666    case MALI_POINT_SIZE_ARRAY_FORMAT_FP32: return "FP32";
1667    default: return "XXX: INVALID";
1668    }
1669}
1670
1671enum mali_primitive_restart {
1672        MALI_PRIMITIVE_RESTART_NONE          =      0,
1673        MALI_PRIMITIVE_RESTART_IMPLICIT      =      2,
1674        MALI_PRIMITIVE_RESTART_EXPLICIT      =      3,
1675};
1676
1677static inline const char *
1678mali_primitive_restart_as_str(enum mali_primitive_restart imm)
1679{
1680    switch (imm) {
1681    case MALI_PRIMITIVE_RESTART_NONE: return "None";
1682    case MALI_PRIMITIVE_RESTART_IMPLICIT: return "Implicit";
1683    case MALI_PRIMITIVE_RESTART_EXPLICIT: return "Explicit";
1684    default: return "XXX: INVALID";
1685    }
1686}
1687
1688struct MALI_PRIMITIVE {
1689   enum mali_draw_mode                  draw_mode;
1690   enum mali_index_type                 index_type;
1691   enum mali_point_size_array_format    point_size_array_format;
1692   bool                                 primitive_index_enable;
1693   bool                                 primitive_index_writeback;
1694   bool                                 first_provoking_vertex;
1695   bool                                 low_depth_cull;
1696   bool                                 high_depth_cull;
1697   enum mali_primitive_restart          primitive_restart;
1698   uint32_t                             job_task_split;
1699   uint32_t                             base_vertex_offset;
1700   uint32_t                             primitive_restart_index;
1701   uint32_t                             index_count;
1702   uint64_t                             indices;
1703};
1704
1705#define MALI_PRIMITIVE_header                   \
1706   .index_type = MALI_INDEX_TYPE_NONE,  \
1707   .first_provoking_vertex = true,  \
1708   .low_depth_cull = true,  \
1709   .high_depth_cull = true
1710
1711static inline void
1712MALI_PRIMITIVE_pack(uint32_t * restrict cl,
1713                    const struct MALI_PRIMITIVE * restrict values)
1714{
1715   assert(values->index_count >= 1);
1716   cl[ 0] = __gen_uint(values->draw_mode, 0, 7) |
1717            __gen_uint(values->index_type, 8, 10) |
1718            __gen_uint(values->point_size_array_format, 11, 12) |
1719            __gen_uint(values->primitive_index_enable, 13, 13) |
1720            __gen_uint(values->primitive_index_writeback, 14, 14) |
1721            __gen_uint(values->first_provoking_vertex, 15, 15) |
1722            __gen_uint(values->low_depth_cull, 16, 16) |
1723            __gen_uint(values->high_depth_cull, 17, 17) |
1724            __gen_uint(values->primitive_restart, 19, 20) |
1725            __gen_uint(values->job_task_split, 26, 31);
1726   cl[ 1] = __gen_uint(values->base_vertex_offset, 0, 31);
1727   cl[ 2] = __gen_uint(values->primitive_restart_index, 0, 31);
1728   cl[ 3] = __gen_uint(values->index_count - 1, 0, 31);
1729   cl[ 4] = __gen_uint(values->indices, 0, 63);
1730   cl[ 5] = __gen_uint(values->indices, 0, 63) >> 32;
1731}
1732
1733
1734#define MALI_PRIMITIVE_LENGTH 24
1735struct mali_primitive_packed { uint32_t opaque[6]; };
1736static inline void
1737MALI_PRIMITIVE_unpack(const uint8_t * restrict cl,
1738                      struct MALI_PRIMITIVE * restrict values)
1739{
1740   if (((const uint32_t *) cl)[0] & 0x3e40000) fprintf(stderr, "XXX: Invalid field of Primitive unpacked at word 0\n");
1741   values->draw_mode = (enum mali_draw_mode)__gen_unpack_uint(cl, 0, 7);
1742   values->index_type = (enum mali_index_type)__gen_unpack_uint(cl, 8, 10);
1743   values->point_size_array_format = (enum mali_point_size_array_format)__gen_unpack_uint(cl, 11, 12);
1744   values->primitive_index_enable = __gen_unpack_uint(cl, 13, 13);
1745   values->primitive_index_writeback = __gen_unpack_uint(cl, 14, 14);
1746   values->first_provoking_vertex = __gen_unpack_uint(cl, 15, 15);
1747   values->low_depth_cull = __gen_unpack_uint(cl, 16, 16);
1748   values->high_depth_cull = __gen_unpack_uint(cl, 17, 17);
1749   values->primitive_restart = (enum mali_primitive_restart)__gen_unpack_uint(cl, 19, 20);
1750   values->job_task_split = __gen_unpack_uint(cl, 26, 31);
1751   values->base_vertex_offset = __gen_unpack_uint(cl, 32, 63);
1752   values->primitive_restart_index = __gen_unpack_uint(cl, 64, 95);
1753   values->index_count = __gen_unpack_uint(cl, 96, 127) + 1;
1754   values->indices = __gen_unpack_uint(cl, 128, 191);
1755}
1756
1757static inline void
1758MALI_PRIMITIVE_print(FILE *fp, const struct MALI_PRIMITIVE * values, unsigned indent)
1759{
1760   fprintf(fp, "%*sDraw mode: %s\n", indent, "", mali_draw_mode_as_str(values->draw_mode));
1761   fprintf(fp, "%*sIndex type: %s\n", indent, "", mali_index_type_as_str(values->index_type));
1762   fprintf(fp, "%*sPoint size array format: %s\n", indent, "", mali_point_size_array_format_as_str(values->point_size_array_format));
1763   fprintf(fp, "%*sPrimitive Index Enable: %s\n", indent, "", values->primitive_index_enable ? "true" : "false");
1764   fprintf(fp, "%*sPrimitive Index Writeback: %s\n", indent, "", values->primitive_index_writeback ? "true" : "false");
1765   fprintf(fp, "%*sFirst provoking vertex: %s\n", indent, "", values->first_provoking_vertex ? "true" : "false");
1766   fprintf(fp, "%*sLow Depth Cull: %s\n", indent, "", values->low_depth_cull ? "true" : "false");
1767   fprintf(fp, "%*sHigh Depth Cull: %s\n", indent, "", values->high_depth_cull ? "true" : "false");
1768   fprintf(fp, "%*sPrimitive restart: %s\n", indent, "", mali_primitive_restart_as_str(values->primitive_restart));
1769   fprintf(fp, "%*sJob Task Split: %u\n", indent, "", values->job_task_split);
1770   fprintf(fp, "%*sBase vertex offset: %u\n", indent, "", values->base_vertex_offset);
1771   fprintf(fp, "%*sPrimitive Restart Index: %u\n", indent, "", values->primitive_restart_index);
1772   fprintf(fp, "%*sIndex count: %u\n", indent, "", values->index_count);
1773   fprintf(fp, "%*sIndices: 0x%" PRIx64 "\n", indent, "", values->indices);
1774}
1775
1776struct MALI_DRAW {
1777   bool                                 four_components_per_vertex;
1778   bool                                 draw_descriptor_is_64b;
1779   bool                                 texture_descriptor_is_64b;
1780   enum mali_occlusion_mode             occlusion_query;
1781   bool                                 front_face_ccw;
1782   bool                                 cull_front_face;
1783   bool                                 cull_back_face;
1784   uint32_t                             flat_shading_vertex;
1785   bool                                 exclude_filtered_perf_counters;
1786   bool                                 primitive_barrier;
1787   bool                                 clean_fragment_write;
1788   uint32_t                             instance_size;
1789   uint32_t                             instance_primitive_size;
1790   uint32_t                             offset_start;
1791   uint32_t                             primitive_index_base;
1792   uint64_t                             position;
1793   uint64_t                             uniform_buffers;
1794   uint64_t                             textures;
1795   uint64_t                             samplers;
1796   uint64_t                             push_uniforms;
1797   uint64_t                             state;
1798   uint64_t                             attribute_buffers;
1799   uint64_t                             attributes;
1800   uint64_t                             varying_buffers;
1801   uint64_t                             varyings;
1802   uint64_t                             viewport;
1803   uint64_t                             occlusion;
1804   uint64_t                             thread_storage;
1805   uint64_t                             fbd;
1806};
1807
1808#define MALI_DRAW_header                        \
1809   .texture_descriptor_is_64b = true,  \
1810   .occlusion_query = MALI_OCCLUSION_MODE_DISABLED,  \
1811   .instance_size = 1,  \
1812   .instance_primitive_size = 1
1813
1814static inline void
1815MALI_DRAW_pack(uint32_t * restrict cl,
1816               const struct MALI_DRAW * restrict values)
1817{
1818   cl[ 0] = __gen_uint(values->four_components_per_vertex, 0, 0) |
1819            __gen_uint(values->draw_descriptor_is_64b, 1, 1) |
1820            __gen_uint(values->texture_descriptor_is_64b, 2, 2) |
1821            __gen_uint(values->occlusion_query, 3, 4) |
1822            __gen_uint(values->front_face_ccw, 5, 5) |
1823            __gen_uint(values->cull_front_face, 6, 6) |
1824            __gen_uint(values->cull_back_face, 7, 7) |
1825            __gen_uint(values->flat_shading_vertex, 8, 8) |
1826            __gen_uint(values->exclude_filtered_perf_counters, 9, 9) |
1827            __gen_uint(values->primitive_barrier, 10, 10) |
1828            __gen_uint(values->clean_fragment_write, 11, 11) |
1829            __gen_padded(values->instance_size, 16, 23) |
1830            __gen_padded(values->instance_primitive_size, 24, 31);
1831   cl[ 1] = __gen_uint(values->offset_start, 0, 31);
1832   cl[ 2] = __gen_uint(values->primitive_index_base, 0, 31);
1833   cl[ 3] = 0;
1834   cl[ 4] = __gen_uint(values->position, 0, 63);
1835   cl[ 5] = __gen_uint(values->position, 0, 63) >> 32;
1836   cl[ 6] = __gen_uint(values->uniform_buffers, 0, 63);
1837   cl[ 7] = __gen_uint(values->uniform_buffers, 0, 63) >> 32;
1838   cl[ 8] = __gen_uint(values->textures, 0, 63);
1839   cl[ 9] = __gen_uint(values->textures, 0, 63) >> 32;
1840   cl[10] = __gen_uint(values->samplers, 0, 63);
1841   cl[11] = __gen_uint(values->samplers, 0, 63) >> 32;
1842   cl[12] = __gen_uint(values->push_uniforms, 0, 63);
1843   cl[13] = __gen_uint(values->push_uniforms, 0, 63) >> 32;
1844   cl[14] = __gen_uint(values->state, 0, 63);
1845   cl[15] = __gen_uint(values->state, 0, 63) >> 32;
1846   cl[16] = __gen_uint(values->attribute_buffers, 0, 63);
1847   cl[17] = __gen_uint(values->attribute_buffers, 0, 63) >> 32;
1848   cl[18] = __gen_uint(values->attributes, 0, 63);
1849   cl[19] = __gen_uint(values->attributes, 0, 63) >> 32;
1850   cl[20] = __gen_uint(values->varying_buffers, 0, 63);
1851   cl[21] = __gen_uint(values->varying_buffers, 0, 63) >> 32;
1852   cl[22] = __gen_uint(values->varyings, 0, 63);
1853   cl[23] = __gen_uint(values->varyings, 0, 63) >> 32;
1854   cl[24] = __gen_uint(values->viewport, 0, 63);
1855   cl[25] = __gen_uint(values->viewport, 0, 63) >> 32;
1856   cl[26] = __gen_uint(values->occlusion, 0, 63);
1857   cl[27] = __gen_uint(values->occlusion, 0, 63) >> 32;
1858   cl[28] = __gen_uint(values->thread_storage, 0, 63) |
1859            __gen_uint(values->fbd, 0, 63);
1860   cl[29] = __gen_uint(values->thread_storage, 0, 63) >> 32 |
1861            __gen_uint(values->fbd, 0, 63) >> 32;
1862}
1863
1864
1865#define MALI_DRAW_LENGTH 120
1866#define MALI_DRAW_ALIGN 64
1867struct mali_draw_packed { uint32_t opaque[30]; };
1868static inline void
1869MALI_DRAW_unpack(const uint8_t * restrict cl,
1870                 struct MALI_DRAW * restrict values)
1871{
1872   if (((const uint32_t *) cl)[0] & 0xf000) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 0\n");
1873   if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Draw unpacked at word 3\n");
1874   values->four_components_per_vertex = __gen_unpack_uint(cl, 0, 0);
1875   values->draw_descriptor_is_64b = __gen_unpack_uint(cl, 1, 1);
1876   values->texture_descriptor_is_64b = __gen_unpack_uint(cl, 2, 2);
1877   values->occlusion_query = (enum mali_occlusion_mode)__gen_unpack_uint(cl, 3, 4);
1878   values->front_face_ccw = __gen_unpack_uint(cl, 5, 5);
1879   values->cull_front_face = __gen_unpack_uint(cl, 6, 6);
1880   values->cull_back_face = __gen_unpack_uint(cl, 7, 7);
1881   values->flat_shading_vertex = __gen_unpack_uint(cl, 8, 8);
1882   values->exclude_filtered_perf_counters = __gen_unpack_uint(cl, 9, 9);
1883   values->primitive_barrier = __gen_unpack_uint(cl, 10, 10);
1884   values->clean_fragment_write = __gen_unpack_uint(cl, 11, 11);
1885   values->instance_size = __gen_unpack_padded(cl, 16, 23);
1886   values->instance_primitive_size = __gen_unpack_padded(cl, 24, 31);
1887   values->offset_start = __gen_unpack_uint(cl, 32, 63);
1888   values->primitive_index_base = __gen_unpack_uint(cl, 64, 95);
1889   values->position = __gen_unpack_uint(cl, 128, 191);
1890   values->uniform_buffers = __gen_unpack_uint(cl, 192, 255);
1891   values->textures = __gen_unpack_uint(cl, 256, 319);
1892   values->samplers = __gen_unpack_uint(cl, 320, 383);
1893   values->push_uniforms = __gen_unpack_uint(cl, 384, 447);
1894   values->state = __gen_unpack_uint(cl, 448, 511);
1895   values->attribute_buffers = __gen_unpack_uint(cl, 512, 575);
1896   values->attributes = __gen_unpack_uint(cl, 576, 639);
1897   values->varying_buffers = __gen_unpack_uint(cl, 640, 703);
1898   values->varyings = __gen_unpack_uint(cl, 704, 767);
1899   values->viewport = __gen_unpack_uint(cl, 768, 831);
1900   values->occlusion = __gen_unpack_uint(cl, 832, 895);
1901   values->thread_storage = __gen_unpack_uint(cl, 896, 959);
1902   values->fbd = __gen_unpack_uint(cl, 896, 959);
1903}
1904
1905static inline void
1906MALI_DRAW_print(FILE *fp, const struct MALI_DRAW * values, unsigned indent)
1907{
1908   fprintf(fp, "%*sFour Components Per Vertex: %s\n", indent, "", values->four_components_per_vertex ? "true" : "false");
1909   fprintf(fp, "%*sDraw Descriptor Is 64b: %s\n", indent, "", values->draw_descriptor_is_64b ? "true" : "false");
1910   fprintf(fp, "%*sTexture Descriptor Is 64b: %s\n", indent, "", values->texture_descriptor_is_64b ? "true" : "false");
1911   fprintf(fp, "%*sOcclusion query: %s\n", indent, "", mali_occlusion_mode_as_str(values->occlusion_query));
1912   fprintf(fp, "%*sFront face CCW: %s\n", indent, "", values->front_face_ccw ? "true" : "false");
1913   fprintf(fp, "%*sCull front face: %s\n", indent, "", values->cull_front_face ? "true" : "false");
1914   fprintf(fp, "%*sCull back face: %s\n", indent, "", values->cull_back_face ? "true" : "false");
1915   fprintf(fp, "%*sFlat Shading Vertex: %u\n", indent, "", values->flat_shading_vertex);
1916   fprintf(fp, "%*sExclude Filtered Perf Counters: %s\n", indent, "", values->exclude_filtered_perf_counters ? "true" : "false");
1917   fprintf(fp, "%*sPrimitive Barrier: %s\n", indent, "", values->primitive_barrier ? "true" : "false");
1918   fprintf(fp, "%*sClean Fragment Write: %s\n", indent, "", values->clean_fragment_write ? "true" : "false");
1919   fprintf(fp, "%*sInstance Size: %u\n", indent, "", values->instance_size);
1920   fprintf(fp, "%*sInstance Primitive Size: %u\n", indent, "", values->instance_primitive_size);
1921   fprintf(fp, "%*sOffset start: %u\n", indent, "", values->offset_start);
1922   fprintf(fp, "%*sPrimitive Index Base: %u\n", indent, "", values->primitive_index_base);
1923   fprintf(fp, "%*sPosition: 0x%" PRIx64 "\n", indent, "", values->position);
1924   fprintf(fp, "%*sUniform buffers: 0x%" PRIx64 "\n", indent, "", values->uniform_buffers);
1925   fprintf(fp, "%*sTextures: 0x%" PRIx64 "\n", indent, "", values->textures);
1926   fprintf(fp, "%*sSamplers: 0x%" PRIx64 "\n", indent, "", values->samplers);
1927   fprintf(fp, "%*sPush uniforms: 0x%" PRIx64 "\n", indent, "", values->push_uniforms);
1928   fprintf(fp, "%*sState: 0x%" PRIx64 "\n", indent, "", values->state);
1929   fprintf(fp, "%*sAttribute buffers: 0x%" PRIx64 "\n", indent, "", values->attribute_buffers);
1930   fprintf(fp, "%*sAttributes: 0x%" PRIx64 "\n", indent, "", values->attributes);
1931   fprintf(fp, "%*sVarying buffers: 0x%" PRIx64 "\n", indent, "", values->varying_buffers);
1932   fprintf(fp, "%*sVaryings: 0x%" PRIx64 "\n", indent, "", values->varyings);
1933   fprintf(fp, "%*sViewport: 0x%" PRIx64 "\n", indent, "", values->viewport);
1934   fprintf(fp, "%*sOcclusion: 0x%" PRIx64 "\n", indent, "", values->occlusion);
1935   fprintf(fp, "%*sThread Storage: 0x%" PRIx64 "\n", indent, "", values->thread_storage);
1936   fprintf(fp, "%*sFBD: 0x%" PRIx64 "\n", indent, "", values->fbd);
1937}
1938
1939struct MALI_SURFACE {
1940   uint64_t                             pointer;
1941};
1942
1943#define MALI_SURFACE_header                     \
1944   0
1945
1946static inline void
1947MALI_SURFACE_pack(uint32_t * restrict cl,
1948                  const struct MALI_SURFACE * restrict values)
1949{
1950   cl[ 0] = __gen_uint(values->pointer, 0, 63);
1951   cl[ 1] = __gen_uint(values->pointer, 0, 63) >> 32;
1952}
1953
1954
1955#define MALI_SURFACE_LENGTH 8
1956#define MALI_SURFACE_ALIGN 8
1957struct mali_surface_packed { uint32_t opaque[2]; };
1958static inline void
1959MALI_SURFACE_unpack(const uint8_t * restrict cl,
1960                    struct MALI_SURFACE * restrict values)
1961{
1962   values->pointer = __gen_unpack_uint(cl, 0, 63);
1963}
1964
1965static inline void
1966MALI_SURFACE_print(FILE *fp, const struct MALI_SURFACE * values, unsigned indent)
1967{
1968   fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
1969}
1970
1971struct MALI_SURFACE_WITH_STRIDE {
1972   uint64_t                             pointer;
1973   int32_t                              row_stride;
1974   int32_t                              surface_stride;
1975};
1976
1977#define MALI_SURFACE_WITH_STRIDE_header         \
1978   0
1979
1980static inline void
1981MALI_SURFACE_WITH_STRIDE_pack(uint32_t * restrict cl,
1982                              const struct MALI_SURFACE_WITH_STRIDE * restrict values)
1983{
1984   cl[ 0] = __gen_uint(values->pointer, 0, 63);
1985   cl[ 1] = __gen_uint(values->pointer, 0, 63) >> 32;
1986   cl[ 2] = __gen_sint(values->row_stride, 0, 31);
1987   cl[ 3] = __gen_sint(values->surface_stride, 0, 31);
1988}
1989
1990
1991#define MALI_SURFACE_WITH_STRIDE_LENGTH 16
1992#define MALI_SURFACE_WITH_STRIDE_ALIGN 8
1993struct mali_surface_with_stride_packed { uint32_t opaque[4]; };
1994static inline void
1995MALI_SURFACE_WITH_STRIDE_unpack(const uint8_t * restrict cl,
1996                                struct MALI_SURFACE_WITH_STRIDE * restrict values)
1997{
1998   values->pointer = __gen_unpack_uint(cl, 0, 63);
1999   values->row_stride = __gen_unpack_sint(cl, 64, 95);
2000   values->surface_stride = __gen_unpack_sint(cl, 96, 127);
2001}
2002
2003static inline void
2004MALI_SURFACE_WITH_STRIDE_print(FILE *fp, const struct MALI_SURFACE_WITH_STRIDE * values, unsigned indent)
2005{
2006   fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
2007   fprintf(fp, "%*sRow stride: %d\n", indent, "", values->row_stride);
2008   fprintf(fp, "%*sSurface stride: %d\n", indent, "", values->surface_stride);
2009}
2010
2011struct MALI_SAMPLER {
2012   bool                                 magnify_nearest;
2013   bool                                 minify_nearest;
2014   enum mali_mipmap_mode                mipmap_mode;
2015   bool                                 normalized_coordinates;
2016   bool                                 isotropic_lod;
2017   int32_t                              lod_bias;
2018   uint32_t                             minimum_lod;
2019   uint32_t                             maximum_lod;
2020   enum mali_wrap_mode                  wrap_mode_s;
2021   enum mali_wrap_mode                  wrap_mode_t;
2022   enum mali_wrap_mode                  wrap_mode_r;
2023   enum mali_func                       compare_function;
2024   bool                                 seamless_cube_map;
2025   uint32_t                             border_color_r;
2026   uint32_t                             border_color_g;
2027   uint32_t                             border_color_b;
2028   uint32_t                             border_color_a;
2029};
2030
2031#define MALI_SAMPLER_header                     \
2032   .magnify_nearest = true,  \
2033   .minify_nearest = true,  \
2034   .mipmap_mode = MALI_MIPMAP_MODE_NEAREST,  \
2035   .normalized_coordinates = true,  \
2036   .lod_bias = 0,  \
2037   .minimum_lod = 0,  \
2038   .maximum_lod = 1,  \
2039   .wrap_mode_s = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
2040   .wrap_mode_t = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
2041   .wrap_mode_r = MALI_WRAP_MODE_CLAMP_TO_EDGE,  \
2042   .compare_function = MALI_FUNC_NEVER,  \
2043   .seamless_cube_map = true,  \
2044   .border_color_r = 0.0,  \
2045   .border_color_g = 0.0,  \
2046   .border_color_b = 0.0,  \
2047   .border_color_a = 0.0
2048
2049static inline void
2050MALI_SAMPLER_pack(uint32_t * restrict cl,
2051                  const struct MALI_SAMPLER * restrict values)
2052{
2053   cl[ 0] = __gen_uint(values->magnify_nearest, 0, 0) |
2054            __gen_uint(values->minify_nearest, 1, 1) |
2055            __gen_uint(values->mipmap_mode, 3, 4) |
2056            __gen_uint(values->normalized_coordinates, 5, 5) |
2057            __gen_uint(values->isotropic_lod, 6, 6) |
2058            __gen_sint(values->lod_bias, 16, 31);
2059   cl[ 1] = __gen_uint(values->minimum_lod, 0, 15) |
2060            __gen_uint(values->maximum_lod, 16, 31);
2061   cl[ 2] = __gen_uint(values->wrap_mode_s, 0, 3) |
2062            __gen_uint(values->wrap_mode_t, 4, 7) |
2063            __gen_uint(values->wrap_mode_r, 8, 11) |
2064            __gen_uint(values->compare_function, 12, 14) |
2065            __gen_uint(values->seamless_cube_map, 15, 15);
2066   cl[ 3] = 0;
2067   cl[ 4] = __gen_uint(values->border_color_r, 0, 31);
2068   cl[ 5] = __gen_uint(values->border_color_g, 0, 31);
2069   cl[ 6] = __gen_uint(values->border_color_b, 0, 31);
2070   cl[ 7] = __gen_uint(values->border_color_a, 0, 31);
2071}
2072
2073
2074#define MALI_SAMPLER_LENGTH 32
2075#define MALI_SAMPLER_ALIGN 32
2076struct mali_sampler_packed { uint32_t opaque[8]; };
2077static inline void
2078MALI_SAMPLER_unpack(const uint8_t * restrict cl,
2079                    struct MALI_SAMPLER * restrict values)
2080{
2081   if (((const uint32_t *) cl)[0] & 0xff84) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 0\n");
2082   if (((const uint32_t *) cl)[2] & 0xffff0000) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 2\n");
2083   if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Sampler unpacked at word 3\n");
2084   values->magnify_nearest = __gen_unpack_uint(cl, 0, 0);
2085   values->minify_nearest = __gen_unpack_uint(cl, 1, 1);
2086   values->mipmap_mode = (enum mali_mipmap_mode)__gen_unpack_uint(cl, 3, 4);
2087   values->normalized_coordinates = __gen_unpack_uint(cl, 5, 5);
2088   values->isotropic_lod = __gen_unpack_uint(cl, 6, 6);
2089   values->lod_bias = __gen_unpack_sint(cl, 16, 31);
2090   values->minimum_lod = __gen_unpack_uint(cl, 32, 47);
2091   values->maximum_lod = __gen_unpack_uint(cl, 48, 63);
2092   values->wrap_mode_s = (enum mali_wrap_mode)__gen_unpack_uint(cl, 64, 67);
2093   values->wrap_mode_t = (enum mali_wrap_mode)__gen_unpack_uint(cl, 68, 71);
2094   values->wrap_mode_r = (enum mali_wrap_mode)__gen_unpack_uint(cl, 72, 75);
2095   values->compare_function = (enum mali_func)__gen_unpack_uint(cl, 76, 78);
2096   values->seamless_cube_map = __gen_unpack_uint(cl, 79, 79);
2097   values->border_color_r = __gen_unpack_uint(cl, 128, 159);
2098   values->border_color_g = __gen_unpack_uint(cl, 160, 191);
2099   values->border_color_b = __gen_unpack_uint(cl, 192, 223);
2100   values->border_color_a = __gen_unpack_uint(cl, 224, 255);
2101}
2102
2103static inline void
2104MALI_SAMPLER_print(FILE *fp, const struct MALI_SAMPLER * values, unsigned indent)
2105{
2106   fprintf(fp, "%*sMagnify Nearest: %s\n", indent, "", values->magnify_nearest ? "true" : "false");
2107   fprintf(fp, "%*sMinify Nearest: %s\n", indent, "", values->minify_nearest ? "true" : "false");
2108   fprintf(fp, "%*sMipmap Mode: %s\n", indent, "", mali_mipmap_mode_as_str(values->mipmap_mode));
2109   fprintf(fp, "%*sNormalized Coordinates: %s\n", indent, "", values->normalized_coordinates ? "true" : "false");
2110   fprintf(fp, "%*sIsotropic LOD: %s\n", indent, "", values->isotropic_lod ? "true" : "false");
2111   fprintf(fp, "%*sLOD Bias: %d\n", indent, "", values->lod_bias);
2112   fprintf(fp, "%*sMinimum LOD: %u\n", indent, "", values->minimum_lod);
2113   fprintf(fp, "%*sMaximum LOD: %u\n", indent, "", values->maximum_lod);
2114   fprintf(fp, "%*sWrap Mode S: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_s));
2115   fprintf(fp, "%*sWrap Mode T: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_t));
2116   fprintf(fp, "%*sWrap Mode R: %s\n", indent, "", mali_wrap_mode_as_str(values->wrap_mode_r));
2117   fprintf(fp, "%*sCompare Function: %s\n", indent, "", mali_func_as_str(values->compare_function));
2118   fprintf(fp, "%*sSeamless Cube Map: %s\n", indent, "", values->seamless_cube_map ? "true" : "false");
2119   fprintf(fp, "%*sBorder Color R: 0x%X (%f)\n", indent, "", values->border_color_r, uif(values->border_color_r));
2120   fprintf(fp, "%*sBorder Color G: 0x%X (%f)\n", indent, "", values->border_color_g, uif(values->border_color_g));
2121   fprintf(fp, "%*sBorder Color B: 0x%X (%f)\n", indent, "", values->border_color_b, uif(values->border_color_b));
2122   fprintf(fp, "%*sBorder Color A: 0x%X (%f)\n", indent, "", values->border_color_a, uif(values->border_color_a));
2123}
2124
2125struct MALI_TEXTURE {
2126   uint32_t                             width;
2127   uint32_t                             height;
2128   uint32_t                             depth;
2129   uint32_t                             sample_count;
2130   uint32_t                             array_size;
2131   uint32_t                             format;
2132   enum mali_texture_dimension          dimension;
2133   enum mali_texture_layout             texel_ordering;
2134   bool                                 surface_pointer_is_64b;
2135   bool                                 manual_stride;
2136   uint32_t                             levels;
2137   uint32_t                             swizzle;
2138};
2139
2140#define MALI_TEXTURE_header                     \
2141   .depth = 1,  \
2142   .sample_count = 1,  \
2143   .surface_pointer_is_64b = true,  \
2144   .manual_stride = false,  \
2145   .levels = 1
2146
2147static inline void
2148MALI_TEXTURE_pack(uint32_t * restrict cl,
2149                  const struct MALI_TEXTURE * restrict values)
2150{
2151   assert(values->width >= 1);
2152   assert(values->height >= 1);
2153   assert(values->depth >= 1);
2154   assert(values->sample_count >= 1);
2155   assert(values->array_size >= 1);
2156   assert(values->levels >= 1);
2157   cl[ 0] = __gen_uint(values->width - 1, 0, 15) |
2158            __gen_uint(values->height - 1, 16, 31);
2159   cl[ 1] = __gen_uint(values->depth - 1, 0, 15) |
2160            __gen_uint(values->sample_count - 1, 0, 15) |
2161            __gen_uint(values->array_size - 1, 16, 31);
2162   cl[ 2] = __gen_uint(values->format, 0, 21) |
2163            __gen_uint(values->dimension, 22, 23) |
2164            __gen_uint(values->texel_ordering, 24, 27) |
2165            __gen_uint(values->surface_pointer_is_64b, 28, 28) |
2166            __gen_uint(values->manual_stride, 29, 29);
2167   cl[ 3] = __gen_uint(values->levels - 1, 24, 31);
2168   cl[ 4] = __gen_uint(values->swizzle, 0, 11);
2169   cl[ 5] = 0;
2170   cl[ 6] = 0;
2171   cl[ 7] = 0;
2172}
2173
2174
2175#define MALI_TEXTURE_LENGTH 32
2176#define MALI_TEXTURE_ALIGN 64
2177struct mali_texture_packed { uint32_t opaque[8]; };
2178static inline void
2179MALI_TEXTURE_unpack(const uint8_t * restrict cl,
2180                    struct MALI_TEXTURE * restrict values)
2181{
2182   if (((const uint32_t *) cl)[2] & 0xc0000000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 2\n");
2183   if (((const uint32_t *) cl)[3] & 0xffffff) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 3\n");
2184   if (((const uint32_t *) cl)[4] & 0xfffff000) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 4\n");
2185   if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 5\n");
2186   if (((const uint32_t *) cl)[6] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 6\n");
2187   if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Texture unpacked at word 7\n");
2188   values->width = __gen_unpack_uint(cl, 0, 15) + 1;
2189   values->height = __gen_unpack_uint(cl, 16, 31) + 1;
2190   values->depth = __gen_unpack_uint(cl, 32, 47) + 1;
2191   values->sample_count = __gen_unpack_uint(cl, 32, 47) + 1;
2192   values->array_size = __gen_unpack_uint(cl, 48, 63) + 1;
2193   values->format = __gen_unpack_uint(cl, 64, 85);
2194   values->dimension = (enum mali_texture_dimension)__gen_unpack_uint(cl, 86, 87);
2195   values->texel_ordering = (enum mali_texture_layout)__gen_unpack_uint(cl, 88, 91);
2196   values->surface_pointer_is_64b = __gen_unpack_uint(cl, 92, 92);
2197   values->manual_stride = __gen_unpack_uint(cl, 93, 93);
2198   values->levels = __gen_unpack_uint(cl, 120, 127) + 1;
2199   values->swizzle = __gen_unpack_uint(cl, 128, 139);
2200}
2201
2202static inline void
2203MALI_TEXTURE_print(FILE *fp, const struct MALI_TEXTURE * values, unsigned indent)
2204{
2205   fprintf(fp, "%*sWidth: %u\n", indent, "", values->width);
2206   fprintf(fp, "%*sHeight: %u\n", indent, "", values->height);
2207   fprintf(fp, "%*sDepth: %u\n", indent, "", values->depth);
2208   fprintf(fp, "%*sSample count: %u\n", indent, "", values->sample_count);
2209   fprintf(fp, "%*sArray size: %u\n", indent, "", values->array_size);
2210   mali_pixel_format_print(fp, values->format);
2211   fprintf(fp, "%*sDimension: %s\n", indent, "", mali_texture_dimension_as_str(values->dimension));
2212   fprintf(fp, "%*sTexel ordering: %s\n", indent, "", mali_texture_layout_as_str(values->texel_ordering));
2213   fprintf(fp, "%*sSurface pointer is 64b: %s\n", indent, "", values->surface_pointer_is_64b ? "true" : "false");
2214   fprintf(fp, "%*sManual stride: %s\n", indent, "", values->manual_stride ? "true" : "false");
2215   fprintf(fp, "%*sLevels: %u\n", indent, "", values->levels);
2216   fprintf(fp, "%*sSwizzle: %u\n", indent, "", values->swizzle);
2217}
2218
2219enum mali_fp_mode {
2220        MALI_FP_MODE_GL_INF_NAN_ALLOWED      =      0,
2221        MALI_FP_MODE_GL_INF_NAN_SUPPRESSED   =      1,
2222        MALI_FP_MODE_CL                      =      2,
2223        MALI_FP_MODE_D3D11                   =      3,
2224};
2225
2226static inline const char *
2227mali_fp_mode_as_str(enum mali_fp_mode imm)
2228{
2229    switch (imm) {
2230    case MALI_FP_MODE_GL_INF_NAN_ALLOWED: return "GL Inf/NaN Allowed";
2231    case MALI_FP_MODE_GL_INF_NAN_SUPPRESSED: return "GL Inf/NaN Suppressed";
2232    case MALI_FP_MODE_CL: return "CL";
2233    case MALI_FP_MODE_D3D11: return "D3D11";
2234    default: return "XXX: INVALID";
2235    }
2236}
2237
2238struct MALI_RENDERER_PROPERTIES {
2239   uint32_t                             uniform_buffer_count;
2240   enum mali_depth_source               depth_source;
2241   bool                                 shader_contains_barrier;
2242   bool                                 force_early_z;
2243   bool                                 shader_contains_discard;
2244   bool                                 shader_has_side_effects;
2245   bool                                 shader_reads_tilebuffer;
2246   bool                                 forward_pixel_kill;
2247   uint32_t                             work_register_count;
2248   uint32_t                             uniform_count;
2249   bool                                 stencil_from_shader;
2250   enum mali_fp_mode                    fp_mode;
2251};
2252
2253#define MALI_RENDERER_PROPERTIES_header         \
2254   .depth_source = MALI_DEPTH_SOURCE_MINIMUM
2255
2256static inline void
2257MALI_RENDERER_PROPERTIES_pack(uint32_t * restrict cl,
2258                              const struct MALI_RENDERER_PROPERTIES * restrict values)
2259{
2260   cl[ 0] = __gen_uint(values->uniform_buffer_count, 0, 7) |
2261            __gen_uint(values->depth_source, 8, 9) |
2262            __gen_uint(values->shader_contains_barrier, 11, 11) |
2263            __gen_uint(values->force_early_z, 10, 10) |
2264            __gen_uint(values->shader_contains_discard, 12, 12) |
2265            __gen_uint(values->shader_has_side_effects, 13, 13) |
2266            __gen_uint(values->shader_reads_tilebuffer, 14, 14) |
2267            __gen_uint(values->forward_pixel_kill, 15, 15) |
2268            __gen_uint(values->work_register_count, 16, 20) |
2269            __gen_uint(values->uniform_count, 21, 25) |
2270            __gen_uint(values->stencil_from_shader, 28, 28) |
2271            __gen_uint(values->fp_mode, 29, 31);
2272}
2273
2274
2275#define MALI_RENDERER_PROPERTIES_LENGTH 4
2276struct mali_renderer_properties_packed { uint32_t opaque[1]; };
2277static inline void
2278MALI_RENDERER_PROPERTIES_unpack(const uint8_t * restrict cl,
2279                                struct MALI_RENDERER_PROPERTIES * restrict values)
2280{
2281   if (((const uint32_t *) cl)[0] & 0xc000000) fprintf(stderr, "XXX: Invalid field of Renderer Properties unpacked at word 0\n");
2282   values->uniform_buffer_count = __gen_unpack_uint(cl, 0, 7);
2283   values->depth_source = (enum mali_depth_source)__gen_unpack_uint(cl, 8, 9);
2284   values->shader_contains_barrier = __gen_unpack_uint(cl, 11, 11);
2285   values->force_early_z = __gen_unpack_uint(cl, 10, 10);
2286   values->shader_contains_discard = __gen_unpack_uint(cl, 12, 12);
2287   values->shader_has_side_effects = __gen_unpack_uint(cl, 13, 13);
2288   values->shader_reads_tilebuffer = __gen_unpack_uint(cl, 14, 14);
2289   values->forward_pixel_kill = __gen_unpack_uint(cl, 15, 15);
2290   values->work_register_count = __gen_unpack_uint(cl, 16, 20);
2291   values->uniform_count = __gen_unpack_uint(cl, 21, 25);
2292   values->stencil_from_shader = __gen_unpack_uint(cl, 28, 28);
2293   values->fp_mode = (enum mali_fp_mode)__gen_unpack_uint(cl, 29, 31);
2294}
2295
2296static inline void
2297MALI_RENDERER_PROPERTIES_print(FILE *fp, const struct MALI_RENDERER_PROPERTIES * values, unsigned indent)
2298{
2299   fprintf(fp, "%*sUniform buffer count: %u\n", indent, "", values->uniform_buffer_count);
2300   fprintf(fp, "%*sDepth source: %s\n", indent, "", mali_depth_source_as_str(values->depth_source));
2301   fprintf(fp, "%*sShader contains barrier: %s\n", indent, "", values->shader_contains_barrier ? "true" : "false");
2302   fprintf(fp, "%*sForce early-z: %s\n", indent, "", values->force_early_z ? "true" : "false");
2303   fprintf(fp, "%*sShader contains discard: %s\n", indent, "", values->shader_contains_discard ? "true" : "false");
2304   fprintf(fp, "%*sShader has side-effects: %s\n", indent, "", values->shader_has_side_effects ? "true" : "false");
2305   fprintf(fp, "%*sShader reads tilebuffer: %s\n", indent, "", values->shader_reads_tilebuffer ? "true" : "false");
2306   fprintf(fp, "%*sForward pixel kill: %s\n", indent, "", values->forward_pixel_kill ? "true" : "false");
2307   fprintf(fp, "%*sWork register count: %u\n", indent, "", values->work_register_count);
2308   fprintf(fp, "%*sUniform count: %u\n", indent, "", values->uniform_count);
2309   fprintf(fp, "%*sStencil from shader: %s\n", indent, "", values->stencil_from_shader ? "true" : "false");
2310   fprintf(fp, "%*sFP mode: %s\n", indent, "", mali_fp_mode_as_str(values->fp_mode));
2311}
2312
2313struct MALI_SHADER {
2314   uint64_t                             shader;
2315   uint32_t                             sampler_count;
2316   uint32_t                             texture_count;
2317   uint32_t                             attribute_count;
2318   uint32_t                             varying_count;
2319};
2320
2321#define MALI_SHADER_header                      \
2322   0
2323
2324static inline void
2325MALI_SHADER_pack(uint32_t * restrict cl,
2326                 const struct MALI_SHADER * restrict values)
2327{
2328   cl[ 0] = __gen_uint(values->shader, 0, 63);
2329   cl[ 1] = __gen_uint(values->shader, 0, 63) >> 32;
2330   cl[ 2] = __gen_uint(values->sampler_count, 0, 15) |
2331            __gen_uint(values->texture_count, 16, 31);
2332   cl[ 3] = __gen_uint(values->attribute_count, 0, 15) |
2333            __gen_uint(values->varying_count, 16, 31);
2334}
2335
2336
2337#define MALI_SHADER_LENGTH 16
2338struct mali_shader_packed { uint32_t opaque[4]; };
2339static inline void
2340MALI_SHADER_unpack(const uint8_t * restrict cl,
2341                   struct MALI_SHADER * restrict values)
2342{
2343   values->shader = __gen_unpack_uint(cl, 0, 63);
2344   values->sampler_count = __gen_unpack_uint(cl, 64, 79);
2345   values->texture_count = __gen_unpack_uint(cl, 80, 95);
2346   values->attribute_count = __gen_unpack_uint(cl, 96, 111);
2347   values->varying_count = __gen_unpack_uint(cl, 112, 127);
2348}
2349
2350static inline void
2351MALI_SHADER_print(FILE *fp, const struct MALI_SHADER * values, unsigned indent)
2352{
2353   fprintf(fp, "%*sShader: 0x%" PRIx64 "\n", indent, "", values->shader);
2354   fprintf(fp, "%*sSampler count: %u\n", indent, "", values->sampler_count);
2355   fprintf(fp, "%*sTexture count: %u\n", indent, "", values->texture_count);
2356   fprintf(fp, "%*sAttribute count: %u\n", indent, "", values->attribute_count);
2357   fprintf(fp, "%*sVarying count: %u\n", indent, "", values->varying_count);
2358}
2359
2360struct MALI_MULTISAMPLE_MISC {
2361   uint32_t                             sample_mask;
2362   bool                                 multisample_enable;
2363   bool                                 multisample_late_coverage;
2364   bool                                 evaluate_per_sample;
2365   bool                                 fixed_function_depth_range_fixed;
2366   bool                                 shader_depth_range_fixed;
2367   enum mali_func                       depth_function;
2368   bool                                 depth_write_mask;
2369   bool                                 fixed_function_near_discard;
2370   bool                                 fixed_function_far_discard;
2371   bool                                 fragment_near_discard;
2372   bool                                 fragment_far_discard;
2373};
2374
2375#define MALI_MULTISAMPLE_MISC_header            \
2376   0
2377
2378static inline void
2379MALI_MULTISAMPLE_MISC_pack(uint32_t * restrict cl,
2380                           const struct MALI_MULTISAMPLE_MISC * restrict values)
2381{
2382   cl[ 0] = __gen_uint(values->sample_mask, 0, 15) |
2383            __gen_uint(values->multisample_enable, 16, 16) |
2384            __gen_uint(values->multisample_late_coverage, 17, 17) |
2385            __gen_uint(values->evaluate_per_sample, 18, 18) |
2386            __gen_uint(values->fixed_function_depth_range_fixed, 19, 19) |
2387            __gen_uint(values->shader_depth_range_fixed, 20, 20) |
2388            __gen_uint(values->depth_function, 24, 26) |
2389            __gen_uint(values->depth_write_mask, 27, 27) |
2390            __gen_uint(values->fixed_function_near_discard, 28, 28) |
2391            __gen_uint(values->fixed_function_far_discard, 29, 29) |
2392            __gen_uint(values->fragment_near_discard, 30, 30) |
2393            __gen_uint(values->fragment_far_discard, 31, 31);
2394}
2395
2396
2397#define MALI_MULTISAMPLE_MISC_LENGTH 4
2398struct mali_multisample_misc_packed { uint32_t opaque[1]; };
2399static inline void
2400MALI_MULTISAMPLE_MISC_unpack(const uint8_t * restrict cl,
2401                             struct MALI_MULTISAMPLE_MISC * restrict values)
2402{
2403   if (((const uint32_t *) cl)[0] & 0xe00000) fprintf(stderr, "XXX: Invalid field of Multisample, Misc unpacked at word 0\n");
2404   values->sample_mask = __gen_unpack_uint(cl, 0, 15);
2405   values->multisample_enable = __gen_unpack_uint(cl, 16, 16);
2406   values->multisample_late_coverage = __gen_unpack_uint(cl, 17, 17);
2407   values->evaluate_per_sample = __gen_unpack_uint(cl, 18, 18);
2408   values->fixed_function_depth_range_fixed = __gen_unpack_uint(cl, 19, 19);
2409   values->shader_depth_range_fixed = __gen_unpack_uint(cl, 20, 20);
2410   values->depth_function = (enum mali_func)__gen_unpack_uint(cl, 24, 26);
2411   values->depth_write_mask = __gen_unpack_uint(cl, 27, 27);
2412   values->fixed_function_near_discard = __gen_unpack_uint(cl, 28, 28);
2413   values->fixed_function_far_discard = __gen_unpack_uint(cl, 29, 29);
2414   values->fragment_near_discard = __gen_unpack_uint(cl, 30, 30);
2415   values->fragment_far_discard = __gen_unpack_uint(cl, 31, 31);
2416}
2417
2418static inline void
2419MALI_MULTISAMPLE_MISC_print(FILE *fp, const struct MALI_MULTISAMPLE_MISC * values, unsigned indent)
2420{
2421   fprintf(fp, "%*sSample mask: %u\n", indent, "", values->sample_mask);
2422   fprintf(fp, "%*sMultisample enable: %s\n", indent, "", values->multisample_enable ? "true" : "false");
2423   fprintf(fp, "%*sMultisample late coverage: %s\n", indent, "", values->multisample_late_coverage ? "true" : "false");
2424   fprintf(fp, "%*sEvaluate per-sample: %s\n", indent, "", values->evaluate_per_sample ? "true" : "false");
2425   fprintf(fp, "%*sFixed-function depth range fixed: %s\n", indent, "", values->fixed_function_depth_range_fixed ? "true" : "false");
2426   fprintf(fp, "%*sShader depth range fixed: %s\n", indent, "", values->shader_depth_range_fixed ? "true" : "false");
2427   fprintf(fp, "%*sDepth function: %s\n", indent, "", mali_func_as_str(values->depth_function));
2428   fprintf(fp, "%*sDepth write mask: %s\n", indent, "", values->depth_write_mask ? "true" : "false");
2429   fprintf(fp, "%*sFixed-function near discard: %s\n", indent, "", values->fixed_function_near_discard ? "true" : "false");
2430   fprintf(fp, "%*sFixed-function far discard: %s\n", indent, "", values->fixed_function_far_discard ? "true" : "false");
2431   fprintf(fp, "%*sFragment near discard: %s\n", indent, "", values->fragment_near_discard ? "true" : "false");
2432   fprintf(fp, "%*sFragment far discard: %s\n", indent, "", values->fragment_far_discard ? "true" : "false");
2433}
2434
2435struct MALI_STENCIL_MASK_MISC {
2436   uint32_t                             stencil_mask_front;
2437   uint32_t                             stencil_mask_back;
2438   bool                                 stencil_enable;
2439   bool                                 alpha_to_coverage;
2440   bool                                 alpha_to_coverage_invert;
2441   enum mali_func                       alpha_test_compare_function;
2442   bool                                 force_seamless_cubemaps;
2443   bool                                 depth_range_1;
2444   bool                                 depth_range_2;
2445   bool                                 single_sampled_lines;
2446   bool                                 point_snap;
2447};
2448
2449#define MALI_STENCIL_MASK_MISC_header           \
2450   0
2451
2452static inline void
2453MALI_STENCIL_MASK_MISC_pack(uint32_t * restrict cl,
2454                            const struct MALI_STENCIL_MASK_MISC * restrict values)
2455{
2456   cl[ 0] = __gen_uint(values->stencil_mask_front, 0, 7) |
2457            __gen_uint(values->stencil_mask_back, 8, 15) |
2458            __gen_uint(values->stencil_enable, 16, 16) |
2459            __gen_uint(values->alpha_to_coverage, 17, 17) |
2460            __gen_uint(values->alpha_to_coverage_invert, 18, 18) |
2461            __gen_uint(values->alpha_test_compare_function, 21, 23) |
2462            __gen_uint(values->force_seamless_cubemaps, 26, 26) |
2463            __gen_uint(values->depth_range_1, 28, 28) |
2464            __gen_uint(values->depth_range_2, 29, 29) |
2465            __gen_uint(values->single_sampled_lines, 30, 30) |
2466            __gen_uint(values->point_snap, 31, 31);
2467}
2468
2469
2470#define MALI_STENCIL_MASK_MISC_LENGTH 4
2471struct mali_stencil_mask_misc_packed { uint32_t opaque[1]; };
2472static inline void
2473MALI_STENCIL_MASK_MISC_unpack(const uint8_t * restrict cl,
2474                              struct MALI_STENCIL_MASK_MISC * restrict values)
2475{
2476   if (((const uint32_t *) cl)[0] & 0xb180000) fprintf(stderr, "XXX: Invalid field of Stencil Mask, Misc unpacked at word 0\n");
2477   values->stencil_mask_front = __gen_unpack_uint(cl, 0, 7);
2478   values->stencil_mask_back = __gen_unpack_uint(cl, 8, 15);
2479   values->stencil_enable = __gen_unpack_uint(cl, 16, 16);
2480   values->alpha_to_coverage = __gen_unpack_uint(cl, 17, 17);
2481   values->alpha_to_coverage_invert = __gen_unpack_uint(cl, 18, 18);
2482   values->alpha_test_compare_function = (enum mali_func)__gen_unpack_uint(cl, 21, 23);
2483   values->force_seamless_cubemaps = __gen_unpack_uint(cl, 26, 26);
2484   values->depth_range_1 = __gen_unpack_uint(cl, 28, 28);
2485   values->depth_range_2 = __gen_unpack_uint(cl, 29, 29);
2486   values->single_sampled_lines = __gen_unpack_uint(cl, 30, 30);
2487   values->point_snap = __gen_unpack_uint(cl, 31, 31);
2488}
2489
2490static inline void
2491MALI_STENCIL_MASK_MISC_print(FILE *fp, const struct MALI_STENCIL_MASK_MISC * values, unsigned indent)
2492{
2493   fprintf(fp, "%*sStencil mask front: %u\n", indent, "", values->stencil_mask_front);
2494   fprintf(fp, "%*sStencil mask back: %u\n", indent, "", values->stencil_mask_back);
2495   fprintf(fp, "%*sStencil enable: %s\n", indent, "", values->stencil_enable ? "true" : "false");
2496   fprintf(fp, "%*sAlpha-to-coverage: %s\n", indent, "", values->alpha_to_coverage ? "true" : "false");
2497   fprintf(fp, "%*sAlpha-to-coverage Invert: %s\n", indent, "", values->alpha_to_coverage_invert ? "true" : "false");
2498   fprintf(fp, "%*sAlpha test compare function: %s\n", indent, "", mali_func_as_str(values->alpha_test_compare_function));
2499   fprintf(fp, "%*sForce seamless cubemaps: %s\n", indent, "", values->force_seamless_cubemaps ? "true" : "false");
2500   fprintf(fp, "%*sDepth Range 1: %s\n", indent, "", values->depth_range_1 ? "true" : "false");
2501   fprintf(fp, "%*sDepth Range 2: %s\n", indent, "", values->depth_range_2 ? "true" : "false");
2502   fprintf(fp, "%*sSingle-sampled lines: %s\n", indent, "", values->single_sampled_lines ? "true" : "false");
2503   fprintf(fp, "%*sPoint snap: %s\n", indent, "", values->point_snap ? "true" : "false");
2504}
2505
2506struct MALI_STENCIL {
2507   uint32_t                             reference_value;
2508   uint32_t                             mask;
2509   enum mali_func                       compare_function;
2510   enum mali_stencil_op                 stencil_fail;
2511   enum mali_stencil_op                 depth_fail;
2512   enum mali_stencil_op                 depth_pass;
2513};
2514
2515#define MALI_STENCIL_header                     \
2516   0
2517
2518static inline void
2519MALI_STENCIL_pack(uint32_t * restrict cl,
2520                  const struct MALI_STENCIL * restrict values)
2521{
2522   cl[ 0] = __gen_uint(values->reference_value, 0, 7) |
2523            __gen_uint(values->mask, 8, 15) |
2524            __gen_uint(values->compare_function, 16, 18) |
2525            __gen_uint(values->stencil_fail, 19, 21) |
2526            __gen_uint(values->depth_fail, 22, 24) |
2527            __gen_uint(values->depth_pass, 25, 27);
2528}
2529
2530
2531#define MALI_STENCIL_LENGTH 4
2532struct mali_stencil_packed { uint32_t opaque[1]; };
2533static inline void
2534MALI_STENCIL_unpack(const uint8_t * restrict cl,
2535                    struct MALI_STENCIL * restrict values)
2536{
2537   if (((const uint32_t *) cl)[0] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Stencil unpacked at word 0\n");
2538   values->reference_value = __gen_unpack_uint(cl, 0, 7);
2539   values->mask = __gen_unpack_uint(cl, 8, 15);
2540   values->compare_function = (enum mali_func)__gen_unpack_uint(cl, 16, 18);
2541   values->stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 19, 21);
2542   values->depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 22, 24);
2543   values->depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 25, 27);
2544}
2545
2546static inline void
2547MALI_STENCIL_print(FILE *fp, const struct MALI_STENCIL * values, unsigned indent)
2548{
2549   fprintf(fp, "%*sReference Value: %u\n", indent, "", values->reference_value);
2550   fprintf(fp, "%*sMask: %u\n", indent, "", values->mask);
2551   fprintf(fp, "%*sCompare Function: %s\n", indent, "", mali_func_as_str(values->compare_function));
2552   fprintf(fp, "%*sStencil Fail: %s\n", indent, "", mali_stencil_op_as_str(values->stencil_fail));
2553   fprintf(fp, "%*sDepth Fail: %s\n", indent, "", mali_stencil_op_as_str(values->depth_fail));
2554   fprintf(fp, "%*sDepth Pass: %s\n", indent, "", mali_stencil_op_as_str(values->depth_pass));
2555}
2556
2557struct MALI_RENDERER_STATE {
2558   struct MALI_SHADER                   shader;
2559   struct MALI_RENDERER_PROPERTIES      properties;
2560   float                                depth_units;
2561   float                                depth_factor;
2562   float                                depth_bias_clamp;
2563   struct MALI_MULTISAMPLE_MISC         multisample_misc;
2564   struct MALI_STENCIL_MASK_MISC        stencil_mask_misc;
2565   struct MALI_STENCIL                  stencil_front;
2566   struct MALI_STENCIL                  stencil_back;
2567   float                                alpha_reference;
2568   uint32_t                             thread_balancing;
2569   uint64_t                             legacy_blend_shader;
2570};
2571
2572#define MALI_RENDERER_STATE_header              \
2573   .shader = { MALI_SHADER_header },  \
2574   .properties = { MALI_RENDERER_PROPERTIES_header },  \
2575   .multisample_misc = { MALI_MULTISAMPLE_MISC_header },  \
2576   .stencil_mask_misc = { MALI_STENCIL_MASK_MISC_header },  \
2577   .stencil_front = { MALI_STENCIL_header },  \
2578   .stencil_back = { MALI_STENCIL_header }
2579
2580static inline void
2581MALI_RENDERER_STATE_pack(uint32_t * restrict cl,
2582                         const struct MALI_RENDERER_STATE * restrict values)
2583{
2584   cl[ 0] = __gen_uint(values->shader.shader, 0, 63);
2585   cl[ 1] = __gen_uint(values->shader.shader, 0, 63) >> 32;
2586   cl[ 2] = __gen_uint(values->shader.sampler_count, 0, 15) |
2587            __gen_uint(values->shader.texture_count, 16, 31);
2588   cl[ 3] = __gen_uint(values->shader.attribute_count, 0, 15) |
2589            __gen_uint(values->shader.varying_count, 16, 31);
2590   cl[ 4] = __gen_uint(values->properties.uniform_buffer_count, 0, 7) |
2591            __gen_uint(values->properties.depth_source, 8, 9) |
2592            __gen_uint(values->properties.shader_contains_barrier, 11, 11) |
2593            __gen_uint(values->properties.force_early_z, 10, 10) |
2594            __gen_uint(values->properties.shader_contains_discard, 12, 12) |
2595            __gen_uint(values->properties.shader_has_side_effects, 13, 13) |
2596            __gen_uint(values->properties.shader_reads_tilebuffer, 14, 14) |
2597            __gen_uint(values->properties.forward_pixel_kill, 15, 15) |
2598            __gen_uint(values->properties.work_register_count, 16, 20) |
2599            __gen_uint(values->properties.uniform_count, 21, 25) |
2600            __gen_uint(values->properties.stencil_from_shader, 28, 28) |
2601            __gen_uint(values->properties.fp_mode, 29, 31);
2602   cl[ 5] = __gen_uint(fui(values->depth_units), 0, 32);
2603   cl[ 6] = __gen_uint(fui(values->depth_factor), 0, 32);
2604   cl[ 7] = __gen_uint(fui(values->depth_bias_clamp), 0, 32);
2605   cl[ 8] = __gen_uint(values->multisample_misc.sample_mask, 0, 15) |
2606            __gen_uint(values->multisample_misc.multisample_enable, 16, 16) |
2607            __gen_uint(values->multisample_misc.multisample_late_coverage, 17, 17) |
2608            __gen_uint(values->multisample_misc.evaluate_per_sample, 18, 18) |
2609            __gen_uint(values->multisample_misc.fixed_function_depth_range_fixed, 19, 19) |
2610            __gen_uint(values->multisample_misc.shader_depth_range_fixed, 20, 20) |
2611            __gen_uint(values->multisample_misc.depth_function, 24, 26) |
2612            __gen_uint(values->multisample_misc.depth_write_mask, 27, 27) |
2613            __gen_uint(values->multisample_misc.fixed_function_near_discard, 28, 28) |
2614            __gen_uint(values->multisample_misc.fixed_function_far_discard, 29, 29) |
2615            __gen_uint(values->multisample_misc.fragment_near_discard, 30, 30) |
2616            __gen_uint(values->multisample_misc.fragment_far_discard, 31, 31);
2617   cl[ 9] = __gen_uint(values->stencil_mask_misc.stencil_mask_front, 0, 7) |
2618            __gen_uint(values->stencil_mask_misc.stencil_mask_back, 8, 15) |
2619            __gen_uint(values->stencil_mask_misc.stencil_enable, 16, 16) |
2620            __gen_uint(values->stencil_mask_misc.alpha_to_coverage, 17, 17) |
2621            __gen_uint(values->stencil_mask_misc.alpha_to_coverage_invert, 18, 18) |
2622            __gen_uint(values->stencil_mask_misc.alpha_test_compare_function, 21, 23) |
2623            __gen_uint(values->stencil_mask_misc.force_seamless_cubemaps, 26, 26) |
2624            __gen_uint(values->stencil_mask_misc.depth_range_1, 28, 28) |
2625            __gen_uint(values->stencil_mask_misc.depth_range_2, 29, 29) |
2626            __gen_uint(values->stencil_mask_misc.single_sampled_lines, 30, 30) |
2627            __gen_uint(values->stencil_mask_misc.point_snap, 31, 31);
2628   cl[10] = __gen_uint(values->stencil_front.reference_value, 0, 7) |
2629            __gen_uint(values->stencil_front.mask, 8, 15) |
2630            __gen_uint(values->stencil_front.compare_function, 16, 18) |
2631            __gen_uint(values->stencil_front.stencil_fail, 19, 21) |
2632            __gen_uint(values->stencil_front.depth_fail, 22, 24) |
2633            __gen_uint(values->stencil_front.depth_pass, 25, 27);
2634   cl[11] = __gen_uint(values->stencil_back.reference_value, 0, 7) |
2635            __gen_uint(values->stencil_back.mask, 8, 15) |
2636            __gen_uint(values->stencil_back.compare_function, 16, 18) |
2637            __gen_uint(values->stencil_back.stencil_fail, 19, 21) |
2638            __gen_uint(values->stencil_back.depth_fail, 22, 24) |
2639            __gen_uint(values->stencil_back.depth_pass, 25, 27);
2640   cl[12] = __gen_uint(fui(values->alpha_reference), 0, 32);
2641   cl[13] = __gen_uint(values->thread_balancing, 0, 15);
2642   cl[14] = __gen_uint(values->legacy_blend_shader, 0, 63);
2643   cl[15] = __gen_uint(values->legacy_blend_shader, 0, 63) >> 32;
2644}
2645
2646
2647#define MALI_RENDERER_STATE_LENGTH 64
2648#define MALI_RENDERER_STATE_ALIGN 64
2649struct mali_renderer_state_packed { uint32_t opaque[16]; };
2650static inline void
2651MALI_RENDERER_STATE_unpack(const uint8_t * restrict cl,
2652                           struct MALI_RENDERER_STATE * restrict values)
2653{
2654   if (((const uint32_t *) cl)[4] & 0xc000000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 4\n");
2655   if (((const uint32_t *) cl)[8] & 0xe00000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 8\n");
2656   if (((const uint32_t *) cl)[9] & 0xb180000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 9\n");
2657   if (((const uint32_t *) cl)[10] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 10\n");
2658   if (((const uint32_t *) cl)[11] & 0xf0000000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 11\n");
2659   if (((const uint32_t *) cl)[13] & 0xffff0000) fprintf(stderr, "XXX: Invalid field of Renderer State unpacked at word 13\n");
2660   values->shader.shader = __gen_unpack_uint(cl, 0, 63);
2661   values->shader.sampler_count = __gen_unpack_uint(cl, 64, 79);
2662   values->shader.texture_count = __gen_unpack_uint(cl, 80, 95);
2663   values->shader.attribute_count = __gen_unpack_uint(cl, 96, 111);
2664   values->shader.varying_count = __gen_unpack_uint(cl, 112, 127);
2665   values->properties.uniform_buffer_count = __gen_unpack_uint(cl, 128, 135);
2666   values->properties.depth_source = (enum mali_depth_source)__gen_unpack_uint(cl, 136, 137);
2667   values->properties.shader_contains_barrier = __gen_unpack_uint(cl, 139, 139);
2668   values->properties.force_early_z = __gen_unpack_uint(cl, 138, 138);
2669   values->properties.shader_contains_discard = __gen_unpack_uint(cl, 140, 140);
2670   values->properties.shader_has_side_effects = __gen_unpack_uint(cl, 141, 141);
2671   values->properties.shader_reads_tilebuffer = __gen_unpack_uint(cl, 142, 142);
2672   values->properties.forward_pixel_kill = __gen_unpack_uint(cl, 143, 143);
2673   values->properties.work_register_count = __gen_unpack_uint(cl, 144, 148);
2674   values->properties.uniform_count = __gen_unpack_uint(cl, 149, 153);
2675   values->properties.stencil_from_shader = __gen_unpack_uint(cl, 156, 156);
2676   values->properties.fp_mode = (enum mali_fp_mode)__gen_unpack_uint(cl, 157, 159);
2677   values->depth_units = __gen_unpack_float(cl, 160, 191);
2678   values->depth_factor = __gen_unpack_float(cl, 192, 223);
2679   values->depth_bias_clamp = __gen_unpack_float(cl, 224, 255);
2680   values->multisample_misc.sample_mask = __gen_unpack_uint(cl, 256, 271);
2681   values->multisample_misc.multisample_enable = __gen_unpack_uint(cl, 272, 272);
2682   values->multisample_misc.multisample_late_coverage = __gen_unpack_uint(cl, 273, 273);
2683   values->multisample_misc.evaluate_per_sample = __gen_unpack_uint(cl, 274, 274);
2684   values->multisample_misc.fixed_function_depth_range_fixed = __gen_unpack_uint(cl, 275, 275);
2685   values->multisample_misc.shader_depth_range_fixed = __gen_unpack_uint(cl, 276, 276);
2686   values->multisample_misc.depth_function = (enum mali_func)__gen_unpack_uint(cl, 280, 282);
2687   values->multisample_misc.depth_write_mask = __gen_unpack_uint(cl, 283, 283);
2688   values->multisample_misc.fixed_function_near_discard = __gen_unpack_uint(cl, 284, 284);
2689   values->multisample_misc.fixed_function_far_discard = __gen_unpack_uint(cl, 285, 285);
2690   values->multisample_misc.fragment_near_discard = __gen_unpack_uint(cl, 286, 286);
2691   values->multisample_misc.fragment_far_discard = __gen_unpack_uint(cl, 287, 287);
2692   values->stencil_mask_misc.stencil_mask_front = __gen_unpack_uint(cl, 288, 295);
2693   values->stencil_mask_misc.stencil_mask_back = __gen_unpack_uint(cl, 296, 303);
2694   values->stencil_mask_misc.stencil_enable = __gen_unpack_uint(cl, 304, 304);
2695   values->stencil_mask_misc.alpha_to_coverage = __gen_unpack_uint(cl, 305, 305);
2696   values->stencil_mask_misc.alpha_to_coverage_invert = __gen_unpack_uint(cl, 306, 306);
2697   values->stencil_mask_misc.alpha_test_compare_function = (enum mali_func)__gen_unpack_uint(cl, 309, 311);
2698   values->stencil_mask_misc.force_seamless_cubemaps = __gen_unpack_uint(cl, 314, 314);
2699   values->stencil_mask_misc.depth_range_1 = __gen_unpack_uint(cl, 316, 316);
2700   values->stencil_mask_misc.depth_range_2 = __gen_unpack_uint(cl, 317, 317);
2701   values->stencil_mask_misc.single_sampled_lines = __gen_unpack_uint(cl, 318, 318);
2702   values->stencil_mask_misc.point_snap = __gen_unpack_uint(cl, 319, 319);
2703   values->stencil_front.reference_value = __gen_unpack_uint(cl, 320, 327);
2704   values->stencil_front.mask = __gen_unpack_uint(cl, 328, 335);
2705   values->stencil_front.compare_function = (enum mali_func)__gen_unpack_uint(cl, 336, 338);
2706   values->stencil_front.stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 339, 341);
2707   values->stencil_front.depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 342, 344);
2708   values->stencil_front.depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 345, 347);
2709   values->stencil_back.reference_value = __gen_unpack_uint(cl, 352, 359);
2710   values->stencil_back.mask = __gen_unpack_uint(cl, 360, 367);
2711   values->stencil_back.compare_function = (enum mali_func)__gen_unpack_uint(cl, 368, 370);
2712   values->stencil_back.stencil_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 371, 373);
2713   values->stencil_back.depth_fail = (enum mali_stencil_op)__gen_unpack_uint(cl, 374, 376);
2714   values->stencil_back.depth_pass = (enum mali_stencil_op)__gen_unpack_uint(cl, 377, 379);
2715   values->alpha_reference = __gen_unpack_float(cl, 384, 415);
2716   values->thread_balancing = __gen_unpack_uint(cl, 416, 431);
2717   values->legacy_blend_shader = __gen_unpack_uint(cl, 448, 511);
2718}
2719
2720static inline void
2721MALI_RENDERER_STATE_print(FILE *fp, const struct MALI_RENDERER_STATE * values, unsigned indent)
2722{
2723   fprintf(fp, "%*sShader:\n", indent, "");
2724   MALI_SHADER_print(fp, &values->shader, indent + 2);
2725   fprintf(fp, "%*sProperties:\n", indent, "");
2726   MALI_RENDERER_PROPERTIES_print(fp, &values->properties, indent + 2);
2727   fprintf(fp, "%*sDepth units: %f\n", indent, "", values->depth_units);
2728   fprintf(fp, "%*sDepth factor: %f\n", indent, "", values->depth_factor);
2729   fprintf(fp, "%*sDepth bias clamp: %f\n", indent, "", values->depth_bias_clamp);
2730   fprintf(fp, "%*sMultisample, Misc:\n", indent, "");
2731   MALI_MULTISAMPLE_MISC_print(fp, &values->multisample_misc, indent + 2);
2732   fprintf(fp, "%*sStencil Mask, Misc:\n", indent, "");
2733   MALI_STENCIL_MASK_MISC_print(fp, &values->stencil_mask_misc, indent + 2);
2734   fprintf(fp, "%*sStencil front:\n", indent, "");
2735   MALI_STENCIL_print(fp, &values->stencil_front, indent + 2);
2736   fprintf(fp, "%*sStencil back:\n", indent, "");
2737   MALI_STENCIL_print(fp, &values->stencil_back, indent + 2);
2738   fprintf(fp, "%*sAlpha reference: %f\n", indent, "", values->alpha_reference);
2739   fprintf(fp, "%*sThread Balancing: %u\n", indent, "", values->thread_balancing);
2740   fprintf(fp, "%*sLegacy Blend Shader: 0x%" PRIx64 "\n", indent, "", values->legacy_blend_shader);
2741}
2742
2743struct MALI_UNIFORM_BUFFER {
2744   uint32_t                             entries;
2745   uint64_t                             pointer;
2746};
2747
2748#define MALI_UNIFORM_BUFFER_header              \
2749   0
2750
2751static inline void
2752MALI_UNIFORM_BUFFER_pack(uint32_t * restrict cl,
2753                         const struct MALI_UNIFORM_BUFFER * restrict values)
2754{
2755   assert(values->entries >= 1);
2756   assert((values->pointer & 0xf) == 0);
2757   cl[ 0] = __gen_uint(values->entries - 1, 0, 11) |
2758            __gen_uint(values->pointer >> 4, 12, 63);
2759   cl[ 1] = __gen_uint(values->pointer >> 4, 12, 63) >> 32;
2760}
2761
2762
2763#define MALI_UNIFORM_BUFFER_LENGTH 8
2764#define MALI_UNIFORM_BUFFER_ALIGN 8
2765struct mali_uniform_buffer_packed { uint32_t opaque[2]; };
2766static inline void
2767MALI_UNIFORM_BUFFER_unpack(const uint8_t * restrict cl,
2768                           struct MALI_UNIFORM_BUFFER * restrict values)
2769{
2770   values->entries = __gen_unpack_uint(cl, 0, 11) + 1;
2771   values->pointer = __gen_unpack_uint(cl, 12, 63) << 4;
2772}
2773
2774static inline void
2775MALI_UNIFORM_BUFFER_print(FILE *fp, const struct MALI_UNIFORM_BUFFER * values, unsigned indent)
2776{
2777   fprintf(fp, "%*sEntries: %u\n", indent, "", values->entries);
2778   fprintf(fp, "%*sPointer: 0x%" PRIx64 "\n", indent, "", values->pointer);
2779}
2780
2781struct MALI_VIEWPORT {
2782   float                                minimum_x;
2783   float                                minimum_y;
2784   float                                maximum_x;
2785   float                                maximum_y;
2786   float                                minimum_z;
2787   float                                maximum_z;
2788   uint32_t                             scissor_minimum_x;
2789   uint32_t                             scissor_minimum_y;
2790   uint32_t                             scissor_maximum_x;
2791   uint32_t                             scissor_maximum_y;
2792};
2793
2794#define MALI_VIEWPORT_header                    \
2795   .minimum_x = -INFINITY,  \
2796   .minimum_y = -INFINITY,  \
2797   .maximum_x = +INFINITY,  \
2798   .maximum_y = +INFINITY,  \
2799   .minimum_z = 0.0,  \
2800   .maximum_z = 1.0,  \
2801   .scissor_minimum_x = 0,  \
2802   .scissor_minimum_y = 0
2803
2804static inline void
2805MALI_VIEWPORT_pack(uint32_t * restrict cl,
2806                   const struct MALI_VIEWPORT * restrict values)
2807{
2808   cl[ 0] = __gen_uint(fui(values->minimum_x), 0, 32);
2809   cl[ 1] = __gen_uint(fui(values->minimum_y), 0, 32);
2810   cl[ 2] = __gen_uint(fui(values->maximum_x), 0, 32);
2811   cl[ 3] = __gen_uint(fui(values->maximum_y), 0, 32);
2812   cl[ 4] = __gen_uint(fui(values->minimum_z), 0, 32);
2813   cl[ 5] = __gen_uint(fui(values->maximum_z), 0, 32);
2814   cl[ 6] = __gen_uint(values->scissor_minimum_x, 0, 15) |
2815            __gen_uint(values->scissor_minimum_y, 16, 31);
2816   cl[ 7] = __gen_uint(values->scissor_maximum_x, 0, 15) |
2817            __gen_uint(values->scissor_maximum_y, 16, 31);
2818}
2819
2820
2821#define MALI_VIEWPORT_LENGTH 32
2822#define MALI_VIEWPORT_ALIGN 32
2823struct mali_viewport_packed { uint32_t opaque[8]; };
2824static inline void
2825MALI_VIEWPORT_unpack(const uint8_t * restrict cl,
2826                     struct MALI_VIEWPORT * restrict values)
2827{
2828   values->minimum_x = __gen_unpack_float(cl, 0, 31);
2829   values->minimum_y = __gen_unpack_float(cl, 32, 63);
2830   values->maximum_x = __gen_unpack_float(cl, 64, 95);
2831   values->maximum_y = __gen_unpack_float(cl, 96, 127);
2832   values->minimum_z = __gen_unpack_float(cl, 128, 159);
2833   values->maximum_z = __gen_unpack_float(cl, 160, 191);
2834   values->scissor_minimum_x = __gen_unpack_uint(cl, 192, 207);
2835   values->scissor_minimum_y = __gen_unpack_uint(cl, 208, 223);
2836   values->scissor_maximum_x = __gen_unpack_uint(cl, 224, 239);
2837   values->scissor_maximum_y = __gen_unpack_uint(cl, 240, 255);
2838}
2839
2840static inline void
2841MALI_VIEWPORT_print(FILE *fp, const struct MALI_VIEWPORT * values, unsigned indent)
2842{
2843   fprintf(fp, "%*sMinimum X: %f\n", indent, "", values->minimum_x);
2844   fprintf(fp, "%*sMinimum Y: %f\n", indent, "", values->minimum_y);
2845   fprintf(fp, "%*sMaximum X: %f\n", indent, "", values->maximum_x);
2846   fprintf(fp, "%*sMaximum Y: %f\n", indent, "", values->maximum_y);
2847   fprintf(fp, "%*sMinimum Z: %f\n", indent, "", values->minimum_z);
2848   fprintf(fp, "%*sMaximum Z: %f\n", indent, "", values->maximum_z);
2849   fprintf(fp, "%*sScissor Minimum X: %u\n", indent, "", values->scissor_minimum_x);
2850   fprintf(fp, "%*sScissor Minimum Y: %u\n", indent, "", values->scissor_minimum_y);
2851   fprintf(fp, "%*sScissor Maximum X: %u\n", indent, "", values->scissor_maximum_x);
2852   fprintf(fp, "%*sScissor Maximum Y: %u\n", indent, "", values->scissor_maximum_y);
2853}
2854
2855struct MALI_LOCAL_STORAGE {
2856   uint32_t                             tls_size;
2857   uint32_t                             tls_initial_stack_pointer_offset;
2858   uint32_t                             wls_instances;
2859#define MALI_LOCAL_STORAGE_NO_WORKGROUP_MEM      2147483648
2860   uint32_t                             wls_size_base;
2861   uint32_t                             wls_size_scale;
2862   uint64_t                             tls_base_pointer;
2863   uint64_t                             wls_base_pointer;
2864};
2865
2866#define MALI_LOCAL_STORAGE_header               \
2867   .wls_instances = MALI_LOCAL_STORAGE_NO_WORKGROUP_MEM
2868
2869static inline void
2870MALI_LOCAL_STORAGE_pack(uint32_t * restrict cl,
2871                        const struct MALI_LOCAL_STORAGE * restrict values)
2872{
2873   assert(util_is_power_of_two_nonzero(values->wls_instances));
2874   cl[ 0] = __gen_uint(values->tls_size, 0, 4) |
2875            __gen_uint(values->tls_initial_stack_pointer_offset, 5, 31);
2876   cl[ 1] = __gen_uint(util_logbase2(values->wls_instances), 0, 4) |
2877            __gen_uint(values->wls_size_base, 5, 6) |
2878            __gen_uint(values->wls_size_scale, 8, 12);
2879   cl[ 2] = __gen_uint(values->tls_base_pointer, 0, 63);
2880   cl[ 3] = __gen_uint(values->tls_base_pointer, 0, 63) >> 32;
2881   cl[ 4] = __gen_uint(values->wls_base_pointer, 0, 63);
2882   cl[ 5] = __gen_uint(values->wls_base_pointer, 0, 63) >> 32;
2883   cl[ 6] = 0;
2884   cl[ 7] = 0;
2885}
2886
2887
2888#define MALI_LOCAL_STORAGE_LENGTH 32
2889#define MALI_LOCAL_STORAGE_ALIGN 64
2890struct mali_local_storage_packed { uint32_t opaque[8]; };
2891static inline void
2892MALI_LOCAL_STORAGE_unpack(const uint8_t * restrict cl,
2893                          struct MALI_LOCAL_STORAGE * restrict values)
2894{
2895   if (((const uint32_t *) cl)[1] & 0xffffe080) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 1\n");
2896   if (((const uint32_t *) cl)[6] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 6\n");
2897   if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Local Storage unpacked at word 7\n");
2898   values->tls_size = __gen_unpack_uint(cl, 0, 4);
2899   values->tls_initial_stack_pointer_offset = __gen_unpack_uint(cl, 5, 31);
2900   values->wls_instances = 1U << __gen_unpack_uint(cl, 32, 36);
2901   values->wls_size_base = __gen_unpack_uint(cl, 37, 38);
2902   values->wls_size_scale = __gen_unpack_uint(cl, 40, 44);
2903   values->tls_base_pointer = __gen_unpack_uint(cl, 64, 127);
2904   values->wls_base_pointer = __gen_unpack_uint(cl, 128, 191);
2905}
2906
2907static inline void
2908MALI_LOCAL_STORAGE_print(FILE *fp, const struct MALI_LOCAL_STORAGE * values, unsigned indent)
2909{
2910   fprintf(fp, "%*sTLS Size: %u\n", indent, "", values->tls_size);
2911   fprintf(fp, "%*sTLS Initial Stack Pointer Offset: %u\n", indent, "", values->tls_initial_stack_pointer_offset);
2912   fprintf(fp, "%*sWLS Instances: %u\n", indent, "", values->wls_instances);
2913   fprintf(fp, "%*sWLS Size Base: %u\n", indent, "", values->wls_size_base);
2914   fprintf(fp, "%*sWLS Size Scale: %u\n", indent, "", values->wls_size_scale);
2915   fprintf(fp, "%*sTLS Base Pointer: 0x%" PRIx64 "\n", indent, "", values->tls_base_pointer);
2916   fprintf(fp, "%*sWLS Base Pointer: 0x%" PRIx64 "\n", indent, "", values->wls_base_pointer);
2917}
2918
2919struct MALI_TILER_CONTEXT {
2920   uint32_t                             polygon_list_size;
2921#define MALI_MIDGARD_TILER_MINIMUM_HEADER_SIZE   512
2922   uint32_t                             hierarchy_mask;
2923#define MALI_MIDGARD_TILER_DISABLED              4096
2924#define MALI_MIDGARD_TILER_USER                  4095
2925#define MALI_MIDGARD_TILER_HIERARCHY_MASK        511
2926   uint64_t                             polygon_list;
2927   uint64_t                             polygon_list_body;
2928   uint64_t                             heap_start;
2929   uint64_t                             heap_end;
2930};
2931
2932#define MALI_TILER_CONTEXT_header               \
2933   0
2934
2935static inline void
2936MALI_TILER_CONTEXT_pack(uint32_t * restrict cl,
2937                        const struct MALI_TILER_CONTEXT * restrict values)
2938{
2939   cl[ 0] = __gen_uint(values->polygon_list_size, 0, 31);
2940   cl[ 1] = __gen_uint(values->hierarchy_mask, 0, 15);
2941   cl[ 2] = __gen_uint(values->polygon_list, 0, 63);
2942   cl[ 3] = __gen_uint(values->polygon_list, 0, 63) >> 32;
2943   cl[ 4] = __gen_uint(values->polygon_list_body, 0, 63);
2944   cl[ 5] = __gen_uint(values->polygon_list_body, 0, 63) >> 32;
2945   cl[ 6] = __gen_uint(values->heap_start, 0, 63);
2946   cl[ 7] = __gen_uint(values->heap_start, 0, 63) >> 32;
2947   cl[ 8] = __gen_uint(values->heap_end, 0, 63);
2948   cl[ 9] = __gen_uint(values->heap_end, 0, 63) >> 32;
2949}
2950
2951
2952#define MALI_TILER_CONTEXT_LENGTH 40
2953struct mali_tiler_context_packed { uint32_t opaque[10]; };
2954static inline void
2955MALI_TILER_CONTEXT_unpack(const uint8_t * restrict cl,
2956                          struct MALI_TILER_CONTEXT * restrict values)
2957{
2958   if (((const uint32_t *) cl)[1] & 0xffff0000) fprintf(stderr, "XXX: Invalid field of Tiler Context unpacked at word 1\n");
2959   values->polygon_list_size = __gen_unpack_uint(cl, 0, 31);
2960   values->hierarchy_mask = __gen_unpack_uint(cl, 32, 47);
2961   values->polygon_list = __gen_unpack_uint(cl, 64, 127);
2962   values->polygon_list_body = __gen_unpack_uint(cl, 128, 191);
2963   values->heap_start = __gen_unpack_uint(cl, 192, 255);
2964   values->heap_end = __gen_unpack_uint(cl, 256, 319);
2965}
2966
2967static inline void
2968MALI_TILER_CONTEXT_print(FILE *fp, const struct MALI_TILER_CONTEXT * values, unsigned indent)
2969{
2970   fprintf(fp, "%*sPolygon List Size: %u\n", indent, "", values->polygon_list_size);
2971   fprintf(fp, "%*sHierarchy Mask: %u\n", indent, "", values->hierarchy_mask);
2972   fprintf(fp, "%*sPolygon List: 0x%" PRIx64 "\n", indent, "", values->polygon_list);
2973   fprintf(fp, "%*sPolygon List Body: 0x%" PRIx64 "\n", indent, "", values->polygon_list_body);
2974   fprintf(fp, "%*sHeap Start: 0x%" PRIx64 "\n", indent, "", values->heap_start);
2975   fprintf(fp, "%*sHeap End: 0x%" PRIx64 "\n", indent, "", values->heap_end);
2976}
2977
2978struct MALI_TILER_WEIGHTS {
2979   uint32_t                             weight0;
2980   uint32_t                             weight1;
2981   uint32_t                             weight2;
2982   uint32_t                             weight3;
2983   uint32_t                             weight4;
2984   uint32_t                             weight5;
2985   uint32_t                             weight6;
2986   uint32_t                             weight7;
2987};
2988
2989#define MALI_TILER_WEIGHTS_header               \
2990   0
2991
2992static inline void
2993MALI_TILER_WEIGHTS_pack(uint32_t * restrict cl,
2994                        const struct MALI_TILER_WEIGHTS * restrict values)
2995{
2996   cl[ 0] = __gen_uint(values->weight0, 0, 31);
2997   cl[ 1] = __gen_uint(values->weight1, 0, 31);
2998   cl[ 2] = __gen_uint(values->weight2, 0, 31);
2999   cl[ 3] = __gen_uint(values->weight3, 0, 31);
3000   cl[ 4] = __gen_uint(values->weight4, 0, 31);
3001   cl[ 5] = __gen_uint(values->weight5, 0, 31);
3002   cl[ 6] = __gen_uint(values->weight6, 0, 31);
3003   cl[ 7] = __gen_uint(values->weight7, 0, 31);
3004}
3005
3006
3007#define MALI_TILER_WEIGHTS_LENGTH 32
3008struct mali_tiler_weights_packed { uint32_t opaque[8]; };
3009static inline void
3010MALI_TILER_WEIGHTS_unpack(const uint8_t * restrict cl,
3011                          struct MALI_TILER_WEIGHTS * restrict values)
3012{
3013   values->weight0 = __gen_unpack_uint(cl, 0, 31);
3014   values->weight1 = __gen_unpack_uint(cl, 32, 63);
3015   values->weight2 = __gen_unpack_uint(cl, 64, 95);
3016   values->weight3 = __gen_unpack_uint(cl, 96, 127);
3017   values->weight4 = __gen_unpack_uint(cl, 128, 159);
3018   values->weight5 = __gen_unpack_uint(cl, 160, 191);
3019   values->weight6 = __gen_unpack_uint(cl, 192, 223);
3020   values->weight7 = __gen_unpack_uint(cl, 224, 255);
3021}
3022
3023static inline void
3024MALI_TILER_WEIGHTS_print(FILE *fp, const struct MALI_TILER_WEIGHTS * values, unsigned indent)
3025{
3026   fprintf(fp, "%*sWeight0: %u\n", indent, "", values->weight0);
3027   fprintf(fp, "%*sWeight1: %u\n", indent, "", values->weight1);
3028   fprintf(fp, "%*sWeight2: %u\n", indent, "", values->weight2);
3029   fprintf(fp, "%*sWeight3: %u\n", indent, "", values->weight3);
3030   fprintf(fp, "%*sWeight4: %u\n", indent, "", values->weight4);
3031   fprintf(fp, "%*sWeight5: %u\n", indent, "", values->weight5);
3032   fprintf(fp, "%*sWeight6: %u\n", indent, "", values->weight6);
3033   fprintf(fp, "%*sWeight7: %u\n", indent, "", values->weight7);
3034}
3035
3036enum mali_color_buffer_internal_format {
3037        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE =      0,
3038        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8 =      1,
3039        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2 =      2,
3040        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2 =      3,
3041        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4 =      4,
3042        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0 =      5,
3043        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1 =      6,
3044        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8 =     32,
3045        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16 =     33,
3046        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32 =     34,
3047        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64 =     35,
3048        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128 =     36,
3049};
3050
3051static inline const char *
3052mali_color_buffer_internal_format_as_str(enum mali_color_buffer_internal_format imm)
3053{
3054    switch (imm) {
3055    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE: return "Raw Value";
3056    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8: return "R8G8B8A8";
3057    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2: return "R10G10B10A2";
3058    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2: return "R8G8B8A2";
3059    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4: return "R4G4B4A4";
3060    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0: return "R5G6B5A0";
3061    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1: return "R5G5B5A1";
3062    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8: return "RAW8";
3063    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16: return "RAW16";
3064    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32: return "RAW32";
3065    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64: return "RAW64";
3066    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128: return "RAW128";
3067    default: return "XXX: INVALID";
3068    }
3069}
3070
3071enum mali_color_format {
3072        MALI_COLOR_FORMAT_RAW8               =      0,
3073        MALI_COLOR_FORMAT_RAW16              =      1,
3074        MALI_COLOR_FORMAT_RAW24              =      2,
3075        MALI_COLOR_FORMAT_RAW32              =      3,
3076        MALI_COLOR_FORMAT_RAW48              =      4,
3077        MALI_COLOR_FORMAT_RAW64              =      5,
3078        MALI_COLOR_FORMAT_RAW96              =      6,
3079        MALI_COLOR_FORMAT_RAW128             =      7,
3080        MALI_COLOR_FORMAT_RAW192             =      8,
3081        MALI_COLOR_FORMAT_RAW256             =      9,
3082        MALI_COLOR_FORMAT_RAW384             =     10,
3083        MALI_COLOR_FORMAT_RAW512             =     11,
3084        MALI_COLOR_FORMAT_RAW768             =     12,
3085        MALI_COLOR_FORMAT_RAW1024            =     13,
3086        MALI_COLOR_FORMAT_RAW1536            =     14,
3087        MALI_COLOR_FORMAT_RAW2048            =     15,
3088        MALI_COLOR_FORMAT_R8                 =     16,
3089        MALI_COLOR_FORMAT_R8G8               =     17,
3090        MALI_COLOR_FORMAT_R8G8B8             =     18,
3091        MALI_COLOR_FORMAT_R8G8B8A8           =     19,
3092        MALI_COLOR_FORMAT_R4G4B4A4           =     20,
3093        MALI_COLOR_FORMAT_R5G6B5             =     21,
3094        MALI_COLOR_FORMAT_R8G8B8_FROM_R8G8B8A2 =     22,
3095        MALI_COLOR_FORMAT_R10G10B10A2        =     24,
3096        MALI_COLOR_FORMAT_A2B10G10R10        =     25,
3097        MALI_COLOR_FORMAT_R5G5B5A1           =     28,
3098        MALI_COLOR_FORMAT_A1B5G5R5           =     29,
3099        MALI_COLOR_FORMAT_NATIVE             =     31,
3100};
3101
3102static inline const char *
3103mali_color_format_as_str(enum mali_color_format imm)
3104{
3105    switch (imm) {
3106    case MALI_COLOR_FORMAT_RAW8: return "RAW8";
3107    case MALI_COLOR_FORMAT_RAW16: return "RAW16";
3108    case MALI_COLOR_FORMAT_RAW24: return "RAW24";
3109    case MALI_COLOR_FORMAT_RAW32: return "RAW32";
3110    case MALI_COLOR_FORMAT_RAW48: return "RAW48";
3111    case MALI_COLOR_FORMAT_RAW64: return "RAW64";
3112    case MALI_COLOR_FORMAT_RAW96: return "RAW96";
3113    case MALI_COLOR_FORMAT_RAW128: return "RAW128";
3114    case MALI_COLOR_FORMAT_RAW192: return "RAW192";
3115    case MALI_COLOR_FORMAT_RAW256: return "RAW256";
3116    case MALI_COLOR_FORMAT_RAW384: return "RAW384";
3117    case MALI_COLOR_FORMAT_RAW512: return "RAW512";
3118    case MALI_COLOR_FORMAT_RAW768: return "RAW768";
3119    case MALI_COLOR_FORMAT_RAW1024: return "RAW1024";
3120    case MALI_COLOR_FORMAT_RAW1536: return "RAW1536";
3121    case MALI_COLOR_FORMAT_RAW2048: return "RAW2048";
3122    case MALI_COLOR_FORMAT_R8: return "R8";
3123    case MALI_COLOR_FORMAT_R8G8: return "R8G8";
3124    case MALI_COLOR_FORMAT_R8G8B8: return "R8G8B8";
3125    case MALI_COLOR_FORMAT_R8G8B8A8: return "R8G8B8A8";
3126    case MALI_COLOR_FORMAT_R4G4B4A4: return "R4G4B4A4";
3127    case MALI_COLOR_FORMAT_R5G6B5: return "R5G6B5";
3128    case MALI_COLOR_FORMAT_R8G8B8_FROM_R8G8B8A2: return "R8G8B8_FROM_R8G8B8A2";
3129    case MALI_COLOR_FORMAT_R10G10B10A2: return "R10G10B10A2";
3130    case MALI_COLOR_FORMAT_A2B10G10R10: return "A2B10G10R10";
3131    case MALI_COLOR_FORMAT_R5G5B5A1: return "R5G5B5A1";
3132    case MALI_COLOR_FORMAT_A1B5G5R5: return "A1B5G5R5";
3133    case MALI_COLOR_FORMAT_NATIVE: return "NATIVE";
3134    default: return "XXX: INVALID";
3135    }
3136}
3137
3138enum mali_downsampling_accumulation_mode {
3139        MALI_DOWNSAMPLING_ACCUMULATION_MODE_UNSIGNED_NORMALIZED_INTEGER =      0,
3140        MALI_DOWNSAMPLING_ACCUMULATION_MODE_SIGNED_NORMALIZED_INTEGER =      1,
3141};
3142
3143static inline const char *
3144mali_downsampling_accumulation_mode_as_str(enum mali_downsampling_accumulation_mode imm)
3145{
3146    switch (imm) {
3147    case MALI_DOWNSAMPLING_ACCUMULATION_MODE_UNSIGNED_NORMALIZED_INTEGER: return "Unsigned normalized integer";
3148    case MALI_DOWNSAMPLING_ACCUMULATION_MODE_SIGNED_NORMALIZED_INTEGER: return "Signed normalized integer";
3149    default: return "XXX: INVALID";
3150    }
3151}
3152
3153enum mali_sample_layout {
3154        MALI_SAMPLE_LAYOUT_ORDERED_4X_GRID   =      0,
3155        MALI_SAMPLE_LAYOUT_ROTATED_4X_GRID   =      1,
3156        MALI_SAMPLE_LAYOUT_D3D_8X_GRID       =      2,
3157        MALI_SAMPLE_LAYOUT_D3D_16X_GRID      =      3,
3158};
3159
3160static inline const char *
3161mali_sample_layout_as_str(enum mali_sample_layout imm)
3162{
3163    switch (imm) {
3164    case MALI_SAMPLE_LAYOUT_ORDERED_4X_GRID: return "Ordered 4x Grid";
3165    case MALI_SAMPLE_LAYOUT_ROTATED_4X_GRID: return "Rotated 4x Grid";
3166    case MALI_SAMPLE_LAYOUT_D3D_8X_GRID: return "D3D 8x Grid";
3167    case MALI_SAMPLE_LAYOUT_D3D_16X_GRID: return "D3D 16x Grid";
3168    default: return "XXX: INVALID";
3169    }
3170}
3171
3172enum mali_zs_format {
3173        MALI_ZS_FORMAT_D16                   =      1,
3174        MALI_ZS_FORMAT_D24                   =      2,
3175        MALI_ZS_FORMAT_D24X8                 =      4,
3176        MALI_ZS_FORMAT_D24S8                 =      5,
3177        MALI_ZS_FORMAT_X8D24                 =      6,
3178        MALI_ZS_FORMAT_S8D24                 =      7,
3179        MALI_ZS_FORMAT_D32                   =     14,
3180        MALI_ZS_FORMAT_D32_S8X24             =     15,
3181};
3182
3183static inline const char *
3184mali_zs_format_as_str(enum mali_zs_format imm)
3185{
3186    switch (imm) {
3187    case MALI_ZS_FORMAT_D16: return "D16";
3188    case MALI_ZS_FORMAT_D24: return "D24";
3189    case MALI_ZS_FORMAT_D24X8: return "D24X8";
3190    case MALI_ZS_FORMAT_D24S8: return "D24S8";
3191    case MALI_ZS_FORMAT_X8D24: return "X8D24";
3192    case MALI_ZS_FORMAT_S8D24: return "S8D24";
3193    case MALI_ZS_FORMAT_D32: return "D32";
3194    case MALI_ZS_FORMAT_D32_S8X24: return "D32_S8X24";
3195    default: return "XXX: INVALID";
3196    }
3197}
3198
3199enum mali_zs_preload_format {
3200        MALI_ZS_PRELOAD_FORMAT_D32_S8X24     =      4,
3201};
3202
3203static inline const char *
3204mali_zs_preload_format_as_str(enum mali_zs_preload_format imm)
3205{
3206    switch (imm) {
3207    case MALI_ZS_PRELOAD_FORMAT_D32_S8X24: return "D32_S8X24";
3208    default: return "XXX: INVALID";
3209    }
3210}
3211
3212enum mali_s_format {
3213        MALI_S_FORMAT_S8                     =      1,
3214        MALI_S_FORMAT_S8X8                   =      2,
3215        MALI_S_FORMAT_S8X24                  =      3,
3216        MALI_S_FORMAT_X24S8                  =      4,
3217        MALI_S_FORMAT_X8S8                   =      5,
3218        MALI_S_FORMAT_X32_S8X24              =      6,
3219};
3220
3221static inline const char *
3222mali_s_format_as_str(enum mali_s_format imm)
3223{
3224    switch (imm) {
3225    case MALI_S_FORMAT_S8: return "S8";
3226    case MALI_S_FORMAT_S8X8: return "S8X8";
3227    case MALI_S_FORMAT_S8X24: return "S8X24";
3228    case MALI_S_FORMAT_X24S8: return "X24S8";
3229    case MALI_S_FORMAT_X8S8: return "X8S8";
3230    case MALI_S_FORMAT_X32_S8X24: return "X32_S8X24";
3231    default: return "XXX: INVALID";
3232    }
3233}
3234
3235enum mali_tie_break_rule {
3236        MALI_TIE_BREAK_RULE_0_IN_180_OUT     =      0,
3237        MALI_TIE_BREAK_RULE_0_OUT_180_IN     =      1,
3238        MALI_TIE_BREAK_RULE_MINUS_180_IN_0_OUT =      2,
3239        MALI_TIE_BREAK_RULE_MINUS_180_OUT_0_IN =      3,
3240        MALI_TIE_BREAK_RULE_90_IN_270_OUT    =      4,
3241        MALI_TIE_BREAK_RULE_90_OUT_270_IN    =      5,
3242        MALI_TIE_BREAK_RULE_MINUS_90_IN_90_OUT =      6,
3243        MALI_TIE_BREAK_RULE_MINUS_90_OUT_90_IN =      7,
3244};
3245
3246static inline const char *
3247mali_tie_break_rule_as_str(enum mali_tie_break_rule imm)
3248{
3249    switch (imm) {
3250    case MALI_TIE_BREAK_RULE_0_IN_180_OUT: return "0_IN_180_OUT";
3251    case MALI_TIE_BREAK_RULE_0_OUT_180_IN: return "0_OUT_180_IN";
3252    case MALI_TIE_BREAK_RULE_MINUS_180_IN_0_OUT: return "MINUS_180_IN_0_OUT";
3253    case MALI_TIE_BREAK_RULE_MINUS_180_OUT_0_IN: return "MINUS_180_OUT_0_IN";
3254    case MALI_TIE_BREAK_RULE_90_IN_270_OUT: return "90_IN_270_OUT";
3255    case MALI_TIE_BREAK_RULE_90_OUT_270_IN: return "90_OUT_270_IN";
3256    case MALI_TIE_BREAK_RULE_MINUS_90_IN_90_OUT: return "MINUS_90_IN_90_OUT";
3257    case MALI_TIE_BREAK_RULE_MINUS_90_OUT_90_IN: return "MINUS_90_OUT_90_IN";
3258    default: return "XXX: INVALID";
3259    }
3260}
3261
3262struct MALI_RT_BUFFER {
3263   uint64_t                             base;
3264   uint32_t                             row_stride;
3265   uint32_t                             surface_stride;
3266};
3267
3268#define MALI_RT_BUFFER_header                   \
3269   0
3270
3271static inline void
3272MALI_RT_BUFFER_pack(uint32_t * restrict cl,
3273                    const struct MALI_RT_BUFFER * restrict values)
3274{
3275   cl[ 0] = __gen_uint(values->base, 0, 63);
3276   cl[ 1] = __gen_uint(values->base, 0, 63) >> 32;
3277   cl[ 2] = __gen_uint(values->row_stride, 0, 31);
3278   cl[ 3] = __gen_uint(values->surface_stride, 0, 31);
3279}
3280
3281
3282#define MALI_RT_BUFFER_LENGTH 16
3283struct mali_rt_buffer_packed { uint32_t opaque[4]; };
3284static inline void
3285MALI_RT_BUFFER_unpack(const uint8_t * restrict cl,
3286                      struct MALI_RT_BUFFER * restrict values)
3287{
3288   values->base = __gen_unpack_uint(cl, 0, 63);
3289   values->row_stride = __gen_unpack_uint(cl, 64, 95);
3290   values->surface_stride = __gen_unpack_uint(cl, 96, 127);
3291}
3292
3293static inline void
3294MALI_RT_BUFFER_print(FILE *fp, const struct MALI_RT_BUFFER * values, unsigned indent)
3295{
3296   fprintf(fp, "%*sBase: 0x%" PRIx64 "\n", indent, "", values->base);
3297   fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
3298   fprintf(fp, "%*sSurface Stride: %u\n", indent, "", values->surface_stride);
3299}
3300
3301enum mali_sample_pattern {
3302        MALI_SAMPLE_PATTERN_SINGLE_SAMPLED   =      0,
3303        MALI_SAMPLE_PATTERN_ORDERED_4X_GRID  =      1,
3304        MALI_SAMPLE_PATTERN_ROTATED_4X_GRID  =      2,
3305        MALI_SAMPLE_PATTERN_D3D_8X_GRID      =      3,
3306        MALI_SAMPLE_PATTERN_D3D_16X_GRID     =      4,
3307};
3308
3309static inline const char *
3310mali_sample_pattern_as_str(enum mali_sample_pattern imm)
3311{
3312    switch (imm) {
3313    case MALI_SAMPLE_PATTERN_SINGLE_SAMPLED: return "Single-sampled";
3314    case MALI_SAMPLE_PATTERN_ORDERED_4X_GRID: return "Ordered 4x Grid";
3315    case MALI_SAMPLE_PATTERN_ROTATED_4X_GRID: return "Rotated 4x Grid";
3316    case MALI_SAMPLE_PATTERN_D3D_8X_GRID: return "D3D 8x Grid";
3317    case MALI_SAMPLE_PATTERN_D3D_16X_GRID: return "D3D 16x Grid";
3318    default: return "XXX: INVALID";
3319    }
3320}
3321
3322enum mali_z_internal_format {
3323        MALI_Z_INTERNAL_FORMAT_D16           =      0,
3324        MALI_Z_INTERNAL_FORMAT_D24           =      1,
3325        MALI_Z_INTERNAL_FORMAT_D32           =      2,
3326};
3327
3328static inline const char *
3329mali_z_internal_format_as_str(enum mali_z_internal_format imm)
3330{
3331    switch (imm) {
3332    case MALI_Z_INTERNAL_FORMAT_D16: return "D16";
3333    case MALI_Z_INTERNAL_FORMAT_D24: return "D24";
3334    case MALI_Z_INTERNAL_FORMAT_D32: return "D32";
3335    default: return "XXX: INVALID";
3336    }
3337}
3338
3339enum mali_fbd_tag {
3340        MALI_FBD_TAG_IS_MFBD                 =      1,
3341        MALI_FBD_TAG_HAS_ZS_RT               =      2,
3342        MALI_FBD_TAG_MASK                    =     63,
3343};
3344
3345static inline const char *
3346mali_fbd_tag_as_str(enum mali_fbd_tag imm)
3347{
3348    switch (imm) {
3349    case MALI_FBD_TAG_IS_MFBD: return "IS_MFBD";
3350    case MALI_FBD_TAG_HAS_ZS_RT: return "HAS_ZS_RT";
3351    case MALI_FBD_TAG_MASK: return "MASK";
3352    default: return "XXX: INVALID";
3353    }
3354}
3355
3356struct MALI_FRAMEBUFFER_PARAMETERS {
3357   uint32_t                             width;
3358   uint32_t                             height;
3359   uint32_t                             bound_min_x;
3360   uint32_t                             bound_min_y;
3361   uint32_t                             bound_max_x;
3362   uint32_t                             bound_max_y;
3363   uint32_t                             sample_count;
3364   enum mali_sample_pattern             sample_pattern;
3365   enum mali_tie_break_rule             tie_break_rule;
3366   uint32_t                             effective_tile_size;
3367   uint32_t                             x_downsampling_scale;
3368   uint32_t                             y_downsampling_scale;
3369   uint32_t                             render_target_count;
3370   uint32_t                             color_buffer_allocation;
3371   uint32_t                             s_clear;
3372   bool                                 s_write_enable;
3373   bool                                 s_preload_enable;
3374   bool                                 s_unload_enable;
3375   enum mali_z_internal_format          z_internal_format;
3376   bool                                 z_write_enable;
3377   bool                                 z_preload_enable;
3378   bool                                 z_unload_enable;
3379   bool                                 has_zs_crc_extension;
3380   bool                                 crc_read_enable;
3381   bool                                 crc_write_enable;
3382   float                                z_clear;
3383};
3384
3385#define MALI_FRAMEBUFFER_PARAMETERS_header      \
3386   .sample_count = 1
3387
3388static inline void
3389MALI_FRAMEBUFFER_PARAMETERS_pack(uint32_t * restrict cl,
3390                                 const struct MALI_FRAMEBUFFER_PARAMETERS * restrict values)
3391{
3392   assert(values->width >= 1);
3393   assert(values->height >= 1);
3394   assert(util_is_power_of_two_nonzero(values->sample_count));
3395   assert(util_is_power_of_two_nonzero(values->effective_tile_size));
3396   assert(values->render_target_count >= 1);
3397   assert((values->color_buffer_allocation & 0x3ff) == 0);
3398   cl[ 0] = __gen_uint(values->width - 1, 0, 15) |
3399            __gen_uint(values->height - 1, 16, 31);
3400   cl[ 1] = __gen_uint(values->bound_min_x, 0, 15) |
3401            __gen_uint(values->bound_min_y, 16, 31);
3402   cl[ 2] = __gen_uint(values->bound_max_x, 0, 15) |
3403            __gen_uint(values->bound_max_y, 16, 31);
3404   cl[ 3] = __gen_uint(util_logbase2(values->sample_count), 0, 2) |
3405            __gen_uint(values->sample_pattern, 3, 5) |
3406            __gen_uint(values->tie_break_rule, 6, 8) |
3407            __gen_uint(util_logbase2(values->effective_tile_size), 9, 12) |
3408            __gen_uint(values->x_downsampling_scale, 13, 15) |
3409            __gen_uint(values->y_downsampling_scale, 16, 18) |
3410            __gen_uint(values->render_target_count - 1, 19, 22) |
3411            __gen_uint(values->color_buffer_allocation >> 10, 24, 31);
3412   cl[ 4] = __gen_uint(values->s_clear, 0, 7) |
3413            __gen_uint(values->s_write_enable, 8, 8) |
3414            __gen_uint(values->s_preload_enable, 9, 9) |
3415            __gen_uint(values->s_unload_enable, 10, 10) |
3416            __gen_uint(values->z_internal_format, 16, 17) |
3417            __gen_uint(values->z_write_enable, 18, 18) |
3418            __gen_uint(values->z_preload_enable, 19, 19) |
3419            __gen_uint(values->z_unload_enable, 20, 20) |
3420            __gen_uint(values->has_zs_crc_extension, 21, 21) |
3421            __gen_uint(values->crc_read_enable, 30, 30) |
3422            __gen_uint(values->crc_write_enable, 31, 31);
3423   cl[ 5] = __gen_uint(fui(values->z_clear), 0, 32);
3424}
3425
3426
3427#define MALI_FRAMEBUFFER_PARAMETERS_LENGTH 24
3428struct mali_framebuffer_parameters_packed { uint32_t opaque[6]; };
3429static inline void
3430MALI_FRAMEBUFFER_PARAMETERS_unpack(const uint8_t * restrict cl,
3431                                   struct MALI_FRAMEBUFFER_PARAMETERS * restrict values)
3432{
3433   if (((const uint32_t *) cl)[3] & 0x800000) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 3\n");
3434   if (((const uint32_t *) cl)[4] & 0x3fc0f800) fprintf(stderr, "XXX: Invalid field of Framebuffer Parameters unpacked at word 4\n");
3435   values->width = __gen_unpack_uint(cl, 0, 15) + 1;
3436   values->height = __gen_unpack_uint(cl, 16, 31) + 1;
3437   values->bound_min_x = __gen_unpack_uint(cl, 32, 47);
3438   values->bound_min_y = __gen_unpack_uint(cl, 48, 63);
3439   values->bound_max_x = __gen_unpack_uint(cl, 64, 79);
3440   values->bound_max_y = __gen_unpack_uint(cl, 80, 95);
3441   values->sample_count = 1U << __gen_unpack_uint(cl, 96, 98);
3442   values->sample_pattern = (enum mali_sample_pattern)__gen_unpack_uint(cl, 99, 101);
3443   values->tie_break_rule = (enum mali_tie_break_rule)__gen_unpack_uint(cl, 102, 104);
3444   values->effective_tile_size = 1U << __gen_unpack_uint(cl, 105, 108);
3445   values->x_downsampling_scale = __gen_unpack_uint(cl, 109, 111);
3446   values->y_downsampling_scale = __gen_unpack_uint(cl, 112, 114);
3447   values->render_target_count = __gen_unpack_uint(cl, 115, 118) + 1;
3448   values->color_buffer_allocation = __gen_unpack_uint(cl, 120, 127) << 10;
3449   values->s_clear = __gen_unpack_uint(cl, 128, 135);
3450   values->s_write_enable = __gen_unpack_uint(cl, 136, 136);
3451   values->s_preload_enable = __gen_unpack_uint(cl, 137, 137);
3452   values->s_unload_enable = __gen_unpack_uint(cl, 138, 138);
3453   values->z_internal_format = (enum mali_z_internal_format)__gen_unpack_uint(cl, 144, 145);
3454   values->z_write_enable = __gen_unpack_uint(cl, 146, 146);
3455   values->z_preload_enable = __gen_unpack_uint(cl, 147, 147);
3456   values->z_unload_enable = __gen_unpack_uint(cl, 148, 148);
3457   values->has_zs_crc_extension = __gen_unpack_uint(cl, 149, 149);
3458   values->crc_read_enable = __gen_unpack_uint(cl, 158, 158);
3459   values->crc_write_enable = __gen_unpack_uint(cl, 159, 159);
3460   values->z_clear = __gen_unpack_float(cl, 160, 191);
3461}
3462
3463static inline void
3464MALI_FRAMEBUFFER_PARAMETERS_print(FILE *fp, const struct MALI_FRAMEBUFFER_PARAMETERS * values, unsigned indent)
3465{
3466   fprintf(fp, "%*sWidth: %u\n", indent, "", values->width);
3467   fprintf(fp, "%*sHeight: %u\n", indent, "", values->height);
3468   fprintf(fp, "%*sBound Min X: %u\n", indent, "", values->bound_min_x);
3469   fprintf(fp, "%*sBound Min Y: %u\n", indent, "", values->bound_min_y);
3470   fprintf(fp, "%*sBound Max X: %u\n", indent, "", values->bound_max_x);
3471   fprintf(fp, "%*sBound Max Y: %u\n", indent, "", values->bound_max_y);
3472   fprintf(fp, "%*sSample Count: %u\n", indent, "", values->sample_count);
3473   fprintf(fp, "%*sSample Pattern: %s\n", indent, "", mali_sample_pattern_as_str(values->sample_pattern));
3474   fprintf(fp, "%*sTie-Break Rule: %s\n", indent, "", mali_tie_break_rule_as_str(values->tie_break_rule));
3475   fprintf(fp, "%*sEffective Tile Size: %u\n", indent, "", values->effective_tile_size);
3476   fprintf(fp, "%*sX Downsampling Scale: %u\n", indent, "", values->x_downsampling_scale);
3477   fprintf(fp, "%*sY Downsampling Scale: %u\n", indent, "", values->y_downsampling_scale);
3478   fprintf(fp, "%*sRender Target Count: %u\n", indent, "", values->render_target_count);
3479   fprintf(fp, "%*sColor Buffer Allocation: %u\n", indent, "", values->color_buffer_allocation);
3480   fprintf(fp, "%*sS Clear: %u\n", indent, "", values->s_clear);
3481   fprintf(fp, "%*sS Write Enable: %s\n", indent, "", values->s_write_enable ? "true" : "false");
3482   fprintf(fp, "%*sS Preload Enable: %s\n", indent, "", values->s_preload_enable ? "true" : "false");
3483   fprintf(fp, "%*sS Unload Enable: %s\n", indent, "", values->s_unload_enable ? "true" : "false");
3484   fprintf(fp, "%*sZ Internal Format: %s\n", indent, "", mali_z_internal_format_as_str(values->z_internal_format));
3485   fprintf(fp, "%*sZ Write Enable: %s\n", indent, "", values->z_write_enable ? "true" : "false");
3486   fprintf(fp, "%*sZ Preload Enable: %s\n", indent, "", values->z_preload_enable ? "true" : "false");
3487   fprintf(fp, "%*sZ Unload Enable: %s\n", indent, "", values->z_unload_enable ? "true" : "false");
3488   fprintf(fp, "%*sHas ZS CRC Extension: %s\n", indent, "", values->has_zs_crc_extension ? "true" : "false");
3489   fprintf(fp, "%*sCRC Read Enable: %s\n", indent, "", values->crc_read_enable ? "true" : "false");
3490   fprintf(fp, "%*sCRC Write Enable: %s\n", indent, "", values->crc_write_enable ? "true" : "false");
3491   fprintf(fp, "%*sZ Clear: %f\n", indent, "", values->z_clear);
3492}
3493
3494struct MALI_ZS_CRC_EXTENSION {
3495   uint64_t                             crc_base;
3496   uint32_t                             crc_row_stride;
3497   enum mali_zs_format                  zs_write_format;
3498   enum mali_block_format               zs_block_format;
3499   enum mali_msaa                       zs_msaa;
3500   bool                                 zs_big_endian;
3501   bool                                 zs_clean_pixel_write_enable;
3502   enum mali_s_format                   s_write_format;
3503   enum mali_block_format               s_block_format;
3504   enum mali_msaa                       s_msaa;
3505   enum mali_zs_preload_format          zs_preload_format;
3506   uint64_t                             zs_writeback_base;
3507   uint32_t                             zs_writeback_row_stride;
3508   uint32_t                             zs_writeback_surface_stride;
3509   uint64_t                             s_writeback_base;
3510   uint32_t                             s_writeback_row_stride;
3511   uint32_t                             s_writeback_surface_stride;
3512   uint64_t                             zs_afbc_header;
3513   uint32_t                             zs_afbc_row_stride;
3514   uint32_t                             zs_afbc_chunk_size;
3515   bool                                 zs_afbc_sparse;
3516   uint64_t                             zs_afbc_body;
3517   uint32_t                             zs_afbc_body_size;
3518   uint64_t                             zs_preload_base;
3519   uint32_t                             zs_preload_row_stride;
3520   uint32_t                             zs_preload_surface_stride;
3521};
3522
3523#define MALI_ZS_CRC_EXTENSION_header            \
3524   .zs_msaa = MALI_MSAA_SINGLE,  \
3525   .s_msaa = MALI_MSAA_SINGLE
3526
3527static inline void
3528MALI_ZS_CRC_EXTENSION_pack(uint32_t * restrict cl,
3529                           const struct MALI_ZS_CRC_EXTENSION * restrict values)
3530{
3531   cl[ 0] = __gen_uint(values->crc_base, 0, 63);
3532   cl[ 1] = __gen_uint(values->crc_base, 0, 63) >> 32;
3533   cl[ 2] = __gen_uint(values->crc_row_stride, 0, 31);
3534   cl[ 3] = __gen_uint(values->zs_write_format, 0, 3) |
3535            __gen_uint(values->zs_block_format, 4, 5) |
3536            __gen_uint(values->zs_msaa, 6, 7) |
3537            __gen_uint(values->zs_big_endian, 8, 8) |
3538            __gen_uint(values->zs_clean_pixel_write_enable, 10, 10) |
3539            __gen_uint(values->s_write_format, 16, 19) |
3540            __gen_uint(values->s_block_format, 20, 21) |
3541            __gen_uint(values->s_msaa, 22, 23) |
3542            __gen_uint(values->zs_preload_format, 28, 31);
3543   cl[ 4] = __gen_uint(values->zs_writeback_base, 0, 63) |
3544            __gen_uint(values->zs_afbc_header, 0, 63);
3545   cl[ 5] = __gen_uint(values->zs_writeback_base, 0, 63) >> 32 |
3546            __gen_uint(values->zs_afbc_header, 0, 63) >> 32;
3547   cl[ 6] = __gen_uint(values->zs_writeback_row_stride, 0, 31) |
3548            __gen_uint(values->zs_afbc_row_stride, 0, 12);
3549   cl[ 7] = __gen_uint(values->zs_writeback_surface_stride, 0, 31) |
3550            __gen_uint(values->zs_afbc_chunk_size, 0, 11) |
3551            __gen_uint(values->zs_afbc_sparse, 16, 16);
3552   cl[ 8] = __gen_uint(values->s_writeback_base, 0, 63) |
3553            __gen_uint(values->zs_afbc_body, 0, 63);
3554   cl[ 9] = __gen_uint(values->s_writeback_base, 0, 63) >> 32 |
3555            __gen_uint(values->zs_afbc_body, 0, 63) >> 32;
3556   cl[10] = __gen_uint(values->s_writeback_row_stride, 0, 31) |
3557            __gen_uint(values->zs_afbc_body_size, 0, 31);
3558   cl[11] = __gen_uint(values->s_writeback_surface_stride, 0, 31);
3559   cl[12] = __gen_uint(values->zs_preload_base, 0, 63);
3560   cl[13] = __gen_uint(values->zs_preload_base, 0, 63) >> 32;
3561   cl[14] = __gen_uint(values->zs_preload_row_stride, 0, 31);
3562   cl[15] = __gen_uint(values->zs_preload_surface_stride, 0, 31);
3563}
3564
3565
3566#define MALI_ZS_CRC_EXTENSION_LENGTH 64
3567#define MALI_ZS_CRC_EXTENSION_ALIGN 64
3568struct mali_zs_crc_extension_packed { uint32_t opaque[16]; };
3569static inline void
3570MALI_ZS_CRC_EXTENSION_unpack(const uint8_t * restrict cl,
3571                             struct MALI_ZS_CRC_EXTENSION * restrict values)
3572{
3573   if (((const uint32_t *) cl)[3] & 0xf00fa00) fprintf(stderr, "XXX: Invalid field of ZS CRC Extension unpacked at word 3\n");
3574   values->crc_base = __gen_unpack_uint(cl, 0, 63);
3575   values->crc_row_stride = __gen_unpack_uint(cl, 64, 95);
3576   values->zs_write_format = (enum mali_zs_format)__gen_unpack_uint(cl, 96, 99);
3577   values->zs_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 100, 101);
3578   values->zs_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 102, 103);
3579   values->zs_big_endian = __gen_unpack_uint(cl, 104, 104);
3580   values->zs_clean_pixel_write_enable = __gen_unpack_uint(cl, 106, 106);
3581   values->s_write_format = (enum mali_s_format)__gen_unpack_uint(cl, 112, 115);
3582   values->s_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 116, 117);
3583   values->s_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 118, 119);
3584   values->zs_preload_format = (enum mali_zs_preload_format)__gen_unpack_uint(cl, 124, 127);
3585   values->zs_writeback_base = __gen_unpack_uint(cl, 128, 191);
3586   values->zs_writeback_row_stride = __gen_unpack_uint(cl, 192, 223);
3587   values->zs_writeback_surface_stride = __gen_unpack_uint(cl, 224, 255);
3588   values->s_writeback_base = __gen_unpack_uint(cl, 256, 319);
3589   values->s_writeback_row_stride = __gen_unpack_uint(cl, 320, 351);
3590   values->s_writeback_surface_stride = __gen_unpack_uint(cl, 352, 383);
3591   values->zs_afbc_header = __gen_unpack_uint(cl, 128, 191);
3592   values->zs_afbc_row_stride = __gen_unpack_uint(cl, 192, 204);
3593   values->zs_afbc_chunk_size = __gen_unpack_uint(cl, 224, 235);
3594   values->zs_afbc_sparse = __gen_unpack_uint(cl, 240, 240);
3595   values->zs_afbc_body = __gen_unpack_uint(cl, 256, 319);
3596   values->zs_afbc_body_size = __gen_unpack_uint(cl, 320, 351);
3597   values->zs_preload_base = __gen_unpack_uint(cl, 384, 447);
3598   values->zs_preload_row_stride = __gen_unpack_uint(cl, 448, 479);
3599   values->zs_preload_surface_stride = __gen_unpack_uint(cl, 480, 511);
3600}
3601
3602static inline void
3603MALI_ZS_CRC_EXTENSION_print(FILE *fp, const struct MALI_ZS_CRC_EXTENSION * values, unsigned indent)
3604{
3605   fprintf(fp, "%*sCRC Base: 0x%" PRIx64 "\n", indent, "", values->crc_base);
3606   fprintf(fp, "%*sCRC Row Stride: %u\n", indent, "", values->crc_row_stride);
3607   fprintf(fp, "%*sZS Write Format: %s\n", indent, "", mali_zs_format_as_str(values->zs_write_format));
3608   fprintf(fp, "%*sZS Block Format: %s\n", indent, "", mali_block_format_as_str(values->zs_block_format));
3609   fprintf(fp, "%*sZS MSAA: %s\n", indent, "", mali_msaa_as_str(values->zs_msaa));
3610   fprintf(fp, "%*sZS Big Endian: %s\n", indent, "", values->zs_big_endian ? "true" : "false");
3611   fprintf(fp, "%*sZS Clean Pixel Write Enable: %s\n", indent, "", values->zs_clean_pixel_write_enable ? "true" : "false");
3612   fprintf(fp, "%*sS Write Format: %s\n", indent, "", mali_s_format_as_str(values->s_write_format));
3613   fprintf(fp, "%*sS Block Format: %s\n", indent, "", mali_block_format_as_str(values->s_block_format));
3614   fprintf(fp, "%*sS MSAA: %s\n", indent, "", mali_msaa_as_str(values->s_msaa));
3615   fprintf(fp, "%*sZS Preload Format: %s\n", indent, "", mali_zs_preload_format_as_str(values->zs_preload_format));
3616   fprintf(fp, "%*sZS Writeback Base: 0x%" PRIx64 "\n", indent, "", values->zs_writeback_base);
3617   fprintf(fp, "%*sZS Writeback Row Stride: %u\n", indent, "", values->zs_writeback_row_stride);
3618   fprintf(fp, "%*sZS Writeback Surface Stride: %u\n", indent, "", values->zs_writeback_surface_stride);
3619   fprintf(fp, "%*sS Writeback Base: 0x%" PRIx64 "\n", indent, "", values->s_writeback_base);
3620   fprintf(fp, "%*sS Writeback Row Stride: %u\n", indent, "", values->s_writeback_row_stride);
3621   fprintf(fp, "%*sS Writeback Surface Stride: %u\n", indent, "", values->s_writeback_surface_stride);
3622   fprintf(fp, "%*sZS AFBC Header: 0x%" PRIx64 "\n", indent, "", values->zs_afbc_header);
3623   fprintf(fp, "%*sZS AFBC Row Stride: %u\n", indent, "", values->zs_afbc_row_stride);
3624   fprintf(fp, "%*sZS AFBC Chunk Size: %u\n", indent, "", values->zs_afbc_chunk_size);
3625   fprintf(fp, "%*sZS AFBC Sparse: %s\n", indent, "", values->zs_afbc_sparse ? "true" : "false");
3626   fprintf(fp, "%*sZS AFBC Body: 0x%" PRIx64 "\n", indent, "", values->zs_afbc_body);
3627   fprintf(fp, "%*sZS AFBC Body Size: %u\n", indent, "", values->zs_afbc_body_size);
3628   fprintf(fp, "%*sZS Preload Base: 0x%" PRIx64 "\n", indent, "", values->zs_preload_base);
3629   fprintf(fp, "%*sZS Preload Row Stride: %u\n", indent, "", values->zs_preload_row_stride);
3630   fprintf(fp, "%*sZS Preload Surface Stride: %u\n", indent, "", values->zs_preload_surface_stride);
3631}
3632
3633enum mali_rt_endianness {
3634        MALI_RT_ENDIANNESS_LITTLE_ENDIAN     =      0,
3635        MALI_RT_ENDIANNESS_BIG_ENDIAN_2B     =      1,
3636        MALI_RT_ENDIANNESS_BIG_ENDIAN_4B     =      2,
3637        MALI_RT_ENDIANNESS_BIG_ENDIAN_8B     =      3,
3638};
3639
3640static inline const char *
3641mali_rt_endianness_as_str(enum mali_rt_endianness imm)
3642{
3643    switch (imm) {
3644    case MALI_RT_ENDIANNESS_LITTLE_ENDIAN: return "Little Endian";
3645    case MALI_RT_ENDIANNESS_BIG_ENDIAN_2B: return "Big Endian 2B";
3646    case MALI_RT_ENDIANNESS_BIG_ENDIAN_4B: return "Big Endian 4B";
3647    case MALI_RT_ENDIANNESS_BIG_ENDIAN_8B: return "Big Endian 8B";
3648    default: return "XXX: INVALID";
3649    }
3650}
3651
3652enum mali_yuv_conv_k6 {
3653        MALI_YUV_CONV_K6_0                   =      0,
3654        MALI_YUV_CONV_K6_16                  =      1,
3655};
3656
3657static inline const char *
3658mali_yuv_conv_k6_as_str(enum mali_yuv_conv_k6 imm)
3659{
3660    switch (imm) {
3661    case MALI_YUV_CONV_K6_0: return "0";
3662    case MALI_YUV_CONV_K6_16: return "16";
3663    default: return "XXX: INVALID";
3664    }
3665}
3666
3667enum mali_yuv_conv_k7_clamp {
3668        MALI_YUV_CONV_K7_CLAMP_MINUS_128_TO_127 =      0,
3669        MALI_YUV_CONV_K7_CLAMP_MINUS_112_TO_111 =      1,
3670        MALI_YUV_CONV_K7_CLAMP_0_TO_255      =      2,
3671        MALI_YUV_CONV_K7_CLAMP_16_TO_239     =      3,
3672};
3673
3674static inline const char *
3675mali_yuv_conv_k7_clamp_as_str(enum mali_yuv_conv_k7_clamp imm)
3676{
3677    switch (imm) {
3678    case MALI_YUV_CONV_K7_CLAMP_MINUS_128_TO_127: return "MINUS_128_TO_127";
3679    case MALI_YUV_CONV_K7_CLAMP_MINUS_112_TO_111: return "MINUS_112_TO_111";
3680    case MALI_YUV_CONV_K7_CLAMP_0_TO_255: return "0_TO_255";
3681    case MALI_YUV_CONV_K7_CLAMP_16_TO_239: return "16_TO_239";
3682    default: return "XXX: INVALID";
3683    }
3684}
3685
3686enum mali_yuv_conv_k8 {
3687        MALI_YUV_CONV_K8_220                 =      0,
3688        MALI_YUV_CONV_K8_256                 =      1,
3689};
3690
3691static inline const char *
3692mali_yuv_conv_k8_as_str(enum mali_yuv_conv_k8 imm)
3693{
3694    switch (imm) {
3695    case MALI_YUV_CONV_K8_220: return "220";
3696    case MALI_YUV_CONV_K8_256: return "256";
3697    default: return "XXX: INVALID";
3698    }
3699}
3700
3701struct MALI_RENDER_TARGET_YUV_OVERLAY {
3702   uint32_t                             conv_k5;
3703   enum mali_yuv_conv_k6                conv_k6;
3704   enum mali_yuv_conv_k7_clamp          conv_k7_clamp;
3705   enum mali_yuv_conv_k8                conv_k8;
3706   bool                                 conv_disable;
3707   uint32_t                             conv_k1;
3708   uint32_t                             conv_k2;
3709   uint32_t                             conv_k3;
3710   uint32_t                             conv_k4;
3711   uint64_t                             plane_0_base;
3712   uint64_t                             plane_1_base;
3713   uint64_t                             plane_2_base;
3714   uint32_t                             plane_0_stride;
3715   uint32_t                             plane_1_2_stride;
3716};
3717
3718#define MALI_RENDER_TARGET_YUV_OVERLAY_header   \
3719   0
3720
3721static inline void
3722MALI_RENDER_TARGET_YUV_OVERLAY_pack(uint32_t * restrict cl,
3723                                    const struct MALI_RENDER_TARGET_YUV_OVERLAY * restrict values)
3724{
3725   cl[ 0] = 0;
3726   cl[ 1] = 0;
3727   cl[ 2] = __gen_uint(values->conv_k5, 16, 23) |
3728            __gen_uint(values->conv_k6, 24, 24) |
3729            __gen_uint(values->conv_k7_clamp, 25, 26) |
3730            __gen_uint(values->conv_k8, 27, 27) |
3731            __gen_uint(values->conv_disable, 31, 31);
3732   cl[ 3] = __gen_uint(values->conv_k1, 0, 7) |
3733            __gen_uint(values->conv_k2, 8, 15) |
3734            __gen_uint(values->conv_k3, 16, 23) |
3735            __gen_uint(values->conv_k4, 24, 31);
3736   cl[ 4] = __gen_uint(values->plane_0_base, 0, 63);
3737   cl[ 5] = __gen_uint(values->plane_0_base, 0, 63) >> 32;
3738   cl[ 6] = __gen_uint(values->plane_1_base, 0, 63);
3739   cl[ 7] = __gen_uint(values->plane_1_base, 0, 63) >> 32;
3740   cl[ 8] = __gen_uint(values->plane_2_base, 0, 63);
3741   cl[ 9] = __gen_uint(values->plane_2_base, 0, 63) >> 32;
3742   cl[10] = __gen_uint(values->plane_0_stride, 0, 31);
3743   cl[11] = __gen_uint(values->plane_1_2_stride, 0, 31);
3744   cl[12] = 0;
3745   cl[13] = 0;
3746   cl[14] = 0;
3747   cl[15] = 0;
3748}
3749
3750
3751#define MALI_RENDER_TARGET_YUV_OVERLAY_LENGTH 64
3752struct mali_render_target_yuv_overlay_packed { uint32_t opaque[16]; };
3753static inline void
3754MALI_RENDER_TARGET_YUV_OVERLAY_unpack(const uint8_t * restrict cl,
3755                                      struct MALI_RENDER_TARGET_YUV_OVERLAY * restrict values)
3756{
3757   if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 0\n");
3758   if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 1\n");
3759   if (((const uint32_t *) cl)[2] & 0x7000ffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 2\n");
3760   if (((const uint32_t *) cl)[12] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 12\n");
3761   if (((const uint32_t *) cl)[13] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 13\n");
3762   if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 14\n");
3763   if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target YUV Overlay unpacked at word 15\n");
3764   values->conv_k5 = __gen_unpack_uint(cl, 80, 87);
3765   values->conv_k6 = (enum mali_yuv_conv_k6)__gen_unpack_uint(cl, 88, 88);
3766   values->conv_k7_clamp = (enum mali_yuv_conv_k7_clamp)__gen_unpack_uint(cl, 89, 90);
3767   values->conv_k8 = (enum mali_yuv_conv_k8)__gen_unpack_uint(cl, 91, 91);
3768   values->conv_disable = __gen_unpack_uint(cl, 95, 95);
3769   values->conv_k1 = __gen_unpack_uint(cl, 96, 103);
3770   values->conv_k2 = __gen_unpack_uint(cl, 104, 111);
3771   values->conv_k3 = __gen_unpack_uint(cl, 112, 119);
3772   values->conv_k4 = __gen_unpack_uint(cl, 120, 127);
3773   values->plane_0_base = __gen_unpack_uint(cl, 128, 191);
3774   values->plane_1_base = __gen_unpack_uint(cl, 192, 255);
3775   values->plane_2_base = __gen_unpack_uint(cl, 256, 319);
3776   values->plane_0_stride = __gen_unpack_uint(cl, 320, 351);
3777   values->plane_1_2_stride = __gen_unpack_uint(cl, 352, 383);
3778}
3779
3780static inline void
3781MALI_RENDER_TARGET_YUV_OVERLAY_print(FILE *fp, const struct MALI_RENDER_TARGET_YUV_OVERLAY * values, unsigned indent)
3782{
3783   fprintf(fp, "%*sConv K5: %u\n", indent, "", values->conv_k5);
3784   fprintf(fp, "%*sConv K6: %s\n", indent, "", mali_yuv_conv_k6_as_str(values->conv_k6));
3785   fprintf(fp, "%*sConv K7 Clamp: %s\n", indent, "", mali_yuv_conv_k7_clamp_as_str(values->conv_k7_clamp));
3786   fprintf(fp, "%*sConv K8: %s\n", indent, "", mali_yuv_conv_k8_as_str(values->conv_k8));
3787   fprintf(fp, "%*sConv Disable: %s\n", indent, "", values->conv_disable ? "true" : "false");
3788   fprintf(fp, "%*sConv K1: %u\n", indent, "", values->conv_k1);
3789   fprintf(fp, "%*sConv K2: %u\n", indent, "", values->conv_k2);
3790   fprintf(fp, "%*sConv K3: %u\n", indent, "", values->conv_k3);
3791   fprintf(fp, "%*sConv K4: %u\n", indent, "", values->conv_k4);
3792   fprintf(fp, "%*sPlane 0 Base: 0x%" PRIx64 "\n", indent, "", values->plane_0_base);
3793   fprintf(fp, "%*sPlane 1 Base: 0x%" PRIx64 "\n", indent, "", values->plane_1_base);
3794   fprintf(fp, "%*sPlane 2 Base: 0x%" PRIx64 "\n", indent, "", values->plane_2_base);
3795   fprintf(fp, "%*sPlane 0 Stride: %u\n", indent, "", values->plane_0_stride);
3796   fprintf(fp, "%*sPlane 1 2 Stride: %u\n", indent, "", values->plane_1_2_stride);
3797}
3798
3799struct MALI_RENDER_TARGET_AFBC_OVERLAY {
3800   uint64_t                             header;
3801   uint32_t                             row_stride;
3802   uint32_t                             chunk_size;
3803   bool                                 sparse;
3804   bool                                 yuv_transform_enable;
3805   uint64_t                             body;
3806   uint32_t                             body_size;
3807};
3808
3809#define MALI_RENDER_TARGET_AFBC_OVERLAY_header  \
3810   0
3811
3812static inline void
3813MALI_RENDER_TARGET_AFBC_OVERLAY_pack(uint32_t * restrict cl,
3814                                     const struct MALI_RENDER_TARGET_AFBC_OVERLAY * restrict values)
3815{
3816   cl[ 0] = 0;
3817   cl[ 1] = 0;
3818   cl[ 2] = 0;
3819   cl[ 3] = 0;
3820   cl[ 4] = __gen_uint(values->header, 0, 63);
3821   cl[ 5] = __gen_uint(values->header, 0, 63) >> 32;
3822   cl[ 6] = __gen_uint(values->row_stride, 0, 12);
3823   cl[ 7] = __gen_uint(values->chunk_size, 0, 11) |
3824            __gen_uint(values->sparse, 16, 16) |
3825            __gen_uint(values->yuv_transform_enable, 17, 17);
3826   cl[ 8] = __gen_uint(values->body, 0, 63);
3827   cl[ 9] = __gen_uint(values->body, 0, 63) >> 32;
3828   cl[10] = __gen_uint(values->body_size, 0, 31);
3829   cl[11] = 0;
3830   cl[12] = 0;
3831   cl[13] = 0;
3832   cl[14] = 0;
3833   cl[15] = 0;
3834}
3835
3836
3837#define MALI_RENDER_TARGET_AFBC_OVERLAY_LENGTH 64
3838struct mali_render_target_afbc_overlay_packed { uint32_t opaque[16]; };
3839static inline void
3840MALI_RENDER_TARGET_AFBC_OVERLAY_unpack(const uint8_t * restrict cl,
3841                                       struct MALI_RENDER_TARGET_AFBC_OVERLAY * restrict values)
3842{
3843   if (((const uint32_t *) cl)[0] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 0\n");
3844   if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 1\n");
3845   if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 2\n");
3846   if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 3\n");
3847   if (((const uint32_t *) cl)[6] & 0xffffe000) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 6\n");
3848   if (((const uint32_t *) cl)[7] & 0xfffcf000) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 7\n");
3849   if (((const uint32_t *) cl)[11] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 11\n");
3850   if (((const uint32_t *) cl)[12] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 12\n");
3851   if (((const uint32_t *) cl)[13] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 13\n");
3852   if (((const uint32_t *) cl)[14] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 14\n");
3853   if (((const uint32_t *) cl)[15] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Render Target AFBC Overlay unpacked at word 15\n");
3854   values->header = __gen_unpack_uint(cl, 128, 191);
3855   values->row_stride = __gen_unpack_uint(cl, 192, 204);
3856   values->chunk_size = __gen_unpack_uint(cl, 224, 235);
3857   values->sparse = __gen_unpack_uint(cl, 240, 240);
3858   values->yuv_transform_enable = __gen_unpack_uint(cl, 241, 241);
3859   values->body = __gen_unpack_uint(cl, 256, 319);
3860   values->body_size = __gen_unpack_uint(cl, 320, 351);
3861}
3862
3863static inline void
3864MALI_RENDER_TARGET_AFBC_OVERLAY_print(FILE *fp, const struct MALI_RENDER_TARGET_AFBC_OVERLAY * values, unsigned indent)
3865{
3866   fprintf(fp, "%*sHeader: 0x%" PRIx64 "\n", indent, "", values->header);
3867   fprintf(fp, "%*sRow Stride: %u\n", indent, "", values->row_stride);
3868   fprintf(fp, "%*sChunk Size: %u\n", indent, "", values->chunk_size);
3869   fprintf(fp, "%*sSparse: %s\n", indent, "", values->sparse ? "true" : "false");
3870   fprintf(fp, "%*sYUV Transform Enable: %s\n", indent, "", values->yuv_transform_enable ? "true" : "false");
3871   fprintf(fp, "%*sBody: 0x%" PRIx64 "\n", indent, "", values->body);
3872   fprintf(fp, "%*sBody Size: %u\n", indent, "", values->body_size);
3873}
3874
3875struct MALI_RT_CLEAR {
3876   uint32_t                             color_0;
3877   uint32_t                             color_1;
3878   uint32_t                             color_2;
3879   uint32_t                             color_3;
3880};
3881
3882#define MALI_RT_CLEAR_header                    \
3883   0
3884
3885static inline void
3886MALI_RT_CLEAR_pack(uint32_t * restrict cl,
3887                   const struct MALI_RT_CLEAR * restrict values)
3888{
3889   cl[ 0] = __gen_uint(values->color_0, 0, 31);
3890   cl[ 1] = __gen_uint(values->color_1, 0, 31);
3891   cl[ 2] = __gen_uint(values->color_2, 0, 31);
3892   cl[ 3] = __gen_uint(values->color_3, 0, 31);
3893}
3894
3895
3896#define MALI_RT_CLEAR_LENGTH 16
3897struct mali_rt_clear_packed { uint32_t opaque[4]; };
3898static inline void
3899MALI_RT_CLEAR_unpack(const uint8_t * restrict cl,
3900                     struct MALI_RT_CLEAR * restrict values)
3901{
3902   values->color_0 = __gen_unpack_uint(cl, 0, 31);
3903   values->color_1 = __gen_unpack_uint(cl, 32, 63);
3904   values->color_2 = __gen_unpack_uint(cl, 64, 95);
3905   values->color_3 = __gen_unpack_uint(cl, 96, 127);
3906}
3907
3908static inline void
3909MALI_RT_CLEAR_print(FILE *fp, const struct MALI_RT_CLEAR * values, unsigned indent)
3910{
3911   fprintf(fp, "%*sColor 0: %u\n", indent, "", values->color_0);
3912   fprintf(fp, "%*sColor 1: %u\n", indent, "", values->color_1);
3913   fprintf(fp, "%*sColor 2: %u\n", indent, "", values->color_2);
3914   fprintf(fp, "%*sColor 3: %u\n", indent, "", values->color_3);
3915}
3916
3917struct MALI_RENDER_TARGET {
3918   struct MALI_RENDER_TARGET_YUV_OVERLAY yuv;
3919   struct MALI_RENDER_TARGET_AFBC_OVERLAY afbc;
3920   uint32_t                             internal_buffer_offset;
3921   bool                                 yuv_enable;
3922   enum mali_color_buffer_internal_format internal_format;
3923   bool                                 write_enable;
3924   enum mali_color_format               writeback_format;
3925   enum mali_rt_endianness              writeback_endianness;
3926   enum mali_block_format               writeback_block_format;
3927   enum mali_msaa                       writeback_msaa;
3928   bool                                 srgb;
3929   bool                                 dithering_enable;
3930   uint32_t                             swizzle;
3931   enum mali_downsampling_accumulation_mode writeback_sampling_mode;
3932   bool                                 clean_pixel_write_enable;
3933   bool                                 preload_enable;
3934   bool                                 unload_enable;
3935   enum mali_color_format               preload_format;
3936   enum mali_rt_endianness              preload_endianness;
3937   enum mali_block_format               preload_block_format;
3938   enum mali_msaa                       preload_msaa;
3939   struct MALI_RT_BUFFER                rgb;
3940   struct MALI_RT_BUFFER                preload_buffer;
3941   struct MALI_RT_CLEAR                 clear;
3942};
3943
3944#define MALI_RENDER_TARGET_header               \
3945   .yuv = { MALI_RENDER_TARGET_YUV_OVERLAY_header },  \
3946   .afbc = { MALI_RENDER_TARGET_AFBC_OVERLAY_header },  \
3947   .rgb = { MALI_RT_BUFFER_header },  \
3948   .preload_buffer = { MALI_RT_BUFFER_header },  \
3949   .clear = { MALI_RT_CLEAR_header }
3950
3951static inline void
3952MALI_RENDER_TARGET_pack(uint32_t * restrict cl,
3953                        const struct MALI_RENDER_TARGET * restrict values)
3954{
3955   assert((values->internal_buffer_offset & 0xf) == 0);
3956   cl[ 0] = __gen_uint(values->internal_buffer_offset >> 4, 4, 15) |
3957            __gen_uint(values->yuv_enable, 24, 24) |
3958            __gen_uint(values->internal_format, 26, 31);
3959   cl[ 1] = __gen_uint(values->write_enable, 0, 0) |
3960            __gen_uint(values->writeback_format, 3, 7) |
3961            __gen_uint(values->writeback_endianness, 8, 9) |
3962            __gen_uint(values->writeback_block_format, 10, 11) |
3963            __gen_uint(values->writeback_msaa, 12, 13) |
3964            __gen_uint(values->srgb, 14, 14) |
3965            __gen_uint(values->dithering_enable, 15, 15) |
3966            __gen_uint(values->swizzle, 16, 27) |
3967            __gen_uint(values->writeback_sampling_mode, 29, 30) |
3968            __gen_uint(values->clean_pixel_write_enable, 31, 31);
3969   cl[ 2] = __gen_uint(values->yuv.conv_k5, 16, 23) |
3970            __gen_uint(values->yuv.conv_k6, 24, 24) |
3971            __gen_uint(values->yuv.conv_k7_clamp, 25, 26) |
3972            __gen_uint(values->yuv.conv_k8, 27, 27) |
3973            __gen_uint(values->yuv.conv_disable, 31, 31) |
3974            __gen_uint(values->preload_enable, 0, 0) |
3975            __gen_uint(values->unload_enable, 1, 1) |
3976            __gen_uint(values->preload_format, 3, 7) |
3977            __gen_uint(values->preload_endianness, 8, 9) |
3978            __gen_uint(values->preload_block_format, 10, 13) |
3979            __gen_uint(values->preload_msaa, 14, 15);
3980   cl[ 3] = __gen_uint(values->yuv.conv_k1, 0, 7) |
3981            __gen_uint(values->yuv.conv_k2, 8, 15) |
3982            __gen_uint(values->yuv.conv_k3, 16, 23) |
3983            __gen_uint(values->yuv.conv_k4, 24, 31);
3984   cl[ 4] = __gen_uint(values->yuv.plane_0_base, 0, 63) |
3985            __gen_uint(values->afbc.header, 0, 63);
3986   cl[ 5] = __gen_uint(values->yuv.plane_0_base, 0, 63) >> 32 |
3987            __gen_uint(values->afbc.header, 0, 63) >> 32;
3988   cl[ 6] = __gen_uint(values->yuv.plane_1_base, 0, 63) |
3989            __gen_uint(values->afbc.row_stride, 0, 12);
3990   cl[ 7] = __gen_uint(values->yuv.plane_1_base, 0, 63) >> 32 |
3991            __gen_uint(values->afbc.chunk_size, 0, 11) |
3992            __gen_uint(values->afbc.sparse, 16, 16) |
3993            __gen_uint(values->afbc.yuv_transform_enable, 17, 17);
3994   cl[ 8] = __gen_uint(values->yuv.plane_2_base, 0, 63) |
3995            __gen_uint(values->afbc.body, 0, 63) |
3996            __gen_uint(values->rgb.base, 0, 63);
3997   cl[ 9] = __gen_uint(values->yuv.plane_2_base, 0, 63) >> 32 |
3998            __gen_uint(values->afbc.body, 0, 63) >> 32 |
3999            __gen_uint(values->rgb.base, 0, 63) >> 32;
4000   cl[10] = __gen_uint(values->yuv.plane_0_stride, 0, 31) |
4001            __gen_uint(values->afbc.body_size, 0, 31) |
4002            __gen_uint(values->rgb.row_stride, 0, 31);
4003   cl[11] = __gen_uint(values->yuv.plane_1_2_stride, 0, 31) |
4004            __gen_uint(values->rgb.surface_stride, 0, 31);
4005   cl[12] = __gen_uint(values->preload_buffer.base, 0, 63) |
4006            __gen_uint(values->clear.color_0, 0, 31);
4007   cl[13] = __gen_uint(values->preload_buffer.base, 0, 63) >> 32 |
4008            __gen_uint(values->clear.color_1, 0, 31);
4009   cl[14] = __gen_uint(values->preload_buffer.row_stride, 0, 31) |
4010            __gen_uint(values->clear.color_2, 0, 31);
4011   cl[15] = __gen_uint(values->preload_buffer.surface_stride, 0, 31) |
4012            __gen_uint(values->clear.color_3, 0, 31);
4013}
4014
4015
4016#define MALI_RENDER_TARGET_LENGTH 64
4017#define MALI_RENDER_TARGET_ALIGN 64
4018struct mali_render_target_packed { uint32_t opaque[16]; };
4019static inline void
4020MALI_RENDER_TARGET_unpack(const uint8_t * restrict cl,
4021                          struct MALI_RENDER_TARGET * restrict values)
4022{
4023   if (((const uint32_t *) cl)[0] & 0x2ff000f) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 0\n");
4024   if (((const uint32_t *) cl)[1] & 0x10000006) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 1\n");
4025   if (((const uint32_t *) cl)[2] & 0x70000004) fprintf(stderr, "XXX: Invalid field of Render Target unpacked at word 2\n");
4026   values->yuv.conv_k5 = __gen_unpack_uint(cl, 80, 87);
4027   values->yuv.conv_k6 = (enum mali_yuv_conv_k6)__gen_unpack_uint(cl, 88, 88);
4028   values->yuv.conv_k7_clamp = (enum mali_yuv_conv_k7_clamp)__gen_unpack_uint(cl, 89, 90);
4029   values->yuv.conv_k8 = (enum mali_yuv_conv_k8)__gen_unpack_uint(cl, 91, 91);
4030   values->yuv.conv_disable = __gen_unpack_uint(cl, 95, 95);
4031   values->yuv.conv_k1 = __gen_unpack_uint(cl, 96, 103);
4032   values->yuv.conv_k2 = __gen_unpack_uint(cl, 104, 111);
4033   values->yuv.conv_k3 = __gen_unpack_uint(cl, 112, 119);
4034   values->yuv.conv_k4 = __gen_unpack_uint(cl, 120, 127);
4035   values->yuv.plane_0_base = __gen_unpack_uint(cl, 128, 191);
4036   values->yuv.plane_1_base = __gen_unpack_uint(cl, 192, 255);
4037   values->yuv.plane_2_base = __gen_unpack_uint(cl, 256, 319);
4038   values->yuv.plane_0_stride = __gen_unpack_uint(cl, 320, 351);
4039   values->yuv.plane_1_2_stride = __gen_unpack_uint(cl, 352, 383);
4040   values->afbc.header = __gen_unpack_uint(cl, 128, 191);
4041   values->afbc.row_stride = __gen_unpack_uint(cl, 192, 204);
4042   values->afbc.chunk_size = __gen_unpack_uint(cl, 224, 235);
4043   values->afbc.sparse = __gen_unpack_uint(cl, 240, 240);
4044   values->afbc.yuv_transform_enable = __gen_unpack_uint(cl, 241, 241);
4045   values->afbc.body = __gen_unpack_uint(cl, 256, 319);
4046   values->afbc.body_size = __gen_unpack_uint(cl, 320, 351);
4047   values->internal_buffer_offset = __gen_unpack_uint(cl, 4, 15) << 4;
4048   values->yuv_enable = __gen_unpack_uint(cl, 24, 24);
4049   values->internal_format = (enum mali_color_buffer_internal_format)__gen_unpack_uint(cl, 26, 31);
4050   values->write_enable = __gen_unpack_uint(cl, 32, 32);
4051   values->writeback_format = (enum mali_color_format)__gen_unpack_uint(cl, 35, 39);
4052   values->writeback_endianness = (enum mali_rt_endianness)__gen_unpack_uint(cl, 40, 41);
4053   values->writeback_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 42, 43);
4054   values->writeback_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 44, 45);
4055   values->srgb = __gen_unpack_uint(cl, 46, 46);
4056   values->dithering_enable = __gen_unpack_uint(cl, 47, 47);
4057   values->swizzle = __gen_unpack_uint(cl, 48, 59);
4058   values->writeback_sampling_mode = (enum mali_downsampling_accumulation_mode)__gen_unpack_uint(cl, 61, 62);
4059   values->clean_pixel_write_enable = __gen_unpack_uint(cl, 63, 63);
4060   values->preload_enable = __gen_unpack_uint(cl, 64, 64);
4061   values->unload_enable = __gen_unpack_uint(cl, 65, 65);
4062   values->preload_format = (enum mali_color_format)__gen_unpack_uint(cl, 67, 71);
4063   values->preload_endianness = (enum mali_rt_endianness)__gen_unpack_uint(cl, 72, 73);
4064   values->preload_block_format = (enum mali_block_format)__gen_unpack_uint(cl, 74, 77);
4065   values->preload_msaa = (enum mali_msaa)__gen_unpack_uint(cl, 78, 79);
4066   values->rgb.base = __gen_unpack_uint(cl, 256, 319);
4067   values->rgb.row_stride = __gen_unpack_uint(cl, 320, 351);
4068   values->rgb.surface_stride = __gen_unpack_uint(cl, 352, 383);
4069   values->preload_buffer.base = __gen_unpack_uint(cl, 384, 447);
4070   values->preload_buffer.row_stride = __gen_unpack_uint(cl, 448, 479);
4071   values->preload_buffer.surface_stride = __gen_unpack_uint(cl, 480, 511);
4072   values->clear.color_0 = __gen_unpack_uint(cl, 384, 415);
4073   values->clear.color_1 = __gen_unpack_uint(cl, 416, 447);
4074   values->clear.color_2 = __gen_unpack_uint(cl, 448, 479);
4075   values->clear.color_3 = __gen_unpack_uint(cl, 480, 511);
4076}
4077
4078static inline void
4079MALI_RENDER_TARGET_print(FILE *fp, const struct MALI_RENDER_TARGET * values, unsigned indent)
4080{
4081   fprintf(fp, "%*sYUV:\n", indent, "");
4082   MALI_RENDER_TARGET_YUV_OVERLAY_print(fp, &values->yuv, indent + 2);
4083   fprintf(fp, "%*sAFBC:\n", indent, "");
4084   MALI_RENDER_TARGET_AFBC_OVERLAY_print(fp, &values->afbc, indent + 2);
4085   fprintf(fp, "%*sInternal Buffer Offset: %u\n", indent, "", values->internal_buffer_offset);
4086   fprintf(fp, "%*sYUV Enable: %s\n", indent, "", values->yuv_enable ? "true" : "false");
4087   fprintf(fp, "%*sInternal Format: %s\n", indent, "", mali_color_buffer_internal_format_as_str(values->internal_format));
4088   fprintf(fp, "%*sWrite Enable: %s\n", indent, "", values->write_enable ? "true" : "false");
4089   fprintf(fp, "%*sWriteback Format: %s\n", indent, "", mali_color_format_as_str(values->writeback_format));
4090   fprintf(fp, "%*sWriteback Endianness: %s\n", indent, "", mali_rt_endianness_as_str(values->writeback_endianness));
4091   fprintf(fp, "%*sWriteback Block Format: %s\n", indent, "", mali_block_format_as_str(values->writeback_block_format));
4092   fprintf(fp, "%*sWriteback MSAA: %s\n", indent, "", mali_msaa_as_str(values->writeback_msaa));
4093   fprintf(fp, "%*ssRGB: %s\n", indent, "", values->srgb ? "true" : "false");
4094   fprintf(fp, "%*sDithering Enable: %s\n", indent, "", values->dithering_enable ? "true" : "false");
4095   fprintf(fp, "%*sSwizzle: %u\n", indent, "", values->swizzle);
4096   fprintf(fp, "%*sWriteback Sampling Mode: %s\n", indent, "", mali_downsampling_accumulation_mode_as_str(values->writeback_sampling_mode));
4097   fprintf(fp, "%*sClean Pixel Write Enable: %s\n", indent, "", values->clean_pixel_write_enable ? "true" : "false");
4098   fprintf(fp, "%*sPreload Enable: %s\n", indent, "", values->preload_enable ? "true" : "false");
4099   fprintf(fp, "%*sUnload Enable: %s\n", indent, "", values->unload_enable ? "true" : "false");
4100   fprintf(fp, "%*sPreload Format: %s\n", indent, "", mali_color_format_as_str(values->preload_format));
4101   fprintf(fp, "%*sPreload Endianness: %s\n", indent, "", mali_rt_endianness_as_str(values->preload_endianness));
4102   fprintf(fp, "%*sPreload Block Format: %s\n", indent, "", mali_block_format_as_str(values->preload_block_format));
4103   fprintf(fp, "%*sPreload MSAA: %s\n", indent, "", mali_msaa_as_str(values->preload_msaa));
4104   fprintf(fp, "%*sRGB:\n", indent, "");
4105   MALI_RT_BUFFER_print(fp, &values->rgb, indent + 2);
4106   fprintf(fp, "%*sPreload buffer:\n", indent, "");
4107   MALI_RT_BUFFER_print(fp, &values->preload_buffer, indent + 2);
4108   fprintf(fp, "%*sClear:\n", indent, "");
4109   MALI_RT_CLEAR_print(fp, &values->clear, indent + 2);
4110}
4111
4112struct mali_framebuffer_packed {
4113   uint32_t opaque[32];
4114};
4115
4116#define MALI_FRAMEBUFFER_LENGTH 128
4117#define MALI_FRAMEBUFFER_ALIGN 64
4118#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_TYPE struct MALI_LOCAL_STORAGE
4119#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_header MALI_LOCAL_STORAGE_header
4120#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_pack MALI_LOCAL_STORAGE_pack
4121#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_unpack MALI_LOCAL_STORAGE_unpack
4122#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_print MALI_LOCAL_STORAGE_print
4123#define MALI_FRAMEBUFFER_SECTION_LOCAL_STORAGE_OFFSET 0
4124#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_TYPE struct MALI_FRAMEBUFFER_PARAMETERS
4125#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_header MALI_FRAMEBUFFER_PARAMETERS_header
4126#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_pack MALI_FRAMEBUFFER_PARAMETERS_pack
4127#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_unpack MALI_FRAMEBUFFER_PARAMETERS_unpack
4128#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_print MALI_FRAMEBUFFER_PARAMETERS_print
4129#define MALI_FRAMEBUFFER_SECTION_PARAMETERS_OFFSET 32
4130#define MALI_FRAMEBUFFER_SECTION_TILER_TYPE struct MALI_TILER_CONTEXT
4131#define MALI_FRAMEBUFFER_SECTION_TILER_header MALI_TILER_CONTEXT_header
4132#define MALI_FRAMEBUFFER_SECTION_TILER_pack MALI_TILER_CONTEXT_pack
4133#define MALI_FRAMEBUFFER_SECTION_TILER_unpack MALI_TILER_CONTEXT_unpack
4134#define MALI_FRAMEBUFFER_SECTION_TILER_print MALI_TILER_CONTEXT_print
4135#define MALI_FRAMEBUFFER_SECTION_TILER_OFFSET 56
4136#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_TYPE struct MALI_TILER_WEIGHTS
4137#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_header MALI_TILER_WEIGHTS_header
4138#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_pack MALI_TILER_WEIGHTS_pack
4139#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_unpack MALI_TILER_WEIGHTS_unpack
4140#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_print MALI_TILER_WEIGHTS_print
4141#define MALI_FRAMEBUFFER_SECTION_TILER_WEIGHTS_OFFSET 96
4142
4143struct MALI_JOB_HEADER {
4144   uint32_t                             exception_status;
4145   uint32_t                             first_incomplete_task;
4146   uint64_t                             fault_pointer;
4147   bool                                 is_64b;
4148   enum mali_job_type                   type;
4149   bool                                 barrier;
4150   bool                                 invalidate_cache;
4151   bool                                 suppress_prefetch;
4152   bool                                 enable_texture_mapper;
4153   bool                                 relax_dependency_1;
4154   bool                                 relax_dependency_2;
4155   uint32_t                             index;
4156   uint32_t                             dependency_1;
4157   uint32_t                             dependency_2;
4158   uint64_t                             next;
4159};
4160
4161#define MALI_JOB_HEADER_header                  \
4162   .is_64b = true
4163
4164static inline void
4165MALI_JOB_HEADER_pack(uint32_t * restrict cl,
4166                     const struct MALI_JOB_HEADER * restrict values)
4167{
4168   cl[ 0] = __gen_uint(values->exception_status, 0, 31);
4169   cl[ 1] = __gen_uint(values->first_incomplete_task, 0, 31);
4170   cl[ 2] = __gen_uint(values->fault_pointer, 0, 63);
4171   cl[ 3] = __gen_uint(values->fault_pointer, 0, 63) >> 32;
4172   cl[ 4] = __gen_uint(values->is_64b, 0, 0) |
4173            __gen_uint(values->type, 1, 7) |
4174            __gen_uint(values->barrier, 8, 8) |
4175            __gen_uint(values->invalidate_cache, 9, 9) |
4176            __gen_uint(values->suppress_prefetch, 11, 11) |
4177            __gen_uint(values->enable_texture_mapper, 12, 12) |
4178            __gen_uint(values->relax_dependency_1, 14, 14) |
4179            __gen_uint(values->relax_dependency_2, 15, 15) |
4180            __gen_uint(values->index, 16, 31);
4181   cl[ 5] = __gen_uint(values->dependency_1, 0, 15) |
4182            __gen_uint(values->dependency_2, 16, 31);
4183   cl[ 6] = __gen_uint(values->next, 0, 63);
4184   cl[ 7] = __gen_uint(values->next, 0, 63) >> 32;
4185}
4186
4187
4188#define MALI_JOB_HEADER_LENGTH 32
4189#define MALI_JOB_HEADER_ALIGN 64
4190struct mali_job_header_packed { uint32_t opaque[8]; };
4191static inline void
4192MALI_JOB_HEADER_unpack(const uint8_t * restrict cl,
4193                       struct MALI_JOB_HEADER * restrict values)
4194{
4195   if (((const uint32_t *) cl)[4] & 0x2400) fprintf(stderr, "XXX: Invalid field of Job Header unpacked at word 4\n");
4196   values->exception_status = __gen_unpack_uint(cl, 0, 31);
4197   values->first_incomplete_task = __gen_unpack_uint(cl, 32, 63);
4198   values->fault_pointer = __gen_unpack_uint(cl, 64, 127);
4199   values->is_64b = __gen_unpack_uint(cl, 128, 128);
4200   values->type = (enum mali_job_type)__gen_unpack_uint(cl, 129, 135);
4201   values->barrier = __gen_unpack_uint(cl, 136, 136);
4202   values->invalidate_cache = __gen_unpack_uint(cl, 137, 137);
4203   values->suppress_prefetch = __gen_unpack_uint(cl, 139, 139);
4204   values->enable_texture_mapper = __gen_unpack_uint(cl, 140, 140);
4205   values->relax_dependency_1 = __gen_unpack_uint(cl, 142, 142);
4206   values->relax_dependency_2 = __gen_unpack_uint(cl, 143, 143);
4207   values->index = __gen_unpack_uint(cl, 144, 159);
4208   values->dependency_1 = __gen_unpack_uint(cl, 160, 175);
4209   values->dependency_2 = __gen_unpack_uint(cl, 176, 191);
4210   values->next = __gen_unpack_uint(cl, 192, 255);
4211}
4212
4213static inline void
4214MALI_JOB_HEADER_print(FILE *fp, const struct MALI_JOB_HEADER * values, unsigned indent)
4215{
4216   fprintf(fp, "%*sException Status: %u\n", indent, "", values->exception_status);
4217   fprintf(fp, "%*sFirst Incomplete Task: %u\n", indent, "", values->first_incomplete_task);
4218   fprintf(fp, "%*sFault Pointer: 0x%" PRIx64 "\n", indent, "", values->fault_pointer);
4219   fprintf(fp, "%*sIs 64b: %s\n", indent, "", values->is_64b ? "true" : "false");
4220   fprintf(fp, "%*sType: %s\n", indent, "", mali_job_type_as_str(values->type));
4221   fprintf(fp, "%*sBarrier: %s\n", indent, "", values->barrier ? "true" : "false");
4222   fprintf(fp, "%*sInvalidate Cache: %s\n", indent, "", values->invalidate_cache ? "true" : "false");
4223   fprintf(fp, "%*sSuppress Prefetch: %s\n", indent, "", values->suppress_prefetch ? "true" : "false");
4224   fprintf(fp, "%*sEnable Texture Mapper: %s\n", indent, "", values->enable_texture_mapper ? "true" : "false");
4225   fprintf(fp, "%*sRelax Dependency 1: %s\n", indent, "", values->relax_dependency_1 ? "true" : "false");
4226   fprintf(fp, "%*sRelax Dependency 2: %s\n", indent, "", values->relax_dependency_2 ? "true" : "false");
4227   fprintf(fp, "%*sIndex: %u\n", indent, "", values->index);
4228   fprintf(fp, "%*sDependency 1: %u\n", indent, "", values->dependency_1);
4229   fprintf(fp, "%*sDependency 2: %u\n", indent, "", values->dependency_2);
4230   fprintf(fp, "%*sNext: 0x%" PRIx64 "\n", indent, "", values->next);
4231}
4232
4233struct MALI_FRAGMENT_JOB_PAYLOAD {
4234   uint32_t                             bound_min_x;
4235   uint32_t                             bound_min_y;
4236   uint32_t                             bound_max_x;
4237   uint32_t                             bound_max_y;
4238   bool                                 has_tile_enable_map;
4239   uint64_t                             framebuffer;
4240   uint64_t                             tile_enable_map;
4241   uint32_t                             tile_enable_map_row_stride;
4242};
4243
4244#define MALI_FRAGMENT_JOB_PAYLOAD_header        \
4245   0
4246
4247static inline void
4248MALI_FRAGMENT_JOB_PAYLOAD_pack(uint32_t * restrict cl,
4249                               const struct MALI_FRAGMENT_JOB_PAYLOAD * restrict values)
4250{
4251   cl[ 0] = __gen_uint(values->bound_min_x, 0, 11) |
4252            __gen_uint(values->bound_min_y, 16, 27);
4253   cl[ 1] = __gen_uint(values->bound_max_x, 0, 11) |
4254            __gen_uint(values->bound_max_y, 16, 27) |
4255            __gen_uint(values->has_tile_enable_map, 31, 31);
4256   cl[ 2] = __gen_uint(values->framebuffer, 0, 63);
4257   cl[ 3] = __gen_uint(values->framebuffer, 0, 63) >> 32;
4258   cl[ 4] = __gen_uint(values->tile_enable_map, 0, 63);
4259   cl[ 5] = __gen_uint(values->tile_enable_map, 0, 63) >> 32;
4260   cl[ 6] = __gen_uint(values->tile_enable_map_row_stride, 0, 7);
4261   cl[ 7] = 0;
4262}
4263
4264
4265#define MALI_FRAGMENT_JOB_PAYLOAD_LENGTH 32
4266struct mali_fragment_job_payload_packed { uint32_t opaque[8]; };
4267static inline void
4268MALI_FRAGMENT_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
4269                                 struct MALI_FRAGMENT_JOB_PAYLOAD * restrict values)
4270{
4271   if (((const uint32_t *) cl)[0] & 0xf000f000) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 0\n");
4272   if (((const uint32_t *) cl)[1] & 0x7000f000) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 1\n");
4273   if (((const uint32_t *) cl)[6] & 0xffffff00) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 6\n");
4274   if (((const uint32_t *) cl)[7] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Fragment Job Payload unpacked at word 7\n");
4275   values->bound_min_x = __gen_unpack_uint(cl, 0, 11);
4276   values->bound_min_y = __gen_unpack_uint(cl, 16, 27);
4277   values->bound_max_x = __gen_unpack_uint(cl, 32, 43);
4278   values->bound_max_y = __gen_unpack_uint(cl, 48, 59);
4279   values->has_tile_enable_map = __gen_unpack_uint(cl, 63, 63);
4280   values->framebuffer = __gen_unpack_uint(cl, 64, 127);
4281   values->tile_enable_map = __gen_unpack_uint(cl, 128, 191);
4282   values->tile_enable_map_row_stride = __gen_unpack_uint(cl, 192, 199);
4283}
4284
4285static inline void
4286MALI_FRAGMENT_JOB_PAYLOAD_print(FILE *fp, const struct MALI_FRAGMENT_JOB_PAYLOAD * values, unsigned indent)
4287{
4288   fprintf(fp, "%*sBound Min X: %u\n", indent, "", values->bound_min_x);
4289   fprintf(fp, "%*sBound Min Y: %u\n", indent, "", values->bound_min_y);
4290   fprintf(fp, "%*sBound Max X: %u\n", indent, "", values->bound_max_x);
4291   fprintf(fp, "%*sBound Max Y: %u\n", indent, "", values->bound_max_y);
4292   fprintf(fp, "%*sHas Tile Enable Map: %s\n", indent, "", values->has_tile_enable_map ? "true" : "false");
4293   fprintf(fp, "%*sFramebuffer: 0x%" PRIx64 "\n", indent, "", values->framebuffer);
4294   fprintf(fp, "%*sTile Enable Map: 0x%" PRIx64 "\n", indent, "", values->tile_enable_map);
4295   fprintf(fp, "%*sTile Enable Map Row Stride: %u\n", indent, "", values->tile_enable_map_row_stride);
4296}
4297
4298struct mali_fragment_job_packed {
4299   uint32_t opaque[16];
4300};
4301
4302#define MALI_FRAGMENT_JOB_LENGTH 64
4303#define MALI_FRAGMENT_JOB_ALIGN 64
4304#define MALI_FRAGMENT_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
4305#define MALI_FRAGMENT_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
4306#define MALI_FRAGMENT_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
4307#define MALI_FRAGMENT_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
4308#define MALI_FRAGMENT_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
4309#define MALI_FRAGMENT_JOB_SECTION_HEADER_OFFSET 0
4310#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_TYPE struct MALI_FRAGMENT_JOB_PAYLOAD
4311#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_header MALI_FRAGMENT_JOB_PAYLOAD_header
4312#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_pack MALI_FRAGMENT_JOB_PAYLOAD_pack
4313#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_unpack MALI_FRAGMENT_JOB_PAYLOAD_unpack
4314#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_print MALI_FRAGMENT_JOB_PAYLOAD_print
4315#define MALI_FRAGMENT_JOB_SECTION_PAYLOAD_OFFSET 32
4316
4317enum mali_write_value_type {
4318        MALI_WRITE_VALUE_TYPE_CYCLE_COUNTER  =      1,
4319        MALI_WRITE_VALUE_TYPE_SYSTEM_TIMESTAMP =      2,
4320        MALI_WRITE_VALUE_TYPE_ZERO           =      3,
4321};
4322
4323static inline const char *
4324mali_write_value_type_as_str(enum mali_write_value_type imm)
4325{
4326    switch (imm) {
4327    case MALI_WRITE_VALUE_TYPE_CYCLE_COUNTER: return "Cycle Counter";
4328    case MALI_WRITE_VALUE_TYPE_SYSTEM_TIMESTAMP: return "System Timestamp";
4329    case MALI_WRITE_VALUE_TYPE_ZERO: return "Zero";
4330    default: return "XXX: INVALID";
4331    }
4332}
4333
4334struct MALI_WRITE_VALUE_JOB_PAYLOAD {
4335   uint64_t                             address;
4336   enum mali_write_value_type           type;
4337};
4338
4339#define MALI_WRITE_VALUE_JOB_PAYLOAD_header     \
4340   0
4341
4342static inline void
4343MALI_WRITE_VALUE_JOB_PAYLOAD_pack(uint32_t * restrict cl,
4344                                  const struct MALI_WRITE_VALUE_JOB_PAYLOAD * restrict values)
4345{
4346   cl[ 0] = __gen_uint(values->address, 0, 63);
4347   cl[ 1] = __gen_uint(values->address, 0, 63) >> 32;
4348   cl[ 2] = __gen_uint(values->type, 0, 31);
4349}
4350
4351
4352#define MALI_WRITE_VALUE_JOB_PAYLOAD_LENGTH 12
4353struct mali_write_value_job_payload_packed { uint32_t opaque[3]; };
4354static inline void
4355MALI_WRITE_VALUE_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
4356                                    struct MALI_WRITE_VALUE_JOB_PAYLOAD * restrict values)
4357{
4358   values->address = __gen_unpack_uint(cl, 0, 63);
4359   values->type = (enum mali_write_value_type)__gen_unpack_uint(cl, 64, 95);
4360}
4361
4362static inline void
4363MALI_WRITE_VALUE_JOB_PAYLOAD_print(FILE *fp, const struct MALI_WRITE_VALUE_JOB_PAYLOAD * values, unsigned indent)
4364{
4365   fprintf(fp, "%*sAddress: 0x%" PRIx64 "\n", indent, "", values->address);
4366   fprintf(fp, "%*sType: %s\n", indent, "", mali_write_value_type_as_str(values->type));
4367}
4368
4369struct MALI_CACHE_FLUSH_JOB_PAYLOAD {
4370   bool                                 clean_shader_core_ls;
4371   bool                                 invalidate_shader_core_ls;
4372   bool                                 invalidate_shader_core_other;
4373   bool                                 job_manager_clean;
4374   bool                                 job_manager_invalidate;
4375   bool                                 tiler_clean;
4376   bool                                 tiler_invalidate;
4377   bool                                 l2_clean;
4378   bool                                 l2_invalidate;
4379};
4380
4381#define MALI_CACHE_FLUSH_JOB_PAYLOAD_header     \
4382   0
4383
4384static inline void
4385MALI_CACHE_FLUSH_JOB_PAYLOAD_pack(uint32_t * restrict cl,
4386                                  const struct MALI_CACHE_FLUSH_JOB_PAYLOAD * restrict values)
4387{
4388   cl[ 0] = __gen_uint(values->clean_shader_core_ls, 0, 0) |
4389            __gen_uint(values->invalidate_shader_core_ls, 1, 1) |
4390            __gen_uint(values->invalidate_shader_core_other, 2, 2) |
4391            __gen_uint(values->job_manager_clean, 16, 16) |
4392            __gen_uint(values->job_manager_invalidate, 17, 17) |
4393            __gen_uint(values->tiler_clean, 24, 24) |
4394            __gen_uint(values->tiler_invalidate, 25, 25);
4395   cl[ 1] = __gen_uint(values->l2_clean, 0, 0) |
4396            __gen_uint(values->l2_invalidate, 1, 1);
4397}
4398
4399
4400#define MALI_CACHE_FLUSH_JOB_PAYLOAD_LENGTH 8
4401struct mali_cache_flush_job_payload_packed { uint32_t opaque[2]; };
4402static inline void
4403MALI_CACHE_FLUSH_JOB_PAYLOAD_unpack(const uint8_t * restrict cl,
4404                                    struct MALI_CACHE_FLUSH_JOB_PAYLOAD * restrict values)
4405{
4406   if (((const uint32_t *) cl)[0] & 0xfcfcfff8) fprintf(stderr, "XXX: Invalid field of Cache Flush Job Payload unpacked at word 0\n");
4407   if (((const uint32_t *) cl)[1] & 0xfffffffc) fprintf(stderr, "XXX: Invalid field of Cache Flush Job Payload unpacked at word 1\n");
4408   values->clean_shader_core_ls = __gen_unpack_uint(cl, 0, 0);
4409   values->invalidate_shader_core_ls = __gen_unpack_uint(cl, 1, 1);
4410   values->invalidate_shader_core_other = __gen_unpack_uint(cl, 2, 2);
4411   values->job_manager_clean = __gen_unpack_uint(cl, 16, 16);
4412   values->job_manager_invalidate = __gen_unpack_uint(cl, 17, 17);
4413   values->tiler_clean = __gen_unpack_uint(cl, 24, 24);
4414   values->tiler_invalidate = __gen_unpack_uint(cl, 25, 25);
4415   values->l2_clean = __gen_unpack_uint(cl, 32, 32);
4416   values->l2_invalidate = __gen_unpack_uint(cl, 33, 33);
4417}
4418
4419static inline void
4420MALI_CACHE_FLUSH_JOB_PAYLOAD_print(FILE *fp, const struct MALI_CACHE_FLUSH_JOB_PAYLOAD * values, unsigned indent)
4421{
4422   fprintf(fp, "%*sClean Shader Core LS: %s\n", indent, "", values->clean_shader_core_ls ? "true" : "false");
4423   fprintf(fp, "%*sInvalidate Shader Core LS: %s\n", indent, "", values->invalidate_shader_core_ls ? "true" : "false");
4424   fprintf(fp, "%*sInvalidate Shader Core Other: %s\n", indent, "", values->invalidate_shader_core_other ? "true" : "false");
4425   fprintf(fp, "%*sJob Manager Clean: %s\n", indent, "", values->job_manager_clean ? "true" : "false");
4426   fprintf(fp, "%*sJob Manager Invalidate: %s\n", indent, "", values->job_manager_invalidate ? "true" : "false");
4427   fprintf(fp, "%*sTiler Clean: %s\n", indent, "", values->tiler_clean ? "true" : "false");
4428   fprintf(fp, "%*sTiler Invalidate: %s\n", indent, "", values->tiler_invalidate ? "true" : "false");
4429   fprintf(fp, "%*sL2 Clean: %s\n", indent, "", values->l2_clean ? "true" : "false");
4430   fprintf(fp, "%*sL2 Invalidate: %s\n", indent, "", values->l2_invalidate ? "true" : "false");
4431}
4432
4433struct mali_write_value_job_packed {
4434   uint32_t opaque[11];
4435};
4436
4437#define MALI_WRITE_VALUE_JOB_LENGTH 44
4438#define MALI_WRITE_VALUE_JOB_ALIGN 64
4439#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
4440#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
4441#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
4442#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
4443#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
4444#define MALI_WRITE_VALUE_JOB_SECTION_HEADER_OFFSET 0
4445#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_TYPE struct MALI_WRITE_VALUE_JOB_PAYLOAD
4446#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_header MALI_WRITE_VALUE_JOB_PAYLOAD_header
4447#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_pack MALI_WRITE_VALUE_JOB_PAYLOAD_pack
4448#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_unpack MALI_WRITE_VALUE_JOB_PAYLOAD_unpack
4449#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_print MALI_WRITE_VALUE_JOB_PAYLOAD_print
4450#define MALI_WRITE_VALUE_JOB_SECTION_PAYLOAD_OFFSET 32
4451
4452struct mali_cache_flush_job_packed {
4453   uint32_t opaque[10];
4454};
4455
4456#define MALI_CACHE_FLUSH_JOB_LENGTH 40
4457#define MALI_CACHE_FLUSH_JOB_ALIGN 64
4458#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
4459#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
4460#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
4461#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
4462#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
4463#define MALI_CACHE_FLUSH_JOB_SECTION_HEADER_OFFSET 0
4464#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_TYPE struct MALI_CACHE_FLUSH_JOB_PAYLOAD
4465#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_header MALI_CACHE_FLUSH_JOB_PAYLOAD_header
4466#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_pack MALI_CACHE_FLUSH_JOB_PAYLOAD_pack
4467#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_unpack MALI_CACHE_FLUSH_JOB_PAYLOAD_unpack
4468#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_print MALI_CACHE_FLUSH_JOB_PAYLOAD_print
4469#define MALI_CACHE_FLUSH_JOB_SECTION_PAYLOAD_OFFSET 32
4470
4471struct MALI_COMPUTE_JOB_PARAMETERS {
4472   uint32_t                             job_task_split;
4473};
4474
4475#define MALI_COMPUTE_JOB_PARAMETERS_header      \
4476   0
4477
4478static inline void
4479MALI_COMPUTE_JOB_PARAMETERS_pack(uint32_t * restrict cl,
4480                                 const struct MALI_COMPUTE_JOB_PARAMETERS * restrict values)
4481{
4482   cl[ 0] = __gen_uint(values->job_task_split, 26, 29);
4483   cl[ 1] = 0;
4484   cl[ 2] = 0;
4485   cl[ 3] = 0;
4486   cl[ 4] = 0;
4487   cl[ 5] = 0;
4488}
4489
4490
4491#define MALI_COMPUTE_JOB_PARAMETERS_LENGTH 24
4492struct mali_compute_job_parameters_packed { uint32_t opaque[6]; };
4493static inline void
4494MALI_COMPUTE_JOB_PARAMETERS_unpack(const uint8_t * restrict cl,
4495                                   struct MALI_COMPUTE_JOB_PARAMETERS * restrict values)
4496{
4497   if (((const uint32_t *) cl)[0] & 0xc3ffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 0\n");
4498   if (((const uint32_t *) cl)[1] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 1\n");
4499   if (((const uint32_t *) cl)[2] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 2\n");
4500   if (((const uint32_t *) cl)[3] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 3\n");
4501   if (((const uint32_t *) cl)[4] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 4\n");
4502   if (((const uint32_t *) cl)[5] & 0xffffffff) fprintf(stderr, "XXX: Invalid field of Compute Job Parameters unpacked at word 5\n");
4503   values->job_task_split = __gen_unpack_uint(cl, 26, 29);
4504}
4505
4506static inline void
4507MALI_COMPUTE_JOB_PARAMETERS_print(FILE *fp, const struct MALI_COMPUTE_JOB_PARAMETERS * values, unsigned indent)
4508{
4509   fprintf(fp, "%*sJob Task Split: %u\n", indent, "", values->job_task_split);
4510}
4511
4512struct mali_compute_job_packed {
4513   uint32_t opaque[46];
4514};
4515
4516#define MALI_COMPUTE_JOB_LENGTH 184
4517#define MALI_COMPUTE_JOB_ALIGN 64
4518#define MALI_COMPUTE_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
4519#define MALI_COMPUTE_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
4520#define MALI_COMPUTE_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
4521#define MALI_COMPUTE_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
4522#define MALI_COMPUTE_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
4523#define MALI_COMPUTE_JOB_SECTION_HEADER_OFFSET 0
4524#define MALI_COMPUTE_JOB_SECTION_INVOCATION_TYPE struct MALI_INVOCATION
4525#define MALI_COMPUTE_JOB_SECTION_INVOCATION_header MALI_INVOCATION_header
4526#define MALI_COMPUTE_JOB_SECTION_INVOCATION_pack MALI_INVOCATION_pack
4527#define MALI_COMPUTE_JOB_SECTION_INVOCATION_unpack MALI_INVOCATION_unpack
4528#define MALI_COMPUTE_JOB_SECTION_INVOCATION_print MALI_INVOCATION_print
4529#define MALI_COMPUTE_JOB_SECTION_INVOCATION_OFFSET 32
4530#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_TYPE struct MALI_COMPUTE_JOB_PARAMETERS
4531#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_header MALI_COMPUTE_JOB_PARAMETERS_header
4532#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_pack MALI_COMPUTE_JOB_PARAMETERS_pack
4533#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_unpack MALI_COMPUTE_JOB_PARAMETERS_unpack
4534#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_print MALI_COMPUTE_JOB_PARAMETERS_print
4535#define MALI_COMPUTE_JOB_SECTION_PARAMETERS_OFFSET 40
4536#define MALI_COMPUTE_JOB_SECTION_DRAW_TYPE struct MALI_DRAW
4537#define MALI_COMPUTE_JOB_SECTION_DRAW_header MALI_DRAW_header
4538#define MALI_COMPUTE_JOB_SECTION_DRAW_pack MALI_DRAW_pack
4539#define MALI_COMPUTE_JOB_SECTION_DRAW_unpack MALI_DRAW_unpack
4540#define MALI_COMPUTE_JOB_SECTION_DRAW_print MALI_DRAW_print
4541#define MALI_COMPUTE_JOB_SECTION_DRAW_OFFSET 64
4542
4543struct MALI_PRIMITIVE_SIZE {
4544   float                                constant;
4545   uint64_t                             size_array;
4546};
4547
4548#define MALI_PRIMITIVE_SIZE_header              \
4549   0
4550
4551static inline void
4552MALI_PRIMITIVE_SIZE_pack(uint32_t * restrict cl,
4553                         const struct MALI_PRIMITIVE_SIZE * restrict values)
4554{
4555   cl[ 0] = __gen_uint(fui(values->constant), 0, 32) |
4556            __gen_uint(values->size_array, 0, 63);
4557   cl[ 1] = __gen_uint(values->size_array, 0, 63) >> 32;
4558}
4559
4560
4561#define MALI_PRIMITIVE_SIZE_LENGTH 8
4562struct mali_primitive_size_packed { uint32_t opaque[2]; };
4563static inline void
4564MALI_PRIMITIVE_SIZE_unpack(const uint8_t * restrict cl,
4565                           struct MALI_PRIMITIVE_SIZE * restrict values)
4566{
4567   values->constant = __gen_unpack_float(cl, 0, 31);
4568   values->size_array = __gen_unpack_uint(cl, 0, 63);
4569}
4570
4571static inline void
4572MALI_PRIMITIVE_SIZE_print(FILE *fp, const struct MALI_PRIMITIVE_SIZE * values, unsigned indent)
4573{
4574   fprintf(fp, "%*sConstant: %f\n", indent, "", values->constant);
4575   fprintf(fp, "%*sSize Array: 0x%" PRIx64 "\n", indent, "", values->size_array);
4576}
4577
4578struct mali_tiler_job_packed {
4579   uint32_t opaque[48];
4580};
4581
4582#define MALI_TILER_JOB_LENGTH 192
4583#define MALI_TILER_JOB_ALIGN 64
4584#define MALI_TILER_JOB_SECTION_HEADER_TYPE struct MALI_JOB_HEADER
4585#define MALI_TILER_JOB_SECTION_HEADER_header MALI_JOB_HEADER_header
4586#define MALI_TILER_JOB_SECTION_HEADER_pack MALI_JOB_HEADER_pack
4587#define MALI_TILER_JOB_SECTION_HEADER_unpack MALI_JOB_HEADER_unpack
4588#define MALI_TILER_JOB_SECTION_HEADER_print MALI_JOB_HEADER_print
4589#define MALI_TILER_JOB_SECTION_HEADER_OFFSET 0
4590#define MALI_TILER_JOB_SECTION_INVOCATION_TYPE struct MALI_INVOCATION
4591#define MALI_TILER_JOB_SECTION_INVOCATION_header MALI_INVOCATION_header
4592#define MALI_TILER_JOB_SECTION_INVOCATION_pack MALI_INVOCATION_pack
4593#define MALI_TILER_JOB_SECTION_INVOCATION_unpack MALI_INVOCATION_unpack
4594#define MALI_TILER_JOB_SECTION_INVOCATION_print MALI_INVOCATION_print
4595#define MALI_TILER_JOB_SECTION_INVOCATION_OFFSET 32
4596#define MALI_TILER_JOB_SECTION_PRIMITIVE_TYPE struct MALI_PRIMITIVE
4597#define MALI_TILER_JOB_SECTION_PRIMITIVE_header MALI_PRIMITIVE_header
4598#define MALI_TILER_JOB_SECTION_PRIMITIVE_pack MALI_PRIMITIVE_pack
4599#define MALI_TILER_JOB_SECTION_PRIMITIVE_unpack MALI_PRIMITIVE_unpack
4600#define MALI_TILER_JOB_SECTION_PRIMITIVE_print MALI_PRIMITIVE_print
4601#define MALI_TILER_JOB_SECTION_PRIMITIVE_OFFSET 40
4602#define MALI_TILER_JOB_SECTION_DRAW_TYPE struct MALI_DRAW
4603#define MALI_TILER_JOB_SECTION_DRAW_header MALI_DRAW_header
4604#define MALI_TILER_JOB_SECTION_DRAW_pack MALI_DRAW_pack
4605#define MALI_TILER_JOB_SECTION_DRAW_unpack MALI_DRAW_unpack
4606#define MALI_TILER_JOB_SECTION_DRAW_print MALI_DRAW_print
4607#define MALI_TILER_JOB_SECTION_DRAW_OFFSET 64
4608#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_TYPE struct MALI_PRIMITIVE_SIZE
4609#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_header MALI_PRIMITIVE_SIZE_header
4610#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_pack MALI_PRIMITIVE_SIZE_pack
4611#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_unpack MALI_PRIMITIVE_SIZE_unpack
4612#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_print MALI_PRIMITIVE_SIZE_print
4613#define MALI_TILER_JOB_SECTION_PRIMITIVE_SIZE_OFFSET 184
4614
4615#include "panfrost-job.h"
4616#endif
4617