]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/compiler.cpp
Fix a name conflict in certain inlining scenarios
[libs/gl.git] / source / glsl / compiler.cpp
index 41734fe85fdb6d170765353653038a6df9183f43..4e9f94d86b51e0044786927f7bc77c6d8e32c720 100644 (file)
@@ -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,18 +23,8 @@ namespace Msp {
 namespace GL {
 namespace SL {
 
-Compiler::Compiler():
-       features(DeviceInfo::get_global().glsl_features),
-       module(0),
-       compiled(false),
-       specialized(false)
-{ }
-
 Compiler::Compiler(const Features &f):
-       features(f),
-       module(0),
-       compiled(false),
-       specialized(false)
+       features(f)
 { }
 
 Compiler::~Compiler()
@@ -86,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);
@@ -112,6 +102,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);
@@ -201,6 +196,14 @@ 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;
@@ -327,7 +330,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);
@@ -369,6 +372,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);
@@ -387,13 +395,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