View Full Version : Uniform Buffer Object layout binding
James A.
04-15-2012, 03:15 AM
I have two Uniform Blocks in my vertex shader :
layout(std140, binding=1) uniform Transforms
{
uniform mat4 mvp;
uniform mat4 proj;
uniform mat4 mv;
uniform mat4 nrmn;
}trans;
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
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
tonyo_au
04-18-2012, 12:42 AM
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?
Alfonse Reinheart
04-18-2012, 10:59 AM
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.
James A.
04-18-2012, 04:53 PM
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.
James A.
04-18-2012, 04:58 PM
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.
Alfonse Reinheart
04-18-2012, 06:03 PM
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?
James A.
04-18-2012, 06:37 PM
The rendering was incorrect, so I just added a few checks to see what was not as I expected.
Alfonse Reinheart
04-18-2012, 07:10 PM
File a bug report on it then. There's not much more you can do than that.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.