MSL: Add test for complex control point outputs.
authorHans-Kristian Arntzen <post@arntzen-software.no>
Fri, 9 Apr 2021 08:45:05 +0000 (10:45 +0200)
committerHans-Kristian Arntzen <post@arntzen-software.no>
Mon, 19 Apr 2021 10:10:49 +0000 (12:10 +0200)
reference/opt/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc [new file with mode: 0644]
reference/opt/shaders-msl/tesc/complex-control-point-inout-types.tesc [new file with mode: 0644]
reference/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc [new file with mode: 0644]
reference/shaders-msl/tesc/complex-control-point-inout-types.tesc [new file with mode: 0644]
shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc [new file with mode: 0644]
shaders-msl/tesc/complex-control-point-inout-types.tesc [new file with mode: 0644]
spirv_msl.cpp
spirv_msl.hpp

diff --git a/reference/opt/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc b/reference/opt/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc
new file mode 100644 (file)
index 0000000..b8f4235
--- /dev/null
@@ -0,0 +1,128 @@
+#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 Meep
+{
+    float a;
+    float b;
+};
+
+struct Block
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct Block_1
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct main0_out
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+    float4 gl_Position;
+};
+
+struct main0_in
+{
+    spvUnsafeArray<float, 2> in_a;
+    float in_b;
+    float2x2 in_m;
+    Meep in_meep;
+    spvUnsafeArray<Meep, 2> in_meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+};
+
+kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
+{
+    device main0_out* gl_out = &spvOut[gl_GlobalInvocationID.x - gl_GlobalInvocationID.x % 4];
+    device main0_in* gl_in = &spvIn[min(gl_GlobalInvocationID.x / 4, spvIndirectParams[1] - 1) * spvIndirectParams[0]];
+    uint gl_InvocationID = gl_GlobalInvocationID.x % 4;
+    uint gl_PrimitiveID = min(gl_GlobalInvocationID.x / 4, spvIndirectParams[1]);
+    gl_out[gl_InvocationID].gl_Position = float4(1.0);
+    gl_out[gl_InvocationID].a[0] = gl_in[gl_InvocationID].in_a[0];
+    gl_out[gl_InvocationID].a[1] = gl_in[gl_InvocationID].in_a[1];
+    gl_out[gl_InvocationID].b = gl_in[gl_InvocationID].in_b;
+    gl_out[gl_InvocationID].m = gl_in[gl_InvocationID].in_m;
+    gl_out[gl_InvocationID].meep.a = gl_in[gl_InvocationID].in_meep.a;
+    gl_out[gl_InvocationID].meep.b = gl_in[gl_InvocationID].in_meep.b;
+    gl_out[gl_InvocationID].meeps[0].a = gl_in[gl_InvocationID].in_meeps[0].a;
+    gl_out[gl_InvocationID].meeps[0].b = gl_in[gl_InvocationID].in_meeps[0].b;
+    gl_out[gl_InvocationID].meeps[1].a = gl_in[gl_InvocationID].in_meeps[1].a;
+    gl_out[gl_InvocationID].meeps[1].b = gl_in[gl_InvocationID].in_meeps[1].b;
+    gl_out[gl_InvocationID].Block_a[0] = gl_in[gl_InvocationID].Block_a[0];
+    gl_out[gl_InvocationID].Block_a[1] = gl_in[gl_InvocationID].Block_a[1];
+    gl_out[gl_InvocationID].Block_b = gl_in[gl_InvocationID].Block_b;
+    gl_out[gl_InvocationID].Block_m = gl_in[gl_InvocationID].Block_m;
+    gl_out[gl_InvocationID].Block_meep.a = gl_in[gl_InvocationID].Block_meep.a;
+    gl_out[gl_InvocationID].Block_meep.b = gl_in[gl_InvocationID].Block_meep.b;
+    gl_out[gl_InvocationID].Block_meeps[0].a = gl_in[gl_InvocationID].Block_meeps[0].a;
+    gl_out[gl_InvocationID].Block_meeps[0].b = gl_in[gl_InvocationID].Block_meeps[0].b;
+    gl_out[gl_InvocationID].Block_meeps[1].a = gl_in[gl_InvocationID].Block_meeps[1].a;
+    gl_out[gl_InvocationID].Block_meeps[1].b = gl_in[gl_InvocationID].Block_meeps[1].b;
+}
+
diff --git a/reference/opt/shaders-msl/tesc/complex-control-point-inout-types.tesc b/reference/opt/shaders-msl/tesc/complex-control-point-inout-types.tesc
new file mode 100644 (file)
index 0000000..5fabb45
--- /dev/null
@@ -0,0 +1,132 @@
+#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 Meep
+{
+    float a;
+    float b;
+};
+
+struct Block
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct Block_1
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+};
+
+struct main0_out
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+    float4 gl_Position;
+};
+
+struct main0_in
+{
+    float in_a_0 [[attribute(0)]];
+    float in_a_1 [[attribute(1)]];
+    float in_b [[attribute(2)]];
+    float2 in_m_0 [[attribute(3)]];
+    float2 in_m_1 [[attribute(4)]];
+    float Meep_a [[attribute(5)]];
+    float Meep_b [[attribute(6)]];
+    float Block_a_0 [[attribute(11)]];
+    float Block_a_1 [[attribute(12)]];
+    float Block_b [[attribute(13)]];
+    float2 Block_m_0 [[attribute(14)]];
+    float2 Block_m_1 [[attribute(15)]];
+};
+
+kernel void main0(main0_in in [[stage_in]], 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)]], threadgroup main0_in* gl_in [[threadgroup(0)]])
+{
+    device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
+    if (gl_InvocationID < spvIndirectParams[0])
+        gl_in[gl_InvocationID] = in;
+    threadgroup_barrier(mem_flags::mem_threadgroup);
+    if (gl_InvocationID >= 4)
+        return;
+    gl_out[gl_InvocationID].gl_Position = float4(1.0);
+    gl_out[gl_InvocationID].a[0] = gl_in[gl_InvocationID].in_a_0;
+    gl_out[gl_InvocationID].a[1] = gl_in[gl_InvocationID].in_a_1;
+    gl_out[gl_InvocationID].b = gl_in[gl_InvocationID].in_b;
+    float2x2 _178 = float2x2(gl_in[gl_InvocationID].in_m_0, gl_in[gl_InvocationID].in_m_1);
+    gl_out[gl_InvocationID].m = _178;
+    gl_out[gl_InvocationID].meep.a = gl_in[gl_InvocationID].Meep_a;
+    gl_out[gl_InvocationID].meep.b = gl_in[gl_InvocationID].Meep_b;
+    gl_out[gl_InvocationID].meeps[0].a = 1.0;
+    gl_out[gl_InvocationID].meeps[0].b = 2.0;
+    gl_out[gl_InvocationID].meeps[1].a = 3.0;
+    gl_out[gl_InvocationID].meeps[1].b = 4.0;
+    gl_out[gl_InvocationID].Block_a[0] = gl_in[gl_InvocationID].Block_a_0;
+    gl_out[gl_InvocationID].Block_a[1] = gl_in[gl_InvocationID].Block_a_1;
+    gl_out[gl_InvocationID].Block_b = gl_in[gl_InvocationID].Block_b;
+    float2x2 _216 = float2x2(gl_in[gl_InvocationID].Block_m_0, gl_in[gl_InvocationID].Block_m_1);
+    gl_out[gl_InvocationID].Block_m = _216;
+    gl_out[gl_InvocationID].Block_meep.a = 10.0;
+    gl_out[gl_InvocationID].Block_meep.b = 20.0;
+    gl_out[gl_InvocationID].Block_meeps[0].a = 5.0;
+    gl_out[gl_InvocationID].Block_meeps[0].b = 6.0;
+    gl_out[gl_InvocationID].Block_meeps[1].a = 7.0;
+    gl_out[gl_InvocationID].Block_meeps[1].b = 8.0;
+}
+
diff --git a/reference/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc b/reference/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc
new file mode 100644 (file)
index 0000000..a366218
--- /dev/null
@@ -0,0 +1,134 @@
+#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 Meep
+{
+    float a;
+    float b;
+};
+
+struct Block
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct Block_1
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct main0_out
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+    float4 gl_Position;
+};
+
+struct main0_in
+{
+    spvUnsafeArray<float, 2> in_a;
+    float in_b;
+    float2x2 in_m;
+    Meep in_meep;
+    spvUnsafeArray<Meep, 2> in_meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+};
+
+static inline __attribute__((always_inline))
+void write_in_func(device main0_out* thread & gl_out, thread uint& gl_InvocationID, device main0_in* thread & gl_in)
+{
+    gl_out[gl_InvocationID].gl_Position = float4(1.0);
+    gl_out[gl_InvocationID].a[0] = gl_in[gl_InvocationID].in_a[0];
+    gl_out[gl_InvocationID].a[1] = gl_in[gl_InvocationID].in_a[1];
+    gl_out[gl_InvocationID].b = gl_in[gl_InvocationID].in_b;
+    gl_out[gl_InvocationID].m = gl_in[gl_InvocationID].in_m;
+    gl_out[gl_InvocationID].meep.a = gl_in[gl_InvocationID].in_meep.a;
+    gl_out[gl_InvocationID].meep.b = gl_in[gl_InvocationID].in_meep.b;
+    gl_out[gl_InvocationID].meeps[0].a = gl_in[gl_InvocationID].in_meeps[0].a;
+    gl_out[gl_InvocationID].meeps[0].b = gl_in[gl_InvocationID].in_meeps[0].b;
+    gl_out[gl_InvocationID].meeps[1].a = gl_in[gl_InvocationID].in_meeps[1].a;
+    gl_out[gl_InvocationID].meeps[1].b = gl_in[gl_InvocationID].in_meeps[1].b;
+    gl_out[gl_InvocationID].Block_a[0] = gl_in[gl_InvocationID].Block_a[0];
+    gl_out[gl_InvocationID].Block_a[1] = gl_in[gl_InvocationID].Block_a[1];
+    gl_out[gl_InvocationID].Block_b = gl_in[gl_InvocationID].Block_b;
+    gl_out[gl_InvocationID].Block_m = gl_in[gl_InvocationID].Block_m;
+    gl_out[gl_InvocationID].Block_meep.a = gl_in[gl_InvocationID].Block_meep.a;
+    gl_out[gl_InvocationID].Block_meep.b = gl_in[gl_InvocationID].Block_meep.b;
+    gl_out[gl_InvocationID].Block_meeps[0].a = gl_in[gl_InvocationID].Block_meeps[0].a;
+    gl_out[gl_InvocationID].Block_meeps[0].b = gl_in[gl_InvocationID].Block_meeps[0].b;
+    gl_out[gl_InvocationID].Block_meeps[1].a = gl_in[gl_InvocationID].Block_meeps[1].a;
+    gl_out[gl_InvocationID].Block_meeps[1].b = gl_in[gl_InvocationID].Block_meeps[1].b;
+}
+
+kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], device main0_in* spvIn [[buffer(22)]])
+{
+    device main0_out* gl_out = &spvOut[gl_GlobalInvocationID.x - gl_GlobalInvocationID.x % 4];
+    device main0_in* gl_in = &spvIn[min(gl_GlobalInvocationID.x / 4, spvIndirectParams[1] - 1) * spvIndirectParams[0]];
+    uint gl_InvocationID = gl_GlobalInvocationID.x % 4;
+    uint gl_PrimitiveID = min(gl_GlobalInvocationID.x / 4, spvIndirectParams[1]);
+    write_in_func(gl_out, gl_InvocationID, gl_in);
+}
+
diff --git a/reference/shaders-msl/tesc/complex-control-point-inout-types.tesc b/reference/shaders-msl/tesc/complex-control-point-inout-types.tesc
new file mode 100644 (file)
index 0000000..4bfb1a4
--- /dev/null
@@ -0,0 +1,138 @@
+#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 Meep
+{
+    float a;
+    float b;
+};
+
+struct Block
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+};
+
+struct Block_1
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+};
+
+struct main0_out
+{
+    spvUnsafeArray<float, 2> a;
+    float b;
+    float2x2 m;
+    Meep meep;
+    spvUnsafeArray<Meep, 2> meeps;
+    spvUnsafeArray<float, 2> Block_a;
+    float Block_b;
+    float2x2 Block_m;
+    Meep Block_meep;
+    spvUnsafeArray<Meep, 2> Block_meeps;
+    float4 gl_Position;
+};
+
+struct main0_in
+{
+    float in_a_0 [[attribute(0)]];
+    float in_a_1 [[attribute(1)]];
+    float in_b [[attribute(2)]];
+    float2 in_m_0 [[attribute(3)]];
+    float2 in_m_1 [[attribute(4)]];
+    float Meep_a [[attribute(5)]];
+    float Meep_b [[attribute(6)]];
+    float Block_a_0 [[attribute(11)]];
+    float Block_a_1 [[attribute(12)]];
+    float Block_b [[attribute(13)]];
+    float2 Block_m_0 [[attribute(14)]];
+    float2 Block_m_1 [[attribute(15)]];
+};
+
+static inline __attribute__((always_inline))
+void write_in_func(device main0_out* thread & gl_out, thread uint& gl_InvocationID, threadgroup main0_in* thread & gl_in)
+{
+    gl_out[gl_InvocationID].gl_Position = float4(1.0);
+    gl_out[gl_InvocationID].a[0] = gl_in[gl_InvocationID].in_a_0;
+    gl_out[gl_InvocationID].a[1] = gl_in[gl_InvocationID].in_a_1;
+    gl_out[gl_InvocationID].b = gl_in[gl_InvocationID].in_b;
+    float2x2 _72 = float2x2(gl_in[gl_InvocationID].in_m_0, gl_in[gl_InvocationID].in_m_1);
+    gl_out[gl_InvocationID].m = _72;
+    gl_out[gl_InvocationID].meep.a = gl_in[gl_InvocationID].Meep_a;
+    gl_out[gl_InvocationID].meep.b = gl_in[gl_InvocationID].Meep_b;
+    gl_out[gl_InvocationID].meeps[0].a = 1.0;
+    gl_out[gl_InvocationID].meeps[0].b = 2.0;
+    gl_out[gl_InvocationID].meeps[1].a = 3.0;
+    gl_out[gl_InvocationID].meeps[1].b = 4.0;
+    gl_out[gl_InvocationID].Block_a[0] = gl_in[gl_InvocationID].Block_a_0;
+    gl_out[gl_InvocationID].Block_a[1] = gl_in[gl_InvocationID].Block_a_1;
+    gl_out[gl_InvocationID].Block_b = gl_in[gl_InvocationID].Block_b;
+    float2x2 _134 = float2x2(gl_in[gl_InvocationID].Block_m_0, gl_in[gl_InvocationID].Block_m_1);
+    gl_out[gl_InvocationID].Block_m = _134;
+    gl_out[gl_InvocationID].Block_meep.a = 10.0;
+    gl_out[gl_InvocationID].Block_meep.b = 20.0;
+    gl_out[gl_InvocationID].Block_meeps[0].a = 5.0;
+    gl_out[gl_InvocationID].Block_meeps[0].b = 6.0;
+    gl_out[gl_InvocationID].Block_meeps[1].a = 7.0;
+    gl_out[gl_InvocationID].Block_meeps[1].b = 8.0;
+}
+
+kernel void main0(main0_in in [[stage_in]], 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)]], threadgroup main0_in* gl_in [[threadgroup(0)]])
+{
+    device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4];
+    if (gl_InvocationID < spvIndirectParams[0])
+        gl_in[gl_InvocationID] = in;
+    threadgroup_barrier(mem_flags::mem_threadgroup);
+    if (gl_InvocationID >= 4)
+        return;
+    write_in_func(gl_out, gl_InvocationID, gl_in);
+}
+
diff --git a/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc b/shaders-msl/tesc/complex-control-point-inout-types.multi-patch.tesc
new file mode 100644 (file)
index 0000000..aec8db7
--- /dev/null
@@ -0,0 +1,70 @@
+#version 450
+layout(vertices = 4) out;
+
+struct Meep
+{
+       float a;
+       float b;
+};
+
+layout(location = 0) out float a[][2];
+layout(location = 2) out float b[];
+layout(location = 3) out mat2 m[];
+layout(location = 5) out Meep meep[];
+layout(location = 7) out Meep meeps[][2];
+
+layout(location = 11) out Block
+{
+       float a[2];
+       float b;
+       mat2 m;
+       Meep meep;
+       Meep meeps[2];
+} B[];
+
+layout(location = 0) in float in_a[][2];
+layout(location = 2) in float in_b[];
+layout(location = 3) in mat2 in_m[];
+layout(location = 5) in Meep in_meep[];
+layout(location = 7) in Meep in_meeps[][2];
+
+layout(location = 11) in Block
+{
+       float a[2];
+       float b;
+       mat2 m;
+       Meep meep;
+       Meep meeps[2];
+} in_B[];
+
+void write_in_func()
+{
+       gl_out[gl_InvocationID].gl_Position = vec4(1.0);
+
+       a[gl_InvocationID][0] = in_a[gl_InvocationID][0];
+       a[gl_InvocationID][1] = in_a[gl_InvocationID][1];
+       b[gl_InvocationID] = in_b[gl_InvocationID];
+       m[gl_InvocationID] = in_m[gl_InvocationID];
+       meep[gl_InvocationID].a = in_meep[gl_InvocationID].a;
+       meep[gl_InvocationID].b = in_meep[gl_InvocationID].b;
+       meeps[gl_InvocationID][0].a = in_meeps[gl_InvocationID][0].a;
+       meeps[gl_InvocationID][0].b = in_meeps[gl_InvocationID][0].b;
+       meeps[gl_InvocationID][1].a = in_meeps[gl_InvocationID][1].a;
+       meeps[gl_InvocationID][1].b = in_meeps[gl_InvocationID][1].b;
+
+       B[gl_InvocationID].a[0] = in_B[gl_InvocationID].a[0];
+       B[gl_InvocationID].a[1] = in_B[gl_InvocationID].a[1];
+       B[gl_InvocationID].b = in_B[gl_InvocationID].b;
+       B[gl_InvocationID].m = in_B[gl_InvocationID].m;
+       B[gl_InvocationID].meep.a = in_B[gl_InvocationID].meep.a;
+       B[gl_InvocationID].meep.b = in_B[gl_InvocationID].meep.b;
+       B[gl_InvocationID].meeps[0].a = in_B[gl_InvocationID].meeps[0].a;
+       B[gl_InvocationID].meeps[0].b = in_B[gl_InvocationID].meeps[0].b;
+       B[gl_InvocationID].meeps[1].a = in_B[gl_InvocationID].meeps[1].a;
+       B[gl_InvocationID].meeps[1].b = in_B[gl_InvocationID].meeps[1].b;
+}
+
+void main()
+{
+       write_in_func();
+}
diff --git a/shaders-msl/tesc/complex-control-point-inout-types.tesc b/shaders-msl/tesc/complex-control-point-inout-types.tesc
new file mode 100644 (file)
index 0000000..b7bb21d
--- /dev/null
@@ -0,0 +1,68 @@
+#version 450
+layout(vertices = 4) out;
+
+struct Meep
+{
+       float a;
+       float b;
+};
+
+layout(location = 0) out float a[][2];
+layout(location = 2) out float b[];
+layout(location = 3) out mat2 m[];
+layout(location = 5) out Meep meep[];
+layout(location = 7) out Meep meeps[][2];
+
+layout(location = 11) out Block
+{
+       float a[2];
+       float b;
+       mat2 m;
+       Meep meep;
+       Meep meeps[2];
+} B[];
+
+layout(location = 0) in float in_a[][2];
+layout(location = 2) in float in_b[];
+layout(location = 3) in mat2 in_m[];
+layout(location = 5) in Meep in_meep[];
+
+layout(location = 11) in Block
+{
+       float a[2];
+       float b;
+       mat2 m;
+       // Non-multi-patch path cannot support structs inside structs.
+} in_B[];
+
+void write_in_func()
+{
+       gl_out[gl_InvocationID].gl_Position = vec4(1.0);
+
+       a[gl_InvocationID][0] = in_a[gl_InvocationID][0];
+       a[gl_InvocationID][1] = in_a[gl_InvocationID][1];
+       b[gl_InvocationID] = in_b[gl_InvocationID];
+       m[gl_InvocationID] = in_m[gl_InvocationID];
+       meep[gl_InvocationID].a = in_meep[gl_InvocationID].a;
+       meep[gl_InvocationID].b = in_meep[gl_InvocationID].b;
+       meeps[gl_InvocationID][0].a = 1.0;
+       meeps[gl_InvocationID][0].b = 2.0;
+       meeps[gl_InvocationID][1].a = 3.0;
+       meeps[gl_InvocationID][1].b = 4.0;
+
+       B[gl_InvocationID].a[0] = in_B[gl_InvocationID].a[0];
+       B[gl_InvocationID].a[1] = in_B[gl_InvocationID].a[1];
+       B[gl_InvocationID].b = in_B[gl_InvocationID].b;
+       B[gl_InvocationID].m = in_B[gl_InvocationID].m;
+       B[gl_InvocationID].meep.a = 10.0;
+       B[gl_InvocationID].meep.b = 20.0;
+       B[gl_InvocationID].meeps[0].a = 5.0;
+       B[gl_InvocationID].meeps[0].b = 6.0;
+       B[gl_InvocationID].meeps[1].a = 7.0;
+       B[gl_InvocationID].meeps[1].b = 8.0;
+}
+
+void main()
+{
+       write_in_func();
+}
index 774e08f..82e83c7 100644 (file)
@@ -2196,7 +2196,9 @@ void CompilerMSL::add_plain_variable_to_interface_block(StorageClass storage, co
                uint32_t locn = get_decoration(var.self, DecorationLocation);
                if (storage == StorageClassInput)
                {
-                       type_id = ensure_correct_input_type(var.basetype, locn, location_meta ? location_meta->num_components : 0);
+                       type_id = ensure_correct_input_type(var.basetype, locn,
+                                                           location_meta ? location_meta->num_components : 0,
+                                                           meta.strip_array);
                        if (!location_meta)
                                var.basetype = type_id;
 
@@ -2366,8 +2368,8 @@ void CompilerMSL::add_composite_variable_to_interface_block(StorageClass storage
                        uint32_t locn = get_decoration(var.self, DecorationLocation) + i;
                        if (storage == StorageClassInput)
                        {
-                               var.basetype = ensure_correct_input_type(var.basetype, locn);
-                               uint32_t mbr_type_id = ensure_correct_input_type(usable_type->self, locn);
+                               var.basetype = ensure_correct_input_type(var.basetype, locn, 0, meta.strip_array);
+                               uint32_t mbr_type_id = ensure_correct_input_type(usable_type->self, locn, 0, meta.strip_array);
                                if (storage == StorageClassInput && pull_model_inputs.count(var.self))
                                        ib_type.member_types[ib_mbr_idx] = build_msl_interpolant_type(mbr_type_id, is_noperspective);
                                else
@@ -2712,7 +2714,7 @@ void CompilerMSL::add_plain_member_variable_to_interface_block(StorageClass stor
                uint32_t locn = get_member_decoration(var_type.self, mbr_idx, DecorationLocation);
                if (storage == StorageClassInput)
                {
-                       mbr_type_id = ensure_correct_input_type(mbr_type_id, locn);
+                       mbr_type_id = ensure_correct_input_type(mbr_type_id, locn, 0, meta.strip_array);
                        var_type.member_types[mbr_idx] = mbr_type_id;
                        if (storage == StorageClassInput && pull_model_inputs.count(var.self))
                                ib_type.member_types[ib_mbr_idx] = build_msl_interpolant_type(mbr_type_id, is_noperspective);
@@ -2729,7 +2731,7 @@ void CompilerMSL::add_plain_member_variable_to_interface_block(StorageClass stor
                uint32_t locn = get_accumulated_member_location(var, mbr_idx, meta.strip_array);
                if (storage == StorageClassInput)
                {
-                       mbr_type_id = ensure_correct_input_type(mbr_type_id, locn);
+                       mbr_type_id = ensure_correct_input_type(mbr_type_id, locn, 0, meta.strip_array);
                        var_type.member_types[mbr_idx] = mbr_type_id;
                        if (storage == StorageClassInput && pull_model_inputs.count(var.self))
                                ib_type.member_types[ib_mbr_idx] = build_msl_interpolant_type(mbr_type_id, is_noperspective);
@@ -3604,12 +3606,14 @@ uint32_t CompilerMSL::ensure_correct_builtin_type(uint32_t type_id, BuiltIn buil
 // Ensure that the type is compatible with the shader input.
 // If it is, simply return the given type ID.
 // Otherwise, create a new type, and return its ID.
-uint32_t CompilerMSL::ensure_correct_input_type(uint32_t type_id, uint32_t location, uint32_t num_components)
+uint32_t CompilerMSL::ensure_correct_input_type(uint32_t type_id, uint32_t location, uint32_t num_components, bool strip_array)
 {
        auto &type = get<SPIRType>(type_id);
 
-       // Struct types must match exactly.
-       if (type.basetype == SPIRType::Struct)
+       uint32_t max_array_dimensions = strip_array ? 1 : 0;
+
+       // Struct and array types must match exactly.
+       if (type.basetype == SPIRType::Struct || type.array.size() > max_array_dimensions)
                return type_id;
 
        auto p_va = inputs_by_location.find(location);
index a7533b8..c0525f7 100644 (file)
@@ -824,7 +824,8 @@ protected:
 
        void mark_location_as_used_by_shader(uint32_t location, const SPIRType &type, spv::StorageClass storage);
        uint32_t ensure_correct_builtin_type(uint32_t type_id, spv::BuiltIn builtin);
-       uint32_t ensure_correct_input_type(uint32_t type_id, uint32_t location, uint32_t num_components = 0);
+       uint32_t ensure_correct_input_type(uint32_t type_id, uint32_t location,
+                                          uint32_t num_components, bool strip_array);
 
        void emit_custom_templates();
        void emit_custom_functions();