From 2226ae0bbbf2cbd5ea2da8aaaa04c9c466af56c3 Mon Sep 17 00:00:00 2001 From: winmad Date: Fri, 14 Apr 2023 11:36:19 -0700 Subject: Bugfix: compiler will run forever to eliminate dead code (#2809) * Add a test case that the compile will run forever * Fix. * fix. --------- Co-authored-by: Lifan Wu Co-authored-by: Yong He --- tests/autodiff/for-loop-eliminate-dead-code.slang | 41 ++++++++++++++++++++++ ...for-loop-eliminate-dead-code.slang.expected.txt | 4 +++ 2 files changed, 45 insertions(+) create mode 100644 tests/autodiff/for-loop-eliminate-dead-code.slang create mode 100644 tests/autodiff/for-loop-eliminate-dead-code.slang.expected.txt (limited to 'tests') diff --git a/tests/autodiff/for-loop-eliminate-dead-code.slang b/tests/autodiff/for-loop-eliminate-dead-code.slang new file mode 100644 index 000000000..be1093c23 --- /dev/null +++ b/tests/autodiff/for-loop-eliminate-dead-code.slang @@ -0,0 +1,41 @@ +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type + +//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +static const uint kMaxSurfaceBounces = 2; + +[BackwardDifferentiable] +void updatePathContrib(inout float3 result, float3 val) +{ + result = result + val; +} + +[BackwardDifferentiable] +float3 evalPath(uint2 pixel) +{ + float3 result = float3(0.f); + float3 thp = float3(1.f); + + [MaxIters(kMaxSurfaceBounces)] + for (int i = 0; i < kMaxSurfaceBounces; i++) + { + float3 neeContrib = float3(1.f); + updatePathContrib(result, thp * neeContrib); + thp = thp * float3(0.9f); + } + return result; +} + +void execute(const uint2 pixel) +{ + float3 dColor = float3(1.f); + __bwd_diff(evalPath)(pixel, dColor); +} + +[numthreads(64, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + execute(dispatchThreadID.xy); +} diff --git a/tests/autodiff/for-loop-eliminate-dead-code.slang.expected.txt b/tests/autodiff/for-loop-eliminate-dead-code.slang.expected.txt new file mode 100644 index 000000000..4465d8c34 --- /dev/null +++ b/tests/autodiff/for-loop-eliminate-dead-code.slang.expected.txt @@ -0,0 +1,4 @@ +type: float +0.000000 +0.000000 +0.000000 \ No newline at end of file -- cgit v1.2.3