Bug 76323

Summary: GLSL compiler ignores layout(binding=N) on uniform blocks
Product: Mesa Reporter: github
Component: glsl-compilerAssignee: Ian Romanick <idr>
Status: RESOLVED FIXED QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: major    
Priority: medium CC: kenneth
Version: 10.1   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: minimal example using glfw and glm
Patch that fixes part of the problem

Description github 2014-03-18 14:51:50 UTC
Created attachment 96005 [details]
minimal example using glfw and glm

Hi Folks,

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).

Regards
Comment 1 Ian Romanick 2014-04-02 22:34:18 UTC
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.
Comment 2 Ian Romanick 2014-04-03 02:04:01 UTC
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
Comment 3 github 2014-04-04 09:13:28 UTC
That patch works!

I patched Mesa version 10.1.0(-4) and recompiled my test. Thank you very much!

Regards
Comment 5 Kenneth Graunke 2014-04-16 04:49:18 UTC
Should be fixed by:

commit 625cf8c874950a38e7afb404345611f0fad4d490
Author: Ian Romanick <ian.d.romanick@intel.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 <ian.d.romanick@intel.com>
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76323
    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
    Tested-by: github@socker.lepus.uberspace.de [v0]
    Cc: "10.1" <mesa-stable@lists.freedesktop.org>
    Cc: github@socker.lepus.uberspace.de

and the preceding commits.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.