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
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')
-rw-r--r--reference/opt/shaders-hlsl/vert/no-contraction.vert39
-rw-r--r--reference/opt/shaders-msl/vert/no-contraction.vert88
-rw-r--r--reference/opt/shaders/vert/no-contraction.vert18
3 files changed, 145 insertions, 0 deletions
diff --git a/reference/opt/shaders-hlsl/vert/no-contraction.vert b/reference/opt/shaders-hlsl/vert/no-contraction.vert
new file mode 100644
index 00000000..10763fbe
--- /dev/null
+++ b/reference/opt/shaders-hlsl/vert/no-contraction.vert
@@ -0,0 +1,39 @@
+static float4 gl_Position;
+static float4 vA;
+static float4 vB;
+static float4 vC;
+
+struct SPIRV_Cross_Input
+{
+ float4 vA : TEXCOORD0;
+ float4 vB : TEXCOORD1;
+ float4 vC : TEXCOORD2;
+};
+
+struct SPIRV_Cross_Output
+{
+ float4 gl_Position : SV_Position;
+};
+
+void vert_main()
+{
+ precise float4 _15 = vA * vB;
+ precise float4 _19 = vA + vB;
+ precise float4 _23 = vA - vB;
+ precise float4 _30 = _15 + vC;
+ precise float4 _34 = _15 + _19;
+ precise float4 _36 = _34 + _23;
+ precise float4 _38 = _36 + _30;
+ gl_Position = _38;
+}
+
+SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
+{
+ vA = stage_input.vA;
+ vB = stage_input.vB;
+ vC = stage_input.vC;
+ vert_main();
+ SPIRV_Cross_Output stage_output;
+ stage_output.gl_Position = gl_Position;
+ return stage_output;
+}
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;
+}
+
diff --git a/reference/opt/shaders/vert/no-contraction.vert b/reference/opt/shaders/vert/no-contraction.vert
new file mode 100644
index 00000000..9f9969cd
--- /dev/null
+++ b/reference/opt/shaders/vert/no-contraction.vert
@@ -0,0 +1,18 @@
+#version 450
+
+layout(location = 0) in vec4 vA;
+layout(location = 1) in vec4 vB;
+layout(location = 2) in vec4 vC;
+
+void main()
+{
+ precise vec4 _15 = vA * vB;
+ precise vec4 _19 = vA + vB;
+ precise vec4 _23 = vA - vB;
+ precise vec4 _30 = _15 + vC;
+ precise vec4 _34 = _15 + _19;
+ precise vec4 _36 = _34 + _23;
+ precise vec4 _38 = _36 + _30;
+ gl_Position = _38;
+}
+