Skip to content

Commit 0e3d9ba

Browse files
author
Tim Foley
authored
IR: pass through [unroll] attribute (shader-slang#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`.
1 parent 871fbee commit 0e3d9ba

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

source/slang/ir.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3063,6 +3063,14 @@ namespace Slang
30633063
}
30643064
break;
30653065

3066+
case kIRDecorationOp_LoopControl:
3067+
{
3068+
auto originalDecoration = (IRLoopControlDecoration*)dd;
3069+
auto newDecoration = context->builder->addDecoration<IRLoopControlDecoration>(clonedValue);
3070+
newDecoration->mode = originalDecoration->mode;
3071+
}
3072+
break;
3073+
30663074
default:
30673075
// Don't clone any decorations we don't understand.
30683076
break;

tests/compute/loop-unroll.slang

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
2+
3+
//TEST_INPUT:ubuffer(data=[0 1 2 3], stride=4):dxbinding(0),glbinding(0),out
4+
//TEST_INPUT:ubuffer(data=[1 2 3 0], stride=4):dxbinding(1),glbinding(1)
5+
6+
// Check that we propagate the `[unroll]` attribute
7+
// through to HLSL output correctly.
8+
//
9+
// If we neglect to generate the attribute in the output,
10+
// it will generate a warning output from fxc, and the
11+
// test will fail to match the expected output.
12+
13+
RWStructuredBuffer<int> buffers[2];
14+
15+
[numthreads(4, 1, 1)]
16+
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
17+
{
18+
uint tid = dispatchThreadID.x;
19+
20+
int val = buffers[1][tid];
21+
22+
[unroll]
23+
for(int ii = 0; ii < 2; ii++)
24+
{
25+
val = buffers[ii][val];
26+
}
27+
28+
buffers[0][tid] = val;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2
2+
3
3+
0
4+
1

0 commit comments

Comments
 (0)