pan/bi: Print shaders only if BIFROST_MESA_DEBUG=shaders
[mesa.git] / src / panfrost / bifrost / bifrost.h
1 /*
2 * Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
3 * Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
4 * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #ifndef __bifrost_h__
27 #define __bifrost_h__
28
29 #include <stdint.h>
30 #include <stdbool.h>
31
32 #define BIFROST_DBG_MSGS 0x0001
33 #define BIFROST_DBG_SHADERS 0x0002
34
35 extern int bifrost_debug;
36
37 enum bifrost_clause_type {
38 BIFROST_CLAUSE_NONE = 0,
39 BIFROST_CLAUSE_LOAD_VARY = 1,
40 BIFROST_CLAUSE_UBO = 2,
41 BIFROST_CLAUSE_TEX = 3,
42 BIFROST_CLAUSE_SSBO_LOAD = 5,
43 BIFROST_CLAUSE_SSBO_STORE = 6,
44 BIFROST_CLAUSE_BLEND = 9,
45 BIFROST_CLAUSE_ATEST = 13,
46 BIFROST_CLAUSE_64BIT = 15
47 };
48
49 struct bifrost_header {
50 unsigned unk0 : 7;
51 // If true, convert any infinite result of any floating-point operation to
52 // the biggest representable number.
53 unsigned suppress_inf: 1;
54 // Convert any NaN results to 0.
55 unsigned suppress_nan : 1;
56 unsigned unk1 : 2;
57 // true if the execution mask of the next clause is the same as the mask of
58 // the current clause.
59 unsigned back_to_back : 1;
60 unsigned no_end_of_shader: 1;
61 unsigned unk2 : 2;
62 // Set to true for fragment shaders, to implement this bit of spec text
63 // from section 7.1.5 of the GLSL ES spec:
64 //
65 // "Stores to image and buffer variables performed by helper invocations
66 // have no effect on the underlying image or buffer memory."
67 //
68 // Helper invocations are threads (invocations) corresponding to pixels in
69 // a quad that aren't actually part of the triangle, but are included to
70 // make derivatives work correctly. They're usually turned on, but they
71 // need to be masked off for GLSL-level stores. This bit seems to be the
72 // only bit that's actually different between fragment shaders and other
73 // shaders, so this is probably what it's doing.
74 unsigned elide_writes : 1;
75 // If backToBack is off:
76 // - true for conditional branches and fallthrough
77 // - false for unconditional branches
78 // The blob seems to always set it to true if back-to-back is on.
79 unsigned branch_cond : 1;
80 // This bit is set when the next clause writes to the data register of some
81 // previous clause.
82 unsigned datareg_writebarrier: 1;
83 unsigned datareg : 6;
84 unsigned scoreboard_deps: 8;
85 unsigned scoreboard_index: 3;
86 enum bifrost_clause_type clause_type: 4;
87 unsigned unk3 : 1; // part of clauseType?
88 enum bifrost_clause_type next_clause_type: 4;
89 unsigned unk4 : 1; // part of nextClauseType?
90 } __attribute__((packed));
91
92 enum bifrost_packed_src {
93 BIFROST_SRC_PORT0 = 0,
94 BIFROST_SRC_PORT1 = 1,
95 BIFROST_SRC_PORT3 = 2,
96 BIFROST_SRC_STAGE = 3,
97 BIFROST_SRC_CONST_LO = 4,
98 BIFROST_SRC_CONST_HI = 5,
99 BIFROST_SRC_PASS_FMA = 6,
100 BIFROST_SRC_PASS_ADD = 7,
101 };
102
103 #define BIFROST_FMA_EXT (0xe0000)
104 #define BIFROST_FMA_OP_MOV BIFROST_FMA_EXT | (0x32d)
105 #define BIFROST_FMA_OP_FREXPE_LOG BIFROST_FMA_EXT | 0x3c5
106 #define BIFROST_FMA_OP_ADD_FREXPM ((BIFROST_FMA_EXT | 0x1e80) >> 3)
107 #define BIFROST_FMA_SEL_16(swiz) (((BIFROST_FMA_EXT | 0x1e00) >> 3) | (swiz))
108
109 #define BIFROST_FMA_ROUND_16(mode, swiz) (BIFROST_FMA_EXT | 0x1800 | (swiz) | ((mode) << 6))
110 #define BIFROST_FMA_ROUND_32(mode) (BIFROST_FMA_EXT | 0x1805 | ((mode) << 6))
111
112 struct bifrost_fma_inst {
113 unsigned src0 : 3;
114 unsigned op : 20;
115 } __attribute__((packed));
116
117 struct bifrost_fma_2src {
118 unsigned src0 : 3;
119 unsigned src1 : 3;
120 unsigned op : 17;
121 } __attribute__((packed));
122
123 #define BIFROST_FMA_OP_SEL8 (0x71)
124
125 struct bifrost_fma_sel8 {
126 unsigned src0 : 3;
127 unsigned src1 : 3;
128 unsigned src2 : 3;
129 unsigned src3 : 3;
130 unsigned swizzle : 4;
131 unsigned op : 7;
132 } __attribute__((packed));
133
134 #define BIFROST_FMA_OP_MSCALE (0x50 >> 3)
135
136 struct bifrost_fma_mscale {
137 unsigned src0 : 3;
138 unsigned src1 : 3;
139 unsigned src2 : 3;
140 unsigned src3 : 3;
141
142 /* If mscale_mode is set - an MSCALE specific mode. If it is not set, a
143 * regular outmod */
144 unsigned mode : 2;
145 unsigned mscale_mode : 1;
146
147 unsigned src0_abs : 1;
148 unsigned src1_neg : 1;
149 unsigned src2_neg : 1;
150 unsigned op : 5;
151 } __attribute__((packed));
152
153 #define BIFROST_ADD_OP_BLEND (0x1952c)
154 #define BIFROST_ADD_OP_FRCP_FAST_F32 (0x0cc00)
155 #define BIFROST_ADD_OP_FRCP_FAST_F16_X (0x0ce10)
156 #define BIFROST_ADD_OP_FRCP_FAST_F16_Y (0x0ce30)
157 #define BIFROST_ADD_OP_FRSQ_FAST_F32 (0x0cc20)
158 #define BIFROST_ADD_OP_FRSQ_FAST_F16_X (0x0ce50)
159 #define BIFROST_ADD_OP_FRSQ_FAST_F16_Y (0x0ce70)
160 #define BIFROST_ADD_OP_LOG2_HELP (0x0cc68)
161 #define BIFROST_ADD_OP_FEXP2_FAST (0x0cd58)
162
163 struct bifrost_add_inst {
164 unsigned src0 : 3;
165 unsigned op : 17;
166 } __attribute__((packed));
167
168 #define BIFROST_ADD_OP_LD_UBO_1 (0x0c1a0 >> 3)
169 #define BIFROST_ADD_OP_LD_UBO_2 (0x0c1e0 >> 3)
170 #define BIFROST_ADD_OP_LD_UBO_3 (0x0caa0 >> 3)
171 #define BIFROST_ADD_OP_LD_UBO_4 (0x0c220 >> 3)
172 #define BIFROST_ADD_SEL_16(swiz) ((0xea60 >> 3) | (swiz))
173
174 struct bifrost_add_2src {
175 unsigned src0 : 3;
176 unsigned src1 : 3;
177 unsigned op : 14;
178 } __attribute__((packed));
179
180 #define BIFROST_ADD_OP_FMAX32 (0x00)
181 #define BIFROST_ADD_OP_FMIN32 (0x01)
182 #define BIFROST_ADD_OP_FADD32 (0x02)
183
184 #define BIFROST_ADD_OP_FADD16 (0x0A)
185
186 struct bifrost_add_faddmin {
187 unsigned src0 : 3;
188 unsigned src1 : 3;
189 unsigned src1_abs : 1;
190 unsigned src0_neg : 1;
191 unsigned src1_neg : 1;
192 unsigned select : 2; /* swizzle_0 for fp16 */
193 unsigned outmod : 2; /* swizzle_1 for fp16 */
194 unsigned mode : 2;
195 unsigned src0_abs : 1;
196 unsigned op : 4;
197 } __attribute__((packed));
198
199 #define BIFROST_ADD_OP_FMAX16 (0x10)
200 #define BIFROST_ADD_OP_FMIN16 (0x12)
201
202 struct bifrost_add_fmin16 {
203 unsigned src0 : 3;
204 unsigned src1 : 3;
205 /* abs2 inferred as with FMA */
206 unsigned abs1 : 1;
207 unsigned src0_neg : 1;
208 unsigned src1_neg : 1;
209 unsigned src0_swizzle : 2;
210 unsigned src1_swizzle : 2;
211 unsigned mode : 2;
212 unsigned op : 5;
213 } __attribute__((packed));
214
215 #define BIFROST_ADD_OP_ST_VAR (0x19300 >> 8)
216
217 struct bifrost_st_vary {
218 unsigned src0 : 3;
219 unsigned src1 : 3;
220 unsigned src2 : 3;
221 unsigned channels : 2;
222 unsigned op : 9;
223 } __attribute__((packed));
224
225 #define BIFROST_ADD_OP_ATEST (0xc8f)
226
227 struct bifrost_add_atest {
228 /* gl_SampleMask (R60) */
229 unsigned src0 : 3;
230
231 /* Alpha value */
232 unsigned src1 : 3;
233
234 /* If half, X/Y select. If !half, always set */
235 unsigned component : 1;
236 unsigned half : 1;
237
238 unsigned op : 12;
239 } __attribute__((packed));
240
241 enum bifrost_outmod {
242 BIFROST_NONE = 0x0,
243 BIFROST_POS = 0x1,
244 BIFROST_SAT_SIGNED = 0x2,
245 BIFROST_SAT = 0x3,
246 };
247
248 enum bifrost_roundmode {
249 BIFROST_RTE = 0x0, /* round to even */
250 BIFROST_RTP = 0x1, /* round to positive */
251 BIFROST_RTN = 0x2, /* round to negative */
252 BIFROST_RTZ = 0x3 /* round to zero */
253 };
254
255 /* NONE: Same as fmax() and fmin() -- return the other
256 * number if any number is NaN. Also always return +0 if
257 * one argument is +0 and the other is -0.
258 *
259 * NAN_WINS: Instead of never returning a NaN, always return
260 * one. The "greater"/"lesser" NaN is always returned, first
261 * by checking the sign and then the mantissa bits.
262 *
263 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
264 * For min, implement src0 < src1 ? src0 : src1. This
265 * includes handling NaN's and signedness of 0 differently
266 * from above, since +0 and -0 compare equal and comparisons
267 * always return false for NaN's. As a result, this mode is
268 * *not* commutative.
269 *
270 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
271 * For min, implement src0 > src1 ? src1 : src0
272 */
273
274
275 enum bifrost_minmax_mode {
276 BIFROST_MINMAX_NONE = 0x0,
277 BIFROST_NAN_WINS = 0x1,
278 BIFROST_SRC1_WINS = 0x2,
279 BIFROST_SRC0_WINS = 0x3,
280 };
281
282 #define BIFROST_FMA_OP_FADD32 (0x58 >> 2)
283 #define BIFROST_FMA_OP_FMAX32 (0x40 >> 2)
284 #define BIFROST_FMA_OP_FMIN32 (0x44 >> 2)
285
286 struct bifrost_fma_add {
287 unsigned src0 : 3;
288 unsigned src1 : 3;
289 unsigned src1_abs : 1;
290 unsigned src0_neg : 1;
291 unsigned src1_neg : 1;
292 unsigned unk : 3;
293 unsigned src0_abs : 1;
294 enum bifrost_roundmode roundmode : 2;
295 enum bifrost_outmod outmod : 2;
296 unsigned op : 6;
297 } __attribute__((packed));
298
299 #define BIFROST_FMA_OP_FMAX16 (0xC0 >> 2)
300 #define BIFROST_FMA_OP_FMIN16 (0xCC >> 2)
301 #define BIFROST_FMA_OP_FADD16 (0xD8 >> 2)
302
303 struct bifrost_fma_add_minmax16 {
304 unsigned src0 : 3;
305 unsigned src1 : 3;
306 /* abs2 inferred as (src1 < src0) */
307 unsigned abs1 : 1;
308 unsigned src0_neg : 1;
309 unsigned src1_neg : 1;
310 unsigned src0_swizzle : 2;
311 unsigned src1_swizzle : 2;
312 unsigned mode : 2;
313 enum bifrost_outmod outmod : 2;
314 /* roundmode for add, min/max mode for min/max */
315 unsigned op : 6;
316 } __attribute__((packed));
317
318 #define BIFROST_FMA_OP_FMA (0x00)
319
320 struct bifrost_fma_fma {
321 unsigned src0 : 3;
322 unsigned src1 : 3;
323 unsigned src2 : 3;
324 unsigned src_expand : 3;
325 unsigned src0_abs : 1;
326 enum bifrost_roundmode roundmode : 2;
327 enum bifrost_outmod outmod : 2;
328 unsigned src0_neg : 1; /* 14 */
329 unsigned src2_neg : 1;
330 unsigned src1_abs : 1;
331 unsigned src2_abs : 1; /* 17 */
332 unsigned op : 2;
333 } __attribute__((packed));
334
335 #define BIFROST_FMA_OP_FMA16 (0x2)
336
337 struct bifrost_fma_fma16 {
338 unsigned src0 : 3;
339 unsigned src1 : 3;
340 unsigned src2 : 3;
341 unsigned swizzle_0 : 2;
342 unsigned swizzle_1 : 2;
343 enum bifrost_roundmode roundmode : 2;
344 enum bifrost_outmod outmod : 2;
345 unsigned src0_neg : 1;
346 unsigned src2_neg : 1;
347 unsigned swizzle_2 : 2;
348 unsigned op : 2;
349 } __attribute__((packed));
350
351 enum bifrost_csel_cond {
352 BIFROST_FEQ_F = 0x0,
353 BIFROST_FGT_F = 0x1,
354 BIFROST_FGE_F = 0x2,
355 BIFROST_IEQ_F = 0x3,
356 BIFROST_IGT_I = 0x4,
357 BIFROST_IGE_I = 0x5,
358 BIFROST_UGT_I = 0x6,
359 BIFROST_UGE_I = 0x7
360 };
361
362 #define BIFROST_FMA_OP_CSEL4 (0x5c)
363 #define BIFROST_FMA_OP_CSEL4_V16 (0xdc)
364
365 struct bifrost_csel4 {
366 unsigned src0 : 3;
367 unsigned src1 : 3;
368 unsigned src2 : 3;
369 unsigned src3 : 3;
370 enum bifrost_csel_cond cond : 3;
371 unsigned op : 8;
372 } __attribute__((packed));
373
374 #define BIFROST_FMA_OP_RSHIFT_NAND (0x60000 >> 12)
375 #define BIFROST_FMA_OP_RSHIFT_AND (0x61000 >> 12)
376 #define BIFROST_FMA_OP_LSHIFT_NAND (0x62000 >> 12)
377 #define BIFROST_FMA_OP_LSHIFT_AND (0x63000 >> 12)
378 #define BIFROST_FMA_OP_RSHIFT_XOR (0x64000 >> 12)
379 #define BIFROST_FMA_OP_LSHIFT_ADD_32 (0x65200 >> 6)
380 #define BIFROST_FMA_OP_LSHIFT_SUB_32 (0x65600 >> 6)
381 #define BIFROST_FMA_OP_LSHIFT_RSUB_32 (0x65a00 >> 6)
382 #define BIFROST_FMA_OP_RSHIFT_ADD_32 (0x65e00 >> 6)
383 #define BIFROST_FMA_OP_RSHIFT_SUB_32 (0x66200 >> 6)
384 #define BIFROST_FMA_OP_RSHIFT_RSUB_32 (0x66600 >> 6)
385
386 struct bifrost_shift_fma {
387 unsigned src0 : 3;
388 unsigned src1 : 3;
389 unsigned src2 : 3;
390 unsigned half : 3;
391 unsigned unk : 1; /* always set? */
392 unsigned invert_1 : 1; /* Inverts sources to combining op */
393 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
394 unsigned invert_2 : 1;
395 unsigned op : 8;
396 } __attribute__((packed));
397
398 struct bifrost_shift_add {
399 unsigned src0 : 3;
400 unsigned src1 : 3;
401 unsigned src2 : 3;
402 unsigned zero : 2;
403
404 unsigned invert_1 : 1;
405 unsigned invert_2 : 1;
406
407 unsigned op : 7;
408 } __attribute__((packed));
409
410 enum bifrost_fcmp_cond {
411 BIFROST_OEQ = 0,
412 BIFROST_OGT = 1,
413 BIFROST_OGE = 2,
414 BIFROST_UNE = 3,
415 BIFROST_OLT = 4,
416 BIFROST_OLE = 5,
417 };
418
419 #define BIFROST_FMA_OP_FCMP_GL (0x48000 >> 13)
420 #define BIFROST_FMA_OP_FCMP_D3D (0x4c000 >> 13)
421
422 struct bifrost_fma_fcmp {
423 unsigned src0 : 3;
424 unsigned src1 : 3;
425 unsigned src1_abs : 1;
426 unsigned unk1 : 1;
427 unsigned src1_neg : 1;
428 unsigned src_expand : 3;
429 unsigned src0_abs : 1;
430 enum bifrost_fcmp_cond cond : 3;
431 unsigned op : 7;
432 } __attribute__((packed));
433
434 struct bifrost_add_fcmp {
435 unsigned src0 : 3;
436 unsigned src1 : 3;
437 enum bifrost_fcmp_cond cond : 3;
438 unsigned src_expand : 2;
439 unsigned src0_abs : 1;
440 unsigned src1_abs : 1;
441 unsigned src1_neg : 1;
442 unsigned op : 6;
443 } __attribute__((packed));
444
445 #define BIFROST_FMA_OP_FCMP_GL_16 (0xc8000 >> 13)
446 #define BIFROST_FMA_OP_FCMP_D3D_16 (0xcc000 >> 13)
447
448 struct bifrost_fma_fcmp16 {
449 unsigned src0 : 3;
450 unsigned src1 : 3;
451
452 /* abs2 inferred */
453 unsigned abs1 : 1;
454 unsigned unk : 2;
455
456 unsigned src0_swizzle : 2;
457 unsigned src1_swizzle : 2;
458
459 enum bifrost_fcmp_cond cond : 3;
460 unsigned op : 7;
461 } __attribute__((packed));
462
463 struct bifrost_add_fcmp16 {
464 unsigned src0 : 3;
465 unsigned src1 : 3;
466 enum bifrost_fcmp_cond cond : 3;
467
468 unsigned src0_swizzle : 2;
469 unsigned src1_swizzle : 2;
470
471 /* No abs mods */
472 unsigned src0_neg : 1;
473
474 unsigned op : 6;
475 } __attribute__((packed));
476
477 enum bifrost_icmp_cond {
478 BIFROST_ICMP_IGT = 0,
479 BIFROST_ICMP_IGE = 1,
480 BIFROST_ICMP_UGT = 2,
481 BIFROST_ICMP_UGE = 3,
482 BIFROST_ICMP_EQ = 4,
483 BIFROST_ICMP_NEQ = 5,
484 };
485
486 struct bifrost_fma_icmp32 {
487 unsigned src0 : 3;
488 unsigned src1 : 3;
489 enum bifrost_icmp_cond cond : 3;
490 unsigned unk1 : 1; /* set */
491 unsigned d3d : 1;
492 unsigned op : 12;
493 } __attribute__((packed));
494
495 struct bifrost_fma_icmp16 {
496 unsigned src0 : 3;
497 unsigned src1 : 3;
498 unsigned unk : 5; /* 11010 */
499 enum bifrost_icmp_cond cond : 3;
500 unsigned op : 9;
501 } __attribute__((packed));
502
503 struct bifrost_add_icmp {
504 unsigned src0 : 3;
505 unsigned src1 : 3;
506 enum bifrost_icmp_cond cond : 3;
507 unsigned sz : 1; /* 1 for 32, 0 for 8 */
508 unsigned d3d : 1;
509 unsigned op : 9;
510 } __attribute__((packed));
511
512 /* Two sources for vectorization */
513 #define BIFROST_FMA_FLOAT32_TO_16 (0xdd000 >> 3)
514 #define BIFROST_ADD_FLOAT32_TO_16 (0x0EC00 >> 3)
515
516 enum bifrost_convert_mode {
517 BIFROST_CONV_UNK0 = 0,
518 BIFROST_CONV_F32_TO_I32 = 1,
519 BIFROST_CONV_F16_TO_I16 = 2,
520 BIFROST_CONV_I32_TO_F32 = 3,
521 BIFROST_CONV_I16_TO_X32 = 4,
522 BIFROST_CONV_F16_TO_F32 = 5,
523 BIFROST_CONV_I16_TO_F16 = 6,
524 BIFROST_CONV_UNK7 = 7
525 };
526
527 /* i16 to x32 */
528 #define BIFROST_CONVERT_4(is_unsigned, component, to_float) \
529 ((is_unsigned & 1) | ((component & 1) << 1) | ((to_float & 1) << 2) | \
530 ((0x3) << 3) | ((4) << 5) | 0x100)
531
532 /* f16 to f32 */
533 #define BIFROST_CONVERT_5(component) \
534 ((component & 1) | ((1) << 1) | ((5) << 5) | 0x100)
535
536 /* Other conversions */
537 #define BIFROST_CONVERT(is_unsigned, roundmode, swizzle, mode) \
538 ((is_unsigned & 1) | ((roundmode & 3) << 1) | ((swizzle & 3) << 3) | ((mode & 7) << 5))
539
540 #define BIFROST_FMA_CONVERT (0xe0000)
541 #define BIFROST_ADD_CONVERT (0x07800)
542
543 enum bifrost_ldst_type {
544 BIFROST_LDST_F16 = 0,
545 BIFROST_LDST_F32 = 1,
546 BIFROST_LDST_I32 = 2,
547 BIFROST_LDST_U32 = 3
548 };
549
550 #define BIFROST_ADD_OP_LD_VAR_ADDR (0x18000 >> 10)
551
552 struct bifrost_ld_var_addr {
553 unsigned src0 : 3;
554 unsigned src1 : 3;
555 unsigned location : 5;
556 enum bifrost_ldst_type type : 2;
557 unsigned op : 7;
558 } __attribute__((packed));
559
560 #define BIFROST_ADD_OP_LD_ATTR (0x08000 >> 12)
561
562 struct bifrost_ld_attr {
563 unsigned src0 : 3;
564 unsigned src1 : 3;
565 unsigned location : 5;
566 unsigned channels : 2; /* MALI_POSITIVE */
567 enum bifrost_ldst_type type : 2;
568 unsigned op : 5;
569 } __attribute__((packed));
570
571 enum bifrost_interp_mode {
572 BIFROST_INTERP_PER_FRAG = 0x0,
573 BIFROST_INTERP_CENTROID = 0x1,
574 BIFROST_INTERP_DEFAULT = 0x2,
575 BIFROST_INTERP_EXPLICIT = 0x3
576 };
577
578 #define BIFROST_ADD_OP_LD_VAR_16 (0x1a << 1)
579 #define BIFROST_ADD_OP_LD_VAR_32 (0x0a << 1)
580
581 struct bifrost_ld_var {
582 unsigned src0 : 3;
583
584 /* If top two bits set, indirect with src in bottom three */
585 unsigned addr : 5;
586
587 unsigned channels : 2; /* MALI_POSITIVE */
588 enum bifrost_interp_mode interp_mode : 2;
589 unsigned reuse : 1;
590 unsigned flat : 1;
591 unsigned op : 6;
592 } __attribute__((packed));
593
594 struct bifrost_tex_ctrl {
595 unsigned sampler_index : 4; // also used to signal indirects
596 unsigned tex_index : 7;
597 bool no_merge_index : 1; // whether to merge (direct) sampler & texture indices
598 bool filter : 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
599 unsigned unk0 : 2;
600 bool texel_offset : 1; // *Offset()
601 bool is_shadow : 1;
602 bool is_array : 1;
603 unsigned tex_type : 2; // 2D, 3D, Cube, Buffer
604 bool compute_lod : 1; // 0 for *Lod()
605 bool not_supply_lod : 1; // 0 for *Lod() or when a bias is applied
606 bool calc_gradients : 1; // 0 for *Grad()
607 unsigned unk1 : 1;
608 unsigned result_type : 4; // integer, unsigned, float TODO: why is this 4 bits?
609 unsigned unk2 : 4;
610 } __attribute__((packed));
611
612 struct bifrost_dual_tex_ctrl {
613 unsigned sampler_index0 : 2;
614 unsigned unk0 : 2;
615 unsigned tex_index0 : 2;
616 unsigned sampler_index1 : 2;
617 unsigned tex_index1 : 2;
618 unsigned unk1 : 22;
619 } __attribute__((packed));
620
621 #define BIFROST_ADD_OP_TEX_COMPACT_F32 (0x0b000 >> 10)
622 #define BIFROST_ADD_OP_TEX_COMPACT_F16 (0x1b000 >> 10)
623
624 struct bifrost_tex_compact {
625 unsigned src0 : 3;
626 unsigned src1 : 3;
627 unsigned tex_index : 3;
628 unsigned unknown : 1;
629 unsigned sampler_index : 3;
630 unsigned op : 7;
631 } __attribute__((packed));
632
633 enum branch_bit_size {
634 BR_SIZE_32 = 0,
635 BR_SIZE_16XX = 1,
636 BR_SIZE_16YY = 2,
637 // For the above combinations of bitsize and location, an extra bit is
638 // encoded via comparing the sources. The only possible source of ambiguity
639 // would be if the sources were the same, but then the branch condition
640 // would be always true or always false anyways, so we can ignore it. But
641 // this no longer works when comparing the y component to the x component,
642 // since it's valid to compare the y component of a source against its own
643 // x component. Instead, the extra bit is encoded via an extra bitsize.
644 BR_SIZE_16YX0 = 3,
645 BR_SIZE_16YX1 = 4,
646 BR_SIZE_32_AND_16X = 5,
647 BR_SIZE_32_AND_16Y = 6,
648 // Used for comparisons with zero and always-true, see below. I think this
649 // only works for integer comparisons.
650 BR_SIZE_ZERO = 7,
651 };
652
653 enum bifrost_reg_write_unit {
654 REG_WRITE_NONE = 0, // don't write
655 REG_WRITE_TWO, // write using reg2
656 REG_WRITE_THREE, // write using reg3
657 };
658
659 struct bifrost_regs {
660 unsigned uniform_const : 8;
661 unsigned reg2 : 6;
662 unsigned reg3 : 6;
663 unsigned reg0 : 5;
664 unsigned reg1 : 6;
665 unsigned ctrl : 4;
666 } __attribute__((packed));
667
668 enum bifrost_branch_cond {
669 BR_COND_LT = 0,
670 BR_COND_LE = 1,
671 BR_COND_GE = 2,
672 BR_COND_GT = 3,
673 // Equal vs. not-equal determined by src0/src1 comparison
674 BR_COND_EQ = 4,
675 // floating-point comparisons
676 // Becomes UNE when you flip the arguments
677 BR_COND_OEQ = 5,
678 // TODO what happens when you flip the arguments?
679 BR_COND_OGT = 6,
680 BR_COND_OLT = 7,
681 };
682
683 enum bifrost_branch_code {
684 BR_ALWAYS = 63,
685 };
686
687 struct bifrost_branch {
688 unsigned src0 : 3;
689
690 /* For BR_SIZE_ZERO, upper two bits become ctrl */
691 unsigned src1 : 3;
692
693 /* Offset source -- always uniform/const but
694 * theoretically could support indirect jumps? */
695 unsigned src2 : 3;
696
697 enum bifrost_branch_cond cond : 3;
698 enum branch_bit_size size : 3;
699
700 unsigned op : 5;
701 };
702
703 /* Clause packing */
704
705 #define BIFROST_FMA_NOP (0x701960 | BIFROST_SRC_STAGE)
706 #define BIFROST_ADD_NOP (0x3D960 | BIFROST_SRC_STAGE)
707
708 struct bifrost_fmt1 {
709 unsigned ins_0 : 3;
710 unsigned tag : 5;
711 uint64_t ins_1 : 64;
712 unsigned ins_2 : 11;
713 uint64_t header : 45;
714 } __attribute__((packed));
715
716 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
717 #define BIFROST_FMT1_FINAL 0b01001
718 #define BIFROST_FMT1_CONSTANTS 0b00001
719
720 #define BIFROST_FMTC_CONSTANTS 0b0011
721 #define BIFROST_FMTC_FINAL 0b0111
722
723 struct bifrost_fmt_constant {
724 unsigned pos : 4;
725 unsigned tag : 4;
726 uint64_t imm_1 : 60;
727 uint64_t imm_2 : 60;
728 } __attribute__((packed));
729
730 enum bifrost_reg_control {
731 BIFROST_WRITE_FMA_P2 = 1,
732 BIFROST_WRITE_FMA_P2_READ_P3 = 2,
733 BIFROST_FIRST_WRITE_FMA_P2_READ_P3 = 3,
734 BIFROST_READ_P3 = 4,
735 BIFROST_WRITE_ADD_P2 = 5,
736 BIFROST_WRITE_ADD_P2_READ_P3 = 6,
737 BIFROST_WRITE_ADD_P2_FMA_P3 = 7,
738
739 BIFROST_FIRST_NONE = 8,
740 BIFROST_FIRST_WRITE_FMA_P2 = 9,
741 /* INSTR_INVALID_ENC */
742 BIFROST_REG_NONE = 11,
743 BIFROST_FIRST_READ_P3 = 12,
744 BIFROST_FIRST_WRITE_ADD_P2 = 13,
745 BIFROST_FIRST_WRITE_ADD_P2_READ_P3 = 14,
746 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3 = 15
747 };
748
749 #endif