From 2162362f8b2bc4117a718fb2c678d7865a102264 Mon Sep 17 00:00:00 2001 From: Danylo Piliaiev Date: Wed, 24 Sep 2025 17:28:04 +0200 Subject: [PATCH] vulkan: Always fill DS state for EXT_dynamic_rendering_unused_attachments If renderpass has D/S attachment, but pipeline has D/S as UNDEFINED, D/S should be properly disabled for the pipeline. The easiest way is to ensure that D/S state is valid when pipeline's D/S format is UNDEFINED. So we always create VkPipelineDepthStencilStateCreateInfo. CC: mesa-stable Signed-off-by: Danylo Piliaiev Reviewed-by: Connor Abbott Part-of: (cherry picked from commit 2798ef7bfdf9ceafb931c2b2db4b6ef5d787fb0a) --- .pick_status.json | 2 +- src/vulkan/runtime/vk_graphics_state.c | 61 +++++++++++--------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index c6a0b3aaf71..f3e2be760ce 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -3134,7 +3134,7 @@ "description": "vulkan: Always fill DS state for EXT_dynamic_rendering_unused_attachments", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/vulkan/runtime/vk_graphics_state.c b/src/vulkan/runtime/vk_graphics_state.c index cee7d74f09d..ee4c42f4e2a 100644 --- a/src/vulkan/runtime/vk_graphics_state.c +++ b/src/vulkan/runtime/vk_graphics_state.c @@ -1588,42 +1588,8 @@ vk_graphics_pipeline_state_fill(const struct vk_device *device, if (info->pMultisampleState != NULL) needs |= MESA_VK_GRAPHICS_STATE_MULTISAMPLE_BIT; - /* From the Vulkan 1.3.218 spec: - * - * VUID-VkGraphicsPipelineCreateInfo-renderPass-06043 - * - * "If renderPass is not VK_NULL_HANDLE, the pipeline is being - * created with fragment shader state, and subpass uses a - * depth/stencil attachment, pDepthStencilState must be a valid - * pointer to a valid VkPipelineDepthStencilStateCreateInfo - * structure" - * - * VUID-VkGraphicsPipelineCreateInfo-renderPass-06053 - * - * "If renderPass is VK_NULL_HANDLE, the pipeline is being created - * with fragment shader state and fragment output interface state, - * and either of VkPipelineRenderingCreateInfo::depthAttachmentFormat - * or VkPipelineRenderingCreateInfo::stencilAttachmentFormat are not - * VK_FORMAT_UNDEFINED, pDepthStencilState must be a valid pointer to - * a valid VkPipelineDepthStencilStateCreateInfo structure" - * - * VUID-VkGraphicsPipelineCreateInfo-renderPass-06590 - * - * "If renderPass is VK_NULL_HANDLE and the pipeline is being created - * with fragment shader state but not fragment output interface - * state, pDepthStencilState must be a valid pointer to a valid - * VkPipelineDepthStencilStateCreateInfo structure" - * - * In the first case, we'll have a real set of aspects in rp. In the - * second case, where we have both fragment shader and fragment output - * state, we will also have a valid set of aspects. In the third case - * where we only have fragment shader state and no render pass, the - * vk_render_pass_state will be incomplete. - */ - if (!vk_render_pass_state_has_attachment_info(&rp) || - (rp.attachments & (MESA_VK_RP_ATTACHMENT_DEPTH_BIT | - MESA_VK_RP_ATTACHMENT_STENCIL_BIT))) - needs |= MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT; + /* Always need D/S state due to VK_EXT_dynamic_rendering_unused_attachments */ + needs |= MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT; needs |= MESA_VK_GRAPHICS_STATE_INPUT_ATTACHMENT_MAP_BIT; } @@ -1767,6 +1733,29 @@ vk_graphics_pipeline_state_fill(const struct vk_device *device, const VkRenderingAttachmentLocationInfoKHR *cal_info = vk_find_struct_const(info->pNext, RENDERING_ATTACHMENT_LOCATION_INFO_KHR); + VkPipelineDepthStencilStateCreateInfo custom_ds_info; + /* With VK_EXT_dynamic_rendering_unused_attachments, we must explicitly + * disable depth and stencil if pDepthStencilState may not be a valid + * pointer. Dynamic renderpasses are allowed to have depth/stencil + * attachments even when the pipeline have them as VK_FORMAT_UNDEFINED, + * in which case pDepthStencilState may not be a valid pointer and we + * cannot access it even if depth/stencil state is statically specified + * by the pipeline. + */ + if ((needs & MESA_VK_GRAPHICS_STATE_DEPTH_STENCIL_BIT) && + vk_render_pass_state_has_attachment_info(&rp)) { + bool has_depth = rp.attachments & MESA_VK_RP_ATTACHMENT_DEPTH_BIT; + bool has_stencil = rp.attachments & MESA_VK_RP_ATTACHMENT_STENCIL_BIT; + + if (!has_depth && !has_stencil) { + custom_ds_info = (VkPipelineDepthStencilStateCreateInfo){ + .depthTestEnable = false, + .stencilTestEnable = false, + }; + ds_info = &custom_ds_info; + } + } + /* * Finally, fill out all the states */