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