Mesa (staging/21.0): radv: fix separate depth/stencil layout in render pass
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 22 17:04:58 UTC 2021
Module: Mesa
Branch: staging/21.0
Commit: c849e15c44d1d3f5b327060b5c9f4c055998db84
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c849e15c44d1d3f5b327060b5c9f4c055998db84
Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date: Mon Jan 18 08:59:29 2021 +0100
radv: fix separate depth/stencil layout in render pass
We used to select the stencil layout even if we should have selected
the depth/stencil one.
Fixes: e4c8491bdf8 ("radv: implement VK_KHR_separate_depth_stencil_layouts")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8552>
(cherry picked from commit 3ef89b245e3e1ac4e67fea9c1b13ebeda75769d0)
---
.pick_status.json | 2 +-
src/amd/vulkan/radv_pass.c | 98 ++++++++++++++++++++++++++++++++--------------
2 files changed, 69 insertions(+), 31 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 9b36471a51d..a0f78840681 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -4,7 +4,7 @@
"description": "radv: fix separate depth/stencil layout in render pass",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": "e4c8491bdf8a1238d475491533d937568019e633"
},
diff --git a/src/amd/vulkan/radv_pass.c b/src/amd/vulkan/radv_pass.c
index e3606adbcd5..63cfaa0259d 100644
--- a/src/amd/vulkan/radv_pass.c
+++ b/src/amd/vulkan/radv_pass.c
@@ -497,6 +497,69 @@ radv_num_subpass_attachments2(const VkSubpassDescription2 *desc)
(ds_resolve && ds_resolve->pDepthStencilResolveAttachment);
}
+static bool
+vk_image_layout_depth_only(VkImageLayout layout)
+{
+ switch (layout) {
+ case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL:
+ case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/* From the Vulkan Specification 1.2.166 - VkAttachmentReference2:
+ *
+ * "If layout only specifies the layout of the depth aspect of the attachment,
+ * the layout of the stencil aspect is specified by the stencilLayout member
+ * of a VkAttachmentReferenceStencilLayout structure included in the pNext
+ * chain. Otherwise, layout describes the layout for all relevant image
+ * aspects."
+ */
+static VkImageLayout
+stencil_ref_layout(const VkAttachmentReference2 *att_ref)
+{
+ if (!vk_image_layout_depth_only(att_ref->layout))
+ return att_ref->layout;
+
+ const VkAttachmentReferenceStencilLayoutKHR *stencil_ref =
+ vk_find_struct_const(att_ref->pNext,
+ ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
+ if (!stencil_ref)
+ return VK_IMAGE_LAYOUT_UNDEFINED;
+
+ return stencil_ref->stencilLayout;
+}
+
+/* From the Vulkan Specification 1.2.166 - VkAttachmentDescription2:
+ *
+ * "If format is a depth/stencil format, and initialLayout only specifies the
+ * initial layout of the depth aspect of the attachment, the initial layout of
+ * the stencil aspect is specified by the stencilInitialLayout member of a
+ * VkAttachmentDescriptionStencilLayout structure included in the pNext chain.
+ * Otherwise, initialLayout describes the initial layout for all relevant
+ * image aspects."
+ */
+static VkImageLayout
+stencil_desc_layout(const VkAttachmentDescription2KHR *att_desc, bool final)
+{
+ const struct vk_format_description *desc = vk_format_description(att_desc->format);
+ if (!vk_format_has_stencil(desc))
+ return VK_IMAGE_LAYOUT_UNDEFINED;
+
+ const VkImageLayout main_layout =
+ final ? att_desc->finalLayout : att_desc->initialLayout;
+ if (!vk_image_layout_depth_only(main_layout))
+ return main_layout;
+
+ const VkAttachmentDescriptionStencilLayoutKHR *stencil_desc =
+ vk_find_struct_const(att_desc->pNext,
+ ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR);
+ assert(stencil_desc);
+ return final ? stencil_desc->stencilFinalLayout : stencil_desc->stencilInitialLayout;
+}
+
VkResult radv_CreateRenderPass2(
VkDevice _device,
const VkRenderPassCreateInfo2* pCreateInfo,
@@ -531,9 +594,6 @@ VkResult radv_CreateRenderPass2(
for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
struct radv_render_pass_attachment *att = &pass->attachments[i];
- const VkAttachmentDescriptionStencilLayoutKHR *stencil_layout =
- vk_find_struct_const(pCreateInfo->pAttachments[i].pNext,
- ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR);
att->format = pCreateInfo->pAttachments[i].format;
att->samples = pCreateInfo->pAttachments[i].samples;
@@ -541,12 +601,8 @@ VkResult radv_CreateRenderPass2(
att->stencil_load_op = pCreateInfo->pAttachments[i].stencilLoadOp;
att->initial_layout = pCreateInfo->pAttachments[i].initialLayout;
att->final_layout = pCreateInfo->pAttachments[i].finalLayout;
- att->stencil_initial_layout = (stencil_layout ?
- stencil_layout->stencilInitialLayout :
- pCreateInfo->pAttachments[i].initialLayout);
- att->stencil_final_layout = (stencil_layout ?
- stencil_layout->stencilFinalLayout :
- pCreateInfo->pAttachments[i].finalLayout);
+ att->stencil_initial_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i], false);
+ att->stencil_final_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i], true);
// att->store_op = pCreateInfo->pAttachments[i].storeOp;
// att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp;
}
@@ -585,16 +641,10 @@ VkResult radv_CreateRenderPass2(
p += desc->inputAttachmentCount;
for (uint32_t j = 0; j < desc->inputAttachmentCount; j++) {
- const VkAttachmentReferenceStencilLayoutKHR *stencil_attachment =
- vk_find_struct_const(desc->pInputAttachments[j].pNext,
- ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
-
subpass->input_attachments[j] = (struct radv_subpass_attachment) {
.attachment = desc->pInputAttachments[j].attachment,
.layout = desc->pInputAttachments[j].layout,
- .stencil_layout = (stencil_attachment ?
- stencil_attachment->stencilLayout :
- desc->pInputAttachments[j].layout),
+ .stencil_layout = stencil_ref_layout(&desc->pInputAttachments[j]),
};
}
}
@@ -626,16 +676,10 @@ VkResult radv_CreateRenderPass2(
if (desc->pDepthStencilAttachment) {
subpass->depth_stencil_attachment = p++;
- const VkAttachmentReferenceStencilLayoutKHR *stencil_attachment =
- vk_find_struct_const(desc->pDepthStencilAttachment->pNext,
- ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
-
*subpass->depth_stencil_attachment = (struct radv_subpass_attachment) {
.attachment = desc->pDepthStencilAttachment->attachment,
.layout = desc->pDepthStencilAttachment->layout,
- .stencil_layout = (stencil_attachment ?
- stencil_attachment->stencilLayout :
- desc->pDepthStencilAttachment->layout),
+ .stencil_layout = stencil_ref_layout(desc->pDepthStencilAttachment),
};
}
@@ -646,16 +690,10 @@ VkResult radv_CreateRenderPass2(
if (ds_resolve && ds_resolve->pDepthStencilResolveAttachment) {
subpass->ds_resolve_attachment = p++;
- const VkAttachmentReferenceStencilLayoutKHR *stencil_resolve_attachment =
- vk_find_struct_const(ds_resolve->pDepthStencilResolveAttachment->pNext,
- ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
-
*subpass->ds_resolve_attachment = (struct radv_subpass_attachment) {
.attachment = ds_resolve->pDepthStencilResolveAttachment->attachment,
.layout = ds_resolve->pDepthStencilResolveAttachment->layout,
- .stencil_layout = (stencil_resolve_attachment ?
- stencil_resolve_attachment->stencilLayout :
- ds_resolve->pDepthStencilResolveAttachment->layout),
+ .stencil_layout = stencil_ref_layout(ds_resolve->pDepthStencilResolveAttachment),
};
subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
More information about the mesa-commit
mailing list