[Mesa-dev] [PATCH v2 45/82] glsl: propagate interface packing information to arrays of scalars, vectors.
Iago Toral Quiroga
itoral at igalia.com
Wed Jun 3 00:01:35 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 | 16 +++++++++++----
src/glsl/glsl_types.h | 8 ++++++--
4 files changed, 69 insertions(+), 19 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 ae8d303..fc84e9d 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);
@@ -4025,7 +4047,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 "
@@ -5233,7 +5256,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;
@@ -5269,7 +5293,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) {
@@ -5338,7 +5362,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;
@@ -5451,7 +5476,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);
@@ -5606,7 +5632,8 @@ ast_interface_block::hir(exec_list *instructions,
true,
matrix_layout,
redeclaring_per_vertex,
- var_mode);
+ var_mode,
+ packing);
state->struct_specifier_depth--;
@@ -5815,7 +5842,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);
var = new(state) ir_variable(block_array_type,
this->instance_name,
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 9e1e247..bf8b43c 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -340,10 +340,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)
{
@@ -637,6 +638,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
@@ -649,14 +657,14 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
if (array_types == NULL) {
array_types = hash_table_ctor(64, hash_table_string_hash,
- hash_table_string_compare);
+ hash_table_string_compare);
}
const glsl_type *t = (glsl_type *) hash_table_find(array_types, key);
if (t == NULL) {
mtx_unlock(&glsl_type::mutex);
- t = new glsl_type(base, array_size);
+ t = new glsl_type(base, array_size, packing);
mtx_lock(&glsl_type::mutex);
hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key));
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 42d5ab9..2a5fa30 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