Uniform arrays on ATI/AMD

I am using uniform arrays for some lighting calculations. All this works without problems on NVidia but I got some reports from ATI users that they’d have problems with it.

Basically what I do is to collect a number of light sources and upload them to a uniform array like this:

	glUniform3iv(lightrange_index, 1, mNumLights);
	glUniform4fv(lights_index, mNumLights, mLightData);

This is some example of how they get used in the shader:

	uniform ivec3 lightrange;
	#ifdef MAXLIGHTS256
	uniform vec4 lights[256];
	uniform vec4 lights[128];

	vec4 GetLight(vec4 pixelpos)
		vec4 dynlight = vec4(0.0,0.0,0.0,0.0);
		for(int i=0; i<lightrange.x; i+=2)
			vec4 lightpos = lights[i];
			vec4 lightcolor = lights[i+1];
			lightcolor.rgb *= max(lightpos.w - distance(pixelpos.xyz, lightpos.xyz),0.0) / lightpos.w;
			dynlight += lightcolor;
		return dynlight;

Does anyone have an idea why there seem to be problems on ATI?
On my own Geforce 8600GT this is a lot faster than using uniform or texture buffers to transfer the light data so I don’t really want to change it.


so when you use “uniform vec4 lights[128];” it shouldn’t crash.
Or is the problem something other than crashing/not-compiling?

I got reports of some ATI HD4xxx users that say they get visual errors. The shader compiles fine but apparently does not work correctly in some situations.

If my understanding is correct, nNumLights is an array with size 3, how could it be the argument of glUniform4fv? Could you please replace it with the size of 256 or 128 to see if the error still exists?

No, that was just a copy/paste error when I made that post. The original code was a lot more complicated because it accesses some internal data structures of my program so I simplified it a bit. That value gets passed properly.

If the uniform values are passed properly and the shader compiles successfully, how could you make sure there is a bug in the “uniform array”? Could you make the program work by modifying the shader?

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