Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: compute shaders and uniform blocks

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13

    compute shaders and uniform blocks

    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
    Code :
    #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.

  2. #2
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    85
    Maybe because of optimization. When the compiler realizes that the uniform is never used in the shader it will not be linked.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13
    Quote Originally Posted by Cornix View Post
    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?

    Code :
    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    11
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    13
    yes, using 'add_color' worked. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •