For/while statements

It says my profile doesn’t support for or while statements in a fragment shader.

umm…
I’m using an fx5600. most of the shader code has to run in software but am I at a loss for using fors and whiles in a fragment shader?

what do I do about this?

Loops are supported in ShaderModel 3.0 (new GF 6800 support it). You have to do manual loop unrolling.

Lets someone confirm following…
In some cases compilers can do loop unrolling, but current GLSL compilers can’t do this.

yooyo

GeForce FX hardware only supports loops in the fragment shader that can be unrolled by the compiler. So the number of iterations must be known at compile time.

In the vertex shader, you will be able to loop based off a per-vertex attribute or uniform value. This should be supported in current drivers already on all GeForce FX GPUs, see the glsl_skinning demo in SDK 7.0 for an example of this.

The 3Dlabs Wildcat VP series of video cards do support for/while loops.

Thanks, I’m not working with the vp990 however nor have intentions to.

I have manually unrolled the loops, i was just trying to avoid that.

In my implementation the loop iteration is known at compile time, but alas…I still can’t get it to compile.

A 6800 might be out of my reach at the moment. Does anyone have any knowledge of whether I’d run into the same problem on a 5950?

thanks.

Please post the code for your loop, it may be a simple problem that is preventing the compiler from unrolling it and giving you that error message.

Does anyone have any knowledge of whether I’d run into the same problem on a 5950?
The 5950 is no different functionally than the 5900. It’s just a performance revision.

sure, here’s the loop…

//loop through all lights, compute contribution from each.
	for(int i=0; i < 8.0; i++)
	{
		if(lightEnabled[i] != 0) 
		{
		
			
		if(gl_LightSource[i].position.w == 0.0)
			DirectionalLight(i,normal,amb,diff,spec);
		
		else if(gl_LightSource[i].spotCutoff == 180.0)
			PointLight(i,normal, amb, diff, spec);
		
		else
			SpotLight(i,normal, amb, diff, spec);
		}
		
		
	}

this is the exact same loop I have in a vertex shader and it works. It just doesn’t like being in a fragment shader.

it’s sort of weird though, if I change the 8.0 to 8 it doesn’t compile.

things behave rather strangely and I’m assuming it’s just due to beta drivers.

Korval - do you know if I would run into these problems on a 5900 then?

I can get it too compile as long as I use “8” not “8.0” in the for loop. Are you saying it only works for you if you use “8.0”?

yup, that’s what I’m saying.
Interesting isn’t it?

Korval - do you know if I would run into these problems on a 5900 then?
Nvidia uses what they call the Unified driver architecture.

That probably means you will get the same behavior across the board except they may provide the hardware support but not the software fallback in some cases.

You should all have the same driver version too!

Aelund, can you send me your app? I’d like to test it against our latest GLSL implementation and see if the problem still persists.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.