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
156enum mali_channel {
157        MALI_CHANNEL_R                       =      0,
158        MALI_CHANNEL_G                       =      1,
159        MALI_CHANNEL_B                       =      2,
160        MALI_CHANNEL_A                       =      3,
161        MALI_CHANNEL_0                       =      4,
162        MALI_CHANNEL_1                       =      5,
163};
164
165static inline const char *
166mali_channel_as_str(enum mali_channel imm)
167{
168    switch (imm) {
169    case MALI_CHANNEL_R: return "R";
170    case MALI_CHANNEL_G: return "G";
171    case MALI_CHANNEL_B: return "B";
172    case MALI_CHANNEL_A: return "A";
173    case MALI_CHANNEL_0: return "0";
174    case MALI_CHANNEL_1: return "1";
175    default: return "XXX: INVALID";
176    }
177}
178
179enum mali_texture_dimension {
180        MALI_TEXTURE_DIMENSION_CUBE          =      0,
181        MALI_TEXTURE_DIMENSION_1D            =      1,
182        MALI_TEXTURE_DIMENSION_2D            =      2,
183        MALI_TEXTURE_DIMENSION_3D            =      3,
184};
185
186static inline const char *
187mali_texture_dimension_as_str(enum mali_texture_dimension imm)
188{
189    switch (imm) {
190    case MALI_TEXTURE_DIMENSION_CUBE: return "Cube";
191    case MALI_TEXTURE_DIMENSION_1D: return "1D";
192    case MALI_TEXTURE_DIMENSION_2D: return "2D";
193    case MALI_TEXTURE_DIMENSION_3D: return "3D";
194    default: return "XXX: INVALID";
195    }
196}
197
198enum mali_sample_pattern {
199        MALI_SAMPLE_PATTERN_SINGLE_SAMPLED   =      0,
200        MALI_SAMPLE_PATTERN_ORDERED_4X_GRID  =      1,
201        MALI_SAMPLE_PATTERN_ROTATED_4X_GRID  =      2,
202        MALI_SAMPLE_PATTERN_D3D_8X_GRID      =      3,
203        MALI_SAMPLE_PATTERN_D3D_16X_GRID     =      4,
204};
205
206static inline const char *
207mali_sample_pattern_as_str(enum mali_sample_pattern imm)
208{
209    switch (imm) {
210    case MALI_SAMPLE_PATTERN_SINGLE_SAMPLED: return "Single-sampled";
211    case MALI_SAMPLE_PATTERN_ORDERED_4X_GRID: return "Ordered 4x Grid";
212    case MALI_SAMPLE_PATTERN_ROTATED_4X_GRID: return "Rotated 4x Grid";
213    case MALI_SAMPLE_PATTERN_D3D_8X_GRID: return "D3D 8x Grid";
214    case MALI_SAMPLE_PATTERN_D3D_16X_GRID: return "D3D 16x Grid";
215    default: return "XXX: INVALID";
216    }
217}
218
219enum mali_blend_operand_a {
220        MALI_BLEND_OPERAND_A_ZERO            =      1,
221        MALI_BLEND_OPERAND_A_SRC             =      2,
222        MALI_BLEND_OPERAND_A_DEST            =      3,
223};
224
225static inline const char *
226mali_blend_operand_a_as_str(enum mali_blend_operand_a imm)
227{
228    switch (imm) {
229    case MALI_BLEND_OPERAND_A_ZERO: return "Zero";
230    case MALI_BLEND_OPERAND_A_SRC: return "Src";
231    case MALI_BLEND_OPERAND_A_DEST: return "Dest";
232    default: return "XXX: INVALID";
233    }
234}
235
236enum mali_blend_operand_b {
237        MALI_BLEND_OPERAND_B_SRC_MINUS_DEST  =      0,
238        MALI_BLEND_OPERAND_B_SRC_PLUS_DEST   =      1,
239        MALI_BLEND_OPERAND_B_SRC             =      2,
240        MALI_BLEND_OPERAND_B_DEST            =      3,
241};
242
243static inline const char *
244mali_blend_operand_b_as_str(enum mali_blend_operand_b imm)
245{
246    switch (imm) {
247    case MALI_BLEND_OPERAND_B_SRC_MINUS_DEST: return "Src Minus Dest";
248    case MALI_BLEND_OPERAND_B_SRC_PLUS_DEST: return "Src Plus Dest";
249    case MALI_BLEND_OPERAND_B_SRC: return "Src";
250    case MALI_BLEND_OPERAND_B_DEST: return "Dest";
251    default: return "XXX: INVALID";
252    }
253}
254
255enum mali_blend_operand_c {
256        MALI_BLEND_OPERAND_C_ZERO            =      1,
257        MALI_BLEND_OPERAND_C_SRC             =      2,
258        MALI_BLEND_OPERAND_C_DEST            =      3,
259        MALI_BLEND_OPERAND_C_SRC_X_2         =      4,
260        MALI_BLEND_OPERAND_C_SRC_ALPHA       =      5,
261        MALI_BLEND_OPERAND_C_DEST_ALPHA      =      6,
262        MALI_BLEND_OPERAND_C_CONSTANT        =      7,
263};
264
265static inline const char *
266mali_blend_operand_c_as_str(enum mali_blend_operand_c imm)
267{
268    switch (imm) {
269    case MALI_BLEND_OPERAND_C_ZERO: return "Zero";
270    case MALI_BLEND_OPERAND_C_SRC: return "Src";
271    case MALI_BLEND_OPERAND_C_DEST: return "Dest";
272    case MALI_BLEND_OPERAND_C_SRC_X_2: return "Src x 2";
273    case MALI_BLEND_OPERAND_C_SRC_ALPHA: return "Src Alpha";
274    case MALI_BLEND_OPERAND_C_DEST_ALPHA: return "Dest Alpha";
275    case MALI_BLEND_OPERAND_C_CONSTANT: return "Constant";
276    default: return "XXX: INVALID";
277    }
278}
279
280struct MALI_BLEND_FUNCTION {
281   enum mali_blend_operand_a            a;
282   bool                                 negate_a;
283   enum mali_blend_operand_b            b;
284   bool                                 negate_b;
285   enum mali_blend_operand_c            c;
286   bool                                 invert_c;
287};
288
289#define MALI_BLEND_FUNCTION_header              \
290   0
291
292static inline void
293MALI_BLEND_FUNCTION_print(FILE *fp, const struct MALI_BLEND_FUNCTION * values, unsigned indent)
294{
295   fprintf(fp, "%*sA: %s\n", indent, "", mali_blend_operand_a_as_str(values->a));
296   fprintf(fp, "%*sNegate A: %s\n", indent, "", values->negate_a ? "true" : "false");
297   fprintf(fp, "%*sB: %s\n", indent, "", mali_blend_operand_b_as_str(values->b));
298   fprintf(fp, "%*sNegate B: %s\n", indent, "", values->negate_b ? "true" : "false");
299   fprintf(fp, "%*sC: %s\n", indent, "", mali_blend_operand_c_as_str(values->c));
300   fprintf(fp, "%*sInvert C: %s\n", indent, "", values->invert_c ? "true" : "false");
301}
302
303struct MALI_BLEND_EQUATION {
304   struct MALI_BLEND_FUNCTION           rgb;
305   struct MALI_BLEND_FUNCTION           alpha;
306   uint32_t                             color_mask;
307};
308
309#define MALI_BLEND_EQUATION_header              \
310   .rgb = { MALI_BLEND_FUNCTION_header },  \
311   .alpha = { MALI_BLEND_FUNCTION_header }
312
313static inline void
314MALI_BLEND_EQUATION_pack(uint32_t * restrict cl,
315                         const struct MALI_BLEND_EQUATION * restrict values)
316{
317   cl[ 0] = __gen_uint(values->rgb.a, 0, 1) |
318            __gen_uint(values->rgb.negate_a, 3, 3) |
319            __gen_uint(values->rgb.b, 4, 5) |
320            __gen_uint(values->rgb.negate_b, 7, 7) |
321            __gen_uint(values->rgb.c, 8, 10) |
322            __gen_uint(values->rgb.invert_c, 11, 11) |
323            __gen_uint(values->alpha.a, 12, 13) |
324            __gen_uint(values->alpha.negate_a, 15, 15) |
325            __gen_uint(values->alpha.b, 16, 17) |
326            __gen_uint(values->alpha.negate_b, 19, 19) |
327            __gen_uint(values->alpha.c, 20, 22) |
328            __gen_uint(values->alpha.invert_c, 23, 23) |
329            __gen_uint(values->color_mask, 28, 31);
330}
331
332
333#define MALI_BLEND_EQUATION_LENGTH 4
334struct mali_blend_equation_packed { uint32_t opaque[1]; };
335static inline void
336MALI_BLEND_EQUATION_unpack(const uint8_t * restrict cl,
337                           struct MALI_BLEND_EQUATION * restrict values)
338{
339   if (((const uint32_t *) cl)[0] & 0xf044044) fprintf(stderr, "XXX: Invalid field of Blend Equation unpacked at word 0\n");
340   values->rgb.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 0, 1);
341   values->rgb.negate_a = __gen_unpack_uint(cl, 3, 3);
342   values->rgb.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 4, 5);
343   values->rgb.negate_b = __gen_unpack_uint(cl, 7, 7);
344   values->rgb.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 8, 10);
345   values->rgb.invert_c = __gen_unpack_uint(cl, 11, 11);
346   values->alpha.a = (enum mali_blend_operand_a)__gen_unpack_uint(cl, 12, 13);
347   values->alpha.negate_a = __gen_unpack_uint(cl, 15, 15);
348   values->alpha.b = (enum mali_blend_operand_b)__gen_unpack_uint(cl, 16, 17);
349   values->alpha.negate_b = __gen_unpack_uint(cl, 19, 19);
350   values->alpha.c = (enum mali_blend_operand_c)__gen_unpack_uint(cl, 20, 22);
351   values->alpha.invert_c = __gen_unpack_uint(cl, 23, 23);
352   values->color_mask = __gen_unpack_uint(cl, 28, 31);
353}
354
355static inline void
356MALI_BLEND_EQUATION_print(FILE *fp, const struct MALI_BLEND_EQUATION * values, unsigned indent)
357{
358   fprintf(fp, "%*sRGB:\n", indent, "");
359   MALI_BLEND_FUNCTION_print(fp, &values->rgb, indent + 2);
360   fprintf(fp, "%*sAlpha:\n", indent, "");
361   MALI_BLEND_FUNCTION_print(fp, &values->alpha, indent + 2);
362   fprintf(fp, "%*sColor Mask: %u\n", indent, "", values->color_mask);
363}
364
365enum mali_format {
366        MALI_ETC2_RGB8                       =      1,
367        MALI_ETC2_R11_UNORM                  =      2,
368        MALI_ETC2_RGBA8                      =      3,
369        MALI_ETC2_RG11_UNORM                 =      4,
370        MALI_BC1_UNORM                       =      7,
371        MALI_BC2_UNORM                       =      8,
372        MALI_BC3_UNORM                       =      9,
373        MALI_BC4_UNORM                       =     10,
374        MALI_BC4_SNORM                       =     11,
375        MALI_BC5_UNORM                       =     12,
376        MALI_BC5_SNORM                       =     13,
377        MALI_BC6H_UF16                       =     14,
378        MALI_BC6H_SF16                       =     15,
379        MALI_BC7_UNORM                       =     16,
380        MALI_ETC2_R11_SNORM                  =     17,
381        MALI_ETC2_RG11_SNORM                 =     18,
382        MALI_ETC2_RGB8A1                     =     19,
383        MALI_ASTC_3D_LDR                     =     20,
384        MALI_ASTC_3D_HDR                     =     21,
385        MALI_ASTC_2D_LDR                     =     22,
386        MALI_ASTC_2D_HDR                     =     23,
387};
388
389static inline const char *
390mali_format_as_str(enum mali_format imm)
391{
392    switch (imm) {
393    case MALI_ETC2_RGB8: return "ETC2 RGB8";
394    case MALI_ETC2_R11_UNORM: return "ETC2 R11 UNORM";
395    case MALI_ETC2_RGBA8: return "ETC2 RGBA8";
396    case MALI_ETC2_RG11_UNORM: return "ETC2 RG11 UNORM";
397    case MALI_BC1_UNORM: return "BC1 UNORM";
398    case MALI_BC2_UNORM: return "BC2 UNORM";
399    case MALI_BC3_UNORM: return "BC3 UNORM";
400    case MALI_BC4_UNORM: return "BC4 UNORM";
401    case MALI_BC4_SNORM: return "BC4 SNORM";
402    case MALI_BC5_UNORM: return "BC5 UNORM";
403    case MALI_BC5_SNORM: return "BC5 SNORM";
404    case MALI_BC6H_UF16: return "BC6H UF16";
405    case MALI_BC6H_SF16: return "BC6H SF16";
406    case MALI_BC7_UNORM: return "BC7 UNORM";
407    case MALI_ETC2_R11_SNORM: return "ETC2 R11 SNORM";
408    case MALI_ETC2_RG11_SNORM: return "ETC2 RG11 SNORM";
409    case MALI_ETC2_RGB8A1: return "ETC2 RGB8A1";
410    case MALI_ASTC_3D_LDR: return "ASTC 3D LDR";
411    case MALI_ASTC_3D_HDR: return "ASTC 3D HDR";
412    case MALI_ASTC_2D_LDR: return "ASTC 2D LDR";
413    case MALI_ASTC_2D_HDR: return "ASTC 2D HDR";
414    default: return "XXX: INVALID";
415    }
416}
417
418enum mali_func {
419        MALI_FUNC_NEVER                      =      0,
420        MALI_FUNC_LESS                       =      1,
421        MALI_FUNC_EQUAL                      =      2,
422        MALI_FUNC_LEQUAL                     =      3,
423        MALI_FUNC_GREATER                    =      4,
424        MALI_FUNC_NOT_EQUAL                  =      5,
425        MALI_FUNC_GEQUAL                     =      6,
426        MALI_FUNC_ALWAYS                     =      7,
427};
428
429static inline const char *
430mali_func_as_str(enum mali_func imm)
431{
432    switch (imm) {
433    case MALI_FUNC_NEVER: return "Never";
434    case MALI_FUNC_LESS: return "Less";
435    case MALI_FUNC_EQUAL: return "Equal";
436    case MALI_FUNC_LEQUAL: return "Lequal";
437    case MALI_FUNC_GREATER: return "Greater";
438    case MALI_FUNC_NOT_EQUAL: return "Not Equal";
439    case MALI_FUNC_GEQUAL: return "Gequal";
440    case MALI_FUNC_ALWAYS: return "Always";
441    default: return "XXX: INVALID";
442    }
443}
444
445enum mali_color_buffer_internal_format {
446        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE =      0,
447        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8 =      1,
448        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2 =      2,
449        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2 =      3,
450        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4 =      4,
451        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0 =      5,
452        MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1 =      6,
453        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8 =     32,
454        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16 =     33,
455        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32 =     34,
456        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64 =     35,
457        MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128 =     36,
458};
459
460static inline const char *
461mali_color_buffer_internal_format_as_str(enum mali_color_buffer_internal_format imm)
462{
463    switch (imm) {
464    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW_VALUE: return "Raw Value";
465    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A8: return "R8G8B8A8";
466    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R10G10B10A2: return "R10G10B10A2";
467    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R8G8B8A2: return "R8G8B8A2";
468    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R4G4B4A4: return "R4G4B4A4";
469    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G6B5A0: return "R5G6B5A0";
470    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_R5G5B5A1: return "R5G5B5A1";
471    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW8: return "RAW8";
472    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW16: return "RAW16";
473    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW32: return "RAW32";
474    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW64: return "RAW64";
475    case MALI_COLOR_BUFFER_INTERNAL_FORMAT_RAW128: return "RAW128";
476    default: return "XXX: INVALID";
477    }
478}
479
480#include "panfrost-job.h"
481#endif
482