11

I'm writing a GLSL vertex shader for an iMac with a AMD Radeon HD 6970M 2048 MB graphics card:

GL_MAX_VERTEX_ATTRIBS: 16
GL_MAX_VERTEX_UNIFORM_COMPONENTS: 4096
GL_VERSION: 2.1 ATI-7.12.9
GL_SHADING_LANGUAGE_VERSION: 1.20

In my shader I would like to have a large array of uniform mat4s:

uniform mat4 T[65]

but if I try to have 65 of these my shader (secretly) switches to Apple Software Renderer mode. If I instead use 64:

uniform mat4 T[64]

everything is fine.

Seems to be a problem with exceeding the maximum number of uniforms. But as I wrote above I'm getting 4096 for GL_MAX_VERTEX_UNIFORM_COMPONENTS so 4096/(4*4) = 256 not 64...

OpenGL.org wiki says

ATI/AMD note: The ATI max component values are wrong. They are the actual number of components divided by 4.

But reading this I would think that if I query GL_MAX_VERTEX_UNIFORM_COMPONENTS and get 4096 that I actually have 16,384. What seems to be the case is that GL_MAX_VERTEX_UNIFORM_COMPONENTS returns the actual number of components multiplied by 4. This would then give 1024/(4*4) = 64.

Can anyone confirm this?

Edit: My shader is simply:

#version 120

// 65 goes into software render mode
#define MAX_T 64
attribute vec4 indices;
uniform mat4 T[MAX_T];

void main()
{
  gl_Position =  T[int(indices[0])]*gl_Vertex;
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
Alec Jacobson
  • 6,032
  • 5
  • 51
  • 88
  • 3
    Could you please post your shader code, or at least the definition of all used uniforms. And you're right isofar, that you need to divide the 1024 by 4 not multiply. The wiki entry is worded badly. – datenwolf Dec 21 '11 at 09:35
  • I posted the shader code above (I also noticed that before I had a one off in my counting, so I edited the numbers in the original question 63->64 and 64->65 accordingly). – Alec Jacobson Dec 21 '11 at 13:06
  • 1
    @datenwolf You should post this as an answer, as this seems to be his problem quite obviously. I guess he just uses some other small uniforms that "block" the last 64th matrix slot (builtin uniforms also count, I think). – Christian Rau Dec 21 '11 at 13:08
  • I'm curious: what happens if you made two `mat4` arrays, of length 33? – Nicol Bolas Dec 21 '11 at 17:53
  • @Nicol 33 doesn't work because you end up with 66. On the other hand 32 does work. – Alec Jacobson Dec 21 '11 at 19:20

1 Answers1

7

You're right isofar, that you need to divide the 4096 by 4 not multiply. The wiki entry is was worded badly.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • 6
    It is *not* worded badly; look again. And don't look at the edit history on that page either; I'm sure that the person who wrote it certainly did not correct it after seeing this Q/A. Nope, that certainly did not happen a few minutes ago. ;) – Nicol Bolas Dec 21 '11 at 17:55