X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fcore%2Fprogram.cpp;h=57ef987950d9dbbaed82d3a75669b53a6b7fbc20;hp=5c8257b2fc60de50bf0e767beb90a5f8da5784e2;hb=959efbf61663efd7879070ce0447e02c8a447ce0;hpb=a833b47ecd5bf91a979a30d0898f768a14cf5067 diff --git a/source/core/program.cpp b/source/core/program.cpp index 5c8257b2..57ef9879 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -17,6 +17,8 @@ void Program::add_stages(const Module &mod, const map &spec_values) if(has_stages()) throw invalid_operation("Program::add_stages"); + reflect_data = ReflectData(); + TransientData transient; switch(mod.get_format()) { @@ -24,34 +26,21 @@ void Program::add_stages(const Module &mod, const map &spec_values) add_glsl_stages(static_cast(mod), spec_values, transient); break; case Module::SPIR_V: - add_spirv_stages(static_cast(mod), spec_values, transient); + add_spirv_stages(static_cast(mod), spec_values); break; default: throw invalid_argument("Program::add_stages"); } - reflect_data = ReflectData(); + finalize(mod, transient); - finalize(mod); - - if(mod.get_format()==Module::GLSL) - { - query_uniforms(); - query_attributes(); - apply_bindings(transient); - } - else if(mod.get_format()==Module::SPIR_V) + if(mod.get_format()==Module::SPIR_V) { - collect_uniforms(static_cast(mod), transient.spec_values); + collect_uniforms(static_cast(mod)); collect_attributes(static_cast(mod)); } - for(ReflectData::UniformBlockInfo &b: reflect_data.uniform_blocks) - if(!b.data_size && !b.uniforms.empty()) - { - const ReflectData::UniformInfo &uni = *b.uniforms.back(); - b.data_size = uni.location*16+uni.array_size*get_type_size(uni.type); - } + finalize_uniforms(); for(const ReflectData::UniformInfo &u: reflect_data.uniforms) require_type(u.type); @@ -59,7 +48,7 @@ void Program::add_stages(const Module &mod, const map &spec_values) require_type(a.type); } -void Program::collect_uniforms(const SpirVModule &mod, const map &spec_values) +void Program::collect_uniforms(const SpirVModule &mod) { // Prepare the default block reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo()); @@ -79,7 +68,7 @@ void Program::collect_uniforms(const SpirVModule &mod, const map if(!v.name.empty()) prefix = v.struct_type->name+"."; block_uniform_names.push_back(vector()); - collect_block_uniforms(*v.struct_type, prefix, 0, spec_values, block_uniform_names.back()); + collect_block_uniforms(*v.struct_type, prefix, 0, block_uniform_names.back()); } else if(v.storage==SpirVModule::UNIFORM_CONSTANT && v.location>=0) { @@ -90,7 +79,7 @@ void Program::collect_uniforms(const SpirVModule &mod, const map info.tag = v.name; info.location = v.location; info.binding = v.binding; - info.array_size = v.array_size; + info.array_size = max(v.array_size, 1U); info.type = v.type; } } @@ -114,29 +103,20 @@ void Program::collect_uniforms(const SpirVModule &mod, const map reflect_data.update_layout_hash(); } -void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, const map &spec_values, vector &uniform_names) +void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, vector &uniform_names) { for(const SpirVModule::StructMember &m: strct.members) { unsigned offset = base_offset+m.offset; if(m.struct_type) { - unsigned array_size = m.array_size; - if(m.array_size_spec) + if(m.array_size) { - array_size = m.array_size_spec->i_value; - auto j = spec_values.find(m.array_size_spec->constant_id); - if(j!=spec_values.end()) - array_size = j->second; - } - - if(array_size) - { - for(unsigned j=0; j