diff --git a/src/amd/vulkan/radv_pass.c b/src/amd/vulkan/radv_pass.c index ff7c42237ca..d4d1a9dbfb5 100644 --- a/src/amd/vulkan/radv_pass.c +++ b/src/amd/vulkan/radv_pass.c @@ -310,89 +310,6 @@ radv_num_subpass_attachments2(const VkSubpassDescription2 *desc) (vrs && vrs->pFragmentShadingRateAttachment); } -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) -{ - 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.184: - * - * "If the pNext chain includes a VkAttachmentDescriptionStencilLayout structure, then the - * stencilInitialLayout and stencilFinalLayout members specify the initial and final layouts of the - * stencil aspect of a depth/stencil format, and initialLayout and finalLayout only apply to the - * depth aspect. For depth-only formats, the VkAttachmentDescriptionStencilLayout structure is - * ignored. For stencil-only formats, the initial and final layouts of the stencil aspect are taken - * from the VkAttachmentDescriptionStencilLayout structure if present, or initialLayout and - * finalLayout if not present." - * - * "If format is a depth/stencil format, and either initialLayout or finalLayout does not specify a - * layout for the stencil aspect, then the application must specify the initial and final layouts - * of the stencil aspect by including a VkAttachmentDescriptionStencilLayout structure in the pNext - * chain." - */ -static VkImageLayout -stencil_desc_layout(const VkAttachmentDescription2KHR *att_desc, bool final) -{ - const struct util_format_description *desc = vk_format_description(att_desc->format); - if (!util_format_has_stencil(desc)) - 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; - - /* 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(final ? att_desc->finalLayout : - att_desc->initialLayout)); - - return final ? att_desc->finalLayout : att_desc->initialLayout; -} - VkResult radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) @@ -430,8 +347,8 @@ radv_CreateRenderPass2(VkDevice _device, const VkRenderPassCreateInfo2 *pCreateI 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_desc_layout(&pCreateInfo->pAttachments[i], false); - att->stencil_final_layout = stencil_desc_layout(&pCreateInfo->pAttachments[i], true); + att->stencil_initial_layout = vk_att_desc_stencil_layout(&pCreateInfo->pAttachments[i], false); + att->stencil_final_layout = vk_att_desc_stencil_layout(&pCreateInfo->pAttachments[i], true); // att->store_op = pCreateInfo->pAttachments[i].storeOp; // att->stencil_store_op = pCreateInfo->pAttachments[i].stencilStoreOp; } @@ -472,7 +389,7 @@ 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 = stencil_ref_layout(&desc->pInputAttachments[j]), + .stencil_layout = vk_att_ref_stencil_layout(&desc->pInputAttachments[j]), }; } } @@ -507,7 +424,7 @@ 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 = stencil_ref_layout(desc->pDepthStencilAttachment), + .stencil_layout = vk_att_ref_stencil_layout(desc->pDepthStencilAttachment), }; } @@ -520,7 +437,7 @@ 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 = stencil_ref_layout(ds_resolve->pDepthStencilResolveAttachment), + .stencil_layout = vk_att_ref_stencil_layout(ds_resolve->pDepthStencilResolveAttachment), }; subpass->depth_resolve_mode = ds_resolve->depthResolveMode; diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 306a2965da8..b5dd2a2f3d1 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -65,6 +65,7 @@ #include "vk_command_buffer.h" #include "vk_queue.h" #include "vk_util.h" +#include "vk_image.h" #include "ac_binary.h" #include "ac_gpu_info.h" diff --git a/src/intel/vulkan/anv_pass.c b/src/intel/vulkan/anv_pass.c index 0dec9fb2951..59e7b24f012 100644 --- a/src/intel/vulkan/anv_pass.c +++ b/src/intel/vulkan/anv_pass.c @@ -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; diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index 7ad08d23be8..b869d62cc7b 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -503,6 +503,98 @@ vk_image_layout_is_read_only(VkImageLayout layout, unreachable("Invalid image layout."); } +bool +vk_image_layout_is_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." + */ +VkImageLayout +vk_att_ref_stencil_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_is_depth_only(att_ref->layout)); + + return att_ref->layout; +} + +/* From the Vulkan Specification 1.2.184: + * + * "If the pNext chain includes a VkAttachmentDescriptionStencilLayout + * structure, then the stencilInitialLayout and stencilFinalLayout members + * specify the initial and final layouts of the stencil aspect of a + * depth/stencil format, and initialLayout and finalLayout only apply to the + * depth aspect. For depth-only formats, the + * VkAttachmentDescriptionStencilLayout structure is ignored. For + * stencil-only formats, the initial and final layouts of the stencil aspect + * are taken from the VkAttachmentDescriptionStencilLayout structure if + * present, or initialLayout and finalLayout if not present." + * + * "If format is a depth/stencil format, and either initialLayout or + * finalLayout does not specify a layout for the stencil aspect, then the + * application must specify the initial and final layouts of the stencil + * aspect by including a VkAttachmentDescriptionStencilLayout structure in + * the pNext chain." + */ +VkImageLayout +vk_att_desc_stencil_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_is_depth_only(main_layout)); + + return main_layout; +} + VkImageUsageFlags vk_image_layout_to_usage_flags(VkImageLayout layout, VkImageAspectFlagBits aspect) diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h index beb26064775..e21779fb076 100644 --- a/src/vulkan/runtime/vk_image.h +++ b/src/vulkan/runtime/vk_image.h @@ -221,9 +221,15 @@ void vk_image_view_destroy(struct vk_device *device, bool vk_image_layout_is_read_only(VkImageLayout layout, VkImageAspectFlagBits aspect); +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_desc_stencil_layout(const VkAttachmentDescription2KHR *att_desc, + bool final); + #ifdef __cplusplus } #endif