From 9bd698c5e565d6a1bb54bc46db8b70b0c6abbfe8 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Tue, 13 Oct 2020 16:28:34 +0200 Subject: [PATCH] radv: fix optimizing needed states if some are marked as dynamic From the Vulkan spec 1.2.157: "VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT specifies that the stencilTestEnable state in VkPipelineDepthStencilStateCreateInfo will be ignored and must be set dynamically with vkCmdSetStencilTestEnableEXT before any draw call." So, stencilTestEnable should be ignored if dynamic. While we are at it, fix depthBoundsTestEnable too. Cc: 20.2 Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3633 Signed-off-by: Samuel Pitoiset Reviewed-by: Bas Nieuwenhuizen Part-of: (cherry picked from commit bb00a6860eeb5c92db3dc4b98df1f2e568fa162d) --- src/amd/vulkan/radv_pipeline.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c index e9901dad340..349a6d197ec 100644 --- a/src/amd/vulkan/radv_pipeline.c +++ b/src/amd/vulkan/radv_pipeline.c @@ -915,6 +915,21 @@ radv_order_invariant_stencil_state(const VkStencilOpState *state) radv_order_invariant_stencil_op(state->failOp)); } +static bool +radv_is_state_dynamic(const VkGraphicsPipelineCreateInfo *pCreateInfo, + VkDynamicState state) +{ + if (pCreateInfo->pDynamicState) { + uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount; + for (uint32_t i = 0; i < count; i++) { + if (pCreateInfo->pDynamicState->pDynamicStates[i] == state) + return true; + } + } + + return false; +} + static bool radv_pipeline_has_dynamic_ds_states(const VkGraphicsPipelineCreateInfo *pCreateInfo) { @@ -926,14 +941,9 @@ radv_pipeline_has_dynamic_ds_states(const VkGraphicsPipelineCreateInfo *pCreateI VK_DYNAMIC_STATE_STENCIL_OP_EXT, }; - if (pCreateInfo->pDynamicState) { - uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount; - for (uint32_t i = 0; i < count; i++) { - for (uint32_t j = 0; j < ARRAY_SIZE(ds_states); j++) { - if (pCreateInfo->pDynamicState->pDynamicStates[i] == ds_states[j]) - return true; - } - } + for (uint32_t i = 0; i < ARRAY_SIZE(ds_states); i++) { + if (radv_is_state_dynamic(pCreateInfo, ds_states[i])) + return true; } return false; @@ -1333,11 +1343,13 @@ static uint32_t radv_pipeline_needed_dynamic_state(const VkGraphicsPipelineCreat states &= ~RADV_DYNAMIC_DEPTH_BIAS; if (!pCreateInfo->pDepthStencilState || - !pCreateInfo->pDepthStencilState->depthBoundsTestEnable) + (!pCreateInfo->pDepthStencilState->depthBoundsTestEnable && + !radv_is_state_dynamic(pCreateInfo, VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT))) states &= ~RADV_DYNAMIC_DEPTH_BOUNDS; if (!pCreateInfo->pDepthStencilState || - !pCreateInfo->pDepthStencilState->stencilTestEnable) + (!pCreateInfo->pDepthStencilState->stencilTestEnable && + !radv_is_state_dynamic(pCreateInfo, VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT))) states &= ~(RADV_DYNAMIC_STENCIL_COMPARE_MASK | RADV_DYNAMIC_STENCIL_WRITE_MASK | RADV_DYNAMIC_STENCIL_REFERENCE);