Support gl_HelperInvocation on GLSL and MSL.
There is no obvious builtin for this on HLSL.
This commit is contained in:
parent
fbae10db15
commit
61f1d8b2cf
32
reference/opt/shaders-msl/frag/helper-invocation.msl21.frag
Normal file
32
reference/opt/shaders-msl/frag/helper-invocation.msl21.frag
Normal file
@ -0,0 +1,32 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float2 vUV [[user(locn0)]];
|
||||
};
|
||||
|
||||
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 _51;
|
||||
if (!gl_HelperInvocation)
|
||||
{
|
||||
_51 = uSampler.sample(uSamplerSmplr, in.vUV, level(0.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
_51 = float4(1.0);
|
||||
}
|
||||
out.FragColor = _51;
|
||||
return out;
|
||||
}
|
||||
|
23
reference/opt/shaders/frag/helper-invocation.frag
Normal file
23
reference/opt/shaders/frag/helper-invocation.frag
Normal file
@ -0,0 +1,23 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
precision highp int;
|
||||
|
||||
layout(binding = 0) uniform mediump sampler2D uSampler;
|
||||
|
||||
layout(location = 0) in vec2 vUV;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 _51;
|
||||
if (!gl_HelperInvocation)
|
||||
{
|
||||
_51 = textureLod(uSampler, vUV, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
_51 = vec4(1.0);
|
||||
}
|
||||
FragColor = _51;
|
||||
}
|
||||
|
39
reference/shaders-msl/frag/helper-invocation.msl21.frag
Normal file
39
reference/shaders-msl/frag/helper-invocation.msl21.frag
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
||||
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
struct main0_in
|
||||
{
|
||||
float2 vUV [[user(locn0)]];
|
||||
};
|
||||
|
||||
float4 foo(thread bool& gl_HelperInvocation, thread texture2d<float> uSampler, thread const sampler uSamplerSmplr, thread float2& vUV)
|
||||
{
|
||||
float4 color;
|
||||
if (!gl_HelperInvocation)
|
||||
{
|
||||
color = uSampler.sample(uSamplerSmplr, vUV, level(0.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
color = float4(1.0);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
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);
|
||||
return out;
|
||||
}
|
||||
|
28
reference/shaders/frag/helper-invocation.frag
Normal file
28
reference/shaders/frag/helper-invocation.frag
Normal file
@ -0,0 +1,28 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
precision highp int;
|
||||
|
||||
layout(binding = 0) uniform mediump sampler2D uSampler;
|
||||
|
||||
layout(location = 0) in vec2 vUV;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
vec4 foo()
|
||||
{
|
||||
vec4 color;
|
||||
if (!gl_HelperInvocation)
|
||||
{
|
||||
color = textureLod(uSampler, vUV, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = vec4(1.0);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = foo();
|
||||
}
|
||||
|
21
shaders-msl/frag/helper-invocation.msl21.frag
Normal file
21
shaders-msl/frag/helper-invocation.msl21.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(location = 0) in vec2 vUV;
|
||||
layout(binding = 0) uniform sampler2D uSampler;
|
||||
|
||||
vec4 foo()
|
||||
{
|
||||
vec4 color;
|
||||
if (!gl_HelperInvocation)
|
||||
color = textureLod(uSampler, vUV, 0.0);
|
||||
else
|
||||
color = vec4(1.0);
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = foo();
|
||||
}
|
21
shaders/frag/helper-invocation.frag
Normal file
21
shaders/frag/helper-invocation.frag
Normal file
@ -0,0 +1,21 @@
|
||||
#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(location = 0) in vec2 vUV;
|
||||
layout(binding = 0) uniform sampler2D uSampler;
|
||||
|
||||
vec4 foo()
|
||||
{
|
||||
vec4 color;
|
||||
if (!gl_HelperInvocation)
|
||||
color = textureLod(uSampler, vUV, 0.0);
|
||||
else
|
||||
color = vec4(1.0);
|
||||
return color;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = foo();
|
||||
}
|
@ -5320,6 +5320,8 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
|
||||
return "gl_GlobalInvocationID";
|
||||
case BuiltInLocalInvocationIndex:
|
||||
return "gl_LocalInvocationIndex";
|
||||
case BuiltInHelperInvocation:
|
||||
return "gl_HelperInvocation";
|
||||
case BuiltInBaseVertex:
|
||||
if (options.es)
|
||||
SPIRV_CROSS_THROW("BaseVertex not supported in ES profile.");
|
||||
|
@ -4023,15 +4023,7 @@ string CompilerMSL::entry_point_args(bool append_comma)
|
||||
// point, we get that by calling get_sample_position() on the sample ID.
|
||||
if (var.storage == StorageClassInput && is_builtin_variable(var))
|
||||
{
|
||||
if (bi_type != BuiltInSamplePosition)
|
||||
{
|
||||
if (!ep_args.empty())
|
||||
ep_args += ", ";
|
||||
|
||||
ep_args += builtin_type_decl(bi_type) + " " + to_expression(var_id);
|
||||
ep_args += " [[" + builtin_qualifier(bi_type) + "]]";
|
||||
}
|
||||
else
|
||||
if (bi_type == BuiltInSamplePosition)
|
||||
{
|
||||
auto &entry_func = get<SPIRFunction>(ir.default_entry_point);
|
||||
entry_func.fixup_hooks_in.push_back([=]() {
|
||||
@ -4039,6 +4031,26 @@ string CompilerMSL::entry_point_args(bool append_comma)
|
||||
to_expression(builtin_sample_id_id), ");");
|
||||
});
|
||||
}
|
||||
else if (bi_type == BuiltInHelperInvocation)
|
||||
{
|
||||
if (msl_options.is_ios())
|
||||
SPIRV_CROSS_THROW("simd_is_helper_thread() is only supported on macOS.");
|
||||
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.");
|
||||
|
||||
auto &entry_func = get<SPIRFunction>(ir.default_entry_point);
|
||||
entry_func.fixup_hooks_in.push_back([=]() {
|
||||
statement(builtin_type_decl(bi_type), " ", to_expression(var_id), " = simd_is_helper_thread();");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ep_args.empty())
|
||||
ep_args += ", ";
|
||||
|
||||
ep_args += builtin_type_decl(bi_type) + " " + to_expression(var_id);
|
||||
ep_args += " [[" + builtin_qualifier(bi_type) + "]]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4794,6 +4806,9 @@ string CompilerMSL::builtin_type_decl(BuiltIn builtin)
|
||||
case BuiltInLocalInvocationIndex:
|
||||
return "uint";
|
||||
|
||||
case BuiltInHelperInvocation:
|
||||
return "bool";
|
||||
|
||||
default:
|
||||
return "unsupported-built-in-type";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user