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>
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:
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
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
32 struct bifrost_header
{
34 // If true, convert any infinite result of any floating-point operation to
35 // the biggest representable number.
36 unsigned suppress_inf
: 1;
37 // Convert any NaN results to 0.
38 unsigned suppress_nan
: 1;
40 // true if the execution mask of the next clause is the same as the mask of
41 // the current clause.
42 unsigned back_to_back
: 1;
43 unsigned no_end_of_shader
: 1;
45 // Set to true for fragment shaders, to implement this bit of spec text
46 // from section 7.1.5 of the GLSL ES spec:
48 // "Stores to image and buffer variables performed by helper invocations
49 // have no effect on the underlying image or buffer memory."
51 // Helper invocations are threads (invocations) corresponding to pixels in
52 // a quad that aren't actually part of the triangle, but are included to
53 // make derivatives work correctly. They're usually turned on, but they
54 // need to be masked off for GLSL-level stores. This bit seems to be the
55 // only bit that's actually different between fragment shaders and other
56 // shaders, so this is probably what it's doing.
57 unsigned elide_writes
: 1;
58 // If backToBack is off:
59 // - true for conditional branches and fallthrough
60 // - false for unconditional branches
61 // The blob seems to always set it to true if back-to-back is on.
62 unsigned branch_cond
: 1;
63 // This bit is set when the next clause writes to the data register of some
65 unsigned datareg_writebarrier
: 1;
67 unsigned scoreboard_deps
: 8;
68 unsigned scoreboard_index
: 3;
69 unsigned clause_type
: 4;
70 unsigned unk3
: 1; // part of clauseType?
71 unsigned next_clause_type
: 4;
72 unsigned unk4
: 1; // part of nextClauseType?
73 } __attribute__((packed
));
75 enum bifrost_packed_src
{
76 BIFROST_SRC_PORT0
= 0,
77 BIFROST_SRC_PORT1
= 1,
78 BIFROST_SRC_PORT3
= 2,
79 BIFROST_SRC_STAGE
= 3,
80 BIFROST_SRC_CONST_LO
= 4,
81 BIFROST_SRC_CONST_HI
= 5,
82 BIFROST_SRC_PASS_FMA
= 6,
83 BIFROST_SRC_PASS_ADD
= 7,
86 struct bifrost_fma_inst
{
89 } __attribute__((packed
));
91 struct bifrost_add_inst
{
94 } __attribute__((packed
));
99 BIFROST_SAT_SIGNED
= 0x2,
103 enum bifrost_roundmode
{
104 BIFROST_RTE
= 0x0, /* round to even */
105 BIFROST_RTP
= 0x1, /* round to positive */
106 BIFROST_RTN
= 0x2, /* round to negative */
107 BIFROST_RTZ
= 0x3 /* round to zero */
110 /* NONE: Same as fmax() and fmin() -- return the other
111 * number if any number is NaN. Also always return +0 if
112 * one argument is +0 and the other is -0.
114 * NAN_WINS: Instead of never returning a NaN, always return
115 * one. The "greater"/"lesser" NaN is always returned, first
116 * by checking the sign and then the mantissa bits.
118 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
119 * For min, implement src0 < src1 ? src0 : src1. This
120 * includes handling NaN's and signedness of 0 differently
121 * from above, since +0 and -0 compare equal and comparisons
122 * always return false for NaN's. As a result, this mode is
125 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
126 * For min, implement src0 > src1 ? src1 : src0
130 enum bifrost_minmax_mode
{
131 BIFROST_MINMAX_NONE
= 0x0,
132 BIFROST_NAN_WINS
= 0x1,
133 BIFROST_SRC1_WINS
= 0x2,
134 BIFROST_SRC0_WINS
= 0x3,
137 struct bifrost_fma_add
{
140 unsigned src1_abs
: 1;
141 unsigned src0_neg
: 1;
142 unsigned src1_neg
: 1;
144 unsigned src0_abs
: 1;
145 enum bifrost_outmod outmod
: 2;
146 enum bifrost_roundmode roundmode
: 2;
148 } __attribute__((packed
));
150 #define BIFROST_FMA_OP_FMA (0x00)
152 struct bifrost_fma_fma
{
156 unsigned src_expand
: 3;
157 unsigned src0_abs
: 1;
159 unsigned src0_neg
: 1;
160 unsigned src2_neg
: 1;
161 unsigned src1_abs
: 1;
162 unsigned src2_abs
: 1;
164 } __attribute__((packed
));
166 enum bifrost_csel_cond
{
177 struct bifrost_csel4
{
182 enum bifrost_csel_cond cond
: 3;
184 } __attribute__((packed
));
186 struct bifrost_shift_fma
{
190 unsigned half
: 3; /* 000 for i32, 100 for i8, 111 for v2i16 */
191 unsigned unk
: 1; /* always set? */
192 unsigned invert_1
: 1; /* Inverts sources to combining op */
193 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
194 unsigned invert_2
: 1;
196 } __attribute__((packed
));
198 struct bifrost_shift_add
{
204 unsigned invert_1
: 1;
205 unsigned invert_2
: 1;
208 } __attribute__((packed
));
210 enum bifrost_ldst_type
{
211 BIFROST_LDST_F16
= 0,
212 BIFROST_LDST_F32
= 1,
213 BIFROST_LDST_I32
= 2,
217 struct bifrost_ld_var_addr
{
220 unsigned location
: 5;
221 enum bifrost_ldst_type type
: 2;
223 } __attribute__((packed
));
225 struct bifrost_ld_attr
{
228 unsigned location
: 5;
229 unsigned channels
: 2; /* MALI_POSITIVE */
230 enum bifrost_ldst_type type
: 2;
232 } __attribute__((packed
));
234 enum bifrost_interp_mode
{
235 BIFROST_INTERP_PER_FRAG
= 0x0,
236 BIFROST_INTERP_CENTROID
= 0x1,
237 BIFROST_INTERP_DEFAULT
= 0x2,
238 BIFROST_INTERP_EXPLICIT
= 0x3
241 struct bifrost_ld_var
{
244 /* If top two bits set, indirect with src in bottom three */
247 unsigned channels
: 2; /* MALI_POSITIVE */
248 enum bifrost_interp_mode interp_mode
: 2;
252 } __attribute__((packed
));
254 struct bifrost_tex_ctrl
{
255 unsigned sampler_index
: 4; // also used to signal indirects
256 unsigned tex_index
: 7;
257 bool no_merge_index
: 1; // whether to merge (direct) sampler & texture indices
258 bool filter
: 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
260 bool texel_offset
: 1; // *Offset()
263 unsigned tex_type
: 2; // 2D, 3D, Cube, Buffer
264 bool compute_lod
: 1; // 0 for *Lod()
265 bool not_supply_lod
: 1; // 0 for *Lod() or when a bias is applied
266 bool calc_gradients
: 1; // 0 for *Grad()
268 unsigned result_type
: 4; // integer, unsigned, float TODO: why is this 4 bits?
270 } __attribute__((packed
));
272 struct bifrost_dual_tex_ctrl
{
273 unsigned sampler_index0
: 2;
275 unsigned tex_index0
: 2;
276 unsigned sampler_index1
: 2;
277 unsigned tex_index1
: 2;
279 } __attribute__((packed
));
281 enum branch_bit_size
{
285 // For the above combinations of bitsize and location, an extra bit is
286 // encoded via comparing the sources. The only possible source of ambiguity
287 // would be if the sources were the same, but then the branch condition
288 // would be always true or always false anyways, so we can ignore it. But
289 // this no longer works when comparing the y component to the x component,
290 // since it's valid to compare the y component of a source against its own
291 // x component. Instead, the extra bit is encoded via an extra bitsize.
294 BR_SIZE_32_AND_16X
= 5,
295 BR_SIZE_32_AND_16Y
= 6,
296 // Used for comparisons with zero and always-true, see below. I think this
297 // only works for integer comparisons.
301 enum bifrost_reg_write_unit
{
302 REG_WRITE_NONE
= 0, // don't write
303 REG_WRITE_TWO
, // write using reg2
304 REG_WRITE_THREE
, // write using reg3
307 struct bifrost_regs
{
308 unsigned uniform_const
: 8;
314 } __attribute__((packed
));
316 enum bifrost_branch_cond
{
321 // Equal vs. not-equal determined by src0/src1 comparison
323 // floating-point comparisons
324 // Becomes UNE when you flip the arguments
326 // TODO what happens when you flip the arguments?
331 enum bifrost_branch_code
{
335 struct bifrost_branch
{
338 /* For BR_SIZE_ZERO, upper two bits become ctrl */
341 /* Offset source -- always uniform/const but
342 * theoretically could support indirect jumps? */
345 enum bifrost_branch_cond cond
: 3;
346 enum branch_bit_size size
: 3;
353 #define BIFROST_FMA_NOP (0x701960)
354 #define BIFROST_ADD_NOP (0x3D960)
356 struct bifrost_fmt1
{
361 uint64_t header
: 45;
362 } __attribute__((packed
));
364 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
365 #define BIFROST_FMT1_FINAL 0b01001
366 #define BIFROST_FMT1_CONSTANTS 0b00001
368 enum bifrost_reg_control
{
369 BIFROST_WRITE_FMA_P2
= 1,
370 BIFROST_WRITE_FMA_P2_READ_P3
= 2,
371 BIFROST_WRITE_FMA_P2_READ_P3_ALT
= 3,
373 BIFROST_WRITE_ADD_P2
= 5,
374 BIFROST_WRITE_ADD_P2_READ_P3
= 6,
375 BIFROST_WRITE_ADD_P2_FMA_P3
= 7,
377 BIFROST_FIRST_NONE
= 8,
378 BIFROST_FIRST_WRITE_FMA_P2
= 9,
379 BIFROST_REG_NONE
= 11,
380 BIFROST_FIRST_READ_P3
= 12,
381 BIFROST_FIRST_WRITE_ADD_P2
= 13,
382 BIFROST_FIRST_WRITE_ADD_P2_READ_P3
= 14,
383 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3
= 15