1#pragma clang diagnostic ignored "-Wmissing-prototypes" 2 3#include <metal_stdlib> 4#include <simd/simd.h> 5 6using namespace metal; 7 8struct main0_out 9{ 10 float4 gl_Position [[position]]; 11}; 12 13struct main0_in 14{ 15 float4 vA [[attribute(0)]]; 16 float4 vB [[attribute(1)]]; 17 float4 vC [[attribute(2)]]; 18}; 19 20template<typename T> 21T spvFMul(T l, T r) 22{ 23 return fma(l, r, T(0)); 24} 25 26template<typename T, int Cols, int Rows> 27vec<T, Cols> spvFMulVectorMatrix(vec<T, Rows> v, matrix<T, Cols, Rows> m) 28{ 29 vec<T, Cols> res = vec<T, Cols>(0); 30 for (uint i = Rows; i > 0; --i) 31 { 32 vec<T, Cols> tmp(0); 33 for (uint j = 0; j < Cols; ++j) 34 { 35 tmp[j] = m[j][i - 1]; 36 } 37 res = fma(tmp, vec<T, Cols>(v[i - 1]), res); 38 } 39 return res; 40} 41 42template<typename T, int Cols, int Rows> 43vec<T, Rows> spvFMulMatrixVector(matrix<T, Cols, Rows> m, vec<T, Cols> v) 44{ 45 vec<T, Rows> res = vec<T, Rows>(0); 46 for (uint i = Cols; i > 0; --i) 47 { 48 res = fma(m[i - 1], vec<T, Rows>(v[i - 1]), res); 49 } 50 return res; 51} 52 53template<typename T, int LCols, int LRows, int RCols, int RRows> 54matrix<T, RCols, LRows> spvFMulMatrixMatrix(matrix<T, LCols, LRows> l, matrix<T, RCols, RRows> r) 55{ 56 matrix<T, RCols, LRows> res; 57 for (uint i = 0; i < RCols; i++) 58 { 59 vec<T, RCols> tmp(0); 60 for (uint j = 0; j < LCols; j++) 61 { 62 tmp = fma(vec<T, RCols>(r[i][j]), l[j], tmp); 63 } 64 res[i] = tmp; 65 } 66 return res; 67} 68 69template<typename T> 70T spvFAdd(T l, T r) 71{ 72 return fma(T(1), l, r); 73} 74 75template<typename T> 76T spvFSub(T l, T r) 77{ 78 return fma(T(-1), r, l); 79} 80 81vertex main0_out main0(main0_in in [[stage_in]]) 82{ 83 main0_out out = {}; 84 float4 mul = spvFMul(in.vA, in.vB); 85 float4 add = spvFAdd(in.vA, in.vB); 86 float4 sub = spvFSub(in.vA, in.vB); 87 float4 mad = spvFAdd(spvFMul(in.vA, in.vB), in.vC); 88 float4 summed = spvFAdd(spvFAdd(spvFAdd(mul, add), sub), mad); 89 out.gl_Position = summed; 90 return out; 91} 92 93