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

Timothy Arceri tarceri at itsqueeze.com
Thu Aug 17 11:03:00 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           |  6 ++--
 9 files changed, 94 insertions(+), 44 deletions(-)

diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h
index 82cdac9b3c..573ddb4a8d 100644
--- a/src/compiler/glsl/ir_optimization.h
+++ b/src/compiler/glsl/ir_optimization.h
@@ -139,21 +139,21 @@ bool lower_variable_index_to_cond_assign(gl_shader_stage stage,
     bool lower_temp, bool lower_uniform);
 bool lower_quadop_vector(exec_list *instructions, bool dont_lower_swz);
 bool lower_const_arrays_to_uniforms(exec_list *instructions, unsigned stage);
 bool lower_clip_cull_distance(struct gl_shader_program *prog,
                               gl_linked_shader *shader);
 void lower_output_reads(unsigned stage, exec_list *instructions);
 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,
                            ir_variable_mode mode,
                            unsigned gs_input_vertices,
                            gl_linked_shader *shader,
                            bool disable_varying_packing, bool xfb_enabled);
 bool lower_vector_insert(exec_list *instructions, bool lower_nonconstant_index);
 bool lower_vector_derefs(gl_linked_shader *shader);
 void lower_named_interface_blocks(void *mem_ctx, gl_linked_shader *shader);
diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index ef2f29dd7a..683b296e33 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -27,34 +27,37 @@
 #include "ir_uniform.h"
 #include "link_uniform_block_active_visitor.h"
 #include "util/hash_table.h"
 #include "program.h"
 
 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 */
    }
 
    void process(const glsl_type *type, const char *name)
    {
       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;
    unsigned offset;
    unsigned buffer_size;
    gl_uniform_buffer_variable *variables;
    unsigned num_variables;
    void *mem_ctx;
    bool is_array_instance;
    struct gl_shader_program *prog;
@@ -174,20 +177,22 @@ private:
        *    For uniform blocks laid out according to [std140] rules, the
        *    minimum buffer object size returned by the UNIFORM_BLOCK_DATA_SIZE
        *    query is derived by taking the offset of the last basic machine
        *    unit consumed by the last uniform of the uniform block (including
        *    any end-of-array or end-of-structure padding), adding one, and
        *    rounding up to the next multiple of the base alignment required
        *    for a vec4.
        */
       this->buffer_size = glsl_align(this->offset, 16);
    }
+
+   bool use_std430_as_default;
 };
 
 class count_block_size : public program_resource_visitor {
 public:
    count_block_size() : num_active_uniforms(0)
    {
       /* empty */
    }
 
    unsigned num_active_uniforms;
@@ -345,21 +350,22 @@ create_buffer_blocks(void *mem_ctx, struct gl_context *ctx,
     * blocks that can be queried through the API.
     */
    struct gl_uniform_block *blocks =
       rzalloc_array(mem_ctx, gl_uniform_block, num_blocks);
    gl_uniform_buffer_variable *variables =
       ralloc_array(blocks, gl_uniform_buffer_variable, num_variables);
 
    /* 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;
    hash_table_foreach (block_hash, entry) {
       const struct link_uniform_block_active *const b =
          (const struct link_uniform_block_active *) entry->data;
       const glsl_type *block_type = b->type;
 
       if ((create_ubo_blocks && !b->is_shader_storage) ||
           (!create_ubo_blocks && b->is_shader_storage)) {
@@ -431,21 +437,22 @@ link_uniform_blocks(void *mem_ctx,
       assert((b->array != NULL) == b->type->is_array());
 
       if (b->array != NULL &&
           (b->type->without_array()->interface_packing ==
            GLSL_INTERFACE_PACKING_PACKED)) {
          b->type = resize_block_array(b->type, b->array);
          b->var->type = b->type;
       }
 
       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();
          if (b->is_shader_storage) {
             *num_ssbo_blocks += aoa_size;
             num_ssbo_variables += aoa_size * block_size.num_active_uniforms;
          } else {
             *num_ubo_blocks += aoa_size;
             num_ubo_variables += aoa_size * block_size.num_active_uniforms;
          }
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 1b87c5860b..f7ee17ef02 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -36,44 +36,48 @@
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
 
 /**
  * Used by linker to indicate uniforms that have no location set.
  */
 #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);
    ralloc_free(name_copy);
 }
 
 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;
    const glsl_type *t_without_array = t->without_array();
 
    /* false is always passed for the row_major parameter to the other
     * processing functions because no information is available to do
     * otherwise.  See the warning in linker.h.
     */
    if (t_without_array->is_record() ||
@@ -246,48 +250,51 @@ namespace {
  * As uniforms are added to the active set the number of active uniforms and
  * the storage requirements for those uniforms are accumulated.  The active
  * uniforms are added to the hash table supplied to the constructor.
  *
  * If the same uniform is added multiple times (i.e., once for each shader
  * target), it will only be accounted once.
  */
 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 */
    }
 
    void start_shader()
    {
       this->num_shader_samplers = 0;
       this->num_shader_images = 0;
       this->num_shader_uniform_components = 0;
       this->num_shader_subroutines = 0;
    }
 
    void process(ir_variable *var)
    {
       this->current_var = var;
       this->is_buffer_block = var->is_in_buffer_block();
       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);
    }
 
    /**
     * Total number of active uniforms counted
     */
    unsigned num_active_uniforms;
 
    unsigned num_hidden_uniforms;
 
    /**
@@ -386,20 +393,22 @@ private:
       if(!is_gl_identifier(name) && !is_shader_storage && !is_buffer_block)
          this->num_values += values;
    }
 
    struct string_to_uint_map *hidden_map;
 
    /**
     * Current variable being processed.
     */
    ir_variable *current_var;
+
+   bool use_std430_as_default;
 };
 
 } /* anonymous namespace */
 
 /**
  * Class to help parcel out pieces of backing storage to uniforms
  *
  * Each uniform processed has some range of the \c gl_constant_value
  * structures associated with it.  The association is done by finding
  * the uniform in the \c string_to_uint_map and using the value from
@@ -410,22 +419,24 @@ private:
  * This class assumes that every uniform that will be processed is
  * already in the \c string_to_uint_map.  In addition, it assumes that
  * the \c gl_uniform_storage and \c gl_constant_value arrays are "big
  * enough."
  */
 class parcel_out_uniform_storage : public program_resource_visitor {
 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)
    {
    }
 
    virtual ~parcel_out_uniform_storage()
    {
       free(this->bindless_targets);
       free(this->bindless_access);
    }
 
