]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/module.cpp
Fix handling of constants in Spir-V reflection
[libs/gl.git] / source / core / module.cpp
index 099e8b7fa988c427def61bddaf77ae08f5916978..116c6241a184d321b6408122713873b16657412e 100644 (file)
@@ -1,6 +1,6 @@
 #include <msp/core/algorithm.h>
 #include <msp/io/print.h>
-#include "deviceinfo.h"
+#include "device.h"
 #include "module.h"
 #include "resources.h"
 
@@ -50,14 +50,14 @@ namespace GL {
 
 void Module::set_source(const string &src)
 {
-       SL::Compiler compiler(DeviceInfo::get_global().glsl_features);
+       SL::Compiler compiler(create_features());
        compiler.set_source(src);
        compile(compiler);
 }
 
 void Module::load_source(IO::Base &io, Resources *res, const string &name)
 {
-       SL::Compiler compiler(DeviceInfo::get_global().glsl_features);
+       SL::Compiler compiler(create_features());
        compiler.load_source(io, res, name);
        compile(compiler);
 }
@@ -67,6 +67,20 @@ void Module::load_source(IO::Base &io, const string &name)
        load_source(io, 0, name);
 }
 
+SL::Features Module::create_features() const
+{
+       const DeviceInfo &dev_info = Device::get_current().get_info();
+       const SL::Features &device_features = dev_info.glsl_features;
+       SL::Features latest_features = SL::Features::latest(dev_info.api);
+       SL::Features features;
+       features.target_api = latest_features.target_api;
+       features.glsl_version = latest_features.glsl_version;
+       features.constant_id_range = device_features.constant_id_range;
+       features.uniform_binding_range = device_features.uniform_binding_range;
+       features.texture_binding_range = device_features.texture_binding_range;
+       return features;
+}
+
 
 void GlslModule::compile(SL::Compiler &compiler)
 {
@@ -82,41 +96,6 @@ void GlslModule::compile(SL::Compiler &compiler)
 }
 
 
-SpirVModule::SpirVModule(const SpirVModule &other):
-       code(other.code),
-       entry_points(other.entry_points),
-       structs(other.structs),
-       variables(other.variables)
-{
-       remap_pointers_from(other);
-}
-
-SpirVModule &SpirVModule::operator=(const SpirVModule &other)
-{
-       code = other.code;
-       entry_points = other.entry_points;
-       structs = other.structs;
-       variables = other.variables;
-       remap_pointers_from(other);
-       return *this;
-}
-
-void SpirVModule::remap_pointers_from(const SpirVModule &other)
-{
-       for(EntryPoint &e: entry_points)
-               for(const Variable *&v: e.globals)
-                       v = &variables[v-&other.variables.front()];
-
-       for(Variable &v: variables)
-               if(v.struct_type)
-                       v.struct_type = &structs[v.struct_type-&other.structs.front()];
-
-       for(Structure &s: structs)
-               for(StructMember &m: s.members)
-                       if(m.struct_type)
-                               m.struct_type = &structs[m.struct_type-&other.structs.front()];
-}
-
 void SpirVModule::load_code(IO::Base &io)
 {
        uint32_t buffer[1024];
@@ -397,7 +376,7 @@ void SpirVModule::Reflection::reflect_image_type(CodeIterator op)
        unsigned dimensions = *(op+3);
        bool depth = *(op+4)==1;
        bool array = *(op+5);
-       type.type = static_cast<DataType>((depth*0x200000) | (array*0x80000) | (dimensions+1) | sample);
+       type.type = static_cast<DataType>((depth*0x200000) | (array*0x80000) | ((dimensions+1)<<16) | sample);
 }
 
 void SpirVModule::Reflection::reflect_sampled_image_type(CodeIterator op)
@@ -449,13 +428,14 @@ void SpirVModule::Reflection::reflect_pointer_type(CodeIterator op)
 
 void SpirVModule::Reflection::reflect_constant(CodeIterator op)
 {
+       unsigned opcode = get_opcode(*op);
        unsigned id = *(op+2);
        Constant &cnst = constants[id];
        cnst.name = names[id];
        cnst.type = types[*(op+1)].type;
-       if(*op==OP_CONSTANT_TRUE || *op==OP_SPEC_CONSTANT_TRUE)
+       if(opcode==OP_CONSTANT_TRUE || opcode==OP_SPEC_CONSTANT_TRUE)
                cnst.i_value = true;
-       else if(*op==OP_CONSTANT_FALSE || *op==OP_SPEC_CONSTANT_FALSE)
+       else if(opcode==OP_CONSTANT_FALSE || opcode==OP_SPEC_CONSTANT_FALSE)
                cnst.i_value = false;
        else if(cnst.type==INT || cnst.type==UNSIGNED_INT)
                cnst.i_value = *(op+3);