v3dv: move check_needs_load/store helpers to unversioned code

These helpers don't depend on the V3D version and we are going
to need them outside v3dvx_cmd_buffer.c soon.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17854>
This commit is contained in:
Iago Toral Quiroga 2022-07-22 09:41:47 +02:00 committed by Marge Bot
parent 87a9951073
commit 9dcf0dd51f
3 changed files with 115 additions and 104 deletions

View file

@ -1399,6 +1399,68 @@ cmd_buffer_emit_subpass_clears(struct v3dv_cmd_buffer *cmd_buffer)
v3dv_CmdClearAttachments(_cmd_buffer, att_count, atts, 1, &rect);
}
bool
v3dv_cmd_buffer_check_needs_load(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t first_subpass_idx,
VkAttachmentLoadOp load_op)
{
/* We call this with image->vk.aspects & aspect, so 0 means the aspect we are
* testing does not exist in the image.
*/
if (!aspect)
return false;
/* Attachment (or view) load operations apply on the first subpass that
* uses the attachment (or view), otherwise we always need to load.
*/
if (state->job->first_subpass > first_subpass_idx)
return true;
/* If the job is continuing a subpass started in another job, we always
* need to load.
*/
if (state->job->is_subpass_continue)
return true;
/* If the area is not aligned to tile boundaries, we always need to load */
if (!state->tile_aligned_render_area)
return true;
/* The attachment load operations must be LOAD */
return load_op == VK_ATTACHMENT_LOAD_OP_LOAD;
}
bool
v3dv_cmd_buffer_check_needs_store(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t last_subpass_idx,
VkAttachmentStoreOp store_op)
{
/* We call this with image->vk.aspects & aspect, so 0 means the aspect we are
* testing does not exist in the image.
*/
if (!aspect)
return false;
/* Attachment (or view) store operations only apply on the last subpass
* where the attachment (or view) is used, in other subpasses we always
* need to store.
*/
if (state->subpass_idx < last_subpass_idx)
return true;
/* Attachment store operations only apply on the last job we emit on the the
* last subpass where the attachment is used, otherwise we always need to
* store.
*/
if (!state->job->is_subpass_finish)
return true;
/* The attachment store operation must be STORE */
return store_op == VK_ATTACHMENT_STORE_OP_STORE;
}
static struct v3dv_job *
cmd_buffer_subpass_create_job(struct v3dv_cmd_buffer *cmd_buffer,
uint32_t subpass_idx,

View file

@ -1583,6 +1583,16 @@ void v3dv_cmd_buffer_add_private_obj(struct v3dv_cmd_buffer *cmd_buffer,
void v3dv_cmd_buffer_merge_barrier_state(struct v3dv_barrier_state *dst,
struct v3dv_barrier_state *src);
bool v3dv_cmd_buffer_check_needs_load(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t first_subpass_idx,
VkAttachmentLoadOp load_op);
bool v3dv_cmd_buffer_check_needs_store(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t last_subpass_idx,
VkAttachmentStoreOp store_op);
struct v3dv_event {
struct vk_object_base base;
int state;

View file

@ -151,38 +151,6 @@ cmd_buffer_render_pass_emit_load(struct v3dv_cmd_buffer *cmd_buffer,
}
}
static bool
check_needs_load(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t first_subpass_idx,
VkAttachmentLoadOp load_op)
{
/* We call this with image->vk.aspects & aspect, so 0 means the aspect we are
* testing does not exist in the image.
*/
if (!aspect)
return false;
/* Attachment (or view) load operations apply on the first subpass that
* uses the attachment (or view), otherwise we always need to load.
*/
if (state->job->first_subpass > first_subpass_idx)
return true;
/* If the job is continuing a subpass started in another job, we always
* need to load.
*/
if (state->job->is_subpass_continue)
return true;
/* If the area is not aligned to tile boundaries, we always need to load */
if (!state->tile_aligned_render_area)
return true;
/* The attachment load operations must be LOAD */
return load_op == VK_ATTACHMENT_LOAD_OP_LOAD;
}
static inline uint32_t
v3dv_zs_buffer(bool depth, bool stencil)
{
@ -237,10 +205,11 @@ cmd_buffer_render_pass_emit_loads(struct v3dv_cmd_buffer *cmd_buffer,
attachment->first_subpass :
attachment->views[layer].first_subpass;
bool needs_load = check_needs_load(state,
VK_IMAGE_ASPECT_COLOR_BIT,
first_subpass,
attachment->desc.loadOp);
bool needs_load =
v3dv_cmd_buffer_check_needs_load(state,
VK_IMAGE_ASPECT_COLOR_BIT,
first_subpass,
attachment->desc.loadOp);
if (needs_load) {
struct v3dv_image_view *iview =
state->attachments[attachment_idx].image_view;
@ -262,16 +231,16 @@ cmd_buffer_render_pass_emit_loads(struct v3dv_cmd_buffer *cmd_buffer,
ds_attachment->views[layer].first_subpass;
const bool needs_depth_load =
check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_first_subpass,
ds_attachment->desc.loadOp);
v3dv_cmd_buffer_check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_first_subpass,
ds_attachment->desc.loadOp);
const bool needs_stencil_load =
check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_first_subpass,
ds_attachment->desc.stencilLoadOp);
v3dv_cmd_buffer_check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_first_subpass,
ds_attachment->desc.stencilLoadOp);
if (needs_depth_load || needs_stencil_load) {
struct v3dv_image_view *iview =
@ -397,36 +366,6 @@ check_needs_clear(const struct v3dv_cmd_buffer_state *state,
return load_op == VK_ATTACHMENT_LOAD_OP_CLEAR;
}
static bool
check_needs_store(const struct v3dv_cmd_buffer_state *state,
VkImageAspectFlags aspect,
uint32_t last_subpass_idx,
VkAttachmentStoreOp store_op)
{
/* We call this with image->vk.aspects & aspect, so 0 means the aspect we are
* testing does not exist in the image.
*/
if (!aspect)
return false;
/* Attachment (or view) store operations only apply on the last subpass
* where the attachment (or view) is used, in other subpasses we always
* need to store.
*/
if (state->subpass_idx < last_subpass_idx)
return true;
/* Attachment store operations only apply on the last job we emit on the the
* last subpass where the attachment is used, otherwise we always need to
* store.
*/
if (!state->job->is_subpass_finish)
return true;
/* The attachment store operation must be STORE */
return store_op == VK_ATTACHMENT_STORE_OP_STORE;
}
static void
cmd_buffer_render_pass_emit_stores(struct v3dv_cmd_buffer *cmd_buffer,
struct v3dv_cl *cl,
@ -491,16 +430,16 @@ cmd_buffer_render_pass_emit_stores(struct v3dv_cmd_buffer *cmd_buffer,
ds_attachment->views[layer].last_subpass;
bool needs_depth_store =
check_needs_store(state,
aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_last_subpass,
ds_attachment->desc.storeOp);
v3dv_cmd_buffer_check_needs_store(state,
aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_last_subpass,
ds_attachment->desc.storeOp);
bool needs_stencil_store =
check_needs_store(state,
aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_last_subpass,
ds_attachment->desc.stencilStoreOp);
v3dv_cmd_buffer_check_needs_store(state,
aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_last_subpass,
ds_attachment->desc.stencilStoreOp);
/* If we have a resolve, handle it before storing the tile */
const struct v3dv_cmd_buffer_attachment_state *ds_att_state =
@ -592,10 +531,10 @@ cmd_buffer_render_pass_emit_stores(struct v3dv_cmd_buffer *cmd_buffer,
attachment->views[layer].last_subpass;
bool needs_store =
check_needs_store(state,
VK_IMAGE_ASPECT_COLOR_BIT,
last_subpass,
attachment->desc.storeOp);
v3dv_cmd_buffer_check_needs_store(state,
VK_IMAGE_ASPECT_COLOR_BIT,
last_subpass,
attachment->desc.storeOp);
/* If we need to resolve this attachment emit that store first. Notice
* that we must not request a tile buffer clear here in that case, since
@ -858,27 +797,27 @@ v3dX(cmd_buffer_emit_render_pass_rcl)(struct v3dv_cmd_buffer *cmd_buffer)
subpass->do_depth_clear_with_draw);
bool needs_depth_store =
check_needs_store(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_attachment->last_subpass,
ds_attachment->desc.storeOp) ||
subpass->resolve_depth;
v3dv_cmd_buffer_check_needs_store(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_attachment->last_subpass,
ds_attachment->desc.storeOp) ||
subpass->resolve_depth;
do_early_zs_clear = needs_depth_clear && !needs_depth_store;
if (do_early_zs_clear &&
vk_format_has_stencil(ds_attachment->desc.format)) {
bool needs_stencil_load =
check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_attachment->first_subpass,
ds_attachment->desc.stencilLoadOp);
v3dv_cmd_buffer_check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_attachment->first_subpass,
ds_attachment->desc.stencilLoadOp);
bool needs_stencil_store =
check_needs_store(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_attachment->last_subpass,
ds_attachment->desc.stencilStoreOp) ||
subpass->resolve_stencil;
v3dv_cmd_buffer_check_needs_store(state,
ds_aspects & VK_IMAGE_ASPECT_STENCIL_BIT,
ds_attachment->last_subpass,
ds_attachment->desc.stencilStoreOp) ||
subpass->resolve_stencil;
do_early_zs_clear = !needs_stencil_load && !needs_stencil_store;
}
@ -1458,10 +1397,10 @@ job_update_ez_state(struct v3dv_job *job,
vk_format_aspects(ds_attachment->desc.format);
bool needs_depth_load =
check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_attachment->first_subpass,
ds_attachment->desc.loadOp);
v3dv_cmd_buffer_check_needs_load(state,
ds_aspects & VK_IMAGE_ASPECT_DEPTH_BIT,
ds_attachment->first_subpass,
ds_attachment->desc.loadOp);
if (needs_depth_load) {
struct v3dv_framebuffer *fb = state->framebuffer;