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 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
44 struct bifrost_header
{
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;
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;
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:
60 // "Stores to image and buffer variables performed by helper invocations
61 // have no effect on the underlying image or buffer memory."
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
77 unsigned datareg_writebarrier
: 1;
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
));
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,
98 struct bifrost_fma_inst
{
101 } __attribute__((packed
));
103 struct bifrost_add_inst
{
106 } __attribute__((packed
));
108 enum bifrost_outmod
{
111 BIFROST_SAT_SIGNED
= 0x2,
115 enum bifrost_roundmode
{
116 BIFROST_RTE
= 0x0, /* round to even */
117 BIFROST_RTP
= 0x1, /* round to positive */
118 BIFROST_RTN
= 0x2, /* round to negative */
119 BIFROST_RTZ
= 0x3 /* round to zero */
122 /* NONE: Same as fmax() and fmin() -- return the other
123 * number if any number is NaN. Also always return +0 if
124 * one argument is +0 and the other is -0.
126 * NAN_WINS: Instead of never returning a NaN, always return
127 * one. The "greater"/"lesser" NaN is always returned, first
128 * by checking the sign and then the mantissa bits.
130 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
131 * For min, implement src0 < src1 ? src0 : src1. This
132 * includes handling NaN's and signedness of 0 differently
133 * from above, since +0 and -0 compare equal and comparisons
134 * always return false for NaN's. As a result, this mode is
137 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
138 * For min, implement src0 > src1 ? src1 : src0
142 enum bifrost_minmax_mode
{
143 BIFROST_MINMAX_NONE
= 0x0,
144 BIFROST_NAN_WINS
= 0x1,
145 BIFROST_SRC1_WINS
= 0x2,
146 BIFROST_SRC0_WINS
= 0x3,
149 #define BIFROST_FMA_OP_FADD32 (0x58 >> 2)
151 struct bifrost_fma_add
{
154 unsigned src1_abs
: 1;
155 unsigned src0_neg
: 1;
156 unsigned src1_neg
: 1;
158 unsigned src0_abs
: 1;
159 enum bifrost_outmod outmod
: 2;
160 enum bifrost_roundmode roundmode
: 2;
162 } __attribute__((packed
));
164 #define BIFROST_FMA_OP_FMA (0x00)
166 struct bifrost_fma_fma
{
170 unsigned src_expand
: 3;
171 unsigned src0_abs
: 1;
173 unsigned src0_neg
: 1;
174 unsigned src2_neg
: 1;
175 unsigned src1_abs
: 1;
176 unsigned src2_abs
: 1;
178 } __attribute__((packed
));
180 enum bifrost_csel_cond
{
191 struct bifrost_csel4
{
196 enum bifrost_csel_cond cond
: 3;
198 } __attribute__((packed
));
200 struct bifrost_shift_fma
{
204 unsigned half
: 3; /* 000 for i32, 100 for i8, 111 for v2i16 */
205 unsigned unk
: 1; /* always set? */
206 unsigned invert_1
: 1; /* Inverts sources to combining op */
207 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
208 unsigned invert_2
: 1;
210 } __attribute__((packed
));
212 struct bifrost_shift_add
{
218 unsigned invert_1
: 1;
219 unsigned invert_2
: 1;
222 } __attribute__((packed
));
224 enum bifrost_ldst_type
{
225 BIFROST_LDST_F16
= 0,
226 BIFROST_LDST_F32
= 1,
227 BIFROST_LDST_I32
= 2,
231 struct bifrost_ld_var_addr
{
234 unsigned location
: 5;
235 enum bifrost_ldst_type type
: 2;
237 } __attribute__((packed
));
239 struct bifrost_ld_attr
{
242 unsigned location
: 5;
243 unsigned channels
: 2; /* MALI_POSITIVE */
244 enum bifrost_ldst_type type
: 2;
246 } __attribute__((packed
));
248 enum bifrost_interp_mode
{
249 BIFROST_INTERP_PER_FRAG
= 0x0,
250 BIFROST_INTERP_CENTROID
= 0x1,
251 BIFROST_INTERP_DEFAULT
= 0x2,
252 BIFROST_INTERP_EXPLICIT
= 0x3
255 #define BIFROST_ADD_OP_LD_VAR_16 (0x1a << 1)
256 #define BIFROST_ADD_OP_LD_VAR_32 (0x0a << 1)
258 struct bifrost_ld_var
{
261 /* If top two bits set, indirect with src in bottom three */
264 unsigned channels
: 2; /* MALI_POSITIVE */
265 enum bifrost_interp_mode interp_mode
: 2;
269 } __attribute__((packed
));
271 struct bifrost_tex_ctrl
{
272 unsigned sampler_index
: 4; // also used to signal indirects
273 unsigned tex_index
: 7;
274 bool no_merge_index
: 1; // whether to merge (direct) sampler & texture indices
275 bool filter
: 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
277 bool texel_offset
: 1; // *Offset()
280 unsigned tex_type
: 2; // 2D, 3D, Cube, Buffer
281 bool compute_lod
: 1; // 0 for *Lod()
282 bool not_supply_lod
: 1; // 0 for *Lod() or when a bias is applied
283 bool calc_gradients
: 1; // 0 for *Grad()
285 unsigned result_type
: 4; // integer, unsigned, float TODO: why is this 4 bits?
287 } __attribute__((packed
));
289 struct bifrost_dual_tex_ctrl
{
290 unsigned sampler_index0
: 2;
292 unsigned tex_index0
: 2;
293 unsigned sampler_index1
: 2;
294 unsigned tex_index1
: 2;
296 } __attribute__((packed
));
298 enum branch_bit_size
{
302 // For the above combinations of bitsize and location, an extra bit is
303 // encoded via comparing the sources. The only possible source of ambiguity
304 // would be if the sources were the same, but then the branch condition
305 // would be always true or always false anyways, so we can ignore it. But
306 // this no longer works when comparing the y component to the x component,
307 // since it's valid to compare the y component of a source against its own
308 // x component. Instead, the extra bit is encoded via an extra bitsize.
311 BR_SIZE_32_AND_16X
= 5,
312 BR_SIZE_32_AND_16Y
= 6,
313 // Used for comparisons with zero and always-true, see below. I think this
314 // only works for integer comparisons.
318 enum bifrost_reg_write_unit
{
319 REG_WRITE_NONE
= 0, // don't write
320 REG_WRITE_TWO
, // write using reg2
321 REG_WRITE_THREE
, // write using reg3
324 struct bifrost_regs
{
325 unsigned uniform_const
: 8;
331 } __attribute__((packed
));
333 enum bifrost_branch_cond
{
338 // Equal vs. not-equal determined by src0/src1 comparison
340 // floating-point comparisons
341 // Becomes UNE when you flip the arguments
343 // TODO what happens when you flip the arguments?
348 enum bifrost_branch_code
{
352 struct bifrost_branch
{
355 /* For BR_SIZE_ZERO, upper two bits become ctrl */
358 /* Offset source -- always uniform/const but
359 * theoretically could support indirect jumps? */
362 enum bifrost_branch_cond cond
: 3;
363 enum branch_bit_size size
: 3;
370 #define BIFROST_FMA_NOP (0x701960)
371 #define BIFROST_ADD_NOP (0x3D960)
373 struct bifrost_fmt1
{
378 uint64_t header
: 45;
379 } __attribute__((packed
));
381 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
382 #define BIFROST_FMT1_FINAL 0b01001
383 #define BIFROST_FMT1_CONSTANTS 0b00001
385 enum bifrost_reg_control
{
386 BIFROST_WRITE_FMA_P2
= 1,
387 BIFROST_WRITE_FMA_P2_READ_P3
= 2,
388 BIFROST_WRITE_FMA_P2_READ_P3_ALT
= 3,
390 BIFROST_WRITE_ADD_P2
= 5,
391 BIFROST_WRITE_ADD_P2_READ_P3
= 6,
392 BIFROST_WRITE_ADD_P2_FMA_P3
= 7,
394 BIFROST_FIRST_NONE
= 8,
395 BIFROST_FIRST_WRITE_FMA_P2
= 9,
396 BIFROST_REG_NONE
= 11,
397 BIFROST_FIRST_READ_P3
= 12,
398 BIFROST_FIRST_WRITE_ADD_P2
= 13,
399 BIFROST_FIRST_WRITE_ADD_P2_READ_P3
= 14,
400 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3
= 15