X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fcompiler.cpp;h=1eeb36252ba899a8f8851798f2a393a1223cc05d;hb=d5c7c7f0b15c407b3da2184936e6deed18554c6a;hp=c68b67bd0cd629f81db2838c60840b43c1abe720;hpb=9ec831710f64a62ad5f2e896a55ae82a3519f29e;p=libs%2Fgl.git diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index c68b67bd..1eeb3625 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -76,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) @@ -221,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); @@ -233,27 +233,29 @@ 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); + 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)