diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-20 00:53:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-20 00:53:24 -0800 |
| commit | 5c9f011fa4948d1f70689b03ddcd203cb2525b2b (patch) | |
| tree | 85b37f7323f921001ddcaa95c43119af1ab234b4 | |
| parent | a00db74d1afa717dd90dfcf3170c63d0d1c0d3d7 (diff) | |
Fix crash during loop unrolling. (#5920)
| -rw-r--r-- | source/slang/slang-ir-loop-unroll.cpp | 3 | ||||
| -rw-r--r-- | tests/ir/loop-unroll-3.slang | 38 |
2 files changed, 41 insertions, 0 deletions
diff --git a/source/slang/slang-ir-loop-unroll.cpp b/source/slang/slang-ir-loop-unroll.cpp index 5f9c53bc7..6b001a562 100644 --- a/source/slang/slang-ir-loop-unroll.cpp +++ b/source/slang/slang-ir-loop-unroll.cpp @@ -463,6 +463,9 @@ bool unrollLoopsInFunc( for (auto loop : loops) { + if (!loop->parent) + continue; + // Remove any continue jumps from the loop. eliminateContinueBlocks(module, loop); diff --git a/tests/ir/loop-unroll-3.slang b/tests/ir/loop-unroll-3.slang new file mode 100644 index 000000000..4e5275e67 --- /dev/null +++ b/tests/ir/loop-unroll-3.slang @@ -0,0 +1,38 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK): -output-using-type + +//TEST_INPUT:set buffer = ubuffer(data=[0 0 0 0], stride=4) +RWStructuredBuffer<float> buffer; + +struct Foo<let D : int> +{ + float load() + { + int idx[D]; + [ForceUnroll] + for (int i = 0; i < D; ++i) + idx[i] = 0; + [ForceUnroll] + for (int i = 0; i < D-2; ++i) + idx[i] = 0; + float result = 100.0; + [ForceUnroll] + for (int i = 0; i < 1; i++) + result += buffer[idx[0]]; + + return result; + } +} + +//TEST_INPUT:set result = out ubuffer(data=[0 0 0 0], stride=4) +uniform RWStructuredBuffer<float> result; + +[shader("compute")] +void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) +{ + Foo<2> biases = {}; + + // Test that we can unroll loops of 0 iterations. + result[0] = biases.load(); + + // CHECK: 100.0 +}
\ No newline at end of file |
