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 8 of 8

Thread: Uniform Buffer Object layout binding

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2006
    Location
    Kyoto.
    Posts
    129

    Uniform Buffer Object layout binding

    I have two Uniform Blocks in my vertex shader :

    Code :
    layout(std140, binding=1) uniform Transforms
    {
    uniform mat4		mvp;
    uniform mat4		proj;
    uniform mat4		mv;
    uniform mat4		nrmn;
    }trans;

    Code :
    layout(std140, binding=3) uniform Shadows
    {
    uniform mat4 shadowMtx[2];
    }sdw;

    I can get the correct binding for Transforms using glGetActiveUniformBlockiv with GL_UNIFORM_BLOCK_BINDING but it gives me 0 for Shadows.

    If I change Shadow to

    Code :
    layout(std140, binding=3) uniform Shadows
    {
    uniform mat4 dummy;
    uniform mat4 shadowMtx[2];
    }sdw;

    querying GL_UNIFORM_BLOCK_BINDING now gives the correct location. Have I misunderstood something or is this a bug?

    I'm using openGL 4.2 with Nvidia 460 w/ 296.10 drivers

    Thanks,

    James

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    Re: Uniform Buffer Object layout binding

    I have not used arrays in my structures; but I don't see anything wrong with your original structure. Do you still need the padding if you just use 2 matrices not as an array?

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Uniform Buffer Object layout binding

    Sounds like a driver bug.

    That being said, in general, the reason for you to assign block bindings in the shader is if you have some convention, so that your source code automatically knows where these bindings are. Say, your projection matrix is always in binding point 0, your array of matrices for skinning is always in binding 1, etc.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2006
    Location
    Kyoto.
    Posts
    129

    Re: Uniform Buffer Object layout binding

    Quote Originally Posted by tonyo_au
    I have not used arrays in my structures; but I don't see anything wrong with your original structure. Do you still need the padding if you just use 2 matrices not as an array?
    I didn't try two arrays, but It also happens if I put a dummy array at the top of Transforms.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2006
    Location
    Kyoto.
    Posts
    129

    Re: Uniform Buffer Object layout binding

    Quote Originally Posted by Alfonse Reinheart
    Sounds like a driver bug.

    That being said, in general, the reason for you to assign block bindings in the shader is if you have some convention, so that your source code automatically knows where these bindings are. Say, your projection matrix is always in binding point 0, your array of matrices for skinning is always in binding 1, etc.
    That's pretty much what I am doing, it's for a bunch of tests with some shared UBOs and it's easier than setting the binding point each time, though that isn't a big undertaking in itself.

    I should try and see if I can still manually bind the uniform block to the right location.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Uniform Buffer Object layout binding

    What I was saying is that you shouldn't be getting the active uniform block binding at all. You should simply know that it's binding X.

    Is the problem that the value you're getting from OpenGL is wrong, or is it that you're getting incorrect rendering if you ignore what OpenGL says?

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2006
    Location
    Kyoto.
    Posts
    129

    Re: Uniform Buffer Object layout binding

    The rendering was incorrect, so I just added a few checks to see what was not as I expected.

  8. #8
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: Uniform Buffer Object layout binding

    File a bug report on it then. There's not much more you can do than that.

Posting Permissions

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