1#pragma clang diagnostic ignored "-Wmissing-prototypes" 2#pragma clang diagnostic ignored "-Wmissing-braces" 3 4#include <metal_stdlib> 5#include <simd/simd.h> 6 7using namespace metal; 8 9template<typename T, size_t Num> 10struct spvUnsafeArray 11{ 12 T elements[Num ? Num : 1]; 13 14 thread T& operator [] (size_t pos) thread 15 { 16 return elements[pos]; 17 } 18 constexpr const thread T& operator [] (size_t pos) const thread 19 { 20 return elements[pos]; 21 } 22 23 device T& operator [] (size_t pos) device 24 { 25 return elements[pos]; 26 } 27 constexpr const device T& operator [] (size_t pos) const device 28 { 29 return elements[pos]; 30 } 31 32 constexpr const constant T& operator [] (size_t pos) const constant 33 { 34 return elements[pos]; 35 } 36 37 threadgroup T& operator [] (size_t pos) threadgroup 38 { 39 return elements[pos]; 40 } 41 constexpr const threadgroup T& operator [] (size_t pos) const threadgroup 42 { 43 return elements[pos]; 44 } 45}; 46 47struct gl_PerVertex 48{ 49 float4 gl_Position; 50 float gl_PointSize; 51 spvUnsafeArray<float, 1> gl_ClipDistance; 52 spvUnsafeArray<float, 1> gl_CullDistance; 53}; 54 55struct main0_out 56{ 57 float4 v0; 58 float gl_PointSize; 59}; 60 61struct main0_patchOut 62{ 63 spvUnsafeArray<float4, 2> v1; 64 float4 v3; 65}; 66 67kernel void main0(uint3 gl_GlobalInvocationID [[thread_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]]) 68{ 69 device main0_out* gl_out = &spvOut[gl_GlobalInvocationID.x - gl_GlobalInvocationID.x % 4]; 70 threadgroup gl_PerVertex spvStoragegl_out_masked[8][4]; 71 threadgroup gl_PerVertex (&gl_out_masked)[4] = spvStoragegl_out_masked[(gl_GlobalInvocationID.x / 4) % 8]; 72 device main0_patchOut& patchOut = spvPatchOut[gl_GlobalInvocationID.x / 4]; 73 uint gl_InvocationID = gl_GlobalInvocationID.x % 4; 74 uint gl_PrimitiveID = min(gl_GlobalInvocationID.x / 4, spvIndirectParams[1] - 1); 75 gl_out[gl_InvocationID].v0 = float4(1.0); 76 gl_out[gl_InvocationID].v0.z = 3.0; 77 if (gl_InvocationID == 0) 78 { 79 patchOut.v1[0] = float4(2.0); 80 ((device float*)&patchOut.v1[0])[0u] = 3.0; 81 patchOut.v1[1] = float4(2.0); 82 ((device float*)&patchOut.v1[1])[0u] = 5.0; 83 } 84 patchOut.v3 = float4(5.0); 85 gl_out_masked[gl_InvocationID].gl_Position = float4(10.0); 86 gl_out_masked[gl_InvocationID].gl_Position.z = 20.0; 87 gl_out[gl_InvocationID].gl_PointSize = 40.0; 88} 89 90