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