Debian Codegraph @

src/imagination/include/hwdef/rogue_hw_utils.h

raw
1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 /* This file is based on rgxdefs.h and should only contain function-like macros
25 * and inline functions. Any object-like macros should instead appear in
26 * rogue_hw_defs.h.
27 */
28
29 #ifndef ROGUE_HW_UTILS_H
30 #define ROGUE_HW_UTILS_H
31
32 #include <stdint.h>
33
34 #include "pvr_types.h"
35
36 #define __pvr_address_type pvr_dev_addr_t
37 #define __pvr_get_address(pvr_dev_addr) (pvr_dev_addr).addr
38 /* clang-format off */
39 #define __pvr_make_address(addr_u64) PVR_DEV_ADDR(addr_u64)
40 /* clang-format on */
41
42 #include "csbgen/rogue/cdm.h"
43 #include "csbgen/rogue/lls.h"
44
45 #undef __pvr_make_address
46 #undef __pvr_get_address
47 #undef __pvr_address_type
48
49 #include "rogue_hw_defs.h"
50 #include "pvr_device_info.h"
51 #include "util/compiler.h"
52 #include "util/macros.h"
53
54 #include "pvr_hw_utils.h"
55
56 static inline void
57 rogue_get_isp_samples_per_tile_xy(const struct pvr_device_info *dev_info,
58 uint32_t samples,
59 uint32_t *const x_out,
60 uint32_t *const y_out)
61 {
62 const uint32_t tile_size_x =
63 PVR_GET_FEATURE_VALUE(dev_info, tile_size_x, 0U);
64 const uint32_t tile_size_y =
65 PVR_GET_FEATURE_VALUE(dev_info, tile_size_y, 0U);
66 const uint32_t samples_per_pixel =
67 PVR_GET_FEATURE_VALUE(dev_info, isp_samples_per_pixel, 0U);
68
69 #if !defined(NDEBUG)
70 switch (samples_per_pixel) {
71 case 1:
72 case 2:
73 case 4:
74 break;
75 default:
76 assert(!"Unsupported ISP samples per pixel");
77 }
78 #endif
79
80 *x_out = tile_size_x;
81 *y_out = tile_size_y;
82
83 switch (samples) {
84 case 1:
85 break;
86 case 2:
87 if (samples_per_pixel == 2 || samples_per_pixel == 4)
88 *y_out *= 2;
89
90 break;
91 case 4:
92 if (samples_per_pixel == 2 || samples_per_pixel == 4)
93 *x_out *= 2;
94
95 if (samples_per_pixel == 4)
96 *y_out *= 2;
97
98 break;
99 case 8:
100 if (samples_per_pixel == 2)
101 *y_out *= 2;
102 break;
103 default:
104 assert(!"Unsupported number of samples");
105 }
106 }
107
108 static void rogue_get_isp_scale_xy_from_samples(const uint32_t samples,
109 uint32_t *const x_scale_out,
110 uint32_t *const y_scale_out)
111 {
112 switch (samples) {
113 case 1:
114 *x_scale_out = 1;
115 *y_scale_out = 1;
116 break;
117 case 2:
118 *x_scale_out = 1;
119 *y_scale_out = 2;
120 break;
121 case 4:
122 *x_scale_out = 2;
123 *y_scale_out = 2;
124 break;
125 case 8:
126 *x_scale_out = 2;
127 *y_scale_out = 4;
128 break;
129 default:
130 UNREACHABLE("Unsupported number of samples");
131 }
132 }
133
134 static inline void
135 rogue_get_isp_num_tiles_xy(const struct pvr_device_info *dev_info,
136 uint32_t samples,
137 uint32_t width,
138 uint32_t height,
139 uint32_t *const x_out,
140 uint32_t *const y_out)
141 {
142 uint32_t tile_samples_x;
143 uint32_t tile_samples_y;
144 uint32_t scale_x;
145 uint32_t scale_y;
146
147 rogue_get_isp_samples_per_tile_xy(dev_info,
148 samples,
149 &tile_samples_x,
150 &tile_samples_y);
151
152 rogue_get_isp_scale_xy_from_samples(samples, &scale_x, &scale_y);
153
154 *x_out = DIV_ROUND_UP(width * scale_x, tile_samples_x);
155 *y_out = DIV_ROUND_UP(height * scale_y, tile_samples_y);
156
157 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
158 assert(PVR_GET_FEATURE_VALUE(dev_info,
159 simple_parameter_format_version,
160 0U) == 2U);
161 /* Align to a 2x2 tile block. */
162 *x_out = ALIGN_POT(*x_out, 2);
163 *y_out = ALIGN_POT(*y_out, 2);
164 }
165 }
166
167 static inline void
168 rogue_get_zls_tile_size_xy(const struct pvr_device_info *dev_info,
169 uint32_t *const x_out,
170 uint32_t *const y_out)
171 {
172 uint32_t version = 0;
173 bool has_version;
174
175 has_version =
176 !PVR_FEATURE_VALUE(dev_info, simple_parameter_format_version, &version);
177
178 *x_out = PVR_GET_FEATURE_VALUE(dev_info, tile_size_x, 0U);
179 *y_out = PVR_GET_FEATURE_VALUE(dev_info, tile_size_y, 0U);
180
181 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format) &&
182 has_version && version == 2) {
183 *x_out *= 2;
184 *y_out *= 2;
185 }
186 }
187
188 static inline uint32_t
189 rogue_get_max_output_regs_per_pixel(const struct pvr_device_info *dev_info)
190 {
191 if (PVR_HAS_FEATURE(dev_info, eight_output_registers))
192 return 8U;
193
194 return 4U;
195 }
196
197 static inline void
198 rogue_get_num_macrotiles_xy(const struct pvr_device_info *dev_info,
199 uint32_t *const x_out,
200 uint32_t *const y_out)
201 {
202 uint32_t version;
203
204 if (PVR_FEATURE_VALUE(dev_info, simple_parameter_format_version, &version))
205 version = 0;
206
207 if (!PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format) ||
208 version == 2) {
209 *x_out = 4;
210 *y_out = 4;
211 } else {
212 *x_out = 1;
213 *y_out = 1;
214 }
215 }
216
217 static inline uint32_t
218 rogue_get_macrotile_array_size(const struct pvr_device_info *dev_info)
219 {
220 uint32_t num_macrotiles_x;
221 uint32_t num_macrotiles_y;
222
223 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format))
224 return 0;
225
226 rogue_get_num_macrotiles_xy(dev_info, &num_macrotiles_x, &num_macrotiles_y);
227
228 return num_macrotiles_x * num_macrotiles_y * 8U;
229 }
230
231 /* Region header size in bytes. */
232 static inline uint32_t
233 rogue_get_region_header_size(const struct pvr_device_info *dev_info)
234 {
235 uint32_t version;
236
237 if (PVR_FEATURE_VALUE(dev_info, simple_parameter_format_version, &version))
238 version = 0;
239
240 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format) &&
241 version == 2) {
242 return 6;
243 }
244
245 return 5;
246 }
247
248 static inline uint32_t
249 rogue_get_render_size_max(const struct pvr_device_info *dev_info)
250 {
251 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format))
252 if (!PVR_HAS_FEATURE(dev_info, screen_size8K))
253 return 4096U;
254
255 return 8192U;
256 }
257
258 #define rogue_get_render_size_max_x(dev_info) \
259 rogue_get_render_size_max(dev_info)
260
261 #define rogue_get_render_size_max_y(dev_info) \
262 rogue_get_render_size_max(dev_info)
263
264 static inline uint32_t
265 rogue_get_render_size_max_z(const struct pvr_device_info *dev_info)
266 {
267 switch (dev_info->ident.arch) {
268 case PVR_DEVICE_ARCH_ROGUE:
269 return 2048;
270 default:
271 UNREACHABLE("unexpected arch");
272 }
273 }
274
275 static inline uint32_t
276 rogue_get_texture_extent_max(const struct pvr_device_info *dev_info)
277 {
278 switch (dev_info->ident.arch) {
279 case PVR_DEVICE_ARCH_ROGUE:
280 return 16384;
281 default:
282 UNREACHABLE("unexpected arch");
283 }
284 }
285
286 static inline uint32_t
287 rogue_max_compute_shared_registers(const struct pvr_device_info *dev_info)
288 {
289 if (PVR_HAS_FEATURE(dev_info, compute))
290 return 1024U;
291
292 return 0U;
293 }
294
295 static inline uint32_t
296 rogue_get_max_num_cores(const struct pvr_device_info *dev_info)
297 {
298 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support) &&
299 PVR_HAS_FEATURE(dev_info, xpu_max_slaves)) {
300 return PVR_GET_FEATURE_VALUE(dev_info, xpu_max_slaves, 0U) + 1U;
301 }
302
303 return 1U;
304 }
305
306 static inline uint32_t
307 rogue_get_cdm_context_resume_buffer_size(const struct pvr_device_info *dev_info)
308 {
309 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) {
310 const uint32_t max_num_cores = rogue_get_max_num_cores(dev_info);
311 const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info);
312 const uint32_t cdm_context_resume_buffer_stride =
313 ALIGN_POT(ROGUE_LLS_CDM_CONTEXT_RESUME_BUFFER_SIZE, cache_line_size);
314
315 /*
316 * TODO: Optimise buffer size based on the core_count,
317 * not max_num_cores
318 */
319 return cdm_context_resume_buffer_stride * max_num_cores;
320 }
321
322 return ROGUE_LLS_CDM_CONTEXT_RESUME_BUFFER_SIZE;
323 }
324
325 static inline uint32_t rogue_get_cdm_context_resume_buffer_alignment(
326 const struct pvr_device_info *dev_info)
327 {
328 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support))
329 return pvr_get_slc_cache_line_size(dev_info);
330
331 return ROGUE_LLS_CDM_CONTEXT_RESUME_BUFFER_ALIGNMENT;
332 }
333
334 static inline uint32_t
335 rogue_get_compute_max_work_group_size(const struct pvr_device_info *dev_info)
336 {
337 /* The number of tasks which can be executed per USC - Limited to 16U by the
338 * CDM.
339 */
340 const uint32_t max_tasks_per_usc = 16U;
341
342 if (!PVR_HAS_ENHANCEMENT(dev_info, 35421)) {
343 /* Barriers on work-groups > 32 instances aren't supported. */
344 return ROGUE_MAX_INSTANCES_PER_TASK;
345 }
346
347 return ROGUE_MAX_INSTANCES_PER_TASK * max_tasks_per_usc;
348 }
349
350 /* Don't use this directly. Use the x and y define macros. */
351 static inline uint32_t
352 __rogue_get_param_vf_max(const struct pvr_device_info *dev_info)
353 {
354 return (rogue_get_render_size_max(dev_info) * 3 / 2) - 1;
355 }
356
357 #define rogue_get_param_vf_max_x(dev_info) __rogue_get_param_vf_max(dev_info)
358 #define rogue_get_param_vf_max_y(dev_info) __rogue_get_param_vf_max(dev_info)
359
360 static inline uint32_t
361 rogue_get_max_total_instances(const struct pvr_device_info *dev_info)
362 {
363 const uint32_t usc_slots = PVR_GET_FEATURE_VALUE(dev_info, usc_slots, 0U);
364 assert(usc_slots);
365
366 return usc_slots * ROGUE_MAX_INSTANCES_PER_TASK;
367 }
368
369 static inline uint32_t rogue_get_unified_store_size_per_instance(
370 const struct pvr_device_info *dev_info)
371 {
372 const uint32_t unified_store_depth =
373 PVR_GET_FEATURE_VALUE(dev_info, unified_store_depth, 0U);
374 assert(unified_store_depth);
375
376 return unified_store_depth * ROGUE_USC_NUM_UNIFIED_STORE_BANKS;
377 }
378
379 static inline uint32_t
380 rogue_get_min_attr_in_usrm_lines(const struct pvr_device_info *dev_info)
381 {
382 const uint32_t unified_store_size_per_instance =
383 rogue_get_unified_store_size_per_instance(dev_info);
384 assert(unified_store_size_per_instance);
385
386 return (unified_store_size_per_instance /
387 ROGUE_USRM_LINE_SIZE_PER_INSTANCE) -
388 ROGUE_RESERVED_USRM_LINES;
389 }
390
391 static inline uint32_t
392 rogue_get_parallel_instances(const struct pvr_device_info *dev_info)
393 {
394 return ROGUE_MAX_INSTANCES_PER_TASK / 2;
395 }
396
397 static inline uint32_t rogue_get_unified_store_temps_per_instance(
398 const struct pvr_device_info *dev_info)
399 {
400 return rogue_get_min_attr_in_usrm_lines(dev_info) *
401 ROGUE_USRM_LINE_SIZE_PER_INSTANCE;
402 }
403
404 static inline uint32_t
405 rogue_get_unified_store_total_temps(const struct pvr_device_info *dev_info)
406 {
407 return rogue_get_unified_store_temps_per_instance(dev_info) *
408 rogue_get_parallel_instances(dev_info);
409 }
410
411 static inline uint32_t
412 rogue_get_instance_groups_per_slot(const struct pvr_device_info *dev_info)
413 {
414 return ROGUE_MAX_INSTANCES_PER_TASK / rogue_get_parallel_instances(dev_info);
415 }
416
417 static inline uint32_t
418 rogue_get_optimal_temps(const struct pvr_device_info *dev_info)
419 {
420 const uint32_t usc_slots = PVR_GET_FEATURE_VALUE(dev_info, usc_slots, 0U);
421 assert(usc_slots);
422
423 uint32_t max_temps_full_slot_use =
424 rogue_get_unified_store_temps_per_instance(dev_info) /
425 (rogue_get_instance_groups_per_slot(dev_info) * usc_slots);
426
427 max_temps_full_slot_use &= ~(ROGUE_PDS_US_TEMP_ALLOCATION_GRANULARITY - 1);
428
429 return MAX2(max_temps_full_slot_use, 24U);
430 }
431
432 static inline uint32_t rogue_get_temps(const struct pvr_device_info *dev_info)
433 {
434 uint32_t temps = rogue_get_unified_store_temps_per_instance(dev_info) / 2;
435
436 return MIN2(temps, 248U);
437 }
438
439 static inline uint32_t
440 rogue_max_wg_temps(const struct pvr_device_info *dev_info,
441 unsigned temps,
442 unsigned wg_size,
443 bool has_barrier)
444 {
445 assert(wg_size <= rogue_get_max_total_instances(dev_info));
446 if (!wg_size)
447 wg_size = rogue_get_compute_max_work_group_size(dev_info);
448
449 if (wg_size > ROGUE_MAX_INSTANCES_PER_TASK && has_barrier) {
450 /* Number of slots allocated for each workgroup. */
451 unsigned slots_per_wg =
452 DIV_ROUND_UP(wg_size, ROGUE_MAX_INSTANCES_PER_TASK);
453
454 /* Lines of USRM lines available for each slot
455 * (+1 for fragmentation / coarse checking).
456 */
457 unsigned lines_per_slot =
458 rogue_get_min_attr_in_usrm_lines(dev_info) / (slots_per_wg + 1);
459
460 unsigned max_allocs;
461 if (lines_per_slot != 0) {
462 /* Convert lines to USRM allocs. */
463 max_allocs = lines_per_slot * ROGUE_USRM_LINE_SIZE;
464 } else {
465 max_allocs = (rogue_get_min_attr_in_usrm_lines(dev_info) *
466 ROGUE_USRM_LINE_SIZE) /
467 (slots_per_wg + 1);
468 }
469
470 /* Convert USRM allocs to temporary registers. */
471 unsigned max_temps_for_barrier =
472 max_allocs * ROGUE_USRM_GRANULARITY_IN_REGISTERS;
473
474 /* Clamp to provided limit */
475 temps = MIN2(temps, max_temps_for_barrier);
476 }
477
478 return temps;
479 }
480
481 static inline uint32_t rogue_get_vtxins(void)
482 {
483 /* TODO: use highest safe number of vertex input registers. */
484 return 12;
485 }
486
487 static inline uint32_t
488 rogue_num_uscs_per_tile(const struct pvr_device_info *dev_info)
489 {
490 if (PVR_HAS_FEATURE(dev_info, tile_per_usc) ||
491 PVR_HAS_FEATURE(dev_info, pbe2_in_xe))
492 return 1;
493
494 return 4;
495 }
496
497 static inline uint32_t rogue_usc_indexed_pixel_output_index_scale(
498 const struct pvr_device_info *dev_info)
499 {
500 if (PVR_HAS_FEATURE(dev_info, tile_per_usc))
501 return 4;
502
503 return 1;
504 }
505
506 static inline uint32_t
507 rogue_get_total_instance_count(const struct pvr_device_info *dev_info)
508 {
509 /* Number of instances calculated as such:
510 * USC_SLOTS * INSTANCES_PER_SLOT * MAX_NUM_CORES * NUM_CLUSTERS
511 */
512 /* TODO: Optimise tile buffer size to use core_count, not max_num_cores. */
513 return rogue_get_max_total_instances(dev_info) *
514 rogue_get_max_num_cores(dev_info) *
515 PVR_GET_FEATURE_VALUE(dev_info, num_clusters, 1);
516 }
517 #endif /* ROGUE_HW_UTILS_H */