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 main0_out 48{ 49 float3 vVertex; 50}; 51 52struct main0_patchOut 53{ 54 spvUnsafeArray<float3, 2> vPatch; 55}; 56 57struct main0_in 58{ 59 float3 vInput [[attribute(0)]]; 60}; 61 62kernel 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 main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], threadgroup main0_in* gl_in [[threadgroup(0)]]) 63{ 64 device main0_out* gl_out = &spvOut[gl_PrimitiveID * 4]; 65 device main0_patchOut& patchOut = spvPatchOut[gl_PrimitiveID]; 66 if (gl_InvocationID < spvIndirectParams[0]) 67 gl_in[gl_InvocationID] = in; 68 threadgroup_barrier(mem_flags::mem_threadgroup); 69 if (gl_InvocationID >= 4) 70 return; 71 gl_out[gl_InvocationID].vVertex = gl_in[gl_InvocationID].vInput + gl_in[gl_InvocationID ^ 1].vInput; 72 threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup); 73 if (gl_InvocationID == 0) 74 { 75 patchOut.vPatch[0] = float3(10.0); 76 patchOut.vPatch[1] = float3(20.0); 77 spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(1.0); 78 spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(2.0); 79 spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(3.0); 80 spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(4.0); 81 spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(1.0); 82 spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(2.0); 83 } 84} 85 86