[Mesa-dev] [PATCH v3 (part2) 18/56] glsl: propagate interface packing information to arrays of scalars, vectors.

Iago Toral Quiroga itoral at igalia.com
Tue Jul 14 00:46:20 PDT 2015


From: Samuel Iglesias Gonsalvez <siglesias at igalia.com>

Now std140 is not the only interface packing qualifier that can be used.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
---
 src/glsl/ast.h          | 10 +++++++++
 src/glsl/ast_to_hir.cpp | 54 +++++++++++++++++++++++++++++++++++++------------
 src/glsl/glsl_types.cpp | 14 ++++++++++---
 src/glsl/glsl_types.h   |  8 ++++++--
 4 files changed, 68 insertions(+), 18 deletions(-)

diff --git a/src/glsl/ast.h b/src/glsl/ast.h
index 6cbbf09..19034c4 100644
--- a/src/glsl/ast.h
+++ b/src/glsl/ast.h
@@ -681,6 +681,11 @@ public:
 				     struct _mesa_glsl_parse_state *state)
       const;
 
+   const struct glsl_type *glsl_type(const char **name,
+                                     struct _mesa_glsl_parse_state *state,
+                                     enum glsl_interface_packing packing)
+      const;
+
    virtual void print(void) const;
 
    ir_rvalue *hir(exec_list *, struct _mesa_glsl_parse_state *);
@@ -708,6 +713,11 @@ public:
 				     struct _mesa_glsl_parse_state *state)
       const;
 
