MSL: Support Invariant qualifier on position.

This commit is contained in:
Hans-Kristian Arntzen 2019-06-11 11:31:29 +02:00
parent fccf1d0462
commit a7b2ba28a0
7 changed files with 147 additions and 1 deletions

View File

@ -0,0 +1,17 @@
#include <metal_stdlib>
#include <simd/simd.h>
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;
}

View File

@ -0,0 +1,26 @@
#include <metal_stdlib>
#include <simd/simd.h>
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;
}

View File

@ -0,0 +1,25 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
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;
}

View File

@ -0,0 +1,26 @@
#include <metal_stdlib>
#include <simd/simd.h>
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;
}

View File

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

View File

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

View File

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