[Mesa-dev] [PATCH 4/5] glsl: pass UseSTD430AsDefaultPacking to where it will be used

Timothy Arceri tarceri at itsqueeze.com
Mon Jul 24 03:32:59 UTC 2017


Here we also make use of the UseSTD430AsDefaultPacking constant
and call the new get_internal_ifc_packing() helper.
---
 src/compiler/glsl/ir_optimization.h       |  2 +-
 src/compiler/glsl/link_uniform_blocks.cpp | 17 +++++++----
 src/compiler/glsl/link_uniforms.cpp       | 50 ++++++++++++++++++++-----------
 src/compiler/glsl/link_varyings.cpp       |  2 +-
 src/compiler/glsl/linker.cpp              | 20 ++++++++-----
 src/compiler/glsl/linker.h                |  5 ++--
 src/compiler/glsl/lower_buffer_access.h   |  3 ++
 src/compiler/glsl/lower_ubo_reference.cpp | 33 +++++++++++++++-----
 src/mesa/program/ir_to_mesa.cpp           |  3 +-
 9 files changed, 92 insertions(+), 43 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 82cdac9..573ddb4 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -146,7 +146,7 @@ bool lower_packing_builtins(exec_list *instructions, int op_mask);
 void lower_shared_reference(struct gl_linked_shader *shader,
                             unsigned *shared_size);
 void lower_ubo_reference(struct gl_linked_shader *shader,
-                         bool clamp_block_indices);
+                         bool clamp_block_indices, bool use_std430_as_default);
 void lower_packed_varyings(void *mem_ctx,
                            unsigned locations_used,
                            const uint8_t *components,
diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index ef2f29d..683b296 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -34,10 +34,12 @@ namespace {
 class ubo_visitor : public program_resource_visitor {
 public:
    ubo_visitor(void *mem_ctx, gl_uniform_buffer_variable *variables,
-               unsigned num_variables, struct gl_shader_program *prog)
+               unsigned num_variables, struct gl_shader_program *prog,
+               bool use_std430_as_default)
       : index(0), offset(0), buffer_size(0), variables(variables),
         num_variables(num_variables), mem_ctx(mem_ctx),
-        is_array_instance(false), prog(prog)
+        is_array_instance(false), prog(prog),
+        use_std430_as_default(use_std430_as_default)
    {
       /* empty */
    }
@@ -47,7 +49,8 @@ public:
       this->offset = 0;
       this->buffer_size = 0;
       this->is_array_instance = strchr(name, ']') != NULL;
-      this->program_resource_visitor::process(type, name);
+      this->program_resource_visitor::process(type, name,
+                                              use_std430_as_default);
    }
 
    unsigned index;
@@ -181,6 +184,8 @@ private:
        */
       this->buffer_size = glsl_align(this->offset, 16);
    }
