12

When compiling the following for loop in my HLSL shader under Shader Model 2.0, I'm getting Error X3511.

for (int x = -5; x <= 5; x++)
{
    for (int y = -5; y <= 5; y++)
    {
            ...

The error reads as follows: unable to unroll loop, loop does not appear to terminate in a timely manner (5 iterations), use the [unroll(n)] attribute to force an exact higher number.

I'm aware of this error message, but I'm not using a variable here for the conditional part of the for statement - it's a hardcoded x <= 5 condition. What is wrong here?

Thanks in advance!

barnacleboy
  • 539
  • 8
  • 18
  • It compiles when I'm removing the second for loop. So: No nested loops in HLSL?!? – barnacleboy Sep 03 '12 at 06:36
  • I'm not sure if it works with nested loops, but did you try bumping up the number of iterations with the attribute? As a wild guess, maybe `[unroll(11)]` on both loops would work? – Andrew Russell Sep 04 '12 at 06:07
  • Unfortunately I cannot use unroll when compiling under Shader Model 2.0. I'm working on an image processing application, so I want to make sure that the application can at least run under Windows XP. – barnacleboy Sep 04 '12 at 09:11

1 Answers1

13

Try this:

[unroll(121)] for (int i=0; i<121; i++)
{
    int x = i / (int)11 - 5;
    int y = i % (int)11 - 5;
}
miloszmaki
  • 1,635
  • 15
  • 21