]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/module.cpp
Enable creation of SPIR-V modules from GLSL source code
[libs/gl.git] / source / core / module.cpp
index 5287ae9c2ec369bbdfcf80242c738e4e2fdc75cf..72a6abca43781a20e84f07abc8dbb1373f2eb295 100644 (file)
@@ -70,6 +70,7 @@ void GlslModule::compile(SL::Compiler &compiler)
        compiler.compile(SL::Compiler::MODULE);
        prepared_source = compiler.get_combined_glsl();
        source_map = compiler.get_source_map();
+
 #ifdef DEBUG
        string diagnostics = compiler.get_diagnostics();
        if(!diagnostics.empty())
@@ -126,6 +127,18 @@ void SpirVModule::load_code(IO::Base &io)
                code.insert(code.end(), buffer, buffer+len);
        }
 
+       reflect();
+}
+
+void SpirVModule::compile(SL::Compiler &compiler)
+{
+       compiler.compile(SL::Compiler::SPIRV);
+       code = compiler.get_combined_spirv();
+       reflect();
+}
+
+void SpirVModule::reflect()
+{
        if(code.empty())
                throw invalid_module("Empty SPIR-V code");
 
@@ -215,11 +228,6 @@ void SpirVModule::load_code(IO::Base &io)
                spec_constants.push_back(i->second);
 }
 
-void SpirVModule::compile(SL::Compiler &)
-{
-       throw logic_error("Not implemented yet");
-}
-
 
 SpirVModule::EntryPoint::EntryPoint():
        stage(VERTEX)
@@ -302,7 +310,7 @@ void SpirVModule::Reflection::reflect_code(const vector<UInt32> &code)
        for(CodeIterator op=code.begin()+5; op!=code.end(); )
        {
                unsigned word_count = *op>>16;
-               if(word_count>code.end()-op)
+               if(word_count>static_cast<unsigned>(code.end()-op))
                        throw invalid_module("Truncated SPIR-V instruction");
 
                switch(get_opcode(*op))