+   const struct glsl_type *glsl_type(const char **name,
+                                     struct _mesa_glsl_parse_state *state,
+                                     enum glsl_interface_packing packing)
+      const;
+
    ast_type_qualifier qualifier;
    ast_type_specifier *specifier;
 };
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index bd5ea6b..04f81aa 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1894,10 +1894,15 @@ process_array_size(exec_node *node,
 static const glsl_type *
 process_array_type(YYLTYPE *loc, const glsl_type *base,
                    ast_array_specifier *array_specifier,
-                   struct _mesa_glsl_parse_state *state)
+                   struct _mesa_glsl_parse_state *state,
+                   enum glsl_interface_packing packing)
 {
    const glsl_type *array_type = base;
 
+   /* Mesa uses std140 interface packing by default. */
+   if (packing != GLSL_INTERFACE_PACKING_STD430)
+      packing = GLSL_INTERFACE_PACKING_STD140;
+
    if (array_specifier != NULL) {
       if (base->is_array()) {
 
@@ -1926,11 +1931,12 @@ process_array_type(YYLTYPE *loc, const glsl_type *base,
       for (exec_node *node = array_specifier->array_dimensions.tail_pred;
            !node->is_head_sentinel(); node = node->prev) {
          unsigned array_size = process_array_size(node, state);
-         array_type = glsl_type::get_array_instance(array_type, array_size);
+         array_type = glsl_type::get_array_instance(array_type, array_size,
+                                                    packing);
       }
 
       if (array_specifier->is_unsized_array)
-         array_type = glsl_type::get_array_instance(array_type, 0);
+         array_type = glsl_type::get_array_instance(array_type, 0, packing);
    }
 
    return array_type;
@@ -1941,13 +1947,22 @@ const glsl_type *
 ast_type_specifier::glsl_type(const char **name,
                               struct _mesa_glsl_parse_state *state) const
 {
+   return glsl_type(name, state, GLSL_INTERFACE_PACKING_STD140);
+}
+
+const glsl_type *
+ast_type_specifier::glsl_type(const char **name,
+                              struct _mesa_glsl_parse_state *state,
+                              enum glsl_interface_packing packing) const
+{
    const struct glsl_type *type;
 
    type = state->symbols->get_type(this->type_name);
    *name = this->type_name;
 
    YYLTYPE loc = this->get_location();
-   type = process_array_type(&loc, type, this->array_specifier, state);
+   type = process_array_type(&loc, type, this->array_specifier, state,
+                             packing);
 
    return type;
 }
@@ -1956,7 +1971,14 @@ const glsl_type *
 ast_fully_specified_type::glsl_type(const char **name,
                                     struct _mesa_glsl_parse_state *state) const
 {
-   const struct glsl_type *type = this->specifier->glsl_type(name, state);
+   return glsl_type(name, state, GLSL_INTERFACE_PACKING_STD140);
+}
+const glsl_type *
+ast_fully_specified_type::glsl_type(const char **name,
+                                    struct _mesa_glsl_parse_state *state,
+                                    enum glsl_interface_packing packing) const
+{
+   const struct glsl_type *type = this->specifier->glsl_type(name, state, packing);
 
    if (type == NULL)
       return NULL;
@@ -3483,7 +3505,7 @@ ast_declarator_list::hir(exec_list *instructions,
       }
 
       var_type = process_array_type(&loc, decl_type, decl->array_specifier,
-                                    state);
+                                    state, GLSL_INTERFACE_PACKING_STD140);
 
       var = new(ctx) ir_variable(var_type, decl->identifier, ir_var_auto);
 
@@ -4117,7 +4139,8 @@ ast_parameter_declarator::hir(exec_list *instructions,
    /* This only handles "vec4 foo[..]".  The earlier specifier->glsl_type(...)
     * call already handled the "vec4[..] foo" case.
     */
-   type = process_array_type(&loc, type, this->array_specifier, state);
+   type = process_array_type(&loc, type, this->array_specifier, state,
+                             GLSL_INTERFACE_PACKING_STD140);
 
    if (!type->is_error() && type->is_unsized_array()) {
       _mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
@@ -5325,7 +5348,8 @@ ast_process_structure_or_interface_block(exec_list *instructions,
                                          bool is_interface,
                                          enum glsl_matrix_layout matrix_layout,
                                          bool allow_reserved_names,
-                                         ir_variable_mode var_mode)
+                                         ir_variable_mode var_mode,
+                                         enum glsl_interface_packing packing)
 {
    unsigned decl_count = 0;
 
@@ -5361,7 +5385,7 @@ ast_process_structure_or_interface_block(exec_list *instructions,
       }
 
       const glsl_type *decl_type =
-         decl_list->type->glsl_type(& type_name, state);
+         decl_list->type->glsl_type(& type_name, state, packing);
 
       foreach_list_typed (ast_declaration, decl, link,
                           &decl_list->declarations) {
@@ -5430,7 +5454,8 @@ ast_process_structure_or_interface_block(exec_list *instructions,
          }
 
          field_type = process_array_type(&loc, decl_type,
-                                         decl->array_specifier, state);
+                                         decl->array_specifier, state,
+                                         packing);
          fields[i].type = field_type;
          fields[i].name = decl->identifier;
          fields[i].location = -1;
@@ -5543,7 +5568,8 @@ ast_struct_specifier::hir(exec_list *instructions,
                                                false,
                                                GLSL_MATRIX_LAYOUT_INHERITED,
                                                false /* allow_reserved_names */,
-                                               ir_var_auto);
+                                               ir_var_auto,
+                                               GLSL_INTERFACE_PACKING_STD140);
 
    validate_identifier(this->name, loc, state);
 
@@ -5698,7 +5724,8 @@ ast_interface_block::hir(exec_list *instructions,
                                                true,
                                                matrix_layout,
                                                redeclaring_per_vertex,
-                                               var_mode);
+                                               var_mode,
+                                               packing);
 
    state->struct_specifier_depth--;
 
@@ -5907,7 +5934,8 @@ ast_interface_block::hir(exec_list *instructions,
          }
 
          const glsl_type *block_array_type =
-            process_array_type(&loc, block_type, this->array_specifier, state);
+            process_array_type(&loc, block_type, this->array_specifier, state,
+                               GLSL_INTERFACE_PACKING_STD140);
 
           /* From section 4.3.9 (Interface Blocks) of the GLSL ES 3.10 spec:
           *
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 9575e1b..48d9ea5 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -345,10 +345,11 @@ _mesa_glsl_release_types(void)
 }
 
 
-glsl_type::glsl_type(const glsl_type *array, unsigned length) :
+glsl_type::glsl_type(const glsl_type *array, unsigned length,
+                     enum glsl_interface_packing packing) :
    base_type(GLSL_TYPE_ARRAY),
    sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
-   sampler_type(0), interface_packing(0),
+   sampler_type(0), interface_packing(packing),
    vector_elements(0), matrix_columns(0),
    length(length), name(NULL)
 {
@@ -642,6 +643,13 @@ glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
 const glsl_type *
 glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
 {
+   return get_array_instance(base, array_size, GLSL_INTERFACE_PACKING_STD140);
+}
+
+const glsl_type *
+glsl_type::get_array_instance(const glsl_type *base, unsigned array_size,
+                              enum glsl_interface_packing packing)
+{
    /* Generate a name using the base type pointer in the key.  This is
     * done because the name of the base type may not be unique across
     * shaders.  For example, two shaders may have different record types
@@ -660,7 +668,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
    const struct hash_entry *entry = _mesa_hash_table_search(array_types, key);
    if (entry == NULL) {
       mtx_unlock(&glsl_type::mutex);
-      const glsl_type *t = new glsl_type(base, array_size);
+      const glsl_type *t = new glsl_type(base, array_size, packing);
       mtx_lock(&glsl_type::mutex);
 
       entry = _mesa_hash_table_insert(array_types,
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 439188b..0d7126e 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -247,7 +247,10 @@ struct glsl_type {
     * Get the instance of an array type
     */
    static const glsl_type *get_array_instance(const glsl_type *base,
-					      unsigned elements);
+                                              unsigned elements);
+   static const glsl_type *get_array_instance(const glsl_type *base,
+					      unsigned elements,
+                                              enum glsl_interface_packing packing);
 
    /**
     * Get the instance of a record type
@@ -690,7 +693,8 @@ private:
 	     enum glsl_interface_packing packing, const char *name);
 
    /** Constructor for array types */
-   glsl_type(const glsl_type *array, unsigned length);
+   glsl_type(const glsl_type *array, unsigned length,
+             enum glsl_interface_packing packing);
 
    /** Hash table containing the known array types. */
    static struct hash_table *array_types;
-- 
1.9.1



More information about the mesa-dev mailing list