Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HLSL for loop with Shader Model 2.0: Error X3511 unable to unroll loop

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!

like image 858
barnacleboy Avatar asked Sep 02 '12 16:09

barnacleboy


1 Answers

Try this:

[unroll(121)] for (int i=0; i<121; i++)
{
    int x = i / (int)11 - 5;
    int y = i % (int)11 - 5;
}
like image 56
miloszmaki Avatar answered Oct 12 '22 13:10

miloszmaki