Debian Codegraph @

src/imagination/vulkan/pvr_usc.h

raw
1 /*
2 * Copyright © 2025 Imagination Technologies Ltd.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef PVR_USC_H
8 #define PVR_USC_H
9
10 /**
11 * \file pvr_usc.h
12 *
13 * \brief USC internal shader generation header.
14 */
15
16 #include "common/pvr_iface.h"
17 #include "compiler/shader_enums.h"
18 #include "pco/pco.h"
19 #include "pvr_common.h"
20 #include "pvr_formats.h"
21
22 struct pvr_load_op;
23
24 /* EOT shader generation. */
25 struct pvr_eot_props {
26 unsigned emit_count;
27
28 bool shared_words;
29 union {
30 const uint32_t *state_words;
31 const unsigned *state_regs;
32 };
33
34 unsigned msaa_samples;
35 unsigned num_output_regs;
36
37 uint64_t tile_buffer_addrs[PVR_MAX_COLOR_ATTACHMENTS];
38 };
39
40 nir_shader *pvr_usc_fs_pfo_passthrough_nir (pco_ctx *ctx);
41
42 pco_shader *pvr_usc_eot(pco_ctx *ctx,
43 struct pvr_eot_props *props,
44 const struct pvr_device_info *dev_info);
45
46 /* Transfer queue shader generation. */
47 struct pvr_tq_props {};
48
49 pco_shader *pvr_usc_tq(pco_ctx *ctx, struct pvr_tq_props *props);
50
51 /* Legacy transfer queue and loadop shader gen. */
52 enum pvr_int_coord_set_floats {
53 PVR_INT_COORD_SET_FLOATS_0 = 0,
54 PVR_INT_COORD_SET_FLOATS_4 = 1,
55 /* For rate changes to 0 base screen space. */
56 PVR_INT_COORD_SET_FLOATS_6 = 2,
57 PVR_INT_COORD_SET_FLOATS_NUM = 3
58 };
59
60 struct pvr_tq_shader_properties {
61 /* Controls whether this is an iterated shader. */
62 bool iterated;
63
64 /* Controls whether this is meant to be running at full rate. */
65 bool full_rate;
66
67 /* Sample specific channel of pixel. */
68 bool pick_component;
69
70 struct pvr_tq_layer_properties {
71 /* Controls whether we need to send the sample count to the TPU. */
72 bool msaa;
73
74 /* In case we run pixel rate, to do an USC resolve - but still in MSAA TPU
75 * samples.
76 */
77 uint32_t sample_count;
78
79 enum pvr_resolve_op resolve_op;
80
81 /* Selects the pixel conversion that we have to perform. */
82 enum pvr_transfer_pbe_pixel_src pbe_format;
83
84 /* Sampling from a 3D texture with a constant Z position. */
85 bool sample;
86
87 /* Number of float coefficients to get from screen space to texture space.
88 */
89 enum pvr_int_coord_set_floats layer_floats;
90
91 /* Unaligned texture address in bytes. */
92 uint32_t byte_unwind;
93
94 /* Enable bilinear filter in shader. */
95 bool linear;
96 } layer_props;
97 };
98
99 /* All offsets are in dwords. */
100 /* Devices may have more than 256 sh regs but we're expecting to use vary few so
101 * let's use uint8_t.
102 */
103 struct pvr_tq_frag_sh_reg_layout {
104 struct {
105 /* How many image sampler descriptors are present. */
106 uint8_t count;
107 /* TODO: See if we ever need more than one combined image sampler
108 * descriptor. If this is linked to the amount of layers used, we only
109 * ever use one layer so this wouldn't need to be an array.
110 */
111 struct {
112 uint8_t image;
113 uint8_t sampler;
114 } offsets[PVR_TRANSFER_MAX_IMAGES];
115 } combined_image_samplers;
116
117 /* TODO: Dynamic consts are used for various things so do this properly by
118 * having an actual layout instead of chucking them all together using an
119 * implicit layout.
120 */
121 struct {
122 /* How many dynamic consts regs have been allocated. */
123 uint8_t count;
124 uint8_t offset;
125 } dynamic_consts;
126
127 /* Total sh regs allocated by the driver. It does not include the regs
128 * necessary for compiler_out.
129 */
130 uint8_t driver_total;
131
132 /* Provided by the compiler to the driver to be appended to the shareds. */
133 /* No offset field since these will be appended at the end so driver_total
134 * can be used instead.
135 */
136 struct {
137 struct {
138 /* TODO: Remove this count and just use `compiler_out_total`? Or remove
139 * that one and use this one?
140 */
141 uint8_t count;
142 /* TODO: The array size is chosen arbitrarily based on the max
143 * constants currently produced by the compiler. Make this dynamic?
144 */
145 /* Values to fill in into each shared reg used for usc constants. */
146 uint32_t values[10];
147 } usc_constants;
148 } compiler_out;
149
150 /* Total extra sh regs needed by the compiler that need to be appended to the
151 * shareds by the driver.
152 */
153 uint8_t compiler_out_total;
154 };
155
156 pco_shader *pvr_uscgen_tq(pco_ctx *ctx,
157 const struct pvr_tq_shader_properties *shader_props,
158 struct pvr_tq_frag_sh_reg_layout *sh_reg_layout);
159
160 pco_shader *pvr_uscgen_loadop(pco_ctx *ctx, struct pvr_load_op *load_op);
161
162 /* Clear attachment shader generation. */
163 struct pvr_clear_attach_props {
164 unsigned dword_count;
165 unsigned offset;
166 bool uses_tile_buffer;
167 };
168
169 pco_shader *pvr_uscgen_clear_attach(pco_ctx *ctx,
170 struct pvr_clear_attach_props *props);
171
172 #define INDEX(d_c, o, u_t_b, i) \
173 if (props->dword_count == d_c && props->offset == o && \
174 props->uses_tile_buffer == u_t_b) \
175 return i
176
177 inline static unsigned
178 pvr_uscgen_clear_attach_index(struct pvr_clear_attach_props *props)
179 {
180 INDEX(1, 0, false, 0);
181 INDEX(1, 1, false, 1);
182 INDEX(1, 2, false, 2);
183 INDEX(1, 3, false, 3);
184 INDEX(2, 0, false, 4);
185 INDEX(2, 1, false, 5);
186 INDEX(2, 2, false, 6);
187 INDEX(3, 0, false, 7);
188 INDEX(3, 1, false, 8);
189 INDEX(4, 0, false, 9);
190
191 INDEX(1, 0, true, 10);
192 INDEX(1, 1, true, 11);
193 INDEX(1, 2, true, 12);
194 INDEX(1, 3, true, 13);
195 INDEX(2, 0, true, 14);
196 INDEX(2, 1, true, 15);
197 INDEX(2, 2, true, 16);
198 INDEX(3, 0, true, 17);
199 INDEX(3, 1, true, 18);
200 INDEX(4, 0, true, 19);
201
202 UNREACHABLE("Invalid clear attachment shader properties.");
203 }
204 #undef INDEX
205
206 pco_shader *
207 pvr_usc_zero_init_wg_mem(pco_ctx *ctx, unsigned start, unsigned count);
208
209 /* SPM load shader generation. */
210 struct pvr_spm_load_props {
211 unsigned output_reg_count;
212 unsigned tile_buffer_count;
213 bool is_multisampled;
214 };
215
216 static inline unsigned pvr_uscgen_spm_buffer_data(unsigned buffer_index,
217 bool addr)
218 {
219 switch (buffer_index) {
220 case 0:
221 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_0 : PVR_SPM_LOAD_DATA_BUF_TEX_0;
222
223 case 1:
224 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_1 : PVR_SPM_LOAD_DATA_BUF_TEX_1;
225
226 case 2:
227 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_2 : PVR_SPM_LOAD_DATA_BUF_TEX_2;
228
229 case 3:
230 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_3 : PVR_SPM_LOAD_DATA_BUF_TEX_3;
231
232 case 4:
233 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_4 : PVR_SPM_LOAD_DATA_BUF_TEX_4;
234
235 case 5:
236 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_5 : PVR_SPM_LOAD_DATA_BUF_TEX_5;
237
238 case 6:
239 return addr ? PVR_SPM_LOAD_DATA_BUF_ADDR_6 : PVR_SPM_LOAD_DATA_BUF_TEX_6;
240
241 default:
242 break;
243 }
244
245 UNREACHABLE("");
246 }
247
248 static inline unsigned
249 pvr_uscgen_spm_load_data_size(struct pvr_spm_load_props *props)
250 {
251 return PVR_SPM_LOAD_DATA_BUF_TEX_0 +
252 props->tile_buffer_count * (ROGUE_NUM_TEXSTATE_DWORDS +
253 (sizeof(uint64_t) / sizeof(uint32_t)));
254 }
255
256 pco_shader *pvr_uscgen_spm_load(pco_ctx *ctx, struct pvr_spm_load_props *props);
257
258 #define INDEX(o_r_c, t_b_c, i_m, i) \
259 if (props->output_reg_count == o_r_c && \
260 props->tile_buffer_count == t_b_c && props->is_multisampled == i_m) \
261 return i
262
263 inline static unsigned
264 pvr_uscgen_spm_load_index(struct pvr_spm_load_props *props)
265 {
266 INDEX(1, 0, false, 0);
267 INDEX(2, 0, false, 1);
268 INDEX(4, 0, false, 2);
269
270 INDEX(4, 1, false, 3);
271 INDEX(4, 2, false, 4);
272 INDEX(4, 3, false, 5);
273 INDEX(4, 4, false, 6);
274 INDEX(4, 5, false, 7);
275 INDEX(4, 6, false, 8);
276 INDEX(4, 7, false, 9);
277
278 INDEX(1, 0, true, 10);
279 INDEX(2, 0, true, 11);
280 INDEX(4, 0, true, 12);
281
282 INDEX(4, 1, true, 13);
283 INDEX(4, 2, true, 14);
284 INDEX(4, 3, true, 15);
285 INDEX(4, 4, true, 16);
286 INDEX(4, 5, true, 17);
287 INDEX(4, 6, true, 18);
288 INDEX(4, 7, true, 19);
289
290 UNREACHABLE("Invalid SPM load shader properties.");
291 }
292 #undef INDEX
293
294 #define PVR_NUM_SPM_LOAD_SHADERS 20U
295
296 #endif /* PVR_USC_H */