+void Program::collect_uniforms()
+{
+ const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
+
+ UniformBlockInfo &default_block = uniform_blocks[string()];
+
+ const vector<SpirVModule::Variable> &variables = mod.get_variables();
+ for(vector<SpirVModule::Variable>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
+ {
+ if(i->storage==SpirVModule::UNIFORM && i->struct_type)
+ {
+ UniformBlockInfo &info = uniform_blocks[i->struct_type->name];
+ info.name = i->struct_type->name;
+ info.bind_point = i->binding;
+ info.data_size = i->struct_type->size;
+
+ string prefix;
+ if(!i->name.empty())
+ prefix = i->struct_type->name+".";
+ collect_block_uniforms(info, *i->struct_type, prefix, 0);
+
+ info.layout_hash = compute_layout_hash(info.uniforms);
+ }
+ else if(i->storage==SpirVModule::UNIFORM_CONSTANT && i->location>=0)
+ {
+ UniformInfo &info = uniforms[i->name];
+ info.name = i->name;
+ info.block = &default_block;
+ info.location = i->location;
+ info.array_size = i->array_size;
+ info.type = i->type;
+ default_block.uniforms.push_back(&info);
+ }
+ }
+
+ default_block.layout_hash = compute_layout_hash(default_block.uniforms);
+
+ update_layout_hash();
+}
+
+void Program::collect_block_uniforms(UniformBlockInfo &block, const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset)
+{
+ for(vector<SpirVModule::StructMember>::const_iterator i=strct.members.begin(); i!=strct.members.end(); ++i)
+ {
+ if(i->struct_type)
+ {
+ if(i->array_size)
+ {
+ for(unsigned j=0; j<i->array_size; ++j)
+ collect_block_uniforms(block, *i->struct_type, format("%s%s[%d].", prefix, i->name, j), base_offset+i->offset+i->array_stride*j);
+ }
+ else
+ collect_block_uniforms(block, *i->struct_type, prefix+i->name+".", base_offset+i->offset);
+ }
+ else
+ {
+ string name = prefix+i->name;
+ UniformInfo &info = uniforms[name];
+ info.name = name;
+ info.block = █
+ info.location = i->offset;
+ info.array_size = i->array_size;
+ info.array_stride = i->array_stride;
+ info.matrix_stride = i->matrix_stride;
+ info.type = i->type;
+ block.uniforms.push_back(&info);
+ }
+ }
+}
+
+void Program::collect_attributes()
+{
+ const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
+
+ const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
+ for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
+ if(i->stage==SpirVModule::VERTEX && i->name=="main")
+ {
+ for(vector<const SpirVModule::Variable *>::const_iterator j=i->globals.begin(); j!=i->globals.end(); ++j)
+ if((*j)->storage==SpirVModule::INPUT)
+ {
+ AttributeInfo &info = attributes[(*j)->name];
+ info.location = (*j)->location;
+ info.array_size = (*j)->array_size;
+ info.type = (*j)->type;
+ }
+ }
+}
+
+void Program::update_layout_hash()
+{
+ string layout_descriptor;
+ for(UniformBlockMap::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
+ layout_descriptor += format("%d:%x\n", i->second.bind_point, i->second.layout_hash);
+ uniform_layout_hash = hash32(layout_descriptor);
+}
+