glsl: Pass _mesa_glsl_parse_state into matching_signature and such.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 31 Aug 2013 06:11:55 +0000 (23:11 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 9 Sep 2013 18:52:21 +0000 (11:52 -0700)
During compilation, we'll use this to determine built-in availability.
The plan is to have a single shader containing every built-in in every
version of the language, but filter out the ones that aren't actually
available to the shader being compiled.

At link time, we don't actually need this filtering capability: we've
already imported prototypes for every built-in that the shader actually
calls, and they're flagged as is_builtin().  The linker doesn't import
any additional prototypes, so it won't pull in any unavailable
built-ins.  When resolving prototypes to function definitions, the
linker ensures the values of is_builtin() match, which means that a
shader can't trick the linker into importing the body of an unavailable
built-in by defining a suspiciously similar prototype.

In other words, during linking, we can just pass in NULL.  It will work
out fine.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
12 files changed:
src/glsl/ast_function.cpp
src/glsl/ast_to_hir.cpp
src/glsl/ir.h
src/glsl/ir_function.cpp
src/glsl/ir_reader.cpp
src/glsl/link_functions.cpp
src/glsl/linker.cpp
src/glsl/lower_packed_varyings.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 7df2b692592c2d661be7119b5fe08839cb528ccd..7580bec3209ce4660bf56f2826ad9497833c4862 100644 (file)
@@ -388,7 +388,8 @@ match_function_by_name(const char *name,
    if (f != NULL) {
       /* Look for a match in the local shader.  If exact, we're done. */
       bool is_exact = false;
-      sig = local_sig = f->matching_signature(actual_parameters, &is_exact);
+      sig = local_sig = f->matching_signature(state, actual_parameters,
+                                              &is_exact);
       if (is_exact)
         goto done;
 
@@ -411,7 +412,7 @@ match_function_by_name(const char *name,
 
       bool is_exact = false;
       ir_function_signature *builtin_sig =
-        builtin->matching_signature(actual_parameters, &is_exact);
+        builtin->matching_signature(state, actual_parameters, &is_exact);
 
       if (builtin_sig == NULL)
         continue;
index 52059e4bfb3937ea1454ad7f37be6f430f997943..2316cf8e5e45e147883baa2b8a9b6992be898b60 100644 (file)
@@ -3576,7 +3576,7 @@ ast_function::hir(exec_list *instructions,
     */
    f = state->symbols->get_function(name);
    if (f != NULL && (state->es_shader || f->has_user_signature())) {
-      sig = f->exact_matching_signature(&hir_parameters);
+      sig = f->exact_matching_signature(state, &hir_parameters);
       if (sig != NULL) {
         const char *badvar = sig->qualifiers_match(&hir_parameters);
         if (badvar != NULL) {
index bd1c12cd90a45fb832138e2710ed8935ae1752a3..c673aac416cd552f634b0485339d011cb57aa031 100644 (file)
@@ -765,20 +765,23 @@ public:
     * Find a signature that matches a set of actual parameters, taking implicit
     * conversions into account.  Also flags whether the match was exact.
     */
-   ir_function_signature *matching_signature(const exec_list *actual_param,
+   ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
+                                             const exec_list *actual_param,
                                             bool *match_is_exact);
 
    /**
     * Find a signature that matches a set of actual parameters, taking implicit
     * conversions into account.
     */
-   ir_function_signature *matching_signature(const exec_list *actual_param);
+   ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
+                                             const exec_list *actual_param);
 
    /**
     * Find a signature that exactly matches a set of actual parameters without
     * any implicit type conversions.
     */
-   ir_function_signature *exact_matching_signature(const exec_list *actual_ps);
+   ir_function_signature *exact_matching_signature(_mesa_glsl_parse_state *state,
+                                                   const exec_list *actual_ps);
 
    /**
     * Name of the function.
index fe4209c77cce58b53f467f64c3c3339765ce2940..2dd98bcc291a895e5b9392aceef47f7348ad2e75 100644 (file)
@@ -116,14 +116,16 @@ parameter_lists_match(const exec_list *list_a, const exec_list *list_b)
 
 
 ir_function_signature *
-ir_function::matching_signature(const exec_list *actual_parameters)
+ir_function::matching_signature(_mesa_glsl_parse_state *state,
+                                const exec_list *actual_parameters)
 {
    bool is_exact;
-   return matching_signature(actual_parameters, &is_exact);
+   return matching_signature(state, actual_parameters, &is_exact);
 }
 
 ir_function_signature *
-ir_function::matching_signature(const exec_list *actual_parameters,
+ir_function::matching_signature(_mesa_glsl_parse_state *state,
+                                const exec_list *actual_parameters,
                                bool *is_exact)
 {
    ir_function_signature *match = NULL;
@@ -203,7 +205,8 @@ parameter_lists_match_exact(const exec_list *list_a, const exec_list *list_b)
 }
 
 ir_function_signature *
-ir_function::exact_matching_signature(const exec_list *actual_parameters)
+ir_function::exact_matching_signature(_mesa_glsl_parse_state *state,
+                                      const exec_list *actual_parameters)
 {
    foreach_iter(exec_list_iterator, iter, signatures) {
       ir_function_signature *const sig =
index 8261d9f43f613d0b10034bca8e4bc6d2b135eb1b..ec35b682eaf87678a232116b57bc24183d4620aa 100644 (file)
@@ -254,7 +254,8 @@ ir_reader::read_function_sig(ir_function *f, s_expression *expr, bool skip_body)
       hir_parameters.push_tail(var);
    }
 
-   ir_function_signature *sig = f->exact_matching_signature(&hir_parameters);
+   ir_function_signature *sig =
+      f->exact_matching_signature(state, &hir_parameters);
    if (sig == NULL && skip_body) {
       /* If scanning for prototypes, generate a new signature. */
       /* ir_reader doesn't know what languages support a given built-in, so
@@ -668,7 +669,7 @@ ir_reader::read_call(s_expression *expr)
       return NULL;
    }
 
-   ir_function_signature *callee = f->matching_signature(&parameters);
+   ir_function_signature *callee = f->matching_signature(state, &parameters);
    if (callee == NULL) {
       ir_read_error(expr, "couldn't find matching signature for function "
                     "%s", name->value());
index c5398f5ff0416198361ccc5bdf60ffdaee691880..9e96365e6de9120caef11f9487695420bcf0181b 100644 (file)
@@ -113,7 +113,7 @@ public:
       }
 
       ir_function_signature *linked_sig =
-        f->exact_matching_signature(&callee->parameters);
+        f->exact_matching_signature(NULL, &callee->parameters);
       if ((linked_sig == NULL)
          || ((linked_sig != NULL)
              && (linked_sig->is_builtin() != ir->use_builtin))) {
@@ -288,7 +288,8 @@ find_matching_signature(const char *name, const exec_list *actual_parameters,
       if (f == NULL)
         continue;
 
-      ir_function_signature *sig = f->matching_signature(actual_parameters);
+      ir_function_signature *sig =
+         f->matching_signature(NULL, actual_parameters);
 
       if ((sig == NULL) || !sig->is_defined)
         continue;
index 350778a01c6da25bd7e9d786b5cfd4997e8aeb7a..65afc2e69b4ff4474071c66a78bccf4fb7a756b0 100644 (file)
@@ -982,7 +982,7 @@ get_main_function_signature(gl_shader *sh)
        * We don't have to check for multiple definitions of main (in multiple
        * shaders) because that would have already been caught above.
        */
-      ir_function_signature *sig = f->matching_signature(&void_parameters);
+      ir_function_signature *sig = f->matching_signature(NULL, &void_parameters);
       if ((sig != NULL) && sig->is_defined) {
         return sig;
       }
@@ -1167,7 +1167,7 @@ link_intrastage_shaders(void *mem_ctx,
                  continue;
 
               ir_function_signature *other_sig =
-                 other->exact_matching_signature(sig->parameters);
+                 other->exact_matching_signature(NULL, &sig->parameters);
 
               if ((other_sig != NULL) && other_sig->is_defined
                   && !other_sig->is_builtin()) {
index 31a50bba59fc5be25b86efe96e68fca3477ec956..4f617225c0f2169680cda90b60b5dfafb88f08bf 100644 (file)
@@ -658,7 +658,7 @@ lower_packed_varyings(void *mem_ctx, unsigned location_base,
    ir_function *main_func = shader->symbols->get_function("main");
    exec_list void_parameters;
    ir_function_signature *main_func_sig
-      = main_func->matching_signature(&void_parameters);
+      = main_func->matching_signature(NULL, &void_parameters);
    exec_list new_instructions;
    lower_packed_varyings_visitor visitor(mem_ctx, location_base,
                                          locations_used, mode,
index 1e01d39d8b4da4e972cd117adc5312679f66a24c..543fe5e8ab1199900011b0e79644f04f42bbddf1 100644 (file)
@@ -2072,7 +2072,7 @@ fs_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(&empty);
+      sig = ir->matching_signature(NULL, &empty);
 
       assert(sig);
 
index 8cfe4e3d93088528e513818a68b8408913116063..3a2f047f46d59f61b92dca2eba05fd4c410553f0 100644 (file)
@@ -1056,7 +1056,7 @@ vec4_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(&empty);
+      sig = ir->matching_signature(NULL, &empty);
 
       assert(sig);
 
index 340a4497fdd3f3b86982670a4c7a2a30e55ec490..fe9cac05f566bf41a3c0ea4c92ea434a327bc669 100644 (file)
@@ -837,7 +837,7 @@ ir_to_mesa_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(&empty);
+      sig = ir->matching_signature(NULL, &empty);
 
       assert(sig);
 
index 37779d4e5e4031caac4923c0c32d030547061b54..d4c4260105c6bed9a1c6aa51e9b89f38ed9ef5d9 100644 (file)
@@ -1209,7 +1209,7 @@ glsl_to_tgsi_visitor::visit(ir_function *ir)
       const ir_function_signature *sig;
       exec_list empty;
 
-      sig = ir->matching_signature(&empty);
+      sig = ir->matching_signature(NULL, &empty);
 
       assert(sig);