Debian Codegraph @

src/imagination/vulkan/pvr_arch_mrt.c

raw
1 /*
2 * Copyright © 2025 Imagination Technologies Ltd.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "pvr_mrt.h"
8
9 #include "vk_log.h"
10
11 #include "pvr_cmd_buffer.h"
12 #include "pvr_csb.h"
13 #include "pvr_device.h"
14 #include "pvr_formats.h"
15 #include "pvr_image.h"
16 #include "pvr_mrt.h"
17 #include "pvr_pass.h"
18 #include "pvr_physical_device.h"
19
20 #include "hwdef/rogue_hw_utils.h"
21 #include "util/macros.h"
22 #include "vulkan/vulkan_core.h"
23 #include "vulkan/runtime/vk_graphics_state.h"
24 #include "vulkan/runtime/vk_image.h"
25
26 /* Which parts of the output registers/a tile buffer are currently allocated. */
27 struct pvr_mrt_alloc_mask {
28 /* Bit array. A bit is set if the corresponding dword is allocated. */
29 BITSET_DECLARE(allocs, 8U);
30 };
31
32 struct pvr_mrt_alloc_ctx {
33 /* Which pixel output registers are allocated. */
34 struct pvr_mrt_alloc_mask output_reg;
35
36 /* Range of allocated output registers. */
37 uint32_t output_regs_count;
38
39 /* Number of tile buffers allocated. */
40 uint32_t tile_buffers_count;
41
42 /* Which parts of each tile buffer are allocated. Length is
43 * tile_buffers_count.
44 */
45 struct pvr_mrt_alloc_mask tile_buffers[PVR_MAX_TILE_BUFFER_COUNT];
46 };
47
48 static uint32_t pvr_get_accum_format_bitsize(VkFormat vk_format)
49 {
50 return pvr_get_pbe_accum_format_size_in_bytes(vk_format) * 8;
51 }
52
53 /**
54 * Check if there is space in a buffer for storing a render target of a
55 * specified size.
56 */
57 static int32_t pvr_mrt_alloc_from_buffer(const struct pvr_device_info *dev_info,
58 struct pvr_mrt_alloc_mask *buffer,
59 uint32_t pixel_size)
60 {
61 const uint32_t max_out_regs = rogue_get_max_output_regs_per_pixel(dev_info);
62 uint32_t alignment = 1U;
63
64 if (PVR_HAS_FEATURE(dev_info, pbe2_in_xe)) {
65 /* For a 64-bit/128-bit source format: the start offset must be even. */
66 if (pixel_size == 2U || pixel_size == 4U)
67 alignment = 2U;
68 }
69
70 assert(pixel_size <= max_out_regs);
71
72 for (uint32_t i = 0U; i <= (max_out_regs - pixel_size); i += alignment) {
73 if (!BITSET_TEST_COUNT(buffer->allocs, i, pixel_size)) {
74 BITSET_SET_COUNT(buffer->allocs, i, pixel_size);
75 return i;
76 }
77 }
78
79 return -1;
80 }
81
82 void pvr_arch_init_mrt_desc(VkFormat format, struct usc_mrt_desc *desc)
83 {
84 uint32_t pixel_size_in_chunks;
85 uint32_t pixel_size_in_bits;
86
87 /* TODO: Add support for packing multiple attachments into the same
88 * register
89 */
90 const uint32_t part_bits = 0;
91 if (vk_format_is_color(format) &&
92 pvr_arch_get_pbe_accum_format(format) == PVR_PBE_ACCUM_FORMAT_INVALID) {
93 /* The VkFormat is not supported as a color attachment so `0`.
94 * vulkan doesn't seem to restrict vkCreateRenderPass() to supported
95 * formats only.
96 */
97 pixel_size_in_bits = 0;
98 } else {
99 /* TODO: handle IMG_PIXFMT_A8_UNORM
100 * For alpha only formats alpha is still placed in channel 3, so channels
101 * 0-2 need to be allocated but are left unused
102 */
103 pixel_size_in_bits = pvr_get_accum_format_bitsize(format);
104 }
105
106 desc->intermediate_size = DIV_ROUND_UP(pixel_size_in_bits, CHAR_BIT);
107
108 pixel_size_in_chunks = DIV_ROUND_UP(pixel_size_in_bits, 32U);
109 for (uint32_t j = 0U; j < pixel_size_in_chunks; j++)
110 desc->valid_mask[j] = ~0;
111
112 if (part_bits > 0U)
113 desc->valid_mask[pixel_size_in_chunks] = BITFIELD_MASK(part_bits);
114 }
115
116 static VkResult pvr_alloc_mrt(const struct pvr_device_info *dev_info,
117 struct pvr_mrt_alloc_ctx *alloc,
118 struct usc_mrt_setup *setup,
119 unsigned rt,
120 VkFormat format)
121 {
122 struct usc_mrt_resource *resource = &setup->mrt_resources[rt];
123
124 const uint32_t pixel_size =
125 DIV_ROUND_UP(pvr_get_accum_format_bitsize(format), 32U);
126
127 const int32_t output_reg =
128 pvr_mrt_alloc_from_buffer(dev_info, &alloc->output_reg, pixel_size);
129
130 if (output_reg != -1) {
131 resource->type = USC_MRT_RESOURCE_TYPE_OUTPUT_REG;
132 resource->reg.output_reg = output_reg;
133 resource->reg.offset = 0;
134
135 alloc->output_regs_count =
136 MAX2(alloc->output_regs_count, resource->reg.output_reg + pixel_size);
137 } else {
138 resource->type = USC_MRT_RESOURCE_TYPE_MEMORY;
139
140 unsigned tib = 0;
141 for (; tib < alloc->tile_buffers_count; tib++) {
142 struct pvr_mrt_alloc_mask *tib_alloc = &alloc->tile_buffers[tib];
143
144 const int32_t tile_buffer_offset =
145 pvr_mrt_alloc_from_buffer(dev_info, tib_alloc, pixel_size);
146
147 if (tile_buffer_offset != -1) {
148 resource->mem.tile_buffer = tib;
149 resource->mem.offset_dw = tile_buffer_offset;
150 break;
151 }
152 }
153
154 if (tib == alloc->tile_buffers_count) {
155 if (alloc->tile_buffers_count == PVR_MAX_TILE_BUFFER_COUNT)
156 return vk_error(NULL, VK_ERROR_TOO_MANY_OBJECTS);
157
158 resource->mem.tile_buffer = alloc->tile_buffers_count;
159 resource->mem.offset_dw = 0;
160 }
161
162 /* If needed a new tile buffer than those that were allocated, then wipe
163 * it bump the global count.
164 */
165 if (resource->mem.tile_buffer >= alloc->tile_buffers_count) {
166 memset(
167 &alloc->tile_buffers[alloc->tile_buffers_count],
168 0U,
169 sizeof(alloc->tile_buffers[0U]) *
170 (resource->mem.tile_buffer + 1U - alloc->tile_buffers_count));
171 alloc->tile_buffers_count = resource->mem.tile_buffer + 1U;
172
173 /* Need to add the resource to the new tile buffer */
174 struct pvr_mrt_alloc_mask *tib_alloc =
175 &alloc->tile_buffers[resource->mem.tile_buffer];
176
177 ASSERTED const int32_t tile_buffer_offset =
178 pvr_mrt_alloc_from_buffer(dev_info,
179 tib_alloc,
180 pixel_size);
181 assert(tile_buffer_offset == 0);
182 }
183
184 /* The hardware makes the bit depth of the on-chip storage and memory
185 * storage the same so make sure the memory storage is large enough to
186 * accommodate the largest render target.
187 */
188 alloc->output_regs_count =
189 MAX2(alloc->output_regs_count, resource->mem.offset_dw + pixel_size);
190 }
191
192 pvr_arch_init_mrt_desc(format, &resource->mrt_desc);
193 resource->intermediate_size = resource->mrt_desc.intermediate_size;
194
195 setup->num_render_targets++;
196
197 return VK_SUCCESS;
198 }
199
200 VkResult
201 pvr_arch_mrt_setup_partial_init(struct pvr_device *const device,
202 struct usc_mrt_setup *mrt_setup,
203 uint32_t num_renger_targets,
204 uint32_t num_output_regs,
205 uint32_t num_tile_buffers)
206 {
207 struct usc_mrt_resource *mrt_resources = NULL;
208
209 if (num_renger_targets) {
210 const uint32_t size =
211 num_renger_targets * sizeof(*mrt_setup->mrt_resources);
212
213 mrt_resources = vk_zalloc(&device->vk.alloc,
214 size,
215 8,
216 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
217 if (!mrt_resources)
218 return VK_ERROR_OUT_OF_HOST_MEMORY;
219 }
220
221 *mrt_setup = (struct usc_mrt_setup){
222 .num_render_targets = num_renger_targets,
223 .num_output_regs = num_output_regs,
224 .num_tile_buffers = num_tile_buffers,
225 .mrt_resources = mrt_resources,
226 };
227
228 return VK_SUCCESS;
229 }
230
231 VkResult
232 pvr_arch_init_usc_mrt_setup(struct pvr_device *device,
233 uint32_t attachment_count,
234 const VkFormat attachment_formats[attachment_count],
235 struct usc_mrt_setup *setup)
236 {
237 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
238 struct pvr_mrt_alloc_ctx alloc = { 0 };
239 VkResult result;
240
241 memset(setup, 0, sizeof(*setup));
242
243 if (!attachment_count)
244 goto early_exit;
245
246 setup->mrt_resources =
247 vk_alloc(&device->vk.alloc,
248 sizeof(*setup->mrt_resources) * attachment_count,
249 8U,
250 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
251 if (!setup->mrt_resources)
252 return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
253
254 for (unsigned i = 0; i < attachment_count; i++) {
255 VkFormat att_format = attachment_formats[i];
256 assert(att_format != VK_FORMAT_UNDEFINED);
257
258 result = pvr_alloc_mrt(dev_info, &alloc, setup, i, att_format);
259 if (result != VK_SUCCESS) {
260 result = vk_error(NULL, VK_ERROR_OUT_OF_DEVICE_MEMORY);
261 goto fail;
262 }
263 }
264
265 early_exit:
266 setup->num_output_regs = util_next_power_of_two(alloc.output_regs_count);
267 setup->num_tile_buffers = alloc.tile_buffers_count;
268 return VK_SUCCESS;
269 fail:
270 vk_free(&device->vk.alloc, setup->mrt_resources);
271 return result;
272 }
273
274 void pvr_arch_destroy_mrt_setup(const struct pvr_device *device,
275 struct usc_mrt_setup *setup)
276 {
277 if (!setup)
278 return;
279
280 vk_free(&device->vk.alloc, setup->mrt_resources);
281 }
282
283 static bool
284 pvr_rendering_info_needs_load(const struct pvr_dynamic_render_info *dr_info)
285 {
286 for (unsigned i = 0; i < dr_info->hw_render.color_init_count; i++) {
287 const uint32_t index = dr_info->hw_render.color_init[i].index;
288 if (index == VK_ATTACHMENT_UNUSED)
289 continue;
290
291 const VkAttachmentLoadOp op = dr_info->hw_render.color_init[i].op;
292 if (op == VK_ATTACHMENT_LOAD_OP_LOAD || op == VK_ATTACHMENT_LOAD_OP_CLEAR)
293 return true;
294 }
295
296 return false;
297 }
298
299 static VkResult pvr_mrt_load_op_init(struct pvr_device *device,
300 const VkAllocationCallbacks *alloc,
301 const struct pvr_render_pass_info *rp_info,
302 struct pvr_load_op *load_op,
303 uint32_t view_idx)
304 {
305 const struct pvr_dynamic_render_info *dr_info = rp_info->dr_info;
306 VkResult result;
307
308 load_op->clears_loads_state.depth_clear_to_reg = PVR_NO_DEPTH_CLEAR_TO_REG;
309
310 assert(dr_info->hw_render.color_init_count <=
311 PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS);
312 for (unsigned i = 0; i < dr_info->hw_render.color_init_count; i++) {
313 const struct pvr_renderpass_colorinit *color_init =
314 &dr_info->hw_render.color_init[i];
315 const struct pvr_image *image;
316
317 assert(color_init->index < rp_info->attachment_count);
318 load_op->clears_loads_state.dest_vk_format[i] =
319 rp_info->attachments[color_init->index]->vk.view_format;
320
321 image = pvr_image_view_get_image(rp_info->attachments[color_init->index]);
322 if (image->vk.samples > VK_SAMPLE_COUNT_1_BIT)
323 load_op->clears_loads_state.unresolved_msaa_mask |= BITFIELD_BIT(i);
324
325 switch (color_init->op) {
326 case VK_ATTACHMENT_LOAD_OP_CLEAR:
327 load_op->clears_loads_state.rt_clear_mask |= BITFIELD_BIT(i);
328 break;
329 case VK_ATTACHMENT_LOAD_OP_LOAD:
330 load_op->clears_loads_state.rt_load_mask |= BITFIELD_BIT(i);
331 break;
332 case VK_ATTACHMENT_LOAD_OP_DONT_CARE:
333 case VK_ATTACHMENT_LOAD_OP_NONE:
334 break;
335 default:
336 UNREACHABLE("unsupported loadOp");
337 }
338 }
339
340 load_op->clears_loads_state.mrt_setup = &dr_info->hw_render.init_setup;
341
342 result = pvr_arch_load_op_shader_generate(device, alloc, load_op);
343 if (result != VK_SUCCESS) {
344 vk_free2(&device->vk.alloc, alloc, load_op);
345 return result;
346 }
347
348 load_op->view_indices[0] = view_idx;
349 load_op->view_count = 1;
350
351 load_op->is_hw_object = true;
352 load_op->hw_render = &dr_info->hw_render;
353
354 return VK_SUCCESS;
355 }
356
357 static void pvr_load_op_fini(struct pvr_load_op *load_op)
358 {
359 pvr_bo_suballoc_free(load_op->pds_tex_state_prog.pvr_bo);
360 pvr_bo_suballoc_free(load_op->pds_frag_prog.pvr_bo);
361 pvr_bo_suballoc_free(load_op->usc_frag_prog_bo);
362 }
363
364 static void pvr_load_op_destroy(struct pvr_device *device,
365 const VkAllocationCallbacks *allocator,
366 struct pvr_load_op *load_op)
367 {
368 pvr_load_op_fini(load_op);
369 vk_free2(&device->vk.alloc, allocator, load_op);
370 }
371
372 void pvr_arch_mrt_load_op_state_cleanup(const struct pvr_device *device,
373 const VkAllocationCallbacks *alloc,
374 struct pvr_load_op_state *state)
375 {
376 if (!state)
377 return;
378
379 while (state->load_op_count--) {
380 const uint32_t load_op_idx = state->load_op_count;
381 struct pvr_load_op *load_op = &state->load_ops[load_op_idx];
382
383 pvr_load_op_fini(load_op);
384 }
385
386 vk_free2(&device->vk.alloc, alloc, state);
387 }
388
389 static VkResult
390 pvr_mrt_load_op_state_create(struct pvr_device *device,
391 const VkAllocationCallbacks *alloc,
392 const struct pvr_render_pass_info *rp_info,
393 struct pvr_load_op_state **state)
394 {
395 const struct pvr_dynamic_render_info *dr_info = rp_info->dr_info;
396 const uint32_t view_count = util_bitcount(dr_info->hw_render.view_mask);
397 struct pvr_load_op_state *load_op_state;
398 struct pvr_load_op *load_ops;
399 VkResult result;
400
401 VK_MULTIALLOC(ma);
402 vk_multialloc_add(&ma, &load_op_state, __typeof__(*load_op_state), 1);
403 vk_multialloc_add(&ma, &load_ops, __typeof__(*load_ops), view_count);
404
405 if (!vk_multialloc_zalloc(&ma, alloc, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE))
406 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
407
408 load_op_state->load_ops = load_ops;
409
410 u_foreach_bit (view_idx, dr_info->hw_render.view_mask) {
411 struct pvr_load_op *const load_op =
412 &load_op_state->load_ops[load_op_state->load_op_count];
413
414 result = pvr_mrt_load_op_init(device, alloc, rp_info, load_op, view_idx);
415 if (result != VK_SUCCESS)
416 goto err_load_op_state_cleanup;
417
418 load_op_state->load_op_count++;
419 }
420
421 *state = load_op_state;
422
423 return VK_SUCCESS;
424
425 err_load_op_state_cleanup:
426 pvr_arch_mrt_load_op_state_cleanup(device, alloc, load_op_state);
427
428 return result;
429 }
430
431 /* TODO: Can we gaurantee that if we have at least one render target there will
432 * be a render target allocated as a REG?
433 */
434 static inline bool
435 pvr_needs_output_register_writes(const struct usc_mrt_setup *setup)
436 {
437 for (uint32_t i = 0; i < setup->num_render_targets; i++) {
438 struct usc_mrt_resource *mrt_resource = &setup->mrt_resources[i];
439
440 if (mrt_resource->type == USC_MRT_RESOURCE_TYPE_OUTPUT_REG)
441 return true;
442 }
443
444 return false;
445 }
446
447 static inline VkResult
448 pvr_mrt_add_missing_output_register_write(struct usc_mrt_setup *setup,
449 const VkAllocationCallbacks *alloc)
450 {
451 const uint32_t last = setup->num_render_targets;
452 struct usc_mrt_resource *mrt_resources;
453
454 if (pvr_needs_output_register_writes(setup))
455 return VK_SUCCESS;
456
457 setup->num_render_targets++;
458
459 mrt_resources =
460 vk_realloc(alloc,
461 setup->mrt_resources,
462 setup->num_render_targets * sizeof(*mrt_resources),
463 8U,
464 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
465
466 if (!mrt_resources)
467 return VK_ERROR_OUT_OF_HOST_MEMORY;
468
469 setup->mrt_resources = mrt_resources;
470
471 mrt_resources[last].type = USC_MRT_RESOURCE_TYPE_OUTPUT_REG;
472 mrt_resources[last].reg.output_reg = 0U;
473 mrt_resources[last].reg.offset = 0U;
474 mrt_resources[last].intermediate_size = 4U;
475 mrt_resources[last].mrt_desc.intermediate_size = 4U;
476 mrt_resources[last].mrt_desc.priority = 0U;
477 mrt_resources[last].mrt_desc.valid_mask[0U] = ~0;
478 mrt_resources[last].mrt_desc.valid_mask[1U] = ~0;
479 mrt_resources[last].mrt_desc.valid_mask[2U] = ~0;
480 mrt_resources[last].mrt_desc.valid_mask[3U] = ~0;
481
482 return VK_SUCCESS;
483 }
484
485 VkResult pvr_arch_mrt_load_ops_setup(struct pvr_cmd_buffer *cmd_buffer,
486 const VkAllocationCallbacks *alloc,
487 struct pvr_load_op_state **load_op_state)
488 {
489 const struct pvr_cmd_buffer_state *state = &cmd_buffer->state;
490 const struct pvr_dynamic_render_info *dr_info =
491 state->render_pass_info.dr_info;
492 struct pvr_device *device = cmd_buffer->device;
493 VkResult result = VK_SUCCESS;
494
495 if (dr_info->mrt_setup->num_tile_buffers) {
496 result = pvr_device_tile_buffer_ensure_cap(
497 device,
498 dr_info->mrt_setup->num_tile_buffers);
499
500 if (result != VK_SUCCESS)
501 return result;
502 }
503
504 if (!pvr_rendering_info_needs_load(dr_info))
505 return VK_SUCCESS;
506
507 result =
508 pvr_mrt_add_missing_output_register_write(dr_info->mrt_setup, alloc);
509 if (result != VK_SUCCESS)
510 return result;
511
512 result = pvr_mrt_load_op_state_create(device,
513 alloc,
514 &state->render_pass_info,
515 load_op_state);
516
517 return result;
518 }
519
520 VkResult pvr_arch_pds_unitex_state_program_create_and_upload(
521 struct pvr_device *device,
522 const VkAllocationCallbacks *allocator,
523 uint32_t texture_kicks,
524 uint32_t uniform_kicks,
525 struct pvr_pds_upload *const pds_upload_out)
526 {
527 struct pvr_pds_pixel_shader_sa_program program = {
528 .num_texture_dma_kicks = texture_kicks,
529 .num_uniform_dma_kicks = uniform_kicks,
530 };
531 uint32_t staging_buffer_size;
532 uint32_t *staging_buffer;
533 VkResult result;
534
535 pvr_pds_set_sizes_pixel_shader_uniform_texture_code(&program);
536
537 staging_buffer_size = PVR_DW_TO_BYTES(program.code_size);
538
539 staging_buffer = vk_alloc2(&device->vk.alloc,
540 allocator,
541 staging_buffer_size,
542 8U,
543 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
544 if (!staging_buffer)
545 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
546
547 pvr_pds_generate_pixel_shader_sa_code_segment(&program, staging_buffer);
548
549 /* FIXME: Figure out the define for alignment of 16. */
550 result = pvr_gpu_upload_pds(device,
551 NULL,
552 0U,
553 0U,
554 staging_buffer,
555 program.code_size,
556 16U,
557 16U,
558 pds_upload_out);
559 if (result != VK_SUCCESS) {
560 vk_free2(&device->vk.alloc, allocator, staging_buffer);
561 return result;
562 }
563
564 vk_free2(&device->vk.alloc, allocator, staging_buffer);
565
566 return VK_SUCCESS;
567 }
568
569 static VkResult pvr_pds_fragment_program_create_and_upload(
570 struct pvr_device *device,
571 const VkAllocationCallbacks *allocator,
572 pco_shader *fs,
573 struct pvr_suballoc_bo *shader_bo,
574 struct pvr_pds_upload *pds_frag_prog,
575 bool msaa)
576 {
577 struct pvr_pds_kickusc_program program = { 0 };
578 pco_data *fs_data = pco_shader_data(fs);
579 uint32_t staging_buffer_size;
580 uint32_t *staging_buffer;
581 VkResult result;
582
583 const pvr_dev_addr_t exec_addr =
584 PVR_DEV_ADDR_OFFSET(shader_bo->dev_addr, fs_data->common.entry_offset);
585
586 /* Note this is not strictly required to be done before calculating the
587 * staging_buffer_size in this particular case. It can also be done after
588 * allocating the buffer. The size from pvr_pds_kick_usc() is constant.
589 */
590 pvr_pds_setup_doutu(&program.usc_task_control,
591 exec_addr.addr,
592 fs_data->common.temps,
593 msaa ? ROGUE_PDSINST_DOUTU_SAMPLE_RATE_FULL
594 : ROGUE_PDSINST_DOUTU_SAMPLE_RATE_INSTANCE,
595 fs_data->fs.uses.phase_change);
596
597 pvr_pds_kick_usc(&program, NULL, 0, false, PDS_GENERATE_SIZES);
598
599 staging_buffer_size = PVR_DW_TO_BYTES(program.code_size + program.data_size);
600
601 staging_buffer = vk_alloc2(&device->vk.alloc,
602 allocator,
603 staging_buffer_size,
604 8,
605 VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
606 if (!staging_buffer)
607 return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY);
608
609 pvr_pds_kick_usc(&program,
610 staging_buffer,
611 0,
612 false,
613 PDS_GENERATE_CODEDATA_SEGMENTS);
614
615 /* FIXME: Figure out the define for alignment of 16. */
616 result = pvr_gpu_upload_pds(device,
617 &staging_buffer[0],
618 program.data_size,
619 16,
620 &staging_buffer[program.data_size],
621 program.code_size,
622 16,
623 16,
624 pds_frag_prog);
625 if (result != VK_SUCCESS) {
626 vk_free2(&device->vk.alloc, allocator, staging_buffer);
627 return result;
628 }
629
630 vk_free2(&device->vk.alloc, allocator, staging_buffer);
631
632 return VK_SUCCESS;
633 }
634
635 VkResult
636 pvr_arch_load_op_shader_generate(struct pvr_device *device,
637 const VkAllocationCallbacks *allocator,
638 struct pvr_load_op *load_op)
639 {
640 const struct pvr_device_info *dev_info = &device->pdevice->dev_info;
641 const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info);
642
643 pco_shader *loadop = pvr_uscgen_loadop(device->pdevice->pco_ctx, load_op);
644
645 VkResult result = pvr_gpu_upload_usc(device,
646 pco_shader_binary_data(loadop),
647 pco_shader_binary_size(loadop),
648 cache_line_size,
649 &load_op->usc_frag_prog_bo);
650
651 if (result != VK_SUCCESS) {
652 ralloc_free(loadop);
653 return result;
654 }
655
656 const bool msaa = load_op->clears_loads_state.unresolved_msaa_mask &
657 load_op->clears_loads_state.rt_load_mask;
658
659 result =
660 pvr_pds_fragment_program_create_and_upload(device,
661 allocator,
662 loadop,
663 load_op->usc_frag_prog_bo,
664 &load_op->pds_frag_prog,
665 msaa);
666
667 load_op->temps_count = pco_shader_data(loadop)->common.temps;
668 ralloc_free(loadop);
669
670 if (result != VK_SUCCESS)
671 goto err_free_usc_frag_prog_bo;
672
673 /* Manually hard coding `texture_kicks` to 1 since we'll pack everything into
674 * one buffer to be DMAed. See `pvr_load_op_data_create_and_upload()`, where
675 * we upload the buffer and upload the code section.
676 */
677 result = pvr_arch_pds_unitex_state_program_create_and_upload(
678 device,
679 allocator,
680 1U,
681 0U,
682 &load_op->pds_tex_state_prog);
683 if (result != VK_SUCCESS)
684 goto err_free_pds_frag_prog;
685
686 return VK_SUCCESS;
687
688 err_free_pds_frag_prog:
689 pvr_bo_suballoc_free(load_op->pds_frag_prog.pvr_bo);
690
691 err_free_usc_frag_prog_bo:
692 pvr_bo_suballoc_free(load_op->usc_frag_prog_bo);
693
694 return result;
695 }