From 568b7b46357e5bac1a8e30947822b30a26ed7aa1 Mon Sep 17 00:00:00 2001 From: Rajnesh Kanwal Date: Sun, 25 Sep 2022 19:20:22 +0100 Subject: [PATCH] pvr: Convert attachment indexes to unsigned. This commit converts attachment indexes used in renderpass to unsigned and uses VK_ATTACHMENT_UNUSED for unused attachments instead of -1. Also fixes some signed to unsigned comparisons. Fixed: CID 1515587, 1515590, 1515597, 1515604. Signed-off-by: Rajnesh Kanwal Reviewed-by: Frank Binns Reviewed-by: Karmjit Mahil Part-of: --- src/imagination/vulkan/pvr_cmd_buffer.c | 12 ++-- src/imagination/vulkan/pvr_hw_pass.c | 117 ++++++++++++++++---------------- src/imagination/vulkan/pvr_hw_pass.h | 2 +- src/imagination/vulkan/pvr_pass.c | 6 +- 4 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/imagination/vulkan/pvr_cmd_buffer.c b/src/imagination/vulkan/pvr_cmd_buffer.c index e163fbc..8843278 100644 --- a/src/imagination/vulkan/pvr_cmd_buffer.c +++ b/src/imagination/vulkan/pvr_cmd_buffer.c @@ -1022,7 +1022,7 @@ static VkResult pvr_sub_cmd_gfx_job_init(const struct pvr_device_info *dev_info, dev_info); /* Setup depth/stencil job information. */ - if (hw_render->ds_attach_idx != -1) { + if (hw_render->ds_attach_idx != VK_ATTACHMENT_UNUSED) { struct pvr_image_view *iview = render_pass_info->attachments[hw_render->ds_attach_idx]; const struct pvr_image *image = vk_to_pvr_image(iview->vk.image); @@ -1087,7 +1087,7 @@ static VkResult pvr_sub_cmd_gfx_job_init(const struct pvr_device_info *dev_info, job->stencil_addr = PVR_DEV_ADDR_INVALID; } - if (hw_render->ds_attach_idx != -1) { + if (hw_render->ds_attach_idx != VK_ATTACHMENT_UNUSED) { struct pvr_image_view *iview = render_pass_info->attachments[hw_render->ds_attach_idx]; const struct pvr_image *image = vk_to_pvr_image(iview->vk.image); @@ -2288,7 +2288,7 @@ static void pvr_perform_start_of_render_attachment_clear( bool is_stencil; bool is_depth; - assert(hw_render->ds_attach_idx != -1); + assert(hw_render->ds_attach_idx != VK_ATTACHMENT_UNUSED); assert(index == 0); view_idx = hw_render->ds_attach_idx; @@ -2372,7 +2372,7 @@ pvr_perform_start_of_render_clears(struct pvr_cmd_buffer *cmd_buffer) info->process_empty_tiles = false; } - if (hw_render->ds_attach_idx != -1) { + if (hw_render->ds_attach_idx != VK_ATTACHMENT_UNUSED) { uint32_t ds_index_list = 0; pvr_perform_start_of_render_attachment_clear(cmd_buffer, @@ -2393,7 +2393,7 @@ static void pvr_stash_depth_format(struct pvr_cmd_buffer_state *state, const struct pvr_renderpass_hwsetup_render *hw_render = &pass->hw_setup->renders[sub_cmd->hw_render_idx]; - if (hw_render->ds_attach_idx != -1) { + if (hw_render->ds_attach_idx != VK_ATTACHMENT_UNUSED) { struct pvr_image_view **iviews = state->render_pass_info.attachments; state->depth_format = iviews[hw_render->ds_attach_idx]->vk.format; @@ -5849,7 +5849,7 @@ static bool pvr_is_stencil_store_load_needed( vk_dst_stage_mask & VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT) return false; - if (hw_render->ds_attach_idx == -1) + if (hw_render->ds_attach_idx == VK_ATTACHMENT_UNUSED) return false; for (uint32_t i = 0; i < memory_barrier_count; i++) { diff --git a/src/imagination/vulkan/pvr_hw_pass.c b/src/imagination/vulkan/pvr_hw_pass.c index c82dc78..347c22a 100644 --- a/src/imagination/vulkan/pvr_hw_pass.c +++ b/src/imagination/vulkan/pvr_hw_pass.c @@ -115,7 +115,8 @@ struct pvr_render_int_attachment { struct usc_mrt_resource resource; /* Index of the subpass in the current render where the attachment is first - * used. -1 if the attachment isn't used in the current render. + * used. VK_ATTACHMENT_UNUSED if the attachment isn't used in the current + * render. */ int32_t first_use; @@ -248,7 +249,7 @@ struct pvr_render_int_subpass_dsts { struct pvr_render_subpass_depth_params { bool existing_ds_is_input; bool incoming_ds_is_input; - int32_t existing_ds_attach; + uint32_t existing_ds_attach; }; struct pvr_renderpass_storage_firstuse_buffer { @@ -540,15 +541,15 @@ pvr_subpass_setup_render_init(struct pvr_renderpass_context *ctx) hw_subpass->stencil_clear)) { struct pvr_render_int_attachment *int_ds_attach; - assert(*input_subpass->depth_stencil_attachment >= 0U); + assert(*input_subpass->depth_stencil_attachment != + VK_ATTACHMENT_UNUSED); assert(*input_subpass->depth_stencil_attachment < - (int32_t)ctx->pass->attachment_count); + ctx->pass->attachment_count); int_ds_attach = &ctx->int_attach[*input_subpass->depth_stencil_attachment]; - assert(hw_render->ds_attach_idx == -1 || - hw_render->ds_attach_idx == - (int32_t)int_ds_attach->attachment->index); + assert(hw_render->ds_attach_idx == VK_ATTACHMENT_UNUSED || + hw_render->ds_attach_idx == int_ds_attach->attachment->index); hw_render->ds_attach_idx = int_ds_attach->attachment->index; if (hw_subpass->depth_initop == VK_ATTACHMENT_LOAD_OP_CLEAR) @@ -560,15 +561,15 @@ pvr_subpass_setup_render_init(struct pvr_renderpass_context *ctx) } } - if (*input_subpass->depth_stencil_attachment != -1) + if (*input_subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) first_ds = false; for (uint32_t j = 0U; j < input_subpass->color_count; j++) { struct usc_mrt_resource *mrt = &hw_subpass->setup.mrt_resources[j]; - const int32_t attach_idx = input_subpass->color_attachments[j]; + const uint32_t attach_idx = input_subpass->color_attachments[j]; struct pvr_render_int_attachment *int_attach; - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -831,10 +832,10 @@ pvr_copy_storage_details(struct pvr_renderpass_context *ctx, } for (uint32_t i = 0U; i < input_subpass->color_count; i++) { - const int32_t attach_idx = input_subpass->color_attachments[i]; + const uint32_t attach_idx = input_subpass->color_attachments[i]; struct pvr_render_int_attachment *int_attach; - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -861,7 +862,7 @@ pvr_copy_storage_details(struct pvr_renderpass_context *ctx, const uint32_t attach_idx = input_subpass->input_attachments[i]; struct pvr_render_int_attachment *int_attach; - if ((int32_t)attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -949,7 +950,7 @@ pvr_copy_z_replicate_details(struct pvr_renderpass_context *ctx, const uint32_t attach_idx = input_subpass->input_attachments[i]; struct pvr_render_int_attachment *int_attach; - if ((int32_t)attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -1097,9 +1098,9 @@ static VkResult pvr_close_render(const struct pvr_device *device, hw_render->stencil_store = true; if (hw_render->depth_store || hw_render->stencil_store) { - assert(hw_render->ds_attach_idx == -1 || + assert(hw_render->ds_attach_idx == VK_ATTACHMENT_UNUSED || hw_render->ds_attach_idx == - (int32_t)ctx->int_ds_attach->attachment->index); + ctx->int_ds_attach->attachment->index); hw_render->ds_attach_idx = ctx->int_ds_attach->attachment->index; /* Allocate memory for the attachment. */ @@ -1170,19 +1171,20 @@ static VkResult pvr_close_render(const struct pvr_device *device, struct pvr_render_subpass *input_subpass = subpass->input_subpass; for (uint32_t j = 0U; j < input_subpass->color_count; j++) { - const int32_t resolve_output = + const uint32_t resolve_output = input_subpass->resolve_attachments ? input_subpass->resolve_attachments[j] - : -1; + : VK_ATTACHMENT_UNUSED; struct pvr_render_int_attachment *color_attach; - if (input_subpass->color_attachments[j] == -1) + if (input_subpass->color_attachments[j] == VK_ATTACHMENT_UNUSED) continue; color_attach = &ctx->int_attach[input_subpass->color_attachments[j]]; if (list_is_linked(&color_attach->link)) { - uint32_t rem_count = resolve_output == -1 ? 0U : 1U; + uint32_t rem_count = resolve_output == VK_ATTACHMENT_UNUSED ? 0U + : 1U; /* If a color attachment is resolved it will have an extra * remaining usage. @@ -1194,7 +1196,7 @@ static VkResult pvr_close_render(const struct pvr_device *device, } } - if (resolve_output != -1) { + if (resolve_output != VK_ATTACHMENT_UNUSED) { struct pvr_render_int_attachment *int_resolve_attach = &ctx->int_attach[resolve_output]; @@ -1223,18 +1225,18 @@ static VkResult pvr_close_render(const struct pvr_device *device, struct pvr_render_subpass *input_subpass = subpass->input_subpass; for (uint32_t j = 0U; j < input_subpass->color_count; j++) { - const int32_t resolve_output = + const uint32_t resolve_output = input_subpass->resolve_attachments ? input_subpass->resolve_attachments[j] - : -1; + : VK_ATTACHMENT_UNUSED; struct pvr_render_int_attachment *color_attach; - if (input_subpass->color_attachments[j] == -1) + if (input_subpass->color_attachments[j] == VK_ATTACHMENT_UNUSED) continue; color_attach = &ctx->int_attach[input_subpass->color_attachments[j]]; - if (resolve_output != -1) { + if (resolve_output != VK_ATTACHMENT_UNUSED) { struct pvr_render_int_attachment *resolve_src = &ctx->int_attach[input_subpass->color_attachments[j]]; struct pvr_render_int_attachment *resolve_dst = @@ -1281,7 +1283,7 @@ static VkResult pvr_close_render(const struct pvr_device *device, pvr_mark_surface_alloc(ctx, color_attach); - assert(color_attach->mrt_idx >= 0U); + assert(color_attach->mrt_idx >= 0); assert(color_attach->mrt_idx < (int32_t)hw_render->eot_setup.num_render_targets); @@ -1337,13 +1339,14 @@ static VkResult pvr_close_render(const struct pvr_device *device, return VK_SUCCESS; } -static bool pvr_is_input(struct pvr_render_subpass *subpass, int32_t attach_idx) +static bool pvr_is_input(struct pvr_render_subpass *subpass, + uint32_t attach_idx) { - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) return false; for (uint32_t i = 0U; i < subpass->input_count; i++) { - if (subpass->input_attachments[i] == (uint32_t)attach_idx) + if (subpass->input_attachments[i] == attach_idx) return true; } @@ -1477,7 +1480,7 @@ pvr_enable_z_replicate(struct pvr_renderpass_context *ctx, break; } } - assert(first_use >= 0U); + assert(first_use >= 0); /* For all subpasses from the first write. */ for (uint32_t i = first_use; i < hw_render->subpass_count; i++) { @@ -1526,7 +1529,7 @@ pvr_enable_z_replicate(struct pvr_renderpass_context *ctx, } static bool pvr_is_pending_resolve_dest(struct pvr_renderpass_context *ctx, - int32_t attach_idx) + uint32_t attach_idx) { struct pvr_render_int_attachment *int_attach = &ctx->int_attach[attach_idx]; @@ -1536,7 +1539,7 @@ static bool pvr_is_pending_resolve_dest(struct pvr_renderpass_context *ctx, } static bool pvr_is_pending_resolve_src(struct pvr_renderpass_context *ctx, - int32_t attach_idx) + uint32_t attach_idx) { struct pvr_render_int_attachment *int_attach = &ctx->int_attach[attach_idx]; @@ -1557,12 +1560,12 @@ static bool pvr_exceeds_pbe_registers(struct pvr_renderpass_context *ctx, ctx->subpasses[i].input_subpass; for (uint32_t j = 0U; j < input_subpass->color_count; j++) { - const int32_t global_color_attach = + const uint32_t global_color_attach = input_subpass->color_attachments[j]; struct pvr_render_int_attachment *int_attach; bool found = false; - if (global_color_attach == -1) + if (global_color_attach == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[global_color_attach]; @@ -1588,11 +1591,11 @@ static bool pvr_exceeds_pbe_registers(struct pvr_renderpass_context *ctx, * would exceed the limit. */ for (uint32_t i = 0U; i < subpass->color_count; i++) { - const int32_t global_color_attach = subpass->color_attachments[i]; + const uint32_t global_color_attach = subpass->color_attachments[i]; struct pvr_render_int_attachment *int_attach; bool found = false; - if (global_color_attach == -1) + if (global_color_attach == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[global_color_attach]; @@ -1770,10 +1773,10 @@ pvr_is_subpass_space_available(const struct pvr_device_info *dev_info, sp_dsts->incoming_zrep.type = USC_MRT_RESOURCE_TYPE_INVALID; for (uint32_t i = 0U; i < subpass->color_count; i++) { - const int32_t attach_idx = subpass->color_attachments[i]; + const uint32_t attach_idx = subpass->color_attachments[i]; struct pvr_render_int_attachment *int_attach; - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -1904,21 +1907,21 @@ pvr_can_combine_with_render(const struct pvr_device_info *dev_info, */ for (uint32_t i = 0U; i < subpass->input_count; i++) { const uint32_t attach_idx = subpass->input_attachments[i]; - if ((int32_t)attach_idx != -1 && + if (attach_idx != VK_ATTACHMENT_UNUSED && pvr_is_pending_resolve_dest(ctx, attach_idx)) { return false; } } for (uint32_t i = 0U; i < subpass->color_count; i++) { - if (subpass->color_attachments[i] != -1 && + if (subpass->color_attachments[i] != VK_ATTACHMENT_UNUSED && (pvr_is_pending_resolve_dest(ctx, subpass->color_attachments[i]) || pvr_is_pending_resolve_src(ctx, subpass->color_attachments[i]))) { return false; } if (subpass->resolve_attachments && - subpass->resolve_attachments[i] != -1 && + subpass->resolve_attachments[i] != VK_ATTACHMENT_UNUSED && pvr_is_pending_resolve_dest(ctx, subpass->resolve_attachments[i])) { return false; } @@ -1965,7 +1968,7 @@ pvr_merge_subpass(const struct pvr_device *device, bool ret; /* Depth attachment for the incoming subpass. */ - if (*input_subpass->depth_stencil_attachment != -1) { + if (*input_subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) { int_ds_attach = &ctx->int_attach[*input_subpass->depth_stencil_attachment]; } else { @@ -1976,7 +1979,7 @@ pvr_merge_subpass(const struct pvr_device *device, if (ctx->int_ds_attach) sp_depth.existing_ds_attach = ctx->int_ds_attach - ctx->int_attach; else - sp_depth.existing_ds_attach = -1; + sp_depth.existing_ds_attach = VK_ATTACHMENT_UNUSED; /* Is the incoming depth attachment used as an input to the incoming subpass? */ @@ -2005,7 +2008,7 @@ pvr_merge_subpass(const struct pvr_device *device, goto end_merge_subpass; sp_depth.existing_ds_is_input = false; - sp_depth.existing_ds_attach = -1; + sp_depth.existing_ds_attach = VK_ATTACHMENT_UNUSED; /* Allocate again in a new render. */ result = pvr_is_subpass_space_available(&device->pdevice->dev_info, @@ -2037,7 +2040,7 @@ pvr_merge_subpass(const struct pvr_device *device, ctx->hw_render = &hw_setup->renders[hw_setup->render_count]; memset(ctx->hw_render, 0U, sizeof(*hw_render)); - ctx->hw_render->ds_attach_idx = -1; + ctx->hw_render->ds_attach_idx = VK_ATTACHMENT_UNUSED; hw_setup->render_count++; ctx->hw_render->depth_init = VK_ATTACHMENT_LOAD_OP_DONT_CARE; ctx->hw_render->stencil_init = VK_ATTACHMENT_LOAD_OP_DONT_CARE; @@ -2125,7 +2128,7 @@ pvr_merge_subpass(const struct pvr_device *device, pvr_mark_surface_alloc(ctx, int_ds_attach); if (setup_render_ds) { - assert(hw_render->ds_attach_idx == -1); + assert(hw_render->ds_attach_idx == VK_ATTACHMENT_UNUSED); hw_render->ds_attach_idx = int_ds_attach->attachment->index; } @@ -2144,10 +2147,10 @@ pvr_merge_subpass(const struct pvr_device *device, } for (uint32_t i = 0U; i < input_subpass->color_count; i++) { - const int32_t attach_idx = input_subpass->color_attachments[i]; + const uint32_t attach_idx = input_subpass->color_attachments[i]; struct pvr_render_int_attachment *int_attach; - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -2172,11 +2175,11 @@ pvr_merge_subpass(const struct pvr_device *device, /* Copy the destinations allocated for the color attachments. */ for (uint32_t i = 0U; i < input_subpass->color_count; i++) { - const int32_t attach_idx = input_subpass->color_attachments[i]; + const uint32_t attach_idx = input_subpass->color_attachments[i]; struct pvr_render_int_attachment *int_attach; struct pvr_renderpass_resource *attach_dst; - if (attach_idx == -1) + if (attach_idx == VK_ATTACHMENT_UNUSED) continue; int_attach = &ctx->int_attach[attach_idx]; @@ -2269,9 +2272,9 @@ pvr_dereference_color_output_list(struct pvr_renderpass_context *ctx, struct pvr_render_subpass *subpass) { for (uint32_t i = 0U; i < subpass->color_count; i++) { - const int32_t attach_idx = subpass->color_attachments[i]; + const uint32_t attach_idx = subpass->color_attachments[i]; - if (attach_idx != -1) + if (attach_idx != VK_ATTACHMENT_UNUSED) pvr_dereference_surface(ctx, attach_idx, subpass_num); } } @@ -2282,7 +2285,7 @@ static void pvr_dereference_surface_list(struct pvr_renderpass_context *ctx, uint32_t count) { for (uint32_t i = 0U; i < count; i++) { - if ((int32_t)attachments[i] != -1) + if (attachments[i] != VK_ATTACHMENT_UNUSED) pvr_dereference_surface(ctx, attachments[i], subpass_num); } } @@ -2319,7 +2322,7 @@ static VkResult pvr_schedule_subpass(const struct pvr_device *device, subpass_num, subpass->input_attachments, subpass->input_count); - if (*subpass->depth_stencil_attachment != -1) { + if (*subpass->depth_stencil_attachment != VK_ATTACHMENT_UNUSED) { struct pvr_render_int_attachment *int_depth_attach = &ctx->int_attach[*subpass->depth_stencil_attachment]; @@ -2356,7 +2359,7 @@ static VkResult pvr_schedule_subpass(const struct pvr_device *device, if (!subpass->resolve_attachments) break; - if (subpass->resolve_attachments[i] == -1) + if (subpass->resolve_attachments[i] == VK_ATTACHMENT_UNUSED) continue; assert(subpass->color_attachments[i] < @@ -2422,11 +2425,11 @@ pvr_count_uses_in_color_output_list(struct pvr_render_subpass *subpass, uint32_t count = 0U; for (uint32_t i = 0U; i < subpass->color_count; i++) { - if (subpass->color_attachments[i] == (int32_t)attach_idx) { + if (subpass->color_attachments[i] == attach_idx) { count++; if (subpass->resolve_attachments && - subpass->resolve_attachments[i] != -1) + subpass->resolve_attachments[i] != VK_ATTACHMENT_UNUSED) count++; } } diff --git a/src/imagination/vulkan/pvr_hw_pass.h b/src/imagination/vulkan/pvr_hw_pass.h index 40c8006..090444f 100644 --- a/src/imagination/vulkan/pvr_hw_pass.h +++ b/src/imagination/vulkan/pvr_hw_pass.h @@ -222,7 +222,7 @@ struct pvr_renderpass_hwsetup_render { /* Index of the attachment to use for depth/stencil load/store in this * render. */ - int32_t ds_attach_idx; + uint32_t ds_attach_idx; /* Operation on the on-chip depth at the start of the render. * Either load from 'ds_attach_idx', clear using 'ds_attach_idx' or leave diff --git a/src/imagination/vulkan/pvr_pass.c b/src/imagination/vulkan/pvr_pass.c index 6789f70..4ab9c7d 100644 --- a/src/imagination/vulkan/pvr_pass.c +++ b/src/imagination/vulkan/pvr_pass.c @@ -107,9 +107,9 @@ static bool pvr_is_subpass_initops_flush_needed( color_attachment_mask = 0; for (uint32_t i = 0; i < subpass->color_count; i++) { - const int32_t color_idx = subpass->color_attachments[i]; + const uint32_t color_idx = subpass->color_attachments[i]; - if (color_idx != -1) + if (color_idx != VK_ATTACHMENT_UNUSED) color_attachment_mask |= (1 << pass->attachments[color_idx].index); } @@ -371,7 +371,7 @@ pvr_is_load_op_needed(const struct pvr_render_pass *pass, } for (uint32_t i = 0; i < subpass->color_count; i++) { - if (subpass->color_attachments[i] == -1) + if (subpass->color_attachments[i] == VK_ATTACHMENT_UNUSED) continue; if (hw_subpass->color_initops[i] == VK_ATTACHMENT_LOAD_OP_LOAD || -- 2.7.4