PDA

View Full Version : Uniform arrays on ATI/AMD



Ketracel White
07-11-2010, 12:46 AM
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];
#else
uniform vec4 lights[128];
#endif


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.

Ilian Dinev
07-11-2010, 02:52 AM
GL_MAX_FRAGMENT_UNIFORM_COMPONENTS = 1024,

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

Ketracel White
07-11-2010, 11:23 AM
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.

frank li
07-11-2010, 07:55 PM
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?

Ketracel White
07-14-2010, 03:02 AM
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.

frank li
07-16-2010, 12:55 AM
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?