Mesa (main): anv/pass: rely on precomputed dynamic rendering pass/subpass more
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Feb 2 17:39:54 UTC 2022
Module: Mesa
Branch: main
Commit: fc837e9f8bf03daf8b373084a2ee8b320b072b12
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=fc837e9f8bf03daf8b373084a2ee8b320b072b12
Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date: Tue Feb 1 21:57:19 2022 +0200
anv/pass: rely on precomputed dynamic rendering pass/subpass more
For instance, the current code in genX_cmd_buffer.c assumes that the
depth/stencil attachments & resolves will be at the end of all
attachments, but that won't be the case anymore with fragment rate
shading.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Ivan Briano <ivan.briano at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13739>
---
src/intel/vulkan/anv_pass.c | 98 +++++++++++++++++++-------------------
src/intel/vulkan/genX_cmd_buffer.c | 92 +++++++++++++++++------------------
2 files changed, 94 insertions(+), 96 deletions(-)
diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c
index 19a839850c0..d823760f99a 100644
--- a/src/intel/vulkan/anv_pass.c
+++ b/src/intel/vulkan/anv_pass.c
@@ -499,7 +499,7 @@ anv_dynamic_pass_init_full(struct anv_dynamic_render_pass *dyn_render_pass,
{
uint32_t att_count;
uint32_t color_count = 0, ds_count = 0;
- uint32_t color_resolve_idx, ds_idx;
+ uint32_t ds_idx;
bool has_color_resolve, has_ds_resolve;
struct anv_render_pass *pass = &dyn_render_pass->pass;
@@ -510,8 +510,6 @@ anv_dynamic_pass_init_full(struct anv_dynamic_render_pass *dyn_render_pass,
* trigger depth/stencil resolve, so clear things to make sure we don't
* leave stale values.
*/
- memset(pass, 0, sizeof(*pass));
- memset(subpass, 0, sizeof(*subpass));
dyn_render_pass->suspending = info->flags & VK_RENDERING_SUSPENDING_BIT_KHR;
dyn_render_pass->resuming = info->flags & VK_RENDERING_RESUMING_BIT_KHR;
@@ -541,60 +539,59 @@ anv_dynamic_pass_init_full(struct anv_dynamic_render_pass *dyn_render_pass,
ds_count *= 2;
att_count = color_count + ds_count;
- color_resolve_idx = info->colorAttachmentCount;
ds_idx = color_count;
- pass->subpass_count = 1;
- pass->attachments = dyn_render_pass->rp_attachments;
- pass->attachment_count = att_count;
+ /* Setup pass & subpass */
+ *pass = (struct anv_render_pass) {
+ .subpass_count = 1,
+ .attachments = dyn_render_pass->rp_attachments,
+ .attachment_count = att_count,
+ };
struct anv_subpass_attachment *subpass_attachments =
dyn_render_pass->sp_attachments;
- subpass->attachment_count = att_count;
- subpass->attachments = subpass_attachments;
- subpass->color_count = info->colorAttachmentCount;
- subpass->color_attachments = subpass_attachments;
- subpass->has_color_resolve = has_color_resolve;
- subpass->resolve_attachments =
- subpass_attachments + subpass->color_count;
- /* The depth field presence is used to trigger resolve/shadow-buffer-copy,
- * only set them if needed.
- */
- if (ds_count > 0) {
- subpass->depth_stencil_attachment = &subpass_attachments[ds_idx];
- if (has_ds_resolve)
- subpass->ds_resolve_attachment = &subpass_attachments[ds_idx + 1];
- }
- subpass->view_mask = info->viewMask;
- for (uint32_t att = 0; att < info->colorAttachmentCount; att++) {
- if (info->pColorAttachments[att].imageView == VK_NULL_HANDLE) {
- subpass->color_attachments[att].attachment = VK_ATTACHMENT_UNUSED;
- continue;
- }
-
- ANV_FROM_HANDLE(anv_image_view, iview, info->pColorAttachments[att].imageView);
+ *subpass = (struct anv_subpass) {
+ .attachment_count = att_count,
+ .attachments = subpass_attachments,
+ .color_count = info->colorAttachmentCount,
+ .color_attachments = subpass_attachments,
+ .has_color_resolve = has_color_resolve,
+ .resolve_attachments = subpass_attachments + info->colorAttachmentCount,
+ .view_mask = info->viewMask,
+ };
- pass->attachments[att] = (struct anv_render_pass_attachment) {
- .format = iview->vk.format,
- .samples = iview->vk.image->samples,
- };
+ for (uint32_t att = 0; att < info->colorAttachmentCount; att++) {
+ if (info->pColorAttachments[att].imageView != VK_NULL_HANDLE) {
+ ANV_FROM_HANDLE(anv_image_view, iview, info->pColorAttachments[att].imageView);
- subpass->color_attachments[att] = (struct anv_subpass_attachment) {
- .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
- .attachment = att,
- };
+ pass->attachments[att] = (struct anv_render_pass_attachment) {
+ .format = iview->vk.format,
+ .samples = iview->vk.image->samples,
+ .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ };
+ subpass->color_attachments[att] = (struct anv_subpass_attachment) {
+ .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ .attachment = att,
+ };
+ } else {
+ subpass->color_attachments[att] = (struct anv_subpass_attachment) {
+ .usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+ .attachment = VK_ATTACHMENT_UNUSED,
+ };
+ }
if (has_color_resolve) {
- if (info->pColorAttachments[att].resolveMode == VK_RESOLVE_MODE_NONE) {
- subpass->resolve_attachments[att].attachment = VK_ATTACHMENT_UNUSED;
- continue;
+ if (info->pColorAttachments[att].resolveMode != VK_RESOLVE_MODE_NONE) {
+ subpass->resolve_attachments[att] = (struct anv_subpass_attachment) {
+ .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
+ .attachment = info->colorAttachmentCount + att,
+ };
+ } else {
+ subpass->resolve_attachments[att] = (struct anv_subpass_attachment) {
+ .attachment = VK_ATTACHMENT_UNUSED,
+ };
}
-
- subpass->resolve_attachments[att] = (struct anv_subpass_attachment) {
- .usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
- .attachment = att + color_resolve_idx,
- };
}
}
@@ -611,23 +608,24 @@ anv_dynamic_pass_init_full(struct anv_dynamic_render_pass *dyn_render_pass,
pass->attachments[ds_idx] = (struct anv_render_pass_attachment) {
.format = iview->vk.format,
.samples = iview->vk.image->samples,
+ .usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
};
+ subpass->depth_stencil_attachment = &subpass_attachments[ds_idx];
*subpass->depth_stencil_attachment = (struct anv_subpass_attachment) {
.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
.attachment = ds_idx,
};
- if (d_att && d_att->imageView) {
+ if (d_att && d_att->imageView)
depth_resolve_mode = d_att->resolveMode;
- }
- if (s_att && s_att->imageView) {
+ if (s_att && s_att->imageView)
stencil_resolve_mode = s_att->resolveMode;
- }
if (has_ds_resolve) {
uint32_t ds_res_idx = ds_idx + 1;
+ subpass->ds_resolve_attachment = &subpass_attachments[ds_res_idx];
*subpass->ds_resolve_attachment = (struct anv_subpass_attachment) {
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
.attachment = ds_res_idx,
diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c
index 93ba8d17fa8..5b454d9ecc9 100644
--- a/src/intel/vulkan/genX_cmd_buffer.c
+++ b/src/intel/vulkan/genX_cmd_buffer.c
@@ -6990,12 +6990,14 @@ genX(cmd_buffer_setup_attachments_dynrender)(struct anv_cmd_buffer *cmd_buffer,
const VkRenderingInfoKHR *info)
{
struct anv_cmd_state *state = &cmd_buffer->state;
- uint32_t att_count = state->pass->attachment_count;
+ struct anv_render_pass *pass = state->pass;
+ struct anv_subpass *subpass = state->subpass;
bool suspending = info->flags & VK_RENDERING_SUSPENDING_BIT_KHR;
bool resuming = info->flags & VK_RENDERING_RESUMING_BIT_KHR;
VkResult result;
- result = cmd_buffer_alloc_state_attachments(cmd_buffer, att_count);
+ result = cmd_buffer_alloc_state_attachments(cmd_buffer,
+ pass->attachment_count);
if (result != VK_SUCCESS)
return result;
@@ -7056,77 +7058,75 @@ genX(cmd_buffer_setup_attachments_dynrender)(struct anv_cmd_buffer *cmd_buffer,
}
}
- const VkRenderingAttachmentInfoKHR *d_att = info->pDepthAttachment;
- const VkRenderingAttachmentInfoKHR *s_att = info->pStencilAttachment;
- const VkRenderingAttachmentInfoKHR *d_or_s_att = d_att ? d_att : s_att;
- if (d_or_s_att && d_or_s_att->imageView) {
- uint32_t ds_idx = att_count - 1;
-
- if (!suspending && d_or_s_att->resolveImageView) {
- struct anv_attachment_state *resolve_att =
- &state->attachments[ds_idx];
- resolve_att->image_view =
- anv_image_view_from_handle(d_or_s_att->resolveImageView);
+ if (subpass->depth_stencil_attachment) {
+ const VkRenderingAttachmentInfoKHR *d_att_info = info->pDepthAttachment;
+ const VkRenderingAttachmentInfoKHR *s_att_info = info->pStencilAttachment;
+ const VkRenderingAttachmentInfoKHR *d_or_s_att_info =
+ d_att_info ? d_att_info : s_att_info;
+
+ struct anv_attachment_state *ds_att_state =
+ &state->attachments[subpass->depth_stencil_attachment->attachment];
+ ds_att_state->image_view =
+ anv_image_view_from_handle(d_or_s_att_info->imageView);
+
+ if (subpass->ds_resolve_attachment) {
+ struct anv_attachment_state *ds_res_att_state =
+ &state->attachments[subpass->ds_resolve_attachment->attachment];
+ ds_res_att_state->image_view =
+ anv_image_view_from_handle(d_or_s_att_info->resolveImageView);
VkImageAspectFlagBits ds_aspect =
- (d_att ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
- (s_att ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
- resolve_att->aux_usage =
+ (d_att_info ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
+ (s_att_info ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
+ ds_res_att_state->aux_usage =
anv_layout_to_aux_usage(&cmd_buffer->device->info,
- resolve_att->image_view->image,
+ ds_res_att_state->image_view->image,
ds_aspect,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
- d_or_s_att->resolveImageLayout);
- ds_idx -= 1;
+ d_or_s_att_info->resolveImageLayout);
}
- struct anv_attachment_state *att_state = &state->attachments[ds_idx];
-
- att_state->image_view =
- anv_image_view_from_handle(d_or_s_att->imageView);
-
VkImageAspectFlags clear_aspects = 0;
- if (d_att && d_att->imageView) {
- VkAttachmentLoadOp load_op = get_effective_load_op(d_att->loadOp, resuming);
- if (load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+ if (d_att_info && d_att_info->imageView) {
+ VkAttachmentLoadOp load_op =
+ get_effective_load_op(d_att_info->loadOp, resuming);
+ if (load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
clear_aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
- }
- att_state->aux_usage =
+ ds_att_state->aux_usage =
anv_layout_to_aux_usage(&cmd_buffer->device->info,
- att_state->image_view->image,
+ ds_att_state->image_view->image,
VK_IMAGE_ASPECT_DEPTH_BIT,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
- d_att->imageLayout);
+ d_att_info->imageLayout);
- att_state->current_layout = d_att->imageLayout;
+ ds_att_state->current_layout = d_att_info->imageLayout;
}
- if (s_att && s_att->imageView) {
- VkAttachmentLoadOp load_op = get_effective_load_op(s_att->loadOp, resuming);
- if (load_op == VK_ATTACHMENT_LOAD_OP_CLEAR) {
+ if (s_att_info && s_att_info->imageView) {
+ VkAttachmentLoadOp load_op =
+ get_effective_load_op(s_att_info->loadOp, resuming);
+ if (load_op == VK_ATTACHMENT_LOAD_OP_CLEAR)
clear_aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
- }
- att_state->current_stencil_layout = s_att->imageLayout;
+ ds_att_state->current_stencil_layout = s_att_info->imageLayout;
}
- att_state->pending_clear_aspects = clear_aspects;
- att_state->clear_value = d_or_s_att->clearValue;
+ ds_att_state->pending_clear_aspects = clear_aspects;
+ ds_att_state->clear_value = d_or_s_att_info->clearValue;
if (clear_aspects) {
- struct anv_image_view *iview = att_state->image_view;
+ struct anv_image_view *iview = ds_att_state->image_view;
const uint32_t num_layers = iview->planes[0].isl.array_len;
- att_state->pending_clear_views = (1 << num_layers) - 1;
+ ds_att_state->pending_clear_views = (1 << num_layers) - 1;
- att_state->fast_clear =
+ ds_att_state->fast_clear =
anv_can_hiz_clear_ds_view(cmd_buffer->device, iview,
- att_state->current_layout,
+ ds_att_state->current_layout,
clear_aspects,
- att_state->clear_value.depthStencil.depth,
+ ds_att_state->clear_value.depthStencil.depth,
info->renderArea);
uint32_t level = iview->planes[0].isl.base_level;
-
uint32_t base_layer, layer_count;
if (iview->image->vk.image_type == VK_IMAGE_TYPE_3D) {
base_layer = 0;
@@ -7136,7 +7136,7 @@ genX(cmd_buffer_setup_attachments_dynrender)(struct anv_cmd_buffer *cmd_buffer,
layer_count = info->layerCount;
}
- clear_depth_stencil_attachment(cmd_buffer, att_state, level,
+ clear_depth_stencil_attachment(cmd_buffer, ds_att_state, level,
base_layer, layer_count);
}
}
More information about the mesa-commit
mailing list