From 911a4401b08f6199e18b32349c236c186a2dd128 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 2 Nov 2023 14:54:22 -0700 Subject: Fix crash when writing to `no_diff` out parameter. (#3308) * Fix crash when writing to `no_diff` out parameter. * Fix. --------- Co-authored-by: Yong He --- tests/autodiff/no-diff-out.slang | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/autodiff/no-diff-out.slang (limited to 'tests') diff --git a/tests/autodiff/no-diff-out.slang b/tests/autodiff/no-diff-out.slang new file mode 100644 index 000000000..c8085a05f --- /dev/null +++ b/tests/autodiff/no-diff-out.slang @@ -0,0 +1,30 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +typedef DifferentialPair dpfloat; + +[Differentiable] +float test(float x, no_diff out float y) +{ + if (x == 1.0) + y = 0.0; + return x * x; +} + +[Differentiable] +float caller(float x, no_diff out float y) +{ + return test(x, y); +} + +[numthreads(1, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + var p = diffPair(3.0, 0.0); + bwd_diff(caller)(p, 1.0); + outputBuffer[dispatchThreadID.x] = p.d; + // CHECK: 6.0 +} -- cgit v1.2.3