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: 979ea394e5 "vulkan/util: Move
helper functions for depth/stencil images to vk_iamge"

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13740>
This commit is contained in:
Danylo Piliaiev 2021-11-10 18:32:45 +02:00 committed by Marge Bot
parent a68a0c9e1c
commit deb23612f7
4 changed files with 25 additions and 8 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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);