diff --git a/reference/opt/shaders-msl/asm/vert/invariant.msl21.asm.vert b/reference/opt/shaders-msl/asm/vert/invariant.msl21.asm.vert new file mode 100644 index 00000000..88ca455e --- /dev/null +++ b/reference/opt/shaders-msl/asm/vert/invariant.msl21.asm.vert @@ -0,0 +1,17 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position, invariant]]; +}; + +vertex main0_out main0() +{ + main0_out out = {}; + out.gl_Position = float4(1.0); + return out; +} + diff --git a/reference/opt/shaders-msl/vert/invariant.msl21.vert b/reference/opt/shaders-msl/vert/invariant.msl21.vert new file mode 100644 index 00000000..73b0ec74 --- /dev/null +++ b/reference/opt/shaders-msl/vert/invariant.msl21.vert @@ -0,0 +1,26 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position, invariant]]; +}; + +struct main0_in +{ + float4 vInput0 [[attribute(0)]]; + float4 vInput1 [[attribute(1)]]; + float4 vInput2 [[attribute(2)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + float4 _20 = in.vInput1 * in.vInput2; + float4 _21 = in.vInput0 + _20; + out.gl_Position = _21; + return out; +} + diff --git a/reference/shaders-msl/asm/vert/invariant.msl21.asm.vert b/reference/shaders-msl/asm/vert/invariant.msl21.asm.vert new file mode 100644 index 00000000..1e3a8653 --- /dev/null +++ b/reference/shaders-msl/asm/vert/invariant.msl21.asm.vert @@ -0,0 +1,25 @@ +#pragma clang diagnostic ignored "-Wmissing-prototypes" + +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position, invariant]]; +}; + +float4 _main() +{ + return float4(1.0); +} + +vertex main0_out main0() +{ + main0_out out = {}; + float4 _14 = _main(); + out.gl_Position = _14; + return out; +} + diff --git a/reference/shaders-msl/vert/invariant.msl21.vert b/reference/shaders-msl/vert/invariant.msl21.vert new file mode 100644 index 00000000..73b0ec74 --- /dev/null +++ b/reference/shaders-msl/vert/invariant.msl21.vert @@ -0,0 +1,26 @@ +#include +#include + +using namespace metal; + +struct main0_out +{ + float4 gl_Position [[position, invariant]]; +}; + +struct main0_in +{ + float4 vInput0 [[attribute(0)]]; + float4 vInput1 [[attribute(1)]]; + float4 vInput2 [[attribute(2)]]; +}; + +vertex main0_out main0(main0_in in [[stage_in]]) +{ + main0_out out = {}; + float4 _20 = in.vInput1 * in.vInput2; + float4 _21 = in.vInput0 + _20; + out.gl_Position = _21; + return out; +} + diff --git a/shaders-msl/asm/vert/invariant.msl21.asm.vert b/shaders-msl/asm/vert/invariant.msl21.asm.vert new file mode 100644 index 00000000..c0d381ee --- /dev/null +++ b/shaders-msl/asm/vert/invariant.msl21.asm.vert @@ -0,0 +1,34 @@ +; SPIR-V +; Version: 1.0 +; Generator: Khronos Glslang Reference Front End; 3 +; Bound: 18 +; Schema: 0 + OpCapability Shader + %1 = OpExtInstImport "GLSL.std.450" + OpMemoryModel Logical GLSL450 + OpEntryPoint Vertex %main "main" %_entryPointOutput + OpSource HLSL 500 + OpName %main "main" + OpName %_main_ "@main(" + OpName %_entryPointOutput "@entryPointOutput" + OpDecorate %_entryPointOutput Invariant + OpDecorate %_entryPointOutput BuiltIn Position + %void = OpTypeVoid + %3 = OpTypeFunction %void + %float = OpTypeFloat 32 + %v4float = OpTypeVector %float 4 + %8 = OpTypeFunction %v4float + %float_1 = OpConstant %float 1 + %12 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1 +%_ptr_Output_v4float = OpTypePointer Output %v4float +%_entryPointOutput = OpVariable %_ptr_Output_v4float Output + %main = OpFunction %void None %3 + %5 = OpLabel + %17 = OpFunctionCall %v4float %_main_ + OpStore %_entryPointOutput %17 + OpReturn + OpFunctionEnd + %_main_ = OpFunction %v4float None %8 + %10 = OpLabel + OpReturnValue %12 + OpFunctionEnd diff --git a/shaders-msl/vert/invariant.msl21.vert b/shaders-msl/vert/invariant.msl21.vert new file mode 100644 index 00000000..f090db5e --- /dev/null +++ b/shaders-msl/vert/invariant.msl21.vert @@ -0,0 +1,11 @@ +#version 310 es + +invariant gl_Position; +layout(location = 0) in vec4 vInput0; +layout(location = 1) in vec4 vInput1; +layout(location = 2) in vec4 vInput2; + +void main() +{ + gl_Position = vInput0 + vInput1 * vInput2; +} diff --git a/spirv_msl.cpp b/spirv_msl.cpp index d8af2d69..be615b1c 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -7598,7 +7598,14 @@ string CompilerMSL::builtin_qualifier(BuiltIn builtin) case BuiltInPointSize: return "point_size"; case BuiltInPosition: - return "position"; + if (position_invariant) + { + if (!msl_options.supports_msl_version(2, 1)) + SPIRV_CROSS_THROW("Invariant position is only supported on MSL 2.1 and up."); + return "position, invariant"; + } + else + return "position"; case BuiltInLayer: return "render_target_array_index"; case BuiltInViewportIndex: