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