Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual number of vertex uniform components for GLSL shader on ATI graphics card?

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;
}
like image 463
Alec Jacobson Avatar asked Dec 21 '11 07:12

Alec Jacobson


People also ask

What are uniforms in GLSL?

A uniform is a global Shader variable declared with the "uniform" storage qualifier. These act as parameters that the user of a shader program can pass to that program. Their values are stored in a program object.

How many times does the vertex shader run?

The vertex shader will be executed roughly once for every vertex in the stream. A vertex shader is (usually) invariant with its input. That is, within a single Drawing Command, two vertex shader invocations that get the exact same input attributes will return binary identical results.

How are vertex coordinates passed to a vertex shader?

So how does the Vertex Shader receives data? It receives data by making use of the Vertex-Fetch stage, in-qualifier variables and glVertexAttrib().

What is the variable in the vertex shader that must be assigned the position of the vertex?

gl_Position is a special variable that holds the position of the vertex in clip space. Since a vertex shader's main output is the position in clip space, it must always set gl_Position. This vertex shader just transforms each vertex position (by the VP matrix).


1 Answers

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

like image 142
datenwolf Avatar answered Nov 15 '22 22:11

datenwolf