+
+   bool use_std430_as_default;
 };
 
 class count_block_size : public program_resource_visitor {
@@ -352,7 +357,8 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
    /* Add each variable from each uniform block to the API tracking
     * structures.
     */
-   ubo_visitor parcel(blocks, variables, num_variables, prog);
+   ubo_visitor parcel(blocks, variables, num_variables, prog,
+                      ctx->Const.UseSTD430AsDefaultPacking);
 
    unsigned i = 0;
    struct hash_entry *entry;
@@ -438,7 +444,8 @@ link_uniform_blocks(void *mem_ctx,
       }
 
       block_size.num_active_uniforms = 0;
-      block_size.process(b->type->without_array(), "");
+      block_size.process(b->type->without_array(), "",
+                         ctx->Const.UseSTD430AsDefaultPacking);
 
       if (b->array != NULL) {
          unsigned aoa_size = b->type->arrays_of_arrays_size();
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 1b87c58..f7ee17e 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -43,14 +43,17 @@
 #define UNMAPPED_UNIFORM_LOC ~0u
 
 void
-program_resource_visitor::process(const glsl_type *type, const char *name)
+program_resource_visitor::process(const glsl_type *type, const char *name,
+                                  bool use_std430_as_default)
 {
    assert(type->without_array()->is_record()
           || type->without_array()->is_interface());
 
    unsigned record_array_count = 1;
    char *name_copy = ralloc_strdup(NULL, name);
-   enum glsl_interface_packing packing = type->get_interface_packing();
+
+   enum glsl_interface_packing packing =
+      type->get_internal_ifc_packing(use_std430_as_default);
 
    recursion(type, &name_copy, strlen(name), false, NULL, packing, false,
              record_array_count, NULL);
@@ -58,15 +61,16 @@ program_resource_visitor::process(const glsl_type *type, const char *name)
 }
 
 void
-program_resource_visitor::process(ir_variable *var)
+program_resource_visitor::process(ir_variable *var, bool use_std430_as_default)
 {
    unsigned record_array_count = 1;
    const bool row_major =
       var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;
 
-   const enum glsl_interface_packing packing = var->get_interface_type() ?
-      var->get_interface_type_packing() :
-      var->type->get_interface_packing();
+   enum glsl_interface_packing packing = var->get_interface_type() ?
+      var->get_interface_type()->
+         get_internal_ifc_packing(use_std430_as_default) :
+      var->type->get_internal_ifc_packing(use_std430_as_default);
 
    const glsl_type *t =
       var->data.from_named_ifc_block ? var->get_interface_type() : var->type;
@@ -253,12 +257,14 @@ namespace {
 class count_uniform_size : public program_resource_visitor {
 public:
    count_uniform_size(struct string_to_uint_map *map,
-                      struct string_to_uint_map *hidden_map)
+                      struct string_to_uint_map *hidden_map,
+                      bool use_std430_as_default)
       : num_active_uniforms(0), num_hidden_uniforms(0), num_values(0),
         num_shader_samplers(0), num_shader_images(0),
         num_shader_uniform_components(0), num_shader_subroutines(0),
         is_buffer_block(false), is_shader_storage(false), map(map),
-        hidden_map(hidden_map), current_var(NULL)
+        hidden_map(hidden_map), current_var(NULL),
+        use_std430_as_default(use_std430_as_default)
    {
       /* empty */
    }
@@ -278,9 +284,10 @@ public:
       this->is_shader_storage = var->is_in_shader_storage_block();
       if (var->is_interface_instance())
          program_resource_visitor::process(var->get_interface_type(),
-                                           var->get_interface_type()->name);
+                                           var->get_interface_type()->name,
+                                           use_std430_as_default);
       else
-         program_resource_visitor::process(var);
+         program_resource_visitor::process(var, use_std430_as_default);
    }
 
    /**
@@ -393,6 +400,8 @@ private:
     * Current variable being processed.
     */
    ir_variable *current_var;
+
+   bool use_std430_as_default;
 };
 
 } /* anonymous namespace */
@@ -417,8 +426,10 @@ public:
    parcel_out_uniform_storage(struct gl_shader_program *prog,
                               struct string_to_uint_map *map,
                               struct gl_uniform_storage *uniforms,
-                              union gl_constant_value *values)
-      : prog(prog), map(map), uniforms(uniforms), values(values),
+                              union gl_constant_value *values,
+                              bool use_std430_as_default)
+      : prog(prog), map(map), uniforms(uniforms),
+        use_std430_as_default(use_std430_as_default), values(values),
         bindless_targets(NULL), bindless_access(NULL)
    {
    }
