Debian Codegraph @

src/imagination/vulkan/pvr_arch_job_render.c

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 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <vulkan/vulkan.h>
28
29 #include "hwdef/rogue_hw_defs.h"
30 #include "hwdef/rogue_hw_utils.h"
31 #include "pvr_bo.h"
32 #include "pvr_border.h"
33 #include "pvr_cmd_buffer.h"
34 #include "pvr_csb.h"
35 #include "pvr_debug.h"
36 #include "pvr_device.h"
37 #include "pvr_csb_enum_helpers.h"
38 #include "pvr_debug.h"
39 #include "pvr_free_list.h"
40 #include "pvr_job_common.h"
41 #include "pvr_job_context.h"
42 #include "pvr_job_render.h"
43 #include "pvr_macros.h"
44 #include "pvr_pds.h"
45 #include "pvr_physical_device.h"
46 #include "pvr_query.h"
47 #include "pvr_rogue_fw.h"
48 #include "pvr_rt_dataset.h"
49 #include "pvr_types.h"
50 #include "pvr_winsys.h"
51 #include "util/compiler.h"
52 #include "util/format/format_utils.h"
53 #include "util/macros.h"
54 #include "util/u_math.h"
55 #include "vk_alloc.h"
56 #include "vk_log.h"
57 #include "vk_util.h"
58
59 static_assert(pvr_cmd_length(PBESTATE_REG_WORD0) == 2,
60 "PBESTATE_REG_WORD0 cannot be stored in uint64_t");
61 static_assert(pvr_cmd_length(PBESTATE_REG_WORD1) == 2,
62 "PBESTATE_REG_WORD1 cannot be stored in uint64_t");
63 static_assert(ROGUE_NUM_PBESTATE_REG_WORDS >= 2,
64 "Cannot store both PBESTATE_REG_WORD{0,1}");
65
66 static_assert(pvr_cmd_length(CR_PDS_BGRND0_BASE) == 2,
67 "CR_PDS_BGRND0_BASE cannot be stored in uint64_t");
68 static_assert(pvr_cmd_length(CR_PDS_BGRND1_BASE) == 2,
69 "CR_PDS_BGRND1_BASE cannot be stored in uint64_t");
70 static_assert(pvr_cmd_length(CR_PDS_BGRND3_SIZEINFO) == 2,
71 "CR_PDS_BGRND3_SIZEINFO cannot be stored in uint64_t");
72 static_assert(ROGUE_NUM_CR_PDS_BGRND_WORDS == 3,
73 "Cannot store all CR_PDS_BGRND words");
74
75 /* FIXME: The three defines below, for the number of PC, PD and PT entries in a
76 * 4KB page, come from rgxmmudefs_km.h (meaning they're part of the
77 * auto-generated hwdefs). Should these be defined in rogue_mmu.xml? Keeping in
78 * mind that we probably only need these three values. */
79 #define ROGUE_NUM_PC_ENTRIES_PER_PAGE 0x400U
80
81 #define ROGUE_NUM_PD_ENTRIES_PER_PAGE 0x200U
82
83 #define ROGUE_NUM_PT_ENTRIES_PER_PAGE 0x200U
84
85 static inline void pvr_get_samples_in_xy(uint32_t samples,
86 uint32_t *const x_out,
87 uint32_t *const y_out)
88 {
89 switch (samples) {
90 case 1:
91 *x_out = 1;
92 *y_out = 1;
93 break;
94 case 2:
95 *x_out = 1;
96 *y_out = 2;
97 break;
98 case 4:
99 *x_out = 2;
100 *y_out = 2;
101 break;
102 case 8:
103 *x_out = 2;
104 *y_out = 4;
105 break;
106 default:
107 UNREACHABLE("Unsupported number of samples");
108 }
109 }
110
111 void pvr_arch_rt_mtile_info_init(const struct pvr_device_info *dev_info,
112 struct pvr_rt_mtile_info *info,
113 uint32_t width,
114 uint32_t height,
115 uint32_t samples)
116 {
117 uint32_t samples_in_x;
118 uint32_t samples_in_y;
119
120 pvr_get_samples_in_xy(samples, &samples_in_x, &samples_in_y);
121
122 info->tile_size_x = PVR_GET_FEATURE_VALUE(dev_info, tile_size_x, 1);
123 info->tile_size_y = PVR_GET_FEATURE_VALUE(dev_info, tile_size_y, 1);
124
125 info->num_tiles_x = DIV_ROUND_UP(width, info->tile_size_x);
126 info->num_tiles_y = DIV_ROUND_UP(height, info->tile_size_y);
127
128 rogue_get_num_macrotiles_xy(dev_info, &info->mtiles_x, &info->mtiles_y);
129
130 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
131 assert(PVR_GET_FEATURE_VALUE(dev_info,
132 simple_parameter_format_version,
133 0) == 2);
134 /* Set up 16 macrotiles with a multiple of 2x2 tiles per macrotile,
135 * which is aligned to a tile group.
136 */
137 info->mtile_x1 = DIV_ROUND_UP(info->num_tiles_x, 8) * 2;
138 info->mtile_y1 = DIV_ROUND_UP(info->num_tiles_y, 8) * 2;
139 info->mtile_x2 = 0;
140 info->mtile_y2 = 0;
141 info->mtile_x3 = 0;
142 info->mtile_y3 = 0;
143 info->x_tile_max = ALIGN_POT(info->num_tiles_x, 2) - 1;
144 info->y_tile_max = ALIGN_POT(info->num_tiles_y, 2) - 1;
145 } else {
146 /* Set up 16 macrotiles with a multiple of 4x4 tiles per macrotile. */
147 info->mtile_x1 = ALIGN_POT(DIV_ROUND_UP(info->num_tiles_x, 4), 4);
148 info->mtile_y1 = ALIGN_POT(DIV_ROUND_UP(info->num_tiles_y, 4), 4);
149 info->mtile_x2 = info->mtile_x1 * 2;
150 info->mtile_y2 = info->mtile_y1 * 2;
151 info->mtile_x3 = info->mtile_x1 * 3;
152 info->mtile_y3 = info->mtile_y1 * 3;
153 info->x_tile_max = info->num_tiles_x - 1;
154 info->y_tile_max = info->num_tiles_y - 1;
155 }
156
157 info->tiles_per_mtile_x = info->mtile_x1 * samples_in_x;
158 info->tiles_per_mtile_y = info->mtile_y1 * samples_in_y;
159 }
160
161 /* Note that the unit of the return value depends on the GPU. For cores with the
162 * simple_internal_parameter_format feature the returned size is interpreted as
163 * the number of region headers. For cores without this feature its interpreted
164 * as the size in dwords.
165 */
166 static uint64_t
167 pvr_rt_get_isp_region_size(struct pvr_device *device,
168 const struct pvr_rt_mtile_info *mtile_info)
169 {
170 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
171 uint64_t rgn_size =
172 (uint64_t)mtile_info->tiles_per_mtile_x * mtile_info->tiles_per_mtile_y;
173
174 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
175 uint32_t version;
176
177 rgn_size *= (uint64_t)mtile_info->mtiles_x * mtile_info->mtiles_y;
178
179 if (PVR_FEATURE_VALUE(dev_info,
180 simple_parameter_format_version,
181 &version)) {
182 version = 0;
183 }
184
185 if (version == 2) {
186 /* One region header per 2x2 tile group. */
187 rgn_size /= (2U * 2U);
188 }
189 } else {
190 const uint64_t single_rgn_header_size =
191 rogue_get_region_header_size(dev_info);
192
193 /* Round up to next dword to prevent IPF overrun and convert to bytes.
194 */
195 rgn_size = DIV_ROUND_UP(rgn_size * single_rgn_header_size, 4);
196 }
197
198 return rgn_size;
199 }
200
201 static VkResult pvr_rt_vheap_rtc_data_init(struct pvr_device *device,
202 struct pvr_rt_dataset *rt_dataset,
203 uint32_t layers)
204 {
205 uint64_t vheap_size;
206 uint32_t alignment;
207 uint64_t rtc_size;
208 VkResult result;
209
210 vheap_size = ROGUE_CR_PM_VHEAP_TABLE_SIZE * ROGUE_PM_VHEAP_ENTRY_SIZE;
211
212 if (layers > 1) {
213 uint64_t rtc_entries;
214
215 vheap_size = ALIGN_POT(vheap_size, ROGUE_CR_TA_RTC_ADDR_BASE_ALIGNMENT);
216
217 rtc_entries = ROGUE_NUM_TEAC + ROGUE_NUM_TE + ROGUE_NUM_VCE;
218 if (PVR_HAS_QUIRK(&device->pdevice->dev_info, 48545))
219 rtc_entries += ROGUE_NUM_TE;
220
221 rtc_size = rtc_entries * ROGUE_RTC_SIZE_IN_BYTES;
222 } else {
223 rtc_size = 0;
224 }
225
226 alignment = MAX2(ROGUE_CR_PM_VHEAP_TABLE_BASE_ADDR_ALIGNMENT,
227 ROGUE_CR_TA_RTC_ADDR_BASE_ALIGNMENT);
228
229 result = pvr_bo_alloc(device,
230 device->heaps.general_heap,
231 vheap_size + rtc_size,
232 alignment,
233 PVR_BO_ALLOC_FLAG_GPU_UNCACHED,
234 &rt_dataset->vheap_rtc_bo);
235 if (result != VK_SUCCESS)
236 return result;
237
238 rt_dataset->vheap_dev_addr = rt_dataset->vheap_rtc_bo->vma->dev_addr;
239
240 if (rtc_size > 0) {
241 rt_dataset->rtc_dev_addr =
242 PVR_DEV_ADDR_OFFSET(rt_dataset->vheap_dev_addr, vheap_size);
243 } else {
244 rt_dataset->rtc_dev_addr = PVR_DEV_ADDR_INVALID;
245 }
246
247 return VK_SUCCESS;
248 }
249
250 static void
251 pvr_rt_get_tail_ptr_stride_size(const struct pvr_device *device,
252 const struct pvr_rt_mtile_info *mtile_info,
253 uint32_t layers,
254 uint64_t *const stride_out,
255 uint64_t *const size_out)
256 {
257 uint32_t max_num_mtiles;
258 uint32_t num_mtiles_x;
259 uint32_t num_mtiles_y;
260 uint32_t version;
261 uint64_t size;
262
263 num_mtiles_x = mtile_info->mtiles_x * mtile_info->tiles_per_mtile_x;
264 num_mtiles_y = mtile_info->mtiles_y * mtile_info->tiles_per_mtile_y;
265
266 max_num_mtiles = MAX2(util_next_power_of_two64(num_mtiles_x),
267 util_next_power_of_two64(num_mtiles_y));
268
269 size = (uint64_t)max_num_mtiles * max_num_mtiles;
270
271 if (PVR_FEATURE_VALUE(&device->pdevice->dev_info,
272 simple_parameter_format_version,
273 &version)) {
274 version = 0;
275 }
276
277 if (version == 2) {
278 /* One tail pointer cache entry per 2x2 tile group. */
279 size /= (2U * 2U);
280 }
281
282 size *= ROGUE_TAIL_POINTER_SIZE;
283
284 if (layers > 1) {
285 size = ALIGN_POT(size, ROGUE_BIF_PM_PHYSICAL_PAGE_SIZE);
286
287 *stride_out = size / ROGUE_BIF_PM_PHYSICAL_PAGE_SIZE;
288 *size_out = size * layers;
289 } else {
290 *stride_out = 0;
291 *size_out = size;
292 }
293 }
294
295 static VkResult pvr_rt_tpc_data_init(struct pvr_device *device,
296 struct pvr_rt_dataset *rt_dataset,
297 const struct pvr_rt_mtile_info *mtile_info,
298 uint32_t layers)
299 {
300 uint64_t tpc_size;
301
302 pvr_rt_get_tail_ptr_stride_size(device,
303 mtile_info,
304 layers,
305 &rt_dataset->tpc_stride,
306 &rt_dataset->tpc_size);
307 tpc_size = ALIGN_POT(rt_dataset->tpc_size, ROGUE_TE_TPC_CACHE_LINE_SIZE);
308
309 return pvr_bo_alloc(device,
310 device->heaps.general_heap,
311 tpc_size,
312 ROGUE_CR_TE_TPC_ADDR_BASE_ALIGNMENT,
313 PVR_BO_ALLOC_FLAG_GPU_UNCACHED,
314 &rt_dataset->tpc_bo);
315 }
316
317 static uint32_t
318 pvr_rt_get_mlist_size(const struct pvr_free_list *global_free_list,
319 const struct pvr_free_list *local_free_list)
320 {
321 uint32_t num_pte_pages;
322 uint32_t num_pde_pages;
323 uint32_t num_pce_pages;
324 uint64_t total_pages;
325 uint32_t mlist_size;
326
327 assert(global_free_list->size + local_free_list->size <=
328 ROGUE_PM_MAX_PB_VIRT_ADDR_SPACE);
329
330 total_pages = (global_free_list->size + local_free_list->size) >>
331 ROGUE_BIF_PM_PHYSICAL_PAGE_SHIFT;
332
333 /* Calculate the total number of physical pages required to hold the page
334 * table, directory and catalog entries for the freelist pages.
335 */
336 num_pte_pages = DIV_ROUND_UP(total_pages, ROGUE_NUM_PT_ENTRIES_PER_PAGE);
337 num_pde_pages = DIV_ROUND_UP(num_pte_pages, ROGUE_NUM_PD_ENTRIES_PER_PAGE);
338 num_pce_pages = DIV_ROUND_UP(num_pde_pages, ROGUE_NUM_PC_ENTRIES_PER_PAGE);
339
340 /* Calculate the MList size considering the total number of pages in the PB
341 * are shared among all the PM address spaces.
342 */
343 mlist_size = (num_pce_pages + num_pde_pages + num_pte_pages) *
344 ROGUE_NUM_PM_ADDRESS_SPACES * ROGUE_MLIST_ENTRY_STRIDE;
345
346 return ALIGN_POT(mlist_size, ROGUE_BIF_PM_PHYSICAL_PAGE_SIZE);
347 }
348
349 static void pvr_rt_get_region_headers_stride_size(
350 const struct pvr_device *device,
351 const struct pvr_rt_mtile_info *mtile_info,
352 uint32_t layers,
353 uint64_t *const stride_out,
354 uint64_t *const size_out)
355 {
356 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
357 const uint32_t single_rgn_header_size =
358 rogue_get_region_header_size(dev_info);
359 uint64_t rgn_headers_size;
360 uint32_t num_tiles_x;
361 uint32_t num_tiles_y;
362 uint32_t group_size;
363 uint32_t version;
364
365 if (PVR_FEATURE_VALUE(dev_info, simple_parameter_format_version, &version))
366 version = 0;
367
368 group_size = version == 2 ? 2 : 1;
369
370 num_tiles_x = mtile_info->mtiles_x * mtile_info->tiles_per_mtile_x;
371 num_tiles_y = mtile_info->mtiles_y * mtile_info->tiles_per_mtile_y;
372
373 rgn_headers_size = (uint64_t)num_tiles_x / group_size;
374 /* Careful here. We want the division to happen first. */
375 rgn_headers_size *= num_tiles_y / group_size;
376 rgn_headers_size *= single_rgn_header_size;
377
378 if (PVR_HAS_FEATURE(dev_info, simple_internal_parameter_format)) {
379 rgn_headers_size =
380 ALIGN_POT(rgn_headers_size, ROGUE_CR_TE_PSGREGION_ADDR_BASE_ALIGNMENT);
381 }
382
383 if (layers > 1) {
384 rgn_headers_size =
385 ALIGN_POT(rgn_headers_size, ROGUE_CR_TE_PSG_REGION_STRIDE_UNIT_SIZE);
386 }
387
388 *stride_out = rgn_headers_size;
389 *size_out = rgn_headers_size * layers;
390 }
391
392 static VkResult pvr_rt_mta_data_init(struct pvr_device *device,
393 struct pvr_rt_dataset *rt_dataset)
394 {
395 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
396 const uint32_t mta_size = rogue_get_macrotile_array_size(dev_info);
397 const uint32_t num_rt_datas = ARRAY_SIZE(rt_dataset->rt_datas);
398 pvr_dev_addr_t dev_addr;
399 VkResult result;
400
401 /* Valid case - see rogue_get_macrotile_array_size() */
402 if (mta_size == 0) {
403 rt_dataset->mta_bo = NULL;
404
405 for (uint32_t i = 0; i < num_rt_datas; i++)
406 rt_dataset->rt_datas[i].mta_dev_addr = PVR_DEV_ADDR_INVALID;
407
408 return VK_SUCCESS;
409 }
410
411 result = pvr_bo_alloc(device,
412 device->heaps.general_heap,
413 mta_size * num_rt_datas,
414 ROGUE_CR_PM_MTILE_ARRAY_BASE_ADDR_ALIGNMENT,
415 PVR_BO_ALLOC_FLAG_GPU_UNCACHED,
416 &rt_dataset->mta_bo);
417 if (result != VK_SUCCESS)
418 return result;
419
420 dev_addr = rt_dataset->mta_bo->vma->dev_addr;
421
422 for (uint32_t i = 0; i < num_rt_datas; i++) {
423 rt_dataset->rt_datas[i].mta_dev_addr = dev_addr;
424 dev_addr = PVR_DEV_ADDR_OFFSET(dev_addr, mta_size);
425 }
426
427 return VK_SUCCESS;
428 }
429
430 static VkResult
431 pvr_rt_mlist_data_init(struct pvr_device *device,
432 struct pvr_rt_dataset *rt_dataset,
433 const struct pvr_free_list *global_free_list,
434 const struct pvr_free_list *local_free_list)
435 {
436 const uint32_t mlist_size =
437 pvr_rt_get_mlist_size(global_free_list, local_free_list);
438 const uint32_t num_rt_datas = ARRAY_SIZE(rt_dataset->rt_datas);
439 pvr_dev_addr_t dev_addr;
440 VkResult result;
441
442 /* No known cores where the Mlist size could be 0 */
443 assert(mlist_size > 0);
444
445 result = pvr_bo_alloc(device,
446 device->heaps.general_heap,
447 mlist_size * num_rt_datas,
448 ROGUE_CR_PM_MTILE_ARRAY_BASE_ADDR_ALIGNMENT,
449 PVR_BO_ALLOC_FLAG_GPU_UNCACHED |
450 PVR_BO_ALLOC_FLAG_PM_FW_PROTECT,
451 &rt_dataset->mlist_bo);
452 if (result != VK_SUCCESS)
453 return result;
454
455 dev_addr = rt_dataset->mlist_bo->vma->dev_addr;
456
457 for (uint32_t i = 0; i < num_rt_datas; i++) {
458 rt_dataset->rt_datas[i].mlist_dev_addr = dev_addr;
459 dev_addr = PVR_DEV_ADDR_OFFSET(dev_addr, mlist_size);
460 }
461
462 return VK_SUCCESS;
463 }
464
465 static VkResult
466 pvr_rt_rgn_headers_data_init(struct pvr_device *device,
467 struct pvr_rt_dataset *rt_dataset,
468 const struct pvr_rt_mtile_info *mtile_info,
469 uint32_t layers)
470 {
471 const uint32_t num_rt_datas = ARRAY_SIZE(rt_dataset->rt_datas);
472 uint64_t rgn_headers_size;
473 pvr_dev_addr_t dev_addr;
474 VkResult result;
475
476 pvr_rt_get_region_headers_stride_size(device,
477 mtile_info,
478 layers,
479 &rt_dataset->rgn_headers_stride,
480 &rgn_headers_size);
481
482 result = pvr_bo_alloc(device,
483 device->heaps.rgn_hdr_heap,
484 rgn_headers_size * num_rt_datas,
485 ROGUE_CR_TE_PSGREGION_ADDR_BASE_ALIGNMENT,
486 PVR_BO_ALLOC_FLAG_GPU_UNCACHED,
487 &rt_dataset->rgn_headers_bo);
488 if (result != VK_SUCCESS)
489 return result;
490
491 dev_addr = rt_dataset->rgn_headers_bo->vma->dev_addr;
492
493 for (uint32_t i = 0; i < num_rt_datas; i++) {
494 rt_dataset->rt_datas[i].rgn_headers_dev_addr = dev_addr;
495 dev_addr = PVR_DEV_ADDR_OFFSET(dev_addr, rgn_headers_size);
496 }
497
498 return VK_SUCCESS;
499 }
500
501 static VkResult pvr_rt_datas_init(struct pvr_device *device,
502 struct pvr_rt_dataset *rt_dataset,
503 const struct pvr_free_list *global_free_list,
504 const struct pvr_free_list *local_free_list,
505 const struct pvr_rt_mtile_info *mtile_info,
506 uint32_t layers)
507 {
508 VkResult result;
509
510 result = pvr_rt_mta_data_init(device, rt_dataset);
511 if (result != VK_SUCCESS)
512 return result;
513
514 result = pvr_rt_mlist_data_init(device,
515 rt_dataset,
516 global_free_list,
517 local_free_list);
518 if (result != VK_SUCCESS)
519 goto err_pvr_rt_mta_data_fini;
520
521 result =
522 pvr_rt_rgn_headers_data_init(device, rt_dataset, mtile_info, layers);
523 if (result != VK_SUCCESS)
524 goto err_pvr_rt_mlist_data_fini;
525
526 return VK_SUCCESS;
527
528 err_pvr_rt_mlist_data_fini:
529 pvr_rt_mlist_data_fini(rt_dataset);
530
531 err_pvr_rt_mta_data_fini:
532 pvr_rt_mta_data_fini(rt_dataset);
533
534 return result;
535 }
536
537 static void pvr_rt_dataset_ws_create_info_init(
538 struct pvr_rt_dataset *rt_dataset,
539 const struct pvr_rt_mtile_info *mtile_info,
540 struct pvr_winsys_rt_dataset_create_info *create_info)
541 {
542 struct pvr_device *device = rt_dataset->device;
543 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
544
545 memset(create_info, 0, sizeof(*create_info));
546
547 /* Local freelist. */
548 create_info->local_free_list = rt_dataset->local_free_list->ws_free_list;
549
550 create_info->width = rt_dataset->width;
551 create_info->height = rt_dataset->height;
552 create_info->samples = rt_dataset->samples;
553 create_info->layers = rt_dataset->layers;
554
555 /* ISP register values. */
556 if (PVR_HAS_ENHANCEMENT(dev_info, 42307) &&
557 !(PVR_HAS_FEATURE(dev_info, roguexe) && mtile_info->tile_size_x == 16)) {
558 float value;
559
560 if (rt_dataset->width != 0) {
561 value =
562 ROGUE_ISP_MERGE_LOWER_LIMIT_NUMERATOR / (float)rt_dataset->width;
563 create_info->isp_merge_lower_x = fui(value);
564
565 value =
566 ROGUE_ISP_MERGE_UPPER_LIMIT_NUMERATOR / (float)rt_dataset->width;
567 create_info->isp_merge_upper_x = fui(value);
568 }
569
570 if (rt_dataset->height != 0) {
571 value =
572 ROGUE_ISP_MERGE_LOWER_LIMIT_NUMERATOR / (float)rt_dataset->height;
573 create_info->isp_merge_lower_y = fui(value);
574
575 value =
576 ROGUE_ISP_MERGE_UPPER_LIMIT_NUMERATOR / (float)rt_dataset->height;
577 create_info->isp_merge_upper_y = fui(value);
578 }
579
580 value = ((float)rt_dataset->width * ROGUE_ISP_MERGE_SCALE_FACTOR) /
581 (ROGUE_ISP_MERGE_UPPER_LIMIT_NUMERATOR -
582 ROGUE_ISP_MERGE_LOWER_LIMIT_NUMERATOR);
583 create_info->isp_merge_scale_x = fui(value);
584
585 value = ((float)rt_dataset->height * ROGUE_ISP_MERGE_SCALE_FACTOR) /
586 (ROGUE_ISP_MERGE_UPPER_LIMIT_NUMERATOR -
587 ROGUE_ISP_MERGE_LOWER_LIMIT_NUMERATOR);
588 create_info->isp_merge_scale_y = fui(value);
589 }
590
591 /* Allocations and associated information. */
592 create_info->vheap_table_dev_addr = rt_dataset->vheap_dev_addr;
593 create_info->rtc_dev_addr = rt_dataset->rtc_dev_addr;
594
595 create_info->tpc_dev_addr = rt_dataset->tpc_bo->vma->dev_addr;
596 create_info->tpc_stride = rt_dataset->tpc_stride;
597 create_info->tpc_size = rt_dataset->tpc_size;
598
599 STATIC_ASSERT(ARRAY_SIZE(create_info->rt_datas) ==
600 ARRAY_SIZE(rt_dataset->rt_datas));
601 for (uint32_t i = 0; i < ARRAY_SIZE(create_info->rt_datas); i++) {
602 create_info->rt_datas[i].pm_mlist_dev_addr =
603 rt_dataset->rt_datas[i].mlist_dev_addr;
604 create_info->rt_datas[i].macrotile_array_dev_addr =
605 rt_dataset->rt_datas[i].mta_dev_addr;
606 create_info->rt_datas[i].rgn_header_dev_addr =
607 rt_dataset->rt_datas[i].rgn_headers_dev_addr;
608 }
609
610 create_info->rgn_header_size =
611 pvr_rt_get_isp_region_size(device, mtile_info);
612 }
613
614 VkResult pvr_arch_render_target_dataset_create(
615 struct pvr_device *device,
616 uint32_t width,
617 uint32_t height,
618 uint32_t samples,
619 uint32_t layers,
620 struct pvr_rt_dataset **const rt_dataset_out)
621 {
622 struct pvr_device_runtime_info *runtime_info =
623 &device->pdevice->dev_runtime_info;
624 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
625 struct pvr_winsys_rt_dataset_create_info rt_dataset_create_info;
626 struct pvr_rt_mtile_info mtile_info;
627 struct pvr_rt_dataset *rt_dataset;
628 VkResult result;
629
630 assert(device->global_free_list);
631 assert(width <= rogue_get_render_size_max_x(dev_info));
632 assert(height <= rogue_get_render_size_max_y(dev_info));
633 assert(layers > 0 && layers <= PVR_MAX_FRAMEBUFFER_LAYERS);
634
635 pvr_arch_rt_mtile_info_init(dev_info, &mtile_info, width, height, samples);
636
637 rt_dataset = vk_zalloc(&device->vk.alloc,
638 sizeof(*rt_dataset),
639 8,
640 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
641 if (!rt_dataset)
642 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
643
644 rt_dataset->device = device;
645 rt_dataset->width = width;
646 rt_dataset->height = height;
647 rt_dataset->samples = samples;
648 rt_dataset->layers = layers;
649 rt_dataset->global_free_list = device->global_free_list;
650
651 /* The maximum supported free list size is based on the assumption that this
652 * freelist (the "local" freelist) is always the minimum size required by
653 * the hardware. See the documentation of ROGUE_FREE_LIST_MAX_SIZE for more
654 * details.
655 */
656 result = pvr_free_list_create(device,
657 runtime_info->min_free_list_size,
658 runtime_info->min_free_list_size,
659 0 /* grow_size */,
660 0 /* grow_threshold */,
661 rt_dataset->global_free_list,
662 &rt_dataset->local_free_list);
663 if (result != VK_SUCCESS)
664 goto err_vk_free_rt_dataset;
665
666 result = pvr_rt_vheap_rtc_data_init(device, rt_dataset, layers);
667 if (result != VK_SUCCESS)
668 goto err_pvr_free_list_destroy;
669
670 result = pvr_rt_tpc_data_init(device, rt_dataset, &mtile_info, layers);
671 if (result != VK_SUCCESS)
672 goto err_pvr_rt_vheap_rtc_data_fini;
673
674 result = pvr_rt_datas_init(device,
675 rt_dataset,
676 rt_dataset->global_free_list,
677 rt_dataset->local_free_list,
678 &mtile_info,
679 layers);
680 if (result != VK_SUCCESS)
681 goto err_pvr_rt_tpc_data_fini;
682
683 /* rt_dataset must be fully initialized by this point since
684 * pvr_rt_dataset_ws_create_info_init() depends on this.
685 */
686 pvr_rt_dataset_ws_create_info_init(rt_dataset,
687 &mtile_info,
688 &rt_dataset_create_info);
689
690 result =
691 device->ws->ops->render_target_dataset_create(device->ws,
692 &rt_dataset_create_info,
693 dev_info,
694 &rt_dataset->ws_rt_dataset);
695 if (result != VK_SUCCESS)
696 goto err_pvr_rt_datas_fini;
697
698 *rt_dataset_out = rt_dataset;
699
700 return VK_SUCCESS;
701
702 err_pvr_rt_datas_fini:
703 pvr_rt_datas_fini(rt_dataset);
704
705 err_pvr_rt_tpc_data_fini:
706 pvr_rt_tpc_data_fini(rt_dataset);
707
708 err_pvr_rt_vheap_rtc_data_fini:
709 pvr_rt_vheap_rtc_data_fini(rt_dataset);
710
711 err_pvr_free_list_destroy:
712 pvr_free_list_destroy(rt_dataset->local_free_list);
713
714 err_vk_free_rt_dataset:
715 vk_free(&device->vk.alloc, rt_dataset);
716
717 return result;
718 }
719
720 static void pvr_geom_state_stream_init(struct pvr_render_ctx *ctx,
721 struct pvr_render_job *job,
722 struct pvr_winsys_geometry_state *state)
723 {
724 const struct pvr_device *const device = ctx->device;
725 const struct pvr_device_info *const dev_info = &device->pdevice->dev_info;
726
727 uint32_t *stream_ptr = (uint32_t *)state->fw_stream;
728 uint32_t *stream_len_ptr = stream_ptr;
729
730 /* Leave space for stream header. */
731 stream_ptr += pvr_cmd_length(KMD_STREAM_HDR);
732
733 pvr_csb_pack ((uint64_t *)stream_ptr, CR_VDM_CTRL_STREAM_BASE, value) {
734 value.addr = job->ctrl_stream_addr;
735 }
736 stream_ptr += pvr_cmd_length(CR_VDM_CTRL_STREAM_BASE);
737
738 pvr_csb_pack ((uint64_t *)stream_ptr,
739 CR_TPU_BORDER_COLOUR_TABLE_VDM,
740 value) {
741 value.border_colour_table_address =
742 device->border_color_table->table->vma->dev_addr;
743 }
744 stream_ptr += pvr_cmd_length(CR_TPU_BORDER_COLOUR_TABLE_VDM);
745
746 pvr_csb_pack (stream_ptr, CR_PPP_CTRL, value) {
747 value.wclampen = true;
748 value.fixed_point_format = 1;
749 }
750 stream_ptr += pvr_cmd_length(CR_PPP_CTRL);
751
752 pvr_csb_pack (stream_ptr, CR_TE_PSG, value) {
753 struct pvr_rt_dataset *rt_dataset =
754 job->view_state.rt_datasets[job->view_state.view_index];
755 value.completeonterminate = job->geometry_terminate;
756
757 value.region_stride = rt_dataset->rgn_headers_stride /
758 ROGUE_CR_TE_PSG_REGION_STRIDE_UNIT_SIZE;
759
760 value.forcenewstate = PVR_HAS_QUIRK(dev_info, 52942);
761 }
762 stream_ptr += pvr_cmd_length(CR_TE_PSG);
763
764 /* Set up the USC common size for the context switch resume/load program
765 * (ctx->ctx_switch.programs[i].sr->pds_load_program), which was created
766 * as part of the render context.
767 */
768 pvr_csb_pack (stream_ptr, VDMCTRL_PDS_STATE0, value) {
769 /* Calculate the size in bytes. */
770 const uint16_t shared_registers_size = job->max_shared_registers * 4;
771
772 value.usc_common_size =
773 DIV_ROUND_UP(shared_registers_size,
774 ROGUE_VDMCTRL_PDS_STATE0_USC_COMMON_SIZE_UNIT_SIZE);
775 }
776 stream_ptr += pvr_cmd_length(VDMCTRL_PDS_STATE0);
777
778 pvr_csb_pack (stream_ptr, KMD_STREAM_VIEW_IDX, value) {
779 value.idx = job->view_state.view_index;
780 }
781 stream_ptr += pvr_cmd_length(KMD_STREAM_VIEW_IDX);
782
783 state->fw_stream_len = (uint8_t *)stream_ptr - (uint8_t *)state->fw_stream;
784 assert(state->fw_stream_len <= ARRAY_SIZE(state->fw_stream));
785
786 pvr_csb_pack ((uint64_t *)stream_len_ptr, KMD_STREAM_HDR, value) {
787 value.length = state->fw_stream_len;
788 }
789 }
790
791 static void
792 pvr_geom_state_stream_ext_init(struct pvr_render_ctx *ctx,
793 struct pvr_render_job *job,
794 struct pvr_winsys_geometry_state *state)
795 {
796 const struct pvr_device_info *dev_info = &ctx->device->pdevice->dev_info;
797
798 uint32_t main_stream_len =
799 pvr_csb_unpack((uint64_t *)state->fw_stream, KMD_STREAM_HDR).length;
800 uint32_t *ext_stream_ptr =
801 (uint32_t *)((uint8_t *)state->fw_stream + main_stream_len);
802 uint32_t *header0_ptr;
803
804 header0_ptr = ext_stream_ptr;
805 ext_stream_ptr += pvr_cmd_length(KMD_STREAM_EXTHDR_GEOM0);
806
807 pvr_csb_pack (header0_ptr, KMD_STREAM_EXTHDR_GEOM0, header0) {
808 if (PVR_HAS_QUIRK(dev_info, 49927)) {
809 header0.has_brn49927 = true;
810
811 /* The set up of CR_TPU must be identical to
812 * pvr_render_job_ws_fragment_state_stream_ext_init().
813 */
814 pvr_csb_pack (ext_stream_ptr, CR_TPU, value) {
815 value.tag_cem_4k_face_packing = true;
816 }
817 ext_stream_ptr += pvr_cmd_length(CR_TPU);
818 }
819 }
820
821 if ((*header0_ptr & ROGUE_KMD_STREAM_EXTHDR_DATA_MASK) != 0) {
822 state->fw_stream_len =
823 (uint8_t *)ext_stream_ptr - (uint8_t *)state->fw_stream;
824 assert(state->fw_stream_len <= ARRAY_SIZE(state->fw_stream));
825 }
826 }
827
828 static void
829 pvr_geom_state_flags_init(const struct pvr_render_job *const job,
830 struct pvr_winsys_geometry_state_flags *flags)
831 {
832 *flags = (struct pvr_winsys_geometry_state_flags){
833 .is_first_geometry =
834 !job->view_state.rt_datasets[job->view_state.view_index]->need_frag,
835 .is_last_geometry = job->geometry_terminate,
836 .use_single_core = job->frag_uses_atomic_ops,
837 };
838 }
839
840 static void
841 pvr_render_job_ws_geometry_state_init(struct pvr_render_ctx *ctx,
842 struct pvr_render_job *job,
843 struct vk_sync *wait,
844 struct pvr_winsys_geometry_state *state)
845 {
846 pvr_geom_state_stream_init(ctx, job, state);
847 pvr_geom_state_stream_ext_init(ctx, job, state);
848
849 state->wait = wait;
850 pvr_geom_state_flags_init(job, &state->flags);
851 }
852
853 static inline uint32_t pvr_frag_km_stream_pbe_reg_words_offset(
854 const struct pvr_device_info *const dev_info)
855 {
856 uint32_t offset = 0;
857
858 offset += pvr_cmd_length(KMD_STREAM_HDR);
859 offset += pvr_cmd_length(CR_ISP_SCISSOR_BASE);
860 offset += pvr_cmd_length(CR_ISP_DBIAS_BASE);
861 offset += pvr_cmd_length(CR_ISP_OCLQRY_BASE);
862 offset += pvr_cmd_length(CR_ISP_ZLSCTL);
863 offset += pvr_cmd_length(CR_ISP_ZLOAD_BASE);
864 offset += pvr_cmd_length(CR_ISP_STENCIL_LOAD_BASE);
865
866 if (PVR_HAS_FEATURE(dev_info, requires_fb_cdc_zls_setup))
867 offset += pvr_cmd_length(CR_FB_CDC_ZLS);
868
869 return PVR_DW_TO_BYTES(offset);
870 }
871
872 #define DWORDS_PER_U64 2
873
874 static inline uint32_t pvr_frag_km_stream_pds_eot_data_addr_offset(
875 const struct pvr_device_info *const dev_info)
876 {
877 uint32_t offset = 0;
878
879 offset += pvr_frag_km_stream_pbe_reg_words_offset(dev_info) / 4U;
880 offset +=
881 PVR_MAX_COLOR_ATTACHMENTS * ROGUE_NUM_PBESTATE_REG_WORDS * DWORDS_PER_U64;
882 offset += pvr_cmd_length(CR_TPU_BORDER_COLOUR_TABLE_PDM);
883 offset += ROGUE_NUM_CR_PDS_BGRND_WORDS * DWORDS_PER_U64;
884 offset += ROGUE_NUM_CR_PDS_BGRND_WORDS * DWORDS_PER_U64;
885 offset += ROGUE_KMD_STREAM_USC_CLEAR_REGISTER_COUNT *
886 pvr_cmd_length(CR_USC_CLEAR_REGISTER);
887 offset += pvr_cmd_length(CR_USC_PIXEL_OUTPUT_CTRL);
888 offset += pvr_cmd_length(CR_ISP_BGOBJDEPTH);
889 offset += pvr_cmd_length(CR_ISP_BGOBJVALS);
890 offset += pvr_cmd_length(CR_ISP_AA);
891 offset += pvr_cmd_length(CR_ISP_CTL);
892 offset += pvr_cmd_length(CR_EVENT_PIXEL_PDS_INFO);
893
894 if (PVR_HAS_FEATURE(dev_info, cluster_grouping))
895 offset += pvr_cmd_length(KMD_STREAM_PIXEL_PHANTOM);
896
897 offset += pvr_cmd_length(KMD_STREAM_VIEW_IDX);
898
899 return PVR_DW_TO_BYTES(offset);
900 }
901
902 static void pvr_frag_state_stream_init(struct pvr_render_ctx *ctx,
903 struct pvr_render_job *job,
904 struct pvr_winsys_fragment_state *state)
905 {
906 const struct pvr_device *const device = ctx->device;
907 const struct pvr_physical_device *const pdevice = device->pdevice;
908 const struct pvr_device_runtime_info *dev_runtime_info =
909 &pdevice->dev_runtime_info;
910 const struct pvr_device_info *dev_info = &pdevice->dev_info;
911 const struct pvr_rt_dataset *rt_dataset =
912 job->view_state.rt_datasets[job->view_state.view_index];
913 const enum ROGUE_CR_ISP_AA_MODE_TYPE isp_aa_mode =
914 pvr_cr_isp_aa_mode_type(job->samples);
915 struct pvr_rt_mtile_info tiling_info = { 0 };
916
917 enum ROGUE_CR_ZLS_FORMAT_TYPE zload_format = ROGUE_CR_ZLS_FORMAT_TYPE_F32Z;
918 uint32_t *stream_ptr = (uint32_t *)state->fw_stream;
919 uint32_t *stream_len_ptr = stream_ptr;
920 uint32_t view_index;
921 uint32_t pixel_ctl;
922 uint32_t isp_ctl;
923
924 /* Leave space for stream header. */
925 stream_ptr += pvr_cmd_length(KMD_STREAM_HDR);
926
927 /* FIXME: pass in the number of samples rather than isp_aa_mode? */
928 pvr_arch_setup_tiles_in_flight(dev_info,
929 dev_runtime_info,
930 isp_aa_mode,
931 job->pixel_output_width,
932 false,
933 job->max_tiles_in_flight,
934 &isp_ctl,
935 &pixel_ctl);
936
937 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_SCISSOR_BASE, value) {
938 value.addr = job->scissor_table_addr;
939 }
940 stream_ptr += pvr_cmd_length(CR_ISP_SCISSOR_BASE);
941
942 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_DBIAS_BASE, value) {
943 value.addr = job->depth_bias_table_addr;
944 }
945 stream_ptr += pvr_cmd_length(CR_ISP_DBIAS_BASE);
946
947 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_OCLQRY_BASE, value) {
948 const struct pvr_sub_cmd_gfx *sub_cmd =
949 container_of(job, const struct pvr_sub_cmd_gfx, job);
950
951 if (sub_cmd->query_pool)
952 value.addr = sub_cmd->query_pool->result_buffer->dev_addr;
953 else
954 value.addr = PVR_DEV_ADDR_INVALID;
955 }
956 stream_ptr += pvr_cmd_length(CR_ISP_OCLQRY_BASE);
957
958 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_ZLSCTL, value) {
959 if (job->has_depth_attachment || job->has_stencil_attachment) {
960 uint32_t alignment_x;
961 uint32_t alignment_y;
962
963 if (job->ds.has_alignment_transfers) {
964 rogue_get_zls_tile_size_xy(dev_info, &alignment_x, &alignment_y);
965 } else {
966 alignment_x = ROGUE_IPF_TILE_SIZE_PIXELS;
967 alignment_y = ROGUE_IPF_TILE_SIZE_PIXELS;
968 }
969
970 rogue_get_isp_num_tiles_xy(
971 dev_info,
972 job->samples,
973 ALIGN_POT(job->ds.physical_extent.width, alignment_x),
974 ALIGN_POT(job->ds.physical_extent.height, alignment_y),
975 &value.zlsextent_x_z,
976 &value.zlsextent_y_z);
977
978 value.zlsextent_x_z -= 1;
979 value.zlsextent_y_z -= 1;
980
981 if (job->ds.memlayout == PVR_MEMLAYOUT_TWIDDLED &&
982 !job->ds.has_alignment_transfers) {
983 value.loadtwiddled = true;
984 value.storetwiddled = true;
985 }
986
987 value.zloadformat = job->ds.zls_format;
988 value.zstoreformat = job->ds.zls_format;
989
990 zload_format = value.zloadformat;
991 }
992
993 if (job->has_depth_attachment) {
994 value.zloaden = job->ds.load.d;
995 value.zstoreen = job->ds.store.d;
996 }
997
998 if (job->has_stencil_attachment) {
999 value.sloaden = job->ds.load.s;
1000 value.sstoreen = job->ds.store.s;
1001 }
1002
1003 value.forcezload = value.zloaden || value.sloaden;
1004 value.forcezstore = value.zstoreen || value.sstoreen;
1005 value.zonlyrender = job->z_only_render;
1006 }
1007 stream_ptr += pvr_cmd_length(CR_ISP_ZLSCTL);
1008
1009 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_ZLOAD_BASE, value) {
1010 if (job->has_depth_attachment)
1011 value.addr = job->ds.addr;
1012 }
1013 stream_ptr += pvr_cmd_length(CR_ISP_ZLOAD_BASE);
1014
1015 pvr_csb_pack ((uint64_t *)stream_ptr, CR_ISP_STENCIL_LOAD_BASE, value) {
1016 if (job->has_stencil_attachment) {
1017 value.addr = job->ds.addr;
1018
1019 /* Enable separate stencil. This should be enabled iff the buffer set
1020 * in CR_ISP_STENCIL_LOAD_BASE does not contain a depth component.
1021 */
1022 assert(job->has_depth_attachment ||
1023 !pvr_zls_format_type_is_packed(job->ds.zls_format));
1024 value.enable = !job->has_depth_attachment;
1025 }
1026 }
1027 stream_ptr += pvr_cmd_length(CR_ISP_STENCIL_LOAD_BASE);
1028
1029 if (PVR_HAS_FEATURE(dev_info, requires_fb_cdc_zls_setup)) {
1030 /* Currently no support for FBC, so just go ahead and set the default
1031 * values.
1032 */
1033 pvr_csb_pack ((uint64_t *)stream_ptr, CR_FB_CDC_ZLS, value) {
1034 value.fbdc_depth_fmt = ROGUE_TEXSTATE_FORMAT_F32;
1035 value.fbdc_stencil_fmt = ROGUE_TEXSTATE_FORMAT_U8;
1036 }
1037 stream_ptr += pvr_cmd_length(CR_FB_CDC_ZLS);
1038 }
1039
1040 /* Make sure that the pvr_frag_km_...() function is returning the correct
1041 * offset.
1042 */
1043 assert((uint8_t *)stream_ptr - (uint8_t *)state->fw_stream ==
1044 pvr_frag_km_stream_pbe_reg_words_offset(dev_info));
1045
1046 STATIC_ASSERT(ARRAY_SIZE(job->pbe_reg_words) == PVR_MAX_COLOR_ATTACHMENTS);
1047 STATIC_ASSERT(ARRAY_SIZE(job->pbe_reg_words[0]) ==
1048 ROGUE_NUM_PBESTATE_REG_WORDS);
1049 STATIC_ASSERT(sizeof(job->pbe_reg_words[0][0]) == sizeof(uint64_t));
1050 memcpy(stream_ptr, job->pbe_reg_words, sizeof(job->pbe_reg_words));
1051 stream_ptr +=
1052 PVR_MAX_COLOR_ATTACHMENTS * ROGUE_NUM_PBESTATE_REG_WORDS * DWORDS_PER_U64;
1053
1054 pvr_csb_pack ((uint64_t *)stream_ptr,
1055 CR_TPU_BORDER_COLOUR_TABLE_PDM,
1056 value) {
1057 value.border_colour_table_address =
1058 device->border_color_table->table->vma->dev_addr;
1059 }
1060 stream_ptr += pvr_cmd_length(CR_TPU_BORDER_COLOUR_TABLE_PDM);
1061
1062 STATIC_ASSERT(ARRAY_SIZE(job->view_state.view[0].pds_bgnd_reg_values) ==
1063 ROGUE_NUM_CR_PDS_BGRND_WORDS);
1064 STATIC_ASSERT(sizeof(job->view_state.view[0].pds_bgnd_reg_values[0]) ==
1065 sizeof(uint64_t));
1066
1067 if (job->view_state.force_pds_bgnd_reg_values_zero)
1068 view_index = 0;
1069 else
1070 view_index = job->view_state.view_index;
1071
1072 memcpy(stream_ptr,
1073 job->view_state.view[view_index].pds_bgnd_reg_values,
1074 sizeof(job->view_state.view[view_index].pds_bgnd_reg_values));
1075 stream_ptr += ROGUE_NUM_CR_PDS_BGRND_WORDS * DWORDS_PER_U64;
1076
1077 STATIC_ASSERT(ARRAY_SIZE(job->view_state.view[0].pr_pds_bgnd_reg_values) ==
1078 ROGUE_NUM_CR_PDS_BGRND_WORDS);
1079 STATIC_ASSERT(sizeof(job->view_state.view[0].pr_pds_bgnd_reg_values[0]) ==
1080 sizeof(uint64_t));
1081 memcpy(stream_ptr,
1082 job->view_state.view[view_index].pr_pds_bgnd_reg_values,
1083 sizeof(job->view_state.view[view_index].pr_pds_bgnd_reg_values));
1084 stream_ptr += ROGUE_NUM_CR_PDS_BGRND_WORDS * DWORDS_PER_U64;
1085
1086 #undef DWORDS_PER_U64
1087
1088 memset(stream_ptr,
1089 0,
1090 ROGUE_KMD_STREAM_USC_CLEAR_REGISTER_COUNT *
1091 PVR_DW_TO_BYTES(pvr_cmd_length(CR_USC_CLEAR_REGISTER)));
1092 stream_ptr += ROGUE_KMD_STREAM_USC_CLEAR_REGISTER_COUNT *
1093 pvr_cmd_length(CR_USC_CLEAR_REGISTER);
1094
1095 *stream_ptr = pixel_ctl;
1096 stream_ptr += pvr_cmd_length(CR_USC_PIXEL_OUTPUT_CTRL);
1097
1098 pvr_csb_pack (stream_ptr, CR_ISP_BGOBJDEPTH, value) {
1099 const float depth_clear = job->ds_clear_value.depth;
1100
1101 /* This is valid even when we don't have a depth attachment because:
1102 * - zload_format is set to a sensible default above, and
1103 * - job->depth_clear_value is set to a sensible default in that case.
1104 */
1105 switch (zload_format) {
1106 case ROGUE_CR_ZLS_FORMAT_TYPE_F32Z:
1107 case ROGUE_CR_ZLS_FORMAT_TYPE_F64Z:
1108 value.value = fui(depth_clear);
1109 break;
1110
1111 case ROGUE_CR_ZLS_FORMAT_TYPE_16BITINT:
1112 value.value = _mesa_float_to_unorm(depth_clear, 16);
1113 break;
1114
1115 case ROGUE_CR_ZLS_FORMAT_TYPE_24BITINT:
1116 value.value = _mesa_float_to_unorm(depth_clear, 24);
1117 break;
1118
1119 default:
1120 UNREACHABLE("Unsupported depth format");
1121 }
1122 }
1123 stream_ptr += pvr_cmd_length(CR_ISP_BGOBJDEPTH);
1124
1125 pvr_csb_pack (stream_ptr, CR_ISP_BGOBJVALS, value) {
1126 value.enablebgtag = job->enable_bg_tag;
1127
1128 value.mask = true;
1129
1130 value.stencil = job->ds_clear_value.stencil & 0xFF;
1131 }
1132 stream_ptr += pvr_cmd_length(CR_ISP_BGOBJVALS);
1133
1134 pvr_csb_pack (stream_ptr, CR_ISP_AA, value) {
1135 value.mode = isp_aa_mode;
1136 }
1137 stream_ptr += pvr_cmd_length(CR_ISP_AA);
1138
1139 pvr_arch_rt_mtile_info_init(dev_info,
1140 &tiling_info,
1141 rt_dataset->width,
1142 rt_dataset->height,
1143 rt_dataset->samples);
1144 pvr_csb_pack (stream_ptr, CR_ISP_CTL, value) {
1145 value.sample_pos = true;
1146 value.process_empty_tiles = job->process_empty_tiles;
1147
1148 /* For integer depth formats we'll convert the specified floating point
1149 * depth bias values and specify them as integers. In this mode a depth
1150 * bias factor of 1.0 equates to 1 ULP of increase to the depth value.
1151 */
1152 value.dbias_is_int = PVR_HAS_ENHANCEMENT(dev_info, 42307) &&
1153 pvr_zls_format_type_is_int(job->ds.zls_format);
1154
1155 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) {
1156 value.skip_init_hdrs = true;
1157
1158 if (PVR_HAS_QUIRK(dev_info, 72168)) {
1159 /* x_tile_max is the 0-based index of the last 16x16 tile in a row.
1160 * We cannot set SKIP_INIT_HDRS if the number of tile group rows is
1161 * odd AND the width is <= 2 tiles.
1162 */
1163 if (((((tiling_info.y_tile_max + 1) / 2) & 0x1) == 1) &&
1164 (tiling_info.x_tile_max <= 1)) {
1165 value.skip_init_hdrs = false;
1166 }
1167 }
1168
1169 if (PVR_HAS_QUIRK(dev_info, 72463)) {
1170 /* We cannot set SKIP_INIT_HDRS if the number of tile group rows is
1171 * <= 2 AND the width is <= 2 tiles.
1172 */
1173 if ((((tiling_info.y_tile_max + 1) / 2) <= 2) &&
1174 (tiling_info.x_tile_max <= 1)) {
1175 value.skip_init_hdrs = false;
1176 }
1177 }
1178 }
1179 }
1180 /* FIXME: When pvr_setup_tiles_in_flight() is refactored it might be
1181 * possible to fully pack CR_ISP_CTL above rather than having to OR in part
1182 * of the value.
1183 */
1184 *stream_ptr |= isp_ctl;
1185 stream_ptr += pvr_cmd_length(CR_ISP_CTL);
1186
1187 pvr_csb_pack (stream_ptr, CR_EVENT_PIXEL_PDS_INFO, value) {
1188 value.const_size =
1189 DIV_ROUND_UP(ctx->device->pixel_event_data_size_in_dwords,
1190 ROGUE_CR_EVENT_PIXEL_PDS_INFO_CONST_SIZE_UNIT_SIZE);
1191 value.temp_stride = 0;
1192 value.usc_sr_size =
1193 DIV_ROUND_UP(PVR_STATE_PBE_DWORDS,
1194 ROGUE_CR_EVENT_PIXEL_PDS_INFO_USC_SR_SIZE_UNIT_SIZE);
1195 }
1196 stream_ptr += pvr_cmd_length(CR_EVENT_PIXEL_PDS_INFO);
1197
1198 if (PVR_HAS_FEATURE(dev_info, cluster_grouping)) {
1199 pvr_csb_pack (stream_ptr, KMD_STREAM_PIXEL_PHANTOM, value) {
1200 /* Each phantom has its own MCU, so atomicity can only be guaranteed
1201 * when all work items are processed on the same phantom. This means
1202 * we need to disable all USCs other than those of the first
1203 * phantom, which has 4 clusters. Note that we only need to do this
1204 * for atomic operations in fragment shaders, since hardware
1205 * prevents the TA to run on more than one phantom anyway.
1206 */
1207 /* Note that leaving all phantoms disabled (as csbgen will do by
1208 * default since it will zero out things) will set them to their
1209 * default state (i.e. enabled) instead of disabling them.
1210 */
1211 if (PVR_HAS_FEATURE(dev_info, slc_mcu_cache_controls) &&
1212 dev_runtime_info->num_phantoms > 1 && job->frag_uses_atomic_ops) {
1213 value.phantom_0 = ROGUE_KMD_STREAM_PIXEL_PHANTOM_STATE_ENABLED;
1214 }
1215 }
1216 stream_ptr += pvr_cmd_length(KMD_STREAM_PIXEL_PHANTOM);
1217 }
1218
1219 pvr_csb_pack (stream_ptr, KMD_STREAM_VIEW_IDX, value) {
1220 value.idx = job->view_state.view_index;
1221 }
1222 stream_ptr += pvr_cmd_length(KMD_STREAM_VIEW_IDX);
1223
1224 /* Make sure that the pvr_frag_km_...() function is returning the correct
1225 * offset.
1226 */
1227 assert((uint8_t *)stream_ptr - (uint8_t *)state->fw_stream ==
1228 pvr_frag_km_stream_pds_eot_data_addr_offset(dev_info));
1229
1230 if (job->view_state.force_pds_pixel_event_data_offset_zero)
1231 view_index = 0;
1232 else
1233 view_index = job->view_state.view_index;
1234
1235 pvr_csb_pack (stream_ptr, CR_EVENT_PIXEL_PDS_DATA, value) {
1236 value.addr = PVR_DEV_ADDR(
1237 job->view_state.view[view_index].pds_pixel_event_data_offset);
1238 }
1239 stream_ptr += pvr_cmd_length(CR_EVENT_PIXEL_PDS_DATA);
1240
1241 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) {
1242 if (device->pdevice->dev_runtime_info.core_count > 1)
1243 pvr_finishme("Emit isp_oclqry_stride, core_count is greater than one");
1244 *stream_ptr = 0;
1245 stream_ptr++;
1246 }
1247
1248 if (PVR_HAS_FEATURE(dev_info, zls_subtile)) {
1249 pvr_csb_pack (stream_ptr, CR_ISP_ZLS_PIXELS, value) {
1250 if (job->has_depth_attachment) {
1251 if (job->ds.has_alignment_transfers) {
1252 value.x = job->ds.physical_extent.width - 1;
1253 value.y = job->ds.physical_extent.height - 1;
1254 } else {
1255 value.x = job->ds.stride - 1;
1256 value.y = job->ds.height - 1;
1257 }
1258 }
1259 }
1260 stream_ptr += pvr_cmd_length(CR_ISP_ZLS_PIXELS);
1261 }
1262
1263 /* zls_stride */
1264 *stream_ptr = job->has_depth_attachment ? job->ds.layer_size : 0;
1265 stream_ptr++;
1266
1267 /* sls_stride */
1268 *stream_ptr = job->has_stencil_attachment ? job->ds.layer_size : 0;
1269 stream_ptr++;
1270
1271 if (PVR_HAS_FEATURE(dev_info, gpu_multicore_support)) {
1272 if (device->pdevice->dev_runtime_info.core_count > 1)
1273 pvr_finishme("Emit execute_count core_count is greater than one");
1274 *stream_ptr = 0;
1275 stream_ptr++;
1276 }
1277
1278 state->fw_stream_len = (uint8_t *)stream_ptr - (uint8_t *)state->fw_stream;
1279 assert(state->fw_stream_len <= ARRAY_SIZE(state->fw_stream));
1280
1281 pvr_csb_pack ((uint64_t *)stream_len_ptr, KMD_STREAM_HDR, value) {
1282 value.length = state->fw_stream_len;
1283 }
1284 }
1285
1286 #undef DWORDS_PER_U64
1287
1288 static void
1289 pvr_frag_state_stream_ext_init(struct pvr_render_ctx *ctx,
1290 struct pvr_render_job *job,
1291 struct pvr_winsys_fragment_state *state)
1292 {
1293 const struct pvr_device_info *dev_info = &ctx->device->pdevice->dev_info;
1294
1295 uint32_t main_stream_len =
1296 pvr_csb_unpack((uint64_t *)state->fw_stream, KMD_STREAM_HDR).length;
1297 uint32_t *ext_stream_ptr =
1298 (uint32_t *)((uint8_t *)state->fw_stream + main_stream_len);
1299 uint32_t *header0_ptr;
1300
1301 header0_ptr = ext_stream_ptr;
1302 ext_stream_ptr += pvr_cmd_length(KMD_STREAM_EXTHDR_FRAG0);
1303
1304 pvr_csb_pack (header0_ptr, KMD_STREAM_EXTHDR_FRAG0, header0) {
1305 if (PVR_HAS_QUIRK(dev_info, 49927)) {
1306 header0.has_brn49927 = true;
1307
1308 /* The set up of CR_TPU must be identical to
1309 * pvr_render_job_ws_geometry_state_stream_ext_init().
1310 */
1311 pvr_csb_pack (ext_stream_ptr, CR_TPU, value) {
1312 value.tag_cem_4k_face_packing = true;
1313 }
1314 ext_stream_ptr += pvr_cmd_length(CR_TPU);
1315 }
1316 }
1317
1318 if ((*header0_ptr & ROGUE_KMD_STREAM_EXTHDR_DATA_MASK) != 0) {
1319 state->fw_stream_len =
1320 (uint8_t *)ext_stream_ptr - (uint8_t *)state->fw_stream;
1321 assert(state->fw_stream_len <= ARRAY_SIZE(state->fw_stream));
1322 }
1323 }
1324
1325 static void
1326 pvr_frag_state_flags_init(const struct pvr_render_job *const job,
1327 struct pvr_winsys_fragment_state_flags *flags)
1328 {
1329 *flags = (struct pvr_winsys_fragment_state_flags){
1330 .has_depth_buffer = job->has_depth_attachment,
1331 .has_stencil_buffer = job->has_stencil_attachment,
1332 .prevent_cdm_overlap = job->disable_compute_overlap,
1333 .use_single_core = job->frag_uses_atomic_ops,
1334 .get_vis_results = job->get_vis_results,
1335 .has_spm_scratch_buffer = job->requires_spm_scratch_buffer,
1336 .disable_pixel_merging = job->disable_pixel_merging,
1337 };
1338 }
1339
1340 static void
1341 pvr_render_job_ws_fragment_state_init(struct pvr_render_ctx *ctx,
1342 struct pvr_render_job *job,
1343 struct vk_sync *wait,
1344 struct pvr_winsys_fragment_state *state)
1345 {
1346 pvr_frag_state_stream_init(ctx, job, state);
1347 pvr_frag_state_stream_ext_init(ctx, job, state);
1348
1349 state->wait = wait;
1350 pvr_frag_state_flags_init(job, &state->flags);
1351 }
1352
1353 /**
1354 * \brief Sets up the fragment state for a Partial Render (PR) based on the
1355 * state for a normal fragment job.
1356 *
1357 * The state of a fragment PR is almost the same as of that for a normal
1358 * fragment job apart the PBE words and the EOT program, both of which are
1359 * necessary for the render to use the SPM scratch buffer instead of the final
1360 * render targets.
1361 *
1362 * By basing the fragment PR state on that of a normal fragment state,
1363 * repacking of the same words can be avoided as we end up mostly doing copies
1364 * instead.
1365 */
1366 static void pvr_render_job_ws_fragment_pr_init_based_on_fragment_state(
1367 const struct pvr_render_ctx *ctx,
1368 struct pvr_render_job *job,
1369 struct vk_sync *wait,
1370 struct pvr_winsys_fragment_state *frag,
1371 struct pvr_winsys_fragment_state *state)
1372 {
1373 const struct pvr_device_info *const dev_info =
1374 &ctx->device->pdevice->dev_info;
1375 const uint32_t pbe_reg_byte_offset =
1376 pvr_frag_km_stream_pbe_reg_words_offset(dev_info);
1377 const uint32_t eot_data_addr_byte_offset =
1378 pvr_frag_km_stream_pds_eot_data_addr_offset(dev_info);
1379 const uint32_t view_index =
1380 job->view_state.force_pds_pixel_event_data_offset_zero
1381 ? 0
1382 : job->view_state.view_index;
1383 const uint32_t pr_pds_pixel_event_data_offset =
1384 job->view_state.use_pds_pixel_event_data_offset
1385 ? job->view_state.view[view_index].pds_pixel_event_data_offset
1386 : job->pr_pds_pixel_event_data_offset;
1387
1388 /* Massive copy :( */
1389 *state = *frag;
1390
1391 assert(state->fw_stream_len >=
1392 pbe_reg_byte_offset + sizeof(job->pr_pbe_reg_words));
1393 memcpy(&state->fw_stream[pbe_reg_byte_offset],
1394 job->pr_pbe_reg_words,
1395 sizeof(job->pr_pbe_reg_words));
1396
1397 /* TODO: Update this when csbgen is byte instead of dword granular. */
1398 assert(state->fw_stream_len >=
1399 eot_data_addr_byte_offset +
1400 PVR_DW_TO_BYTES(pvr_cmd_length(CR_EVENT_PIXEL_PDS_DATA)));
1401
1402 pvr_csb_pack ((uint32_t *)&state->fw_stream[eot_data_addr_byte_offset],
1403 CR_EVENT_PIXEL_PDS_DATA,
1404 eot_pds_data) {
1405 eot_pds_data.addr = PVR_DEV_ADDR(pr_pds_pixel_event_data_offset);
1406 }
1407 }
1408
1409 static void pvr_render_job_ws_submit_info_init(
1410 struct pvr_render_ctx *ctx,
1411 struct pvr_render_job *job,
1412 struct vk_sync *wait_geom,
1413 struct vk_sync *wait_frag,
1414 struct pvr_winsys_render_submit_info *submit_info)
1415 {
1416 memset(submit_info, 0, sizeof(*submit_info));
1417
1418 submit_info->rt_dataset =
1419 job->view_state.rt_datasets[job->view_state.view_index]->ws_rt_dataset;
1420 submit_info->rt_data_idx =
1421 job->view_state.rt_datasets[job->view_state.view_index]->rt_data_idx;
1422
1423 submit_info->frame_num = ctx->device->global_queue_present_count;
1424 submit_info->job_num = ctx->device->global_cmd_buffer_submit_count;
1425
1426 pvr_render_job_ws_geometry_state_init(ctx,
1427 job,
1428 wait_geom,
1429 &submit_info->geometry);
1430
1431 submit_info->has_fragment_job = job->run_frag;
1432
1433 /* TODO: Move the job setup from queue submit into cmd_buffer if possible. */
1434
1435 /* TODO: See if it's worth avoiding setting up the fragment state and setup
1436 * the pr state directly if `!job->run_frag`. For now we'll always set it up.
1437 */
1438 pvr_render_job_ws_fragment_state_init(ctx,
1439 job,
1440 wait_frag,
1441 &submit_info->fragment);
1442
1443 /* TODO: In some cases we could eliminate the pr and use the frag directly in
1444 * case we enter SPM. There's likely some performance improvement to be had
1445 * there. For now we'll always setup the pr.
1446 */
1447 pvr_render_job_ws_fragment_pr_init_based_on_fragment_state(
1448 ctx,
1449 job,
1450 wait_frag,
1451 &submit_info->fragment,
1452 &submit_info->fragment_pr);
1453 }
1454
1455 VkResult pvr_arch_render_job_submit(struct pvr_render_ctx *ctx,
1456 struct pvr_render_job *job,
1457 struct vk_sync *wait_geom,
1458 struct vk_sync *wait_frag,
1459 struct vk_sync *signal_sync_geom,
1460 struct vk_sync *signal_sync_frag)
1461 {
1462 struct pvr_rt_dataset *rt_dataset =
1463 job->view_state.rt_datasets[job->view_state.view_index];
1464 struct pvr_winsys_render_submit_info submit_info;
1465 struct pvr_device *device = ctx->device;
1466 VkResult result;
1467
1468 pvr_render_job_ws_submit_info_init(ctx,
1469 job,
1470 wait_geom,
1471 wait_frag,
1472 &submit_info);
1473
1474 #ifdef PVR_BUILD_ARCH_ROGUE
1475 if (PVR_IS_DEBUG_SET(DUMP_CONTROL_STREAM)) {
1476 /* FIXME: This isn't an ideal method of accessing the information we
1477 * need, but it's considered good enough for a debug code path. It can be
1478 * streamlined and made more correct if/when pvr_render_job becomes a
1479 * subclass of pvr_sub_cmd.
1480 */
1481 const struct pvr_sub_cmd *sub_cmd =
1482 container_of(job, const struct pvr_sub_cmd, gfx.job);
1483
1484 pvr_csb_dump(&sub_cmd->gfx.control_stream,
1485 submit_info.frame_num,
1486 submit_info.job_num);
1487 }
1488 #endif
1489
1490 result = device->ws->ops->render_submit(ctx->ws_ctx,
1491 &submit_info,
1492 &device->pdevice->dev_info,
1493 signal_sync_geom,
1494 signal_sync_frag);
1495 if (result != VK_SUCCESS)
1496 return result;
1497
1498 if (job->run_frag) {
1499 /* Move to the next render target data now that a fragment job has been
1500 * successfully submitted. This will allow the next geometry job to be
1501 * submitted to been run in parallel with it.
1502 */
1503 rt_dataset->rt_data_idx =
1504 (rt_dataset->rt_data_idx + 1) % ARRAY_SIZE(rt_dataset->rt_datas);
1505
1506 rt_dataset->need_frag = false;
1507 } else {
1508 rt_dataset->need_frag = true;
1509 }
1510
1511 return VK_SUCCESS;
1512 }