diff --git a/reference/opt/shaders-msl/frag/helper-invocation.msl21.frag b/reference/opt/shaders-msl/frag/helper-invocation.msl21.frag index a833fa08..9d876df1 100644 --- a/reference/opt/shaders-msl/frag/helper-invocation.msl21.frag +++ b/reference/opt/shaders-msl/frag/helper-invocation.msl21.frag @@ -16,9 +16,8 @@ struct main0_in fragment main0_out main0(main0_in in [[stage_in]], texture2d uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - bool gl_HelperInvocation = simd_is_helper_thread(); float4 _52; - if (!gl_HelperInvocation) + if (!simd_is_helper_thread()) { _52 = uSampler.sample(uSamplerSmplr, in.vUV, level(0.0)); } diff --git a/reference/shaders-msl-no-opt/frag/volatile-helper-invocation.msl23.spv16.frag b/reference/shaders-msl-no-opt/frag/volatile-helper-invocation.msl23.spv16.frag index 562cddaa..eef92efe 100644 --- a/reference/shaders-msl-no-opt/frag/volatile-helper-invocation.msl23.spv16.frag +++ b/reference/shaders-msl-no-opt/frag/volatile-helper-invocation.msl23.spv16.frag @@ -11,12 +11,11 @@ struct main0_out fragment main0_out main0() { main0_out out = {}; - bool gl_HelperInvocation = simd_is_helper_thread(); - bool _12 = gl_HelperInvocation; + bool _12 = simd_is_helper_thread(); float _15 = float(_12); out.FragColor = _15; discard_fragment(); - bool _16 = gl_HelperInvocation; + bool _16 = simd_is_helper_thread(); float _17 = float(_16); out.FragColor = _17; return out; diff --git a/reference/shaders-msl/frag/helper-invocation.msl21.frag b/reference/shaders-msl/frag/helper-invocation.msl21.frag index 7cf97a25..36d14239 100644 --- a/reference/shaders-msl/frag/helper-invocation.msl21.frag +++ b/reference/shaders-msl/frag/helper-invocation.msl21.frag @@ -16,10 +16,10 @@ struct main0_in }; static inline __attribute__((always_inline)) -float4 foo(thread bool& gl_HelperInvocation, texture2d uSampler, sampler uSamplerSmplr, thread float2& vUV) +float4 foo(texture2d uSampler, sampler uSamplerSmplr, thread float2& vUV) { float4 color; - if (!gl_HelperInvocation) + if (!simd_is_helper_thread()) { color = uSampler.sample(uSamplerSmplr, vUV, level(0.0)); } @@ -33,8 +33,7 @@ float4 foo(thread bool& gl_HelperInvocation, texture2d uSampler, sampler fragment main0_out main0(main0_in in [[stage_in]], texture2d uSampler [[texture(0)]], sampler uSamplerSmplr [[sampler(0)]]) { main0_out out = {}; - bool gl_HelperInvocation = simd_is_helper_thread(); - out.FragColor = foo(gl_HelperInvocation, uSampler, uSamplerSmplr, in.vUV); + out.FragColor = foo(uSampler, uSamplerSmplr, in.vUV); return out; } diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 4eeb3b7f..8ea27d5f 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -1548,6 +1548,14 @@ void CompilerMSL::extract_global_variables_from_functions() // Uniforms unordered_set global_var_ids; ir.for_each_typed_id([&](uint32_t, SPIRVariable &var) { + // Some builtins resolve directly to a function call which does not need any declared variables. + // Skip these. + if (var.storage == StorageClassInput && has_decoration(var.self, DecorationBuiltIn) && + BuiltIn(get_decoration(var.self, DecorationBuiltIn)) == BuiltInHelperInvocation) + { + return; + } + if (var.storage == StorageClassInput || var.storage == StorageClassOutput || var.storage == StorageClassUniform || var.storage == StorageClassUniformConstant || var.storage == StorageClassPushConstant || var.storage == StorageClassStorageBuffer) @@ -12163,16 +12171,6 @@ void CompilerMSL::fix_up_shader_inputs_outputs() }); } break; - case BuiltInHelperInvocation: - if (msl_options.is_ios() && !msl_options.supports_msl_version(2, 3)) - SPIRV_CROSS_THROW("simd_is_helper_thread() requires version 2.3 on iOS."); - else if (msl_options.is_macos() && !msl_options.supports_msl_version(2, 1)) - SPIRV_CROSS_THROW("simd_is_helper_thread() requires version 2.1 on macOS."); - - entry_func.fixup_hooks_in.push_back([=]() { - statement(builtin_type_decl(bi_type), " ", to_expression(var_id), " = simd_is_helper_thread();"); - }); - break; case BuiltInInvocationId: // This is direct-mapped without multi-patch workgroups. if (get_execution_model() != ExecutionModelTessellationControl || !msl_options.multi_patch_workgroup) @@ -14467,6 +14465,14 @@ string CompilerMSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage) } break; + case BuiltInHelperInvocation: + if (msl_options.is_ios() && !msl_options.supports_msl_version(2, 3)) + SPIRV_CROSS_THROW("simd_is_helper_thread() requires version 2.3 on iOS."); + else if (msl_options.is_macos() && !msl_options.supports_msl_version(2, 1)) + SPIRV_CROSS_THROW("simd_is_helper_thread() requires version 2.1 on macOS."); + // In SPIR-V 1.6 with Volatile HelperInvocation, we cannot emit a fixup early. + return "simd_is_helper_thread()"; + default: break; }