X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fcompiler.cpp;h=55a69f0df38ecaf1b681f9a698e6bbc2abed02da;hb=518f751d385b733adbf43fe4056403740709edec;hp=5bec9c8b1b8f475163b50a35b57b0a92e5bec84b;hpb=30465dd3b9f55ec42c4b19c3c2077eede7237a26;p=libs%2Fgl.git diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index 5bec9c8b..55a69f0d 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "builtin.h" #include "compatibility.h" #include "compiler.h" #include "debug.h" @@ -75,11 +76,13 @@ void Compiler::compile(Mode mode) { for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) generate(*i, mode); - for(list::iterator i=module->stages.begin(); i!=module->stages.end(); ) + unsigned n = 0; + for(list::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::iterator i=module->stages.begin(); i!=module->stages.end(); ++i) @@ -185,6 +188,13 @@ void Compiler::append_stage(Stage &stage) target = &*i; } + if(target->content.body.empty()) + { + Stage *builtins = get_builtins(stage.type); + if(builtins && builtins!=&stage) + append_stage(*builtins); + } + if(stage.required_features.glsl_version>target->required_features.glsl_version) target->required_features.glsl_version = stage.required_features.glsl_version; for(NodeList::iterator i=stage.content.body.begin(); i!=stage.content.body.end(); ++i) @@ -213,8 +223,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); @@ -225,27 +233,26 @@ 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); + bool any_inlined = FunctionInliner().apply(stage); BlockHierarchyResolver().apply(stage); VariableResolver().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)