pan/bi: Add missing __attribute__((packed))
[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 struct bifrost_header {
33 unsigned unk0 : 7;
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;
39 unsigned unk1 : 2;
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;
44 unsigned unk2 : 2;
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:
47 //
48 // "Stores to image and buffer variables performed by helper invocations
49 // have no effect on the underlying image or buffer memory."
50 //
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
64 // previous clause.
65 unsigned datareg_writebarrier: 1;
66 unsigned datareg : 6;
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));
74
75 struct bifrost_fma_inst {
76 unsigned src0 : 3;
77 unsigned op : 20;
78 } __attribute__((packed));
79
80 struct bifrost_add_inst {
81 unsigned src0 : 3;
82 unsigned op : 17;
83 } __attribute__((packed));
84
85 enum bifrost_outmod {
86 BIFROST_NONE = 0x0,
87 BIFROST_POS = 0x1,
88 BIFROST_SAT_SIGNED = 0x2,
89 BIFROST_SAT = 0x3,
90 };
91
92 enum bifrost_roundmode {
93 BIFROST_RTE = 0x0, /* round to even */
94 BIFROST_RTP = 0x1, /* round to positive */
95 BIFROST_RTN = 0x2, /* round to negative */
96 BIFROST_RTZ = 0x3 /* round to zero */
97 };
98
99 /* NONE: Same as fmax() and fmin() -- return the other
100 * number if any number is NaN. Also always return +0 if
101 * one argument is +0 and the other is -0.
102 *
103 * NAN_WINS: Instead of never returning a NaN, always return
104 * one. The "greater"/"lesser" NaN is always returned, first
105 * by checking the sign and then the mantissa bits.
106 *
107 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
108 * For min, implement src0 < src1 ? src0 : src1. This
109 * includes handling NaN's and signedness of 0 differently
110 * from above, since +0 and -0 compare equal and comparisons
111 * always return false for NaN's. As a result, this mode is
112 * *not* commutative.
113 *
114 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
115 * For min, implement src0 > src1 ? src1 : src0
116 */
117
118
119 enum bifrost_minmax_mode {
120 BIFROST_MINMAX_NONE = 0x0,
121 BIFROST_NAN_WINS = 0x1,
122 BIFROST_SRC1_WINS = 0x2,
123 BIFROST_SRC0_WINS = 0x3,
124 };
125
126 struct bifrost_fma_add {
127 unsigned src0 : 3;
128 unsigned src1 : 3;
129 unsigned src1_abs : 1;
130 unsigned src0_neg : 1;
131 unsigned src1_neg : 1;
132 unsigned unk : 3;
133 unsigned src0_abs : 1;
134 enum bifrost_outmod outmod : 2;
135 enum bifrost_roundmode roundmode : 2;
136 unsigned op : 6;
137 } __attribute__((packed));
138
139 enum bifrost_csel_cond {
140 BIFROST_FEQ_F = 0x0,
141 BIFROST_FGT_F = 0x1,
142 BIFROST_FGE_F = 0x2,
143 BIFROST_IEQ_F = 0x3,
144 BIFROST_IGT_I = 0x4,
145 BIFROST_IGE_I = 0x5,
146 BIFROST_UGT_I = 0x6,
147 BIFROST_UGE_I = 0x7
148 };
149
150 struct bifrost_csel4 {
151 unsigned src0 : 3;
152 unsigned src1 : 3;
153 unsigned src2 : 3;
154 unsigned src3 : 3;
155 enum bifrost_csel_cond cond : 3;
156 unsigned op : 8;
157 } __attribute__((packed));
158
159 struct bifrost_shift_fma {
160 unsigned src0 : 3;
161 unsigned src1 : 3;
162 unsigned src2 : 3;
163 unsigned half : 3; /* 000 for i32, 100 for i8, 111 for v2i16 */
164 unsigned unk : 1; /* always set? */
165 unsigned invert_1 : 1; /* Inverts sources to combining op */
166 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
167 unsigned invert_2 : 1;
168 unsigned op : 8;
169 } __attribute__((packed));
170
171 struct bifrost_shift_add {
172 unsigned src0 : 3;
173 unsigned src1 : 3;
174 unsigned src2 : 3;
175 unsigned zero : 2;
176
177 unsigned invert_1 : 1;
178 unsigned invert_2 : 1;
179
180 unsigned op : 7;
181 } __attribute__((packed));
182
183 enum bifrost_ldst_type {
184 BIFROST_LDST_F16 = 0,
185 BIFROST_LDST_F32 = 1,
186 BIFROST_LDST_I32 = 2,
187 BIFROST_LDST_U32 = 3
188 };
189
190 struct bifrost_ld_var_addr {
191 unsigned src0 : 3;
192 unsigned src1 : 3;
193 unsigned location : 5;
194 enum bifrost_ldst_type type : 2;
195 unsigned op : 7;
196 } __attribute__((packed));
197
198 struct bifrost_ld_attr {
199 unsigned src0 : 3;
200 unsigned src1 : 3;
201 unsigned location : 5;
202 unsigned channels : 2; /* MALI_POSITIVE */
203 enum bifrost_ldst_type type : 2;
204 unsigned op : 5;
205 } __attribute__((packed));
206
207 enum bifrost_interp_mode {
208 BIFROST_INTERP_PER_FRAG = 0x0,
209 BIFROST_INTERP_CENTROID = 0x1,
210 BIFROST_INTERP_DEFAULT = 0x2,
211 BIFROST_INTERP_EXPLICIT = 0x3
212 };
213
214 struct bifrost_ld_var {
215 unsigned src0 : 3;
216
217 /* If top two bits set, indirect with src in bottom three */
218 unsigned addr : 5;
219
220 unsigned channels : 2; /* MALI_POSITIVE */
221 enum bifrost_interp_mode interp_mode : 2;
222 unsigned reuse : 1;
223 unsigned flat : 1;
224 unsigned op : 6;
225 } __attribute__((packed));
226
227 struct bifrost_tex_ctrl {
228 unsigned sampler_index : 4; // also used to signal indirects
229 unsigned tex_index : 7;
230 bool no_merge_index : 1; // whether to merge (direct) sampler & texture indices
231 bool filter : 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
232 unsigned unk0 : 2;
233 bool texel_offset : 1; // *Offset()
234 bool is_shadow : 1;
235 bool is_array : 1;
236 unsigned tex_type : 2; // 2D, 3D, Cube, Buffer
237 bool compute_lod : 1; // 0 for *Lod()
238 bool not_supply_lod : 1; // 0 for *Lod() or when a bias is applied
239 bool calc_gradients : 1; // 0 for *Grad()
240 unsigned unk1 : 1;
241 unsigned result_type : 4; // integer, unsigned, float TODO: why is this 4 bits?
242 unsigned unk2 : 4;
243 } __attribute__((packed));
244
245 struct bifrost_dual_tex_ctrl {
246 unsigned sampler_index0 : 2;
247 unsigned unk0 : 2;
248 unsigned tex_index0 : 2;
249 unsigned sampler_index1 : 2;
250 unsigned tex_index1 : 2;
251 unsigned unk1 : 22;
252 } __attribute__((packed));
253
254 enum branch_bit_size {
255 BR_SIZE_32 = 0,
256 BR_SIZE_16XX = 1,
257 BR_SIZE_16YY = 2,
258 // For the above combinations of bitsize and location, an extra bit is
259 // encoded via comparing the sources. The only possible source of ambiguity
260 // would be if the sources were the same, but then the branch condition
261 // would be always true or always false anyways, so we can ignore it. But
262 // this no longer works when comparing the y component to the x component,
263 // since it's valid to compare the y component of a source against its own
264 // x component. Instead, the extra bit is encoded via an extra bitsize.
265 BR_SIZE_16YX0 = 3,
266 BR_SIZE_16YX1 = 4,
267 BR_SIZE_32_AND_16X = 5,
268 BR_SIZE_32_AND_16Y = 6,
269 // Used for comparisons with zero and always-true, see below. I think this
270 // only works for integer comparisons.
271 BR_SIZE_ZERO = 7,
272 };
273
274 enum bifrost_reg_write_unit {
275 REG_WRITE_NONE = 0, // don't write
276 REG_WRITE_TWO, // write using reg2
277 REG_WRITE_THREE, // write using reg3
278 };
279
280 struct bifrost_regs {
281 unsigned uniform_const : 8;
282 unsigned reg2 : 6;
283 unsigned reg3 : 6;
284 unsigned reg0 : 5;
285 unsigned reg1 : 6;
286 unsigned ctrl : 4;
287 } __attribute__((packed));
288
289 enum bifrost_branch_cond {
290 BR_COND_LT = 0,
291 BR_COND_LE = 1,
292 BR_COND_GE = 2,
293 BR_COND_GT = 3,
294 // Equal vs. not-equal determined by src0/src1 comparison
295 BR_COND_EQ = 4,
296 // floating-point comparisons
297 // Becomes UNE when you flip the arguments
298 BR_COND_OEQ = 5,
299 // TODO what happens when you flip the arguments?
300 BR_COND_OGT = 6,
301 BR_COND_OLT = 7,
302 };
303
304 enum bifrost_branch_code {
305 BR_ALWAYS = 63,
306 };
307
308 struct bifrost_branch {
309 unsigned src0 : 3;
310
311 /* For BR_SIZE_ZERO, upper two bits become ctrl */
312 unsigned src1 : 3;
313
314 /* Offset source -- always uniform/const but
315 * theoretically could support indirect jumps? */
316 unsigned src2 : 3;
317
318 enum bifrost_branch_cond cond : 3;
319 enum branch_bit_size size : 3;
320
321 unsigned op : 5;
322 };
323
324 /* Clause packing */
325
326 #define BIFROST_FMA_NOP (0x701960)
327 #define BIFROST_ADD_NOP (0x3D960)
328
329 struct bifrost_fmt1 {
330 unsigned ins_0 : 3;
331 unsigned tag : 5;
332 uint64_t ins_1 : 64;
333 unsigned ins_2 : 11;
334 uint64_t header : 45;
335 } __attribute__((packed));
336
337 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
338 #define BIFROST_FMT1_FINAL 0b01001
339 #define BIFROST_FMT1_CONSTANTS 0b00001
340
341 enum bifrost_reg_control {
342 BIFROST_WRITE_FMA_P2 = 1,
343 BIFROST_WRITE_FMA_P2_READ_P3 = 2,
344 BIFROST_WRITE_FMA_P2_READ_P3_ALT = 3,
345 BIFROST_READ_P3 = 4,
346 BIFROST_WRITE_ADD_P2 = 5,
347 BIFROST_WRITE_ADD_P2_READ_P3 = 6,
348 BIFROST_WRITE_ADD_P2_FMA_P3 = 7,
349
350 BIFROST_FIRST_NONE = 8,
351 BIFROST_FIRST_WRITE_FMA_P2 = 9,
352 BIFROST_REG_NONE = 11,
353 BIFROST_FIRST_READ_P3 = 12,
354 BIFROST_FIRST_WRITE_ADD_P2 = 13,
355 BIFROST_FIRST_WRITE_ADD_P2_READ_P3 = 14,
356 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3 = 15
357 };
358
359 #endif