]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Split up ComponentSpecializer
[libs/gl.git] / source / glsl / compiler.cpp
index 8a18fdf48df64d6224f9fc3f8d0b00d6a749be7e..fab054737a8872bc7e8631b2298615c0fc9b6cf0 100644 (file)
@@ -2,14 +2,15 @@
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
 #include "builtin.h"
-#include "compatibility.h"
 #include "compiler.h"
 #include "debug.h"
 #include "error.h"
+#include "finalize.h"
 #include "generate.h"
 #include "glsl_error.h"
 #include "optimize.h"
 #include "output.h"
+#include "resolve.h"
 #include "resources.h"
 #include "validate.h"
 
@@ -78,7 +79,7 @@ void Compiler::specialize(const map<string, int> &sv)
 void Compiler::compile(Mode mode)
 {
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
-               generate(*i, mode);
+               generate(*i);
 
        bool valid = true;
        for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
@@ -87,8 +88,12 @@ void Compiler::compile(Mode mode)
        if(!valid)
                throw invalid_shader_source(get_diagnostics());
 
-       unsigned n = 0;
-       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++n)
+       if(mode==PROGRAM && specialized)
+       {
+               for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
+                       ConstantSpecializer().apply(*i, spec_values);
+       }
+       for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); )
        {
                OptimizeResult result = optimize(*i);
                if(result==REDO_PREVIOUS)
@@ -243,7 +248,7 @@ void Compiler::import(DataFile::Collection *resources, const string &name)
        append_module(import_parser.parse(*io, fn, module->source_map.get_count()), resources);
 }
 
-void Compiler::generate(Stage &stage, Mode mode)
+void Compiler::generate(Stage &stage)
 {
        stage.required_features.gl_api = features.gl_api;
        if(module->shared.required_features.glsl_version>stage.required_features.glsl_version)
@@ -263,12 +268,7 @@ void Compiler::generate(Stage &stage, Mode mode)
        InterfaceGenerator().apply(stage);
        resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES);
 
-       ConstantSpecializer().apply(stage, (mode==PROGRAM && specialized ? &spec_values : 0));
-       if(mode==PROGRAM)
-       {
-               LegacyConverter().apply(stage, features);
-               resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
-       }
+       ConstantIdAssigner().apply(stage);
 }
 
 template<typename T>
@@ -300,8 +300,8 @@ void Compiler::resolve(Stage &stage, unsigned flags)
 
 bool Compiler::validate(Stage &stage)
 {
-       TypeValidator().apply(stage);
        DeclarationValidator().apply(stage);
+       IdentifierValidator().apply(stage);
        ReferenceValidator().apply(stage);
        ExpressionValidator().apply(stage);
 
@@ -358,10 +358,12 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage)
 
 void Compiler::finalize(Stage &stage, Mode mode)
 {
-       if(get_gl_api()==OPENGL_ES2 && mode==PROGRAM)
-               DefaultPrecisionGenerator().apply(stage);
-       else if(mode==MODULE)
-               PrecisionRemover().apply(stage);
+       if(mode==PROGRAM)
+       {
+               LegacyConverter().apply(stage, features);
+               resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS);
+               PrecisionConverter().apply(stage);
+       }
 }
 
 void Compiler::inject_block(Block &target, const Block &source)