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