@@ -498,7 +509,8 @@ public:
          if (var->is_interface_instance()) {
             ubo_byte_offset = 0;
             process(var->get_interface_type(),
-                    var->get_interface_type()->name);
+                    var->get_interface_type()->name,
+                    use_std430_as_default);
          } else {
             const struct gl_uniform_block *const block =
                &blks[buffer_block_index];
@@ -509,7 +521,7 @@ public:
                &block->Uniforms[var->data.location];
 
             ubo_byte_offset = ubo_var->Offset;
-            process(var);
+            process(var, use_std430_as_default);
          }
       } else {
          /* Store any explicit location and reset data location so we can
@@ -518,7 +530,7 @@ public:
          this->explicit_location = current_var->data.location;
          current_var->data.location = -1;
 
-         process(var);
+         process(var, use_std430_as_default);
       }
       delete this->record_next_sampler;
       delete this->record_next_bindless_sampler;
@@ -896,6 +908,8 @@ private:
    unsigned next_bindless_image;
    unsigned next_subroutine;
 
+   bool use_std430_as_default;
+
    /**
     * Field counter is used to take care that uniform structures
     * with explicit locations get sequential locations.
@@ -1333,7 +1347,8 @@ link_assign_uniform_storage(struct gl_context *ctx,
 #endif
 
    parcel_out_uniform_storage parcel(prog, prog->UniformHash,
-                                     prog->data->UniformStorage, data);
+                                     prog->data->UniformStorage, data,
+                                     ctx->Const.UseSTD430AsDefaultPacking);
 
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       struct gl_linked_shader *shader = prog->_LinkedShaders[i];
@@ -1436,7 +1451,8 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
     * glGetUniformLocation.
     */
    struct string_to_uint_map *hiddenUniforms = new string_to_uint_map;
-   count_uniform_size uniform_size(prog->UniformHash, hiddenUniforms);
+   count_uniform_size uniform_size(prog->UniformHash, hiddenUniforms,
+                                   ctx->Const.UseSTD430AsDefaultPacking);
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       struct gl_linked_shader *sh = prog->_LinkedShaders[i];
 
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index de3754c..fa99b4b 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1843,7 +1843,7 @@ public:
 
       this->toplevel_var = var;
       this->varying_floats = 0;
-      program_resource_visitor::process(var);
+      program_resource_visitor::process(var, false);
    }
 
 private:
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index b4784c5..67e3a8f 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4133,9 +4133,9 @@ get_array_size(struct gl_uniform_storage *uni, const glsl_struct_field *field,
 }
 
 static int
