[Feat] (MG_Backend/DirectVulkan): depth state

This commit is contained in:
2026-02-18 09:43:45 +08:00
parent f96f4a0a3b
commit ea71b3d96f
3 changed files with 28 additions and 3 deletions
@@ -21,6 +21,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.renderPass, sizeof(payload.renderPass)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.subpass, sizeof(payload.subpass)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.topology, sizeof(payload.topology)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthTestEnable, sizeof(payload.depthTestEnable)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthWriteEnable, sizeof(payload.depthWriteEnable)));
XXHASH_VERIFY(XXH64_update(m_hashState, &payload.depthCompareOp, sizeof(payload.depthCompareOp)));
return XXH64_digest(m_hashState);
}
@@ -78,9 +81,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
ms.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
VkPipelineDepthStencilStateCreateInfo depthStencil{VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO};
depthStencil.depthTestEnable = VK_FALSE;
depthStencil.depthWriteEnable = VK_FALSE;
depthStencil.depthCompareOp = VK_COMPARE_OP_ALWAYS;
depthStencil.depthTestEnable = payload.depthTestEnable ? VK_TRUE : VK_FALSE;
depthStencil.depthWriteEnable = payload.depthWriteEnable ? VK_TRUE : VK_FALSE;
depthStencil.depthCompareOp = payload.depthCompareOp;
depthStencil.depthBoundsTestEnable = VK_FALSE;
depthStencil.stencilTestEnable = VK_FALSE;
@@ -24,6 +24,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
VkRenderPass renderPass = VK_NULL_HANDLE;
Uint32 subpass = 0;
VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
Bool depthTestEnable = false;
Bool depthWriteEnable = false;
VkCompareOp depthCompareOp = VK_COMPARE_OP_ALWAYS;
const Vector<VkPipelineShaderStageCreateInfo>* stages = nullptr;
const VkPipelineVertexInputStateCreateInfo* vertexInputState = nullptr;
};
@@ -72,6 +72,19 @@ namespace MobileGL::MG_Backend::DirectVulkan {
return VK_NULL_HANDLE;
}
const Uint64 programHash = m_programFactory->ComputeHash(program, ProgramFactory::CompileOptionBit::None);
auto toVkCompareOp = [](DepthTestFunc func) -> VkCompareOp {
switch (func) {
case DepthTestFunc::Never: return VK_COMPARE_OP_NEVER;
case DepthTestFunc::Less: return VK_COMPARE_OP_LESS;
case DepthTestFunc::Equal: return VK_COMPARE_OP_EQUAL;
case DepthTestFunc::LessEqual: return VK_COMPARE_OP_LESS_OR_EQUAL;
case DepthTestFunc::Greater: return VK_COMPARE_OP_GREATER;
case DepthTestFunc::NotEqual: return VK_COMPARE_OP_NOT_EQUAL;
case DepthTestFunc::GreaterEqual: return VK_COMPARE_OP_GREATER_OR_EQUAL;
case DepthTestFunc::Always: return VK_COMPARE_OP_ALWAYS;
default: return VK_COMPARE_OP_ALWAYS;
}
};
PipelineFactory::PipelineCreatePayload payload{};
payload.programHash = programHash;
@@ -80,6 +93,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
payload.renderPass = (m_activeRenderPass != VK_NULL_HANDLE) ? m_activeRenderPass : m_renderPassLoad;
payload.subpass = 0;
payload.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
if (MG_State::pGLContext != nullptr) {
const Bool depthTestEnabled = MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::DepthTest);
payload.depthTestEnable = depthTestEnabled;
payload.depthWriteEnable = depthTestEnabled && MG_State::pGLContext->GetDepthMask();
payload.depthCompareOp = toVkCompareOp(MG_State::pGLContext->GetDepthFunc());
}
payload.stages = &stages;
payload.vertexInputState = &vertexInputState;
return m_pipelineFactory->GetOrCreatePipeline(payload);