panfrost/midgard: Typofix
[mesa.git] / src / gallium / drivers / panfrost / midgard / midgard.h
1 /* Author(s):
2 * Connor Abbott
3 * Alyssa Rosenzweig
4 *
5 * Copyright (c) 2013 Connor Abbott (connor@abbott.cx)
6 * Copyright (c) 2018 Alyssa Rosenzweig (alyssa@rosenzweig.io)
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27 #ifndef __midgard_h__
28 #define __midgard_h__
29
30 #include <stdint.h>
31 #include <stdbool.h>
32
33 #define MIDGARD_DBG_MSGS 0x0001
34 #define MIDGARD_DBG_SHADERS 0x0002
35
36 extern int midgard_debug;
37
38 typedef enum {
39 midgard_word_type_alu,
40 midgard_word_type_load_store,
41 midgard_word_type_texture,
42 midgard_word_type_unknown
43 } midgard_word_type;
44
45 typedef enum {
46 midgard_alu_vmul,
47 midgard_alu_sadd,
48 midgard_alu_smul,
49 midgard_alu_vadd,
50 midgard_alu_lut
51 } midgard_alu;
52
53 /*
54 * ALU words
55 */
56
57 typedef enum {
58 midgard_alu_op_fadd = 0x10,
59 midgard_alu_op_fmul = 0x14,
60
61 midgard_alu_op_fmin = 0x28,
62 midgard_alu_op_fmax = 0x2C,
63
64 midgard_alu_op_fmov = 0x30,
65 midgard_alu_op_froundeven = 0x34,
66 midgard_alu_op_ftrunc = 0x35,
67 midgard_alu_op_ffloor = 0x36,
68 midgard_alu_op_fceil = 0x37,
69 midgard_alu_op_ffma = 0x38,
70 midgard_alu_op_fdot3 = 0x3C,
71 midgard_alu_op_fdot3r = 0x3D,
72 midgard_alu_op_fdot4 = 0x3E,
73 midgard_alu_op_freduce = 0x3F,
74
75 midgard_alu_op_iadd = 0x40,
76 midgard_alu_op_ishladd = 0x41,
77 midgard_alu_op_isub = 0x46,
78
79 midgard_alu_op_imul = 0x58,
80
81 midgard_alu_op_imin = 0x60,
82 midgard_alu_op_umin = 0x61,
83 midgard_alu_op_imax = 0x62,
84 midgard_alu_op_umax = 0x63,
85 midgard_alu_op_iasr = 0x68,
86 midgard_alu_op_ilsr = 0x69,
87 midgard_alu_op_ishl = 0x6E,
88
89 midgard_alu_op_iand = 0x70,
90 midgard_alu_op_ior = 0x71,
91 midgard_alu_op_inand = 0x72, /* ~(a & b), for inot let a = b */
92 midgard_alu_op_inor = 0x73, /* ~(a | b) */
93 midgard_alu_op_iandnot = 0x74, /* (a & ~b), used for not/b2f */
94 midgard_alu_op_iornot = 0x75, /* (a | ~b) */
95 midgard_alu_op_ixor = 0x76,
96 midgard_alu_op_inxor = 0x77, /* ~(a & b) */
97 midgard_alu_op_iclz = 0x78, /* Number of zeroes on left */
98 midgard_alu_op_ibitcount8 = 0x7A, /* Counts bits in 8-bit increments */
99 midgard_alu_op_imov = 0x7B,
100 midgard_alu_op_iabs = 0x7C,
101
102 midgard_alu_op_feq = 0x80,
103 midgard_alu_op_fne = 0x81,
104 midgard_alu_op_flt = 0x82,
105 midgard_alu_op_fle = 0x83,
106 midgard_alu_op_fball_eq = 0x88,
107 midgard_alu_op_bball_eq = 0x89,
108 midgard_alu_op_fball_lt = 0x8A, /* all(lessThan(.., ..)) */
109 midgard_alu_op_fball_lte = 0x8B, /* all(lessThanEqual(.., ..)) */
110
111 midgard_alu_op_bbany_neq = 0x90, /* used for bvec4(1) */
112 midgard_alu_op_fbany_neq = 0x91, /* bvec4(0) also */
113 midgard_alu_op_fbany_lt = 0x92, /* any(lessThan(.., ..)) */
114 midgard_alu_op_fbany_lte = 0x93, /* any(lessThanEqual(.., ..)) */
115 midgard_alu_op_f2i = 0x99,
116 midgard_alu_op_f2u8 = 0x9C,
117 midgard_alu_op_f2u = 0x9D,
118
119 midgard_alu_op_ieq = 0xA0,
120 midgard_alu_op_ine = 0xA1,
121 midgard_alu_op_ult = 0xA2,
122 midgard_alu_op_ule = 0xA3,
123 midgard_alu_op_ilt = 0xA4,
124 midgard_alu_op_ile = 0xA5,
125 midgard_alu_op_iball_eq = 0xA8,
126 midgard_alu_op_iball_neq = 0xA9,
127 midgard_alu_op_uball_lt = 0xAA,
128 midgard_alu_op_uball_lte = 0xAB,
129 midgard_alu_op_iball_lt = 0xAC,
130 midgard_alu_op_iball_lte = 0xAD,
131
132 midgard_alu_op_ibany_eq = 0xB0,
133 midgard_alu_op_ibany_neq = 0xB1,
134 midgard_alu_op_ubany_lt = 0xB2,
135 midgard_alu_op_ubany_lte = 0xB3,
136 midgard_alu_op_ibany_lt = 0xB4, /* any(lessThan(.., ..)) */
137 midgard_alu_op_ibany_lte = 0xB5, /* any(lessThanEqual(.., ..)) */
138 midgard_alu_op_i2f = 0xB8,
139 midgard_alu_op_u2f = 0xBC,
140
141 midgard_alu_op_icsel_v = 0xC0, /* condition code r31 */
142 midgard_alu_op_icsel = 0xC1, /* condition code r31.w */
143 midgard_alu_op_fcsel_v = 0xC4,
144 midgard_alu_op_fcsel = 0xC5,
145 midgard_alu_op_fround = 0xC6,
146
147 midgard_alu_op_fatan_pt2 = 0xE8,
148 midgard_alu_op_fpow_pt1 = 0xEC,
149
150 midgard_alu_op_frcp = 0xF0,
151 midgard_alu_op_frsqrt = 0xF2,
152 midgard_alu_op_fsqrt = 0xF3,
153 midgard_alu_op_fexp2 = 0xF4,
154 midgard_alu_op_flog2 = 0xF5,
155 midgard_alu_op_fsin = 0xF6,
156 midgard_alu_op_fcos = 0xF7,
157 midgard_alu_op_fatan2_pt1 = 0xF9,
158 } midgard_alu_op;
159
160 typedef enum {
161 midgard_outmod_none = 0,
162 midgard_outmod_pos = 1,
163 midgard_outmod_int = 2,
164 midgard_outmod_sat = 3
165 } midgard_outmod;
166
167 typedef enum {
168 midgard_reg_mode_8 = 0,
169 midgard_reg_mode_16 = 1,
170 midgard_reg_mode_32 = 2,
171 midgard_reg_mode_64 = 3 /* TODO: verify */
172 } midgard_reg_mode;
173
174 typedef enum {
175 midgard_dest_override_lower = 0,
176 midgard_dest_override_upper = 1,
177 midgard_dest_override_none = 2
178 } midgard_dest_override;
179
180 typedef enum {
181 midgard_int_sign_extend = 0,
182 midgard_int_zero_extend = 1,
183 midgard_int_normal = 2,
184 midgard_int_reserved = 3
185 } midgard_int_mod;
186
187 #define MIDGARD_FLOAT_MOD_ABS (1 << 0)
188 #define MIDGARD_FLOAT_MOD_NEG (1 << 1)
189
190 typedef struct
191 __attribute__((__packed__))
192 {
193 /* Either midgard_int_mod or from midgard_float_mod_*, depending on the
194 * type of op */
195 unsigned mod : 2;
196
197 /* replicate lower half if dest = half, or low/high half selection if
198 * dest = full
199 */
200 bool rep_low : 1;
201 bool rep_high : 1; /* unused if dest = full */
202 bool half : 1; /* only matters if dest = full */
203 unsigned swizzle : 8;
204 }
205 midgard_vector_alu_src;
206
207 typedef struct
208 __attribute__((__packed__))
209 {
210 midgard_alu_op op : 8;
211 midgard_reg_mode reg_mode : 2;
212 unsigned src1 : 13;
213 unsigned src2 : 13;
214 midgard_dest_override dest_override : 2;
215 midgard_outmod outmod : 2;
216 unsigned mask : 8;
217 }
218 midgard_vector_alu;
219
220 typedef struct
221 __attribute__((__packed__))
222 {
223 bool abs : 1;
224 bool negate : 1;
225 bool full : 1; /* 0 = half, 1 = full */
226 unsigned component : 3;
227 }
228 midgard_scalar_alu_src;
229
230 typedef struct
231 __attribute__((__packed__))
232 {
233 midgard_alu_op op : 8;
234 unsigned src1 : 6;
235 unsigned src2 : 11;
236 unsigned unknown : 1;
237 midgard_outmod outmod : 2;
238 bool output_full : 1;
239 unsigned output_component : 3;
240 }
241 midgard_scalar_alu;
242
243 typedef struct
244 __attribute__((__packed__))
245 {
246 unsigned src1_reg : 5;
247 unsigned src2_reg : 5;
248 unsigned out_reg : 5;
249 bool src2_imm : 1;
250 }
251 midgard_reg_info;
252
253 /* In addition to conditional branches and jumps (unconditional branches),
254 * Midgard implements a bit of fixed function functionality used in fragment
255 * shaders via specially crafted branches. These have special branch opcodes,
256 * which perform a fixed-function operation and/or use the results of a
257 * fixed-function operation as the branch condition. */
258
259 typedef enum {
260 /* Regular branches */
261 midgard_jmp_writeout_op_branch_uncond = 1,
262 midgard_jmp_writeout_op_branch_cond = 2,
263
264 /* In a fragment shader, execute a discard_if instruction, with the
265 * corresponding condition code. Terminates the shader, so generally
266 * set the branch target to out of the shader */
267 midgard_jmp_writeout_op_discard = 4,
268
269 /* Branch if the tilebuffer is not yet ready. At the beginning of a
270 * fragment shader that reads from the tile buffer, for instance via
271 * ARM_shader_framebuffer_fetch or EXT_pixel_local_storage, this branch
272 * operation should be used as a loop. An instruction like
273 * "br.tilebuffer.always -1" does the trick, corresponding to
274 * "while(!is_tilebuffer_ready) */
275 midgard_jmp_writeout_op_tilebuffer_pending = 6,
276
277 /* In a fragment shader, try to write out the value pushed to r0 to the
278 * tilebuffer, subject to unknown state in r1.z and r1.w. If this
279 * succeeds, the shader terminates. If it fails, it branches to the
280 * specified branch target. Generally, this should be used in a loop to
281 * itself, acting as "do { write(r0); } while(!write_successful);" */
282 midgard_jmp_writeout_op_writeout = 7,
283 } midgard_jmp_writeout_op;
284
285 typedef enum {
286 midgard_condition_write0 = 0,
287
288 /* These condition codes denote a conditional branch on FALSE and on
289 * TRUE respectively */
290 midgard_condition_false = 1,
291 midgard_condition_true = 2,
292
293 /* This condition code always branches. For a pure branch, the
294 * unconditional branch coding should be used instead, but for
295 * fixed-function branch opcodes, this is still useful */
296 midgard_condition_always = 3,
297 } midgard_condition;
298
299 typedef struct
300 __attribute__((__packed__))
301 {
302 midgard_jmp_writeout_op op : 3; /* == branch_uncond */
303 unsigned dest_tag : 4; /* tag of branch destination */
304 unsigned unknown : 2;
305 int offset : 7;
306 }
307 midgard_branch_uncond;
308
309 typedef struct
310 __attribute__((__packed__))
311 {
312 midgard_jmp_writeout_op op : 3; /* == branch_cond */
313 unsigned dest_tag : 4; /* tag of branch destination */
314 int offset : 7;
315 midgard_condition cond : 2;
316 }
317 midgard_branch_cond;
318
319 typedef struct
320 __attribute__((__packed__))
321 {
322 midgard_jmp_writeout_op op : 3; /* == branch_cond */
323 unsigned dest_tag : 4; /* tag of branch destination */
324 unsigned unknown : 2;
325 signed offset : 23;
326 unsigned cond : 16;
327 }
328 midgard_branch_extended;
329
330 typedef struct
331 __attribute__((__packed__))
332 {
333 midgard_jmp_writeout_op op : 3; /* == writeout */
334 unsigned unknown : 13;
335 }
336 midgard_writeout;
337
338 /*
339 * Load/store words
340 */
341
342 typedef enum {
343 midgard_op_ld_st_noop = 0x03,
344
345 /* Unclear why this is on the L/S unit, but (with an address of 0,
346 * appropriate swizzle, magic constant 0x24, and xy mask?) moves fp32 cube
347 * map coordinates in r27 to its cube map texture coordinate
348 * destination (e.g r29). 0x4 magic for lding from fp16 instead */
349
350 midgard_op_st_cubemap_coords = 0x0E,
351
352 /* Used in OpenCL. Probably can ld other things as well */
353 midgard_op_ld_global_id = 0x10,
354
355 /* val in r27.y, address embedded, outputs result to argument. Invert val for sub. Let val = +-1 for inc/dec. */
356 midgard_op_atomic_add = 0x40,
357 midgard_op_atomic_and = 0x44,
358 midgard_op_atomic_or = 0x48,
359 midgard_op_atomic_xor = 0x4C,
360
361 midgard_op_atomic_imin = 0x50,
362 midgard_op_atomic_umin = 0x54,
363 midgard_op_atomic_imax = 0x58,
364 midgard_op_atomic_umax = 0x5C,
365
366 midgard_op_atomic_xchg = 0x60,
367
368 /* Used for compute shader's __global arguments, __local variables (or
369 * for register spilling) */
370
371 midgard_op_ld_char = 0x81,
372 midgard_op_ld_char2 = 0x84,
373 midgard_op_ld_short = 0x85,
374 midgard_op_ld_char4 = 0x88, /* short2, int, float */
375 midgard_op_ld_short4 = 0x8C, /* int2, float2, long */
376 midgard_op_ld_int4 = 0x90, /* float4, long2 */
377
378 midgard_op_ld_attr_32 = 0x94,
379 midgard_op_ld_attr_16 = 0x95,
380 midgard_op_ld_attr_32i = 0x97,
381 midgard_op_ld_vary_32 = 0x98,
382 midgard_op_ld_vary_16 = 0x99,
383 midgard_op_ld_vary_32i = 0x9B,
384 midgard_op_ld_color_buffer_16 = 0x9D,
385
386 midgard_op_ld_uniform_16 = 0xAC,
387
388 midgard_op_ld_uniform_32 = 0xB0,
389 midgard_op_ld_color_buffer_8 = 0xBA,
390
391 midgard_op_st_char = 0xC0,
392 midgard_op_st_char2 = 0xC4, /* short */
393 midgard_op_st_char4 = 0xC8, /* short2, int, float */
394 midgard_op_st_short4 = 0xCC, /* int2, float2, long */
395 midgard_op_st_int4 = 0xD0, /* float4, long2 */
396
397 midgard_op_st_vary_32 = 0xD4,
398 midgard_op_st_vary_16 = 0xD5,
399 midgard_op_st_vary_32i = 0xD7,
400
401 /* Value to st in r27, location r26.w as short2 */
402 midgard_op_st_image_f = 0xD8,
403 midgard_op_st_image_ui = 0xDA,
404 midgard_op_st_image_i = 0xDB,
405 } midgard_load_store_op;
406
407 typedef enum {
408 midgard_interp_centroid = 1,
409 midgard_interp_default = 2
410 } midgard_interpolation;
411
412 typedef struct
413 __attribute__((__packed__))
414 {
415 unsigned zero1 : 4; /* Always zero */
416
417 /* Varying qualifiers, zero if not a varying */
418 unsigned flat : 1;
419 unsigned is_varying : 1; /* Always one for varying, but maybe something else? */
420 midgard_interpolation interpolation : 2;
421
422 unsigned zero2 : 2; /* Always zero */
423 }
424 midgard_varying_parameter;
425
426 typedef struct
427 __attribute__((__packed__))
428 {
429 midgard_load_store_op op : 8;
430 unsigned reg : 5;
431 unsigned mask : 4;
432 unsigned swizzle : 8;
433 unsigned unknown : 16;
434
435 unsigned varying_parameters : 10;
436
437 unsigned address : 9;
438 }
439 midgard_load_store_word;
440
441 typedef struct
442 __attribute__((__packed__))
443 {
444 unsigned type : 4;
445 unsigned next_type : 4;
446 uint64_t word1 : 60;
447 uint64_t word2 : 60;
448 }
449 midgard_load_store;
450
451 /* Texture pipeline results are in r28-r29 */
452 #define REG_TEX_BASE 28
453
454 /* Texture opcodes... maybe? */
455 #define TEXTURE_OP_NORMAL 0x11
456 #define TEXTURE_OP_TEXEL_FETCH 0x14
457
458 /* Texture format types, found in format */
459 #define TEXTURE_CUBE 0x00
460 #define TEXTURE_2D 0x02
461 #define TEXTURE_3D 0x03
462
463 typedef struct
464 __attribute__((__packed__))
465 {
466 unsigned type : 4;
467 unsigned next_type : 4;
468
469 unsigned op : 6;
470 unsigned shadow : 1;
471 unsigned unknown3 : 1;
472
473 /* A little obscure, but last is set for the last texture operation in
474 * a shader. cont appears to just be last's opposite (?). Yeah, I know,
475 * kind of funky.. BiOpen thinks it could do with memory hinting, or
476 * tile locking? */
477
478 unsigned cont : 1;
479 unsigned last : 1;
480
481 unsigned format : 5;
482 unsigned has_offset : 1;
483
484 /* Like in Bifrost */
485 unsigned filter : 1;
486
487 unsigned in_reg_select : 1;
488 unsigned in_reg_upper : 1;
489
490 unsigned in_reg_swizzle_left : 2;
491 unsigned in_reg_swizzle_right : 2;
492
493 unsigned unknown1 : 2;
494
495 unsigned unknown8 : 4;
496
497 unsigned out_full : 1;
498
499 /* Always 1 afaict... */
500 unsigned unknown7 : 2;
501
502 unsigned out_reg_select : 1;
503 unsigned out_upper : 1;
504
505 unsigned mask : 4;
506
507 unsigned unknown2 : 2;
508
509 unsigned swizzle : 8;
510 unsigned unknown4 : 8;
511
512 unsigned unknownA : 4;
513
514 unsigned offset_unknown1 : 1;
515 unsigned offset_reg_select : 1;
516 unsigned offset_reg_upper : 1;
517 unsigned offset_unknown4 : 1;
518 unsigned offset_unknown5 : 1;
519 unsigned offset_unknown6 : 1;
520 unsigned offset_unknown7 : 1;
521 unsigned offset_unknown8 : 1;
522 unsigned offset_unknown9 : 1;
523
524 unsigned unknownB : 3;
525
526 /* Texture bias or LOD, depending on whether it is executed in a
527 * fragment/vertex shader respectively. Compute as int(2^8 * biasf).
528 *
529 * For texel fetch, this is the LOD as is. */
530 unsigned bias : 8;
531
532 unsigned unknown9 : 8;
533
534 unsigned texture_handle : 16;
535 unsigned sampler_handle : 16;
536 }
537 midgard_texture_word;
538
539 static char *load_store_opcode_names[256] = {
540 [midgard_op_st_cubemap_coords] = "st_cubemap_coords",
541 [midgard_op_ld_global_id] = "ld_global_id",
542
543 [midgard_op_atomic_add] = "atomic_add",
544 [midgard_op_atomic_and] = "atomic_and",
545 [midgard_op_atomic_or] = "atomic_or",
546 [midgard_op_atomic_xor] = "atomic_xor",
547 [midgard_op_atomic_imin] = "atomic_imin",
548 [midgard_op_atomic_umin] = "atomic_umin",
549 [midgard_op_atomic_imax] = "atomic_imax",
550 [midgard_op_atomic_umax] = "atomic_umax",
551 [midgard_op_atomic_xchg] = "atomic_xchg",
552
553 [midgard_op_ld_char] = "ld_char",
554 [midgard_op_ld_char2] = "ld_char2",
555 [midgard_op_ld_short] = "ld_short",
556 [midgard_op_ld_char4] = "ld_char4",
557 [midgard_op_ld_short4] = "ld_short4",
558 [midgard_op_ld_int4] = "ld_int4",
559
560 [midgard_op_ld_attr_32] = "ld_attr_32",
561 [midgard_op_ld_attr_16] = "ld_attr_16",
562 [midgard_op_ld_attr_32i] = "ld_attr_32i",
563
564 [midgard_op_ld_vary_32] = "ld_vary_32",
565 [midgard_op_ld_vary_16] = "ld_vary_16",
566 [midgard_op_ld_vary_32i] = "ld_vary_32i",
567
568 [midgard_op_ld_color_buffer_16] = "ld_color_buffer_16",
569
570 [midgard_op_ld_uniform_16] = "ld_uniform_16",
571 [midgard_op_ld_uniform_32] = "ld_uniform_32",
572 [midgard_op_ld_color_buffer_8] = "ld_color_buffer_8",
573
574 [midgard_op_st_char] = "st_char",
575 [midgard_op_st_char2] = "st_char2",
576 [midgard_op_st_char4] = "st_char4",
577 [midgard_op_st_short4] = "st_short4",
578 [midgard_op_st_int4] = "st_int4",
579
580 [midgard_op_st_vary_32] = "st_vary_32",
581 [midgard_op_st_vary_16] = "st_vary_16",
582 [midgard_op_st_vary_32i] = "st_vary_32i",
583
584 [midgard_op_st_image_f] = "st_image_f",
585 [midgard_op_st_image_ui] = "st_image_ui",
586 [midgard_op_st_image_i] = "st_image_i",
587 };
588
589 #endif