const map<string, unsigned> &block_bindings = compiler.get_uniform_block_bindings();
if(!block_bindings.empty())
{
- for(unsigned i=0; i<rd.uniform_blocks.size(); ++i)
+ for(unsigned i=0; i<rd.blocks.size(); ++i)
{
- auto j = block_bindings.find(rd.uniform_blocks[i].name);
+ auto j = block_bindings.find(rd.blocks[i].name);
if(j!=block_bindings.end())
{
glUniformBlockBinding(id, i, j->second);
- rd.uniform_blocks[i].bind_point = j->second;
+ rd.blocks[i].bind_point = j->second;
}
}
}
}
}
- sort_member(rd.uniform_blocks, &ReflectData::UniformBlockInfo::tag);
- for(ReflectData::UniformBlockInfo &b: rd.uniform_blocks)
+ sort_member(rd.blocks, &ReflectData::BlockInfo::tag);
+ for(ReflectData::BlockInfo &b: rd.blocks)
for(const ReflectData::UniformInfo *u: b.uniforms)
const_cast<ReflectData::UniformInfo *>(u)->block = &b;
query_uniform_blocks(uniforms_by_index);
}
- rd.uniform_blocks.emplace_back();
- ReflectData::UniformBlockInfo &default_block = rd.uniform_blocks.back();
+ rd.blocks.emplace_back();
+ ReflectData::BlockInfo &default_block = rd.blocks.back();
for(ReflectData::UniformInfo &u: rd.uniforms)
if(!u.block)
unsigned count = 0;
glGetProgramiv(id, GL_ACTIVE_UNIFORM_BLOCKS, reinterpret_cast<int *>(&count));
// Reserve an extra index for the default block
- rd.uniform_blocks.reserve(count+1);
+ rd.blocks.reserve(count+1);
for(unsigned i=0; i<count; ++i)
{
char name[128];
int len;
glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
- rd.uniform_blocks.emplace_back();
- ReflectData::UniformBlockInfo &info = rd.uniform_blocks.back();
+ rd.blocks.emplace_back();
+ ReflectData::BlockInfo &info = rd.blocks.back();
info.tag = info.name = name;
int value;
{
ReflectData &rd = static_cast<Program *>(this)->reflect_data;
- auto i = find_member(rd.uniform_blocks, static_cast<int>(ReflectData::DEFAULT_BLOCK), &ReflectData::UniformBlockInfo::bind_point);
- if(i!=rd.uniform_blocks.end() && !i->uniforms.empty())
+ auto i = find_member(rd.blocks, static_cast<int>(ReflectData::DEFAULT_BLOCK), &ReflectData::BlockInfo::bind_point);
+ if(i!=rd.blocks.end() && !i->uniforms.empty())
{
for(const ReflectData::UniformInfo *u: i->uniforms)
if(u->location>=0)
if(r.changed || changed_sets==~0U)
{
if(r.type==PipelineState::UNIFORM_BLOCK)
- r.used = self.shprog->uses_uniform_block_binding(r.binding);
+ r.used = self.shprog->uses_block_binding(r.binding);
else if(r.type==PipelineState::SAMPLED_TEXTURE || r.type==PipelineState::STORAGE_TEXTURE)
{
r.used = self.shprog->uses_texture_binding(r.binding);
const VulkanFunctions &vk = device.get_functions();
const ReflectData &rd = static_cast<const Program *>(this)->reflect_data;
- auto i = find_member(rd.uniform_blocks, static_cast<int>(ReflectData::PUSH_CONSTANT), &ReflectData::UniformBlockInfo::bind_point);
- const ReflectData::UniformBlockInfo *push_const_block = (i!=rd.uniform_blocks.end() ? &*i : 0);
+ auto i = find_member(rd.blocks, static_cast<int>(ReflectData::PUSH_CONSTANT), &ReflectData::BlockInfo::bind_point);
+ const ReflectData::BlockInfo *push_const_block = (i!=rd.blocks.end() ? &*i : 0);
desc_set_layout_handles.resize(rd.n_descriptor_sets);
for(unsigned j=0; j<rd.n_descriptor_sets; ++j)
{
std::vector<VkDescriptorSetLayoutBinding> bindings;
- for(const ReflectData::UniformBlockInfo &b: rd.uniform_blocks)
+ for(const ReflectData::BlockInfo &b: rd.blocks)
if(b.bind_point>=0 && static_cast<unsigned>(b.bind_point>>20)==j)
{
bindings.emplace_back();
if(!shprog)
return;
- for(const ReflectData::UniformBlockInfo &b: shprog->get_uniform_blocks())
+ for(const ReflectData::BlockInfo &b: shprog->get_blocks())
if(b.bind_point!=ReflectData::DEFAULT_BLOCK)
{
auto i = lower_bound_member(resources, b.bind_point, &PipelineState::BoundResource::binding);
void Program::collect_uniforms(const SpirVModule &mod)
{
// Prepare the default block
- reflect_data.uniform_blocks.emplace_back();
+ reflect_data.blocks.emplace_back();
vector<vector<string> > block_uniform_names(1);
for(const SpirVModule::Variable &v: mod.get_variables())
{
if((v.storage==SpirVModule::UNIFORM || v.storage==SpirVModule::PUSH_CONSTANT) && v.struct_type)
{
- reflect_data.uniform_blocks.emplace_back();
- ReflectData::UniformBlockInfo &info = reflect_data.uniform_blocks.back();
+ reflect_data.blocks.emplace_back();
+ ReflectData::BlockInfo &info = reflect_data.blocks.back();
info.tag = info.name = v.struct_type->name;
info.data_size = v.struct_type->size;
if(v.storage==SpirVModule::PUSH_CONSTANT)
if(block_uniform_names.front().empty())
{
- reflect_data.uniform_blocks.erase(reflect_data.uniform_blocks.begin());
+ reflect_data.blocks.erase(reflect_data.blocks.begin());
block_uniform_names.erase(block_uniform_names.begin());
}
- for(unsigned i=0; i<reflect_data.uniform_blocks.size(); ++i)
+ for(unsigned i=0; i<reflect_data.blocks.size(); ++i)
{
- ReflectData::UniformBlockInfo &block = reflect_data.uniform_blocks[i];
+ ReflectData::BlockInfo &block = reflect_data.blocks[i];
for(const string &n: block_uniform_names[i])
{
// The element is already known to be present
block.update_layout_hash();
}
- sort_member(reflect_data.uniform_blocks, &ReflectData::UniformBlockInfo::tag);
- for(ReflectData::UniformBlockInfo &b: reflect_data.uniform_blocks)
+ sort_member(reflect_data.blocks, &ReflectData::BlockInfo::tag);
+ for(ReflectData::BlockInfo &b: reflect_data.blocks)
for(const ReflectData::UniformInfo *u: b.uniforms)
const_cast<ReflectData::UniformInfo *>(u)->block = &b;
reflect_data.n_clip_distances = m.array_size;
}
-int Program::get_uniform_block_binding(Tag tag) const
+int Program::get_block_binding(Tag tag) const
{
- auto i = lower_bound_member(reflect_data.uniform_blocks, tag, &ReflectData::UniformBlockInfo::tag);
- return i!=reflect_data.uniform_blocks.end() && i->tag==tag ? i->bind_point : -1;
+ auto i = lower_bound_member(reflect_data.blocks, tag, &ReflectData::BlockInfo::tag);
+ return i!=reflect_data.blocks.end() && i->tag==tag ? i->bind_point : -1;
}
const ReflectData::UniformInfo &Program::get_uniform_info(Tag tag) const
ReflectData::LayoutHash get_uniform_layout_hash() const { return reflect_data.layout_hash; }
unsigned get_n_descriptor_sets() const { return reflect_data.n_descriptor_sets; }
unsigned get_push_constants_size() const { return reflect_data.push_constants_size; }
- const std::vector<ReflectData::UniformBlockInfo> &get_uniform_blocks() const { return reflect_data.uniform_blocks; }
- int get_uniform_block_binding(Tag) const;
+ const std::vector<ReflectData::BlockInfo> &get_blocks() const { return reflect_data.blocks; }
+ int get_block_binding(Tag) const;
const std::vector<ReflectData::UniformInfo> &get_uniforms() const { return reflect_data.uniforms; }
const ReflectData::UniformInfo &get_uniform_info(Tag) const;
int get_uniform_location(const std::string &) const;
int get_uniform_location(Tag) const;
int get_uniform_binding(Tag) const;
- bool uses_uniform_block_binding(int b) const { return uses_binding(b|ReflectData::UNIFORM_BLOCK_BINDING); }
+ bool uses_block_binding(int b) const { return uses_binding(b|ReflectData::BLOCK_BINDING); }
bool uses_texture_binding(unsigned b) const { return uses_binding(b|ReflectData::TEXTURE_BINDING); }
private:
bool uses_binding(int) const;
void ReflectData::update_layout_hash()
{
- layout_hash = hash<32>(uniform_blocks.size());
- for(const UniformBlockInfo &b: uniform_blocks)
+ layout_hash = hash<32>(blocks.size());
+ for(const BlockInfo &b: blocks)
{
layout_hash = hash_update<32>(layout_hash, b.bind_point);
layout_hash = hash_update<32>(layout_hash, b.layout_hash);
for(const UniformInfo &u: uniforms)
if(u.binding>=0 && is_image(u.type))
used_bindings.push_back(u.binding|TEXTURE_BINDING);
- for(const UniformBlockInfo &b: uniform_blocks)
- used_bindings.push_back(b.bind_point|UNIFORM_BLOCK_BINDING);
+ for(const BlockInfo &b: blocks)
+ used_bindings.push_back(b.bind_point|BLOCK_BINDING);
sort(used_bindings);
}
-void ReflectData::UniformBlockInfo::sort_uniforms()
+void ReflectData::BlockInfo::sort_uniforms()
{
sort(uniforms, [](const UniformInfo *u1, const UniformInfo *u2){ return u1->location<u2->location; });
}
-void ReflectData::UniformBlockInfo::update_layout_hash()
+void ReflectData::BlockInfo::update_layout_hash()
{
layout_hash = hash<32>(uniforms.size());
for(const UniformInfo *u: uniforms)
{
DEFAULT_BLOCK = -1,
PUSH_CONSTANT = -2,
- UNIFORM_BLOCK_BINDING = 0,
+ BLOCK_BINDING = 0,
TEXTURE_BINDING = 0x1000000
};
typedef unsigned LayoutHash;
- struct UniformBlockInfo;
+ struct BlockInfo;
struct UniformInfo
{
std::string name;
- const UniformBlockInfo *block = 0;
+ const BlockInfo *block = 0;
union
{
int location = -1;
int binding = -1;
};
- struct UniformBlockInfo
+ struct BlockInfo
{
std::string name;
unsigned data_size = 0;
DataType type = VOID;
};
- std::vector<UniformBlockInfo> uniform_blocks;
+ std::vector<BlockInfo> blocks;
std::vector<UniformInfo> uniforms;
LayoutHash layout_hash = 0;
std::vector<AttributeInfo> attributes;
namespace Msp {
namespace GL {
-UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
+UniformBlock::UniformBlock(const ReflectData::BlockInfo &info):
UniformBlockBackend(info.bind_point>=0),
data(info.data_size)
{ }
std::vector<char> data;
public:
- UniformBlock(const ReflectData::UniformBlockInfo &);
+ UniformBlock(const ReflectData::BlockInfo &);
virtual std::size_t get_data_size() const { return data.size(); }
virtual const void *get_data_pointer() const { return &data[0]; }
if(i!=programs.end() && i->prog_hash==prog_hash)
return i;
- const vector<ReflectData::UniformBlockInfo> &block_infos = prog.get_uniform_blocks();
+ const vector<ReflectData::BlockInfo> &block_infos = prog.get_blocks();
unsigned index = i-programs.begin();
programs.insert(i, 1+block_infos.size(), ProgramBlock(prog_hash));
for(unsigned j=0; j<block_infos.size(); ++j)
{
- const ReflectData::UniformBlockInfo &info = block_infos[j];
+ const ReflectData::BlockInfo &info = block_infos[j];
block_hashes[index+1+j] = info.layout_hash;
programs[index+1+j].bind_point = info.bind_point;
#endif
}
-void ProgramData::update_block_uniform_indices(SharedBlock &block, const ReflectData::UniformBlockInfo &info) const
+void ProgramData::update_block_uniform_indices(SharedBlock &block, const ReflectData::BlockInfo &info) const
{
uint8_t *indices = block.indices.values;
if(info.uniforms.size()>16)
}
}
-void ProgramData::update_block(SharedBlock &block, const ReflectData::UniformBlockInfo &info) const
+void ProgramData::update_block(SharedBlock &block, const ReflectData::BlockInfo &info) const
{
const uint8_t *indices = block.get_uniform_indices();
for(unsigned i=0; i<info.uniforms.size(); ++i)
dirty = 0;
}
- const vector<ReflectData::UniformBlockInfo> &block_infos = prog.get_uniform_blocks();
+ const vector<ReflectData::BlockInfo> &block_infos = prog.get_blocks();
if(prog_begin->masks.dirty==ALL_ONES)
{
Refresh uniform indices within the program's blocks. */
prog_begin->masks.used = 0;
auto j = prog_begin+1;
- for(const ReflectData::UniformBlockInfo &b: block_infos)
+ for(const ReflectData::BlockInfo &b: block_infos)
{
SharedBlock &shared = blocks[j->block_index];
if(shared.dirty==ALL_ONES)
// Update the contents of all dirty blocks.
bool buffered_blocks_updated = false;
auto j = prog_begin+1;
- for(const ReflectData::UniformBlockInfo &b: block_infos)
+ for(const ReflectData::BlockInfo &b: block_infos)
{
SharedBlock &shared = blocks[j->block_index];
if(shared.dirty)
int find_uniform_index(Tag) const;
std::vector<ProgramBlock>::iterator get_program(const Program &) const;
void recreate_buffer() const;
- void update_block_uniform_indices(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
- void update_block(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
+ void update_block_uniform_indices(SharedBlock &, const ReflectData::BlockInfo &) const;
+ void update_block(SharedBlock &, const ReflectData::BlockInfo &) const;
std::vector<ProgramBlock>::const_iterator prepare_program(const Program &) const;
public: