Mesa (master): glsl: store ubo or ssbo index in block index

Timothy Arceri tarceri at kemper.freedesktop.org
Sat Apr 2 06:12:05 UTC 2016


Module: Mesa
Branch: master
Commit: 0fbd073dc284f952ea7df691941a65ddc89b7554
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0fbd073dc284f952ea7df691941a65ddc89b7554

Author: Timothy Arceri <timothy.arceri at collabora.com>
Date:   Sat Apr  2 13:54:06 2016 +1100

glsl: store ubo or ssbo index in block index

Previously we store the buffer block index i.e the index of a combined
ubo/ssbo list.

Fixes several dEQP-GLES31.functional tests:
- program_interface_query.uniform.block_index.block_array
- program_interface_query.uniform.block_index.named_block
- program_interface_query.uniform.block_index.unnamed_block
- program_interface_query.uniform.random.10
- program_interface_query.uniform.random.15
- program_interface_query.uniform.random.22
- program_interface_query.uniform.random.24
- program_interface_query.uniform.random.26
- program_interface_query.uniform.random.28
- program_interface_query.uniform.random.3
- program_interface_query.uniform.random.31
- program_interface_query.uniform.random.38
- program_interface_query.uniform.random.5

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94116
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/compiler/glsl/link_uniforms.cpp | 41 ++++++++++++++++++++-----------------
 src/compiler/glsl/linker.cpp        | 10 ++++++---
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 0a230ca..43ff525 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -460,30 +460,33 @@ public:
       field_counter = 0;
       this->record_next_sampler = new string_to_uint_map;
 
-      ubo_block_index = -1;
+      buffer_block_index = -1;
       if (var->is_in_buffer_block()) {
+         struct gl_uniform_block **blks = var->is_in_shader_storage_block() ?
+            prog->ShaderStorageBlocks : prog->UniformBlocks;
+         unsigned num_blks = var->is_in_shader_storage_block() ?
+            prog->NumShaderStorageBlocks : prog->NumUniformBlocks;
+
          if (var->is_interface_instance() && var->type->is_array()) {
             unsigned l = strlen(var->get_interface_type()->name);
 
-            for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
-               if (strncmp(var->get_interface_type()->name,
-                           prog->BufferInterfaceBlocks[i].Name,
-                           l) == 0
-                   && prog->BufferInterfaceBlocks[i].Name[l] == '[') {
-                  ubo_block_index = i;
+            for (unsigned i = 0; i < num_blks; i++) {
+               if (strncmp(var->get_interface_type()->name, blks[i]->Name, l)
+                   == 0 && blks[i]->Name[l] == '[') {
+                  buffer_block_index = i;
                   break;
                }
             }
          } else {
-            for (unsigned i = 0; i < prog->NumBufferInterfaceBlocks; i++) {
-               if (strcmp(var->get_interface_type()->name,
-                          prog->BufferInterfaceBlocks[i].Name) == 0) {
-                  ubo_block_index = i;
+            for (unsigned i = 0; i < num_blks; i++) {
+               if (strcmp(var->get_interface_type()->name, blks[i]->Name) ==
+                   0) {
+                  buffer_block_index = i;
                   break;
                }
             }
          }
-         assert(ubo_block_index != -1);
+         assert(buffer_block_index != -1);
 
          /* Uniform blocks that were specified with an instance name must be
           * handled a little bit differently.  The name of the variable is the
@@ -497,7 +500,7 @@ public:
                     var->get_interface_type()->name);
          } else {
             const struct gl_uniform_block *const block =
-               &prog->BufferInterfaceBlocks[ubo_block_index];
+               blks[buffer_block_index];
 
             assert(var->data.location != -1);
 
@@ -519,7 +522,7 @@ public:
       delete this->record_next_sampler;
    }
 
-   int ubo_block_index;
+   int buffer_block_index;
    int ubo_byte_offset;
    gl_shader_stage shader_type;
 
@@ -659,7 +662,7 @@ private:
    virtual void enter_record(const glsl_type *type, const char *,
                              bool row_major, const unsigned packing) {
       assert(type->is_record());
-      if (this->ubo_block_index == -1)
+      if (this->buffer_block_index == -1)
          return;
       if (packing == GLSL_INTERFACE_PACKING_STD430)
          this->ubo_byte_offset = glsl_align(
@@ -672,7 +675,7 @@ private:
    virtual void leave_record(const glsl_type *type, const char *,
                              bool row_major, const unsigned packing) {
       assert(type->is_record());
-      if (this->ubo_block_index == -1)
+      if (this->buffer_block_index == -1)
          return;
       if (packing == GLSL_INTERFACE_PACKING_STD430)
          this->ubo_byte_offset = glsl_align(
@@ -719,7 +722,7 @@ private:
       /* For array of arrays or struct arrays the base location may have
        * already been set so don't set it again.
        */
-      if (ubo_block_index == -1 && current_var->data.location == -1) {
+      if (buffer_block_index == -1 && current_var->data.location == -1) {
          current_var->data.location = id;
       }
 
@@ -766,8 +769,8 @@ private:
       this->uniforms[id].is_shader_storage =
          current_var->is_in_shader_storage_block();
 
-      if (this->ubo_block_index != -1) {
-         this->uniforms[id].block_index = this->ubo_block_index;
+      if (this->buffer_block_index != -1) {
+         this->uniforms[id].block_index = this->buffer_block_index;
 
          unsigned alignment = type->std140_base_alignment(row_major);
          if (packing == GLSL_INTERFACE_PACKING_STD430)
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index f750f5b..d9a681c 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -3804,7 +3804,9 @@ calculate_array_size_and_stride(struct gl_shader_program *shProg,
    int array_stride = -1;
    char *var_name = get_top_level_name(uni->name);
    char *interface_name =
-      get_top_level_name(shProg->BufferInterfaceBlocks[block_index].Name);
+      get_top_level_name(uni->is_shader_storage ?
+                         shProg->ShaderStorageBlocks[block_index]->Name :
+                         shProg->UniformBlocks[block_index]->Name);
 
    if (strcmp(var_name, interface_name) == 0) {
       /* Deal with instanced array of SSBOs */
@@ -3941,12 +3943,14 @@ build_program_resource_list(struct gl_context *ctx,
                         ir_var_uniform);
 
       /* Add stagereferences for uniforms in a uniform block. */
+      bool is_shader_storage =  shProg->UniformStorage[i].is_shader_storage;
       int block_index = shProg->UniformStorage[i].block_index;
       if (block_index != -1) {
-         stageref |= shProg->BufferInterfaceBlocks[block_index].stageref;
+         stageref |= is_shader_storage ?
+            shProg->ShaderStorageBlocks[block_index]->stageref :
+            shProg->UniformBlocks[block_index]->stageref;
       }
 
-      bool is_shader_storage =  shProg->UniformStorage[i].is_shader_storage;
       GLenum type = is_shader_storage ? GL_BUFFER_VARIABLE : GL_UNIFORM;
       if (!should_add_buffer_variable(shProg, type,
                                       shProg->UniformStorage[i].name))




More information about the mesa-commit mailing list