summaryrefslogtreecommitdiff
path: root/tests/autodiff/custom-diff-empty-func.slang
diff options
context:
space:
mode:
Diffstat (limited to 'tests/autodiff/custom-diff-empty-func.slang')
-rw-r--r--tests/autodiff/custom-diff-empty-func.slang35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/autodiff/custom-diff-empty-func.slang b/tests/autodiff/custom-diff-empty-func.slang
new file mode 100644
index 000000000..c566d9e19
--- /dev/null
+++ b/tests/autodiff/custom-diff-empty-func.slang
@@ -0,0 +1,35 @@
+//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type -g0
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+void foo_bwd(float a, inout DifferentialPair<float> dpx)
+{
+ outputBuffer[2] = 2.f;
+}
+
+[Differentiable, BackwardDerivative(foo_bwd)]
+void foo(no_diff float a, float x)
+{ }
+
+[Differentiable]
+float outerFunc(no_diff float a, float x)
+{
+ foo(a, x);
+ return 1.f;
+}
+
+[numthreads(1, 1, 1)]
+[shader("compute")]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ float a = 10.0;
+ DifferentialPair<float> dpx = DifferentialPair<float>(4.f, 1.f);
+ bwd_diff(outerFunc)(a, dpx, 1.0);
+
+ // CHECK: type: float
+ // CHECK: 0.0
+ // CHECK: 0.0
+ // CHECK: 2.0
+ // CHECK: 0.0
+} \ No newline at end of file