X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fprogram.cpp;h=0b07da8e501e2a959d826dd4441347353223f27c;hb=e0d9f85a9e4554f2bbf4354aa37ad6ae46aef718;hp=6013e7e82e9f35656f6741bb3743ea25a0237f5b;hpb=0757f7d3e514836ca85954708c41a1accac0574b;p=libs%2Fgl.git diff --git a/source/core/program.cpp b/source/core/program.cpp index 6013e7e8..0b07da8e 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -26,7 +26,7 @@ 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"); @@ -36,16 +36,12 @@ void Program::add_stages(const Module &mod, const map &spec_values) 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)); + collect_builtins(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); @@ -53,7 +49,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()); @@ -61,19 +57,25 @@ void Program::collect_uniforms(const SpirVModule &mod, const map for(const SpirVModule::Variable &v: mod.get_variables()) { - if(v.storage==SpirVModule::UNIFORM && v.struct_type) + if((v.storage==SpirVModule::UNIFORM || v.storage==SpirVModule::PUSH_CONSTANT) && v.struct_type) { reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo()); ReflectData::UniformBlockInfo &info = reflect_data.uniform_blocks.back(); info.name = v.struct_type->name; - info.bind_point = v.binding; + if(v.storage==SpirVModule::PUSH_CONSTANT) + info.bind_point = ReflectData::PUSH_CONSTANT; + else + { + info.bind_point = v.binding; + info.descriptor_set = v.descriptor_set; + } info.data_size = v.struct_type->size; string prefix; 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) { @@ -84,13 +86,20 @@ 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.descriptor_set = v.descriptor_set; + info.array_size = max(v.array_size, 1U); info.type = v.type; } } sort_member(reflect_data.uniforms, &ReflectData::UniformInfo::tag); + if(block_uniform_names.front().empty()) + { + reflect_data.uniform_blocks.erase(reflect_data.uniform_blocks.begin()); + block_uniform_names.erase(block_uniform_names.begin()); + } + for(unsigned i=0; i 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) - { - 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) + if(m.array_size) { - for(unsigned j=0; j