summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-02-06 18:16:36 -0500
committerGitHub <noreply@github.com>2020-02-06 15:16:36 -0800
commit7981da51debc66aa78cda72a4b0be3fc3a74d634 (patch)
treeb5b4372530c1413f1d23f207c1936d93e4049ac9 /tests
parentd3331fba6eaab44646010b556106da38925d43e0 (diff)
Float matrix intrinsic test/fixes (#1203)
* Fix CPP construct when matrix type. * Test intrinsics on float matrices. * Fix typo in _areNearlyEqual test. Increased default sensitivity. Added matrix-float test.
Diffstat (limited to 'tests')
-rw-r--r--tests/hlsl-intrinsic/matrix-float.slang133
-rw-r--r--tests/hlsl-intrinsic/matrix-float.slang.expected.txt5
2 files changed, 138 insertions, 0 deletions
diff --git a/tests/hlsl-intrinsic/matrix-float.slang b/tests/hlsl-intrinsic/matrix-float.slang
new file mode 100644
index 000000000..34591d3d9
--- /dev/null
+++ b/tests/hlsl-intrinsic/matrix-float.slang
@@ -0,0 +1,133 @@
+// NOTE we can't test on VK/gl at the moment because we don't support intrinsics over matrices on that target currently
+
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -use-dxil -output-using-type
+//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef matrix<float, 2, 2> FloatMatrix;
+typedef matrix<int, 2, 2> IntMatrix;
+typedef matrix<uint, 2, 2> UIntMatrix;
+typedef vector<float, 2> FloatVector;
+
+float calcTotal(vector<float, 2> v)
+{
+ return v.x + v.y;
+}
+
+float calcTotal(FloatMatrix v)
+{
+ return calcTotal(v[0]) + calcTotal(v[1]);
+}
+
+FloatMatrix makeFloatMatrix(float f)
+{
+ FloatMatrix m = { { f, f }, { f, f } };
+ return m;
+}
+
+IntMatrix makeIntMatrix(int v)
+{
+ IntMatrix m = { { v, v }, { v, v } };
+ return m;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int idx = int(dispatchThreadID.x);
+
+ float scalarF = idx * (1.0f / (4.0f));
+
+ FloatMatrix ft = {};
+
+ FloatMatrix f = { { scalarF + 0.01, scalarF + 0.02f}, { scalarF + 0.011f, scalarF + 0.022f}};
+
+ // fmod
+ ft += FloatMatrix(IntMatrix(((f % makeFloatMatrix(0.11f)) * makeFloatMatrix(100)) + makeFloatMatrix(0.5)));
+
+ ft += sin(f);
+
+ // Lets try some matrix/matrix
+ ft = f * ft;
+
+ // Lets try some vector matrix
+
+ {
+ FloatMatrix r = {mul(f[0], ft), mul(ft, f[1])};
+ ft += r;
+ }
+
+ // Back to the transcendentals
+
+ ft += cos(f);
+ ft += tan(f);
+
+ ft += asin(f);
+ ft += acos(f);
+ ft += atan(f);
+
+ ft += atan2(f, makeFloatMatrix(2));
+
+#if 0
+ // This fails from DXC with a validation error(!)
+ {
+ FloatMatrix sf, cf;
+ sincos(f, sf, cf);
+
+ ft += sf;
+ ft += cf;
+ }
+#endif
+
+ ft += rcp(makeFloatMatrix(1.0) + f);
+ ft += FloatMatrix(sign(f - makeFloatMatrix(0.5)));
+
+ ft += saturate(f * makeFloatMatrix(4) - makeFloatMatrix(2.0));
+
+ ft += sqrt(f);
+ ft += rsqrt(makeFloatMatrix(1.0f) + f);
+
+ ft += exp2(f);
+ ft += exp(f);
+
+ ft += frac(f * makeFloatMatrix(3));
+ ft += ceil(f * makeFloatMatrix(5) - makeFloatMatrix(3));
+
+ ft += floor(f * makeFloatMatrix(10) - makeFloatMatrix(7));
+ ft += trunc(f * makeFloatMatrix(7));
+
+ ft += log(f + makeFloatMatrix(10.0));
+ ft += log2(f * makeFloatMatrix(3) + makeFloatMatrix(2));
+
+ {
+ float scalarVs[] = { 1, 10, 100, 1000 };
+ ft += FloatMatrix(IntMatrix(log10(makeFloatMatrix(scalarVs[idx])) + makeFloatMatrix(0.5f)));
+ }
+
+ ft += abs(f * makeFloatMatrix(4) - makeFloatMatrix(2.0f));
+
+ ft += min(makeFloatMatrix(0.5), f);
+ ft += max(f, makeFloatMatrix(0.75));
+
+ ft += pow(makeFloatMatrix(0.5), f);
+
+ ft += smoothstep(makeFloatMatrix(0.2), makeFloatMatrix(0.7), f);
+ ft += lerp(makeFloatMatrix(-100), makeFloatMatrix(100), f);
+
+ ft += clamp(f, makeFloatMatrix(0.1), makeFloatMatrix(0.3));
+
+ ft += step(f, makeFloatMatrix(0.5));
+
+ IntMatrix vi = asint(makeFloatMatrix(idx));
+ ft += asfloat(vi);
+
+ UIntMatrix vu = asuint(f);
+ ft += asfloat(vu);
+
+ outputBuffer[idx] = calcTotal(ft);
+} \ No newline at end of file
diff --git a/tests/hlsl-intrinsic/matrix-float.slang.expected.txt b/tests/hlsl-intrinsic/matrix-float.slang.expected.txt
new file mode 100644
index 000000000..10941c176
--- /dev/null
+++ b/tests/hlsl-intrinsic/matrix-float.slang.expected.txt
@@ -0,0 +1,5 @@
+type: float
+-367.570129
+-128.128876
+139.494034
+414.148346