]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Remove unnecessary includes
[libs/gl.git] / source / glsl / compiler.cpp
index c68b67bd0cd629f81db2838c60840b43c1abe720..7fe608bf6b0c80cce51a987f79ea4be225632494 100644 (file)
@@ -1,5 +1,4 @@
 #include <msp/core/algorithm.h>
-#include <msp/gl/extensions/ext_gpu_shader4.h>
 #include <msp/strings/format.h>
 #include "builtin.h"
 #include "compatibility.h"
@@ -10,7 +9,6 @@
 #include "optimize.h"
 #include "output.h"
 #include "resources.h"
-#include "shader.h"
 
 #undef interface
 
@@ -76,11 +74,13 @@ void Compiler::compile(Mode mode)
 {
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
                generate(*i, mode);
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); )
+       unsigned n = 0;
+       for(list<Stage>::iterator i=module->stages.begin(); (i!=module->stages.end() && n<10000); ++n)
        {
-               if(optimize(*i))
+               OptimizeResult result = optimize(*i);
+               if(result==REDO_PREVIOUS)
                        i = module->stages.begin();
-               else
+               else if(result!=REDO_STAGE)
                        ++i;
        }
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
@@ -221,8 +221,6 @@ void Compiler::generate(Stage &stage, Mode mode)
                stage.required_features.glsl_version = module->shared.required_features.glsl_version;
        inject_block(stage.content, module->shared.content);
 
-       DeclarationReorderer().apply(stage);
-
        // Initial resolving pass
        BlockHierarchyResolver().apply(stage);
        FunctionResolver().apply(stage);
@@ -233,27 +231,30 @@ void Compiler::generate(Stage &stage, Mode mode)
        InterfaceGenerator().apply(stage);
        VariableResolver().apply(stage);
 
-       DeclarationReorderer().apply(stage);
        FunctionResolver().apply(stage);
        ConstantSpecializer().apply(stage, (mode==PROGRAM && specialized ? &spec_values : 0));
        if(mode==PROGRAM)
                LegacyConverter().apply(stage, features);
 }
 
-bool Compiler::optimize(Stage &stage)
+Compiler::OptimizeResult Compiler::optimize(Stage &stage)
 {
        ConstantConditionEliminator().apply(stage);
 
-       FunctionInliner().apply(stage);
-       BlockHierarchyResolver().apply(stage);
-       VariableResolver().apply(stage);
+       bool any_inlined = FunctionInliner().apply(stage);
+       any_inlined |= ExpressionInliner().apply(stage);
+       if(any_inlined)
+       {
+               VariableResolver().apply(stage);
+               FunctionResolver().apply(stage);
+       }
 
        /* Removing variables or functions may cause things from the previous stage
        to become unused. */
-       bool result = UnusedVariableRemover().apply(stage);
-       result |= UnusedFunctionRemover().apply(stage);
+       bool any_removed = UnusedVariableRemover().apply(stage);
+       any_removed |= UnusedFunctionRemover().apply(stage);
 
-       return result;
+       return any_removed ? REDO_PREVIOUS : any_inlined ? REDO_STAGE : NEXT_STAGE;
 }
 
 void Compiler::finalize(Stage &stage, Mode mode)