X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fcompiler.cpp;h=4c8c1d03d893d277395b2f64b5def34aa7e55168;hb=77f6973f58167d94059d3f324c29ab2ca8de4544;hp=e658a79ea98c2adc7c469b092f43ca84da9db161;hpb=f82ef715f0d7e1e7d0b93be4b7b89c8ce6bba40b;p=libs%2Fgl.git diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index e658a79e..4c8c1d03 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -4,7 +4,6 @@ #include "builtin.h" #include "compiler.h" #include "debug.h" -#include "deviceinfo.h" #include "error.h" #include "finalize.h" #include "generate.h" @@ -24,10 +23,6 @@ namespace Msp { namespace GL { namespace SL { -Compiler::Compiler(): - features(DeviceInfo::get_global().glsl_features) -{ } - Compiler::Compiler(const Features &f): features(f) { } @@ -80,6 +75,7 @@ void Compiler::compile(Mode mode) for(Stage &s: module->stages) generate(s); ConstantIdAssigner().apply(*module, features); + LocationAllocator().apply(*module, features, false); for(Stage &s: module->stages) validate(s); @@ -97,6 +93,11 @@ void Compiler::compile(Mode mode) for(Stage &s: module->stages) ConstantSpecializer().apply(s, spec_values); } + if(mode==PROGRAM) + { + for(Stage &s: module->stages) + DepthRangeConverter().apply(s, features); + } for(auto i=module->stages.begin(); i!=module->stages.end(); ) { OptimizeResult result = optimize(*i); @@ -106,6 +107,11 @@ void Compiler::compile(Mode mode) ++i; } + for(Stage &s: module->stages) + { + StructuralFeatureConverter().apply(s, features); + resolve(s, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS); + } LocationAllocator().apply(*module, features); for(Stage &s: module->stages) finalize(s, mode); @@ -157,7 +163,7 @@ vector Compiler::get_combined_spirv() const if(!compiled) throw invalid_operation("Compiler::get_combined_spirv"); SpirVGenerator gen; - gen.apply(*module); + gen.apply(*module, features); return gen.get_code(); } @@ -208,11 +214,11 @@ const SourceMap &Compiler::get_source_map() const return module->source_map; } -string Compiler::get_stage_debug(Stage::Type stage_type) const +string Compiler::get_stage_debug(Stage::Type stage_type, bool use_colors) const { auto i = find_member(module->stages, stage_type, &Stage::type); if(i!=module->stages.end()) - return DumpTree().apply(*i); + return DumpTree(use_colors).apply(*i); throw key_error(Stage::get_stage_name(stage_type)); } @@ -298,6 +304,9 @@ void Compiler::generate(Stage &stage) variables through interfaces. */ InterfaceGenerator().apply(stage); resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES); + + ArraySizer().apply(stage); + resolve(stage, RESOLVE_EXPRESSIONS); } template @@ -329,7 +338,7 @@ void Compiler::resolve(Stage &stage, unsigned flags) void Compiler::validate(Stage &stage) { - DeclarationValidator().apply(stage); + DeclarationValidator().apply(stage, features); IdentifierValidator().apply(stage); ReferenceValidator().apply(stage); ExpressionValidator().apply(stage); @@ -363,7 +372,8 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage) { if(ConstantFolder().apply(stage)) resolve(stage, RESOLVE_EXPRESSIONS); - ConstantConditionEliminator().apply(stage); + if(ConstantConditionEliminator().apply(stage)) + resolve(stage, RESOLVE_VARIABLES); bool any_inlined = false; if(FunctionInliner().apply(stage)) @@ -394,13 +404,9 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage) void Compiler::finalize(Stage &stage, Mode mode) { - if(mode==PROGRAM) - { - LegacyConverter().apply(stage, features); - resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS); - PrecisionConverter().apply(stage); - } - else if(mode==SPIRV) + QualifierConverter().apply(stage, features); + PrecisionConverter().apply(stage); + if(mode==SPIRV) StructOrganizer().apply(stage); // Collect bindings from all stages into the shared stage's maps