@@ -491,41 +502,42 @@ public:
 
          /* Uniform blocks that were specified with an instance name must be
           * handled a little bit differently.  The name of the variable is the
           * name used to reference the uniform block instead of being the name
           * of a variable within the block.  Therefore, searching for the name
           * within the block will fail.
           */
          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];
 
             assert(var->data.location != -1);
 
             const struct gl_uniform_buffer_variable *const ubo_var =
                &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
           * reuse this variable for storing the uniform slot number.
           */
          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;
       delete this->record_next_image;
       delete this->record_next_bindless_image;
    }
 
    int buffer_block_index;
    int ubo_byte_offset;
    gl_shader_stage shader_type;
@@ -889,20 +901,22 @@ private:
 
    struct string_to_uint_map *map;
 
    struct gl_uniform_storage *uniforms;
    unsigned next_sampler;
    unsigned next_bindless_sampler;
    unsigned next_image;
    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.
     */
    unsigned field_counter;
 
    /**
     * Current variable being processed.
     */
    ir_variable *current_var;
@@ -1326,21 +1340,22 @@ link_assign_uniform_storage(struct gl_context *ctx,
                            union gl_constant_value, num_data_slots);
    } else {
       data = prog->data->UniformDataSlots;
    }
 
 #ifndef NDEBUG
    union gl_constant_value *data_end = &data[num_data_slots];
 #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];
 
       if (!shader)
          continue;
 
       parcel.start_shader((gl_shader_stage)i);
 
       foreach_in_list(ir_instruction, node, shader->ir) {
@@ -1429,21 +1444,22 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
    }
 
    /* First pass: Count the uniform resources used by the user-defined
     * uniforms.  While this happens, each active uniform will have an index
     * assigned to it.
     *
     * Note: this is *NOT* the index that is returned to the application by
     * 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];
 
       if (sh == NULL)
          continue;
 
       link_update_uniform_buffer_variables(sh, i);
 
       /* Reset various per-shader target counts.
        */
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index de3754c423..fa99b4b4f3 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1836,21 +1836,21 @@ public:
    {
    }
 
    void process(ir_variable *var)
    {
       /* All named varying interface blocks should be flattened by now */
       assert(!var->is_interface_instance());
 
       this->toplevel_var = var;
       this->varying_floats = 0;
-      program_resource_visitor::process(var);
+      program_resource_visitor::process(var, false);
    }
 
 private:
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool /* row_major */,
                             const glsl_type * /* record_type */,
                             const enum glsl_interface_packing,
                             bool /* last_field */)
    {
       assert(!type->without_array()->is_record());
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 9af7d8033a..fa0afe6c16 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -4119,23 +4119,23 @@ get_array_size(struct gl_uniform_storage *uni, const glsl_struct_field *field,
       return  1;
    else if (field->type->is_unsized_array())
       return 0;
    else if (field->type->is_array())
       return field->type->length;
 
    return 1;
 }
 
 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:
     *
     *     "For the property TOP_LEVEL_ARRAY_STRIDE, a single integer
     *     identifying the stride between array elements of the top-level
     *     shader storage block member containing the active variable is
     *     written to <params>.  For top-level block members declared as
     *     arrays, the value written is the difference, in basic machine units,
     *     between the offsets of the active variable for consecutive elements
     *     in the top-level array.  For top-level block members not declared as
@@ -4145,34 +4145,37 @@ get_array_stride(struct gl_uniform_storage *uni, const glsl_type *interface,
       const enum glsl_matrix_layout matrix_layout =
          glsl_matrix_layout(field->matrix_layout);
       bool row_major = matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;
       const glsl_type *array_type = field->type->fields.array;
 
       if (is_top_level_shader_storage_block_member(uni->name,
                                                    interface_name,
                                                    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
             return MAX2(array_type->std140_base_alignment(row_major), 16);
       } else {
          return array_type->std430_array_stride(row_major);
       }
    }
    return 0;
 }
 
 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;
    int array_size = -1;
    int array_stride = -1;
    char *var_name = get_top_level_name(uni->name);
    char *interface_name =
       get_top_level_name(uni->is_shader_storage ?
                          shProg->data->ShaderStorageBlocks[block_index].Name :
                          shProg->data->UniformBlocks[block_index].Name);
@@ -4207,21 +4210,21 @@ calculate_array_size_and_stride(struct gl_shader_program *shProg,
          const glsl_type *interface = var->get_interface_type();
 
          if (strcmp(interface_name, interface->name) != 0)
             continue;
 
          for (unsigned i = 0; i < interface->length; i++) {
             const glsl_struct_field *field = &interface->fields.structure[i];
             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;
          }
       }
    }
 write_top_level_array_size_and_stride:
    free(interface_name);
    free(var_name);
    uni->top_level_array_stride = array_stride;
