Merge pull request #1581 from KhronosGroup/fix-1554

GLSL/MSL: Handle more complicated tessellation Output initializers
This commit is contained in:
Hans-Kristian Arntzen 2021-01-07 09:51:09 +01:00 committed by GitHub
commit 42ec132357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 1601 additions and 53 deletions

View File

@ -2,10 +2,12 @@
layout(location = 0) out vec4 FragColors[2];
layout(location = 2) out vec4 FragColor;
const vec4 _3_init[2] = vec4[](vec4(1.0, 2.0, 3.0, 4.0), vec4(10.0));
const vec4 _4_init = vec4(5.0);
void main()
{
FragColors = vec4[](vec4(1.0, 2.0, 3.0, 4.0), vec4(10.0));
FragColor = vec4(5.0);
FragColors = _3_init;
FragColor = _4_init;
}

View File

@ -0,0 +1,65 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
constant spvUnsafeArray<float, 3> _49 = spvUnsafeArray<float, 3>({ 0.0, 0.0, 0.0 });
constant spvUnsafeArray<spvUnsafeArray<float, 3>, 4> _27 = spvUnsafeArray<spvUnsafeArray<float, 3>, 4>({ spvUnsafeArray<float, 3>({ 0.0, 0.0, 0.0 }), spvUnsafeArray<float, 3>({ 0.0, 0.0, 0.0 }), spvUnsafeArray<float, 3>({ 0.0, 0.0, 0.0 }), spvUnsafeArray<float, 3>({ 0.0, 0.0, 0.0 }) });
struct main0_out
{
spvUnsafeArray<float, 3> foo;
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
gl_out[gl_InvocationID].foo = _27[gl_InvocationID];
gl_out[gl_InvocationID].gl_Position = float4(1.0);
gl_out[gl_InvocationID].foo[0] = float(gl_InvocationID);
gl_out[gl_InvocationID].foo[1] = float(gl_InvocationID) + 1.0;
gl_out[gl_InvocationID].foo[2] = float(gl_InvocationID) + 2.0;
}

View File

@ -0,0 +1,70 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
struct Verts
{
float a;
float2 b;
};
struct main0_out
{
float Verts_a;
float2 Verts_b;
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
spvUnsafeArray<Verts, 4> _27 = spvUnsafeArray<Verts, 4>({ Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) } });
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
gl_out[gl_InvocationID].Verts_a = _27[gl_InvocationID].a;
gl_out[gl_InvocationID].Verts_b = _27[gl_InvocationID].b;
gl_out[gl_InvocationID].gl_Position = float4(1.0);
gl_out[gl_InvocationID].Verts_a = float(gl_InvocationID);
}

View File

@ -0,0 +1,83 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
struct _RESERVED_IDENTIFIER_FIXUP_gl_PerVertex
{
float4 _RESERVED_IDENTIFIER_FIXUP_gl_Position;
float _RESERVED_IDENTIFIER_FIXUP_gl_PointSize;
spvUnsafeArray<float, 1> _RESERVED_IDENTIFIER_FIXUP_gl_ClipDistance;
spvUnsafeArray<float, 1> _RESERVED_IDENTIFIER_FIXUP_gl_CullDistance;
};
struct Verts
{
float a;
float2 b;
};
constant spvUnsafeArray<float, 1> _40 = spvUnsafeArray<float, 1>({ 0.0 });
constant spvUnsafeArray<float, 1> _41 = spvUnsafeArray<float, 1>({ 0.0 });
struct main0_out
{
float Verts_a;
float2 Verts_b;
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
spvUnsafeArray<_RESERVED_IDENTIFIER_FIXUP_gl_PerVertex, 4> _18 = spvUnsafeArray<_RESERVED_IDENTIFIER_FIXUP_gl_PerVertex, 4>({ _RESERVED_IDENTIFIER_FIXUP_gl_PerVertex{ float4(0.0), 0.0, spvUnsafeArray<float, 1>({ 0.0 }), spvUnsafeArray<float, 1>({ 0.0 }) }, _RESERVED_IDENTIFIER_FIXUP_gl_PerVertex{ float4(0.0), 0.0, spvUnsafeArray<float, 1>({ 0.0 }), spvUnsafeArray<float, 1>({ 0.0 }) }, _RESERVED_IDENTIFIER_FIXUP_gl_PerVertex{ float4(0.0), 0.0, spvUnsafeArray<float, 1>({ 0.0 }), spvUnsafeArray<float, 1>({ 0.0 }) }, _RESERVED_IDENTIFIER_FIXUP_gl_PerVertex{ float4(0.0), 0.0, spvUnsafeArray<float, 1>({ 0.0 }), spvUnsafeArray<float, 1>({ 0.0 }) } });
spvUnsafeArray<Verts, 4> _28 = spvUnsafeArray<Verts, 4>({ Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) }, Verts{ 0.0, float2(0.0) } });
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
gl_out[gl_InvocationID].gl_Position = _18[gl_InvocationID]._RESERVED_IDENTIFIER_FIXUP_gl_Position;
gl_out[gl_InvocationID].Verts_a = _28[gl_InvocationID].a;
gl_out[gl_InvocationID].Verts_b = _28[gl_InvocationID].b;
gl_out[gl_InvocationID].gl_Position = float4(1.0);
gl_out[gl_InvocationID].Verts_a = float(gl_InvocationID);
}

View File

