From 6216c59dbba7312f2077125b94109c663bf1d255 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 12 May 2022 16:47:46 -0500 Subject: [PATCH] vulkan/render_pass: Use a special layout for self-dependencies Reviewed-by: Samuel Pitoiset Acked-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/genX_cmd_buffer.c | 4 +- src/microsoft/vulkan/dzn_image.c | 1 + src/vulkan/runtime/vk_image.c | 17 +++++++ src/vulkan/runtime/vk_render_pass.c | 74 +++++++++++++++++++---------- src/vulkan/runtime/vk_render_pass.h | 2 + 5 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index f3d3ee1cd71..2cafe874d3f 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -7169,6 +7169,7 @@ void genX(CmdEndRendering)( * - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL * - VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL * - VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL + * - VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA * * For general, we have no nice opportunity to transition so we do the copy * to the shadow unconditionally at the end of the subpass. For transfer @@ -7182,7 +7183,8 @@ void genX(CmdEndRendering)( anv_image_aspect_to_plane(image, VK_IMAGE_ASPECT_STENCIL_BIT); if (anv_surface_is_valid(&image->planes[plane].shadow_surface) && - gfx->stencil_att.layout == VK_IMAGE_LAYOUT_GENERAL) { + (gfx->stencil_att.layout == VK_IMAGE_LAYOUT_GENERAL || + gfx->stencil_att.layout == VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA)) { anv_image_copy_to_shadow(cmd_buffer, image, VK_IMAGE_ASPECT_STENCIL_BIT, iview->planes[plane].isl.base_level, 1, diff --git a/src/microsoft/vulkan/dzn_image.c b/src/microsoft/vulkan/dzn_image.c index 0f5e40fa095..f98e3153d02 100644 --- a/src/microsoft/vulkan/dzn_image.c +++ b/src/microsoft/vulkan/dzn_image.c @@ -521,6 +521,7 @@ dzn_image_layout_to_state(VkImageLayout layout, VkImageAspectFlagBits aspect) case VK_IMAGE_LAYOUT_PREINITIALIZED: case VK_IMAGE_LAYOUT_UNDEFINED: case VK_IMAGE_LAYOUT_GENERAL: + case VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA: /* YOLO! */ case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: return D3D12_RESOURCE_STATE_COMMON; diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index f171e259f7f..c42ecaf2dc3 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -33,6 +33,7 @@ #include "vk_common_entrypoints.h" #include "vk_device.h" #include "vk_format.h" +#include "vk_render_pass.h" #include "vk_util.h" #include "vulkan/wsi/wsi_common.h" @@ -555,6 +556,14 @@ vk_image_layout_is_read_only(VkImageLayout layout, case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL: case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL: case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR: +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch" +#endif + case VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA: +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif return false; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: @@ -703,6 +712,14 @@ vk_image_layout_to_usage_flags(VkImageLayout layout, return 0u; case VK_IMAGE_LAYOUT_GENERAL: +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch" +#endif + case VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA: +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif return ~0u; case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: diff --git a/src/vulkan/runtime/vk_render_pass.c b/src/vulkan/runtime/vk_render_pass.c index 91f2a055d1e..41fe532e1d1 100644 --- a/src/vulkan/runtime/vk_render_pass.c +++ b/src/vulkan/runtime/vk_render_pass.c @@ -488,11 +488,6 @@ vk_common_CreateRenderPass2(VkDevice _device, subpass->view_mask = desc->viewMask ? desc->viewMask : 1; pass->view_mask |= subpass->view_mask; - assert(desc->colorAttachmentCount <= 32); - uint32_t color_self_deps = 0; - bool has_depth_self_dep = false; - bool has_stencil_self_dep = false; - subpass->input_count = desc->inputAttachmentCount; if (desc->inputAttachmentCount > 0) { subpass->input_attachments = next_subpass_attachment; @@ -504,25 +499,6 @@ vk_common_CreateRenderPass2(VkDevice _device, &desc->pInputAttachments[a], pCreateInfo->pAttachments, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT); - - if (desc->pInputAttachments[a].attachment != VK_ATTACHMENT_UNUSED) { - for (uint32_t c = 0; c < desc->colorAttachmentCount; c++) { - if (desc->pColorAttachments[c].attachment == - desc->pInputAttachments[a].attachment) - color_self_deps |= (1u << c); - } - - if (desc->pDepthStencilAttachment != NULL && - desc->pDepthStencilAttachment->attachment == - desc->pInputAttachments[a].attachment) { - VkImageAspectFlags aspects = - subpass->input_attachments[a].aspects; - if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) - has_depth_self_dep = true; - if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) - has_stencil_self_dep = true; - } - } } } @@ -616,6 +592,48 @@ vk_common_CreateRenderPass2(VkDevice _device, fsr_att_info->shadingRateAttachmentTexelSize; } + /* Figure out any self-dependencies */ + assert(desc->colorAttachmentCount <= 32); + uint32_t color_self_deps = 0; + bool has_depth_self_dep = false; + bool has_stencil_self_dep = false; + for (uint32_t a = 0; a < desc->inputAttachmentCount; a++) { + if (desc->pInputAttachments[a].attachment == VK_ATTACHMENT_UNUSED) + continue; + + for (uint32_t c = 0; c < desc->colorAttachmentCount; c++) { + if (desc->pColorAttachments[c].attachment == + desc->pInputAttachments[a].attachment) { + subpass->input_attachments[a].layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + subpass->color_attachments[c].layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + color_self_deps |= (1u << c); + } + } + + if (desc->pDepthStencilAttachment != NULL && + desc->pDepthStencilAttachment->attachment == + desc->pInputAttachments[a].attachment) { + VkImageAspectFlags aspects = + subpass->input_attachments[a].aspects; + if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) { + subpass->input_attachments[a].layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + subpass->depth_stencil_attachment->layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + has_depth_self_dep = true; + } + if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) { + subpass->input_attachments[a].stencil_layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + subpass->depth_stencil_attachment->stencil_layout = + VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA; + has_stencil_self_dep = true; + } + } + } + VkFormat *color_formats = NULL; VkSampleCountFlagBits samples = 0; if (desc->colorAttachmentCount > 0) { @@ -974,6 +992,14 @@ vk_image_layout_supports_input_attachment(VkImageLayout layout) case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL: case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL: case VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR: +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch" +#endif + case VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA: +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif return true; default: return false; diff --git a/src/vulkan/runtime/vk_render_pass.h b/src/vulkan/runtime/vk_render_pass.h index 59b40a25bf5..53af598e295 100644 --- a/src/vulkan/runtime/vk_render_pass.h +++ b/src/vulkan/runtime/vk_render_pass.h @@ -79,6 +79,8 @@ typedef struct VkRenderingAttachmentInitialLayoutInfoMESA { VkImageLayout initialLayout; } VkRenderingAttachmentInitialLayoutInfoMESA; +#define VK_IMAGE_LAYOUT_SUBPASS_SELF_DEPENDENCY_MESA (VkImageLayout)1000044902 + struct vk_subpass_attachment { /** VkAttachmentReference2::attachment */ uint32_t attachment;