pan/bi: Pack ld_ubo ops
[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
101 struct bifrost_fma_inst {
102 unsigned src0 : 3;
103 unsigned op : 20;
104 } __attribute__((packed));
105
106 #define BIFROST_ADD_OP_BLEND (0x1952c)
107
108 struct bifrost_add_inst {
109 unsigned src0 : 3;
110 unsigned op : 17;
111 } __attribute__((packed));
112
113 #define BIFROST_ADD_OP_LD_UBO_1 (0x0c1a0 >> 3)
114 #define BIFROST_ADD_OP_LD_UBO_2 (0x0c1e0 >> 3)
115 #define BIFROST_ADD_OP_LD_UBO_3 (0x0caa0 >> 3)
116 #define BIFROST_ADD_OP_LD_UBO_4 (0x0c220 >> 3)
117
118 struct bifrost_add_2src {
119 unsigned src0 : 3;
120 unsigned src1 : 3;
121 unsigned op : 14;
122 } __attribute__((packed));
123
124 #define BIFROST_ADD_OP_ATEST (0xc8f)
125
126 struct bifrost_add_atest {
127 /* gl_SampleMask (R60) */
128 unsigned src0 : 3;
129
130 /* Alpha value */
131 unsigned src1 : 3;
132
133 /* If half, X/Y select. If !half, always set */
134 unsigned component : 1;
135 unsigned half : 1;
136
137 unsigned op : 12;
138 } __attribute__((packed));
139
140 enum bifrost_outmod {
141 BIFROST_NONE = 0x0,
142 BIFROST_POS = 0x1,
143 BIFROST_SAT_SIGNED = 0x2,
144 BIFROST_SAT = 0x3,
145 };
146
147 enum bifrost_roundmode {
148 BIFROST_RTE = 0x0, /* round to even */
149 BIFROST_RTP = 0x1, /* round to positive */
150 BIFROST_RTN = 0x2, /* round to negative */
151 BIFROST_RTZ = 0x3 /* round to zero */
152 };
153
154 /* NONE: Same as fmax() and fmin() -- return the other
155 * number if any number is NaN. Also always return +0 if
156 * one argument is +0 and the other is -0.
157 *
158 * NAN_WINS: Instead of never returning a NaN, always return
159 * one. The "greater"/"lesser" NaN is always returned, first
160 * by checking the sign and then the mantissa bits.
161 *
162 * SRC1_WINS: For max, implement src0 > src1 ? src0 : src1.
163 * For min, implement src0 < src1 ? src0 : src1. This
164 * includes handling NaN's and signedness of 0 differently
165 * from above, since +0 and -0 compare equal and comparisons
166 * always return false for NaN's. As a result, this mode is
167 * *not* commutative.
168 *
169 * SRC0_WINS: For max, implement src0 < src1 ? src1 : src0
170 * For min, implement src0 > src1 ? src1 : src0
171 */
172
173
174 enum bifrost_minmax_mode {
175 BIFROST_MINMAX_NONE = 0x0,
176 BIFROST_NAN_WINS = 0x1,
177 BIFROST_SRC1_WINS = 0x2,
178 BIFROST_SRC0_WINS = 0x3,
179 };
180
181 #define BIFROST_FMA_OP_FADD32 (0x58 >> 2)
182
183 struct bifrost_fma_add {
184 unsigned src0 : 3;
185 unsigned src1 : 3;
186 unsigned src1_abs : 1;
187 unsigned src0_neg : 1;
188 unsigned src1_neg : 1;
189 unsigned unk : 3;
190 unsigned src0_abs : 1;
191 enum bifrost_outmod outmod : 2;
192 enum bifrost_roundmode roundmode : 2;
193 unsigned op : 6;
194 } __attribute__((packed));
195
196 #define BIFROST_FMA_OP_FMA (0x00)
197
198 struct bifrost_fma_fma {
199 unsigned src0 : 3;
200 unsigned src1 : 3;
201 unsigned src2 : 3;
202 unsigned src_expand : 3;
203 unsigned src0_abs : 1;
204 unsigned unk : 4;
205 unsigned src0_neg : 1;
206 unsigned src2_neg : 1;
207 unsigned src1_abs : 1;
208 unsigned src2_abs : 1;
209 unsigned op : 5;
210 } __attribute__((packed));
211
212 enum bifrost_csel_cond {
213 BIFROST_FEQ_F = 0x0,
214 BIFROST_FGT_F = 0x1,
215 BIFROST_FGE_F = 0x2,
216 BIFROST_IEQ_F = 0x3,
217 BIFROST_IGT_I = 0x4,
218 BIFROST_IGE_I = 0x5,
219 BIFROST_UGT_I = 0x6,
220 BIFROST_UGE_I = 0x7
221 };
222
223 struct bifrost_csel4 {
224 unsigned src0 : 3;
225 unsigned src1 : 3;
226 unsigned src2 : 3;
227 unsigned src3 : 3;
228 enum bifrost_csel_cond cond : 3;
229 unsigned op : 8;
230 } __attribute__((packed));
231
232 struct bifrost_shift_fma {
233 unsigned src0 : 3;
234 unsigned src1 : 3;
235 unsigned src2 : 3;
236 unsigned half : 3; /* 000 for i32, 100 for i8, 111 for v2i16 */
237 unsigned unk : 1; /* always set? */
238 unsigned invert_1 : 1; /* Inverts sources to combining op */
239 /* For XOR, switches RSHIFT to LSHIFT since only one invert needed */
240 unsigned invert_2 : 1;
241 unsigned op : 8;
242 } __attribute__((packed));
243
244 struct bifrost_shift_add {
245 unsigned src0 : 3;
246 unsigned src1 : 3;
247 unsigned src2 : 3;
248 unsigned zero : 2;
249
250 unsigned invert_1 : 1;
251 unsigned invert_2 : 1;
252
253 unsigned op : 7;
254 } __attribute__((packed));
255
256 enum bifrost_ldst_type {
257 BIFROST_LDST_F16 = 0,
258 BIFROST_LDST_F32 = 1,
259 BIFROST_LDST_I32 = 2,
260 BIFROST_LDST_U32 = 3
261 };
262
263 struct bifrost_ld_var_addr {
264 unsigned src0 : 3;
265 unsigned src1 : 3;
266 unsigned location : 5;
267 enum bifrost_ldst_type type : 2;
268 unsigned op : 7;
269 } __attribute__((packed));
270
271 struct bifrost_ld_attr {
272 unsigned src0 : 3;
273 unsigned src1 : 3;
274 unsigned location : 5;
275 unsigned channels : 2; /* MALI_POSITIVE */
276 enum bifrost_ldst_type type : 2;
277 unsigned op : 5;
278 } __attribute__((packed));
279
280 enum bifrost_interp_mode {
281 BIFROST_INTERP_PER_FRAG = 0x0,
282 BIFROST_INTERP_CENTROID = 0x1,
283 BIFROST_INTERP_DEFAULT = 0x2,
284 BIFROST_INTERP_EXPLICIT = 0x3
285 };
286
287 #define BIFROST_ADD_OP_LD_VAR_16 (0x1a << 1)
288 #define BIFROST_ADD_OP_LD_VAR_32 (0x0a << 1)
289
290 struct bifrost_ld_var {
291 unsigned src0 : 3;
292
293 /* If top two bits set, indirect with src in bottom three */
294 unsigned addr : 5;
295
296 unsigned channels : 2; /* MALI_POSITIVE */
297 enum bifrost_interp_mode interp_mode : 2;
298 unsigned reuse : 1;
299 unsigned flat : 1;
300 unsigned op : 6;
301 } __attribute__((packed));
302
303 struct bifrost_tex_ctrl {
304 unsigned sampler_index : 4; // also used to signal indirects
305 unsigned tex_index : 7;
306 bool no_merge_index : 1; // whether to merge (direct) sampler & texture indices
307 bool filter : 1; // use the usual filtering pipeline (0 for texelFetch & textureGather)
308 unsigned unk0 : 2;
309 bool texel_offset : 1; // *Offset()
310 bool is_shadow : 1;
311 bool is_array : 1;
312 unsigned tex_type : 2; // 2D, 3D, Cube, Buffer
313 bool compute_lod : 1; // 0 for *Lod()
314 bool not_supply_lod : 1; // 0 for *Lod() or when a bias is applied
315 bool calc_gradients : 1; // 0 for *Grad()
316 unsigned unk1 : 1;
317 unsigned result_type : 4; // integer, unsigned, float TODO: why is this 4 bits?
318 unsigned unk2 : 4;
319 } __attribute__((packed));
320
321 struct bifrost_dual_tex_ctrl {
322 unsigned sampler_index0 : 2;
323 unsigned unk0 : 2;
324 unsigned tex_index0 : 2;
325 unsigned sampler_index1 : 2;
326 unsigned tex_index1 : 2;
327 unsigned unk1 : 22;
328 } __attribute__((packed));
329
330 enum branch_bit_size {
331 BR_SIZE_32 = 0,
332 BR_SIZE_16XX = 1,
333 BR_SIZE_16YY = 2,
334 // For the above combinations of bitsize and location, an extra bit is
335 // encoded via comparing the sources. The only possible source of ambiguity
336 // would be if the sources were the same, but then the branch condition
337 // would be always true or always false anyways, so we can ignore it. But
338 // this no longer works when comparing the y component to the x component,
339 // since it's valid to compare the y component of a source against its own
340 // x component. Instead, the extra bit is encoded via an extra bitsize.
341 BR_SIZE_16YX0 = 3,
342 BR_SIZE_16YX1 = 4,
343 BR_SIZE_32_AND_16X = 5,
344 BR_SIZE_32_AND_16Y = 6,
345 // Used for comparisons with zero and always-true, see below. I think this
346 // only works for integer comparisons.
347 BR_SIZE_ZERO = 7,
348 };
349
350 enum bifrost_reg_write_unit {
351 REG_WRITE_NONE = 0, // don't write
352 REG_WRITE_TWO, // write using reg2
353 REG_WRITE_THREE, // write using reg3
354 };
355
356 struct bifrost_regs {
357 unsigned uniform_const : 8;
358 unsigned reg2 : 6;
359 unsigned reg3 : 6;
360 unsigned reg0 : 5;
361 unsigned reg1 : 6;
362 unsigned ctrl : 4;
363 } __attribute__((packed));
364
365 enum bifrost_branch_cond {
366 BR_COND_LT = 0,
367 BR_COND_LE = 1,
368 BR_COND_GE = 2,
369 BR_COND_GT = 3,
370 // Equal vs. not-equal determined by src0/src1 comparison
371 BR_COND_EQ = 4,
372 // floating-point comparisons
373 // Becomes UNE when you flip the arguments
374 BR_COND_OEQ = 5,
375 // TODO what happens when you flip the arguments?
376 BR_COND_OGT = 6,
377 BR_COND_OLT = 7,
378 };
379
380 enum bifrost_branch_code {
381 BR_ALWAYS = 63,
382 };
383
384 struct bifrost_branch {
385 unsigned src0 : 3;
386
387 /* For BR_SIZE_ZERO, upper two bits become ctrl */
388 unsigned src1 : 3;
389
390 /* Offset source -- always uniform/const but
391 * theoretically could support indirect jumps? */
392 unsigned src2 : 3;
393
394 enum bifrost_branch_cond cond : 3;
395 enum branch_bit_size size : 3;
396
397 unsigned op : 5;
398 };
399
400 /* Clause packing */
401
402 #define BIFROST_FMA_NOP (0x701960)
403 #define BIFROST_ADD_NOP (0x3D960)
404
405 struct bifrost_fmt1 {
406 unsigned ins_0 : 3;
407 unsigned tag : 5;
408 uint64_t ins_1 : 64;
409 unsigned ins_2 : 11;
410 uint64_t header : 45;
411 } __attribute__((packed));
412
413 #define BIFROST_FMT1_INSTRUCTIONS 0b00101
414 #define BIFROST_FMT1_FINAL 0b01001
415 #define BIFROST_FMT1_CONSTANTS 0b00001
416
417 #define BIFROST_FMTC_CONSTANTS 0b0011
418 #define BIFROST_FMTC_FINAL 0b0111
419
420 struct bifrost_fmt_constant {
421 unsigned pos : 4;
422 unsigned tag : 4;
423 uint64_t imm_1 : 60;
424 uint64_t imm_2 : 60;
425 } __attribute__((packed));
426
427 enum bifrost_reg_control {
428 BIFROST_WRITE_FMA_P2 = 1,
429 BIFROST_WRITE_FMA_P2_READ_P3 = 2,
430 BIFROST_WRITE_FMA_P2_READ_P3_ALT = 3,
431 BIFROST_READ_P3 = 4,
432 BIFROST_WRITE_ADD_P2 = 5,
433 BIFROST_WRITE_ADD_P2_READ_P3 = 6,
434 BIFROST_WRITE_ADD_P2_FMA_P3 = 7,
435
436 BIFROST_FIRST_NONE = 8,
437 BIFROST_FIRST_WRITE_FMA_P2 = 9,
438 BIFROST_REG_NONE = 11,
439 BIFROST_FIRST_READ_P3 = 12,
440 BIFROST_FIRST_WRITE_ADD_P2 = 13,
441 BIFROST_FIRST_WRITE_ADD_P2_READ_P3 = 14,
442 BIFROST_FIRST_WRITE_ADD_P2_FMA_P3 = 15
443 };
444
445 #endif