@ -0,0 +1,69 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
struct Foo
{
float a;
float2 b;
float4 c;
};
struct main0_out
{
Foo foo;
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
spvUnsafeArray<Foo, 4> _27 = spvUnsafeArray<Foo, 4>({ Foo{ 0.0, float2(0.0), float4(0.0) }, Foo{ 0.0, float2(0.0), float4(0.0) }, Foo{ 0.0, float2(0.0), float4(0.0) }, Foo{ 0.0, float2(0.0), float4(0.0) } });
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
gl_out[gl_InvocationID].foo = _27[gl_InvocationID];
gl_out[gl_InvocationID].gl_Position = float4(1.0);
gl_out[gl_InvocationID].foo.a = float(gl_InvocationID);
}

View File

@ -0,0 +1,62 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
constant spvUnsafeArray<float, 4> _25 = spvUnsafeArray<float, 4>({ 0.0, 0.0, 0.0, 0.0 });
struct main0_out
{
float v;
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
gl_out[gl_InvocationID].v = _25[gl_InvocationID];
gl_out[gl_InvocationID].gl_Position = float4(1.0);
gl_out[gl_InvocationID].v = float(gl_InvocationID);
}

View File

@ -0,0 +1,78 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
constant spvUnsafeArray<float, 2> _27 = spvUnsafeArray<float, 2>({ 0.0, 0.0 });
constant spvUnsafeArray<float, 4> _33 = spvUnsafeArray<float, 4>({ 0.0, 0.0, 0.0, 0.0 });
struct main0_out
{
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(0.0);
gl_out[gl_InvocationID].gl_Position = float4(1.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(1.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(2.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(3.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(4.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(5.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(6.0);
}

View File

@ -0,0 +1,72 @@
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
constant spvUnsafeArray<float, 2> _27 = spvUnsafeArray<float, 2>({ 0.0, 0.0 });
constant spvUnsafeArray<float, 4> _33 = spvUnsafeArray<float, 4>({ 0.0, 0.0, 0.0, 0.0 });
struct main0_out
{
float4 gl_Position;
};
kernel void main0(uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLTriangleTessellationFactorsHalf* spvTessLevel [[buffer(26)]])
{
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(0.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(0.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor = half(0.0);
gl_out[gl_InvocationID].gl_Position = float4(1.0);
spvTessLevel[gl_PrimitiveID].insideTessellationFactor = half(1.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(3.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(4.0);
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(5.0);
}

View File

@ -0,0 +1,70 @@
#version 450
layout(vertices = 4) out;
layout(location = 0) patch out vert
{
float v0;
float v1;
} _5;
layout(location = 2) patch out vert_patch
{
float v2;
float v3;
} patches[2];
layout(location = 6) patch out float v2;
layout(location = 7) out float v3[4];
layout(location = 8) out vert2
{
float v4;
float v5;
} verts[4];
const vec4 _3_0_init[4] = vec4[](vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0));
const float _3_1_init[4] = float[](0.0, 0.0, 0.0, 0.0);
const float _6_0_init[2] = float[](0.0, 0.0);
const float _6_1_init[2] = float[](0.0, 0.0);
const float _7_init = 0.0;
const float _8_init[4] = float[](0.0, 0.0, 0.0, 0.0);
const float _9_0_init[4] = float[](0.0, 0.0, 0.0, 0.0);
const float _9_1_init[4] = float[](0.0, 0.0, 0.0, 0.0);
void main()
{
gl_out[gl_InvocationID].gl_Position = _3_0_init[gl_InvocationID];
gl_out[gl_InvocationID].gl_PointSize = _3_1_init[gl_InvocationID];
if (gl_InvocationID == 0)
{
_5.v0 = 0.0;
}
if (gl_InvocationID == 0)
{
_5.v1 = 0.0;
}
if (gl_InvocationID == 0)
{
patches[0].v2 = _6_0_init[0];
}
if (gl_InvocationID == 0)
{
patches[1].v2 = _6_0_init[1];
}
if (gl_InvocationID == 0)
{
patches[0].v3 = _6_1_init[0];
}
if (gl_InvocationID == 0)
{
patches[1].v3 = _6_1_init[1];
}
if (gl_InvocationID == 0)
{
v2 = _7_init;
}
v3[gl_InvocationID] = _8_init[gl_InvocationID];
verts[gl_InvocationID].v4 = _9_0_init[gl_InvocationID];
verts[gl_InvocationID].v5 = _9_1_init[gl_InvocationID];
gl_out[gl_InvocationID].gl_Position = vec4(1.0);
}

View File

@ -0,0 +1,24 @@
#version 450
layout(vertices = 4) out;
const float _5_init[2] = float[](0.0, 0.0);
const float _6_init[4] = float[](0.0, 0.0, 0.0, 0.0);
void main()
{
if (gl_InvocationID == 0)
{
gl_TessLevelInner = _5_init;
}
if (gl_InvocationID == 0)
{
gl_TessLevelOuter = _6_init;
}
gl_out[gl_InvocationID].gl_Position = vec4(1.0);
gl_TessLevelInner[0] = 1.0;
gl_TessLevelInner[1] = 2.0;
gl_TessLevelOuter[0] = 3.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 5.0;
gl_TessLevelOuter[3] = 6.0;
}

View File

@ -13,11 +13,12 @@ layout(location = 0) out Vert
} _3;
layout(location = 2) out Foo foo;
const Foo _4_init = Foo(0.0, 0.0);
void main()
{
_3.a = 0.0;
_3.b = 0.0;
foo = Foo(0.0, 0.0);
foo = _4_init;
}

View File

@ -2,10 +2,12 @@
layout(location = 0) out vec4 FragColors[2];
layout(location = 2) out vec4 FragColor;
const vec4 _3_init[2] = vec4[](vec4(1.0, 2.0, 3.0, 4.0), vec4(10.0));
const vec4 _4_init = vec4(5.0);
void main()
{
FragColors = vec4[](vec4(1.0, 2.0, 3.0, 4.0), vec4(10.0));
FragColor = vec4(5.0);
FragColors = _3_init;
FragColor = _4_init;
}

View File

@ -0,0 +1,80 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 48
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %foo
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %foo "foo"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %foo Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%uint_3 = OpConstant %uint 3
%_arr_float_uint_3 = OpTypeArray %float %uint_3
%_arr__arr_float_uint_3_uint_4 = OpTypeArray %_arr_float_uint_3 %uint_4
%_ptr_Output__arr__arr_float_uint_3_uint_4 = OpTypePointer Output %_arr__arr_float_uint_3_uint_4
%foo_zero = OpConstantNull %_arr__arr_float_uint_3_uint_4
%foo = OpVariable %_ptr_Output__arr__arr_float_uint_3_uint_4 Output %foo_zero
%_ptr_Output_float = OpTypePointer Output %float
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%float_2 = OpConstant %float 2
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpLoad %int %gl_InvocationID
%31 = OpLoad %int %gl_InvocationID
%32 = OpConvertSToF %float %31
%34 = OpAccessChain %_ptr_Output_float %foo %30 %int_0
OpStore %34 %32
%35 = OpLoad %int %gl_InvocationID
%37 = OpLoad %int %gl_InvocationID
%38 = OpConvertSToF %float %37
%39 = OpFAdd %float %38 %float_1
%40 = OpAccessChain %_ptr_Output_float %foo %35 %int_1
OpStore %40 %39
%41 = OpLoad %int %gl_InvocationID
%43 = OpLoad %int %gl_InvocationID
%44 = OpConvertSToF %float %43
%46 = OpFAdd %float %44 %float_2
%47 = OpAccessChain %_ptr_Output_float %foo %41 %int_2
OpStore %47 %46
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,70 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 35
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %verts
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %Verts "Verts"
OpMemberName %Verts 0 "a"
OpMemberName %Verts 1 "b"
OpName %verts "verts"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %Verts Block
OpDecorate %verts Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
;%gl_out_zero = OpConstantNull %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output ;%gl_out_zero
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%v2float = OpTypeVector %float 2
%Verts = OpTypeStruct %float %v2float
%_arr_Verts_uint_4 = OpTypeArray %Verts %uint_4
%_ptr_Output__arr_Verts_uint_4 = OpTypePointer Output %_arr_Verts_uint_4
%verts_zero = OpConstantNull %_arr_Verts_uint_4
%verts = OpVariable %_ptr_Output__arr_Verts_uint_4 Output %verts_zero
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpLoad %int %gl_InvocationID
%31 = OpLoad %int %gl_InvocationID
%32 = OpConvertSToF %float %31
%34 = OpAccessChain %_ptr_Output_float %verts %30 %int_0
OpStore %34 %32
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,70 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 35
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %verts
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %Verts "Verts"
OpMemberName %Verts 0 "a"
OpMemberName %Verts 1 "b"
OpName %verts "verts"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %Verts Block
OpDecorate %verts Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out_zero = OpConstantNull %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output %gl_out_zero
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%v2float = OpTypeVector %float 2
%Verts = OpTypeStruct %float %v2float
%_arr_Verts_uint_4 = OpTypeArray %Verts %uint_4
%_ptr_Output__arr_Verts_uint_4 = OpTypePointer Output %_arr_Verts_uint_4
%verts_zero = OpConstantNull %_arr_Verts_uint_4
%verts = OpVariable %_ptr_Output__arr_Verts_uint_4 Output %verts_zero
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpLoad %int %gl_InvocationID
%31 = OpLoad %int %gl_InvocationID
%32 = OpConvertSToF %float %31
%34 = OpAccessChain %_ptr_Output_float %verts %30 %int_0
OpStore %34 %32
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,69 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 35
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %foo
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %Foo "Foo"
OpMemberName %Foo 0 "a"
OpMemberName %Foo 1 "b"
OpMemberName %Foo 2 "c"
OpName %foo "foo"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %foo Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%v2float = OpTypeVector %float 2
%Foo = OpTypeStruct %float %v2float %v4float
%_arr_Foo_uint_4 = OpTypeArray %Foo %uint_4
%_ptr_Output__arr_Foo_uint_4 = OpTypePointer Output %_arr_Foo_uint_4
%foo_zero = OpConstantNull %_arr_Foo_uint_4
%foo = OpVariable %_ptr_Output__arr_Foo_uint_4 Output %foo_zero
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpLoad %int %gl_InvocationID
%31 = OpLoad %int %gl_InvocationID
%32 = OpConvertSToF %float %31
%34 = OpAccessChain %_ptr_Output_float %foo %30 %int_0
OpStore %34 %32
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,63 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 33
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %v
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %v "v"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %v Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
%v_zero = OpConstantNull %_arr_float_uint_4
%v = OpVariable %_ptr_Output__arr_float_uint_4 Output %v_zero
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%28 = OpLoad %int %gl_InvocationID
%29 = OpLoad %int %gl_InvocationID
%30 = OpConvertSToF %float %29
%32 = OpAccessChain %_ptr_Output_float %v %28
OpStore %32 %30
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,88 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 47
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %gl_TessLevelInner %gl_TessLevelOuter
OpExecutionMode %main OutputVertices 4
OpExecutionMode %main Quads
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %gl_TessLevelInner "gl_TessLevelInner"
OpName %gl_TessLevelOuter "gl_TessLevelOuter"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %gl_TessLevelInner Patch
OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner
OpDecorate %gl_TessLevelOuter Patch
OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%uint_2 = OpConstant %uint 2
%_arr_float_uint_2 = OpTypeArray %float %uint_2
%_ptr_Output__arr_float_uint_2 = OpTypePointer Output %_arr_float_uint_2
%inner_zero = OpConstantNull %_arr_float_uint_2
%gl_TessLevelInner = OpVariable %_ptr_Output__arr_float_uint_2 Output %inner_zero
%_ptr_Output_float = OpTypePointer Output %float
%int_1 = OpConstant %int 1
%float_2 = OpConstant %float 2
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
%outer_zero = OpConstantNull %_arr_float_uint_4
%gl_TessLevelOuter = OpVariable %_ptr_Output__arr_float_uint_4 Output %outer_zero
%float_3 = OpConstant %float 3
%float_4 = OpConstant %float 4
%int_2 = OpConstant %int 2
%float_5 = OpConstant %float 5
%int_3 = OpConstant %int 3
%float_6 = OpConstant %float 6
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_0
OpStore %30 %float_1
%33 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_1
OpStore %33 %float_2
%38 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_0
OpStore %38 %float_3
%40 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_1
OpStore %40 %float_4
%43 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_2
OpStore %43 %float_5
%46 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_3
OpStore %46 %float_6
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,88 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 47
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %gl_TessLevelInner %gl_TessLevelOuter
OpExecutionMode %main OutputVertices 4
OpExecutionMode %main Triangles
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %gl_TessLevelInner "gl_TessLevelInner"
OpName %gl_TessLevelOuter "gl_TessLevelOuter"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %gl_TessLevelInner Patch
OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner
OpDecorate %gl_TessLevelOuter Patch
OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%uint_2 = OpConstant %uint 2
%_arr_float_uint_2 = OpTypeArray %float %uint_2
%_ptr_Output__arr_float_uint_2 = OpTypePointer Output %_arr_float_uint_2
%inner_zero = OpConstantNull %_arr_float_uint_2
%gl_TessLevelInner = OpVariable %_ptr_Output__arr_float_uint_2 Output %inner_zero
%_ptr_Output_float = OpTypePointer Output %float
%int_1 = OpConstant %int 1
%float_2 = OpConstant %float 2
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
%outer_zero = OpConstantNull %_arr_float_uint_4
%gl_TessLevelOuter = OpVariable %_ptr_Output__arr_float_uint_4 Output %outer_zero
%float_3 = OpConstant %float 3
%float_4 = OpConstant %float 4
%int_2 = OpConstant %int 2
%float_5 = OpConstant %float 5
%int_3 = OpConstant %int 3
%float_6 = OpConstant %float 6
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_0
OpStore %30 %float_1
%33 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_1
OpStore %33 %float_2
%38 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_0
OpStore %38 %float_3
%40 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_1
OpStore %40 %float_4
%43 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_2
OpStore %43 %float_5
%46 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_3
OpStore %46 %float_6
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,101 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 42
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %_ %patches %v2 %v3 %verts
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %vert "vert"
OpMemberName %vert 0 "v0"
OpMemberName %vert 1 "v1"
OpName %_ ""
OpName %vert_patch "vert_patch"
OpMemberName %vert_patch 0 "v2"
OpMemberName %vert_patch 1 "v3"
OpName %patches "patches"
OpName %v2 "v2"
OpName %v3 "v3"
OpName %vert2 "vert2"
OpMemberName %vert2 0 "v4"
OpMemberName %vert2 1 "v5"
OpName %verts "verts"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpMemberDecorate %vert 0 Patch
OpMemberDecorate %vert 1 Patch
OpDecorate %vert Block
OpDecorate %_ Location 0
OpMemberDecorate %vert_patch 0 Patch
OpMemberDecorate %vert_patch 1 Patch
OpDecorate %vert_patch Block
OpDecorate %patches Location 2
OpDecorate %v2 Patch
OpDecorate %v2 Location 6
OpDecorate %v3 Location 7
OpDecorate %vert2 Block
OpDecorate %verts Location 8
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out_zero = OpConstantNull %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output %gl_out_zero
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%vert = OpTypeStruct %float %float
%_ptr_Output_vert = OpTypePointer Output %vert
%__zero = OpConstantNull %vert
%_ = OpVariable %_ptr_Output_vert Output %__zero
%vert_patch = OpTypeStruct %float %float
%uint_2 = OpConstant %uint 2
%_arr_vert_patch_uint_2 = OpTypeArray %vert_patch %uint_2
%_ptr_Output__arr_vert_patch_uint_2 = OpTypePointer Output %_arr_vert_patch_uint_2
%patches_zero = OpConstantNull %_arr_vert_patch_uint_2
%patches = OpVariable %_ptr_Output__arr_vert_patch_uint_2 Output %patches_zero
%_ptr_Output_float = OpTypePointer Output %float
%v2_zero = OpConstantNull %float
%v2 = OpVariable %_ptr_Output_float Output %v2_zero
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
%v3_zero = OpConstantNull %_arr_float_uint_4
%v3 = OpVariable %_ptr_Output__arr_float_uint_4 Output %v3_zero
%vert2 = OpTypeStruct %float %float
%_arr_vert2_uint_4 = OpTypeArray %vert2 %uint_4
%_ptr_Output__arr_vert2_uint_4 = OpTypePointer Output %_arr_vert2_uint_4
%verts_zero = OpConstantNull %_arr_vert2_uint_4
%verts = OpVariable %_ptr_Output__arr_vert2_uint_4 Output %verts_zero
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,87 @@
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 47
; Schema: 0
OpCapability Tessellation
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint TessellationControl %main "main" %gl_out %gl_InvocationID %gl_TessLevelInner %gl_TessLevelOuter
OpExecutionMode %main OutputVertices 4
OpSource GLSL 450
OpName %main "main"
OpName %gl_PerVertex "gl_PerVertex"
OpMemberName %gl_PerVertex 0 "gl_Position"
OpMemberName %gl_PerVertex 1 "gl_PointSize"
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
OpName %gl_out "gl_out"
OpName %gl_InvocationID "gl_InvocationID"
OpName %gl_TessLevelInner "gl_TessLevelInner"
OpName %gl_TessLevelOuter "gl_TessLevelOuter"
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
OpDecorate %gl_PerVertex Block
OpDecorate %gl_InvocationID BuiltIn InvocationId
OpDecorate %gl_TessLevelInner Patch
OpDecorate %gl_TessLevelInner BuiltIn TessLevelInner
OpDecorate %gl_TessLevelOuter Patch
OpDecorate %gl_TessLevelOuter BuiltIn TessLevelOuter
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
%uint_4 = OpConstant %uint 4
%_arr_gl_PerVertex_uint_4 = OpTypeArray %gl_PerVertex %uint_4
%_ptr_Output__arr_gl_PerVertex_uint_4 = OpTypePointer Output %_arr_gl_PerVertex_uint_4
%gl_out = OpVariable %_ptr_Output__arr_gl_PerVertex_uint_4 Output
%int = OpTypeInt 32 1
%_ptr_Input_int = OpTypePointer Input %int
%gl_InvocationID = OpVariable %_ptr_Input_int Input
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%22 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%_ptr_Output_v4float = OpTypePointer Output %v4float
%uint_2 = OpConstant %uint 2
%_arr_float_uint_2 = OpTypeArray %float %uint_2
%_ptr_Output__arr_float_uint_2 = OpTypePointer Output %_arr_float_uint_2
%inner_zero = OpConstantNull %_arr_float_uint_2
%gl_TessLevelInner = OpVariable %_ptr_Output__arr_float_uint_2 Output %inner_zero
%_ptr_Output_float = OpTypePointer Output %float
%int_1 = OpConstant %int 1
%float_2 = OpConstant %float 2
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Output__arr_float_uint_4 = OpTypePointer Output %_arr_float_uint_4
%outer_zero = OpConstantNull %_arr_float_uint_4
%gl_TessLevelOuter = OpVariable %_ptr_Output__arr_float_uint_4 Output %outer_zero
%float_3 = OpConstant %float 3
%float_4 = OpConstant %float 4
%int_2 = OpConstant %int 2
%float_5 = OpConstant %float 5
%int_3 = OpConstant %int 3
%float_6 = OpConstant %float 6
%main = OpFunction %void None %3
%5 = OpLabel
%19 = OpLoad %int %gl_InvocationID
%24 = OpAccessChain %_ptr_Output_v4float %gl_out %19 %int_0
OpStore %24 %22
%30 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_0
OpStore %30 %float_1
%33 = OpAccessChain %_ptr_Output_float %gl_TessLevelInner %int_1
OpStore %33 %float_2
%38 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_0
OpStore %38 %float_3
%40 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_1
OpStore %40 %float_4
%43 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_2
OpStore %43 %float_5
%46 = OpAccessChain %_ptr_Output_float %gl_TessLevelOuter %int_3
OpStore %46 %float_6
OpReturn
OpFunctionEnd

View File

@ -2363,6 +2363,9 @@ void CompilerGLSL::emit_interface_block(const SPIRVariable &var)
require_extension_internal("GL_EXT_shader_io_blocks");
}
// Workaround to make sure we can emit "patch in/out" correctly.
fixup_io_block_patch_qualifiers(var);
// Block names should never alias.
auto block_name = to_name(type.self, false);
@ -2384,7 +2387,8 @@ void CompilerGLSL::emit_interface_block(const SPIRVariable &var)
// Instance names cannot alias block names.
resource_names.insert(block_name);
statement(layout_for_variable(var), qual, block_name);
bool is_patch = has_decoration(var.self, DecorationPatch);
statement(layout_for_variable(var), (is_patch ? "patch " : ""), qual, block_name);
begin_scope();
type.member_name_cache.clear();
@ -3425,41 +3429,7 @@ void CompilerGLSL::emit_resources()
}
else if (var.initializer && maybe_get<SPIRConstant>(var.initializer) != nullptr)
{
// If a StorageClassOutput variable has an initializer, we need to initialize it in main().
auto &entry_func = this->get<SPIRFunction>(ir.default_entry_point);
auto &type = get<SPIRType>(var.basetype);
bool is_block = has_decoration(type.self, DecorationBlock);
if (is_block)
{
// If the initializer is a block, we must initialize each block member one at a time.
uint32_t member_count = uint32_t(type.member_types.size());
for (uint32_t i = 0; i < member_count; i++)
{
// These outputs might not have been properly declared, so don't initialize them in that case.
if (has_member_decoration(type.self, i, DecorationBuiltIn))
{
if (get_member_decoration(type.self, i, DecorationBuiltIn) == BuiltInCullDistance &&
!cull_distance_count)
continue;
if (get_member_decoration(type.self, i, DecorationBuiltIn) == BuiltInClipDistance &&
!clip_distance_count)
continue;
}
entry_func.fixup_hooks_in.push_back([&var, this, i]() {
AccessChainMeta meta;
auto &c = this->get<SPIRConstant>(var.initializer);
auto chain = access_chain_internal(var.self, &i, 1, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, &meta);
statement(chain, " = ", to_expression(c.subconstants[i]), ";");
});
}
}
else
{
entry_func.fixup_hooks_in.push_back(
[&]() { statement(to_name(var.self), " = ", to_expression(var.initializer), ";"); });
}
emit_output_variable_initializer(var);
}
}
@ -3469,6 +3439,140 @@ void CompilerGLSL::emit_resources()
declare_undefined_values();
}
void CompilerGLSL::emit_output_variable_initializer(const SPIRVariable &var)
{
// If a StorageClassOutput variable has an initializer, we need to initialize it in main().
auto &entry_func = this->get<SPIRFunction>(ir.default_entry_point);
auto &type = get<SPIRType>(var.basetype);
bool is_patch = has_decoration(var.self, DecorationPatch);
bool is_block = has_decoration(type.self, DecorationBlock);
bool is_control_point = get_execution_model() == ExecutionModelTessellationControl && !is_patch;
if (is_block)
{
uint32_t member_count = uint32_t(type.member_types.size());
bool type_is_array = type.array.size() == 1;
uint32_t array_size = 1;
if (type_is_array)
array_size = to_array_size_literal(type);
uint32_t iteration_count = is_control_point ? 1 : array_size;
// If the initializer is a block, we must initialize each block member one at a time.
for (uint32_t i = 0; i < member_count; i++)
{
// These outputs might not have been properly declared, so don't initialize them in that case.
if (has_member_decoration(type.self, i, DecorationBuiltIn))
{
if (get_member_decoration(type.self, i, DecorationBuiltIn) == BuiltInCullDistance &&
!cull_distance_count)
continue;
if (get_member_decoration(type.self, i, DecorationBuiltIn) == BuiltInClipDistance &&
!clip_distance_count)
continue;
}
// We need to build a per-member array first, essentially transposing from AoS to SoA.
// This code path hits when we have an array of blocks.
string lut_name;
if (type_is_array)
{
lut_name = join("_", var.self, "_", i, "_init");
uint32_t member_type_id = get<SPIRType>(var.basetype).member_types[i];
auto &member_type = get<SPIRType>(member_type_id);
auto array_type = member_type;
array_type.parent_type = member_type_id;
array_type.array.push_back(array_size);
array_type.array_size_literal.push_back(true);
SmallVector<string> exprs;
exprs.reserve(array_size);
auto &c = get<SPIRConstant>(var.initializer);
for (uint32_t j = 0; j < array_size; j++)
exprs.push_back(to_expression(get<SPIRConstant>(c.subconstants[j]).subconstants[i]));
statement("const ", type_to_glsl(array_type), " ", lut_name, type_to_array_glsl(array_type), " = ",
type_to_glsl_constructor(array_type), "(", merge(exprs, ", "), ");");
}
for (uint32_t j = 0; j < iteration_count; j++)
{
entry_func.fixup_hooks_in.push_back([=, &var]() {
AccessChainMeta meta;
auto &c = this->get<SPIRConstant>(var.initializer);
uint32_t invocation_id = 0;
uint32_t member_index_id = 0;
if (is_control_point)
{
uint32_t ids = ir.increase_bound_by(3);
SPIRType uint_type;
uint_type.basetype = SPIRType::UInt;
uint_type.width = 32;
set<SPIRType>(ids, uint_type);
set<SPIRExpression>(ids + 1, builtin_to_glsl(BuiltInInvocationId, StorageClassInput), ids, true);
set<SPIRConstant>(ids + 2, ids, i, false);
invocation_id = ids + 1;
member_index_id = ids + 2;
}
if (is_patch)
{
statement("if (gl_InvocationID == 0)");
begin_scope();
}
if (type_is_array && !is_control_point)
{
uint32_t indices[2] = { j, i };
auto chain = access_chain_internal(var.self, indices, 2, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, &meta);
statement(chain, " = ", lut_name, "[", j, "];");
}
else if (is_control_point)
{
uint32_t indices[2] = { invocation_id, member_index_id };
auto chain = access_chain_internal(var.self, indices, 2, 0, &meta);
statement(chain, " = ", lut_name, "[", builtin_to_glsl(BuiltInInvocationId, StorageClassInput), "];");
}
else
{
auto chain =
access_chain_internal(var.self, &i, 1, ACCESS_CHAIN_INDEX_IS_LITERAL_BIT, &meta);
statement(chain, " = ", to_expression(c.subconstants[i]), ";");
}
if (is_patch)
end_scope();
});
}
}
}
else if (is_control_point)
{
auto lut_name = join("_", var.self, "_init");
statement("const ", type_to_glsl(type), " ", lut_name, type_to_array_glsl(type),
" = ", to_expression(var.initializer), ";");
entry_func.fixup_hooks_in.push_back([&, lut_name]() {
statement(to_expression(var.self), "[gl_InvocationID] = ", lut_name, "[gl_InvocationID];");
});
}
else
{
auto lut_name = join("_", var.self, "_init");
statement("const ", type_to_glsl(type), " ", lut_name,
type_to_array_glsl(type), " = ", to_expression(var.initializer), ";");
entry_func.fixup_hooks_in.push_back([&, lut_name, is_patch]() {
if (is_patch)
{
statement("if (gl_InvocationID == 0)");
begin_scope();
}
statement(to_expression(var.self), " = ", lut_name, ";");
if (is_patch)
end_scope();
});
}
}
void CompilerGLSL::emit_extension_workarounds(spv::ExecutionModel model)
{
static const char *workaround_types[] = { "int", "ivec2", "ivec3", "ivec4", "uint", "uvec2", "uvec3", "uvec4",
@ -12449,6 +12553,31 @@ const char *CompilerGLSL::to_precision_qualifiers_glsl(uint32_t id)
return flags_to_qualifiers_glsl(type, ir.meta[id].decoration.decoration_flags);
}
void CompilerGLSL::fixup_io_block_patch_qualifiers(const SPIRVariable &var)
{
// Works around weird behavior in glslangValidator where
// a patch out block is translated to just block members getting the decoration.
// To make glslang not complain when we compile again, we have to transform this back to a case where
// the variable itself has Patch decoration, and not members.
auto &type = get<SPIRType>(var.basetype);
if (has_decoration(type.self, DecorationBlock))
{
uint32_t member_count = uint32_t(type.member_types.size());
for (uint32_t i = 0; i < member_count; i++)
{
if (has_member_decoration(type.self, i, DecorationPatch))
{
set_decoration(var.self, DecorationPatch);
break;
}
}
if (has_decoration(var.self, DecorationPatch))
for (uint32_t i = 0; i < member_count; i++)
unset_member_decoration(type.self, i, DecorationPatch);
}
}
string CompilerGLSL::to_qualifiers_glsl(uint32_t id)
{
auto &flags = ir.meta[id].decoration.decoration_flags;

View File

@ -711,6 +711,8 @@ protected:
std::string type_to_glsl_constructor(const SPIRType &type);
std::string argument_decl(const SPIRFunction::Parameter &arg);
virtual std::string to_qualifiers_glsl(uint32_t id);
void fixup_io_block_patch_qualifiers(const SPIRVariable &var);
void emit_output_variable_initializer(const SPIRVariable &var);
const char *to_precision_qualifiers_glsl(uint32_t id);
virtual const char *to_storage_qualifiers_glsl(const SPIRVariable &var);
const char *flags_to_qualifiers_glsl(const SPIRType &type, const Bitset &flags);

View File

@ -1994,8 +1994,22 @@ void CompilerMSL::add_plain_variable_to_interface_block(StorageClass storage, co
}
else
{
entry_func.fixup_hooks_in.push_back(
[=, &var]() { statement(qual_var_name, " = ", to_expression(var.initializer), ";"); });
if (meta.strip_array)
{
entry_func.fixup_hooks_in.push_back([=, &var]() {
uint32_t index = get_extended_decoration(var.self, SPIRVCrossDecorationInterfaceMemberIndex);
statement(to_expression(stage_out_ptr_var_id), "[",
builtin_to_glsl(BuiltInInvocationId, StorageClassInput), "].",
to_member_name(ib_type, index), " = ", to_expression(var.initializer), "[",
builtin_to_glsl(BuiltInInvocationId, StorageClassInput), "];");
});
}
else
{
entry_func.fixup_hooks_in.push_back([=, &var]() {
statement(qual_var_name, " = ", to_expression(var.initializer), ";");
});
}
}
}
@ -2512,6 +2526,8 @@ void CompilerMSL::add_plain_member_variable_to_interface_block(StorageClass stor
qual_var_name += ".interpolate_at_center()";
}
bool flatten_stage_out = false;
if (is_builtin && !meta.strip_array)
{
// For the builtin gl_PerVertex, we cannot treat it as a block anyways,
@ -2530,6 +2546,7 @@ void CompilerMSL::add_plain_member_variable_to_interface_block(StorageClass stor
break;
case StorageClassOutput:
flatten_stage_out = true;
entry_func.fixup_hooks_out.push_back([=, &var, &var_type]() {
statement(qual_var_name, " = ", to_name(var.self), ".", to_member_name(var_type, mbr_idx), ";");
});
@ -2596,16 +2613,34 @@ void CompilerMSL::add_plain_member_variable_to_interface_block(StorageClass stor
set_member_decoration(ib_type.self, ib_mbr_idx, DecorationBuiltIn, builtin);
if (builtin == BuiltInPosition && storage == StorageClassOutput)
qual_pos_var_name = qual_var_name;
}
if (var.storage == StorageClassOutput && var.initializer != ID(0))
const SPIRConstant *c = nullptr;
if (!flatten_stage_out && var.storage == StorageClassOutput &&
var.initializer != ID(0) && (c = maybe_get<SPIRConstant>(var.initializer)))
{
if (meta.strip_array)
{
auto *c = maybe_get<SPIRConstant>(var.initializer);
if (c)
{
entry_func.fixup_hooks_in.push_back([=]() {
statement(qual_var_name, " = ", constant_expression(this->get<SPIRConstant>(c->subconstants[mbr_idx])), ";");
});
}
entry_func.fixup_hooks_in.push_back([=, &var]() {
auto &type = this->get<SPIRType>(var.basetype);
uint32_t index = get_extended_decoration(var.self, SPIRVCrossDecorationInterfaceMemberIndex);
index += mbr_idx;
AccessChainMeta chain_meta;
auto constant_chain = access_chain_internal(var.initializer, &builtin_invocation_id_id, 1, 0, &chain_meta);
statement(to_expression(stage_out_ptr_var_id), "[",
builtin_to_glsl(BuiltInInvocationId, StorageClassInput), "].",
to_member_name(ib_type, index), " = ",
constant_chain, ".", to_member_name(type, mbr_idx), ";");
});
}
else
{
entry_func.fixup_hooks_in.push_back([=]() {
statement(qual_var_name, " = ", constant_expression(
this->get<SPIRConstant>(c->subconstants[mbr_idx])), ";");
});
}
}
@ -6115,6 +6150,15 @@ void CompilerMSL::emit_specialization_constants_and_structs()
mark_scalar_layout_structs(type);
});
bool builtin_block_type_is_required = false;
// Very special case. If gl_PerVertex is initialized as an array (tessellation)
// we have to potentially emit the gl_PerVertex struct type so that we can emit a constant LUT.
ir.for_each_typed_id<SPIRConstant>([&](uint32_t, SPIRConstant &c) {
auto &type = this->get<SPIRType>(c.constant_type);
if (is_array(type) && has_decoration(type.self, DecorationBlock) && is_builtin_type(type))
builtin_block_type_is_required = true;
});
// Very particular use of the soft loop lock.
// align_struct may need to create custom types on the fly, but we don't care about
// these types for purpose of iterating over them in ir.ids_for_type and friends.
@ -6199,7 +6243,7 @@ void CompilerMSL::emit_specialization_constants_and_structs()
has_decoration(type.self, DecorationBlock) || has_decoration(type.self, DecorationBufferBlock);
bool is_builtin_block = is_block && is_builtin_type(type);
bool is_declarable_struct = is_struct && !is_builtin_block;
bool is_declarable_struct = is_struct && (!is_builtin_block || builtin_block_type_is_required);
// We'll declare this later.
if (stage_out_var_id && get_stage_out_struct_type().self == type_id)
@ -9862,7 +9906,14 @@ string CompilerMSL::to_struct_member(const SPIRType &type, uint32_t member_type_
physical_type.basetype != SPIRType::SampledImage)
{
BuiltIn builtin = BuiltInMax;
if (is_member_builtin(type, index, &builtin))
// Special handling. In [[stage_out]] or [[stage_in]] blocks,
// we need flat arrays, but if we're somehow declaring gl_PerVertex for constant array reasons, we want
// template array types to be declared.
bool is_ib_in_out =
((stage_out_var_id && get_stage_out_struct_type().self == type.self) ||
(stage_in_var_id && get_stage_in_struct_type().self == type.self));
if (is_ib_in_out && is_member_builtin(type, index, &builtin))
is_using_builtin_array = true;
array_type = type_to_array_glsl(physical_type);
}
@ -10681,6 +10732,58 @@ void CompilerMSL::entry_point_args_builtin(string &ep_args)
ep_args += ", ";
ep_args += join("device ", get_tess_factor_struct_name(), "* ", tess_factor_buffer_var_name, " [[buffer(",
convert_to_string(msl_options.shader_tess_factor_buffer_index), ")]]");
// Initializer for tess factors must be handled specially since it's never declared as a normal variable.
uint32_t outer_factor_initializer_id = 0;
uint32_t inner_factor_initializer_id = 0;
ir.for_each_typed_id<SPIRVariable>([&](uint32_t, SPIRVariable &var) {
if (!has_decoration(var.self, DecorationBuiltIn) || var.storage != StorageClassOutput || !var.initializer)
return;
BuiltIn builtin = BuiltIn(get_decoration(var.self, DecorationBuiltIn));
if (builtin == BuiltInTessLevelInner)
inner_factor_initializer_id = var.initializer;
else if (builtin == BuiltInTessLevelOuter)
outer_factor_initializer_id = var.initializer;
});
const SPIRConstant *c = nullptr;
if (outer_factor_initializer_id && (c = maybe_get<SPIRConstant>(outer_factor_initializer_id)))
{
auto &entry_func = get<SPIRFunction>(ir.default_entry_point);
entry_func.fixup_hooks_in.push_back([=]() {
uint32_t components = get_execution_mode_bitset().get(ExecutionModeTriangles) ? 3 : 4;
for (uint32_t i = 0; i < components; i++)
{
statement(builtin_to_glsl(BuiltInTessLevelOuter, StorageClassOutput), "[", i, "] = ",
"half(", to_expression(c->subconstants[i]), ");");
}
});
}
if (inner_factor_initializer_id && (c = maybe_get<SPIRConstant>(inner_factor_initializer_id)))
{
auto &entry_func = get<SPIRFunction>(ir.default_entry_point);
if (get_execution_mode_bitset().get(ExecutionModeTriangles))
{
entry_func.fixup_hooks_in.push_back([=]() {
statement(builtin_to_glsl(BuiltInTessLevelInner, StorageClassOutput), " = ", "half(",
to_expression(c->subconstants[0]), ");");
});
}
else
{
entry_func.fixup_hooks_in.push_back([=]() {
for (uint32_t i = 0; i < 2; i++)
{
statement(builtin_to_glsl(BuiltInTessLevelInner, StorageClassOutput), "[", i, "] = ",
"half(", to_expression(c->subconstants[i]), ");");
}
});
}
}
if (stage_in_var_id)
{
if (!ep_args.empty())