MSL: Consider that gl_IsHelperInvocation can be Volatile.

Just emit simd_is_helper_thread() directly.
This commit is contained in:
Hans-Kristian Arntzen 2022-03-04 11:46:35 +01:00
parent 15d29f00e2
commit b192b8887a
4 changed files with 22 additions and 19 deletions

View File

@ -16,9 +16,8 @@ struct main0_in
fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> 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));
}

View File

@ -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;

View File

@ -16,10 +16,10 @@ struct main0_in
};
static inline __attribute__((always_inline))
float4 foo(thread bool& gl_HelperInvocation, texture2d<float> uSampler, sampler uSamplerSmplr, thread float2& vUV)
float4 foo(texture2d<float> 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<float> uSampler, sampler
fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> 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;
}

View File

@ -1548,6 +1548,14 @@ void CompilerMSL::extract_global_variables_from_functions()
// Uniforms
unordered_set<uint32_t> global_var_ids;
ir.for_each_typed_id<SPIRVariable>([&](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;
}