diff --git a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp index b88d78206..0ba707852 100644 --- a/src/graphics/host_gpu/renderer/depthRenderTarget.cpp +++ b/src/graphics/host_gpu/renderer/depthRenderTarget.cpp @@ -19,6 +19,7 @@ #include "graphics/host_gpu/vulkanCommon.h" #include +#include #include #include #include @@ -76,6 +77,16 @@ static vk::StencilOp ConvertStencilOp(uint8_t value, uint8_t write_mask, uint8_t } } +static PipelineStencilStaticState ConvertStencilState( + uint8_t compare, const std::array& operations, uint8_t op_value, + PipelineStencilDynamicState& dynamic) { + return { + ConvertStencilOp(operations[0], dynamic.writeMask, op_value, dynamic.reference), + ConvertStencilOp(operations[1], dynamic.writeMask, op_value, dynamic.reference), + ConvertStencilOp(operations[2], dynamic.writeMask, op_value, dynamic.reference), + static_cast(compare)}; +} + [[nodiscard]] static vk::Format ResolveHostDepthAttachmentFormat(const CommandBuffer& buffer, const DepthFormatPolicy& policy, bool has_stencil, @@ -304,22 +315,15 @@ void RenderExecutor::ResolveRenderDepthTarget(CommandBuffer& buffer, RenderDepth dc.stencilfunc_bf > static_cast(vk::CompareOp::eAlways))) { DepthFatal("unsupported stencil compare state"); } - r.stencil_static_front = { - ConvertStencilOp(sc.stencil_fail, front_write_mask, sm.stencil_opval, sm.stencil_testval), - ConvertStencilOp(sc.stencil_zpass, front_write_mask, sm.stencil_opval, sm.stencil_testval), - ConvertStencilOp(sc.stencil_zfail, front_write_mask, sm.stencil_opval, sm.stencil_testval), - static_cast(dc.stencilfunc)}; r.stencil_dynamic_front = {sm.stencil_mask, front_write_mask, sm.stencil_testval}; + r.stencil_static_front = ConvertStencilState( + dc.stencilfunc, {sc.stencil_fail, sc.stencil_zpass, sc.stencil_zfail}, + sm.stencil_opval, r.stencil_dynamic_front); if (dc.backface_enable) { - r.stencil_static_back = { - ConvertStencilOp(sc.stencil_fail_bf, back_write_mask, sm.stencil_opval_bf, - sm.stencil_testval_bf), - ConvertStencilOp(sc.stencil_zpass_bf, back_write_mask, sm.stencil_opval_bf, - sm.stencil_testval_bf), - ConvertStencilOp(sc.stencil_zfail_bf, back_write_mask, sm.stencil_opval_bf, - sm.stencil_testval_bf), - static_cast(dc.stencilfunc_bf)}; r.stencil_dynamic_back = {sm.stencil_mask_bf, back_write_mask, sm.stencil_testval_bf}; + r.stencil_static_back = ConvertStencilState( + dc.stencilfunc_bf, {sc.stencil_fail_bf, sc.stencil_zpass_bf, sc.stencil_zfail_bf}, + sm.stencil_opval_bf, r.stencil_dynamic_back); } else { r.stencil_static_back = r.stencil_static_front; r.stencil_dynamic_back = r.stencil_dynamic_front;