X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fmodule.cpp;h=15bd750cf0b299bd7ea8440ed6d0be5adc3788d1;hp=ed5f02823f0bf34671a7ee4a31e7dad4035f0dc9;hb=d16d28d2ccf7c6255204f02975834f713ff1df08;hpb=3a1b9cbe2441ae670a97541dc8ccb0a2860c8302 diff --git a/source/core/module.cpp b/source/core/module.cpp index ed5f0282..15bd750c 100644 --- a/source/core/module.cpp +++ b/source/core/module.cpp @@ -1,5 +1,6 @@ #include #include +#include "device.h" #include "module.h" #include "resources.h" @@ -37,6 +38,7 @@ enum SpirVConstants DECO_SPEC_ID = 1, DECO_ARRAY_STRIDE = 6, DECO_MATRIX_STRIDE = 7, + DECO_BUILTIN = 11, DECO_LOCATION = 30, DECO_BINDING = 33, DECO_DESCRIPTOR_SET = 34, @@ -48,14 +50,14 @@ namespace GL { void Module::set_source(const string &src) { - SL::Compiler compiler; + 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; + SL::Compiler compiler(create_features()); compiler.load_source(io, res, name); compile(compiler); } @@ -65,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) { @@ -173,18 +189,11 @@ void SpirVModule::reflect() for(Structure &s: structs) { for(StructMember &m: s.members) - { if(m.struct_type) { auto i = struct_indices.find(m.struct_type); m.struct_type = (i!=struct_indices.end() ? &structs[i->second] : 0); } - if(m.array_size_spec) - { - auto i = spec_indices.find(m.array_size_spec); - m.array_size_spec = (i!=spec_indices.end() ? &spec_constants[i->second] : 0); - } - } const StructMember *last_member = &s.members.back(); unsigned last_offset = last_member->offset; @@ -193,13 +202,14 @@ void SpirVModule::reflect() const StructMember *lm = &last_member->struct_type->members.back(); if(last_member->array_size) last_offset += last_member->array_stride*(last_member->array_size-1); - else if(last_member->array_size_spec) - last_offset += last_member->array_stride*(last_member->array_size_spec->i_value-1); last_offset += lm->offset; last_member = lm; } - s.size = last_offset+get_type_size(last_member->type); + unsigned last_size = get_type_size(last_member->type); + if(last_member->array_size) + last_size += last_member->array_stride*(last_member->array_size-1); + s.size = last_offset+last_size; s.size = (s.size+15)&~15; } @@ -218,18 +228,11 @@ void SpirVModule::reflect() } for(Variable &v: variables) - { if(v.struct_type) { auto i = struct_indices.find(v.struct_type); v.struct_type = (i!=struct_indices.end() ? &structs[i->second] : 0); } - if(v.array_size_spec) - { - auto i = spec_indices.find(v.array_size_spec); - v.array_size_spec = (i!=spec_indices.end() ? &spec_constants[i->second] : 0); - } - } entry_points.reserve(reflection.entry_points.size()); for(const auto &kvp: reflection.entry_points) @@ -245,30 +248,6 @@ void SpirVModule::reflect() } -SpirVModule::EntryPoint::EntryPoint(): - stage(VERTEX) -{ } - - -SpirVModule::StructMember::StructMember(): - type(VOID), - struct_type(0), - offset(0), - array_size(0), - array_size_spec(0), - array_stride(0), - matrix_stride(0) -{ } - - -SpirVModule::Variable::Variable(): - type(VOID), - struct_type(0), - location(-1), - descriptor_set(-1), - binding(-1) -{ } - bool SpirVModule::Variable::operator==(const Variable &other) const { if(storage!=UNIFORM_CONSTANT && storage!=UNIFORM) @@ -281,16 +260,6 @@ bool SpirVModule::Variable::operator==(const Variable &other) const } -SpirVModule::TypeInfo::TypeInfo(): - type(VOID), - struct_type(0), - array_size_spec(0), - array_size(0), - array_stride(0), - storage(static_cast(-1)) -{ } - - uint32_t SpirVModule::Reflection::get_opcode(uint32_t op) { return op&0xFFFF; @@ -341,7 +310,7 @@ void SpirVModule::Reflection::reflect_code(const vector &code) case OP_TYPE_INT: reflect_int_type(op); break; case OP_TYPE_FLOAT: reflect_float_type(op); break; case OP_TYPE_VECTOR: reflect_vector_type(op); break; - case OP_TYPE_MATRIX: reflect_vector_type(op); break; + case OP_TYPE_MATRIX: reflect_matrix_type(op); break; case OP_TYPE_IMAGE: reflect_image_type(op); break; case OP_TYPE_SAMPLED_IMAGE: reflect_sampled_image_type(op); break; case OP_TYPE_ARRAY: reflect_array_type(op); break; @@ -424,7 +393,7 @@ void SpirVModule::Reflection::reflect_vector_type(CodeIterator op) TypeInfo &type = types[*(op+1)]; DataType component = types[*(op+2)].type; unsigned count = *(op+3); - type.type = static_cast((count<<12) | (component&0xF00) | ((component&0xFF)*count)); + type.type = static_cast(((count-1)<<12) | (component&0xF00) | ((component&0xFF)*count)); } void SpirVModule::Reflection::reflect_matrix_type(CodeIterator op) @@ -432,7 +401,7 @@ void SpirVModule::Reflection::reflect_matrix_type(CodeIterator op) TypeInfo &type = types[*(op+1)]; DataType column = types[*(op+2)].type; unsigned count = *(op+3); - type.type = static_cast((count<<16) | (column&0xF00) | ((column&0xFF)*count)); + type.type = static_cast(((count-1)<<14) | (column&0x3F00) | ((column&0xFF)*count)); } void SpirVModule::Reflection::reflect_image_type(CodeIterator op) @@ -460,9 +429,7 @@ void SpirVModule::Reflection::reflect_array_type(CodeIterator op) type.struct_type = elem.struct_type; const Constant &size = constants[*(op+3)]; - if(size.constant_id>=0) - type.array_size_spec = &size; - else if(size.type==INT || size.type==UNSIGNED_INT) + if(size.type==INT || size.type==UNSIGNED_INT) type.array_size = size.i_value; } @@ -483,7 +450,6 @@ void SpirVModule::Reflection::reflect_struct_type(CodeIterator op) mem->type = type.type; mem->struct_type = type.struct_type; mem->array_size = type.array_size; - mem->array_size_spec = type.array_size_spec; mem->array_stride = type.array_stride; } } @@ -521,7 +487,6 @@ void SpirVModule::Reflection::reflect_variable(CodeIterator op) var.type = type.type; var.struct_type = type.struct_type; var.array_size = type.array_size; - var.array_size_spec = type.array_size_spec; } void SpirVModule::Reflection::reflect_decorate(CodeIterator op) @@ -538,6 +503,9 @@ void SpirVModule::Reflection::reflect_decorate(CodeIterator op) case DECO_ARRAY_STRIDE: types[id].array_stride = *op; break; + case DECO_BUILTIN: + variables[id].builtin = static_cast(*op); + break; case DECO_LOCATION: variables[id].location = *op; break; @@ -565,6 +533,9 @@ void SpirVModule::Reflection::reflect_member_decorate(CodeIterator op) case DECO_MATRIX_STRIDE: member.matrix_stride = *op; break; + case DECO_BUILTIN: + member.builtin = static_cast(*op); + break; case DECO_OFFSET: member.offset = *op; break;