[Mesa-dev] [PATCH 2/3] glsl: UBOs and SSBOs must match the binding qualifier too

Andres Gomez agomez at igalia.com
Thu Feb 23 08:55:42 UTC 2017


>From page 140 (page 147 of the PDF) of the GLSL ES 3.10 v.4 spec:

  " 9.2 Matching of Qualifiers

    The following tables summarize the requirements for matching of
    qualifiers.  It applies whenever there are two or more matching
    variables in a shader interface.

    Notes:

    1. Yes means the qualifiers must match.

    ...

    9.2.1 Linked Shaders

    | Qualifier | Qualifier | in/out | Default  | uniform | buffer|
    |   Class   |           |        | Uniforms |  Block  | Block |

    ...

    |  Layout   |  binding  |  N/A   |   Yes    |   Yes   |  Yes  |"

>From page 93 (page 110 of the PDF) of the GL 4.2 (Core Profile) spec:

  " 2.11.7 Uniform Variables

    ...

    Uniform Blocks

    ...

    When a named uniform block is declared by multiple shaders in a
    program, it must be declared identically in each shader. The
    uniforms within the block must be declared with the same names and
    types, and in the same order. If a program contains multiple
    shaders with different declarations for the same named uniform
    block differs between shader, the program will fail to link."

>From page 129 (page 150 of the PDF) of the GL 4.3 (Core Profile) spec:

  " 7.8 Shader Buffer Variables and Shader Storage Blocks

    ...

    When a named shader storage block is declared by multiple shaders
    in a program, it must be declared identically in each shader. The
    buffer variables within the block must be declared with the same
    names, types, qualification, and declaration order. If a program
    contains multiple shaders with different declarations for the same
    named shader storage block, the program will fail to link."

Therefore, if the binding qualifier differs between two linked Uniform
or Shader Storage Blocks of the same name, a link error should happen.

This patch will make that a link error will be reported on a program
like this:

    "# VS

    layout(binding = 1) Block {
      vec4 color;
    } uni_block1;

    ...

    # FS

    layout(binding = 2) Block {
      vec4 color;
    } uni_block2;

    ..."

Signed-off-by: Andres Gomez <agomez at igalia.com>
Cc: Ian Romanick <ian.d.romanick at intel.com>
---
 src/compiler/glsl/link_uniform_blocks.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index 839fd07fa4b..249a767636c 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -504,6 +504,9 @@ link_uniform_blocks_are_compatible(const gl_uniform_block *a,
    if (a->_RowMajor != b->_RowMajor)
       return false;
 
+   if (a->Binding != b->Binding)
+      return false;
+
    for (unsigned i = 0; i < a->NumUniforms; i++) {
       if (strcmp(a->Uniforms[i].Name, b->Uniforms[i].Name) != 0)
          return false;
-- 
2.11.0



More information about the mesa-dev mailing list