From f9f455144cf87e785cfd23647e45c3513dab1aff Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 20 Jul 2026 04:37:23 -0400 Subject: [PATCH] [Refactor] (MG_Config, DirectVulkan): route the blended depth-write quirk through the FeaturesTable as MOBILEGL_MAGMA_DISABLE_BLENDED_DEPTH_WRITE instead of an ad-hoc getenv --- MobileGL/Config.h | 5 +++++ MobileGL/ConfigLoader.cpp | 2 ++ .../DirectVulkan/Renderer/VulkanRenderer.cpp | 22 +++++++++---------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/MobileGL/Config.h b/MobileGL/Config.h index a99cd7a9..3d1435a8 100644 --- a/MobileGL/Config.h +++ b/MobileGL/Config.h @@ -80,6 +80,11 @@ namespace MobileGL::MG_Config { // rewrites the recognized workgroup prefix-scan template on Qualcomm devices with // subgroups wider than 32 lanes (see ShaderSourceProcessor's quirk registry). QuirkOverride SubgroupPrefixScanQuirk = QuirkOverride::Auto; + // MOBILEGL_MAGMA_DISABLE_BLENDED_DEPTH_WRITE: overrides the DirectVulkan quirk that + // strips depth writes from blended pipelines on drivers without cross-pipeline + // vertex position invariance (see VulkanRenderer's PipelineFactory setup). Auto + // detects Qualcomm. + QuirkOverride MagmaDisableBlendedDepthWriteQuirk = QuirkOverride::Auto; // MOBILEGL_DISABLE_ROBUST_BUFFER_ACCESS: leave the Vulkan robustBufferAccess device // feature off. It is enabled by default to match GL's defined out-of-range fetch // behavior; this escape hatch exists to measure or dodge its GPU cost on a device. diff --git a/MobileGL/ConfigLoader.cpp b/MobileGL/ConfigLoader.cpp index 59aff28f..5b98d637 100644 --- a/MobileGL/ConfigLoader.cpp +++ b/MobileGL/ConfigLoader.cpp @@ -135,6 +135,8 @@ namespace MobileGL::MG_ConfigLoader { features.DisableUboRing = QueryEnvFlag("MOBILEGL_DISABLE_UBO_RING"); features.RelaxedSemantics = QueryEnvFlag("MOBILEGL_RELAXED_SEMANTICS"); features.SubgroupPrefixScanQuirk = QueryEnvQuirkOverride("MOBILEGL_QUIRK_SUBGROUP_PREFIX_SCAN"); + features.MagmaDisableBlendedDepthWriteQuirk = + QueryEnvQuirkOverride("MOBILEGL_MAGMA_DISABLE_BLENDED_DEPTH_WRITE"); features.DisableRobustBufferAccess = QueryEnvFlag("MOBILEGL_DISABLE_ROBUST_BUFFER_ACCESS"); } diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp index cf8edc47..ceca31c3 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp @@ -2112,20 +2112,20 @@ void main() { // the pipelines of a multi-pass depth-equality chain (even with the SPIR-V // Invariant decoration), so a blended depth-writing prepass makes later // equality-compare passes drop whole primitives (MC 26.3 improved-transparency - // clouds flicker black). Suppress blended depth writes there; the env variable - // forces the quirk on ("0") or off ("1") on any driver. + // clouds flicker black). Suppress blended depth writes there; + // MOBILEGL_MAGMA_DISABLE_BLENDED_DEPTH_WRITE forces the quirk on or off on any + // driver. static constexpr Uint32 kVendorIdQualcomm = 0x5143; - Bool suppressBlendedDepthWrite = m_physicalDevice.properties.vendorID == kVendorIdQualcomm; - if (const char* env = getenv("MOBILEGL_MAGMA_BLENDED_DEPTH_WRITE")) { - if (env[0] == '0') { - suppressBlendedDepthWrite = true; - } else if (env[0] == '1') { - suppressBlendedDepthWrite = false; - } - } + const MG_Config::QuirkOverride quirkOverride = + MG_Config::Features.MagmaDisableBlendedDepthWriteQuirk; + const Bool suppressBlendedDepthWrite = + quirkOverride == MG_Config::QuirkOverride::ForceOn || + (quirkOverride == MG_Config::QuirkOverride::Auto && + m_physicalDevice.properties.vendorID == kVendorIdQualcomm); if (suppressBlendedDepthWrite) { MGLOG_I("DirectVulkan: suppressing depth writes on blended pipelines " - "(driver lacks cross-pipeline position invariance)"); + "(driver lacks cross-pipeline position invariance)%s", + quirkOverride == MG_Config::QuirkOverride::ForceOn ? " (forced on)" : ""); } PipelineFactory::SetSuppressBlendedDepthWrite(suppressBlendedDepthWrite); }