diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-11-16 19:31:57 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-16 19:31:57 -0800 |
| commit | 0e3d9ba255b86c11521a951183d38bffae008559 (patch) | |
| tree | 3be0a0da5a8f6bfddaae761dff7a4872f355787d | |
| parent | 871fbeec58caaa02ec990a676f10fa7014391a58 (diff) | |
IR: pass through `[unroll]` attribute (#284)
The initial lowering was adding an `IRLoopControlDecoration` to the instruction at the head of a loop, but this was getting dropped when the IR gets cloned for a particular entry point.
The fix was simply to add a case for loop-control decorations to `cloneDecoration`.
| -rw-r--r-- | source/slang/ir.cpp | 8 | ||||
| -rw-r--r-- | tests/compute/loop-unroll.slang | 29 | ||||
| -rw-r--r-- | tests/compute/loop-unroll.slang.expected.txt | 4 |
3 files changed, 41 insertions, 0 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 9ecafbc7d..9068e717b 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -3063,6 +3063,14 @@ namespace Slang } break; + case kIRDecorationOp_LoopControl: + { + auto originalDecoration = (IRLoopControlDecoration*)dd; + auto newDecoration = context->builder->addDecoration<IRLoopControlDecoration>(clonedValue); + newDecoration->mode = originalDecoration->mode; + } + break; + default: // Don't clone any decorations we don't understand. break; diff --git a/tests/compute/loop-unroll.slang b/tests/compute/loop-unroll.slang new file mode 100644 index 000000000..5b1635a8d --- /dev/null +++ b/tests/compute/loop-unroll.slang @@ -0,0 +1,29 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir + +//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(0),glbinding(0),out +//TEST_INPUT:ubuffer(data=[1 2 3 0], stride=4):dxbinding(1),glbinding(1) + +// Check that we propagate the `[unroll]` attribute +// through to HLSL output correctly. +// +// If we neglect to generate the attribute in the output, +// it will generate a warning output from fxc, and the +// test will fail to match the expected output. + +RWStructuredBuffer<int> buffers[2]; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + + int val = buffers[1][tid]; + + [unroll] + for(int ii = 0; ii < 2; ii++) + { + val = buffers[ii][val]; + } + + buffers[0][tid] = val; +}
\ No newline at end of file diff --git a/tests/compute/loop-unroll.slang.expected.txt b/tests/compute/loop-unroll.slang.expected.txt new file mode 100644 index 000000000..7ffb87d2b --- /dev/null +++ b/tests/compute/loop-unroll.slang.expected.txt @@ -0,0 +1,4 @@ +2 +3 +0 +1 |
