PDA

View Full Version : Problems with TBO on ATI



thekend
01-06-2012, 01:30 AM
Hi!

I have problems with Texture Buffer Objects on ATI. After a lot of searcing for the cause I finally made a simple shader like this:

vertex shader:


#version 330

precision highp float;

layout(location = 0) in vec4 vPosition;

void main()
{
gl_Position = vPosition;
}



fragment shader:


#version 330

precision highp float;

layout(location = 0) out vec4 fragColor;

uniform samplerBuffer texBuf;
uniform int screenWidth;

void main()
{
int offset = int(gl_FragCoord.y) * screenWidth + int(gl_FragCoord.x);
vec4 color = texelFetch(texBuf, offset);
fragColor = color;
}



It works as excepted, the test RGBA8 buffer texture set up for a fullscreen quad with an image is rendered correctly with these shaders. Works on NV and ATI too.

The problems arise when I want to use some other uniform. The following shader should set the green channel output to 1 when I load an identity matrix into modelViewProjMat.

vertex shader:


#version 330

precision highp float;

layout(location = 0) in vec4 vPosition;
uniform mat4 modelViewProjMat;

out mat4 test;

void main()
{
test = modelViewProjMat;
gl_Position = vPosition;

//gl_Position = modelViewProjMat * vPosition;
}


fragment shader:


#version 330

precision highp float;

layout(location = 0) out vec4 fragColor;

in mat4 test;

uniform samplerBuffer texBuf;
uniform int screenWidth;

void main()
{
int offset = int(gl_FragCoord.y) * screenWidth + int(gl_FragCoord.x);
vec4 color = texelFetch(texBuf, offset);
fragColor = color;
fragColor.g = test[0].x;
}


On NV it works as expected, fragColor.g is 1. Unfortunately on ATI, fragColor.g is 0. As I checked, I found that all components of modelViewProjMat is 0 whatever I set them. Without the texel fetch the modelViewProjMat is correctly loaded into the shader program.
There's no OpenGL errors raised, the location for the modelViewProjMat uniform is non-negative, so I can only think that it's a driver bug. It happen with a Radeon 4850 with Catalyst 11.12 on Vista 64 bit.

If anyone have found a similiar problem any help is appreciated. Thanks

Hongwei Li
01-08-2012, 08:02 PM
Will you like to show what your geometry like? I could not produce your problem with my code snippet. Matrix interpolation is working as expected.

thekend
01-10-2012, 02:40 AM
Ok, I'm sorry, it was my fault. I intercepted the uniforms using the glGetProgram and glGetActiveUniform functions. What I missed is that the location of the uniform and the index used for GetActiveUniform is not the same. For some reasons, the 3 uniforms of the upper program have locations 16, 17 and 18.
But I think glUniform should generate some error if I try to use it with locations 0, 1 and 2.

Hongwei Li
01-16-2012, 06:19 PM
But I think glUniform should generate some error if I try to use it with locations 0, 1 and 2.


It won't generate any errors at fact. The location of uniforms are generated in compiling. Usually, locations are filled in order, which means your 0, 1, 2 are filled by other hidden uniforms. That is because in many cases, driver will patch the user shader code for some specific purposes. Some uniforms are inserted into user shader. It is very important to make sure your uniform location is correct.

thekend
01-17-2012, 08:26 AM
It won't generate any errors at fact. The location of uniforms are generated in compiling. Usually, locations are filled in order, which means your 0, 1, 2 are filled by other hidden uniforms. That is because in many cases, driver will patch the user shader code for some specific purposes. Some uniforms are inserted into user shader. It is very important to make sure your uniform location is correct.

Yes, I keep in mind that. Thanks for the answer.