turnip: Save the renderpass's clear values in the cmdbuf state.

For delaying clears to subpass begin time, I needed to save these until
later.  Turns out this cleans up a good bit of threading these values all
through the command buffer setup.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20994>
This commit is contained in:
Emma Anholt 2022-10-05 14:34:29 -07:00 committed by Marge Bot
parent 139cc91697
commit 4cfd021e3f
6 changed files with 43 additions and 42 deletions

View file

@ -3110,7 +3110,6 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
struct tu_cs *cs,
VkFormat vk_format,
VkImageAspectFlags clear_mask,
const VkClearValue *value,
uint32_t a,
bool separate_ds)
{
@ -3119,6 +3118,7 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
const struct tu_image_view *iview = cmd->state.attachments[a];
const uint32_t clear_views = cmd->state.pass->attachments[a].clear_views;
const struct blit_ops *ops = &r2d_ops;
const VkClearValue *value = &cmd->state.clear_values[a];
if (cmd->state.pass->attachments[a].samples > 1)
ops = &r3d_ops;
@ -3152,8 +3152,7 @@ clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
void
tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
struct tu_cs *cs,
uint32_t a,
const VkClearValue *value)
uint32_t a)
{
const struct tu_render_pass_attachment *attachment =
&cmd->state.pass->attachments[a];
@ -3164,15 +3163,15 @@ tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
if (attachment->format == VK_FORMAT_D32_SFLOAT_S8_UINT) {
if (attachment->clear_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
clear_sysmem_attachment(cmd, cs, VK_FORMAT_D32_SFLOAT, VK_IMAGE_ASPECT_COLOR_BIT,
value, a, true);
a, true);
}
if (attachment->clear_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
clear_sysmem_attachment(cmd, cs, VK_FORMAT_S8_UINT, VK_IMAGE_ASPECT_COLOR_BIT,
value, a, true);
a, true);
}
} else {
clear_sysmem_attachment(cmd, cs, attachment->format, attachment->clear_mask,
value, a, false);
a, false);
}
/* The spec doesn't explicitly say, but presumably the initial renderpass
@ -3199,8 +3198,7 @@ tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
void
tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
struct tu_cs *cs,
uint32_t a,
const VkClearValue *value)
uint32_t a)
{
const struct tu_render_pass_attachment *attachment =
&cmd->state.pass->attachments[a];
@ -3210,7 +3208,8 @@ tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
tu_emit_clear_gmem_attachment(cmd, cs, a, 0, cmd->state.framebuffer->layers,
attachment->clear_views,
attachment->clear_mask, value);
attachment->clear_mask,
&cmd->state.clear_values[a]);
}
static void

View file

@ -34,14 +34,12 @@ tu_resolve_sysmem(struct tu_cmd_buffer *cmd,
void
tu_clear_sysmem_attachment(struct tu_cmd_buffer *cmd,
struct tu_cs *cs,
uint32_t a,
const VkClearValue *value);
uint32_t a);
void
tu_clear_gmem_attachment(struct tu_cmd_buffer *cmd,
struct tu_cs *cs,
uint32_t a,
const VkClearValue *value);
uint32_t a);
void
tu_load_gmem_attachment(struct tu_cmd_buffer *cmd,

View file

@ -1462,8 +1462,7 @@ tu_set_input_attachments(struct tu_cmd_buffer *cmd, const struct tu_subpass *sub
static void
tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
const VkClearValue *clear_values)
tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd)
{
struct tu_cs *cs = &cmd->draw_cs;
@ -1477,7 +1476,7 @@ tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
tu6_emit_blit_scissor(cmd, cs, false);
for (uint32_t i = 0; i < cmd->state.pass->attachment_count; ++i)
tu_clear_gmem_attachment(cmd, cs, i, &clear_values[i]);
tu_clear_gmem_attachment(cmd, cs, i);
tu_cond_exec_end(cs);
@ -1487,7 +1486,7 @@ tu_emit_renderpass_begin(struct tu_cmd_buffer *cmd,
tu_cond_exec_start(cs, CP_COND_EXEC_0_RENDER_MODE_SYSMEM);
for (uint32_t i = 0; i < cmd->state.pass->attachment_count; ++i)
tu_clear_sysmem_attachment(cmd, cs, i, &clear_values[i]);
tu_clear_sysmem_attachment(cmd, cs, i);
tu_cond_exec_end(cs);
@ -1806,6 +1805,7 @@ static void tu_reset_render_pass(struct tu_cmd_buffer *cmd_buffer)
cmd_buffer->state.subpass = NULL;
cmd_buffer->state.framebuffer = NULL;
cmd_buffer->state.attachments = NULL;
cmd_buffer->state.clear_values = NULL;
cmd_buffer->state.gmem_layout = TU_GMEM_LAYOUT_COUNT; /* invalid value to prevent looking up gmem offsets */
memset(&cmd_buffer->state.rp, 0, sizeof(cmd_buffer->state.rp));
@ -3641,12 +3641,13 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
cmd->state.framebuffer = fb;
cmd->state.render_area = pRenderPassBegin->renderArea;
cmd->state.attachments = (const struct tu_image_view **)
vk_alloc(&cmd->vk.pool->alloc, pass->attachment_count *
sizeof(cmd->state.attachments[0]), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!cmd->state.attachments) {
VK_MULTIALLOC(ma);
vk_multialloc_add(&ma, &cmd->state.attachments,
const struct tu_image_view *, pass->attachment_count);
vk_multialloc_add(&ma, &cmd->state.clear_values, VkClearValue,
pRenderPassBegin->clearValueCount);
if (!vk_multialloc_alloc(&ma, &cmd->vk.pool->alloc,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)) {
vk_command_buffer_set_error(&cmd->vk, VK_ERROR_OUT_OF_HOST_MEMORY);
return;
}
@ -3660,6 +3661,9 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
tu_image_view_from_handle(pAttachmentInfo->pAttachments[i]) :
cmd->state.framebuffer->attachments[i].attachment;
}
for (unsigned i = 0; i < pRenderPassBegin->clearValueCount; i++)
cmd->state.clear_values[i] = pRenderPassBegin->pClearValues[i];
tu_choose_gmem_layout(cmd);
trace_start_render_pass(&cmd->trace, &cmd->cs, cmd->state.framebuffer,
@ -3677,11 +3681,11 @@ tu_CmdBeginRenderPass2(VkCommandBuffer commandBuffer,
if (pass->subpasses[0].feedback_invalidate)
cmd->state.renderpass_cache.flush_bits |= TU_CMD_FLAG_CACHE_INVALIDATE;
tu_lrz_begin_renderpass(cmd, pRenderPassBegin->pClearValues);
tu_lrz_begin_renderpass(cmd);
cmd->trace_renderpass_start = u_trace_end_iterator(&cmd->trace);
tu_emit_renderpass_begin(cmd, pRenderPassBegin->pClearValues);
tu_emit_renderpass_begin(cmd);
tu_emit_subpass_begin(cmd);
if (pass->has_fdm)
@ -3693,7 +3697,6 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
const VkRenderingInfo *pRenderingInfo)
{
TU_FROM_HANDLE(tu_cmd_buffer, cmd, commandBuffer);
VkClearValue clear_values[2 * (MAX_RTS + 1)];
tu_setup_dynamic_render_pass(cmd, pRenderingInfo);
tu_setup_dynamic_framebuffer(cmd, pRenderingInfo);
@ -3704,16 +3707,19 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
cmd->state.render_area = pRenderingInfo->renderArea;
cmd->state.attachments = cmd->dynamic_attachments;
cmd->state.clear_values = cmd->dynamic_clear_values;
for (unsigned i = 0; i < pRenderingInfo->colorAttachmentCount; i++) {
uint32_t a = cmd->dynamic_subpass.color_attachments[i].attachment;
if (!pRenderingInfo->pColorAttachments[i].imageView)
continue;
cmd->state.clear_values[a] =
pRenderingInfo->pColorAttachments[i].clearValue;
TU_FROM_HANDLE(tu_image_view, view,
pRenderingInfo->pColorAttachments[i].imageView);
cmd->state.attachments[a] = view;
clear_values[a] = pRenderingInfo->pColorAttachments[i].clearValue;
a = cmd->dynamic_subpass.resolve_attachments[i].attachment;
if (a != VK_ATTACHMENT_UNUSED) {
@ -3734,12 +3740,12 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
TU_FROM_HANDLE(tu_image_view, view, common_info->imageView);
cmd->state.attachments[a] = view;
if (pRenderingInfo->pDepthAttachment) {
clear_values[a].depthStencil.depth =
cmd->state.clear_values[a].depthStencil.depth =
pRenderingInfo->pDepthAttachment->clearValue.depthStencil.depth;
}
if (pRenderingInfo->pStencilAttachment) {
clear_values[a].depthStencil.stencil =
cmd->state.clear_values[a].depthStencil.stencil =
pRenderingInfo->pStencilAttachment->clearValue.depthStencil.stencil;
}
@ -3788,9 +3794,9 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
cmd->state.lrz.valid = false;
} else {
if (resuming)
tu_lrz_begin_resumed_renderpass(cmd, clear_values);
tu_lrz_begin_resumed_renderpass(cmd);
else
tu_lrz_begin_renderpass(cmd, clear_values);
tu_lrz_begin_renderpass(cmd);
}
@ -3812,7 +3818,7 @@ tu_CmdBeginRendering(VkCommandBuffer commandBuffer,
}
if (!resuming) {
tu_emit_renderpass_begin(cmd, clear_values);
tu_emit_renderpass_begin(cmd);
tu_emit_subpass_begin(cmd);
}

View file

@ -448,6 +448,7 @@ struct tu_cmd_state
VkRect2D render_area;
const struct tu_image_view **attachments;
VkClearValue *clear_values;
/* State that in the dynamic case comes from VkRenderingInfo and needs to
* be saved/restored when suspending. This holds the state for the last
@ -529,6 +530,7 @@ struct tu_cmd_buffer
struct tu_subpass_attachment dynamic_color_attachments[MAX_RTS];
struct tu_subpass_attachment dynamic_resolve_attachments[MAX_RTS + 1];
const struct tu_image_view *dynamic_attachments[2 * (MAX_RTS + 1) + 1];
VkClearValue dynamic_clear_values[2 * (MAX_RTS + 1)];
struct tu_render_pass dynamic_pass;
struct tu_subpass dynamic_subpass;

View file

@ -188,8 +188,7 @@ tu_lrz_init_secondary(struct tu_cmd_buffer *cmd,
* lrz etc.
*/
void
tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
const VkClearValue *clear_values)
tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd)
{
/* Track LRZ valid state */
memset(&cmd->state.lrz, 0, sizeof(cmd->state.lrz));
@ -204,7 +203,7 @@ tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
const struct tu_render_pass_attachment *att = &cmd->state.pass->attachments[a];
tu_lrz_init_state(cmd, att, cmd->state.attachments[a]);
if (att->clear_mask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT)) {
VkClearValue clear = clear_values[a];
VkClearValue clear = cmd->state.clear_values[a];
cmd->state.lrz.depth_clear_value = clear;
cmd->state.lrz.fast_clear = cmd->state.lrz.fast_clear &&
(clear.depthStencil.depth == 0.f ||
@ -215,8 +214,7 @@ tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
}
void
tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
const VkClearValue *clear_values)
tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd)
{
const struct tu_render_pass *pass = cmd->state.pass;
@ -251,7 +249,7 @@ tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
}
/* Track LRZ valid state */
tu_lrz_begin_resumed_renderpass(cmd, clear_values);
tu_lrz_begin_resumed_renderpass(cmd);
if (!cmd->state.lrz.valid) {
tu6_emit_lrz_buffer(&cmd->cs, NULL);

View file

@ -57,12 +57,10 @@ tu_lrz_clear_depth_image(struct tu_cmd_buffer *cmd,
const VkImageSubresourceRange *pRanges);
void
tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd,
const VkClearValue *clear_values);
tu_lrz_begin_renderpass(struct tu_cmd_buffer *cmd);
void
tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd,
const VkClearValue *clear_values);
tu_lrz_begin_resumed_renderpass(struct tu_cmd_buffer *cmd);
void
tu_lrz_begin_secondary_cmdbuf(struct tu_cmd_buffer *cmd);