Welcome to mirror list, hosted at ThFree Co, Russian Federation.

float-math.invariant-float-math.vert « vert « shaders-msl « opt « reference - github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d8f44bec041040cfe7ce767f2b029fda135e140a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

template<typename T, size_t Num>
struct spvUnsafeArray
{
    T elements[Num ? Num : 1];
    
    thread T& operator [] (size_t pos) thread
    {
        return elements[pos];
    }
    constexpr const thread T& operator [] (size_t pos) const thread
    {
        return elements[pos];
    }
    
    device T& operator [] (size_t pos) device
    {
        return elements[pos];
    }
    constexpr const device T& operator [] (size_t pos) const device
    {
        return elements[pos];
    }
    
    constexpr const constant T& operator [] (size_t pos) const constant
    {
        return elements[pos];
    }
    
    threadgroup T& operator [] (size_t pos) threadgroup
    {
        return elements[pos];
    }
    constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
    {
        return elements[pos];
    }
};

struct Matrices
{
    float4x4 vpMatrix;
    float4x4 wMatrix;
    float4x3 wMatrix4x3;
    float3x4 wMatrix3x4;
};

struct main0_out
{
    float3 OutNormal [[user(locn0)]];
    float4 OutWorldPos_0 [[user(locn1)]];
    float4 OutWorldPos_1 [[user(locn2)]];
    float4 OutWorldPos_2 [[user(locn3)]];
    float4 OutWorldPos_3 [[user(locn4)]];
    float4 gl_Position [[position]];
};

struct main0_in
{
    float3 InPos [[attribute(0)]];
    float3 InNormal [[attribute(1)]];
};

template<typename T>
[[clang::optnone]] T spvFMul(T l, T r)
{
    return fma(l, r, T(0));
}

template<typename T, int Cols, int Rows>
[[clang::optnone]] vec<T, Cols> spvFMulVectorMatrix(vec<T, Rows> v, matrix<T, Cols, Rows> m)
{
    vec<T, Cols> res = vec<T, Cols>(0);
    for (uint i = Rows; i > 0; --i)
    {
        vec<T, Cols> tmp(0);
        for (uint j = 0; j < Cols; ++j)
        {
            tmp[j] = m[j][i - 1];
        }
        res = fma(tmp, vec<T, Cols>(v[i - 1]), res);
    }
    return res;
}

template<typename T, int Cols, int Rows>
[[clang::optnone]] vec<T, Rows> spvFMulMatrixVector(matrix<T, Cols, Rows> m, vec<T, Cols> v)
{
    vec<T, Rows> res = vec<T, Rows>(0);
    for (uint i = Cols; i > 0; --i)
    {
        res = fma(m[i - 1], vec<T, Rows>(v[i - 1]), res);
    }
    return res;
}

template<typename T, int LCols, int LRows, int RCols, int RRows>
[[clang::optnone]] matrix<T, RCols, LRows> spvFMulMatrixMatrix(matrix<T, LCols, LRows> l, matrix<T, RCols, RRows> r)
{
    matrix<T, RCols, LRows> res;
    for (uint i = 0; i < RCols; i++)
    {
        vec<T, RCols> tmp(0);
        for (uint j = 0; j < LCols; j++)
        {
            tmp = fma(vec<T, RCols>(r[i][j]), l[j], tmp);
        }
        res[i] = tmp;
    }
    return res;
}

vertex main0_out main0(main0_in in [[stage_in]], constant Matrices& _22 [[buffer(0)]])
{
    main0_out out = {};
    spvUnsafeArray<float4, 4> OutWorldPos = {};
    float4 _37 = float4(in.InPos, 1.0);
    out.gl_Position = spvFMulMatrixVector(spvFMulMatrixMatrix(_22.vpMatrix, _22.wMatrix), _37);
    OutWorldPos[0] = spvFMulMatrixVector(_22.wMatrix, _37);
    OutWorldPos[1] = spvFMulVectorMatrix(_37, _22.wMatrix);
    OutWorldPos[2] = spvFMulMatrixVector(_22.wMatrix3x4, in.InPos);
    OutWorldPos[3] = spvFMulVectorMatrix(in.InPos, _22.wMatrix4x3);
    out.OutNormal = spvFMulMatrixVector(_22.wMatrix, float4(in.InNormal, 0.0)).xyz;
    out.OutWorldPos_0 = OutWorldPos[0];
    out.OutWorldPos_1 = OutWorldPos[1];
    out.OutWorldPos_2 = OutWorldPos[2];
    out.OutWorldPos_3 = OutWorldPos[3];
    return out;
}