| 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 "pvr_job_context.h" |
| 25 |
|
| 26 |
#include <assert.h> |
| 27 |
#include <stdbool.h> |
| 28 |
#include <stddef.h> |
| 29 |
#include <stdint.h> |
| 30 |
#include <stdio.h> |
| 31 |
#include <vulkan/vulkan.h> |
| 32 |
|
| 33 |
#include "hwdef/rogue_hw_utils.h" |
| 34 |
#include "pco_uscgen_programs.h" |
| 35 |
#include "pvr_bo.h" |
| 36 |
#include "pvr_common.h" |
| 37 |
#include "pvr_csb.h" |
| 38 |
#include "pvr_device.h" |
| 39 |
#include "pvr_macros.h" |
| 40 |
#include "pvr_mrt.h" |
| 41 |
#include "pvr_pass.h" |
| 42 |
#include "pvr_pds.h" |
| 43 |
#include "pvr_physical_device.h" |
| 44 |
#include "pvr_transfer_frag_store.h" |
| 45 |
#include "pvr_types.h" |
| 46 |
#include "pvr_usc.h" |
| 47 |
#include "pvr_winsys.h" |
| 48 |
#include "util/macros.h" |
| 49 |
#include "util/os_file.h" |
| 50 |
#include "vk_alloc.h" |
| 51 |
#include "vk_log.h" |
| 52 |
|
| 53 |
/* TODO: Is there some way to ensure the Vulkan driver doesn't exceed this |
| 54 |
* value when constructing the control stream? |
| 55 |
*/ |
| 56 |
/* The VDM callstack is used by the hardware to implement control stream links |
| 57 |
* with a return, i.e. sub-control streams/subroutines. This value specifies the |
| 58 |
* maximum callstack depth. |
| 59 |
*/ |
| 60 |
#define PVR_VDM_CALLSTACK_MAX_DEPTH 1U |
| 61 |
|
| 62 |
#define ROGUE_PDS_TASK_PROGRAM_SIZE 256U |
| 63 |
|
| 64 |
static VkResult pvr_ctx_reset_cmd_init(struct pvr_device *device, |
| 65 |
struct pvr_reset_cmd *const reset_cmd) |
| 66 |
{ |
| 67 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 68 |
|
| 69 |
/* The reset framework depends on compute support in the hw. */ |
| 70 |
assert(PVR_HAS_FEATURE(dev_info, compute)); |
| 71 |
|
| 72 |
if (PVR_HAS_QUIRK(dev_info, 51764)) |
| 73 |
pvr_finishme("Missing reset support for brn51764"); |
| 74 |
|
| 75 |
if (PVR_HAS_QUIRK(dev_info, 58839)) |
| 76 |
pvr_finishme("Missing reset support for brn58839"); |
| 77 |
|
| 78 |
return VK_SUCCESS; |
| 79 |
} |
| 80 |
|
| 81 |
static void pvr_ctx_reset_cmd_fini(struct pvr_device *device, |
| 82 |
struct pvr_reset_cmd *reset_cmd) |
| 83 |
|
| 84 |
{ |
| 85 |
/* TODO: reset command cleanup. */ |
| 86 |
} |
| 87 |
|
| 88 |
static VkResult pvr_pds_pt_store_program_create_and_upload( |
| 89 |
struct pvr_device *device, |
| 90 |
struct pvr_bo *pt_bo, |
| 91 |
uint32_t pt_bo_size, |
| 92 |
struct pvr_pds_upload *const pds_upload_out) |
| 93 |
{ |
| 94 |
struct pvr_pds_stream_out_terminate_program program = { 0 }; |
| 95 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 96 |
const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info); |
| 97 |
size_t staging_buffer_size; |
| 98 |
uint32_t *staging_buffer; |
| 99 |
uint32_t *data_buffer; |
| 100 |
uint32_t *code_buffer; |
| 101 |
VkResult result; |
| 102 |
|
| 103 |
/* Check the bo size can be converted to dwords without any rounding. */ |
| 104 |
assert(pt_bo_size % 4 == 0); |
| 105 |
|
| 106 |
program.pds_persistent_temp_size_to_store = pt_bo_size / 4; |
| 107 |
program.dev_address_for_storing_persistent_temp = pt_bo->vma->dev_addr.addr; |
| 108 |
|
| 109 |
pvr_pds_generate_stream_out_terminate_program(&program, |
| 110 |
NULL, |
| 111 |
PDS_GENERATE_SIZES, |
| 112 |
dev_info); |
| 113 |
|
| 114 |
staging_buffer_size = (program.stream_out_terminate_pds_data_size + |
| 115 |
program.stream_out_terminate_pds_code_size) * |
| 116 |
sizeof(*staging_buffer); |
| 117 |
|
| 118 |
staging_buffer = vk_zalloc(&device->vk.alloc, |
| 119 |
staging_buffer_size, |
| 120 |
8, |
| 121 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 122 |
if (!staging_buffer) |
| 123 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 124 |
|
| 125 |
data_buffer = staging_buffer; |
| 126 |
code_buffer = |
| 127 |
pvr_pds_generate_stream_out_terminate_program(&program, |
| 128 |
data_buffer, |
| 129 |
PDS_GENERATE_DATA_SEGMENT, |
| 130 |
dev_info); |
| 131 |
pvr_pds_generate_stream_out_terminate_program(&program, |
| 132 |
code_buffer, |
| 133 |
PDS_GENERATE_CODE_SEGMENT, |
| 134 |
dev_info); |
| 135 |
|
| 136 |
/* This PDS program is passed to the HW via the PPP state words. These only |
| 137 |
* allow the data segment address to be specified and expect the code |
| 138 |
* segment to immediately follow. Assume the code alignment is the same as |
| 139 |
* the data. |
| 140 |
*/ |
| 141 |
result = |
| 142 |
pvr_gpu_upload_pds(device, |
| 143 |
data_buffer, |
| 144 |
program.stream_out_terminate_pds_data_size, |
| 145 |
ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE, |
| 146 |
code_buffer, |
| 147 |
program.stream_out_terminate_pds_code_size, |
| 148 |
ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE, |
| 149 |
cache_line_size, |
| 150 |
pds_upload_out); |
| 151 |
|
| 152 |
vk_free(&device->vk.alloc, staging_buffer); |
| 153 |
|
| 154 |
return result; |
| 155 |
} |
| 156 |
|
| 157 |
static VkResult pvr_pds_pt_resume_program_create_and_upload( |
| 158 |
struct pvr_device *device, |
| 159 |
struct pvr_bo *pt_bo, |
| 160 |
uint32_t pt_bo_size, |
| 161 |
struct pvr_pds_upload *const pds_upload_out) |
| 162 |
{ |
| 163 |
struct pvr_pds_stream_out_init_program program = { 0 }; |
| 164 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 165 |
const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info); |
| 166 |
size_t staging_buffer_size; |
| 167 |
uint32_t *staging_buffer; |
| 168 |
uint32_t *data_buffer; |
| 169 |
uint32_t *code_buffer; |
| 170 |
VkResult result; |
| 171 |
|
| 172 |
/* Check the bo size can be converted to dwords without any rounding. */ |
| 173 |
assert(pt_bo_size % 4 == 0); |
| 174 |
|
| 175 |
program.num_buffers = 1; |
| 176 |
program.pds_buffer_data_size[0] = pt_bo_size / 4; |
| 177 |
program.dev_address_for_buffer_data[0] = pt_bo->vma->dev_addr.addr; |
| 178 |
|
| 179 |
pvr_pds_generate_stream_out_init_program(&program, |
| 180 |
NULL, |
| 181 |
false, |
| 182 |
PDS_GENERATE_SIZES, |
| 183 |
dev_info); |
| 184 |
|
| 185 |
staging_buffer_size = (program.stream_out_init_pds_data_size + |
| 186 |
program.stream_out_init_pds_code_size) * |
| 187 |
sizeof(*staging_buffer); |
| 188 |
|
| 189 |
staging_buffer = vk_zalloc(&device->vk.alloc, |
| 190 |
staging_buffer_size, |
| 191 |
8, |
| 192 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 193 |
if (!staging_buffer) |
| 194 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 195 |
|
| 196 |
data_buffer = staging_buffer; |
| 197 |
code_buffer = |
| 198 |
pvr_pds_generate_stream_out_init_program(&program, |
| 199 |
data_buffer, |
| 200 |
false, |
| 201 |
PDS_GENERATE_DATA_SEGMENT, |
| 202 |
dev_info); |
| 203 |
pvr_pds_generate_stream_out_init_program(&program, |
| 204 |
code_buffer, |
| 205 |
false, |
| 206 |
PDS_GENERATE_CODE_SEGMENT, |
| 207 |
dev_info); |
| 208 |
|
| 209 |
/* This PDS program is passed to the HW via the PPP state words. These only |
| 210 |
* allow the data segment address to be specified and expect the code |
| 211 |
* segment to immediately follow. Assume the code alignment is the same as |
| 212 |
* the data. |
| 213 |
*/ |
| 214 |
result = |
| 215 |
pvr_gpu_upload_pds(device, |
| 216 |
data_buffer, |
| 217 |
program.stream_out_init_pds_data_size, |
| 218 |
ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE, |
| 219 |
code_buffer, |
| 220 |
program.stream_out_init_pds_code_size, |
| 221 |
ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE, |
| 222 |
cache_line_size, |
| 223 |
pds_upload_out); |
| 224 |
|
| 225 |
vk_free(&device->vk.alloc, staging_buffer); |
| 226 |
|
| 227 |
return result; |
| 228 |
} |
| 229 |
|
| 230 |
static VkResult |
| 231 |
pvr_render_job_pt_programs_setup(struct pvr_device *device, |
| 232 |
struct rogue_pt_programs *pt_programs) |
| 233 |
{ |
| 234 |
VkResult result; |
| 235 |
|
| 236 |
result = pvr_bo_alloc(device, |
| 237 |
device->heaps.pds_heap, |
| 238 |
ROGUE_LLS_PDS_PERSISTENT_TEMPS_BUFFER_SIZE, |
| 239 |
ROGUE_LLS_PDS_PERSISTENT_TEMPS_BUFFER_ALIGNMENT, |
| 240 |
PVR_BO_ALLOC_FLAG_CPU_ACCESS, |
| 241 |
&pt_programs->store_resume_state_bo); |
| 242 |
if (result != VK_SUCCESS) |
| 243 |
return result; |
| 244 |
|
| 245 |
result = pvr_pds_pt_store_program_create_and_upload( |
| 246 |
device, |
| 247 |
pt_programs->store_resume_state_bo, |
| 248 |
ROGUE_LLS_PDS_PERSISTENT_TEMPS_BUFFER_SIZE, |
| 249 |
&pt_programs->pds_store_program); |
| 250 |
if (result != VK_SUCCESS) |
| 251 |
goto err_free_store_resume_state_bo; |
| 252 |
|
| 253 |
result = pvr_pds_pt_resume_program_create_and_upload( |
| 254 |
device, |
| 255 |
pt_programs->store_resume_state_bo, |
| 256 |
ROGUE_LLS_PDS_PERSISTENT_TEMPS_BUFFER_SIZE, |
| 257 |
&pt_programs->pds_resume_program); |
| 258 |
if (result != VK_SUCCESS) |
| 259 |
goto err_free_pds_store_program; |
| 260 |
|
| 261 |
return VK_SUCCESS; |
| 262 |
|
| 263 |
err_free_pds_store_program: |
| 264 |
pvr_bo_suballoc_free(pt_programs->pds_store_program.pvr_bo); |
| 265 |
|
| 266 |
err_free_store_resume_state_bo: |
| 267 |
pvr_bo_free(device, pt_programs->store_resume_state_bo); |
| 268 |
|
| 269 |
return result; |
| 270 |
} |
| 271 |
|
| 272 |
static void |
| 273 |
pvr_render_job_pt_programs_cleanup(struct pvr_device *device, |
| 274 |
struct rogue_pt_programs *pt_programs) |
| 275 |
{ |
| 276 |
pvr_bo_suballoc_free(pt_programs->pds_resume_program.pvr_bo); |
| 277 |
pvr_bo_suballoc_free(pt_programs->pds_store_program.pvr_bo); |
| 278 |
pvr_bo_free(device, pt_programs->store_resume_state_bo); |
| 279 |
} |
| 280 |
|
| 281 |
static void pvr_pds_ctx_sr_program_setup( |
| 282 |
uint32_t core_count, |
| 283 |
bool cc_enable, |
| 284 |
uint64_t usc_program_upload_offset, |
| 285 |
uint8_t usc_temps, |
| 286 |
pvr_dev_addr_t sr_addr, |
| 287 |
struct pvr_pds_shared_storing_program *const program_out) |
| 288 |
{ |
| 289 |
/* The PDS task is the same for stores and loads. */ |
| 290 |
*program_out = (struct pvr_pds_shared_storing_program){ |
| 291 |
.cc_enable = cc_enable, |
| 292 |
.doutw_control = { |
| 293 |
.dest_store = PDS_UNIFIED_STORE, |
| 294 |
.num_const64 = 2, |
| 295 |
.doutw_data = { |
| 296 |
[0] = sr_addr.addr, |
| 297 |
[1] = sr_addr.addr + ROGUE_LLS_SHARED_REGS_RESERVE_SIZE, |
| 298 |
}, |
| 299 |
.last_instruction = false, |
| 300 |
}, |
| 301 |
}; |
| 302 |
|
| 303 |
if (core_count > 1) { |
| 304 |
pvr_finishme( |
| 305 |
"Handle LLS_USC_SHARED_REGS_BUFFER_SIZE in DOUTW data_control"); |
| 306 |
} |
| 307 |
|
| 308 |
pvr_pds_setup_doutu(&program_out->usc_task.usc_task_control, |
| 309 |
usc_program_upload_offset, |
| 310 |
usc_temps, |
| 311 |
ROGUE_PDSINST_DOUTU_SAMPLE_RATE_INSTANCE, |
| 312 |
false); |
| 313 |
} |
| 314 |
|
| 315 |
/* Note: pvr_pds_compute_ctx_sr_program_create_and_upload() is very similar to |
| 316 |
* this. If there is a problem here it's likely that the same problem exists |
| 317 |
* there so don't forget to update the compute function. |
| 318 |
*/ |
| 319 |
static VkResult pvr_pds_render_ctx_sr_program_create_and_upload( |
| 320 |
struct pvr_device *device, |
| 321 |
uint64_t usc_program_upload_offset, |
| 322 |
uint8_t usc_temps, |
| 323 |
pvr_dev_addr_t sr_addr, |
| 324 |
struct pvr_pds_upload *const pds_upload_out) |
| 325 |
{ |
| 326 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 327 |
const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info); |
| 328 |
const uint32_t pds_data_alignment = |
| 329 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE / 4U; |
| 330 |
|
| 331 |
/* FIXME: pvr_pds_generate_shared_storing_program() doesn't return the data |
| 332 |
* and code size when using the PDS_GENERATE_SIZES mode. |
| 333 |
*/ |
| 334 |
STATIC_ASSERT(ROGUE_PDS_TASK_PROGRAM_SIZE % 4 == 0); |
| 335 |
uint32_t staging_buffer[ROGUE_PDS_TASK_PROGRAM_SIZE / 4U] = { 0 }; |
| 336 |
struct pvr_pds_shared_storing_program program; |
| 337 |
ASSERTED uint32_t *buffer_end; |
| 338 |
uint32_t code_offset; |
| 339 |
|
| 340 |
pvr_pds_ctx_sr_program_setup(device->pdevice->dev_runtime_info.core_count, |
| 341 |
false, |
| 342 |
usc_program_upload_offset, |
| 343 |
usc_temps, |
| 344 |
sr_addr, |
| 345 |
&program); |
| 346 |
|
| 347 |
pvr_pds_generate_shared_storing_program(&program, |
| 348 |
&staging_buffer[0], |
| 349 |
PDS_GENERATE_DATA_SEGMENT, |
| 350 |
dev_info); |
| 351 |
|
| 352 |
code_offset = ALIGN_POT(program.data_size, pds_data_alignment); |
| 353 |
|
| 354 |
buffer_end = |
| 355 |
pvr_pds_generate_shared_storing_program(&program, |
| 356 |
&staging_buffer[code_offset], |
| 357 |
PDS_GENERATE_CODE_SEGMENT, |
| 358 |
dev_info); |
| 359 |
|
| 360 |
assert((uint32_t)(buffer_end - staging_buffer) * sizeof(staging_buffer[0]) < |
| 361 |
ROGUE_PDS_TASK_PROGRAM_SIZE); |
| 362 |
|
| 363 |
return pvr_gpu_upload_pds(device, |
| 364 |
&staging_buffer[0], |
| 365 |
program.data_size, |
| 366 |
ROGUE_VDMCTRL_PDS_STATE1_PDS_DATA_ADDR_ALIGNMENT, |
| 367 |
&staging_buffer[code_offset], |
| 368 |
program.code_size, |
| 369 |
ROGUE_VDMCTRL_PDS_STATE2_PDS_CODE_ADDR_ALIGNMENT, |
| 370 |
cache_line_size, |
| 371 |
pds_upload_out); |
| 372 |
} |
| 373 |
|
| 374 |
/* Note: pvr_pds_render_ctx_sr_program_create_and_upload() is very similar to |
| 375 |
* this. If there is a problem here it's likely that the same problem exists |
| 376 |
* there so don't forget to update the render_ctx function. |
| 377 |
*/ |
| 378 |
static VkResult pvr_pds_compute_ctx_sr_program_create_and_upload( |
| 379 |
struct pvr_device *device, |
| 380 |
bool is_loading_program, |
| 381 |
uint64_t usc_program_upload_offset, |
| 382 |
uint8_t usc_temps, |
| 383 |
pvr_dev_addr_t sr_addr, |
| 384 |
struct pvr_pds_upload *const pds_upload_out) |
| 385 |
{ |
| 386 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 387 |
const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info); |
| 388 |
const uint32_t pds_data_alignment = |
| 389 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE / 4U; |
| 390 |
|
| 391 |
/* FIXME: pvr_pds_generate_shared_storing_program() doesn't return the data |
| 392 |
* and code size when using the PDS_GENERATE_SIZES mode. |
| 393 |
*/ |
| 394 |
STATIC_ASSERT(ROGUE_PDS_TASK_PROGRAM_SIZE % 4 == 0); |
| 395 |
uint32_t staging_buffer[ROGUE_PDS_TASK_PROGRAM_SIZE / 4U] = { 0 }; |
| 396 |
struct pvr_pds_shared_storing_program program; |
| 397 |
uint32_t *buffer_ptr; |
| 398 |
uint32_t code_offset; |
| 399 |
|
| 400 |
pvr_pds_ctx_sr_program_setup(device->pdevice->dev_runtime_info.core_count, |
| 401 |
PVR_HAS_ENHANCEMENT(dev_info, 35421), |
| 402 |
usc_program_upload_offset, |
| 403 |
usc_temps, |
| 404 |
sr_addr, |
| 405 |
&program); |
| 406 |
|
| 407 |
if (is_loading_program && PVR_NEED_SW_COMPUTE_PDS_BARRIER(dev_info)) { |
| 408 |
pvr_pds_generate_compute_shared_loading_program(&program, |
| 409 |
&staging_buffer[0], |
| 410 |
PDS_GENERATE_DATA_SEGMENT, |
| 411 |
dev_info); |
| 412 |
} else { |
| 413 |
pvr_pds_generate_shared_storing_program(&program, |
| 414 |
&staging_buffer[0], |
| 415 |
PDS_GENERATE_DATA_SEGMENT, |
| 416 |
dev_info); |
| 417 |
} |
| 418 |
|
| 419 |
code_offset = ALIGN_POT(program.data_size, pds_data_alignment); |
| 420 |
|
| 421 |
buffer_ptr = |
| 422 |
pvr_pds_generate_compute_barrier_conditional(&staging_buffer[code_offset], |
| 423 |
PDS_GENERATE_CODE_SEGMENT); |
| 424 |
|
| 425 |
if (is_loading_program && PVR_NEED_SW_COMPUTE_PDS_BARRIER(dev_info)) { |
| 426 |
buffer_ptr = pvr_pds_generate_compute_shared_loading_program( |
| 427 |
&program, |
| 428 |
buffer_ptr, |
| 429 |
PDS_GENERATE_CODE_SEGMENT, |
| 430 |
dev_info); |
| 431 |
} else { |
| 432 |
buffer_ptr = |
| 433 |
pvr_pds_generate_shared_storing_program(&program, |
| 434 |
buffer_ptr, |
| 435 |
PDS_GENERATE_CODE_SEGMENT, |
| 436 |
dev_info); |
| 437 |
} |
| 438 |
|
| 439 |
assert((uint32_t)(buffer_ptr - staging_buffer) * sizeof(staging_buffer[0]) < |
| 440 |
ROGUE_PDS_TASK_PROGRAM_SIZE); |
| 441 |
|
| 442 |
STATIC_ASSERT(ROGUE_CR_CDM_CONTEXT_PDS0_DATA_ADDR_ALIGNMENT == |
| 443 |
ROGUE_CR_CDM_CONTEXT_LOAD_PDS0_DATA_ADDR_ALIGNMENT); |
| 444 |
|
| 445 |
STATIC_ASSERT(ROGUE_CR_CDM_CONTEXT_PDS0_CODE_ADDR_ALIGNMENT == |
| 446 |
ROGUE_CR_CDM_CONTEXT_LOAD_PDS0_CODE_ADDR_ALIGNMENT); |
| 447 |
|
| 448 |
return pvr_gpu_upload_pds( |
| 449 |
device, |
| 450 |
&staging_buffer[0], |
| 451 |
program.data_size, |
| 452 |
ROGUE_CR_CDM_CONTEXT_PDS0_DATA_ADDR_ALIGNMENT, |
| 453 |
&staging_buffer[code_offset], |
| 454 |
(uint32_t)(buffer_ptr - &staging_buffer[code_offset]), |
| 455 |
ROGUE_CR_CDM_CONTEXT_PDS0_CODE_ADDR_ALIGNMENT, |
| 456 |
cache_line_size, |
| 457 |
pds_upload_out); |
| 458 |
} |
| 459 |
|
| 460 |
enum pvr_ctx_sr_program_target { |
| 461 |
PVR_CTX_SR_RENDER_TARGET, |
| 462 |
PVR_CTX_SR_COMPUTE_TARGET, |
| 463 |
}; |
| 464 |
|
| 465 |
static VkResult pvr_ctx_sr_programs_setup(struct pvr_device *device, |
| 466 |
enum pvr_ctx_sr_program_target target, |
| 467 |
struct rogue_sr_programs *sr_programs) |
| 468 |
{ |
| 469 |
const uint64_t store_load_state_bo_size = |
| 470 |
ROGUE_LLS_USC_SHARED_REGS_BUFFER_SIZE + |
| 471 |
ROGUE_LLS_SHARED_REGS_RESERVE_SIZE; |
| 472 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 473 |
const uint32_t cache_line_size = pvr_get_slc_cache_line_size(dev_info); |
| 474 |
uint64_t usc_store_program_upload_offset; |
| 475 |
uint64_t usc_load_program_upload_offset; |
| 476 |
const pco_precomp_data *precomp_data; |
| 477 |
unsigned store_temps; |
| 478 |
unsigned load_temps; |
| 479 |
VkResult result; |
| 480 |
|
| 481 |
/* Note that this is being used for both compute and render ctx. There is no |
| 482 |
* compute equivalent define for the VDMCTRL unit size. |
| 483 |
*/ |
| 484 |
/* 4 blocks (16 dwords / 64 bytes) in USC to prevent fragmentation. */ |
| 485 |
sr_programs->usc.unified_size = |
| 486 |
DIV_ROUND_UP(64, ROGUE_VDMCTRL_PDS_STATE0_USC_UNIFIED_SIZE_UNIT_SIZE); |
| 487 |
|
| 488 |
result = pvr_bo_alloc(device, |
| 489 |
device->heaps.pds_heap, |
| 490 |
store_load_state_bo_size, |
| 491 |
cache_line_size, |
| 492 |
PVR_WINSYS_BO_FLAG_CPU_ACCESS, |
| 493 |
&sr_programs->store_load_state_bo); |
| 494 |
if (result != VK_SUCCESS) |
| 495 |
return result; |
| 496 |
|
| 497 |
/* We shouldn't need to limit the size of these programs any more, but if |
| 498 |
* we end up having to, this would be the place to check. |
| 499 |
*/ |
| 500 |
|
| 501 |
/* USC state update: SR state store. */ |
| 502 |
precomp_data = |
| 503 |
(pco_precomp_data *)pco_usclib_common[CS_STORE_SR_1024_COMMON]; |
| 504 |
|
| 505 |
result = pvr_gpu_upload_usc(device, |
| 506 |
precomp_data->binary, |
| 507 |
precomp_data->size_dwords * sizeof(uint32_t), |
| 508 |
cache_line_size, |
| 509 |
&sr_programs->usc.store_program_bo); |
| 510 |
if (result != VK_SUCCESS) |
| 511 |
goto err_free_store_load_state_bo; |
| 512 |
|
| 513 |
store_temps = precomp_data->temps; |
| 514 |
|
| 515 |
usc_store_program_upload_offset = |
| 516 |
sr_programs->usc.store_program_bo->dev_addr.addr - |
| 517 |
device->heaps.usc_heap->base_addr.addr; |
| 518 |
|
| 519 |
/* USC state update: SR state load. */ |
| 520 |
precomp_data = (pco_precomp_data *)pco_usclib_common[CS_LOAD_SR_256_COMMON]; |
| 521 |
|
| 522 |
if (target == PVR_CTX_SR_COMPUTE_TARGET && PVR_HAS_QUIRK(dev_info, 62269)) |
| 523 |
pvr_finishme("Missing support for brn62269"); |
| 524 |
|
| 525 |
result = pvr_gpu_upload_usc(device, |
| 526 |
precomp_data->binary, |
| 527 |
precomp_data->size_dwords * sizeof(uint32_t), |
| 528 |
cache_line_size, |
| 529 |
&sr_programs->usc.load_program_bo); |
| 530 |
if (result != VK_SUCCESS) |
| 531 |
goto err_free_usc_store_program_bo; |
| 532 |
|
| 533 |
load_temps = precomp_data->temps; |
| 534 |
|
| 535 |
usc_load_program_upload_offset = |
| 536 |
sr_programs->usc.load_program_bo->dev_addr.addr - |
| 537 |
device->heaps.usc_heap->base_addr.addr; |
| 538 |
|
| 539 |
/* Create and upload the PDS load and store programs. Point them to the |
| 540 |
* appropriate USC load and store programs. |
| 541 |
*/ |
| 542 |
switch (target) { |
| 543 |
case PVR_CTX_SR_RENDER_TARGET: |
| 544 |
/* PDS state update: SR state store. */ |
| 545 |
result = pvr_pds_render_ctx_sr_program_create_and_upload( |
| 546 |
device, |
| 547 |
usc_store_program_upload_offset, |
| 548 |
store_temps, |
| 549 |
sr_programs->store_load_state_bo->vma->dev_addr, |
| 550 |
&sr_programs->pds.store_program); |
| 551 |
if (result != VK_SUCCESS) |
| 552 |
goto err_free_usc_load_program_bo; |
| 553 |
|
| 554 |
/* PDS state update: SR state load. */ |
| 555 |
result = pvr_pds_render_ctx_sr_program_create_and_upload( |
| 556 |
device, |
| 557 |
usc_load_program_upload_offset, |
| 558 |
load_temps, |
| 559 |
sr_programs->store_load_state_bo->vma->dev_addr, |
| 560 |
&sr_programs->pds.load_program); |
| 561 |
if (result != VK_SUCCESS) |
| 562 |
goto err_free_pds_store_program_bo; |
| 563 |
|
| 564 |
break; |
| 565 |
|
| 566 |
case PVR_CTX_SR_COMPUTE_TARGET: |
| 567 |
/* PDS state update: SR state store. */ |
| 568 |
result = pvr_pds_compute_ctx_sr_program_create_and_upload( |
| 569 |
device, |
| 570 |
false, |
| 571 |
usc_store_program_upload_offset, |
| 572 |
store_temps, |
| 573 |
sr_programs->store_load_state_bo->vma->dev_addr, |
| 574 |
&sr_programs->pds.store_program); |
| 575 |
if (result != VK_SUCCESS) |
| 576 |
goto err_free_usc_load_program_bo; |
| 577 |
|
| 578 |
/* PDS state update: SR state load. */ |
| 579 |
result = pvr_pds_compute_ctx_sr_program_create_and_upload( |
| 580 |
device, |
| 581 |
true, |
| 582 |
usc_load_program_upload_offset, |
| 583 |
load_temps, |
| 584 |
sr_programs->store_load_state_bo->vma->dev_addr, |
| 585 |
&sr_programs->pds.load_program); |
| 586 |
if (result != VK_SUCCESS) |
| 587 |
goto err_free_pds_store_program_bo; |
| 588 |
|
| 589 |
break; |
| 590 |
|
| 591 |
default: |
| 592 |
UNREACHABLE("Invalid target."); |
| 593 |
break; |
| 594 |
} |
| 595 |
|
| 596 |
return VK_SUCCESS; |
| 597 |
|
| 598 |
err_free_pds_store_program_bo: |
| 599 |
pvr_bo_suballoc_free(sr_programs->pds.store_program.pvr_bo); |
| 600 |
|
| 601 |
err_free_usc_load_program_bo: |
| 602 |
pvr_bo_suballoc_free(sr_programs->usc.load_program_bo); |
| 603 |
|
| 604 |
err_free_usc_store_program_bo: |
| 605 |
pvr_bo_suballoc_free(sr_programs->usc.store_program_bo); |
| 606 |
|
| 607 |
err_free_store_load_state_bo: |
| 608 |
pvr_bo_free(device, sr_programs->store_load_state_bo); |
| 609 |
|
| 610 |
return result; |
| 611 |
} |
| 612 |
|
| 613 |
static void pvr_ctx_sr_programs_cleanup(struct pvr_device *device, |
| 614 |
struct rogue_sr_programs *sr_programs) |
| 615 |
{ |
| 616 |
pvr_bo_suballoc_free(sr_programs->pds.load_program.pvr_bo); |
| 617 |
pvr_bo_suballoc_free(sr_programs->pds.store_program.pvr_bo); |
| 618 |
pvr_bo_suballoc_free(sr_programs->usc.load_program_bo); |
| 619 |
pvr_bo_suballoc_free(sr_programs->usc.store_program_bo); |
| 620 |
pvr_bo_free(device, sr_programs->store_load_state_bo); |
| 621 |
} |
| 622 |
|
| 623 |
static VkResult |
| 624 |
pvr_render_ctx_switch_programs_setup(struct pvr_device *device, |
| 625 |
struct pvr_render_ctx_programs *programs) |
| 626 |
{ |
| 627 |
VkResult result; |
| 628 |
|
| 629 |
result = pvr_render_job_pt_programs_setup(device, &programs->pt); |
| 630 |
if (result != VK_SUCCESS) |
| 631 |
return result; |
| 632 |
|
| 633 |
result = pvr_ctx_sr_programs_setup(device, |
| 634 |
PVR_CTX_SR_RENDER_TARGET, |
| 635 |
&programs->sr); |
| 636 |
if (result != VK_SUCCESS) |
| 637 |
goto err_pt_programs_cleanup; |
| 638 |
|
| 639 |
return VK_SUCCESS; |
| 640 |
|
| 641 |
err_pt_programs_cleanup: |
| 642 |
pvr_render_job_pt_programs_cleanup(device, &programs->pt); |
| 643 |
|
| 644 |
return result; |
| 645 |
} |
| 646 |
|
| 647 |
static void |
| 648 |
pvr_render_ctx_switch_programs_cleanup(struct pvr_device *device, |
| 649 |
struct pvr_render_ctx_programs *programs) |
| 650 |
{ |
| 651 |
pvr_ctx_sr_programs_cleanup(device, &programs->sr); |
| 652 |
pvr_render_job_pt_programs_cleanup(device, &programs->pt); |
| 653 |
} |
| 654 |
|
| 655 |
static VkResult pvr_render_ctx_switch_init(struct pvr_device *device, |
| 656 |
struct pvr_render_ctx *ctx) |
| 657 |
{ |
| 658 |
struct pvr_render_ctx_switch *ctx_switch = &ctx->ctx_switch; |
| 659 |
const uint64_t vdm_state_bo_flags = PVR_BO_ALLOC_FLAG_GPU_UNCACHED | |
| 660 |
PVR_BO_ALLOC_FLAG_CPU_ACCESS; |
| 661 |
const uint64_t geom_state_bo_flags = PVR_BO_ALLOC_FLAG_GPU_UNCACHED | |
| 662 |
PVR_BO_ALLOC_FLAG_CPU_ACCESS; |
| 663 |
VkResult result; |
| 664 |
uint32_t i; |
| 665 |
|
| 666 |
result = pvr_bo_alloc(device, |
| 667 |
device->heaps.general_heap, |
| 668 |
ROGUE_LLS_VDM_CONTEXT_RESUME_BUFFER_SIZE, |
| 669 |
ROGUE_LLS_VDM_CONTEXT_RESUME_BUFFER_ALIGNMENT, |
| 670 |
vdm_state_bo_flags, |
| 671 |
&ctx_switch->vdm_state_bo); |
| 672 |
if (result != VK_SUCCESS) |
| 673 |
return result; |
| 674 |
|
| 675 |
result = pvr_bo_alloc(device, |
| 676 |
device->heaps.general_heap, |
| 677 |
ROGUE_LLS_TA_STATE_BUFFER_SIZE, |
| 678 |
ROGUE_LLS_TA_STATE_BUFFER_ALIGNMENT, |
| 679 |
geom_state_bo_flags, |
| 680 |
&ctx_switch->geom_state_bo); |
| 681 |
if (result != VK_SUCCESS) |
| 682 |
goto err_pvr_bo_free_vdm_state_bo; |
| 683 |
|
| 684 |
for (i = 0; i < ARRAY_SIZE(ctx_switch->programs); i++) { |
| 685 |
result = |
| 686 |
pvr_render_ctx_switch_programs_setup(device, &ctx_switch->programs[i]); |
| 687 |
if (result != VK_SUCCESS) |
| 688 |
goto err_programs_cleanup; |
| 689 |
} |
| 690 |
|
| 691 |
return VK_SUCCESS; |
| 692 |
|
| 693 |
err_programs_cleanup: |
| 694 |
for (uint32_t j = 0; j < i; j++) |
| 695 |
pvr_render_ctx_switch_programs_cleanup(device, &ctx_switch->programs[j]); |
| 696 |
|
| 697 |
pvr_bo_free(device, ctx_switch->geom_state_bo); |
| 698 |
|
| 699 |
err_pvr_bo_free_vdm_state_bo: |
| 700 |
pvr_bo_free(device, ctx_switch->vdm_state_bo); |
| 701 |
|
| 702 |
return result; |
| 703 |
} |
| 704 |
|
| 705 |
static void pvr_render_ctx_switch_fini(struct pvr_device *device, |
| 706 |
struct pvr_render_ctx *ctx) |
| 707 |
{ |
| 708 |
struct pvr_render_ctx_switch *ctx_switch = &ctx->ctx_switch; |
| 709 |
|
| 710 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx_switch->programs); i++) |
| 711 |
pvr_render_ctx_switch_programs_cleanup(device, &ctx_switch->programs[i]); |
| 712 |
|
| 713 |
pvr_bo_free(device, ctx_switch->geom_state_bo); |
| 714 |
pvr_bo_free(device, ctx_switch->vdm_state_bo); |
| 715 |
} |
| 716 |
|
| 717 |
static void |
| 718 |
pvr_rogue_get_vdmctrl_pds_state_words(struct pvr_pds_upload *pds_program, |
| 719 |
enum ROGUE_VDMCTRL_USC_TARGET usc_target, |
| 720 |
uint8_t usc_unified_size, |
| 721 |
uint32_t *const state0_out, |
| 722 |
uint32_t *const state1_out) |
| 723 |
{ |
| 724 |
pvr_csb_pack (state0_out, VDMCTRL_PDS_STATE0, state) { |
| 725 |
/* Convert the data size from dwords to bytes. */ |
| 726 |
const uint32_t pds_data_size = PVR_DW_TO_BYTES(pds_program->data_size); |
| 727 |
|
| 728 |
state.dm_target = ROGUE_VDMCTRL_DM_TARGET_VDM; |
| 729 |
state.usc_target = usc_target; |
| 730 |
state.usc_common_size = 0; |
| 731 |
state.usc_unified_size = usc_unified_size; |
| 732 |
state.pds_temp_size = 0; |
| 733 |
|
| 734 |
assert(pds_data_size % ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE == |
| 735 |
0); |
| 736 |
state.pds_data_size = |
| 737 |
pds_data_size / ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE; |
| 738 |
}; |
| 739 |
|
| 740 |
pvr_csb_pack (state1_out, VDMCTRL_PDS_STATE1, state) { |
| 741 |
state.pds_data_addr = PVR_DEV_ADDR(pds_program->data_offset); |
| 742 |
state.sd_type = ROGUE_VDMCTRL_SD_TYPE_PDS; |
| 743 |
state.sd_next_type = ROGUE_VDMCTRL_SD_TYPE_PDS; |
| 744 |
} |
| 745 |
} |
| 746 |
|
| 747 |
static void |
| 748 |
pvr_rogue_get_geom_state_stream_out_words(struct pvr_pds_upload *pds_program, |
| 749 |
uint32_t *const stream_out1_out, |
| 750 |
uint32_t *const stream_out2_out) |
| 751 |
{ |
| 752 |
pvr_csb_pack (stream_out1_out, TA_STATE_STREAM_OUT1, state) { |
| 753 |
/* Convert the data size from dwords to bytes. */ |
| 754 |
const uint32_t pds_data_size = PVR_DW_TO_BYTES(pds_program->data_size); |
| 755 |
|
| 756 |
state.sync = true; |
| 757 |
|
| 758 |
assert(pds_data_size % |
| 759 |
ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE == |
| 760 |
0); |
| 761 |
state.pds_data_size = |
| 762 |
pds_data_size / ROGUE_TA_STATE_STREAM_OUT1_PDS_DATA_SIZE_UNIT_SIZE; |
| 763 |
|
| 764 |
state.pds_temp_size = 0; |
| 765 |
} |
| 766 |
|
| 767 |
pvr_csb_pack (stream_out2_out, TA_STATE_STREAM_OUT2, state) { |
| 768 |
state.pds_data_addr = PVR_DEV_ADDR(pds_program->data_offset); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
static void pvr_render_ctx_ws_static_state_init( |
| 773 |
struct pvr_render_ctx *ctx, |
| 774 |
struct PVR_PER_ARCH(winsys_render_ctx_static_state) * static_state) |
| 775 |
{ |
| 776 |
uint64_t *q_dst; |
| 777 |
uint32_t *d_dst; |
| 778 |
|
| 779 |
q_dst = &static_state->vdm_ctx_state_base_addr; |
| 780 |
pvr_csb_pack (q_dst, CR_VDM_CONTEXT_STATE_BASE, base) { |
| 781 |
base.addr = ctx->ctx_switch.vdm_state_bo->vma->dev_addr; |
| 782 |
} |
| 783 |
|
| 784 |
q_dst = &static_state->geom_ctx_state_base_addr; |
| 785 |
pvr_csb_pack (q_dst, CR_TA_CONTEXT_STATE_BASE, base) { |
| 786 |
base.addr = ctx->ctx_switch.geom_state_bo->vma->dev_addr; |
| 787 |
} |
| 788 |
|
| 789 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->ctx_switch.programs); i++) { |
| 790 |
struct rogue_pt_programs *pt_prog = &ctx->ctx_switch.programs[i].pt; |
| 791 |
struct rogue_sr_programs *sr_prog = &ctx->ctx_switch.programs[i].sr; |
| 792 |
|
| 793 |
/* Context store state. */ |
| 794 |
q_dst = &static_state->geom_state[i].vdm_ctx_store_task0; |
| 795 |
pvr_csb_pack (q_dst, CR_VDM_CONTEXT_STORE_TASK0, task0) { |
| 796 |
pvr_rogue_get_vdmctrl_pds_state_words(&sr_prog->pds.store_program, |
| 797 |
ROGUE_VDMCTRL_USC_TARGET_ANY, |
| 798 |
sr_prog->usc.unified_size, |
| 799 |
&task0.pds_state0, |
| 800 |
&task0.pds_state1); |
| 801 |
} |
| 802 |
|
| 803 |
d_dst = &static_state->geom_state[i].vdm_ctx_store_task1; |
| 804 |
pvr_csb_pack (d_dst, CR_VDM_CONTEXT_STORE_TASK1, task1) { |
| 805 |
pvr_csb_pack (&task1.pds_state2, VDMCTRL_PDS_STATE2, state) { |
| 806 |
state.pds_code_addr = |
| 807 |
PVR_DEV_ADDR(sr_prog->pds.store_program.code_offset); |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
q_dst = &static_state->geom_state[i].vdm_ctx_store_task2; |
| 812 |
pvr_csb_pack (q_dst, CR_VDM_CONTEXT_STORE_TASK2, task2) { |
| 813 |
pvr_rogue_get_geom_state_stream_out_words(&pt_prog->pds_store_program, |
| 814 |
&task2.stream_out1, |
| 815 |
&task2.stream_out2); |
| 816 |
} |
| 817 |
|
| 818 |
/* Context resume state. */ |
| 819 |
q_dst = &static_state->geom_state[i].vdm_ctx_resume_task0; |
| 820 |
pvr_csb_pack (q_dst, CR_VDM_CONTEXT_RESUME_TASK0, task0) { |
| 821 |
pvr_rogue_get_vdmctrl_pds_state_words(&sr_prog->pds.load_program, |
| 822 |
ROGUE_VDMCTRL_USC_TARGET_ALL, |
| 823 |
sr_prog->usc.unified_size, |
| 824 |
&task0.pds_state0, |
| 825 |
&task0.pds_state1); |
| 826 |
} |
| 827 |
|
| 828 |
d_dst = &static_state->geom_state[i].vdm_ctx_resume_task1; |
| 829 |
pvr_csb_pack (d_dst, CR_VDM_CONTEXT_RESUME_TASK1, task1) { |
| 830 |
pvr_csb_pack (&task1.pds_state2, VDMCTRL_PDS_STATE2, state) { |
| 831 |
state.pds_code_addr = |
| 832 |
PVR_DEV_ADDR(sr_prog->pds.load_program.code_offset); |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
q_dst = &static_state->geom_state[i].vdm_ctx_resume_task2; |
| 837 |
pvr_csb_pack (q_dst, CR_VDM_CONTEXT_RESUME_TASK2, task2) { |
| 838 |
pvr_rogue_get_geom_state_stream_out_words(&pt_prog->pds_resume_program, |
| 839 |
&task2.stream_out1, |
| 840 |
&task2.stream_out2); |
| 841 |
} |
| 842 |
} |
| 843 |
} |
| 844 |
|
| 845 |
static void pvr_render_ctx_ws_create_info_init( |
| 846 |
struct pvr_render_ctx *ctx, |
| 847 |
enum pvr_winsys_ctx_priority priority, |
| 848 |
struct pvr_winsys_render_ctx_create_info *create_info) |
| 849 |
{ |
| 850 |
create_info->priority = priority; |
| 851 |
create_info->vdm_callstack_addr = ctx->vdm_callstack_bo->vma->dev_addr; |
| 852 |
|
| 853 |
#if defined(PVR_BUILD_ARCH_ROGUE) |
| 854 |
pvr_render_ctx_ws_static_state_init(ctx, &create_info->static_state.rogue); |
| 855 |
#else |
| 856 |
# error "Missing arch" |
| 857 |
#endif |
| 858 |
} |
| 859 |
|
| 860 |
VkResult pvr_arch_render_ctx_create(struct pvr_device *device, |
| 861 |
enum pvr_winsys_ctx_priority priority, |
| 862 |
struct pvr_render_ctx **const ctx_out) |
| 863 |
{ |
| 864 |
const uint64_t vdm_callstack_size = |
| 865 |
sizeof(uint64_t) * PVR_VDM_CALLSTACK_MAX_DEPTH; |
| 866 |
struct pvr_winsys_render_ctx_create_info create_info; |
| 867 |
struct pvr_render_ctx *ctx; |
| 868 |
VkResult result; |
| 869 |
|
| 870 |
ctx = vk_alloc(&device->vk.alloc, |
| 871 |
sizeof(*ctx), |
| 872 |
8, |
| 873 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 874 |
if (!ctx) |
| 875 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 876 |
|
| 877 |
ctx->device = device; |
| 878 |
|
| 879 |
result = pvr_bo_alloc(device, |
| 880 |
device->heaps.general_heap, |
| 881 |
vdm_callstack_size, |
| 882 |
ROGUE_CR_VDM_CALL_STACK_POINTER_ADDR_ALIGNMENT, |
| 883 |
0, |
| 884 |
&ctx->vdm_callstack_bo); |
| 885 |
if (result != VK_SUCCESS) |
| 886 |
goto err_vk_free_ctx; |
| 887 |
|
| 888 |
result = pvr_render_ctx_switch_init(device, ctx); |
| 889 |
if (result != VK_SUCCESS) |
| 890 |
goto err_free_vdm_callstack_bo; |
| 891 |
|
| 892 |
result = pvr_ctx_reset_cmd_init(device, &ctx->reset_cmd); |
| 893 |
if (result != VK_SUCCESS) |
| 894 |
goto err_render_ctx_switch_fini; |
| 895 |
|
| 896 |
/* ctx must be fully initialized by this point since |
| 897 |
* pvr_render_ctx_ws_create_info_init() depends on this. |
| 898 |
*/ |
| 899 |
pvr_render_ctx_ws_create_info_init(ctx, priority, &create_info); |
| 900 |
|
| 901 |
result = device->ws->ops->render_ctx_create(device->ws, |
| 902 |
&create_info, |
| 903 |
&device->pdevice->dev_info, |
| 904 |
&ctx->ws_ctx); |
| 905 |
if (result != VK_SUCCESS) |
| 906 |
goto err_render_ctx_reset_cmd_fini; |
| 907 |
|
| 908 |
*ctx_out = ctx; |
| 909 |
|
| 910 |
return VK_SUCCESS; |
| 911 |
|
| 912 |
err_render_ctx_reset_cmd_fini: |
| 913 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 914 |
|
| 915 |
err_render_ctx_switch_fini: |
| 916 |
pvr_render_ctx_switch_fini(device, ctx); |
| 917 |
|
| 918 |
err_free_vdm_callstack_bo: |
| 919 |
pvr_bo_free(device, ctx->vdm_callstack_bo); |
| 920 |
|
| 921 |
err_vk_free_ctx: |
| 922 |
vk_free(&device->vk.alloc, ctx); |
| 923 |
|
| 924 |
return result; |
| 925 |
} |
| 926 |
|
| 927 |
void pvr_arch_render_ctx_destroy(struct pvr_render_ctx *ctx) |
| 928 |
{ |
| 929 |
struct pvr_device *device = ctx->device; |
| 930 |
|
| 931 |
device->ws->ops->render_ctx_destroy(ctx->ws_ctx); |
| 932 |
|
| 933 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 934 |
pvr_render_ctx_switch_fini(device, ctx); |
| 935 |
pvr_bo_free(device, ctx->vdm_callstack_bo); |
| 936 |
vk_free(&device->vk.alloc, ctx); |
| 937 |
} |
| 938 |
|
| 939 |
static VkResult pvr_pds_sr_fence_terminate_program_create_and_upload( |
| 940 |
struct pvr_device *device, |
| 941 |
struct pvr_pds_upload *const pds_upload_out) |
| 942 |
{ |
| 943 |
const uint32_t pds_data_alignment = |
| 944 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE / 4U; |
| 945 |
const struct pvr_device_runtime_info *dev_runtime_info = |
| 946 |
&device->pdevice->dev_runtime_info; |
| 947 |
ASSERTED const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 948 |
uint32_t staging_buffer[ROGUE_PDS_TASK_PROGRAM_SIZE >> 2U]; |
| 949 |
struct pvr_pds_fence_program program = { 0 }; |
| 950 |
ASSERTED uint32_t *buffer_end; |
| 951 |
uint32_t code_offset; |
| 952 |
uint32_t data_size; |
| 953 |
|
| 954 |
/* SW_COMPUTE_PDS_BARRIER is not supported with 2 or more phantoms. */ |
| 955 |
assert(!(PVR_NEED_SW_COMPUTE_PDS_BARRIER(dev_info) && |
| 956 |
dev_runtime_info->num_phantoms >= 2)); |
| 957 |
|
| 958 |
pvr_pds_generate_fence_terminate_program(&program, |
| 959 |
staging_buffer, |
| 960 |
PDS_GENERATE_DATA_SEGMENT, |
| 961 |
&device->pdevice->dev_info); |
| 962 |
|
| 963 |
/* FIXME: pvr_pds_generate_fence_terminate_program() zeros out the data_size |
| 964 |
* when we generate the code segment. Implement |
| 965 |
* PDS_GENERATE_CODEDATA_SEGMENTS? Or wait for the pds gen api to change? |
| 966 |
* This behavior doesn't seem consistent with the rest of the api. For now |
| 967 |
* we store the size in a variable. |
| 968 |
*/ |
| 969 |
data_size = program.data_size; |
| 970 |
code_offset = ALIGN_POT(program.data_size, pds_data_alignment); |
| 971 |
|
| 972 |
buffer_end = |
| 973 |
pvr_pds_generate_fence_terminate_program(&program, |
| 974 |
&staging_buffer[code_offset], |
| 975 |
PDS_GENERATE_CODE_SEGMENT, |
| 976 |
&device->pdevice->dev_info); |
| 977 |
|
| 978 |
assert((uint64_t)(buffer_end - staging_buffer) * sizeof(staging_buffer[0]) < |
| 979 |
ROGUE_PDS_TASK_PROGRAM_SIZE); |
| 980 |
|
| 981 |
return pvr_gpu_upload_pds(device, |
| 982 |
staging_buffer, |
| 983 |
data_size, |
| 984 |
ROGUE_CR_CDM_TERMINATE_PDS_DATA_ADDR_ALIGNMENT, |
| 985 |
&staging_buffer[code_offset], |
| 986 |
program.code_size, |
| 987 |
ROGUE_CR_CDM_TERMINATE_PDS_CODE_ADDR_ALIGNMENT, |
| 988 |
0, |
| 989 |
pds_upload_out); |
| 990 |
} |
| 991 |
|
| 992 |
static void pvr_compute_ctx_ws_static_state_init( |
| 993 |
const struct pvr_device_info *const dev_info, |
| 994 |
const struct pvr_compute_ctx *const ctx, |
| 995 |
struct PVR_PER_ARCH(winsys_compute_ctx_static_state) *const static_state) |
| 996 |
{ |
| 997 |
const struct pvr_compute_ctx_switch *const ctx_switch = &ctx->ctx_switch; |
| 998 |
|
| 999 |
/* CR_CDM_CONTEXT_... use state store program info. */ |
| 1000 |
|
| 1001 |
pvr_csb_pack (&static_state->cdm_ctx_store_pds0, |
| 1002 |
CR_CDM_CONTEXT_PDS0, |
| 1003 |
state) { |
| 1004 |
state.data_addr = |
| 1005 |
PVR_DEV_ADDR(ctx_switch->sr[0].pds.store_program.data_offset); |
| 1006 |
state.code_addr = |
| 1007 |
PVR_DEV_ADDR(ctx_switch->sr[0].pds.store_program.code_offset); |
| 1008 |
} |
| 1009 |
|
| 1010 |
pvr_csb_pack (&static_state->cdm_ctx_store_pds0_b, |
| 1011 |
CR_CDM_CONTEXT_PDS0, |
| 1012 |
state) { |
| 1013 |
state.data_addr = |
| 1014 |
PVR_DEV_ADDR(ctx_switch->sr[1].pds.store_program.data_offset); |
| 1015 |
state.code_addr = |
| 1016 |
PVR_DEV_ADDR(ctx_switch->sr[1].pds.store_program.code_offset); |
| 1017 |
} |
| 1018 |
|
| 1019 |
pvr_csb_pack (&static_state->cdm_ctx_store_pds1, |
| 1020 |
CR_CDM_CONTEXT_PDS1, |
| 1021 |
state) { |
| 1022 |
const uint32_t store_program_data_size = |
| 1023 |
PVR_DW_TO_BYTES(ctx_switch->sr[0].pds.store_program.data_size); |
| 1024 |
|
| 1025 |
state.pds_seq_dep = true; |
| 1026 |
state.usc_seq_dep = false; |
| 1027 |
state.target = true; |
| 1028 |
state.unified_size = ctx_switch->sr[0].usc.unified_size; |
| 1029 |
state.common_shared = false; |
| 1030 |
state.common_size = 0; |
| 1031 |
state.temp_size = 0; |
| 1032 |
|
| 1033 |
assert(store_program_data_size % |
| 1034 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE == |
| 1035 |
0); |
| 1036 |
state.data_size = store_program_data_size / |
| 1037 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE; |
| 1038 |
|
| 1039 |
state.fence = true; |
| 1040 |
} |
| 1041 |
|
| 1042 |
/* CR_CDM_TERMINATE_... use fence terminate info. */ |
| 1043 |
|
| 1044 |
pvr_csb_pack (&static_state->cdm_ctx_terminate_pds, |
| 1045 |
CR_CDM_TERMINATE_PDS, |
| 1046 |
state) { |
| 1047 |
state.data_addr = |
| 1048 |
PVR_DEV_ADDR(ctx_switch->sr_fence_terminate_program.data_offset); |
| 1049 |
state.code_addr = |
| 1050 |
PVR_DEV_ADDR(ctx_switch->sr_fence_terminate_program.code_offset); |
| 1051 |
} |
| 1052 |
|
| 1053 |
pvr_csb_pack (&static_state->cdm_ctx_terminate_pds1, |
| 1054 |
CR_CDM_TERMINATE_PDS1, |
| 1055 |
state) { |
| 1056 |
/* Convert the data size from dwords to bytes. */ |
| 1057 |
const uint32_t fence_terminate_program_data_size = |
| 1058 |
PVR_DW_TO_BYTES(ctx_switch->sr_fence_terminate_program.data_size); |
| 1059 |
|
| 1060 |
state.pds_seq_dep = true; |
| 1061 |
state.usc_seq_dep = false; |
| 1062 |
state.target = !PVR_HAS_FEATURE(dev_info, compute_morton_capable); |
| 1063 |
state.unified_size = 0; |
| 1064 |
/* Common store is for shareds -- this will free the partitions. */ |
| 1065 |
state.common_shared = true; |
| 1066 |
state.common_size = 0; |
| 1067 |
state.temp_size = 0; |
| 1068 |
|
| 1069 |
assert(fence_terminate_program_data_size % |
| 1070 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE == |
| 1071 |
0); |
| 1072 |
state.data_size = fence_terminate_program_data_size / |
| 1073 |
ROGUE_VDMCTRL_PDS_STATE0_PDS_DATA_SIZE_UNIT_SIZE; |
| 1074 |
state.fence = true; |
| 1075 |
} |
| 1076 |
|
| 1077 |
/* CR_CDM_RESUME_... use state load program info. */ |
| 1078 |
|
| 1079 |
pvr_csb_pack (&static_state->cdm_ctx_resume_pds0, |
| 1080 |
CR_CDM_CONTEXT_LOAD_PDS0, |
| 1081 |
state) { |
| 1082 |
state.data_addr = |
| 1083 |
PVR_DEV_ADDR(ctx_switch->sr[0].pds.load_program.data_offset); |
| 1084 |
state.code_addr = |
| 1085 |
PVR_DEV_ADDR(ctx_switch->sr[0].pds.load_program.code_offset); |
| 1086 |
} |
| 1087 |
|
| 1088 |
pvr_csb_pack (&static_state->cdm_ctx_resume_pds0_b, |
| 1089 |
CR_CDM_CONTEXT_LOAD_PDS0, |
| 1090 |
state) { |
| 1091 |
state.data_addr = |
| 1092 |
PVR_DEV_ADDR(ctx_switch->sr[1].pds.load_program.data_offset); |
| 1093 |
state.code_addr = |
| 1094 |
PVR_DEV_ADDR(ctx_switch->sr[1].pds.load_program.code_offset); |
| 1095 |
} |
| 1096 |
} |
| 1097 |
|
| 1098 |
static void pvr_compute_ctx_ws_create_info_init( |
| 1099 |
const struct pvr_compute_ctx *const ctx, |
| 1100 |
enum pvr_winsys_ctx_priority priority, |
| 1101 |
struct pvr_winsys_compute_ctx_create_info *const create_info) |
| 1102 |
{ |
| 1103 |
create_info->priority = priority; |
| 1104 |
|
| 1105 |
#if defined(PVR_BUILD_ARCH_ROGUE) |
| 1106 |
pvr_compute_ctx_ws_static_state_init(&ctx->device->pdevice->dev_info, |
| 1107 |
ctx, |
| 1108 |
&create_info->static_state.rogue); |
| 1109 |
#else |
| 1110 |
# error "Missing arch" |
| 1111 |
#endif |
| 1112 |
} |
| 1113 |
|
| 1114 |
VkResult pvr_arch_compute_ctx_create(struct pvr_device *const device, |
| 1115 |
enum pvr_winsys_ctx_priority priority, |
| 1116 |
struct pvr_compute_ctx **const ctx_out) |
| 1117 |
{ |
| 1118 |
struct pvr_winsys_compute_ctx_create_info create_info; |
| 1119 |
struct pvr_compute_ctx *ctx; |
| 1120 |
VkResult result; |
| 1121 |
|
| 1122 |
ctx = vk_alloc(&device->vk.alloc, |
| 1123 |
sizeof(*ctx), |
| 1124 |
8, |
| 1125 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1126 |
if (!ctx) |
| 1127 |
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1128 |
|
| 1129 |
ctx->device = device; |
| 1130 |
|
| 1131 |
result = pvr_bo_alloc( |
| 1132 |
device, |
| 1133 |
device->heaps.general_heap, |
| 1134 |
rogue_get_cdm_context_resume_buffer_size(&device->pdevice->dev_info), |
| 1135 |
rogue_get_cdm_context_resume_buffer_alignment(&device->pdevice->dev_info), |
| 1136 |
PVR_WINSYS_BO_FLAG_CPU_ACCESS | PVR_WINSYS_BO_FLAG_GPU_UNCACHED, |
| 1137 |
&ctx->ctx_switch.compute_state_bo); |
| 1138 |
if (result != VK_SUCCESS) |
| 1139 |
goto err_free_ctx; |
| 1140 |
|
| 1141 |
/* TODO: Change this so that enabling storage to B doesn't change the array |
| 1142 |
* size. Instead of looping we could unroll this and have the second |
| 1143 |
* programs setup depending on the B enable. Doing it that way would make |
| 1144 |
* things more obvious. |
| 1145 |
*/ |
| 1146 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->ctx_switch.sr); i++) { |
| 1147 |
result = pvr_ctx_sr_programs_setup(device, |
| 1148 |
PVR_CTX_SR_COMPUTE_TARGET, |
| 1149 |
&ctx->ctx_switch.sr[i]); |
| 1150 |
if (result != VK_SUCCESS) { |
| 1151 |
for (uint32_t j = 0; j < i; j++) |
| 1152 |
pvr_ctx_sr_programs_cleanup(device, &ctx->ctx_switch.sr[j]); |
| 1153 |
|
| 1154 |
goto err_free_state_buffer; |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
result = pvr_pds_sr_fence_terminate_program_create_and_upload( |
| 1159 |
device, |
| 1160 |
&ctx->ctx_switch.sr_fence_terminate_program); |
| 1161 |
if (result != VK_SUCCESS) |
| 1162 |
goto err_free_sr_programs; |
| 1163 |
|
| 1164 |
pvr_compute_ctx_ws_create_info_init(ctx, priority, &create_info); |
| 1165 |
|
| 1166 |
result = pvr_ctx_reset_cmd_init(device, &ctx->reset_cmd); |
| 1167 |
if (result != VK_SUCCESS) |
| 1168 |
goto err_free_pds_fence_terminate_program; |
| 1169 |
|
| 1170 |
result = device->ws->ops->compute_ctx_create(device->ws, |
| 1171 |
&create_info, |
| 1172 |
&device->pdevice->dev_info, |
| 1173 |
&ctx->ws_ctx); |
| 1174 |
if (result != VK_SUCCESS) |
| 1175 |
goto err_fini_reset_cmd; |
| 1176 |
|
| 1177 |
*ctx_out = ctx; |
| 1178 |
|
| 1179 |
return VK_SUCCESS; |
| 1180 |
|
| 1181 |
err_fini_reset_cmd: |
| 1182 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 1183 |
|
| 1184 |
err_free_pds_fence_terminate_program: |
| 1185 |
pvr_bo_suballoc_free(ctx->ctx_switch.sr_fence_terminate_program.pvr_bo); |
| 1186 |
|
| 1187 |
err_free_sr_programs: |
| 1188 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->ctx_switch.sr); ++i) |
| 1189 |
pvr_ctx_sr_programs_cleanup(device, &ctx->ctx_switch.sr[i]); |
| 1190 |
|
| 1191 |
err_free_state_buffer: |
| 1192 |
pvr_bo_free(device, ctx->ctx_switch.compute_state_bo); |
| 1193 |
|
| 1194 |
err_free_ctx: |
| 1195 |
vk_free(&device->vk.alloc, ctx); |
| 1196 |
|
| 1197 |
return result; |
| 1198 |
} |
| 1199 |
|
| 1200 |
void pvr_arch_compute_ctx_destroy(struct pvr_compute_ctx *const ctx) |
| 1201 |
{ |
| 1202 |
struct pvr_device *device = ctx->device; |
| 1203 |
|
| 1204 |
device->ws->ops->compute_ctx_destroy(ctx->ws_ctx); |
| 1205 |
|
| 1206 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 1207 |
|
| 1208 |
pvr_bo_suballoc_free(ctx->ctx_switch.sr_fence_terminate_program.pvr_bo); |
| 1209 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->ctx_switch.sr); ++i) |
| 1210 |
pvr_ctx_sr_programs_cleanup(device, &ctx->ctx_switch.sr[i]); |
| 1211 |
|
| 1212 |
pvr_bo_free(device, ctx->ctx_switch.compute_state_bo); |
| 1213 |
|
| 1214 |
vk_free(&device->vk.alloc, ctx); |
| 1215 |
} |
| 1216 |
|
| 1217 |
static void pvr_transfer_ctx_ws_create_info_init( |
| 1218 |
enum pvr_winsys_ctx_priority priority, |
| 1219 |
struct pvr_winsys_transfer_ctx_create_info *const create_info) |
| 1220 |
{ |
| 1221 |
create_info->priority = priority; |
| 1222 |
} |
| 1223 |
|
| 1224 |
static VkResult pvr_transfer_eot_shaders_init(struct pvr_device *device, |
| 1225 |
struct pvr_transfer_ctx *ctx) |
| 1226 |
{ |
| 1227 |
unsigned rt_pbe_regs[PVR_TRANSFER_MAX_RENDER_TARGETS]; |
| 1228 |
|
| 1229 |
/* Setup start indexes of the shared registers that will contain the PBE |
| 1230 |
* state words for each render target. These must match the indexes used in |
| 1231 |
* pvr_pds_generate_pixel_event(), which is used to generate the |
| 1232 |
* corresponding PDS program in pvr_pbe_setup_emit() via |
| 1233 |
* pvr_pds_generate_pixel_event_data_segment() and |
| 1234 |
* pvr_pds_generate_pixel_event_code_segment(). |
| 1235 |
*/ |
| 1236 |
/* TODO: store the shared register information somewhere so that it can be |
| 1237 |
* shared with pvr_pbe_setup_emit() rather than having the shared register |
| 1238 |
* indexes and number of shared registers hard coded in |
| 1239 |
* pvr_pds_generate_pixel_event(). |
| 1240 |
*/ |
| 1241 |
for (unsigned i = 0; i < ARRAY_SIZE(rt_pbe_regs); i++) |
| 1242 |
rt_pbe_regs[i] = i * PVR_STATE_PBE_DWORDS; |
| 1243 |
|
| 1244 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->usc_eot_bos); i++) { |
| 1245 |
const uint32_t cache_line_size = |
| 1246 |
pvr_get_slc_cache_line_size(&device->pdevice->dev_info); |
| 1247 |
struct pvr_eot_props props = { |
| 1248 |
.emit_count = i + 1, |
| 1249 |
.shared_words = true, |
| 1250 |
.state_regs = rt_pbe_regs, |
| 1251 |
}; |
| 1252 |
pco_shader *eot; |
| 1253 |
VkResult result; |
| 1254 |
|
| 1255 |
eot = pvr_usc_eot(device->pdevice->pco_ctx, |
| 1256 |
&props, |
| 1257 |
&device->pdevice->dev_info); |
| 1258 |
|
| 1259 |
result = pvr_gpu_upload_usc(device, |
| 1260 |
pco_shader_binary_data(eot), |
| 1261 |
pco_shader_binary_size(eot), |
| 1262 |
cache_line_size, |
| 1263 |
&ctx->usc_eot_bos[i]); |
| 1264 |
|
| 1265 |
ctx->usc_eot_usc_temps[i] = pco_shader_data(eot)->common.temps; |
| 1266 |
ralloc_free(eot); |
| 1267 |
|
| 1268 |
if (result != VK_SUCCESS) { |
| 1269 |
for (uint32_t j = 0; j < i; j++) |
| 1270 |
pvr_bo_suballoc_free(ctx->usc_eot_bos[j]); |
| 1271 |
|
| 1272 |
return result; |
| 1273 |
} |
| 1274 |
} |
| 1275 |
|
| 1276 |
return VK_SUCCESS; |
| 1277 |
} |
| 1278 |
|
| 1279 |
static void pvr_transfer_eot_shaders_fini(struct pvr_device *device, |
| 1280 |
struct pvr_transfer_ctx *ctx) |
| 1281 |
{ |
| 1282 |
for (uint32_t i = 0; i < ARRAY_SIZE(ctx->usc_eot_bos); i++) |
| 1283 |
pvr_bo_suballoc_free(ctx->usc_eot_bos[i]); |
| 1284 |
} |
| 1285 |
|
| 1286 |
static VkResult pvr_transfer_ctx_shaders_init(struct pvr_device *device, |
| 1287 |
struct pvr_transfer_ctx *ctx) |
| 1288 |
{ |
| 1289 |
VkResult result; |
| 1290 |
|
| 1291 |
result = pvr_transfer_frag_store_init(device, &ctx->frag_store); |
| 1292 |
if (result != VK_SUCCESS) |
| 1293 |
goto err_out; |
| 1294 |
|
| 1295 |
result = pvr_transfer_eot_shaders_init(device, ctx); |
| 1296 |
if (result != VK_SUCCESS) |
| 1297 |
goto err_frag_store_fini; |
| 1298 |
|
| 1299 |
return VK_SUCCESS; |
| 1300 |
|
| 1301 |
err_frag_store_fini: |
| 1302 |
pvr_transfer_frag_store_fini(device, &ctx->frag_store); |
| 1303 |
|
| 1304 |
err_out: |
| 1305 |
return result; |
| 1306 |
} |
| 1307 |
|
| 1308 |
static void pvr_transfer_ctx_shaders_fini(struct pvr_device *device, |
| 1309 |
struct pvr_transfer_ctx *ctx) |
| 1310 |
{ |
| 1311 |
pvr_transfer_eot_shaders_fini(device, ctx); |
| 1312 |
pvr_transfer_frag_store_fini(device, &ctx->frag_store); |
| 1313 |
} |
| 1314 |
|
| 1315 |
VkResult pvr_arch_transfer_ctx_create(struct pvr_device *const device, |
| 1316 |
enum pvr_winsys_ctx_priority priority, |
| 1317 |
struct pvr_transfer_ctx **const ctx_out) |
| 1318 |
{ |
| 1319 |
struct pvr_winsys_transfer_ctx_create_info create_info; |
| 1320 |
struct pvr_transfer_ctx *ctx; |
| 1321 |
VkResult result; |
| 1322 |
|
| 1323 |
ctx = vk_zalloc(&device->vk.alloc, |
| 1324 |
sizeof(*ctx), |
| 1325 |
8U, |
| 1326 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 1327 |
if (!ctx) |
| 1328 |
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 1329 |
|
| 1330 |
ctx->device = device; |
| 1331 |
|
| 1332 |
result = pvr_ctx_reset_cmd_init(device, &ctx->reset_cmd); |
| 1333 |
if (result != VK_SUCCESS) |
| 1334 |
goto err_free_ctx; |
| 1335 |
|
| 1336 |
pvr_transfer_ctx_ws_create_info_init(priority, &create_info); |
| 1337 |
|
| 1338 |
result = device->ws->ops->transfer_ctx_create(device->ws, |
| 1339 |
&create_info, |
| 1340 |
&ctx->ws_ctx); |
| 1341 |
if (result != VK_SUCCESS) |
| 1342 |
goto err_fini_reset_cmd; |
| 1343 |
|
| 1344 |
result = pvr_transfer_ctx_shaders_init(device, ctx); |
| 1345 |
if (result != VK_SUCCESS) |
| 1346 |
goto err_destroy_transfer_ctx; |
| 1347 |
|
| 1348 |
/* Create the PDS Uniform/Tex state code segment array. */ |
| 1349 |
for (uint32_t i = 0U; i < ARRAY_SIZE(ctx->pds_unitex_code); i++) { |
| 1350 |
for (uint32_t j = 0U; j < ARRAY_SIZE(ctx->pds_unitex_code[0U]); j++) { |
| 1351 |
if (i == 0U && j == 0U) |
| 1352 |
continue; |
| 1353 |
|
| 1354 |
result = pvr_arch_pds_unitex_state_program_create_and_upload( |
| 1355 |
device, |
| 1356 |
NULL, |
| 1357 |
i, |
| 1358 |
j, |
| 1359 |
&ctx->pds_unitex_code[i][j]); |
| 1360 |
if (result != VK_SUCCESS) { |
| 1361 |
goto err_free_pds_unitex_bos; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
} |
| 1365 |
|
| 1366 |
*ctx_out = ctx; |
| 1367 |
|
| 1368 |
return VK_SUCCESS; |
| 1369 |
|
| 1370 |
err_free_pds_unitex_bos: |
| 1371 |
for (uint32_t i = 0U; i < ARRAY_SIZE(ctx->pds_unitex_code); i++) { |
| 1372 |
for (uint32_t j = 0U; j < ARRAY_SIZE(ctx->pds_unitex_code[0U]); j++) { |
| 1373 |
if (!ctx->pds_unitex_code[i][j].pvr_bo) |
| 1374 |
continue; |
| 1375 |
|
| 1376 |
pvr_bo_suballoc_free(ctx->pds_unitex_code[i][j].pvr_bo); |
| 1377 |
} |
| 1378 |
} |
| 1379 |
|
| 1380 |
pvr_transfer_ctx_shaders_fini(device, ctx); |
| 1381 |
|
| 1382 |
err_destroy_transfer_ctx: |
| 1383 |
device->ws->ops->transfer_ctx_destroy(ctx->ws_ctx); |
| 1384 |
|
| 1385 |
err_fini_reset_cmd: |
| 1386 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 1387 |
|
| 1388 |
err_free_ctx: |
| 1389 |
vk_free(&device->vk.alloc, ctx); |
| 1390 |
|
| 1391 |
return result; |
| 1392 |
} |
| 1393 |
|
| 1394 |
void pvr_arch_transfer_ctx_destroy(struct pvr_transfer_ctx *const ctx) |
| 1395 |
{ |
| 1396 |
struct pvr_device *device = ctx->device; |
| 1397 |
|
| 1398 |
for (uint32_t i = 0U; i < ARRAY_SIZE(ctx->pds_unitex_code); i++) { |
| 1399 |
for (uint32_t j = 0U; j < ARRAY_SIZE(ctx->pds_unitex_code[0U]); j++) { |
| 1400 |
if (!ctx->pds_unitex_code[i][j].pvr_bo) |
| 1401 |
continue; |
| 1402 |
|
| 1403 |
pvr_bo_suballoc_free(ctx->pds_unitex_code[i][j].pvr_bo); |
| 1404 |
} |
| 1405 |
} |
| 1406 |
|
| 1407 |
pvr_transfer_ctx_shaders_fini(device, ctx); |
| 1408 |
device->ws->ops->transfer_ctx_destroy(ctx->ws_ctx); |
| 1409 |
pvr_ctx_reset_cmd_fini(device, &ctx->reset_cmd); |
| 1410 |
vk_free(&device->vk.alloc, ctx); |
| 1411 |
} |