From bd5dd01ae473d6337d1633e8352114588cb8c19e Mon Sep 17 00:00:00 2001 From: ssjia Date: Mon, 4 May 2026 16:51:01 -0700 Subject: [PATCH] [ez][ET-VK][glsl-codegen] Use mediump precision for half-precision shader variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The highp default in gen_vulkan_spv.py blocks Mali GPUs from using FP16 ALU because Mali respects the highp precision contract literally. Adreno silently demotes via Qualcomm's relaxed-precision pass, so it was unaffected, but Mali-G715 was running half-precision shaders at FP32 throughput. The mediump qualifier produces SPIR-V with RelaxedPrecision decorations, which Mali's compiler uses to enable f16 packed math. Note: this is a partial fix — texture-storage shaders still declare local `vec4` working values, so the speedup is bounded; the follow-up is to make `texel_type("half")` return `f16vec4` and enable the FP16 extension on the texture path. Differential Revision: [D103759541](https://our.internmc.facebook.com/intern/diff/D103759541/) [ghstack-poisoned] --- backends/vulkan/runtime/gen_vulkan_spv.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backends/vulkan/runtime/gen_vulkan_spv.py b/backends/vulkan/runtime/gen_vulkan_spv.py index dab33fb3097..192bfa3f900 100644 --- a/backends/vulkan/runtime/gen_vulkan_spv.py +++ b/backends/vulkan/runtime/gen_vulkan_spv.py @@ -857,6 +857,13 @@ def create_shader_params( for key, value in variant_params.items(): shader_params[key] = value + # Downgrade PRECISION to mediump for half-precision variants. + if ( + shader_params.get("DTYPE") == "half" + and shader_params.get("PRECISION") == "highp" + ): + shader_params["PRECISION"] = "mediump" + return shader_params def constructOutputMap(self) -> None: