PDA

View Full Version : compute shaders and uniform blocks



harsha
09-19-2013, 07:21 AM
Hi,

Have just started working on compute shaders.
I have a uniform block in a compute shader and I am trying to get the uniform block index in my application , but it is always returning me index as -1. Whereas for normal uniforms (without blocks) it is returning proper location values (+ve values) . I am working on OPENGL 4.3 with GLSL 430 on Nvidia quadro 600.

Compute Shader


#version 430
#extension GL_EXT_shader_image_load_store : enable
layout(rgba32f) uniform image2D destTex;
layout(std140) uniform colors_UB{
vec4 color1;
vec4 color2;
vec4 color3;
vec4 color4;
};

layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
void main() {
vec4 add_color= vec4(color1 + color2 + color3 + color4); // just to make active
ivec2 image_new = imageSize(destTex); // just to make active
}


The compute shader is compiling and linking properly. Also 'destTex' uniform is returning location value as 0.

But glGetUniformBlockIndex(compute_program, "colors_UB"); is always returning values as -1.

I am missing anything?

Thanks.

Cornix
09-19-2013, 08:04 AM
Maybe because of optimization. When the compiler realizes that the uniform is never used in the shader it will not be linked.

harsha
09-20-2013, 01:04 AM
When the compiler realizes that the uniform is never used in the shader it will not be linked.

What do you mean by uniform never used here?



vec4 add_color= vec4(color1 + color2 + color3 + color4);


Here I am using the uniforms of the uniform block. So, I thought they are active.
Could you please elaborate more.

AHeumann
09-20-2013, 03:14 AM
But 'add_color' is not used anywhere. The compiler removes all calculations and references to resources if the results of the calculations are not used. This also includes the 'colorN' uniforms.

harsha
09-23-2013, 08:02 AM
yes, using 'add_color' worked. Thanks :)