-get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
-                 const glsl_struct_field *field, char *interface_name,
-                 char *var_name)
+get_array_stride(struct gl_context *ctx, struct gl_uniform_storage *uni,
+                 const glsl_type *interface, const glsl_struct_field *field,
+                 char *interface_name, char *var_name)
 {
    /* The ARB_program_interface_query spec says:
     *
@@ -4159,7 +4159,9 @@ get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
                                                    var_name))
          return 0;
 
-      if (interface->interface_packing != GLSL_INTERFACE_PACKING_STD430) {
+      if (GLSL_INTERFACE_PACKING_STD140 ==
+          interface->
+             get_internal_ifc_packing(ctx->Const.UseSTD430AsDefaultPacking)) {
          if (array_type->is_record() || array_type->is_array())
             return glsl_align(array_type->std140_size(row_major), 16);
          else
@@ -4172,7 +4174,8 @@ get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
 }
 
 static void
-calculate_array_size_and_stride(struct gl_shader_program *shProg,
+calculate_array_size_and_stride(struct gl_context *ctx,
+                                struct gl_shader_program *shProg,
                                 struct gl_uniform_storage *uni)
 {
    int block_index = uni->block_index;
@@ -4221,7 +4224,7 @@ calculate_array_size_and_stride(struct gl_shader_program *shProg,
             if (strcmp(field->name, var_name) != 0)
                continue;
 
-            array_stride = get_array_stride(uni, interface, field,
+            array_stride = get_array_stride(ctx, uni, interface, field,
                                             interface_name, var_name);
             array_size = get_array_size(uni, field, interface_name, var_name);
             goto write_top_level_array_size_and_stride;
@@ -4347,7 +4350,7 @@ build_program_resource_list(struct gl_context *ctx,
          continue;
 
       if (is_shader_storage) {
-         calculate_array_size_and_stride(shProg,
+         calculate_array_size_and_stride(ctx, shProg,
                                          &shProg->data->UniformStorage[i]);
       }
 
@@ -4649,7 +4652,8 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
 
       if (options->LowerBufferInterfaceBlocks)
          lower_ubo_reference(prog->_LinkedShaders[i],
-                             options->ClampBlockIndicesToArrayBounds);
+                             options->ClampBlockIndicesToArrayBounds,
+                             ctx->Const.UseSTD430AsDefaultPacking);
 
       if (i == MESA_SHADER_COMPUTE)
          lower_shared_reference(prog->_LinkedShaders[i],
diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
index dd627be..5cec121 100644
--- a/src/compiler/glsl/linker.h
+++ b/src/compiler/glsl/linker.h
@@ -122,7 +122,7 @@ public:
     * matter.  For example, enumerating the names of members of the block, but
     * not for determining the offsets of members.
     */
-   void process(ir_variable *var);
+   void process(ir_variable *var, bool use_std430_as_default);
 
    /**
     * Begin processing a variable of a structured type.
@@ -139,7 +139,8 @@ public:
     * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
     * there of.
     */
-   void process(const glsl_type *type, const char *name);
+   void process(const glsl_type *type, const char *name,
+                bool use_std430_as_default);
 
 protected:
    /**
diff --git a/src/compiler/glsl/lower_buffer_access.h b/src/compiler/glsl/lower_buffer_access.h
index cb186f0..9e89d32 100644
--- a/src/compiler/glsl/lower_buffer_access.h
+++ b/src/compiler/glsl/lower_buffer_access.h
@@ -58,6 +58,9 @@ public:
                             bool *row_major, int *matrix_columns,
                             const glsl_struct_field **struct_field,
                             enum glsl_interface_packing packing);
+
+protected:
+   bool use_std430_as_default;
 };
 
 } /* namespace lower_buffer_access */
diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
index 163c25e..bc33767 100644
--- a/src/compiler/glsl/lower_ubo_reference.cpp
+++ b/src/compiler/glsl/lower_ubo_reference.cpp
@@ -45,10 +45,12 @@ class lower_ubo_reference_visitor :
       public lower_buffer_access::lower_buffer_access {
 public:
    lower_ubo_reference_visitor(struct gl_linked_shader *shader,
-                               bool clamp_block_indices)
+                               bool clamp_block_indices,
+                               bool use_std430_as_default)
    : shader(shader), clamp_block_indices(clamp_block_indices),
      struct_field(NULL), variable(NULL)
    {
+      this->use_std430_as_default = use_std430_as_default;
    }
 
    void handle_rvalue(ir_rvalue **rvalue);
@@ -345,7 +347,10 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   enum glsl_interface_packing packing = var->get_interface_type_packing();
+
+   enum glsl_interface_packing packing =
+      var->get_interface_type()->
+         get_internal_ifc_packing(use_std430_as_default);
 
    this->buffer_access_type =
       var->is_in_shader_storage_block() ?
@@ -558,7 +563,10 @@ lower_ubo_reference_visitor::write_to_memory(void *mem_ctx,
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   enum glsl_interface_packing packing = var->get_interface_type_packing();
+
+   enum glsl_interface_packing packing =
+      var->get_interface_type()->
+         get_internal_ifc_packing(use_std430_as_default);
 
    this->buffer_access_type = ssbo_store_access;
    this->variable = var;
@@ -737,8 +745,12 @@ lower_ubo_reference_visitor::process_ssbo_unsized_array_length(ir_rvalue **rvalu
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   enum glsl_interface_packing packing = var->get_interface_type_packing();
-   int unsized_array_stride = calculate_unsized_array_stride(deref, packing);
+
+   enum glsl_interface_packing packing =
+      var->get_interface_type()->
+         get_internal_ifc_packing(use_std430_as_default);
+   int unsized_array_stride =
+      calculate_unsized_array_stride(deref, packing);
 
    this->buffer_access_type = ssbo_unsized_array_length_access;
    this->variable = var;
@@ -971,7 +983,10 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   enum glsl_interface_packing packing = var->get_interface_type_packing();
+
+   enum glsl_interface_packing packing =
+      var->get_interface_type()->
+         get_internal_ifc_packing(use_std430_as_default);
 
    this->buffer_access_type = ssbo_atomic_access;
    this->variable = var;
@@ -1108,9 +1123,11 @@ lower_ubo_reference_visitor::visit_enter(ir_texture *ir)
 } /* unnamed namespace */
 
 void
-lower_ubo_reference(struct gl_linked_shader *shader, bool clamp_block_indices)
+lower_ubo_reference(struct gl_linked_shader *shader,
+                    bool clamp_block_indices, bool use_std430_as_default)
 {
-   lower_ubo_reference_visitor v(shader, clamp_block_indices);
+   lower_ubo_reference_visitor v(shader, clamp_block_indices,
+                                 use_std430_as_default);
 
    /* Loop over the instructions lowering references, because we take
     * a deref of a UBO array using a UBO dereference as the index will
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 5c8ba92..5befbd1 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2420,7 +2420,8 @@ public:
    {
       this->idx = -1;
       this->var = var;
-      this->program_resource_visitor::process(var);
+      this->program_resource_visitor::process(var,
+                                         ctx->Const.UseSTD430AsDefaultPacking);
       var->data.param_index = this->idx;
    }
 
-- 
2.9.4



More information about the mesa-dev mailing list