if(has_stages())
throw invalid_operation("Program::add_stages");
+ reflect_data = ReflectData();
+
TransientData transient;
switch(mod.get_format())
{
add_glsl_stages(static_cast<const GlslModule &>(mod), spec_values, transient);
break;
case Module::SPIR_V:
- add_spirv_stages(static_cast<const SpirVModule &>(mod), spec_values, transient);
+ add_spirv_stages(static_cast<const SpirVModule &>(mod), spec_values);
break;
default:
throw invalid_argument("Program::add_stages");
}
- reflect_data = ReflectData();
-
- finalize(mod);
+ finalize(mod, transient);
- 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<const SpirVModule &>(mod), transient.spec_values);
+ collect_uniforms(static_cast<const SpirVModule &>(mod));
collect_attributes(static_cast<const SpirVModule &>(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);
require_type(a.type);
}
-void Program::collect_uniforms(const SpirVModule &mod, const map<unsigned, int> &spec_values)
+void Program::collect_uniforms(const SpirVModule &mod)
{
// Prepare the default block
reflect_data.uniform_blocks.push_back(ReflectData::UniformBlockInfo());
if(!v.name.empty())
prefix = v.struct_type->name+".";
block_uniform_names.push_back(vector<string>());
- 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)
{
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;
}
}
reflect_data.update_layout_hash();
}
-void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, const map<unsigned, int> &spec_values, vector<string> &uniform_names)
+void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, vector<string> &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<array_size; ++j, offset+=m.array_stride)
- collect_block_uniforms(*m.struct_type, format("%s%s[%d].", prefix, m.name, j), offset, spec_values, uniform_names);
+ for(unsigned j=0; j<m.array_size; ++j, offset+=m.array_stride)
+ collect_block_uniforms(*m.struct_type, format("%s%s[%d].", prefix, m.name, j), offset, uniform_names);
}
else
- collect_block_uniforms(*m.struct_type, prefix+m.name+".", offset, spec_values, uniform_names);
+ collect_block_uniforms(*m.struct_type, prefix+m.name+".", offset, uniform_names);
}
else
{
info.name = name;
info.tag = name;
info.offset = offset;
- info.array_size = m.array_size;
+ info.array_size = max(m.array_size, 1U);
info.array_stride = m.array_stride;
info.matrix_stride = m.matrix_stride;
info.type = m.type;