lavapipe: ignore depth/stencil states if attachment is not present

depth and stencil states should only be set if the corresponding attachment
is present, otherwise they should be ignored. this is different from
ignoring the entire VkPipelineDepthStencilStateCreateInfo struct, as
it's possible that only depth or only stencil may be present

cc: mesa-stable

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16457>
This commit is contained in:
Mike Blumenkrantz 2022-05-12 11:43:51 -04:00 committed by Marge Bot
parent 77392e4983
commit 0b2d383316

View file

@ -242,7 +242,8 @@ static VkResult
deep_copy_dynamic_state(void *mem_ctx,
VkPipelineDynamicStateCreateInfo *dst,
const VkPipelineDynamicStateCreateInfo *src,
VkGraphicsPipelineLibraryFlagsEXT stages)
VkGraphicsPipelineLibraryFlagsEXT stages,
bool has_depth, bool has_stencil)
{
dst->sType = src->sType;
dst->pNext = NULL;
@ -274,17 +275,21 @@ deep_copy_dynamic_state(void *mem_ctx,
case VK_DYNAMIC_STATE_DEPTH_BIAS:
case VK_DYNAMIC_STATE_DEPTH_BOUNDS:
case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
case VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE_EXT:
case VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE_EXT:
case VK_DYNAMIC_STATE_DEPTH_COMPARE_OP_EXT:
case VK_DYNAMIC_STATE_DEPTH_BOUNDS_TEST_ENABLE_EXT:
case VK_DYNAMIC_STATE_DEPTH_BIAS_ENABLE_EXT:
if (has_depth && (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT))
states[dst->dynamicStateCount++] = src->pDynamicStates[i];
break;
case VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK:
case VK_DYNAMIC_STATE_STENCIL_WRITE_MASK:
case VK_DYNAMIC_STATE_STENCIL_REFERENCE:
case VK_DYNAMIC_STATE_STENCIL_TEST_ENABLE_EXT:
case VK_DYNAMIC_STATE_STENCIL_OP_EXT:
if (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT)
if (has_stencil && (stages & VK_GRAPHICS_PIPELINE_LIBRARY_FRAGMENT_SHADER_BIT_EXT))
states[dst->dynamicStateCount++] = src->pDynamicStates[i];
break;
@ -355,6 +360,12 @@ deep_copy_graphics_create_info(void *mem_ctx,
dst->renderPass = src->renderPass;
rp_info = vk_get_pipeline_rendering_create_info(src);
}
bool has_depth = false;
bool has_stencil = false;
if (rp_info) {
has_depth = rp_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED;
has_stencil = rp_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED;
}
dst->basePipelineHandle = src->basePipelineHandle;
dst->basePipelineIndex = src->basePipelineIndex;
@ -440,12 +451,23 @@ deep_copy_graphics_create_info(void *mem_ctx,
assert(rp_info);
/* pDepthStencilState */
if (src->pDepthStencilState && !rasterization_disabled &&
(rp_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED ||
rp_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED)) {
(has_depth || has_stencil)) {
LVP_PIPELINE_DUP(dst->pDepthStencilState,
src->pDepthStencilState,
VkPipelineDepthStencilStateCreateInfo,
1);
VkPipelineDepthStencilStateCreateInfo *pDepthStencilState = (void*)dst->pDepthStencilState;
if (!has_depth) {
pDepthStencilState->depthTestEnable = VK_FALSE;
pDepthStencilState->depthWriteEnable = VK_FALSE;
pDepthStencilState->depthCompareOp = VK_COMPARE_OP_ALWAYS;
pDepthStencilState->depthBoundsTestEnable = VK_FALSE;
}
if (!has_stencil) {
pDepthStencilState->stencilTestEnable = VK_FALSE;
memset(&pDepthStencilState->front, 0, sizeof(VkStencilOpState));
memset(&pDepthStencilState->back, 0, sizeof(VkStencilOpState));
}
} else
dst->pDepthStencilState = NULL;
}
@ -517,7 +539,7 @@ deep_copy_graphics_create_info(void *mem_ctx,
}
if (!dyn_state || !dyn_state->pDynamicStates)
return VK_ERROR_OUT_OF_HOST_MEMORY;
deep_copy_dynamic_state(mem_ctx, dyn_state, src->pDynamicState, shaders);
deep_copy_dynamic_state(mem_ctx, dyn_state, src->pDynamicState, shaders, has_depth, has_stencil);
dst->pDynamicState = dyn_state;
} else
dst->pDynamicState = NULL;