summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimothy Arceri <t_arceri@yahoo.com.au>2015-08-05 15:49:22 +1000
committerTimothy Arceri <timothy.arceri@collabora.com>2015-10-21 14:56:57 +1100
commitfd01840c0bd3b22d058a65a17ad30e3b45813b60 (patch)
treeeed8c7c0acdbfb1871ca3328ce892e576b70ebef
parenta59c1adcc665b70ca5a8fbfebe3f0d6e05ad2778 (diff)
downloadexternal_mesa3d-fd01840c0bd3b22d058a65a17ad30e3b45813b60.zip
external_mesa3d-fd01840c0bd3b22d058a65a17ad30e3b45813b60.tar.gz
external_mesa3d-fd01840c0bd3b22d058a65a17ad30e3b45813b60.tar.bz2
glsl: add AoA support to subroutines
process_parameters() will now be called earlier because we need actual_parameters processed earlier so we can use it with match_subroutine_by_name() to get the subroutine variable, we need to do this inside the recursive function generate_array_index() because we can't create the ir_dereference_array() until we have gotten to the outermost array. For the remainder of the array dimensions the type doesn't matter so we can just use the existing _mesa_ast_array_index_to_hir() function to process the ast. Reviewed-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--src/glsl/ast_function.cpp43
-rw-r--r--src/glsl/lower_subroutine.cpp2
2 files changed, 39 insertions, 6 deletions
diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index c5c5cae..e4e4a3f 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -610,6 +610,37 @@ match_subroutine_by_name(const char *name,
return sig;
}
+static ir_rvalue *
+generate_array_index(void *mem_ctx, exec_list *instructions,
+ struct _mesa_glsl_parse_state *state, YYLTYPE loc,
+ const ast_expression *array, ast_expression *idx,
+ const char **function_name, exec_list *actual_parameters)
+{
+ if (array->oper == ast_array_index) {
+ /* This handles arrays of arrays */
+ ir_rvalue *outer_array = generate_array_index(mem_ctx, instructions,
+ state, loc,
+ array->subexpressions[0],
+ array->subexpressions[1],
+ function_name, actual_parameters);
+ ir_rvalue *outer_array_idx = idx->hir(instructions, state);
+
+ YYLTYPE index_loc = idx->get_location();
+ return _mesa_ast_array_index_to_hir(mem_ctx, state, outer_array,
+ outer_array_idx, loc,
+ index_loc);
+ } else {
+ ir_variable *sub_var = NULL;
+ *function_name = array->primary_expression.identifier;
+
+ match_subroutine_by_name(*function_name, actual_parameters,
+ state, &sub_var);
+
+ ir_rvalue *outer_array_idx = idx->hir(instructions, state);
+ return new(mem_ctx) ir_dereference_array(sub_var, outer_array_idx);
+ }
+}
+
static void
print_function_prototypes(_mesa_glsl_parse_state *state, YYLTYPE *loc,
ir_function *f)
@@ -1989,16 +2020,18 @@ ast_function_expression::hir(exec_list *instructions,
ir_variable *sub_var = NULL;
ir_rvalue *array_idx = NULL;
+ process_parameters(instructions, &actual_parameters, &this->expressions,
+ state);
+
if (id->oper == ast_array_index) {
- func_name = id->subexpressions[0]->primary_expression.identifier;
- array_idx = id->subexpressions[1]->hir(instructions, state);
+ array_idx = generate_array_index(ctx, instructions, state, loc,
+ id->subexpressions[0],
+ id->subexpressions[1], &func_name,
+ &actual_parameters);
} else {
func_name = id->primary_expression.identifier;
}
- process_parameters(instructions, &actual_parameters, &this->expressions,
- state);
-
ir_function_signature *sig =
match_function_by_name(func_name, &actual_parameters, state);
diff --git a/src/glsl/lower_subroutine.cpp b/src/glsl/lower_subroutine.cpp
index c1aed61..a0df5e1 100644
--- a/src/glsl/lower_subroutine.cpp
+++ b/src/glsl/lower_subroutine.cpp
@@ -84,7 +84,7 @@ lower_subroutine_visitor::visit_leave(ir_call *ir)
continue;
if (ir->array_idx != NULL)
- var = new(mem_ctx) ir_dereference_array(ir->sub_var, ir->array_idx->clone(mem_ctx, NULL));
+ var = ir->array_idx->clone(mem_ctx, NULL);
else
var = new(mem_ctx) ir_dereference_variable(ir->sub_var);