Debian Codegraph @

src/panfrost/compiler/bifrost/valhall/valhall.h

raw
1 /*
2 * Copyright (C) 2021 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef __VALHALL_H
7 #define __VALHALL_H
8
9 #include <stdint.h>
10 #include "util/macros.h"
11 #include "bi_opcodes.h"
12 #include "valhall_enums.h"
13 #include "shader_enums.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 #define VA_NUM_GENERAL_SLOTS 3
20
21 extern const uint32_t valhall_immediates[32];
22
23 enum va_size {
24 VA_SIZE_8 = 0,
25 VA_SIZE_16 = 1,
26 VA_SIZE_32 = 2,
27 VA_SIZE_64 = 3,
28 };
29
30 enum va_unit {
31 /** Fused floating-point multiply-add */
32 VA_UNIT_FMA = 0,
33
34 /** Type conversion and basic arithmetic */
35 VA_UNIT_CVT = 1,
36
37 /** Special function unit */
38 VA_UNIT_SFU = 2,
39
40 /** Varying */
41 VA_UNIT_V = 3,
42
43 /** General load/store */
44 VA_UNIT_LS = 4,
45
46 /** Texture */
47 VA_UNIT_T = 5,
48
49 /** Fused varying and texture */
50 VA_UNIT_VT = 6,
51
52 /** Produces a message for a unit not otherwise specified */
53 VA_UNIT_NONE = 7
54 };
55
56 struct va_src_info {
57 bool absneg : 1;
58 bool swizzle : 1;
59 bool notted : 1;
60 bool lane : 1;
61 bool lanes : 1;
62 bool halfswizzle : 1;
63 bool widen : 1;
64 bool combine : 1;
65 enum va_size size : 2;
66 } __attribute__((packed));
67
68 struct va_opcode_info {
69 uint64_t exact;
70 struct va_src_info srcs[4];
71 uint8_t type_size : 8;
72 enum va_unit unit : 3;
73 unsigned nr_srcs : 3;
74 unsigned nr_staging_srcs : 2;
75 unsigned nr_staging_dests : 2;
76 bool has_dest : 1;
77 bool is_signed : 1;
78 bool clamp : 1;
79 bool saturate : 1;
80 bool rhadd : 1;
81 bool round_mode : 1;
82 bool condition : 1;
83 bool result_type : 1;
84 bool vecsize : 1;
85 bool register_format : 1;
86 bool slot : 1;
87 bool sr_count : 1;
88 bool sr_write_count : 1;
89 unsigned sr_control : 2;
90 };
91
92 extern const struct va_opcode_info valhall_opcodes[BI_NUM_OPCODES];
93
94 /* Bifrost specifies the source of bitwise operations as (A, B, shift), but
95 * Valhall specifies (A, shift, B). We follow Bifrost conventions in the
96 * compiler, so normalize.
97 *
98 * Bifrost specifies BLEND as staging + (coverage, blend descriptor), but
99 * Valhall specifies staging + (blend descriptor, coverage). Given we put
100 * staging sources first, this works out to the same swap as bitwise ops.
101 */
102
103 static inline bool
104 va_swap_12(enum bi_opcode op)
105 {
106 switch (op) {
107 case BI_OPCODE_BLEND:
108 case BI_OPCODE_LSHIFT_AND_I32:
109 case BI_OPCODE_LSHIFT_AND_V2I16:
110 case BI_OPCODE_LSHIFT_AND_V4I8:
111 case BI_OPCODE_LSHIFT_OR_I32:
112 case BI_OPCODE_LSHIFT_OR_V2I16:
113 case BI_OPCODE_LSHIFT_OR_V4I8:
114 case BI_OPCODE_LSHIFT_XOR_I32:
115 case BI_OPCODE_LSHIFT_XOR_V2I16:
116 case BI_OPCODE_LSHIFT_XOR_V4I8:
117 case BI_OPCODE_RSHIFT_AND_I32:
118 case BI_OPCODE_RSHIFT_AND_V2I16:
119 case BI_OPCODE_RSHIFT_AND_V4I8:
120 case BI_OPCODE_RSHIFT_OR_I32:
121 case BI_OPCODE_RSHIFT_OR_V2I16:
122 case BI_OPCODE_RSHIFT_OR_V4I8:
123 case BI_OPCODE_RSHIFT_XOR_I32:
124 case BI_OPCODE_RSHIFT_XOR_V2I16:
125 case BI_OPCODE_RSHIFT_XOR_V4I8:
126 return true;
127 default:
128 return false;
129 }
130 }
131
132 static inline struct va_src_info
133 va_src_info(enum bi_opcode op, unsigned src)
134 {
135 unsigned idx = (va_swap_12(op) && (src == 1 || src == 2)) ? (3 - src) : src;
136 return valhall_opcodes[op].srcs[idx];
137 }
138
139 static inline bool
140 va_flow_is_wait_or_none(enum va_flow flow)
141 {
142 return (flow <= VA_FLOW_WAIT);
143 }
144
145 static inline bool
146 va_is_valid_const_table(unsigned table)
147 {
148 return (table >= 0 && table <= 11) || (table >= 60 && table <= 63);
149 }
150
151 static inline uint32_t
152 va_res_fold_table_idx(uint32_t table)
153 {
154 switch (table) {
155 case 0 ... 11:
156 return table;
157 case 60 ... 63:
158 return table + 12 - 60;
159 default:
160 assert(!"Can't pack table");
161 return 0;
162 }
163 }
164
165 static inline bool
166 va_op_dest_modifier_does_convert(enum bi_opcode op)
167 {
168 switch (op) {
169 case BI_OPCODE_FADD_F32:
170 case BI_OPCODE_FADD_LSCALE_F32:
171 case BI_OPCODE_FABSNEG_F32:
172 case BI_OPCODE_FMA_F32:
173 return true;
174 default:
175 return false;
176 }
177 }
178
179 enum va_shader_output {
180 /* Output position data */
181 VA_SHADER_OUTPUT_POSITION,
182
183 /* Output position FIFO attributes */
184 VA_SHADER_OUTPUT_ATTRIB,
185
186 /* Output varying */
187 VA_SHADER_OUTPUT_VARY,
188
189 /* Number of variants, keep last */
190 VA_SHADER_OUTPUT_COUNT
191 };
192
193 #define VA_SHADER_OUTPUT_POSITION_BIT BITFIELD_BIT(VA_SHADER_OUTPUT_POSITION)
194 #define VA_SHADER_OUTPUT_ATTRIB_BIT BITFIELD_BIT(VA_SHADER_OUTPUT_ATTRIB)
195 #define VA_SHADER_OUTPUT_VARY_BIT BITFIELD_BIT(VA_SHADER_OUTPUT_VARY)
196
197 static inline enum va_shader_output
198 va_shader_output_from_loc(gl_varying_slot location)
199 {
200 switch (location) {
201 case VARYING_SLOT_POS:
202 return VA_SHADER_OUTPUT_POSITION;
203 case VARYING_SLOT_PSIZ:
204 case VARYING_SLOT_LAYER:
205 case VARYING_SLOT_PRIMITIVE_ID:
206 return VA_SHADER_OUTPUT_ATTRIB;
207 default:
208 return VA_SHADER_OUTPUT_VARY;
209 }
210 }
211
212 #ifdef __cplusplus
213 } /* extern C */
214 #endif
215
216 #endif