]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Remove Vulkan checks from feature converters
[libs/gl.git] / source / glsl / compiler.cpp
index 8d96cc4270b5b1566f75e37f26e1e35fa04c0352..05bf421cd422428dbf1b09b5eef3d0daf737c3f9 100644 (file)
@@ -23,18 +23,8 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
-Compiler::Compiler():
-       features(Features::from_context()),
-       module(0),
-       compiled(false),
-       specialized(false)
-{ }
-
 Compiler::Compiler(const Features &f):
-       features(f),
-       module(0),
-       compiled(false),
-       specialized(false)
+       features(f)
 { }
 
 Compiler::~Compiler()
@@ -85,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);
@@ -102,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);
@@ -111,6 +107,24 @@ void Compiler::compile(Mode mode)
                        ++i;
        }
 
+       Stage *prev_stage = 0;
+       for(auto i=module->stages.begin(); i!=module->stages.end(); )
+       {
+               if(i->functions.empty())
+                       i = module->stages.erase(i);
+               else
+               {
+                       i->previous = prev_stage;
+                       prev_stage = &*i;
+                       ++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);
@@ -162,7 +176,7 @@ vector<uint32_t> 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();
 }
 
@@ -200,16 +214,24 @@ const map<string, unsigned> &Compiler::get_uniform_block_bindings() const
        return module->shared.uniform_block_bindings;
 }
 
+unsigned Compiler::get_n_clip_distances() const
+{
+       if(!compiled)
+               throw invalid_operation("Compiler::get_n_clip_distances");
+       auto i = find_member(module->stages, Stage::VERTEX, &Stage::type);
+       return (i!=module->stages.end() ? i->n_clip_distances : 0);
+}
+
 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));
 }
 
@@ -278,7 +300,7 @@ void Compiler::import(ModuleCache &mod_cache, const string &name)
 
 void Compiler::generate(Stage &stage)
 {
-       stage.required_features.gl_api = features.gl_api;
+       stage.required_features.target_api = features.target_api;
        if(module->shared.required_features.glsl_version>stage.required_features.glsl_version)
                stage.required_features.glsl_version = module->shared.required_features.glsl_version;
 
@@ -295,6 +317,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<typename T>
@@ -326,7 +351,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);
@@ -360,7 +385,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))
@@ -368,6 +394,11 @@ Compiler::OptimizeResult Compiler::optimize(Stage &stage)
                resolve(stage, RESOLVE_TYPES|RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
                any_inlined = true;
        }
+       if(AggregateDismantler().apply(stage))
+       {
+               resolve(stage, RESOLVE_TYPES|RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
+               any_inlined = true;
+       }
        if(ExpressionInliner().apply(stage))
        {
                resolve(stage, RESOLVE_VARIABLES|RESOLVE_FUNCTIONS|RESOLVE_EXPRESSIONS);
@@ -386,13 +417,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