Debian Codegraph @

src/panfrost/compiler/bifrost/bifrost.h

raw
1 /*
2 * Copyright (C) 2019 Connor Abbott <[email protected]>
3 * Copyright (C) 2019 Lyude Paul <[email protected]>
4 * Copyright (C) 2019 Ryan Houdek <[email protected]>
5 * SPDX-License-Identifier: MIT
6 */
7
8 #ifndef __bifrost_h__
9 #define __bifrost_h__
10
11 #include <assert.h>
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <string.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 enum bifrost_message_type {
21 BIFROST_MESSAGE_NONE = 0,
22 BIFROST_MESSAGE_VARYING = 1,
23 BIFROST_MESSAGE_ATTRIBUTE = 2,
24 BIFROST_MESSAGE_TEX = 3,
25 BIFROST_MESSAGE_VARTEX = 4,
26 BIFROST_MESSAGE_LOAD = 5,
27 BIFROST_MESSAGE_STORE = 6,
28 BIFROST_MESSAGE_ATOMIC = 7,
29 BIFROST_MESSAGE_BARRIER = 8,
30 BIFROST_MESSAGE_BLEND = 9,
31 BIFROST_MESSAGE_TILE = 10,
32 /* type 11 reserved */
33 BIFROST_MESSAGE_Z_STENCIL = 12,
34 BIFROST_MESSAGE_ATEST = 13,
35 BIFROST_MESSAGE_JOB = 14,
36 BIFROST_MESSAGE_64BIT = 15
37 };
38
39 enum bifrost_ftz {
40 BIFROST_FTZ_DISABLE = 0,
41 BIFROST_FTZ_DX11 = 1,
42 BIFROST_FTZ_ALWAYS = 2,
43 BIFROST_FTZ_ABRUPT = 3
44 };
45
46 enum bifrost_exceptions {
47 BIFROST_EXCEPTIONS_ENABLED = 0,
48 BIFROST_EXCEPTIONS_DISABLED = 1,
49 BIFROST_EXCEPTIONS_PRECISE_DIVISION = 2,
50 BIFROST_EXCEPTIONS_PRECISE_SQRT = 3,
51 };
52
53 /* Describes clause flow control, with respect to control flow and branch
54 * reconvergence.
55 *
56 * Control flow may be considered back-to-back (execute clauses back-to-back),
57 * non-back-to-back (switch warps after clause before the next clause), write
58 * elision (back-to-back and elide register slot #3 write from the clause), or
59 * end of shader.
60 *
61 * Branch reconvergence may be disabled, enabled unconditionally, or enabled
62 * based on the program counter. A clause requires reconvergence if it has a
63 * successor that can be executed without first executing the clause itself.
64 * Separate iterations of a loop are treated separately here, so it is also the
65 * case for a loop exit where the iteration count is not warp-invariant.
66 *
67 */
68
69 enum bifrost_flow {
70 /* End-of-shader */
71 BIFROST_FLOW_END = 0,
72
73 /* Non back-to-back, PC-encoded reconvergence */
74 BIFROST_FLOW_NBTB_PC = 1,
75
76 /* Non back-to-back, unconditional reconvergence */
77 BIFROST_FLOW_NBTB_UNCONDITIONAL = 2,
78
79 /* Non back-to-back, no reconvergence */
80 BIFROST_FLOW_NBTB = 3,
81
82 /* Back-to-back, unconditional reconvergence */
83 BIFROST_FLOW_BTB_UNCONDITIONAL = 4,
84
85 /* Back-to-back, no reconvergence */
86 BIFROST_FLOW_BTB_NONE = 5,
87
88 /* Write elision, unconditional reconvergence */
89 BIFROST_FLOW_WE_UNCONDITIONAL = 6,
90
91 /* Write elision, no reconvergence */
92 BIFROST_FLOW_WE = 7,
93 };
94
95 enum bifrost_slot {
96 /* 0-5 are general purpose */
97 BIFROST_SLOT_ELDEST_DEPTH = 6,
98 BIFROST_SLOT_ELDEST_COLOUR = 7,
99 };
100
101 struct bifrost_header {
102 /* Reserved */
103 unsigned zero1 : 5;
104
105 /* Flush-to-zero mode, leave zero for GL */
106 enum bifrost_ftz flush_to_zero : 2;
107
108 /* Convert any infinite result of any floating-point operation to the
109 * biggest representable number */
110 unsigned suppress_inf : 1;
111
112 /* Convert NaN to +0.0 */
113 unsigned suppress_nan : 1;
114
115 /* Floating-point excception handling mode */
116 enum bifrost_exceptions float_exceptions : 2;
117
118 /* Enum describing the flow control, which matters for handling
119 * divergence and reconvergence efficiently */
120 enum bifrost_flow flow_control : 3;
121
122 /* Reserved */
123 unsigned zero2 : 1;
124
125 /* Terminate discarded threads, rather than continuing execution. Set
126 * for fragment shaders for standard GL behaviour of DISCARD. Also in a
127 * fragment shader, this disables helper invocations, so cannot be used
128 * in a shader that requires derivatives or texture LOD computation */
129 unsigned terminate_discarded_threads : 1;
130
131 /* If set, the hardware may prefetch the next clause. If false, the
132 * hardware may not. Clear for unconditional branches. */
133 unsigned next_clause_prefetch : 1;
134
135 /* If set, a barrier will be inserted after the clause waiting for all
136 * message passing instructions to read their staging registers, such
137 * that it is safe for the next clause to write them. */
138 unsigned staging_barrier : 1;
139 unsigned staging_register : 6;
140
141 /* Slots to wait on and slot to be used for message passing
142 * instructions respectively */
143 unsigned dependency_wait : 8;
144 unsigned dependency_slot : 3;
145
146 enum bifrost_message_type message_type : 5;
147 enum bifrost_message_type next_message_type : 5;
148 } __attribute__((packed));
149
150 enum bifrost_packed_src {
151 BIFROST_SRC_PORT0 = 0,
152 BIFROST_SRC_PORT1 = 1,
153 BIFROST_SRC_PORT2 = 2,
154 BIFROST_SRC_STAGE = 3,
155 BIFROST_SRC_FAU_LO = 4,
156 BIFROST_SRC_FAU_HI = 5,
157 BIFROST_SRC_PASS_FMA = 6,
158 BIFROST_SRC_PASS_ADD = 7,
159 };
160
161 struct bifrost_fma_inst {
162 unsigned src0 : 3;
163 unsigned op : 20;
164 } __attribute__((packed));
165
166 struct bifrost_add_inst {
167 unsigned src0 : 3;
168 unsigned op : 17;
169 } __attribute__((packed));
170
171 enum branch_bit_size {
172 BR_SIZE_32 = 0,
173 BR_SIZE_16XX = 1,
174 BR_SIZE_16YY = 2,
175 // For the above combinations of bitsize and location, an extra bit is
176 // encoded via comparing the sources. The only possible source of ambiguity
177 // would be if the sources were the same, but then the branch condition
178 // would be always true or always false anyways, so we can ignore it. But
179 // this no longer works when comparing the y component to the x component,
180 // since it's valid to compare the y component of a source against its own
181 // x component. Instead, the extra bit is encoded via an extra bitsize.
182 BR_SIZE_16YX0 = 3,
183 BR_SIZE_16YX1 = 4,
184 BR_SIZE_32_AND_16X = 5,
185 BR_SIZE_32_AND_16Y = 6,
186 // Used for comparisons with zero and always-true, see below. I think this
187 // only works for integer comparisons.
188 BR_SIZE_ZERO = 7,
189 };
190
191 struct bifrost_regs {
192 unsigned fau_idx : 8;
193 unsigned reg3 : 6;
194 unsigned reg2 : 6;
195 unsigned reg0 : 5;
196 unsigned reg1 : 6;
197 unsigned ctrl : 4;
198 } __attribute__((packed));
199
200 #define BIFROST_FMTC_CONSTANTS 0b0011
201 #define BIFROST_FMTC_FINAL 0b0111
202
203 struct bifrost_fmt_constant {
204 unsigned pos : 4;
205 unsigned tag : 4;
206 uint64_t imm_1 : 60;
207 uint64_t imm_2 : 60;
208 } __attribute__((packed));
209
210 /* Clause formats, encoded in a table */
211
212 enum bi_clause_subword {
213 /* Literal 3-bit values */
214 BI_CLAUSE_SUBWORD_LITERAL_0 = 0,
215 /* etc */
216 BI_CLAUSE_SUBWORD_LITERAL_7 = 7,
217
218 /* The value of the corresponding tuple in the corresponding bits */
219 BI_CLAUSE_SUBWORD_TUPLE_0 = 8,
220 /* etc */
221 BI_CLAUSE_SUBWORD_TUPLE_7 = 15,
222
223 /* Clause header */
224 BI_CLAUSE_SUBWORD_HEADER = 16,
225
226 /* Leave zero, but semantically distinct from literal 0 */
227 BI_CLAUSE_SUBWORD_RESERVED = 17,
228
229 /* Embedded constant 0 */
230 BI_CLAUSE_SUBWORD_CONSTANT = 18,
231
232 /* M bits controlling modifier for the constant */
233 BI_CLAUSE_SUBWORD_M = 19,
234
235 /* Z bit: 1 to begin encoding constants, 0 to terminate the clause */
236 BI_CLAUSE_SUBWORD_Z = 20,
237
238 /* Upper 3-bits of a given tuple and zero extended */
239 BI_CLAUSE_SUBWORD_UPPER_0 = 32,
240 /* etc */
241 BI_CLAUSE_SUBWORD_UPPER_7 = BI_CLAUSE_SUBWORD_UPPER_0 + 7,
242
243 /* Upper 3-bits of two tuples, concatenated and zero-extended */
244 BI_CLAUSE_SUBWORD_UPPER_23 = BI_CLAUSE_SUBWORD_UPPER_0 + 23,
245 BI_CLAUSE_SUBWORD_UPPER_56 = BI_CLAUSE_SUBWORD_UPPER_0 + 56,
246 };
247
248 #define L(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_LITERAL_0 + x))
249 #define U(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_UPPER_0 + x))
250 #define T(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_TUPLE_0 + x))
251 #define EC BI_CLAUSE_SUBWORD_CONSTANT
252 #define M BI_CLAUSE_SUBWORD_M
253 #define Z BI_CLAUSE_SUBWORD_Z
254 #define H BI_CLAUSE_SUBWORD_HEADER
255 #define R BI_CLAUSE_SUBWORD_RESERVED
256
257 struct bi_clause_format {
258 unsigned format; /* format number */
259 unsigned pos; /* index in the clause */
260 enum bi_clause_subword tag_1; /* 2-bits */
261 enum bi_clause_subword tag_2; /* 3-bits */
262 enum bi_clause_subword tag_3; /* 3-bits */
263 enum bi_clause_subword s0_s3; /* 60 bits */
264 enum bi_clause_subword s4; /* 15 bits */
265 enum bi_clause_subword s5_s6; /* 30 bits */
266 enum bi_clause_subword s7; /* 15 bits */
267 };
268
269 /* clang-format off */
270 static const struct bi_clause_format bi_clause_formats[] = {
271 { 0, 0, L(0), L(5), U(0), T(0), T(0), H, H },
272 { 0, 0, Z, L(1), U(0), T(0), T(0), H, H },
273 { 1, 1, Z, L(0), L(3), T(1), T(1), R, U(1) },
274 { 2, 1, L(0), L(4), U(1), T(1), T(1), T(2), T(2) },
275 { 3, 2, Z, L(0), L(4), EC, M, T(2), U(2) },
276 { 4, 2, L(0), L(0), L(1), T(3), T(3), T(2), U(23) },
277 { 4, 2, Z, L(0), L(5), T(3), T(3), T(2), U(23) },
278 { 5, 2, L(2), U(3), U(2), T(3), T(3), T(2), EC },
279 { 6, 3, Z, L(2), U(4), T(4), T(4), EC, EC },
280 { 7, 3, L(1), L(4), U(4), T(4), T(4), T(5), T(5) },
281 { 8, 4, Z, L(0), L(6), EC, M, T(5), U(5) },
282 { 9, 4, Z, L(0), L(7), T(6), T(6), T(5), U(56) },
283 { 10, 4, L(3), U(6), U(5), T(6), T(6), T(5), EC },
284 { 11, 5, Z, L(3), U(7), T(7), T(7), EC, EC },
285 };
286 /* clang-format on */
287
288 #undef L
289 #undef U
290 #undef T
291 #undef EC
292 #undef M
293 #undef Z
294 #undef H
295 #undef R
296
297 /* 32-bit modes for slots 2/3, as encoded in the register block. Other values
298 * are reserved. First part specifies behaviour of slot 2 (Idle, Read, Write
299 * Full, Write Low, Write High), second part behaviour of slot 3, and the last
300 * part specifies the source for the write (FMA, ADD, or MIX for FMA/ADD).
301 *
302 * IDLE is a special mode disabling both slots, except for the first
303 * instruction in the clause which uses IDLE_1 for the same purpose.
304 *
305 * All fields 0 used as sentinel for reserved encoding, so IDLE(_1) have FMA
306 * set (and ignored) as a placeholder to differentiate from reserved.
307 */
308 enum bifrost_reg_mode {
309 BIFROST_R_WL_FMA = 1,
310 BIFROST_R_WH_FMA = 2,
311 BIFROST_R_W_FMA = 3,
312 BIFROST_R_WL_ADD = 4,
313 BIFROST_R_WH_ADD = 5,
314 BIFROST_R_W_ADD = 6,
315 BIFROST_WL_WL_ADD = 7,
316 BIFROST_WL_WH_ADD = 8,
317 BIFROST_WL_W_ADD = 9,
318 BIFROST_WH_WL_ADD = 10,
319 BIFROST_WH_WH_ADD = 11,
320 BIFROST_WH_W_ADD = 12,
321 BIFROST_W_WL_ADD = 13,
322 BIFROST_W_WH_ADD = 14,
323 BIFROST_W_W_ADD = 15,
324 BIFROST_IDLE_1 = 16,
325 BIFROST_I_W_FMA = 17,
326 BIFROST_I_WL_FMA = 18,
327 BIFROST_I_WH_FMA = 19,
328 BIFROST_R_I = 20,
329 BIFROST_I_W_ADD = 21,
330 BIFROST_I_WL_ADD = 22,
331 BIFROST_I_WH_ADD = 23,
332 BIFROST_WL_WH_MIX = 24,
333 BIFROST_WH_WL_MIX = 26,
334 BIFROST_IDLE = 27,
335 };
336
337 enum bifrost_reg_op {
338 BIFROST_OP_IDLE = 0,
339 BIFROST_OP_READ = 1,
340 BIFROST_OP_WRITE = 2,
341 BIFROST_OP_WRITE_LO = 3,
342 BIFROST_OP_WRITE_HI = 4,
343 };
344
345 struct bifrost_reg_ctrl_23 {
346 enum bifrost_reg_op slot2;
347 enum bifrost_reg_op slot3;
348 bool slot3_fma;
349 };
350
351 /* clang-format off */
352 #ifndef __cplusplus
353 static const struct bifrost_reg_ctrl_23 bifrost_reg_ctrl_lut[32] = {
354 [BIFROST_R_WL_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_LO, true },
355 [BIFROST_R_WH_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_HI, true },
356 [BIFROST_R_W_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE, true },
357 [BIFROST_R_WL_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE_LO, false },
358 [BIFROST_R_WH_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE_HI, false },
359 [BIFROST_R_W_ADD] = { BIFROST_OP_READ, BIFROST_OP_WRITE, false },
360 [BIFROST_WL_WL_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_LO, false },
361 [BIFROST_WL_WH_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_HI, false },
362 [BIFROST_WL_W_ADD] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE, false },
363 [BIFROST_WH_WL_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_LO, false },
364 [BIFROST_WH_WH_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_HI, false },
365 [BIFROST_WH_W_ADD] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE, false },
366 [BIFROST_W_WL_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE_LO, false },
367 [BIFROST_W_WH_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE_HI, false },
368 [BIFROST_W_W_ADD] = { BIFROST_OP_WRITE, BIFROST_OP_WRITE, false },
369 [BIFROST_IDLE_1] = { BIFROST_OP_IDLE, BIFROST_OP_IDLE, true },
370 [BIFROST_I_W_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE, true },
371 [BIFROST_I_WL_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_LO, true },
372 [BIFROST_I_WH_FMA] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_HI, true },
373 [BIFROST_R_I] = { BIFROST_OP_READ, BIFROST_OP_IDLE, false },
374 [BIFROST_I_W_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE, false },
375 [BIFROST_I_WL_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_LO, false },
376 [BIFROST_I_WH_ADD] = { BIFROST_OP_IDLE, BIFROST_OP_WRITE_HI, false },
377 [BIFROST_WL_WH_MIX] = { BIFROST_OP_WRITE_LO, BIFROST_OP_WRITE_HI, false },
378 [BIFROST_WH_WL_MIX] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_LO, false },
379 [BIFROST_IDLE] = { BIFROST_OP_IDLE, BIFROST_OP_IDLE, true },
380 };
381 #endif
382 /* clang-format on */
383
384 /* Texture operator descriptors in various states. Usually packed in the
385 * compiler and stored as a constant */
386
387 enum bifrost_texture_operation_mode {
388 /* Dual texturing */
389 BIFROST_TEXTURE_OPERATION_DUAL = 1,
390
391 /* Single texturing */
392 BIFROST_TEXTURE_OPERATION_SINGLE = 3,
393 };
394
395 enum bifrost_index {
396 /* Both texture/sampler index immediate */
397 BIFROST_INDEX_IMMEDIATE_SHARED = 0,
398
399 /* Sampler index immediate, texture index from staging */
400 BIFROST_INDEX_IMMEDIATE_SAMPLER = 1,
401
402 /* Texture index immediate, sampler index from staging */
403 BIFROST_INDEX_IMMEDIATE_TEXTURE = 2,
404
405 /* Both indices from (separate) staging registers */
406 BIFROST_INDEX_REGISTER = 3,
407 };
408
409 enum bifrost_tex_op {
410 /* Given explicit derivatives, compute a gradient descriptor */
411 BIFROST_TEX_OP_GRDESC_DER = 4,
412
413 /* Given implicit derivatives (texture coordinates in a fragment
414 * shader), compute a gradient descriptor */
415 BIFROST_TEX_OP_GRDESC = 5,
416
417 /* Fetch a texel. Takes a staging register with LOD level / face index
418 * packed 16:16 */
419 BIFROST_TEX_OP_FETCH = 6,
420
421 /* Filtered texture */
422 BIFROST_TEX_OP_TEX = 7,
423 };
424
425 enum bifrost_lod_mode {
426 /* Takes two staging registers forming a 64-bit gradient descriptor
427 * (computed by a previous GRDESC or GRDESC_DER operation) */
428 BIFROST_LOD_MODE_GRDESC = 3,
429
430 /* Take a staging register with 8:8 fixed-point in bottom 16-bits
431 * specifying an explicit LOD */
432 BIFROST_LOD_MODE_EXPLICIT = 4,
433
434 /* Takes a staging register with bottom 16-bits as 8:8 fixed-point LOD
435 * bias and top 16-bit as 8:8 fixed-point lower bound (generally left
436 * zero), added and clamped to a computed LOD */
437 BIFROST_LOD_MODE_BIAS = 5,
438
439 /* Set LOD to zero */
440 BIFROST_LOD_MODE_ZERO = 6,
441
442 /* Compute LOD */
443 BIFROST_LOD_MODE_COMPUTE = 7,
444 };
445
446 enum bifrost_texture_format {
447 /* 16-bit floating point, with optional clamping */
448 BIFROST_TEXTURE_FORMAT_F16 = 0,
449 BIFROST_TEXTURE_FORMAT_F16_POS = 1,
450 BIFROST_TEXTURE_FORMAT_F16_PM1 = 2,
451 BIFROST_TEXTURE_FORMAT_F16_1 = 3,
452
453 /* 32-bit floating point, with optional clamping */
454 BIFROST_TEXTURE_FORMAT_F32 = 4,
455 BIFROST_TEXTURE_FORMAT_F32_POS = 5,
456 BIFROST_TEXTURE_FORMAT_F32_PM1 = 6,
457 BIFROST_TEXTURE_FORMAT_F32_1 = 7,
458 };
459
460 enum bifrost_texture_format_full {
461 /* Transclude bifrost_texture_format from above */
462
463 /* Integers, unclamped */
464 BIFROST_TEXTURE_FORMAT_U16 = 12,
465 BIFROST_TEXTURE_FORMAT_S16 = 13,
466 BIFROST_TEXTURE_FORMAT_U32 = 14,
467 BIFROST_TEXTURE_FORMAT_S32 = 15,
468 };
469
470 enum bifrost_texture_fetch {
471 /* Default texelFetch */
472 BIFROST_TEXTURE_FETCH_TEXEL = 1,
473
474 /* Deprecated, fetches 4x U32 of a U8 x 4 texture. Do not use. */
475 BIFROST_TEXTURE_FETCH_GATHER4_RGBA = 3,
476
477 /* Gathers */
478 BIFROST_TEXTURE_FETCH_GATHER4_R = 4,
479 BIFROST_TEXTURE_FETCH_GATHER4_G = 5,
480 BIFROST_TEXTURE_FETCH_GATHER4_B = 6,
481 BIFROST_TEXTURE_FETCH_GATHER4_A = 7
482 };
483
484 struct bifrost_texture_operation {
485 union {
486 struct {
487 /* If immediate_indices is set:
488 * - immediate sampler index
489 * - index used as texture index
490 * Otherwise:
491 * - bifrost_single_index in lower 2 bits
492 * - 0x3 in upper 2 bits (single-texturing)
493 */
494 unsigned sampler_index_or_mode : 4;
495 unsigned index : 7;
496 bool immediate_indices : 1;
497 enum bifrost_tex_op op : 3;
498
499 /* If set for TEX/FETCH, loads texel offsets and multisample index from
500 * a staging register containing offset_x:offset_y:offset_z:ms_index
501 * packed 8:8:8:8. Offsets must be in [-31, +31]. If set for
502 * GRDESC(_DER), disable LOD bias. */
503 bool offset_or_bias_disable : 1;
504
505 /* If set for TEX/FETCH, loads fp32 shadow comparison value from a
506 * staging register. Implies fetch_component = gather4_r. If set for
507 * GRDESC(_DER), disables LOD clamping. */
508 bool shadow_or_clamp_disable : 1;
509
510 /* If set, loads an uint32 array index from a staging register. */
511 bool array : 1;
512
513 /* Texture dimension, or 0 for a cubemap */
514 unsigned dimension : 2;
515
516 /* Method to compute LOD value or for a FETCH, the
517 * bifrost_texture_fetch component specification */
518 enum bifrost_lod_mode lod_or_fetch : 3;
519
520 /* Reserved */
521 unsigned zero : 1;
522
523 /* Register format for the result */
524 enum bifrost_texture_format_full format : 4;
525
526 /* Write mask for the result */
527 unsigned mask : 4;
528 };
529
530 uint32_t packed;
531 };
532 } __attribute__((packed));
533
534 struct bifrost_dual_texture_operation {
535 unsigned primary_sampler_index : 2;
536 unsigned mode : 2; /* 0x1 for dual */
537 unsigned primary_texture_index : 2;
538 unsigned secondary_sampler_index : 2;
539 unsigned secondary_texture_index : 2;
540
541 /* Leave zero for dual texturing */
542 unsigned reserved : 1;
543 unsigned index_mode_zero : 1;
544
545 /* Base staging register to write the secondary results to */
546 unsigned secondary_register : 6;
547
548 /* Format/mask for each texture */
549 enum bifrost_texture_format secondary_format : 3;
550 unsigned secondary_mask : 4;
551
552 enum bifrost_texture_format primary_format : 3;
553 unsigned primary_mask : 4;
554 } __attribute__((packed));
555
556 static inline uint32_t
557 bi_dual_tex_as_u32(struct bifrost_dual_texture_operation desc)
558 {
559 uint32_t desc_u;
560 memcpy(&desc_u, &desc, sizeof(desc));
561
562 return desc_u;
563 }
564
565 #define BIFROST_MEGA_SAMPLE 128
566 #define BIFROST_ALL_SAMPLES 255
567 #define BIFROST_CURRENT_PIXEL 255
568
569 struct bifrost_pixel_indices {
570 unsigned sample : 8;
571 unsigned rt : 8;
572 unsigned x : 8;
573 unsigned y : 8;
574 } __attribute__((packed));
575
576 enum bi_constmod {
577 BI_CONSTMOD_NONE,
578 BI_CONSTMOD_PC_LO,
579 BI_CONSTMOD_PC_HI,
580 BI_CONSTMOD_PC_LO_HI
581 };
582
583 struct bi_constants {
584 /* Raw constant values */
585 /* There are at most 6 constants per clause, but internally
586 * we can use an extra slot for modifiers, so give room for 7
587 */
588 uint64_t raw[7];
589
590 /* Associated modifier derived from M values */
591 enum bi_constmod mods[7];
592 };
593
594 /* FAU selectors for constants are out-of-order, construct the top bits
595 * here given a embedded constant index in a clause */
596
597 static inline unsigned
598 bi_constant_field(unsigned idx)
599 {
600 const unsigned values[] = {4, 5, 6, 7, 2, 3};
601
602 assert(idx <= 5);
603 return values[idx] << 4;
604 }
605
606 #ifdef __cplusplus
607 } /* extern C */
608 #endif
609
610 #endif