Module: Mesa Branch: main Commit: 5da4f5fe8d32722958d28910e09e8321cd709b9a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5da4f5fe8d32722958d28910e09e8321cd709b9a
Author: Iago Toral Quiroga <[email protected]> Date: Fri Jul 22 09:45:10 2022 +0200 v3dv: track if a job is compatible with double-buffer mode MSAA is not compatible with double-buffer mode. Also, jobs that emit tile loads or that don't have any stores can't take advantage of double-buffer mode. Reviewed-by: Alejandro PiƱeiro <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17854> --- src/broadcom/vulkan/v3dv_cmd_buffer.c | 108 ++++++++++++++++++++++++++++++++++ src/broadcom/vulkan/v3dv_private.h | 6 ++ 2 files changed, 114 insertions(+) diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index d2214d436a0..4d6ef4d5df5 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -1461,6 +1461,111 @@ v3dv_cmd_buffer_check_needs_store(const struct v3dv_cmd_buffer_state *state, return store_op == VK_ATTACHMENT_STORE_OP_STORE; } +static void +cmd_buffer_subpass_check_double_buffer_mode(struct v3dv_cmd_buffer *cmd_buffer, + bool msaa) +{ + const struct v3dv_cmd_buffer_state *state = &cmd_buffer->state; + struct v3dv_job *job = cmd_buffer->state.job; + assert(job); + + job->can_use_double_buffer = false; + + /* Double-buffer can only be used if requested via V3D_DEBUG */ + if (!unlikely(V3D_DEBUG & V3D_DEBUG_DOUBLE_BUFFER)) + return; + + /* Double-buffer cannot be enabled for MSAA jobs */ + if (msaa) + return; + + const struct v3dv_render_pass *pass = state->pass; + const struct v3dv_subpass *subpass = &pass->subpasses[state->subpass_idx]; + + /* FIXME: For now we discard multiview jobs (which have an implicit geometry + * shader) for this optimization. If we want to enable this with multiview + * we would need to check if any view (layer) in any attachment used by the + * job has loads and/or stores as we do below for regular attachments. Also, + * we would want to have a heuristic that doesn't automatically disable + * double-buffer in the presence of geometry shaders. + */ + if (state->pass->multiview_enabled) + return; + + /* Tile loads are serialized against stores, in which case we don't get + * any benefits from enabling double-buffer and would just pay the price + * of a smaller tile size instead. Similarly, we only benefit from + * double-buffer if we have tile stores, as the point of this mode is + * to execute rendering of a new tile while we store the previous one to + * hide latency on the tile store operation. + */ + bool has_stores = false; + for (uint32_t i = 0; i < subpass->color_count; i++) { + uint32_t attachment_idx = subpass->color_attachments[i].attachment; + if (attachment_idx == VK_ATTACHMENT_UNUSED) + continue; + + const struct v3dv_render_pass_attachment *attachment = + &state->pass->attachments[attachment_idx]; + + /* FIXME: This will check 'tile_aligned_render_area' but that was + * computed with a tile size without double-buffer. That is okay + * because if the larger tile size is aligned then we know the smaller + * tile size for double-buffer will be as well. However, we might + * still benefit from doing this check with the smaller tile size + * because it can happen that the smaller size is aligned and the + * larger size is not. + */ + if (v3dv_cmd_buffer_check_needs_load(state, + VK_IMAGE_ASPECT_COLOR_BIT, + attachment->first_subpass, + attachment->desc.loadOp)) { + return; + } + + if (v3dv_cmd_buffer_check_needs_store(state, + VK_IMAGE_ASPECT_COLOR_BIT, + attachment->last_subpass, + attachment->desc.storeOp)) { + has_stores = true; + } + } + + if (subpass->ds_attachment.attachment != VK_ATTACHMENT_UNUSED) { + uint32_t ds_attachment_idx = subpass->ds_attachment.attachment; + const struct v3dv_render_pass_attachment *ds_attachment = + &state->pass->attachments[ds_attachment_idx]; + + const VkImageAspectFlags ds_aspects = + vk_format_aspects(ds_attachment->desc.format); + + if (v3dv_cmd_buffer_check_needs_load(state, + ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT, + ds_attachment->first_subpass, + ds_attachment->desc.loadOp)) { + return; + } + + if (v3dv_cmd_buffer_check_needs_load(state, + ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT, + ds_attachment->first_subpass, + ds_attachment->desc.stencilLoadOp)) { + return; + } + + has_stores |= v3dv_cmd_buffer_check_needs_store(state, + ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT, + ds_attachment->last_subpass, + ds_attachment->desc.storeOp); + has_stores |= v3dv_cmd_buffer_check_needs_store(state, + ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT, + ds_attachment->last_subpass, + ds_attachment->desc.stencilStoreOp); + } + + job->can_use_double_buffer = has_stores; +} + static struct v3dv_job * cmd_buffer_subpass_create_job(struct v3dv_cmd_buffer *cmd_buffer, uint32_t subpass_idx, @@ -1548,6 +1653,9 @@ v3dv_cmd_buffer_subpass_start(struct v3dv_cmd_buffer *cmd_buffer, */ cmd_buffer_update_tile_alignment(cmd_buffer); + /* Decide if we can use double-buffer for this subpass job */ + cmd_buffer_subpass_check_double_buffer_mode(cmd_buffer, job->frame_tiling.msaa); + cmd_buffer_update_attachment_resolve_state(cmd_buffer); /* If we can't use TLB clears then we need to emit draw clears for any diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 61fa11f0785..1ad0731ce71 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -1080,6 +1080,12 @@ struct v3dv_job { */ bool uses_buffer_device_address; + /* True if we have not identified anything that would be incompatible + * with double-buffer (like MSAA) or that would make double-buffer mode + * not efficient (like tile loads or not having any stores). + */ + bool can_use_double_buffer; + enum v3dv_job_type type; struct v3dv_device *device;
