glsl/standalone: Enable par-linking
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 15 Sep 2016 18:24:12 +0000 (11:24 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Thu, 10 Nov 2016 22:30:49 +0000 (14:30 -0800)
If the user did not request full linking, link the shader with the
built-in functions, inline them, and eliminate them.  Previous to this
you'd see all these calls to "dot" and "max" in the output.  This
prevented a lot of expected optimizations and cluttered the output.
This gives it some chance of being useful.

v2: Rebase on top of Ken's "built-ins now" work.

v3: Don't do_common_optimizations if par-linking fails.  Update expected
output of warnings tests to prevent 'make check' regressions.

v4: Optimize harder.  Most important, do function inlining.  Otherwise
it's quite impractical for one function in a file to call another
function in the same file.

v5: Add some code simplifications and an assertion suggested by Iago.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
src/compiler/glsl/standalone.cpp
src/compiler/glsl/tests/warnings/026-out-function-parameter-shaderout.vert.expected
src/compiler/glsl/tests/warnings/027-inout-function-parameter-shaderout.vert.expected
src/compiler/glsl/tests/warnings/030-array-as-function-parameter.vert.expected

index 7e633a72c6a32ba43166ddc9984e7cad9344e7b4..73c7408a96bdbc9ed06556c67a72ced9744441ce 100644 (file)
@@ -38,6 +38,8 @@
 #include "standalone.h"
 #include "util/string_to_uint_map.h"
 #include "util/set.h"
+#include "linker.h"
+#include "glsl_parser_extras.h"
 #include "opt_add_neg_to_sub.h"
 
 class dead_variable_visitor : public ir_hierarchical_visitor {
@@ -478,10 +480,49 @@ standalone_compile_shader(const struct standalone_options *_options,
       }
    }
 
-   if ((status == EXIT_SUCCESS) && options->do_link)  {
+   if (status == EXIT_SUCCESS) {
       _mesa_clear_shader_program_data(ctx, whole_program);
 
-      link_shaders(ctx, whole_program);
+      if (options->do_link)  {
+         link_shaders(ctx, whole_program);
+      } else {
+         const gl_shader_stage stage = whole_program->Shaders[0]->Stage;
+
+         whole_program->LinkStatus = GL_TRUE;
+         whole_program->_LinkedShaders[stage] =
+            link_intrastage_shaders(whole_program /* mem_ctx */,
+                                    ctx,
+                                    whole_program,
+                                    whole_program->Shaders,
+                                    1,
+                                    true);
+
+         /* Par-linking can fail, for example, if there are undefined external
+          * references.
+          */
+         if (whole_program->_LinkedShaders[stage] != NULL) {
+            assert(whole_program->LinkStatus);
+
+            struct gl_shader_compiler_options *const compiler_options =
+               &ctx->Const.ShaderCompilerOptions[stage];
+
+            exec_list *const ir =
+               whole_program->_LinkedShaders[stage]->ir;
+
+            bool progress;
+            do {
+               progress = do_function_inlining(ir);
+
+               progress = do_common_optimization(ir,
+                                                 false,
+                                                 false,
+                                                 compiler_options,
+                                                 true)
+                  && progress;
+            } while(progress);
+         }
+      }
+
       status = (whole_program->LinkStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
 
       if (strlen(whole_program->InfoLog) > 0) {
index 17249752d226bf771050083910b496556d320438..651818d9195fb4016df6fdef56b49c9a94ffb6a9 100644 (file)
@@ -1 +1,3 @@
 0:11(14): warning: `willBeDefined' used uninitialized
+
+error: unresolved reference to function `fooFunction'
index 21cb2c5a2c80bbac438532ff1eeffad6b5796051..b1355d3a947c71e14e0e78809966b0384f76c17a 100644 (file)
@@ -5,3 +5,5 @@
 0:14(20): warning: `undefinedIndex' used uninitialized
 0:14(51): warning: `undefinedIndex' used uninitialized
 0:14(82): warning: `undefinedIndex' used uninitialized
+
+error: unresolved reference to function `foo'