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

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Kristian Arntzen <post@arntzen-software.no>2021-05-07 13:28:08 +0300
committerHans-Kristian Arntzen <post@arntzen-software.no>2021-05-07 13:59:47 +0300
commite47a30e807990c6fe1998c9c4f291d825f043557 (patch)
treed795231de807b3489b3b70dde421f9d3689ceb97 /reference/opt/shaders-msl
parent0eeaffe048b91af45eb289b6934e222bf8ab8ae0 (diff)
Honor NoContraction qualifier.
We'll need to force a temporary and mark it as precise. MSL is a little weird here, but we can piggyback on top of the invariant float math option here to force fma() operations everywhere.
Diffstat (limited to 'reference/opt/shaders-msl')
-rw-r--r--reference/opt/shaders-msl/vert/no-contraction.vert88
1 files changed, 88 insertions, 0 deletions
diff --git a/reference/opt/shaders-msl/vert/no-contraction.vert b/reference/opt/shaders-msl/vert/no-contraction.vert
new file mode 100644
index 00000000..a48731ed
--- /dev/null
+++ b/reference/opt/shaders-msl/vert/no-contraction.vert
@@ -0,0 +1,88 @@
+#pragma clang diagnostic ignored "-Wmissing-prototypes"
+
+#include <metal_stdlib>
+#include <simd/simd.h>
+
+using namespace metal;
+
+struct main0_out
+{
+ float4 gl_Position [[position]];
+};
+
+struct main0_in
+{
+ float4 vA [[attribute(0)]];
+ float4 vB [[attribute(1)]];
+ float4 vC [[attribute(2)]];
+};
+
+template<typename T>
+T spvFMul(T l, T r)
+{
+ return fma(l, r, T(0));
+}
+
+template<typename T, int Cols, int Rows>
+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>
+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>
+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;
+}
+
+template<typename T>
+T spvFAdd(T l, T r)
+{
+ return fma(T(1), l, r);
+}
+
+template<typename T>
+T spvFSub(T l, T r)
+{
+ return fma(T(-1), r, l);
+}
+
+vertex main0_out main0(main0_in in [[stage_in]])
+{
+ main0_out out = {};
+ float4 _15 = spvFMul(in.vA, in.vB);
+ out.gl_Position = spvFAdd(spvFAdd(spvFAdd(_15, spvFAdd(in.vA, in.vB)), spvFSub(in.vA, in.vB)), spvFAdd(_15, in.vC));
+ return out;
+}
+