Mesa (main): vulkan/util: Handle depth-only formats in vk_att_ref_stencil_layout

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Nov 11 17:39:10 UTC 2021


Module: Mesa
Branch: main
Commit: deb23612f7554f8db7f3574d068f36ccefd99487
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=deb23612f7554f8db7f3574d068f36ccefd99487

Author: Danylo Piliaiev <dpiliaiev at igalia.com>
Date:   Wed Nov 10 18:32:45 2021 +0200

vulkan/util: Handle depth-only formats in vk_att_ref_stencil_layout

>From VUID-VkAttachmentReference2-attachment-04755:
 "If attachment is not VK_ATTACHMENT_UNUSED, and the format of the
  referenced attachment is a depth/stencil format which includes both
  depth and stencil aspects, and layout is
  VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL or
  VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL, the pNext chain must include
  a VkAttachmentReferenceStencilLayout structure."

We did not check that there even could be a stencil layout
before fetching it.

Fixes a few tests from:
 dEQP-VK.image.depth_stencil_descriptor.depth_read_only_optimal.*

Fixes: 979ea394e56a418f4138b5f440ec0b641cc5fa0e "vulkan/util: Move
helper functions for depth/stencil images to vk_iamge"

Signed-off-by: Danylo Piliaiev <dpiliaiev at igalia.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13740>

---

 src/amd/vulkan/radv_pass.c    |  9 ++++++---
 src/intel/vulkan/anv_pass.c   |  9 ++++++---
 src/vulkan/runtime/vk_image.c | 12 +++++++++++-
 src/vulkan/runtime/vk_image.h |  3 ++-
 4 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/amd/vulkan/radv_pass.c b/src/amd/vulkan/radv_pass.c
index d4d1a9dbfb5..8247174ec56 100644
--- a/src/amd/vulkan/radv_pass.c
+++ b/src/amd/vulkan/radv_pass.c
@@ -389,7 +389,8 @@ radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateI
             subpass->input_attachments[j] = (struct radv_subpass_attachment){
                .attachment = desc->pInputAttachments[j].attachment,
                .layout = desc->pInputAttachments[j].layout,
-               .stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j]),
+               .stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j],
+                                                           pCreateInfo->pAttachments),
             };
          }
       }
@@ -424,7 +425,8 @@ radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateI
          *subpass->depth_stencil_attachment = (struct radv_subpass_attachment){
             .attachment = desc->pDepthStencilAttachment->attachment,
             .layout = desc->pDepthStencilAttachment->layout,
-            .stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment),
+            .stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment,
+                                                        pCreateInfo->pAttachments),
          };
       }
 
@@ -437,7 +439,8 @@ radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateI
          *subpass->ds_resolve_attachment = (struct radv_subpass_attachment){
             .attachment = ds_resolve->pDepthStencilResolveAttachment->attachment,
             .layout = ds_resolve->pDepthStencilResolveAttachment->layout,
-            .stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment),
+            .stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment,
+                                                        pCreateInfo->pAttachments),
          };
 
          subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c
index 59e7b24f012..491525e7399 100644
--- a/src/intel/vulkan/anv_pass.c
+++ b/src/intel/vulkan/anv_pass.c
@@ -326,7 +326,8 @@ VkResult anv_CreateRenderPass2(
                .usage =          VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT,
                .attachment =     desc->pInputAttachments[j].attachment,
                .layout =         desc->pInputAttachments[j].layout,
-               .stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j]),
+               .stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j],
+                                                           pCreateInfo->pAttachments),
             };
          }
       }
@@ -364,7 +365,8 @@ VkResult anv_CreateRenderPass2(
             .usage =          VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
             .attachment =     desc->pDepthStencilAttachment->attachment,
             .layout =         desc->pDepthStencilAttachment->layout,
-            .stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment),
+            .stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment,
+                                                        pCreateInfo->pAttachments),
          };
       }
 
@@ -379,7 +381,8 @@ VkResult anv_CreateRenderPass2(
             .usage =          VK_IMAGE_USAGE_TRANSFER_DST_BIT,
             .attachment =     ds_resolve->pDepthStencilResolveAttachment->attachment,
             .layout =         ds_resolve->pDepthStencilResolveAttachment->layout,
-            .stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment),
+            .stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment,
+                                                        pCreateInfo->pAttachments),
          };
          subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
          subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode;
diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c
index b869d62cc7b..2dccaf4bf05 100644
--- a/src/vulkan/runtime/vk_image.c
+++ b/src/vulkan/runtime/vk_image.c
@@ -525,8 +525,18 @@ vk_image_layout_is_depth_only(VkImageLayout layout)
  *    all relevant image aspects."
  */
 VkImageLayout
-vk_att_ref_stencil_layout(const VkAttachmentReference2KHR *att_ref)
+vk_att_ref_stencil_layout(const VkAttachmentReference2KHR *att_ref,
+                          const VkAttachmentDescription2 *attachments)
 {
+   /* From VUID-VkAttachmentReference2-attachment-04755:
+    *  "If attachment is not VK_ATTACHMENT_UNUSED, and the format of the
+    *   referenced attachment is a depth/stencil format which includes both
+    *   depth and stencil aspects [...]
+    */
+   if (att_ref->attachment == VK_ATTACHMENT_UNUSED ||
+       !vk_format_has_stencil(attachments[att_ref->attachment].format))
+      return VK_IMAGE_LAYOUT_UNDEFINED;
+
    const VkAttachmentReferenceStencilLayoutKHR *stencil_ref =
       vk_find_struct_const(att_ref->pNext, ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
 
diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h
index e21779fb076..e636edb1352 100644
--- a/src/vulkan/runtime/vk_image.h
+++ b/src/vulkan/runtime/vk_image.h
@@ -226,7 +226,8 @@ bool vk_image_layout_is_depth_only(VkImageLayout layout);
 VkImageUsageFlags vk_image_layout_to_usage_flags(VkImageLayout layout,
                                                  VkImageAspectFlagBits aspect);
 
-VkImageLayout vk_att_ref_stencil_layout(const VkAttachmentReference2KHR *att_ref);
+VkImageLayout vk_att_ref_stencil_layout(const VkAttachmentReference2KHR *att_ref,
+                                        const VkAttachmentDescription2 *attachments);
 VkImageLayout vk_att_desc_stencil_layout(const VkAttachmentDescription2KHR *att_desc,
                                            bool final);
 



More information about the mesa-commit mailing list