@@ -4333,21 +4336,21 @@ build_program_resource_list(struct gl_context *ctx,
             shProg->data->ShaderStorageBlocks[block_index].stageref :
             shProg->data->UniformBlocks[block_index].stageref;
       }
 
       GLenum type = is_shader_storage ? GL_BUFFER_VARIABLE : GL_UNIFORM;
       if (!should_add_buffer_variable(shProg, type,
                                       shProg->data->UniformStorage[i].name))
          continue;
 
       if (is_shader_storage) {
-         calculate_array_size_and_stride(shProg,
+         calculate_array_size_and_stride(ctx, shProg,
                                          &shProg->data->UniformStorage[i]);
       }
 
       if (!add_program_resource(shProg, resource_set, type,
                                 &shProg->data->UniformStorage[i], stageref))
          return;
    }
 
    /* Add program uniform blocks. */
    for (unsigned i = 0; i < shProg->data->NumUniformBlocks; i++) {
@@ -4635,21 +4638,22 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
 
    for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
       if (prog->_LinkedShaders[i] == NULL)
          continue;
 
       const struct gl_shader_compiler_options *options =
          &ctx->Const.ShaderCompilerOptions[i];
 
       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],
                                 &prog->Comp.SharedSize);
 
       lower_vector_derefs(prog->_LinkedShaders[i]);
       do_vec_index_to_swizzle(prog->_LinkedShaders[i]->ir);
    }
 
    return true;
diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
index dd627be5f1..5cec121e63 100644
--- a/src/compiler/glsl/linker.h
+++ b/src/compiler/glsl/linker.h
@@ -115,38 +115,39 @@ public:
     * \param var  The variable that is to be processed
     *
     * Calls \c ::visit_field for each leaf of the variable.
     *
     * \warning
     * When processing a uniform block, this entry should only be used in cases
     * where the row / column ordering of matrices in the block does not
     * 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.
     *
     * This flavor of \c process should be used to handle structured types
     * (i.e., structures, interfaces, or arrays there of) that need special
     * name handling.  A common usage is to handle cases where the block name
     * (instead of the instance name) is used for an interface block.
     *
     * \param type  Type that is to be processed, associated with \c name
     * \param name  Base name of the structured variable being processed
     *
     * \note
     * \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:
    /**
     * Method invoked for each leaf of the variable
     *
     * \param type  Type of the field.
     * \param name  Fully qualified name of the field.
     * \param row_major  For a matrix type, is it stored row-major.
     * \param record_type  Type of the record containing the field.
     * \param last_field   Set if \c name is the last field of the structure
diff --git a/src/compiler/glsl/lower_buffer_access.h b/src/compiler/glsl/lower_buffer_access.h
index cb186f0dcf..9e89d324be 100644
--- a/src/compiler/glsl/lower_buffer_access.h
+++ b/src/compiler/glsl/lower_buffer_access.h
@@ -51,15 +51,18 @@ public:
                     bool row_major, int matrix_columns,
                     unsigned int packing, unsigned int write_mask);
 
    bool is_dereferenced_thing_row_major(const ir_rvalue *deref);
 
    void setup_buffer_access(void *mem_ctx, ir_rvalue *deref,
                             ir_rvalue **offset, unsigned *const_offset,
                             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 */
 
 #endif /* LOWER_BUFFER_ACCESS_H */
diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
index a63d80c139..e0745670df 100644
--- a/src/compiler/glsl/lower_ubo_reference.cpp
+++ b/src/compiler/glsl/lower_ubo_reference.cpp
@@ -38,24 +38,26 @@
 #include "main/macros.h"
 #include "glsl_parser_extras.h"
 
 using namespace ir_builder;
 
 namespace {
 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);
    ir_visitor_status visit_enter(ir_assignment *ir);
 
    void setup_for_load_or_store(void *mem_ctx,
                                 ir_variable *var,
                                 ir_rvalue *deref,
                                 ir_rvalue **offset,
                                 unsigned *const_offset,
@@ -338,21 +340,24 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
    ir_variable *var = deref->variable_referenced();
    if (!var || !var->is_in_buffer_block())
       return;
 
    void *mem_ctx = ralloc_parent(shader->ir);
 
    ir_rvalue *offset = NULL;
    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() ?
       ssbo_load_access : ubo_load_access;
    this->variable = var;
 
    /* Compute the offset to the start if the dereference as well as other
     * information we need to configure the write
     */
    setup_for_load_or_store(mem_ctx, var, deref,
@@ -551,21 +556,24 @@ void
 lower_ubo_reference_visitor::write_to_memory(void *mem_ctx,
                                              ir_dereference *deref,
                                              ir_variable *var,
                                              ir_variable *write_var,
                                              unsigned write_mask)
 {
    ir_rvalue *offset = NULL;
    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;
 
    /* Compute the offset to the start if the dereference as well as other
     * information we need to configure the write
     */
    setup_for_load_or_store(mem_ctx, var, deref,
                            &offset, &const_offset,
                            &row_major, &matrix_columns,
@@ -730,22 +738,26 @@ ir_expression *
 lower_ubo_reference_visitor::process_ssbo_unsized_array_length(ir_rvalue **rvalue,
                                                                ir_dereference *deref,
                                                                ir_variable *var)
 {
    void *mem_ctx = ralloc_parent(*rvalue);
 
    ir_rvalue *base_offset = NULL;
    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;
 
    /* Compute the offset to the start if the dereference as well as other
     * information we need to calculate the length.
     */
    setup_for_load_or_store(mem_ctx, var, deref,
                            &base_offset, &const_offset,
                            &row_major, &matrix_columns,
@@ -964,21 +976,24 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
 
    /* Compute the offset to the start if the dereference and the
     * block index
     */
    void *mem_ctx = ralloc_parent(shader->ir);
 
    ir_rvalue *offset = NULL;
    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;
 
    setup_for_load_or_store(mem_ctx, var, deref,
                            &offset, &const_offset,
                            &row_major, &matrix_columns,
                            packing);
    assert(offset);
    assert(!row_major);
@@ -1101,23 +1116,25 @@ lower_ubo_reference_visitor::visit_enter(ir_texture *ir)
       return visit_continue_with_parent;
    }
 
    return rvalue_visit(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
     * produce a collection of instructions all of which have cloned
     * UBO dereferences for that array index.
     */
    do {
       v.progress = false;
       visit_list_elements(&v, shader->ir);
    } while (v.progress);
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 0e6a95ce99..d04ea67b07 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2411,39 +2411,41 @@ print_program(struct prog_instruction *mesa_instructions,
 					    PROG_PRINT_DEBUG, NULL);
    }
 }
 
 namespace {
 
 class add_uniform_to_shader : public program_resource_visitor {
 public:
    add_uniform_to_shader(struct gl_shader_program *shader_program,
 			 struct gl_program_parameter_list *params)
-      : shader_program(shader_program), params(params), idx(-1)
+      : ctx(ctx), shader_program(shader_program), params(params), idx(-1)
    {
       /* empty */
    }
 
    void process(ir_variable *var)
    {
       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;
    }
 
 private:
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool row_major, const glsl_type *record_type,
                             const enum glsl_interface_packing packing,
                             bool last_field);
 
+   struct gl_context *ctx;
    struct gl_shader_program *shader_program;
    struct gl_program_parameter_list *params;
    int idx;
    ir_variable *var;
 };
 
 } /* anonymous namespace */
 
 void
 add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
-- 
2.13.4



More information about the mesa-dev mailing list