summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2015-04-20 10:22:57 +1000
committerDave Airlie <[email protected]>2015-07-23 17:25:32 +1000
commit30681c3bb80ad78392f1740aa915efa072c837e8 (patch)
tree7de576f29799ea7e571ad904332c619d34e872dc /src
parentd8a250ce5edc3da092ede6d62d433fbb37aa6cf6 (diff)
glsl/ir: add subroutine information storage to ir_function (v1.1)
We need to store two sets of info into the ir_function, if this is a function definition with a subroutine list (subroutine_def) or if it a subroutine prototype. v1.1: add some more documentation. Reviewed-by: Chris Forbes <[email protected]> Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/glsl/ir.cpp4
-rw-r--r--src/glsl/ir.h15
-rw-r--r--src/glsl/ir_clone.cpp6
-rw-r--r--src/glsl/ir_print_visitor.cpp2
4 files changed, 26 insertions, 1 deletions
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index fa1d85a5026..3a40926e911 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1855,6 +1855,7 @@ static void
steal_memory(ir_instruction *ir, void *new_ctx)
{
ir_variable *var = ir->as_variable();
+ ir_function *fn = ir->as_function();
ir_constant *constant = ir->as_constant();
if (var != NULL && var->constant_value != NULL)
steal_memory(var->constant_value, ir);
@@ -1862,6 +1863,9 @@ steal_memory(ir_instruction *ir, void *new_ctx)
if (var != NULL && var->constant_initializer != NULL)
steal_memory(var->constant_initializer, ir);
+ if (fn != NULL && fn->subroutine_types)
+ ralloc_steal(new_ctx, fn->subroutine_types);
+
/* The components of aggregate constants are not visited by the normal
* visitor, so steal their values by hand.
*/
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 8294b8a19bd..da867427e1a 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -1126,6 +1126,21 @@ public:
* List of ir_function_signature for each overloaded function with this name.
*/
struct exec_list signatures;
+
+ /**
+ * is this function a subroutine type declaration
+ * e.g. subroutine void type1(float arg1);
+ */
+ bool is_subroutine;
+
+ /**
+ * is this function associated to a subroutine type
+ * e.g. subroutine (type1, type2) function_name { function_body };
+ * would have num_subroutine_types 2,
+ * and pointers to the type1 and type2 types.
+ */
+ int num_subroutine_types;
+ const struct glsl_type **subroutine_types;
};
inline const char *ir_function_signature::function_name() const
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 49834ffbabf..a8fac183a8d 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -267,6 +267,12 @@ ir_function::clone(void *mem_ctx, struct hash_table *ht) const
{
ir_function *copy = new(mem_ctx) ir_function(this->name);
+ copy->is_subroutine = this->is_subroutine;
+ copy->num_subroutine_types = this->num_subroutine_types;
+ copy->subroutine_types = ralloc_array(mem_ctx, const struct glsl_type *, copy->num_subroutine_types);
+ for (int i = 0; i < copy->num_subroutine_types; i++)
+ copy->subroutine_types[i] = this->subroutine_types[i];
+
foreach_in_list(const ir_function_signature, sig, &this->signatures) {
ir_function_signature *sig_copy = sig->clone(mem_ctx, ht);
copy->add_signature(sig_copy);
diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
index 428fc310373..78475f39b78 100644
--- a/src/glsl/ir_print_visitor.cpp
+++ b/src/glsl/ir_print_visitor.cpp
@@ -231,7 +231,7 @@ void ir_print_visitor::visit(ir_function_signature *ir)
void ir_print_visitor::visit(ir_function *ir)
{
- fprintf(f, "(function %s\n", ir->name);
+ fprintf(f, "(%s function %s\n", ir->is_subroutine ? "subroutine" : "", ir->name);
indentation++;
foreach_in_list(ir_function_signature, sig, &ir->signatures) {
indent();