From 90c913487595b7f688c0c642e931d9f82b6e85a9 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sat, 23 Aug 2025 09:12:17 +1000 Subject: [PATCH] Metal: Read gl_ViewIndex for multi-view subpasses This is necessary to ensure the SpvCapabilityMultiView is included in the SPIR-V, informing downstream transpilers, like Metal, that it should enable multi-view capabilities in the generated Metal shader source. --- servers/rendering/renderer_rd/shaders/effects/tonemap.glsl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl b/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl index df2719a6bc3..8e3eca40977 100644 --- a/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl +++ b/servers/rendering/renderer_rd/shaders/effects/tonemap.glsl @@ -834,6 +834,11 @@ vec3 screen_space_dither(vec2 frag_coord, float bit_alignment_diviser) { void main() { #ifdef SUBPASS // SUBPASS and USE_MULTIVIEW can be combined but in that case we're already reading from the correct layer +#ifdef USE_MULTIVIEW + // In order to ensure the `SpvCapabilityMultiView` is included in the SPIR-V capabilities, gl_ViewIndex must + // be read in the shader. Without this, transpilation to Metal fails to include the multi-view variant. + uint vi = ViewIndex; +#endif vec4 color = subpassLoad(input_color); #elif defined(USE_MULTIVIEW) vec4 color = textureLod(source_color, vec3(uv_interp, ViewIndex), 0.0f);