| 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 |
|
| 7 |
using namespace metal; |
| 8 |
|
| 9 |
template<typename T, size_t Num> |
| 10 |
struct 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 |
|
| 47 |
struct Matrices |
| 48 |
{ |
| 49 |
float4x4 vpMatrix; |
| 50 |
float4x4 wMatrix; |
| 51 |
float4x3 wMatrix4x3; |
| 52 |
float3x4 wMatrix3x4; |
| 53 |
}; |
| 54 |
|
| 55 |
struct main0_out |
| 56 |
{ |
| 57 |
float3 OutNormal [[user(locn0)]]; |
| 58 |
float4 OutWorldPos_0 [[user(locn1)]]; |
| 59 |
float4 OutWorldPos_1 [[user(locn2)]]; |
| 60 |
float4 OutWorldPos_2 [[user(locn3)]]; |
| 61 |
float4 OutWorldPos_3 [[user(locn4)]]; |
| 62 |
float4 gl_Position [[position]]; |
| 63 |
}; |
| 64 |
|
| 65 |
struct main0_in |
| 66 |
{ |
| 67 |
float3 InPos [[attribute(0)]]; |
| 68 |
float3 InNormal [[attribute(1)]]; |
| 69 |
}; |
| 70 |
|
| 71 |
vertex main0_out main0(main0_in in [[stage_in]], constant Matrices& _22 [[buffer(0)]]) |
| 72 |
{ |
| 73 |
main0_out out = {}; |
| 74 |
spvUnsafeArray<float4, 4> OutWorldPos = {}; |
| 75 |
out.gl_Position = (_22.vpMatrix * _22.wMatrix) * float4(in.InPos, 1.0); |
| 76 |
OutWorldPos[0] = _22.wMatrix * float4(in.InPos, 1.0); |
| 77 |
OutWorldPos[1] = float4(in.InPos, 1.0) * _22.wMatrix; |
| 78 |
OutWorldPos[2] = _22.wMatrix3x4 * in.InPos; |
| 79 |
OutWorldPos[3] = in.InPos * _22.wMatrix4x3; |
| 80 |
out.OutNormal = (_22.wMatrix * float4(in.InNormal, 0.0)).xyz; |
| 81 |
out.OutWorldPos_0 = OutWorldPos[0]; |
| 82 |
out.OutWorldPos_1 = OutWorldPos[1]; |
| 83 |
out.OutWorldPos_2 = OutWorldPos[2]; |
| 84 |
out.OutWorldPos_3 = OutWorldPos[3]; |
| 85 |
return out; |
| 86 |
} |
| 87 |
|