summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-01-17 20:21:01 -0500
committerGitHub <noreply@github.com>2023-01-17 17:21:01 -0800
commit1a486813ef0bc7f7a2eb6eaeec2921fd71a2bd05 (patch)
tree5d64c73b7859a1657f71af95da7bc9e78fc58bf2 /tests
parent2c437498d3a09b58de17a8865242814d9ea92fde (diff)
Added switch-case support; fixed non-diff parameter transposition (#2596)
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/reverse-switch-case.slang55
-rw-r--r--tests/autodiff/reverse-switch-case.slang.expected.txt6
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/autodiff/reverse-switch-case.slang b/tests/autodiff/reverse-switch-case.slang
new file mode 100644
index 000000000..21a7565af
--- /dev/null
+++ b/tests/autodiff/reverse-switch-case.slang
@@ -0,0 +1,55 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+typedef DifferentialPair<float> dpfloat;
+typedef float.Differential dfloat;
+
+[BackwardDifferentiable]
+float test_simple_switch(float y, int i)
+{
+ float o;
+ switch (i)
+ {
+ case 0:
+ case 1:
+ o = y * 2.0;
+ break;
+
+ case 2:
+ o = y * 3.0;
+ break;
+
+ default:
+ o = y;
+ }
+
+ return o;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ {
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(test_simple_switch)(dpa, 1, 1.0f);
+ outputBuffer[0] = dpa.d; // Expect: 2.0
+ }
+
+ {
+ dpfloat dpa = dpfloat(0.4, 0.0);
+
+ __bwd_diff(test_simple_switch)(dpa, 2, 1.0f);
+ outputBuffer[1] = dpa.d; // Expect: 3.0
+ }
+
+ {
+ dpfloat dpa = dpfloat(1.0, 0.0);
+
+ __bwd_diff(test_simple_switch)(dpa, 3, 1.0f);
+ outputBuffer[2] = dpa.d; // Expect: 1.0
+ }
+}
diff --git a/tests/autodiff/reverse-switch-case.slang.expected.txt b/tests/autodiff/reverse-switch-case.slang.expected.txt
new file mode 100644
index 000000000..6e3b3dd12
--- /dev/null
+++ b/tests/autodiff/reverse-switch-case.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+2.000000
+3.000000
+1.000000
+0.000000
+0.000000