summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwinmad <winmad.wlf@gmail.com>2023-04-14 11:36:19 -0700
committerGitHub <noreply@github.com>2023-04-14 11:36:19 -0700
commit2226ae0bbbf2cbd5ea2da8aaaa04c9c466af56c3 (patch)
tree7041f86d73eee2357306c2b12c8ef6d7c0996b84
parent168c58389e9155312a8cef88d986a4ceee5a511e (diff)
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 <lifanw@nvidia.com> Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--source/slang/slang-ir.cpp2
-rw-r--r--tests/autodiff/for-loop-eliminate-dead-code.slang41
-rw-r--r--tests/autodiff/for-loop-eliminate-dead-code.slang.expected.txt4
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp2
4 files changed, 48 insertions, 1 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 92da981ad..dd3034da1 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -6889,6 +6889,8 @@ namespace Slang
SLANG_ASSERT(other);
if (other->getPrevInst() == this)
return;
+ if (other == this)
+ return;
_insertAt(other->getPrevInst(), other, other->getParent());
}
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<float> 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
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 9bf54a01b..ad71388c4 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -407,7 +407,7 @@ Result DeviceImpl::initialize(const Desc& desc)
SharedLibrary::Handle d3dModule;
#if SLANG_WINDOWS_FAMILY
- const char* libName = "d3d11";
+ const char* libName = "d3d12";
#else
const char* libName = "vkd3d-proton-d3d12";
#endif