glsl: Move is_builtin flag back to ir_function_signature.
authorKenneth Graunke <kenneth@whitecape.org>
Sun, 5 Sep 2010 08:48:11 +0000 (01:48 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Wed, 8 Sep 2010 00:30:38 +0000 (17:30 -0700)
This effectively reverts b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c.

In desktop GLSL, defining a function with the same name as a built-in
hides that built-in function completely, so there would never be
built-in and user function signatures in the same ir_function.

However, in GLSL ES, overloading built-ins is allowed, and does not
hide the built-in signatures - so we're back to needing this.

src/glsl/ast_to_hir.cpp
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_clone.cpp
src/glsl/ir_constant_expression.cpp
src/glsl/ir_import_prototypes.cpp
src/glsl/ir_print_visitor.cpp
src/glsl/ir_reader.cpp
src/glsl/linker.cpp

index 9e639efd0ab0326fcd59e0bd29e7c369589e20a6..b8a01b8db866ba4b76e46332ad391b8da3d7cca4 100644 (file)
@@ -2279,7 +2279,7 @@ ast_function::hir(exec_list *instructions,
     * that the previously seen signature does not have an associated definition.
     */
    f = state->symbols->get_function(name);
-   if (f != NULL && !f->is_builtin) {
+   if (f != NULL && !f->has_builtin_signature()) {
       sig = f->exact_matching_signature(&hir_parameters);
       if (sig != NULL) {
         const char *badvar = sig->qualifiers_match(&hir_parameters);
index 6d72725374003d25e1ceda951f1210243e9584b7..9ac24858958830ade0683b89da85ca342b197a8c 100644 (file)
@@ -1073,6 +1073,7 @@ ir_function_signature::ir_function_signature(const glsl_type *return_type)
    : return_type(return_type), is_defined(false), _function(NULL)
 {
    this->ir_type = ir_type_function_signature;
+   this->is_builtin = false;
 }
 
 
@@ -1124,7 +1125,18 @@ ir_function::ir_function(const char *name)
 {
    this->ir_type = ir_type_function;
    this->name = talloc_strdup(this, name);
-   this->is_builtin = false;
+}
+
+
+bool
+ir_function::has_builtin_signature()
+{
+   foreach_list(n, &this->signatures) {
+      ir_function_signature *const sig = (ir_function_signature *) n;
+      if (sig->is_builtin)
+        return true;
+   }
+   return false;
 }
 
 
index efe59d80642f3096d55a512a8680146926cdfa7f..0d933024df08a9ff9abe095000b0051790b75ef0 100644 (file)
@@ -342,6 +342,9 @@ public:
    /** Whether or not this function has a body (which may be empty). */
    unsigned is_defined:1;
 
+   /** Whether or not this function signature is a built-in. */
+   unsigned is_builtin:1;
+
    /** Body of instructions in the function. */
    struct exec_list body;
 
@@ -407,8 +410,8 @@ public:
     */
    const char *name;
 
-   /** Whether or not this function is a built-in. */
-   unsigned is_builtin:1;
+   /** Whether or not this function has a signature that is a built-in. */
+   bool has_builtin_signature();
 
    /**
     * List of ir_function_signature for each overloaded function with this name.
index 3b8beb54b53d008c6959733b03df87a0c4423809..aa84cf0572514ae7361d5a76e35d0a73563c505e 100644 (file)
@@ -250,8 +250,6 @@ ir_function::clone(void *mem_ctx, struct hash_table *ht) const
 {
    ir_function *copy = new(mem_ctx) ir_function(this->name);
 
-   copy->is_builtin = this->is_builtin;
-
    foreach_list_const(node, &this->signatures) {
       const ir_function_signature *const sig =
         (const ir_function_signature *const) node;
@@ -274,6 +272,7 @@ ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const
       new(mem_ctx) ir_function_signature(this->return_type);
 
    copy->is_defined = this->is_defined;
+   copy->is_builtin = this->is_builtin;
 
    /* Clone the parameter list.
     */
index 458dca7977a17b301a20d66ee9fdb2e65be74057..ca12392a74f747b98282d193e24d5beac8b4eaa0 100644 (file)
@@ -785,7 +785,7 @@ ir_call::constant_expression_value()
     * "Function calls to user-defined functions (non-built-in functions)
     *  cannot be used to form constant expressions."
     */
-   if (!this->callee->function()->is_builtin)
+   if (!this->callee->is_builtin)
       return NULL;
 
    unsigned num_parameters = 0;
index a39b384071a326643c41a7982944172e9e5b9a67..066137e60aab5d9b372a64f9788050803231bbd8 100644 (file)
@@ -59,7 +59,6 @@ public:
       this->function = this->symbols->get_function(ir->name);
       if (!this->function) {
         this->function = new(this->mem_ctx) ir_function(ir->name);
-        this->function->is_builtin = ir->is_builtin;
 
         list->push_tail(this->function);
 
@@ -87,6 +86,7 @@ public:
         new(mem_ctx) ir_function_signature(ir->return_type);
 
       copy->is_defined = false;
+      copy->is_builtin = ir->is_builtin;
 
       /* Clone the parameter list, but NOT the body.
        */
index 9d81cef9f858b560e94d63ee34e74f8fb8b5f2ca..eff950ebd79461df7fe827871225672b45e3b5af 100644 (file)
@@ -153,15 +153,14 @@ void ir_print_visitor::visit(ir_function_signature *ir)
 
 void ir_print_visitor::visit(ir_function *ir)
 {
-   /* Don't print built-in functions as part of the IR. */
-   if (ir->is_builtin)
-      return;
-
    printf("(function %s\n", ir->name);
    indentation++;
    foreach_iter(exec_list_iterator, iter, *ir) {
       ir_function_signature *const sig = (ir_function_signature *) iter.get();
 
+      if (sig->is_builtin)
+        continue;
+
       indent();
       sig->accept(this);
       printf("\n");
index 04b982974e10402bdea2a8dcbcf926a19d3e06ea..a9cbf8ea94457b9a561c8abd9e9bd5be5a789881 100644 (file)
@@ -218,7 +218,6 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body)
    ir_function *f = st->symbols->get_function(name->value());
    if (f == NULL) {
       f = new(ctx) ir_function(name->value());
-      f->is_builtin = true;
       added = st->symbols->add_function(f->name, f);
       assert(added);
    }
@@ -291,6 +290,7 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list,
    if (sig == NULL && skip_body) {
       /* If scanning for prototypes, generate a new signature. */
       sig = new(ctx) ir_function_signature(return_type);
+      sig->is_builtin = true;
       f->add_signature(sig);
    } else if (sig != NULL) {
       const char *badvar = sig->qualifiers_match(&hir_parameters);
index 4d84ab39b38db6d15e6895e5c0db783a52e4ce60..78f3a7402badf259a168d0f2dbb0744e55b769be 100644 (file)
@@ -740,14 +740,14 @@ link_intrastage_shaders(GLcontext *ctx,
               ir_function_signature *sig =
                  (ir_function_signature *) iter.get();
 
-              if (!sig->is_defined || f->is_builtin)
+              if (!sig->is_defined || sig->is_builtin)
                  continue;
 
               ir_function_signature *other_sig =
                  other->exact_matching_signature(& sig->parameters);
 
               if ((other_sig != NULL) && other_sig->is_defined
-                  && !other_sig->function()->is_builtin) {
+                  && !other_sig->is_builtin) {
                  linker_error_printf(prog,
                                      "function `%s' is multiply defined",
                                      f->name);