X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fmodule.cpp;h=ce540505fdf32d75a71c8430cb564b0537a3ca61;hb=1f71ec73edacd6c1bd230abace3cb791eb2ca759;hp=374ef8ae4d71537fcfa36b37cdba910e63b7faf9;hpb=70d9d2d28e5fe723c6b46894276e4c935f578e2d;p=libs%2Fgl.git diff --git a/source/core/module.cpp b/source/core/module.cpp index 374ef8ae..ce540505 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -127,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"); @@ -212,13 +224,9 @@ void SpirVModule::load_code(IO::Base &io) } } - for(map::const_iterator i=reflection.spec_constants.begin(); i!=reflection.spec_constants.end(); ++i) - spec_constants.push_back(i->second); -} - -void SpirVModule::compile(SL::Compiler &) -{ - throw logic_error("Not implemented yet"); + for(map::const_iterator i=reflection.constants.begin(); i!=reflection.constants.end(); ++i) + if(i->second->constant_id>=0) + spec_constants.push_back(i->second); } @@ -303,7 +311,7 @@ void SpirVModule::Reflection::reflect_code(const vector &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(code.end()-op)) throw invalid_module("Truncated SPIR-V instruction"); switch(get_opcode(*op)) @@ -322,12 +330,12 @@ void SpirVModule::Reflection::reflect_code(const vector &code) case OP_TYPE_ARRAY: reflect_array_type(op); break; case OP_TYPE_STRUCT: reflect_struct_type(op); break; case OP_TYPE_POINTER: reflect_pointer_type(op); break; - case OP_CONSTANT_TRUE: constants[*(op+2)] = true; break; - case OP_CONSTANT_FALSE: constants[*(op+2)] = false; break; - case OP_CONSTANT: reflect_constant(op); break; + case OP_CONSTANT_TRUE: + case OP_CONSTANT_FALSE: + case OP_CONSTANT: case OP_SPEC_CONSTANT_TRUE: case OP_SPEC_CONSTANT_FALSE: - case OP_SPEC_CONSTANT: reflect_spec_constant(op); break; + case OP_SPEC_CONSTANT: reflect_constant(op); break; case OP_VARIABLE: reflect_variable(op); break; case OP_DECORATE: reflect_decorate(op); break; case OP_MEMBER_DECORATE: reflect_member_decorate(op); break; @@ -433,11 +441,10 @@ void SpirVModule::Reflection::reflect_array_type(CodeIterator op) const TypeInfo &elem = types[*(op+2)]; type.type = elem.type; type.struct_type = elem.struct_type; - const Variant &size = constants[*(op+3)]; - if(size.check_type()) - type.array_size = size.value(); - else if(size.check_type()) - type.array_size = size.value(); + + const Constant &size = constants[*(op+3)]; + if(size.type==INT || size.type==UNSIGNED_INT) + type.array_size = size.i_value; } void SpirVModule::Reflection::reflect_struct_type(CodeIterator op) @@ -469,23 +476,19 @@ void SpirVModule::Reflection::reflect_pointer_type(CodeIterator op) } void SpirVModule::Reflection::reflect_constant(CodeIterator op) -{ - const TypeInfo &type = types[*(op+1)]; - unsigned id = *(op+2); - if(type.type==INT) - constants[id] = static_cast(*(op+3)); - else if(type.type==UNSIGNED_INT) - constants[id] = static_cast(*(op+3)); - else if(type.type==FLOAT) - constants[id] = *reinterpret_cast(&*(op+3)); -} - -void SpirVModule::Reflection::reflect_spec_constant(CodeIterator op) { unsigned id = *(op+2); - SpecConstant &spec = spec_constants[id]; - spec.name = names[id]; - spec.type = types[*(op+1)].type; + Constant &cnst = constants[id]; + cnst.name = names[id]; + cnst.type = types[*(op+1)].type; + if(*op==OP_CONSTANT_TRUE || *op==OP_SPEC_CONSTANT_TRUE) + cnst.i_value = true; + else if(*op==OP_CONSTANT_FALSE || *op==OP_SPEC_CONSTANT_FALSE) + cnst.i_value = false; + else if(cnst.type==INT || cnst.type==UNSIGNED_INT) + cnst.i_value = *(op+3); + else if(cnst.type==FLOAT) + cnst.f_value = *reinterpret_cast(&*(op+3)); } void SpirVModule::Reflection::reflect_variable(CodeIterator op) @@ -509,7 +512,7 @@ void SpirVModule::Reflection::reflect_decorate(CodeIterator op) switch(decoration) { case DECO_SPEC_ID: - spec_constants[id].constant_id = *op; + constants[id].constant_id = *op; break; case DECO_ARRAY_STRIDE: types[id].array_stride = *op;