Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm porting an iOS game to Android. One of the shaders I'm using wouldn't compile until I reduced the number of uniform variables. Here are the uniform definitions:

uniform highp   mat4 ViewProjMatrix;
uniform mediump vec3 LightDirWorld;
uniform mediump int  BoneCount;
uniform highp   mat4 BoneMatrixArray[8];
uniform highp   mat3 BoneMatrixArrayIT[8];
uniform mediump int  LightCount;
uniform mediump vec3 LightPos[4]; // This used to be 12, but now 4, next lines also
uniform lowp    vec3 LightColour[4];
uniform mediump vec3 LightInnerOuterFalloff[4];

My issue is that the GLSL shader wouldn't compile until I reduced the count of the above arrays from 12 to 4. My understanding is that if those 3 lines were arrays of 12 then I would be using 56 vertex uniform vectors. I query the system at startup (GL_MAX_VERTEX_UNIFORM_VECTORS) and it says that 128 are available. Why wouldn't it compile with 56? I'm having issues on the Kindle Fire.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Uniform variables are counted in units of vec4's. So each mat4 counts as four, and each mat3 counts as three. Your BoneMatrixArray is using up 4*8=32 slots. Your BoneMatrixArrayIT is using 3*8=16. There's 48 slots right there.

Toss in your three arrays of 12 elements and you're up another 36 slots. Miscellaneous other items you've got there give you another 7. Totals up to 91 slots.

Not 128 still, but some uniform slots may be getting used by other things not in your code. Not sure if built-ins count (don't think so), but samplers and such probably do.

The implementation may also just be lying about its limits. GL does not have a conformance test suite, so many implementations suffer from lots of bugs.

share|improve this answer
    
Thanks for pointing that out, I forgot about the matrices accounting for multiple vectors. Is there a way to more accurately test this restriction at run time, what do other companies do when supporting a multitude of platforms with undefined differences like this? Perhaps I need to define make files that define this test whilst setting up the project for a group of platforms, or have preconfigured platform limitation files. –  reapz May 22 '12 at 6:05
1  
@reapz: Actual companies just test on the various hardware they support. It's the only way to be certain that your code will work. Indeed, that's primarily what is meant when someone say that they support a platform. –  Nicol Bolas May 22 '12 at 7:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.