| 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_pass.h" |
| 25 |
|
| 26 |
#include <stdbool.h> |
| 27 |
#include <stdint.h> |
| 28 |
|
| 29 |
#include "hwdef/rogue_hw_utils.h" |
| 30 |
#include "pvr_bo.h" |
| 31 |
#include "pvr_device.h" |
| 32 |
#include "pvr_device_info.h" |
| 33 |
#include "pvr_entrypoints.h" |
| 34 |
#include "pvr_formats.h" |
| 35 |
#include "pvr_hw_pass.h" |
| 36 |
#include "pvr_macros.h" |
| 37 |
#include "pvr_pds.h" |
| 38 |
#include "pvr_physical_device.h" |
| 39 |
#include "pvr_pipeline.h" |
| 40 |
#include "pvr_types.h" |
| 41 |
#include "pvr_usc.h" |
| 42 |
#include "util/macros.h" |
| 43 |
#include "vk_alloc.h" |
| 44 |
#include "vk_format.h" |
| 45 |
#include "vk_log.h" |
| 46 |
#include "vk_render_pass.h" |
| 47 |
#include "vk_util.h" |
| 48 |
|
| 49 |
static inline bool pvr_subpass_has_msaa_input_attachment( |
| 50 |
struct pvr_render_subpass *subpass, |
| 51 |
const VkRenderPassCreateInfo2 *pCreateInfo) |
| 52 |
{ |
| 53 |
for (uint32_t i = 0; i < subpass->input_count; i++) { |
| 54 |
const uint32_t attachment = subpass->input_attachments[i].attachment_idx; |
| 55 |
|
| 56 |
if (pCreateInfo->pAttachments[attachment].samples > 1) |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
static bool pvr_is_subpass_initops_flush_needed( |
| 64 |
const struct pvr_render_pass *pass, |
| 65 |
const struct pvr_renderpass_hwsetup_render *hw_render) |
| 66 |
{ |
| 67 |
struct pvr_render_subpass *subpass = &pass->subpasses[0]; |
| 68 |
uint32_t render_loadop_mask = 0; |
| 69 |
uint32_t color_attachment_mask; |
| 70 |
|
| 71 |
for (uint32_t i = 0; i < hw_render->color_init_count; i++) { |
| 72 |
if (hw_render->color_init[i].op != VK_ATTACHMENT_LOAD_OP_DONT_CARE) |
| 73 |
render_loadop_mask |= (1 << hw_render->color_init[i].index); |
| 74 |
} |
| 75 |
|
| 76 |
/* If there are no load ops then there's nothing to flush. */ |
| 77 |
if (render_loadop_mask == 0) |
| 78 |
return false; |
| 79 |
|
| 80 |
/* If the first subpass has any input attachments, they need to be |
| 81 |
* initialized with the result of the load op. Since the input attachment |
| 82 |
* may be read from fragments with an opaque pass type, the load ops must be |
| 83 |
* flushed or else they would be obscured and eliminated by HSR. |
| 84 |
*/ |
| 85 |
if (subpass->input_count != 0) |
| 86 |
return true; |
| 87 |
|
| 88 |
color_attachment_mask = 0; |
| 89 |
|
| 90 |
for (uint32_t i = 0; i < subpass->color_count; i++) { |
| 91 |
const uint32_t color_idx = subpass->color_attachments[i]; |
| 92 |
|
| 93 |
if (color_idx != VK_ATTACHMENT_UNUSED) |
| 94 |
color_attachment_mask |= (1 << pass->attachments[color_idx].index); |
| 95 |
} |
| 96 |
|
| 97 |
/* If the first subpass does not write to all attachments which have a load |
| 98 |
* op then the load ops need to be flushed to ensure they don't get obscured |
| 99 |
* and removed by HSR. |
| 100 |
*/ |
| 101 |
return (render_loadop_mask & color_attachment_mask) != render_loadop_mask; |
| 102 |
} |
| 103 |
|
| 104 |
static void |
| 105 |
pvr_init_subpass_isp_userpass(struct pvr_renderpass_hwsetup *hw_setup, |
| 106 |
struct pvr_render_pass *pass, |
| 107 |
struct pvr_render_subpass *subpasses) |
| 108 |
{ |
| 109 |
uint32_t subpass_idx = 0; |
| 110 |
|
| 111 |
for (uint32_t i = 0; i < hw_setup->render_count; i++) { |
| 112 |
struct pvr_renderpass_hwsetup_render *hw_render = &hw_setup->renders[i]; |
| 113 |
const uint32_t initial_isp_userpass = |
| 114 |
(uint32_t)pvr_is_subpass_initops_flush_needed(pass, hw_render); |
| 115 |
|
| 116 |
for (uint32_t j = 0; j < hw_render->subpass_count; j++) { |
| 117 |
subpasses[subpass_idx].isp_userpass = |
| 118 |
(j + initial_isp_userpass) & ROGUE_CR_ISP_CTL_UPASS_START_SIZE_MAX; |
| 119 |
subpass_idx++; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
assert(subpass_idx == pass->subpass_count); |
| 124 |
} |
| 125 |
|
| 126 |
static inline bool pvr_has_output_register_writes( |
| 127 |
const struct pvr_renderpass_hwsetup_render *hw_render) |
| 128 |
{ |
| 129 |
for (uint32_t i = 0; i < hw_render->init_setup.num_render_targets; i++) { |
| 130 |
struct usc_mrt_resource *mrt_resource = |
| 131 |
&hw_render->init_setup.mrt_resources[i]; |
| 132 |
|
| 133 |
if (mrt_resource->type == USC_MRT_RESOURCE_TYPE_OUTPUT_REG) |
| 134 |
return true; |
| 135 |
} |
| 136 |
|
| 137 |
return false; |
| 138 |
} |
| 139 |
|
| 140 |
/* TODO: pvr_subpass_load_op_init() and pvr_render_load_op_init() are quite |
| 141 |
* similar. See if we can dedup them? |
| 142 |
*/ |
| 143 |
static VkResult |
| 144 |
pvr_subpass_load_op_init(struct pvr_device *device, |
| 145 |
const VkAllocationCallbacks *allocator, |
| 146 |
const struct pvr_render_pass *pass, |
| 147 |
struct pvr_renderpass_hwsetup_render *hw_render, |
| 148 |
uint32_t hw_subpass_idx) |
| 149 |
{ |
| 150 |
const struct pvr_renderpass_hwsetup_subpass *hw_subpass = |
| 151 |
&hw_render->subpasses[hw_subpass_idx]; |
| 152 |
const struct pvr_render_subpass *subpass = |
| 153 |
&pass->subpasses[hw_subpass->index]; |
| 154 |
struct pvr_load_op *load_op; |
| 155 |
VkResult result; |
| 156 |
|
| 157 |
load_op = vk_zalloc2(&device->vk.alloc, |
| 158 |
allocator, |
| 159 |
sizeof(*load_op), |
| 160 |
8, |
| 161 |
VK_SYSTEM_ALLOCATION_SCOPE_DEVICE); |
| 162 |
if (!load_op) |
| 163 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 164 |
|
| 165 |
load_op->clears_loads_state.depth_clear_to_reg = PVR_NO_DEPTH_CLEAR_TO_REG; |
| 166 |
|
| 167 |
if (hw_subpass->z_replicate != -1) { |
| 168 |
const int32_t z_replicate = hw_subpass->z_replicate; |
| 169 |
|
| 170 |
switch (hw_subpass->depth_initop) { |
| 171 |
case VK_ATTACHMENT_LOAD_OP_LOAD: |
| 172 |
assert(z_replicate < PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS); |
| 173 |
load_op->clears_loads_state.rt_load_mask = BITFIELD_BIT(z_replicate); |
| 174 |
|
| 175 |
assert(subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED); |
| 176 |
load_op->clears_loads_state.dest_vk_format[z_replicate] = |
| 177 |
pass->attachments[subpass->depth_stencil_attachment].vk_format; |
| 178 |
|
| 179 |
break; |
| 180 |
|
| 181 |
case VK_ATTACHMENT_LOAD_OP_CLEAR: |
| 182 |
load_op->clears_loads_state.depth_clear_to_reg = z_replicate; |
| 183 |
break; |
| 184 |
|
| 185 |
default: |
| 186 |
break; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
assert(subpass->color_count <= PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS); |
| 191 |
for (uint32_t i = 0; i < subpass->color_count; i++) { |
| 192 |
const uint32_t attachment_idx = subpass->color_attachments[i]; |
| 193 |
|
| 194 |
assert(attachment_idx < pass->attachment_count); |
| 195 |
load_op->clears_loads_state.dest_vk_format[i] = |
| 196 |
pass->attachments[attachment_idx].vk_format; |
| 197 |
|
| 198 |
if (pass->attachments[attachment_idx].sample_count > 1) |
| 199 |
load_op->clears_loads_state.unresolved_msaa_mask |= BITFIELD_BIT(i); |
| 200 |
|
| 201 |
if (hw_subpass->color_initops[i] == VK_ATTACHMENT_LOAD_OP_LOAD) |
| 202 |
load_op->clears_loads_state.rt_load_mask |= BITFIELD_BIT(i); |
| 203 |
else if (hw_subpass->color_initops[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) |
| 204 |
load_op->clears_loads_state.rt_clear_mask |= BITFIELD_BIT(i); |
| 205 |
} |
| 206 |
|
| 207 |
load_op->is_hw_object = false; |
| 208 |
load_op->subpass = subpass; |
| 209 |
load_op->clears_loads_state.mrt_setup = &hw_subpass->setup; |
| 210 |
|
| 211 |
result = pvr_arch_load_op_shader_generate(device, allocator, load_op); |
| 212 |
if (result != VK_SUCCESS) { |
| 213 |
vk_free2(&device->vk.alloc, allocator, load_op); |
| 214 |
return result; |
| 215 |
} |
| 216 |
|
| 217 |
load_op->view_count = 0; |
| 218 |
u_foreach_bit (view_idx, hw_render->view_mask) { |
| 219 |
load_op->view_indices[load_op->view_count] = view_idx; |
| 220 |
load_op->view_count++; |
| 221 |
} |
| 222 |
|
| 223 |
hw_render->subpasses[hw_subpass_idx].load_op = load_op; |
| 224 |
|
| 225 |
return VK_SUCCESS; |
| 226 |
} |
| 227 |
|
| 228 |
struct pvr_per_view_attachment_first_use_info { |
| 229 |
uint32_t *first_subpass[PVR_MAX_MULTIVIEW]; |
| 230 |
uint32_t *first_subpass_memory; |
| 231 |
}; |
| 232 |
|
| 233 |
/** |
| 234 |
* \brief Returns true if a clear op is needed instead of the hw render reported |
| 235 |
* load op load. |
| 236 |
* |
| 237 |
* The hw render isn't aware of multiview renders so it thinks we're reusing the |
| 238 |
* attachment of a previous subpass even if it's the first time the attachment |
| 239 |
* is used in the render pass, so a clear op gets reported as a load op load |
| 240 |
* instead. |
| 241 |
*/ |
| 242 |
/* FIXME: Investigate whether we can change the HW render code so it reports |
| 243 |
* the correct load operation. This will mean we can get rid of struct |
| 244 |
* pvr_per_view_attachment_first_use_info and struct pvr_load_op_state. |
| 245 |
* Instead we'll be able to have a single render struct load_op like we do for |
| 246 |
* subpasses. |
| 247 |
*/ |
| 248 |
static bool pvr_render_load_op_multiview_load_should_be_clear( |
| 249 |
const struct pvr_render_pass *pass, |
| 250 |
const struct pvr_renderpass_hwsetup_render *hw_render, |
| 251 |
uint32_t hw_render_index, |
| 252 |
const struct pvr_renderpass_colorinit *color_init, |
| 253 |
const struct pvr_per_view_attachment_first_use_info *first_use_info, |
| 254 |
uint32_t view_index) |
| 255 |
{ |
| 256 |
uint32_t first_use_view_index; |
| 257 |
|
| 258 |
if (!pass->multiview_enabled) |
| 259 |
return false; |
| 260 |
|
| 261 |
/* Check we have a load op load to see if we might need to correct the hw |
| 262 |
* render. |
| 263 |
*/ |
| 264 |
if (color_init->op != VK_ATTACHMENT_LOAD_OP_LOAD) |
| 265 |
return false; |
| 266 |
|
| 267 |
first_use_view_index = |
| 268 |
first_use_info->first_subpass[view_index][color_init->index]; |
| 269 |
|
| 270 |
/* Check that we're looking at the render where the attachment is used for |
| 271 |
* the first time. |
| 272 |
*/ |
| 273 |
if (first_use_view_index != hw_render_index) |
| 274 |
return false; |
| 275 |
|
| 276 |
/* Check that the original load op was a clear op. */ |
| 277 |
if (pass->attachments[color_init->index].load_op != |
| 278 |
VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 279 |
return false; |
| 280 |
} |
| 281 |
|
| 282 |
return true; |
| 283 |
} |
| 284 |
|
| 285 |
static VkResult pvr_render_load_op_init( |
| 286 |
struct pvr_device *device, |
| 287 |
const VkAllocationCallbacks *allocator, |
| 288 |
struct pvr_load_op *const load_op, |
| 289 |
const struct pvr_render_pass *pass, |
| 290 |
const struct pvr_renderpass_hwsetup_render *hw_render, |
| 291 |
uint32_t hw_render_index, |
| 292 |
uint32_t view_index, |
| 293 |
const struct pvr_per_view_attachment_first_use_info *first_use_info) |
| 294 |
{ |
| 295 |
load_op->clears_loads_state.depth_clear_to_reg = PVR_NO_DEPTH_CLEAR_TO_REG; |
| 296 |
|
| 297 |
assert(hw_render->color_init_count <= PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS); |
| 298 |
for (uint32_t i = 0; i < hw_render->color_init_count; i++) { |
| 299 |
struct pvr_renderpass_colorinit *color_init = &hw_render->color_init[i]; |
| 300 |
bool multiview_load_op_should_be_clear = false; |
| 301 |
|
| 302 |
assert(color_init->index < pass->attachment_count); |
| 303 |
load_op->clears_loads_state.dest_vk_format[i] = |
| 304 |
pass->attachments[color_init->index].vk_format; |
| 305 |
|
| 306 |
if (pass->attachments[color_init->index].sample_count > 1) |
| 307 |
load_op->clears_loads_state.unresolved_msaa_mask |= BITFIELD_BIT(i); |
| 308 |
|
| 309 |
multiview_load_op_should_be_clear = |
| 310 |
pvr_render_load_op_multiview_load_should_be_clear(pass, |
| 311 |
hw_render, |
| 312 |
hw_render_index, |
| 313 |
color_init, |
| 314 |
first_use_info, |
| 315 |
view_index); |
| 316 |
|
| 317 |
if (color_init->op == VK_ATTACHMENT_LOAD_OP_CLEAR || |
| 318 |
multiview_load_op_should_be_clear) { |
| 319 |
load_op->clears_loads_state.rt_clear_mask |= BITFIELD_BIT(i); |
| 320 |
} else if (color_init->op == VK_ATTACHMENT_LOAD_OP_LOAD) { |
| 321 |
load_op->clears_loads_state.rt_load_mask |= BITFIELD_BIT(i); |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
load_op->is_hw_object = true; |
| 326 |
load_op->hw_render = hw_render; |
| 327 |
load_op->clears_loads_state.mrt_setup = &hw_render->init_setup; |
| 328 |
load_op->view_indices[0] = view_index; |
| 329 |
load_op->view_count = 1; |
| 330 |
|
| 331 |
return pvr_arch_load_op_shader_generate(device, allocator, load_op); |
| 332 |
} |
| 333 |
|
| 334 |
static void pvr_load_op_fini(struct pvr_load_op *load_op) |
| 335 |
{ |
| 336 |
pvr_bo_suballoc_free(load_op->pds_tex_state_prog.pvr_bo); |
| 337 |
pvr_bo_suballoc_free(load_op->pds_frag_prog.pvr_bo); |
| 338 |
pvr_bo_suballoc_free(load_op->usc_frag_prog_bo); |
| 339 |
} |
| 340 |
|
| 341 |
static void pvr_load_op_destroy(struct pvr_device *device, |
| 342 |
const VkAllocationCallbacks *allocator, |
| 343 |
struct pvr_load_op *load_op) |
| 344 |
{ |
| 345 |
pvr_load_op_fini(load_op); |
| 346 |
vk_free2(&device->vk.alloc, allocator, load_op); |
| 347 |
} |
| 348 |
|
| 349 |
static void |
| 350 |
pvr_render_load_op_state_destroy(struct pvr_device *device, |
| 351 |
const VkAllocationCallbacks *pAllocator, |
| 352 |
struct pvr_load_op_state *load_op_state) |
| 353 |
{ |
| 354 |
if (!load_op_state) |
| 355 |
return; |
| 356 |
|
| 357 |
while (load_op_state->load_op_count--) { |
| 358 |
const uint32_t load_op_idx = load_op_state->load_op_count; |
| 359 |
struct pvr_load_op *load_op = &load_op_state->load_ops[load_op_idx]; |
| 360 |
|
| 361 |
pvr_load_op_fini(load_op); |
| 362 |
} |
| 363 |
|
| 364 |
vk_free2(&device->vk.alloc, pAllocator, load_op_state); |
| 365 |
} |
| 366 |
|
| 367 |
static VkResult pvr_render_load_op_state_create( |
| 368 |
struct pvr_device *device, |
| 369 |
const VkAllocationCallbacks *allocator, |
| 370 |
const struct pvr_render_pass *pass, |
| 371 |
const struct pvr_renderpass_hwsetup_render *hw_render, |
| 372 |
uint32_t hw_render_index, |
| 373 |
const struct pvr_per_view_attachment_first_use_info *first_use_info, |
| 374 |
struct pvr_load_op_state **const load_op_state_out) |
| 375 |
{ |
| 376 |
const uint32_t view_count = util_bitcount(hw_render->view_mask); |
| 377 |
struct pvr_load_op_state *load_op_state; |
| 378 |
struct pvr_load_op *load_ops; |
| 379 |
VkResult result; |
| 380 |
|
| 381 |
VK_MULTIALLOC(ma); |
| 382 |
vk_multialloc_add(&ma, &load_op_state, __typeof__(*load_op_state), 1); |
| 383 |
vk_multialloc_add(&ma, &load_ops, __typeof__(*load_ops), view_count); |
| 384 |
|
| 385 |
if (!vk_multialloc_zalloc(&ma, allocator, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE)) |
| 386 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 387 |
|
| 388 |
load_op_state->load_ops = load_ops; |
| 389 |
|
| 390 |
u_foreach_bit (view_idx, hw_render->view_mask) { |
| 391 |
struct pvr_load_op *const load_op = |
| 392 |
&load_op_state->load_ops[load_op_state->load_op_count]; |
| 393 |
|
| 394 |
result = pvr_render_load_op_init(device, |
| 395 |
allocator, |
| 396 |
load_op, |
| 397 |
pass, |
| 398 |
hw_render, |
| 399 |
hw_render_index, |
| 400 |
view_idx, |
| 401 |
first_use_info); |
| 402 |
if (result != VK_SUCCESS) |
| 403 |
goto err_load_op_state_destroy; |
| 404 |
|
| 405 |
load_op_state->load_op_count++; |
| 406 |
} |
| 407 |
|
| 408 |
*load_op_state_out = load_op_state; |
| 409 |
|
| 410 |
return VK_SUCCESS; |
| 411 |
|
| 412 |
err_load_op_state_destroy: |
| 413 |
pvr_render_load_op_state_destroy(device, allocator, load_op_state); |
| 414 |
|
| 415 |
return result; |
| 416 |
} |
| 417 |
|
| 418 |
#define PVR_SPM_LOAD_IN_BUFFERS_COUNT(dev_info) \ |
| 419 |
({ \ |
| 420 |
int __ret = PVR_MAX_TILE_BUFFER_COUNT; \ |
| 421 |
if (PVR_HAS_FEATURE(dev_info, eight_output_registers)) \ |
| 422 |
__ret -= 4U; \ |
| 423 |
__ret; \ |
| 424 |
}) |
| 425 |
|
| 426 |
static bool |
| 427 |
pvr_is_load_op_needed(const struct pvr_render_pass *pass, |
| 428 |
struct pvr_renderpass_hwsetup_render *hw_render, |
| 429 |
const uint32_t subpass_idx) |
| 430 |
{ |
| 431 |
struct pvr_renderpass_hwsetup_subpass *hw_subpass = |
| 432 |
&hw_render->subpasses[subpass_idx]; |
| 433 |
const struct pvr_render_subpass *subpass = |
| 434 |
&pass->subpasses[hw_subpass->index]; |
| 435 |
|
| 436 |
if (hw_subpass->z_replicate != -1 && |
| 437 |
(hw_subpass->depth_initop == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 438 |
hw_subpass->depth_initop == VK_ATTACHMENT_LOAD_OP_CLEAR)) { |
| 439 |
return true; |
| 440 |
} |
| 441 |
|
| 442 |
for (uint32_t i = 0; i < subpass->color_count; i++) { |
| 443 |
if (subpass->color_attachments[i] == VK_ATTACHMENT_UNUSED) |
| 444 |
continue; |
| 445 |
|
| 446 |
if (hw_subpass->color_initops[i] == VK_ATTACHMENT_LOAD_OP_LOAD || |
| 447 |
hw_subpass->color_initops[i] == VK_ATTACHMENT_LOAD_OP_CLEAR) { |
| 448 |
return true; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
return false; |
| 453 |
} |
| 454 |
|
| 455 |
static VkResult pvr_per_view_attachment_first_use_info_init( |
| 456 |
struct pvr_device *device, |
| 457 |
const VkAllocationCallbacks *allocator, |
| 458 |
struct pvr_render_pass *pass, |
| 459 |
struct pvr_per_view_attachment_first_use_info *first_use_info) |
| 460 |
{ |
| 461 |
size_t alloc_size; |
| 462 |
|
| 463 |
if (!pass->attachment_count) { |
| 464 |
memset(first_use_info, 0, sizeof(*first_use_info)); |
| 465 |
|
| 466 |
return VK_SUCCESS; |
| 467 |
} |
| 468 |
|
| 469 |
STATIC_ASSERT(ARRAY_SIZE(first_use_info->first_subpass) == |
| 470 |
PVR_MAX_MULTIVIEW); |
| 471 |
|
| 472 |
alloc_size = |
| 473 |
sizeof(first_use_info->first_subpass_memory[0]) * pass->attachment_count; |
| 474 |
alloc_size *= ARRAY_SIZE(first_use_info->first_subpass); |
| 475 |
|
| 476 |
first_use_info->first_subpass_memory = |
| 477 |
vk_zalloc2(&device->vk.alloc, |
| 478 |
allocator, |
| 479 |
alloc_size, |
| 480 |
4, |
| 481 |
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND); |
| 482 |
if (!first_use_info->first_subpass_memory) |
| 483 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 484 |
|
| 485 |
#define PVR_SUBPASS_INVALID (~0U) |
| 486 |
for (uint32_t i = 0; i < ARRAY_SIZE(first_use_info->first_subpass); i++) { |
| 487 |
first_use_info->first_subpass[i] = |
| 488 |
&first_use_info->first_subpass_memory[i * pass->attachment_count]; |
| 489 |
|
| 490 |
for (uint32_t j = 0; j < pass->attachment_count; j++) |
| 491 |
first_use_info->first_subpass[i][j] = PVR_SUBPASS_INVALID; |
| 492 |
} |
| 493 |
|
| 494 |
for (uint32_t subpass_idx = 0; subpass_idx < pass->subpass_count; |
| 495 |
subpass_idx++) { |
| 496 |
struct pvr_render_subpass *const subpass = &pass->subpasses[subpass_idx]; |
| 497 |
|
| 498 |
u_foreach_bit (view_idx, subpass->view_mask) { |
| 499 |
for (uint32_t i = 0; i < subpass->color_count; i++) { |
| 500 |
const uint32_t attach_idx = subpass->color_attachments[i]; |
| 501 |
uint32_t *first_use = |
| 502 |
&first_use_info->first_subpass[view_idx][attach_idx]; |
| 503 |
|
| 504 |
if (attach_idx < pass->attachment_count && |
| 505 |
*first_use == PVR_SUBPASS_INVALID) { |
| 506 |
*first_use = subpass_idx; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
for (uint32_t i = 0; i < subpass->input_count; i++) { |
| 511 |
const uint32_t input_attach_idx = |
| 512 |
subpass->input_attachments[i].attachment_idx; |
| 513 |
uint32_t *first_use = |
| 514 |
&first_use_info->first_subpass[view_idx][input_attach_idx]; |
| 515 |
|
| 516 |
if (input_attach_idx < pass->attachment_count && |
| 517 |
*first_use == PVR_SUBPASS_INVALID) { |
| 518 |
*first_use = subpass_idx; |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) { |
| 523 |
const uint32_t ds_attach_idx = subpass->depth_stencil_attachment; |
| 524 |
uint32_t *first_use = |
| 525 |
&first_use_info->first_subpass[view_idx][ds_attach_idx]; |
| 526 |
|
| 527 |
if (*first_use == PVR_SUBPASS_INVALID) |
| 528 |
*first_use = subpass_idx; |
| 529 |
} |
| 530 |
} |
| 531 |
} |
| 532 |
#undef PVR_SUBPASS_INVALID |
| 533 |
|
| 534 |
return VK_SUCCESS; |
| 535 |
} |
| 536 |
|
| 537 |
static inline void pvr_per_view_attachment_first_use_info_fini( |
| 538 |
struct pvr_device *device, |
| 539 |
const VkAllocationCallbacks *allocator, |
| 540 |
struct pvr_per_view_attachment_first_use_info *first_use_info) |
| 541 |
{ |
| 542 |
vk_free2(&device->vk.alloc, allocator, first_use_info->first_subpass_memory); |
| 543 |
} |
| 544 |
|
| 545 |
static inline VkResult pvr_render_add_missing_output_register_write( |
| 546 |
struct pvr_renderpass_hwsetup_render *hw_render, |
| 547 |
const VkAllocationCallbacks *allocator) |
| 548 |
{ |
| 549 |
const uint32_t last = hw_render->init_setup.num_render_targets; |
| 550 |
struct usc_mrt_resource *mrt_resources; |
| 551 |
|
| 552 |
/* Add a dummy output register use to the HW render setup if it has no |
| 553 |
* output registers in use. |
| 554 |
*/ |
| 555 |
if (pvr_has_output_register_writes(hw_render)) |
| 556 |
return VK_SUCCESS; |
| 557 |
|
| 558 |
hw_render->init_setup.num_render_targets++; |
| 559 |
|
| 560 |
mrt_resources = vk_realloc(allocator, |
| 561 |
hw_render->init_setup.mrt_resources, |
| 562 |
hw_render->init_setup.num_render_targets * |
| 563 |
sizeof(*mrt_resources), |
| 564 |
8U, |
| 565 |
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); |
| 566 |
if (!mrt_resources) |
| 567 |
return VK_ERROR_OUT_OF_HOST_MEMORY; |
| 568 |
|
| 569 |
hw_render->init_setup.mrt_resources = mrt_resources; |
| 570 |
|
| 571 |
mrt_resources[last].type = USC_MRT_RESOURCE_TYPE_OUTPUT_REG; |
| 572 |
mrt_resources[last].reg.output_reg = 0U; |
| 573 |
mrt_resources[last].reg.offset = 0U; |
| 574 |
mrt_resources[last].intermediate_size = 4U; |
| 575 |
mrt_resources[last].mrt_desc.intermediate_size = 4U; |
| 576 |
mrt_resources[last].mrt_desc.priority = 0U; |
| 577 |
mrt_resources[last].mrt_desc.valid_mask[0U] = ~0; |
| 578 |
mrt_resources[last].mrt_desc.valid_mask[1U] = ~0; |
| 579 |
mrt_resources[last].mrt_desc.valid_mask[2U] = ~0; |
| 580 |
mrt_resources[last].mrt_desc.valid_mask[3U] = ~0; |
| 581 |
|
| 582 |
return VK_SUCCESS; |
| 583 |
} |
| 584 |
|
| 585 |
static inline void |
| 586 |
pvr_subpass_load_op_cleanup(struct pvr_device *device, |
| 587 |
const VkAllocationCallbacks *allocator, |
| 588 |
struct pvr_renderpass_hwsetup_render *hw_render, |
| 589 |
uint32_t subpass_count) |
| 590 |
{ |
| 591 |
while (subpass_count--) { |
| 592 |
const uint32_t subpass_idx = subpass_count; |
| 593 |
|
| 594 |
if (hw_render->subpasses[subpass_idx].load_op) { |
| 595 |
pvr_load_op_destroy(device, |
| 596 |
allocator, |
| 597 |
hw_render->subpasses[subpass_idx].load_op); |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
static inline VkResult |
| 603 |
pvr_subpass_load_op_setup(struct pvr_device *device, |
| 604 |
const VkAllocationCallbacks *allocator, |
| 605 |
struct pvr_render_pass *pass, |
| 606 |
struct pvr_renderpass_hwsetup_render *hw_render) |
| 607 |
{ |
| 608 |
for (uint32_t i = 0; i < hw_render->subpass_count; i++) { |
| 609 |
VkResult result; |
| 610 |
|
| 611 |
if (!pvr_is_load_op_needed(pass, hw_render, i)) |
| 612 |
continue; |
| 613 |
|
| 614 |
result = pvr_subpass_load_op_init(device, allocator, pass, hw_render, i); |
| 615 |
if (result != VK_SUCCESS) { |
| 616 |
/* pvr_subpass_load_op_setup() is responsible for cleaning |
| 617 |
* up all load_ops created in this loop for this hw_render. |
| 618 |
*/ |
| 619 |
pvr_subpass_load_op_cleanup(device, allocator, hw_render, i); |
| 620 |
return result; |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
return VK_SUCCESS; |
| 625 |
} |
| 626 |
|
| 627 |
static inline VkResult pvr_hw_render_load_ops_setup( |
| 628 |
struct pvr_device *device, |
| 629 |
const VkAllocationCallbacks *allocator, |
| 630 |
struct pvr_render_pass *pass, |
| 631 |
struct pvr_renderpass_hwsetup_render *hw_render, |
| 632 |
uint32_t hw_render_idx, |
| 633 |
struct pvr_per_view_attachment_first_use_info *first_use_info) |
| 634 |
{ |
| 635 |
VkResult result; |
| 636 |
|
| 637 |
if (hw_render->tile_buffers_count) { |
| 638 |
result = pvr_device_tile_buffer_ensure_cap(device, |
| 639 |
hw_render->tile_buffers_count); |
| 640 |
if (result != VK_SUCCESS) |
| 641 |
return result; |
| 642 |
} |
| 643 |
|
| 644 |
assert(!hw_render->load_op_state); |
| 645 |
|
| 646 |
if (hw_render->color_init_count != 0U) { |
| 647 |
struct pvr_load_op_state *load_op_state = NULL; |
| 648 |
|
| 649 |
result = |
| 650 |
pvr_render_add_missing_output_register_write(hw_render, allocator); |
| 651 |
if (result != VK_SUCCESS) |
| 652 |
return result; |
| 653 |
|
| 654 |
result = pvr_render_load_op_state_create(device, |
| 655 |
allocator, |
| 656 |
pass, |
| 657 |
hw_render, |
| 658 |
hw_render_idx, |
| 659 |
first_use_info, |
| 660 |
&load_op_state); |
| 661 |
if (result != VK_SUCCESS) |
| 662 |
return result; |
| 663 |
|
| 664 |
hw_render->load_op_state = load_op_state; |
| 665 |
} |
| 666 |
|
| 667 |
result = pvr_subpass_load_op_setup(device, allocator, pass, hw_render); |
| 668 |
if (result != VK_SUCCESS) { |
| 669 |
/* pvr_hw_render_load_ops_setup() is responsible for cleaning up only |
| 670 |
* one load_op_state for this hw_render. |
| 671 |
*/ |
| 672 |
pvr_render_load_op_state_destroy(device, |
| 673 |
allocator, |
| 674 |
hw_render->load_op_state); |
| 675 |
return result; |
| 676 |
} |
| 677 |
|
| 678 |
return VK_SUCCESS; |
| 679 |
} |
| 680 |
|
| 681 |
static void |
| 682 |
pvr_render_pass_load_ops_cleanup(struct pvr_device *device, |
| 683 |
const VkAllocationCallbacks *allocator, |
| 684 |
struct pvr_render_pass *pass, |
| 685 |
uint32_t hw_render_count) |
| 686 |
{ |
| 687 |
while (hw_render_count--) { |
| 688 |
const uint32_t hw_render_idx = hw_render_count; |
| 689 |
struct pvr_renderpass_hwsetup_render *hw_render = |
| 690 |
&pass->hw_setup->renders[hw_render_idx]; |
| 691 |
|
| 692 |
pvr_subpass_load_op_cleanup(device, |
| 693 |
allocator, |
| 694 |
hw_render, |
| 695 |
hw_render->subpass_count); |
| 696 |
pvr_render_load_op_state_destroy(device, |
| 697 |
allocator, |
| 698 |
hw_render->load_op_state); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
static VkResult |
| 703 |
pvr_render_pass_load_ops_setup(struct pvr_device *device, |
| 704 |
const VkAllocationCallbacks *allocator, |
| 705 |
struct pvr_render_pass *pass) |
| 706 |
{ |
| 707 |
struct pvr_per_view_attachment_first_use_info first_use_info; |
| 708 |
uint32_t hw_render_idx; |
| 709 |
VkResult result; |
| 710 |
|
| 711 |
result = pvr_per_view_attachment_first_use_info_init(device, |
| 712 |
allocator, |
| 713 |
pass, |
| 714 |
&first_use_info); |
| 715 |
if (result != VK_SUCCESS) |
| 716 |
goto err_return; |
| 717 |
|
| 718 |
for (hw_render_idx = 0; hw_render_idx < pass->hw_setup->render_count; |
| 719 |
hw_render_idx++) { |
| 720 |
struct pvr_renderpass_hwsetup_render *hw_render = |
| 721 |
&pass->hw_setup->renders[hw_render_idx]; |
| 722 |
|
| 723 |
result = pvr_hw_render_load_ops_setup(device, |
| 724 |
allocator, |
| 725 |
pass, |
| 726 |
hw_render, |
| 727 |
hw_render_idx, |
| 728 |
&first_use_info); |
| 729 |
if (result != VK_SUCCESS) |
| 730 |
goto err_pvr_render_pass_load_ops_cleanup; |
| 731 |
} |
| 732 |
|
| 733 |
pvr_per_view_attachment_first_use_info_fini(device, |
| 734 |
allocator, |
| 735 |
&first_use_info); |
| 736 |
|
| 737 |
return VK_SUCCESS; |
| 738 |
|
| 739 |
err_pvr_render_pass_load_ops_cleanup: |
| 740 |
/* pvr_render_pass_load_ops_setup() is responsible for cleaning |
| 741 |
* up all load_ops created in this loop for each hw_render. |
| 742 |
*/ |
| 743 |
pvr_render_pass_load_ops_cleanup(device, allocator, pass, hw_render_idx); |
| 744 |
|
| 745 |
pvr_per_view_attachment_first_use_info_fini(device, |
| 746 |
allocator, |
| 747 |
&first_use_info); |
| 748 |
|
| 749 |
err_return: |
| 750 |
return result; |
| 751 |
} |
| 752 |
|
| 753 |
VkResult |
| 754 |
PVR_PER_ARCH(CreateRenderPass2)(VkDevice _device, |
| 755 |
const VkRenderPassCreateInfo2 *pCreateInfo, |
| 756 |
const VkAllocationCallbacks *pAllocator, |
| 757 |
VkRenderPass *pRenderPass) |
| 758 |
{ |
| 759 |
struct pvr_render_pass_attachment *attachments; |
| 760 |
VK_FROM_HANDLE(pvr_device, device, _device); |
| 761 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 762 |
struct pvr_render_subpass *subpasses; |
| 763 |
const VkAllocationCallbacks *alloc; |
| 764 |
size_t subpass_attachment_count; |
| 765 |
size_t subpass_input_attachment_count; |
| 766 |
size_t subpass_preserve_attachment_count; |
| 767 |
struct pvr_render_attachment *subpass_input_attachments; |
| 768 |
struct pvr_render_attachment *subpass_preserve_attachments; |
| 769 |
uint32_t *subpass_attachments; |
| 770 |
struct pvr_render_pass *pass; |
| 771 |
uint32_t *dep_list; |
| 772 |
bool *flush_on_dep; |
| 773 |
VkResult result; |
| 774 |
|
| 775 |
alloc = pAllocator ? pAllocator : &device->vk.alloc; |
| 776 |
|
| 777 |
VK_MULTIALLOC(ma); |
| 778 |
vk_multialloc_add(&ma, &pass, __typeof__(*pass), 1); |
| 779 |
vk_multialloc_add(&ma, |
| 780 |
&attachments, |
| 781 |
__typeof__(*attachments), |
| 782 |
pCreateInfo->attachmentCount); |
| 783 |
vk_multialloc_add(&ma, |
| 784 |
&subpasses, |
| 785 |
__typeof__(*subpasses), |
| 786 |
pCreateInfo->subpassCount); |
| 787 |
|
| 788 |
subpass_attachment_count = 0; |
| 789 |
subpass_input_attachment_count = 0; |
| 790 |
subpass_preserve_attachment_count = 0; |
| 791 |
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { |
| 792 |
const VkSubpassDescription2 *desc = &pCreateInfo->pSubpasses[i]; |
| 793 |
subpass_attachment_count += |
| 794 |
desc->colorAttachmentCount + |
| 795 |
(desc->pResolveAttachments ? desc->colorAttachmentCount : 0); |
| 796 |
subpass_input_attachment_count += desc->inputAttachmentCount; |
| 797 |
subpass_preserve_attachment_count += desc->preserveAttachmentCount; |
| 798 |
} |
| 799 |
|
| 800 |
vk_multialloc_add(&ma, |
| 801 |
&subpass_attachments, |
| 802 |
__typeof__(*subpass_attachments), |
| 803 |
subpass_attachment_count); |
| 804 |
vk_multialloc_add(&ma, |
| 805 |
&subpass_input_attachments, |
| 806 |
__typeof__(*subpass_input_attachments), |
| 807 |
subpass_input_attachment_count); |
| 808 |
vk_multialloc_add(&ma, |
| 809 |
&subpass_preserve_attachments, |
| 810 |
__typeof__(*subpass_preserve_attachments), |
| 811 |
subpass_preserve_attachment_count); |
| 812 |
vk_multialloc_add(&ma, |
| 813 |
&dep_list, |
| 814 |
__typeof__(*dep_list), |
| 815 |
pCreateInfo->dependencyCount); |
| 816 |
vk_multialloc_add(&ma, |
| 817 |
&flush_on_dep, |
| 818 |
__typeof__(*flush_on_dep), |
| 819 |
pCreateInfo->dependencyCount); |
| 820 |
|
| 821 |
if (!vk_multialloc_zalloc(&ma, alloc, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)) |
| 822 |
return vk_error(device, VK_ERROR_OUT_OF_HOST_MEMORY); |
| 823 |
|
| 824 |
vk_object_base_init(&device->vk, &pass->base, VK_OBJECT_TYPE_RENDER_PASS); |
| 825 |
pass->attachment_count = pCreateInfo->attachmentCount; |
| 826 |
pass->attachments = attachments; |
| 827 |
pass->subpass_count = pCreateInfo->subpassCount; |
| 828 |
pass->subpasses = subpasses; |
| 829 |
pass->max_sample_count = 1; |
| 830 |
|
| 831 |
/* Copy attachment descriptions. */ |
| 832 |
for (uint32_t i = 0; i < pass->attachment_count; i++) { |
| 833 |
const VkAttachmentDescription2 *desc = &pCreateInfo->pAttachments[i]; |
| 834 |
struct pvr_render_pass_attachment *attachment = &pass->attachments[i]; |
| 835 |
|
| 836 |
assert(!(desc->flags & ~VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT)); |
| 837 |
|
| 838 |
attachment->load_op = desc->loadOp; |
| 839 |
attachment->store_op = desc->storeOp; |
| 840 |
|
| 841 |
attachment->aspects = vk_format_aspects(desc->format); |
| 842 |
if (attachment->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) { |
| 843 |
attachment->stencil_load_op = desc->stencilLoadOp; |
| 844 |
attachment->stencil_store_op = desc->stencilStoreOp; |
| 845 |
} |
| 846 |
|
| 847 |
attachment->vk_format = desc->format; |
| 848 |
attachment->sample_count = desc->samples; |
| 849 |
attachment->initial_layout = desc->initialLayout; |
| 850 |
attachment->index = i; |
| 851 |
|
| 852 |
/* On cores without gs_rta_support, PBE resolves might depend on writes |
| 853 |
* that occur within the deferred RTA clears that happen after the PBE has |
| 854 |
* written. Since the driver doesn't know at renderpass creation whether |
| 855 |
* RTA clears are needed, PBE resolves can't be used. |
| 856 |
*/ |
| 857 |
attachment->is_pbe_downscalable = |
| 858 |
PVR_HAS_FEATURE(dev_info, gs_rta_support) && |
| 859 |
pvr_arch_format_is_pbe_downscalable(&device->pdevice->dev_info, |
| 860 |
attachment->vk_format); |
| 861 |
|
| 862 |
if (attachment->sample_count > pass->max_sample_count) |
| 863 |
pass->max_sample_count = attachment->sample_count; |
| 864 |
} |
| 865 |
|
| 866 |
/* Count how many dependencies each subpass has. */ |
| 867 |
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) { |
| 868 |
const VkSubpassDependency2 *dep = &pCreateInfo->pDependencies[i]; |
| 869 |
|
| 870 |
if (dep->srcSubpass != VK_SUBPASS_EXTERNAL && |
| 871 |
dep->dstSubpass != VK_SUBPASS_EXTERNAL && |
| 872 |
dep->srcSubpass != dep->dstSubpass) { |
| 873 |
pass->subpasses[dep->dstSubpass].dep_count++; |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
/* Multiview is considered enabled for all subpasses when the viewMask |
| 878 |
* of them all isn't 0. Assume this now and assert later that it holds |
| 879 |
* for each subpass viewMask. |
| 880 |
*/ |
| 881 |
pass->multiview_enabled = pass->subpass_count && |
| 882 |
pCreateInfo->pSubpasses[0].viewMask; |
| 883 |
|
| 884 |
/* Assign reference pointers to lists, and fill in the attachments list, we |
| 885 |
* need to re-walk the dependencies array later to fill the per-subpass |
| 886 |
* dependencies lists in. |
| 887 |
*/ |
| 888 |
for (uint32_t i = 0; i < pass->subpass_count; i++) { |
| 889 |
const VkSubpassDescription2 *desc = &pCreateInfo->pSubpasses[i]; |
| 890 |
struct pvr_render_subpass *subpass = &pass->subpasses[i]; |
| 891 |
const VkSubpassDescriptionDepthStencilResolve *resolve_desc = |
| 892 |
vk_find_struct_const(desc->pNext, |
| 893 |
SUBPASS_DESCRIPTION_DEPTH_STENCIL_RESOLVE); |
| 894 |
|
| 895 |
subpass->pipeline_bind_point = desc->pipelineBindPoint; |
| 896 |
subpass->view_mask = desc->viewMask; |
| 897 |
|
| 898 |
assert(!pass->multiview_enabled || subpass->view_mask); |
| 899 |
|
| 900 |
if (!pass->multiview_enabled) |
| 901 |
subpass->view_mask = 1; |
| 902 |
|
| 903 |
/* From the Vulkan spec. 1.3.265 |
| 904 |
* VUID-VkSubpassDescription2-multisampledRenderToSingleSampled-06872: |
| 905 |
* |
| 906 |
* "If none of the VK_AMD_mixed_attachment_samples extension, the |
| 907 |
* VK_NV_framebuffer_mixed_samples extension, or the |
| 908 |
* multisampledRenderToSingleSampled feature are enabled, all |
| 909 |
* attachments in pDepthStencilAttachment or pColorAttachments that are |
| 910 |
* not VK_ATTACHMENT_UNUSED must have the same sample count" |
| 911 |
* |
| 912 |
*/ |
| 913 |
subpass->sample_count = VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM; |
| 914 |
|
| 915 |
if (desc->pDepthStencilAttachment) { |
| 916 |
uint32_t index = desc->pDepthStencilAttachment->attachment; |
| 917 |
|
| 918 |
if (index != VK_ATTACHMENT_UNUSED) |
| 919 |
subpass->sample_count = pass->attachments[index].sample_count; |
| 920 |
|
| 921 |
subpass->depth_stencil_attachment = index; |
| 922 |
} else { |
| 923 |
subpass->depth_stencil_attachment = VK_ATTACHMENT_UNUSED; |
| 924 |
} |
| 925 |
|
| 926 |
subpass->depth_stencil_resolve_attachment = VK_ATTACHMENT_UNUSED; |
| 927 |
|
| 928 |
if (resolve_desc) { |
| 929 |
uint32_t index = VK_ATTACHMENT_UNUSED; |
| 930 |
|
| 931 |
if (resolve_desc->pDepthStencilResolveAttachment) |
| 932 |
index = resolve_desc->pDepthStencilResolveAttachment->attachment; |
| 933 |
else if (subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) |
| 934 |
index = subpass->depth_stencil_attachment; |
| 935 |
|
| 936 |
if (index != VK_ATTACHMENT_UNUSED) { |
| 937 |
const VkFormat format = pCreateInfo->pAttachments[index].format; |
| 938 |
const bool stencil_has_store = |
| 939 |
vk_format_has_stencil(format) && |
| 940 |
(pass->attachments[index].stencil_store_op == |
| 941 |
VK_ATTACHMENT_STORE_OP_STORE); |
| 942 |
const bool depth_has_store = vk_format_has_depth(format) && |
| 943 |
(pass->attachments[index].store_op == |
| 944 |
VK_ATTACHMENT_STORE_OP_STORE); |
| 945 |
|
| 946 |
if (stencil_has_store || depth_has_store) { |
| 947 |
subpass->stencil_resolve_mode = resolve_desc->stencilResolveMode; |
| 948 |
subpass->depth_resolve_mode = resolve_desc->depthResolveMode; |
| 949 |
subpass->depth_stencil_resolve_attachment = index; |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
subpass->color_count = desc->colorAttachmentCount; |
| 955 |
if (subpass->color_count > 0) { |
| 956 |
subpass->color_attachments = subpass_attachments; |
| 957 |
subpass_attachments += subpass->color_count; |
| 958 |
|
| 959 |
for (uint32_t j = 0; j < subpass->color_count; j++) { |
| 960 |
subpass->color_attachments[j] = |
| 961 |
desc->pColorAttachments[j].attachment; |
| 962 |
|
| 963 |
if (subpass->color_attachments[j] == VK_ATTACHMENT_UNUSED) |
| 964 |
continue; |
| 965 |
|
| 966 |
if (subpass->sample_count == VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM) { |
| 967 |
uint32_t index; |
| 968 |
index = subpass->color_attachments[j]; |
| 969 |
subpass->sample_count = pass->attachments[index].sample_count; |
| 970 |
} |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
if (subpass->sample_count == VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM) |
| 975 |
subpass->sample_count = VK_SAMPLE_COUNT_1_BIT; |
| 976 |
|
| 977 |
if (desc->pResolveAttachments) { |
| 978 |
subpass->resolve_attachments = subpass_attachments; |
| 979 |
subpass_attachments += subpass->color_count; |
| 980 |
|
| 981 |
for (uint32_t j = 0; j < subpass->color_count; j++) { |
| 982 |
subpass->resolve_attachments[j] = |
| 983 |
desc->pResolveAttachments[j].attachment; |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
subpass->input_count = desc->inputAttachmentCount; |
| 988 |
if (subpass->input_count > 0) { |
| 989 |
subpass->input_attachments = subpass_input_attachments; |
| 990 |
subpass_input_attachments += subpass->input_count; |
| 991 |
|
| 992 |
for (uint32_t j = 0; j < subpass->input_count; j++) { |
| 993 |
subpass->input_attachments[j].attachment_idx = |
| 994 |
desc->pInputAttachments[j].attachment; |
| 995 |
subpass->input_attachments[j].aspect_mask = |
| 996 |
desc->pInputAttachments[j].aspectMask; |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
subpass->preserve_count = desc->preserveAttachmentCount; |
| 1001 |
if (subpass->preserve_count > 0) { |
| 1002 |
subpass->preserve_attachments = subpass_preserve_attachments; |
| 1003 |
subpass_preserve_attachments += subpass->preserve_count; |
| 1004 |
|
| 1005 |
for (uint32_t j = 0; j < subpass->preserve_count; j++) { |
| 1006 |
subpass->preserve_attachments[j].attachment_idx = |
| 1007 |
desc->pPreserveAttachments[j]; |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
/* Give the dependencies a slice of the subpass_attachments array. */ |
| 1012 |
subpass->dep_list = dep_list; |
| 1013 |
dep_list += subpass->dep_count; |
| 1014 |
subpass->flush_on_dep = flush_on_dep; |
| 1015 |
flush_on_dep += subpass->dep_count; |
| 1016 |
|
| 1017 |
/* Reset the dependencies count so we can start from 0 and index into |
| 1018 |
* the dependencies array. |
| 1019 |
*/ |
| 1020 |
subpass->dep_count = 0; |
| 1021 |
subpass->index = i; |
| 1022 |
} |
| 1023 |
|
| 1024 |
/* Compute dependencies and populate dep_list and flush_on_dep. */ |
| 1025 |
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) { |
| 1026 |
const VkSubpassDependency2 *dep = &pCreateInfo->pDependencies[i]; |
| 1027 |
|
| 1028 |
if (dep->srcSubpass != VK_SUBPASS_EXTERNAL && |
| 1029 |
dep->dstSubpass != VK_SUBPASS_EXTERNAL && |
| 1030 |
dep->srcSubpass != dep->dstSubpass) { |
| 1031 |
struct pvr_render_subpass *subpass = &pass->subpasses[dep->dstSubpass]; |
| 1032 |
const bool is_dep_fb_local = |
| 1033 |
vk_subpass_dependency_is_fb_local(dep, |
| 1034 |
dep->srcStageMask, |
| 1035 |
dep->dstStageMask); |
| 1036 |
const bool dst_has_resolve = subpass->stencil_resolve_mode || |
| 1037 |
subpass->depth_resolve_mode; |
| 1038 |
const bool src_has_resolve = |
| 1039 |
pass->subpasses[dep->srcSubpass].stencil_resolve_mode || |
| 1040 |
pass->subpasses[dep->srcSubpass].depth_resolve_mode; |
| 1041 |
|
| 1042 |
subpass->dep_list[subpass->dep_count] = dep->srcSubpass; |
| 1043 |
if (dst_has_resolve || src_has_resolve || |
| 1044 |
pvr_subpass_has_msaa_input_attachment(subpass, pCreateInfo) || |
| 1045 |
!is_dep_fb_local) { |
| 1046 |
subpass->flush_on_dep[subpass->dep_count] = true; |
| 1047 |
} |
| 1048 |
|
| 1049 |
subpass->dep_count++; |
| 1050 |
} |
| 1051 |
} |
| 1052 |
|
| 1053 |
pass->max_tilebuffer_count = |
| 1054 |
PVR_SPM_LOAD_IN_BUFFERS_COUNT(&device->pdevice->dev_info); |
| 1055 |
|
| 1056 |
result = pvr_arch_create_renderpass_hwsetup(device, |
| 1057 |
alloc, |
| 1058 |
pass, |
| 1059 |
false, |
| 1060 |
&pass->hw_setup); |
| 1061 |
if (result != VK_SUCCESS) |
| 1062 |
goto err_free_pass; |
| 1063 |
|
| 1064 |
pvr_init_subpass_isp_userpass(pass->hw_setup, pass, pass->subpasses); |
| 1065 |
|
| 1066 |
result = pvr_render_pass_load_ops_setup(device, alloc, pass); |
| 1067 |
if (result != VK_SUCCESS) |
| 1068 |
goto err_destroy_renderpass_hwsetup; |
| 1069 |
|
| 1070 |
*pRenderPass = pvr_render_pass_to_handle(pass); |
| 1071 |
|
| 1072 |
return VK_SUCCESS; |
| 1073 |
|
| 1074 |
err_destroy_renderpass_hwsetup: |
| 1075 |
pvr_arch_destroy_renderpass_hwsetup(alloc, pass->hw_setup); |
| 1076 |
|
| 1077 |
err_free_pass: |
| 1078 |
vk_object_base_finish(&pass->base); |
| 1079 |
vk_free2(&device->vk.alloc, pAllocator, pass); |
| 1080 |
|
| 1081 |
return result; |
| 1082 |
} |
| 1083 |
|
| 1084 |
void PVR_PER_ARCH(DestroyRenderPass)(VkDevice _device, |
| 1085 |
VkRenderPass _pass, |
| 1086 |
const VkAllocationCallbacks *pAllocator) |
| 1087 |
{ |
| 1088 |
VK_FROM_HANDLE(pvr_device, device, _device); |
| 1089 |
VK_FROM_HANDLE(pvr_render_pass, pass, _pass); |
| 1090 |
const VkAllocationCallbacks *allocator = pAllocator ? pAllocator |
| 1091 |
: &device->vk.alloc; |
| 1092 |
|
| 1093 |
if (!pass) |
| 1094 |
return; |
| 1095 |
|
| 1096 |
pvr_render_pass_load_ops_cleanup(device, |
| 1097 |
allocator, |
| 1098 |
pass, |
| 1099 |
pass->hw_setup->render_count); |
| 1100 |
pvr_arch_destroy_renderpass_hwsetup(allocator, pass->hw_setup); |
| 1101 |
vk_object_base_finish(&pass->base); |
| 1102 |
vk_free2(&device->vk.alloc, pAllocator, pass); |
| 1103 |
} |
| 1104 |
|
| 1105 |
void PVR_PER_ARCH(GetRenderAreaGranularity)(VkDevice _device, |
| 1106 |
VkRenderPass renderPass, |
| 1107 |
VkExtent2D *pGranularity) |
| 1108 |
{ |
| 1109 |
VK_FROM_HANDLE(pvr_device, device, _device); |
| 1110 |
const struct pvr_device_info *dev_info = &device->pdevice->dev_info; |
| 1111 |
|
| 1112 |
/* Granularity does not depend on any settings in the render pass, so return |
| 1113 |
* the tile granularity. |
| 1114 |
* |
| 1115 |
* The default value is based on the minimum value found in all existing |
| 1116 |
* cores. |
| 1117 |
*/ |
| 1118 |
pGranularity->width = PVR_GET_FEATURE_VALUE(dev_info, tile_size_x, 16); |
| 1119 |
pGranularity->height = PVR_GET_FEATURE_VALUE(dev_info, tile_size_y, 16); |
| 1120 |
} |