1#pragma clang diagnostic ignored "-Wmissing-prototypes" 2#pragma clang diagnostic ignored "-Wmissing-braces" 3#pragma clang diagnostic ignored "-Wunused-variable" 4 5#include <metal_stdlib> 6#include <simd/simd.h> 7#include <metal_atomic> 8 9using namespace metal; 10 11template<typename T, size_t Num> 12struct spvUnsafeArray 13{ 14 T elements[Num ? Num : 1]; 15 16 thread T& operator [] (size_t pos) thread 17 { 18 return elements[pos]; 19 } 20 constexpr const thread T& operator [] (size_t pos) const thread 21 { 22 return elements[pos]; 23 } 24 25 device T& operator [] (size_t pos) device 26 { 27 return elements[pos]; 28 } 29 constexpr const device T& operator [] (size_t pos) const device 30 { 31 return elements[pos]; 32 } 33 34 constexpr const constant T& operator [] (size_t pos) const constant 35 { 36 return elements[pos]; 37 } 38 39 threadgroup T& operator [] (size_t pos) threadgroup 40 { 41 return elements[pos]; 42 } 43 constexpr const threadgroup T& operator [] (size_t pos) const threadgroup 44 { 45 return elements[pos]; 46 } 47}; 48 49struct type_StructuredBuffer_v4float 50{ 51 spvUnsafeArray<float4, 1> _m0; 52}; 53 54struct type_Globals 55{ 56 uint2 ShadowTileListGroupSize; 57}; 58 59constant float3 _70 = {}; 60 61struct main0_out 62{ 63 float4 out_var_SV_Target0 [[color(0)]]; 64}; 65 66struct main0_in 67{ 68 uint in_var_TEXCOORD0 [[user(locn0)]]; 69}; 70 71fragment main0_out main0(main0_in in [[stage_in]], const device type_StructuredBuffer_v4float& CulledObjectBoxBounds [[buffer(0)]], constant type_Globals& _Globals [[buffer(1)]], texture2d<uint> RWShadowTileNumCulledObjects [[texture(2)]], device atomic_uint* RWShadowTileNumCulledObjects_atomic [[buffer(2)]], float4 gl_FragCoord [[position]]) 72{ 73 main0_out out = {}; 74 uint2 _77 = uint2(gl_FragCoord.xy); 75 uint _78 = _77.y; 76 uint _83 = _77.x; 77 float2 _91 = float2(float(_83), float((_Globals.ShadowTileListGroupSize.y - 1u) - _78)); 78 float2 _93 = float2(_Globals.ShadowTileListGroupSize); 79 float2 _96 = ((_91 / _93) * float2(2.0)) - float2(1.0); 80 float2 _100 = (((_91 + float2(1.0)) / _93) * float2(2.0)) - float2(1.0); 81 float3 _102 = float3(_100.x, _100.y, _70.z); 82 _102.z = 1.0; 83 uint _103 = in.in_var_TEXCOORD0 * 5u; 84 uint _107 = _103 + 1u; 85 if (all(CulledObjectBoxBounds._m0[_107].xy > _96.xy) && all(CulledObjectBoxBounds._m0[_103].xyz < _102)) 86 { 87 float _122 = _96.x; 88 float _123 = _96.y; 89 spvUnsafeArray<float3, 8> _73; 90 _73[0] = float3(_122, _123, -1000.0); 91 float _126 = _100.x; 92 _73[1] = float3(_126, _123, -1000.0); 93 float _129 = _100.y; 94 _73[2] = float3(_122, _129, -1000.0); 95 _73[3] = float3(_126, _129, -1000.0); 96 _73[4] = float3(_122, _123, 1.0); 97 _73[5] = float3(_126, _123, 1.0); 98 _73[6] = float3(_122, _129, 1.0); 99 _73[7] = float3(_126, _129, 1.0); 100 float3 _155; 101 float3 _158; 102 _155 = float3(-500000.0); 103 _158 = float3(500000.0); 104 for (int _160 = 0; _160 < 8; ) 105 { 106 float3 _166 = _73[_160] - (float3(0.5) * (CulledObjectBoxBounds._m0[_103].xyz + CulledObjectBoxBounds._m0[_107].xyz)); 107 float3 _170 = float3(dot(_166, CulledObjectBoxBounds._m0[_103 + 2u].xyz), dot(_166, CulledObjectBoxBounds._m0[_103 + 3u].xyz), dot(_166, CulledObjectBoxBounds._m0[_103 + 4u].xyz)); 108 _155 = fast::max(_155, _170); 109 _158 = fast::min(_158, _170); 110 _160++; 111 continue; 112 } 113 if (all(_158 < float3(1.0)) && all(_155 > float3(-1.0))) 114 { 115 uint _179 = atomic_fetch_add_explicit((device atomic_uint*)&RWShadowTileNumCulledObjects_atomic[(_78 * _Globals.ShadowTileListGroupSize.x) + _83], 1u, memory_order_relaxed); 116 } 117 } 118 out.out_var_SV_Target0 = float4(0.0); 119 return out; 120} 121 122