vulkan/util: Move helper functions for depth/stencil images to vk_iamge

Signed-off-by: Hyunjun Ko <zzoon@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12785>
This commit is contained in:
Hyunjun Ko
2021-09-27 03:42:43 +00:00
committed by Marge Bot
parent 2a0253b9b5
commit 979ea394e5
5 changed files with 109 additions and 177 deletions
+5 -89
View File
@@ -251,90 +251,6 @@ num_subpass_attachments2(const VkSubpassDescription2KHR *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 VkAttachmentReference2KHR *att_ref)
{
const VkAttachmentReferenceStencilLayoutKHR *stencil_ref =
vk_find_struct_const(att_ref->pNext,
ATTACHMENT_REFERENCE_STENCIL_LAYOUT_KHR);
if (stencil_ref)
return stencil_ref->stencilLayout;
/* 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."
*/
assert(!vk_image_layout_depth_only(att_ref->layout));
return att_ref->layout;
}
/* 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)
{
if (!vk_format_has_stencil(att_desc->format))
return VK_IMAGE_LAYOUT_UNDEFINED;
const VkAttachmentDescriptionStencilLayoutKHR *stencil_desc =
vk_find_struct_const(att_desc->pNext,
ATTACHMENT_DESCRIPTION_STENCIL_LAYOUT_KHR);
if (stencil_desc) {
return final ?
stencil_desc->stencilFinalLayout :
stencil_desc->stencilInitialLayout;
}
const VkImageLayout main_layout =
final ? att_desc->finalLayout : att_desc->initialLayout;
/* From VUID-VkAttachmentDescription2-format-03302/03303:
* "If format is a depth/stencil format which includes both depth and
* stencil aspects, and initial/finalLayout is
* VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL or
* VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL, the pNext chain must include
* a VkAttachmentDescriptionStencilLayout structure."
*/
assert(!vk_image_layout_depth_only(main_layout));
return main_layout;
}
VkResult anv_CreateRenderPass2(
VkDevice _device,
const VkRenderPassCreateInfo2KHR* pCreateInfo,
@@ -384,9 +300,9 @@ VkResult anv_CreateRenderPass2(
.initial_layout = pCreateInfo->pAttachments[i].initialLayout,
.final_layout = pCreateInfo->pAttachments[i].finalLayout,
.stencil_initial_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i],
.stencil_initial_layout = vk_att_desc_stencil_layout(&pCreateInfo->pAttachments[i],
false),
.stencil_final_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i],
.stencil_final_layout = vk_att_desc_stencil_layout(&pCreateInfo->pAttachments[i],
true),
};
}
@@ -410,7 +326,7 @@ VkResult anv_CreateRenderPass2(
.usage = VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT,
.attachment = desc->pInputAttachments[j].attachment,
.layout = desc->pInputAttachments[j].layout,
.stencil_layout = stencil_ref_layout(&desc->pInputAttachments[j]),
.stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j]),
};
}
}
@@ -448,7 +364,7 @@ VkResult anv_CreateRenderPass2(
.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
.attachment = desc->pDepthStencilAttachment->attachment,
.layout = desc->pDepthStencilAttachment->layout,
.stencil_layout = stencil_ref_layout(desc->pDepthStencilAttachment),
.stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment),
};
}
@@ -463,7 +379,7 @@ VkResult anv_CreateRenderPass2(
.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT,
.attachment = ds_resolve->pDepthStencilResolveAttachment->attachment,
.layout = ds_resolve->pDepthStencilResolveAttachment->layout,
.stencil_layout = stencil_ref_layout(ds_resolve->pDepthStencilResolveAttachment),
.stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment),
};
subpass->depth_resolve_mode = ds_resolve->depthResolveMode;
subpass->stencil_resolve_mode = ds_resolve->stencilResolveMode;