Created attachment 96005 [details]
minimal example using glfw and glm
it seems that the GLSL compiler (or maybe some other component) simply ignores a layout(binding=N) specifier on uniform blocks. This means, no matter what you set there, the binding is always overridden by some default value (when having a single uniform block it seems to be always 0).
I've attached a simple test program (could be a little simpler, I just copied stuff together from my projects) that demonstrates the bug. The program either works when binding the uniform buffer to binding point 0, or when manually setting the shaders bind point with glUniformBlockBinding.
Tested on a Intel HD4000 with Mesa 10.0.3 and Mesa 10.1.0 on Arch Linux. Tried Kernels 3.13.5 and 3.13.6. The program works on a nVidia GeForce 9600 GT with the proprietary driver (haven't tested nouveau yet).
I talked to Ken (who wrote a bunch of this code), and he explained what happened. Commit bfcec461 added /most/ of the necessary support for the binding layout. This was added in the Mesa 10.0 time frame... when we only supported GLSL 1.40. Some cases that could only exist in GLSL 1.50 were not implemented. When we added GLSL 1.50 in Mesa 10.1, we didn't notice this support was missing. That said, the code in the provided test case should work. :(
It looks like there are zero test cases for this in piglit, I guess I shouldn't be too surprised.
Created attachment 96816 [details] [review]
Patch that fixes part of the problem
Let me know if this patch helps. It's not complete, but it should make your test case work.
I have also sent a test case to the piglit mailing list that reproduces a couple issues in this area: http://lists.freedesktop.org/archives/piglit/2014-April/010176.html
That patch works!
I patched Mesa version 10.1.0(-4) and recompiled my test. Thank you very much!
Great news! I just sent the (hopefully) final series to the mesa-dev list for review. I also CC'ed you on the patches. If you could try those and send a Tested-by, that would be awesome.
Should be fixed by:
Author: Ian Romanick <email@example.com>
Date: Wed Apr 2 18:58:54 2014 -0700
glsl: Propagate explicit binding information from the AST all the way to the linker
Information about the binding was not being properly communicated from
the front-end compiler to the linker. As a result, the linker never
knew that any UBOs had explicit bindings!
Fixes the piglit test arb_shading_language_420pack-binding-layout.
Signed-off-by: Ian Romanick <firstname.lastname@example.org>
Reviewed-by: Kenneth Graunke <email@example.com>
Tested-by: firstname.lastname@example.org [v0]
Cc: "10.1" <email@example.com>
and the preceding commits.