   [HLSL] i try to make a loop but i get errors
  Hi !I try to pass an int with SetInt to my shader, and this int will be used in two loops :for(int x= -myInt; x <= myInt ; x++){ for(int y = -myInt ; y <= myInt; y++ ) {//stuff }}the errors are : -unable to unroll loop, loop does not appear to terminate in a timely manner (1024 iterations).-forced to unroll loop but unrolling failed.This occurs even if myInt is always the same... and not if i put a value like 40 or anything else.   
  add [unroll] before each loop.Also make sure that myInt is not NULL, because myInt is probably not being correctly set in your shader...Also run your program in PIX and see the value of myInt   ;  Which shader profile are you compiling to?   ;  i'm using vista and i use a geforce 8800 GT, so i suppose that it is SM3.for the unroll i'll try it.   ;  NV 8800 is SM4.0 capable (dx10)   ;Quote:Original post by blueCloudi'm using vista and i use a geforce 8800 GT, so i suppose that it is SM3.for the unroll i'll try it.Whenever you compile a shader, you have to specify a shader profile. Like vs_2_0, ps_3_0, etc. For standalone shaders, you pass it as an argument to the D3DX compilation function or to fxc.exe. For effects, it's part of your technique declaration. ;  in fact, i do a D3DXGetVertexShaderProfile, so i don't take care about the shader profile, and like i use dx9 i wonder if sm4 can be used with ? Or if dx9 uses at best sm3 ?   ;  dx9 CAN use SM3, but nothing newer. The SM4_x is available in dx10 and above. Didn't the [unroll] thingys came with dx10?   ;  [unroll] and the other HLSL attributes came in a later release of the shader compiler. It works with vs_3_0 and ps_3_0. Anyway the HLSL compiler will, in general, attempt to unroll loops and flatten branches unless you try to convince it otherwise. In your case it's doing this, and since you don't provide an upper bound for "myInt" it doesn't know many times to repeat it. If you wanted to keep the unrolling, you can try doing something like this:static const int MaxVal = 5;int val = min(myInt, MaxVal);for(int x= -val; x <= val; x++)...You could also try using the [unroll] attribute to specify the upper bound:static const int MaxVal = 5;[unroll(MaxVal)]for(int x= -myInt; x <= myInt; x++)Otherwise the [loop] attribute should make the compiler use the loop instruction, using the loop control register. You can check the assembly to be sure. However I would profile with and without loop unroll to see which is faster.[Edited by - MJP on May 26, 2010 2:18:22 AM];  Thanks ! I'll try this.   