id = glCreateProgram();
module = 0;
- bindings = 0;
+ transient = 0;
linked = false;
}
compile_glsl_stage(stage_id);
}
- if(!bindings)
- bindings = new Bindings;
- bindings->textures = compiler.get_texture_bindings();
- bindings->blocks = compiler.get_uniform_block_bindings();
+ if(!transient)
+ transient = new TransientData;
+ transient->textures = compiler.get_texture_bindings();
+ transient->blocks = compiler.get_uniform_block_bindings();
}
void Program::compile_glsl_stage(unsigned stage_id)
const vector<UInt32> &code = mod.get_code();
glShaderBinary(stage_ids.size(), &stage_ids[0], GL_SHADER_BINARY_FORMAT_SPIR_V, &code[0], code.size()*4);
- const vector<SpirVModule::SpecConstant> &spec_consts = mod.get_spec_constants();
+ if(!spec_values.empty() && !transient)
+ transient = new TransientData;
+
+ const vector<SpirVModule::Constant> &spec_consts = mod.get_spec_constants();
vector<unsigned> spec_id_array;
vector<unsigned> spec_value_array;
spec_id_array.reserve(spec_consts.size());
spec_value_array.reserve(spec_consts.size());
- for(vector<SpirVModule::SpecConstant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
+ for(vector<SpirVModule::Constant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
{
map<string, int>::const_iterator j = spec_values.find(i->name);
if(j!=spec_values.end())
{
spec_id_array.push_back(i->constant_id);
spec_value_array.push_back(j->second);
+ transient->spec_values[i->constant_id] = j->second;
}
}
{
query_uniforms();
query_attributes();
- if(bindings)
+ if(transient)
{
for(unsigned i=0; i<uniform_blocks.size(); ++i)
{
- map<string, unsigned>::const_iterator j = bindings->blocks.find(uniform_blocks[i].name);
- if(j!=bindings->blocks.end())
+ map<string, unsigned>::const_iterator j = transient->blocks.find(uniform_blocks[i].name);
+ if(j!=transient->blocks.end())
{
glUniformBlockBinding(id, i, j->second);
uniform_blocks[i].bind_point = j->second;
}
Conditional<BindRestore> _bind(!ARB_separate_shader_objects, this);
- for(map<string, unsigned>::const_iterator i=bindings->textures.begin(); i!=bindings->textures.end(); ++i)
+ for(map<string, unsigned>::const_iterator i=transient->textures.begin(); i!=transient->textures.end(); ++i)
{
int location = get_uniform_location(i->first);
if(location>=0)
glUniform1i(location, i->second);
}
}
-
- delete bindings;
- bindings = 0;
}
}
else if(module->get_format()==Module::SPIR_V)
collect_attributes();
}
+ delete transient;
+ transient = 0;
+
for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
require_type(i->type);
for(vector<AttributeInfo>::const_iterator i=attributes.begin(); i!=attributes.end(); ++i)
i->location = glGetUniformLocation(id, i->name.c_str());
i->block = &default_block;
default_block.uniforms.push_back(&*i);
+
+ if(is_image(i->type) && i->location>=0)
+ glGetUniformiv(id, i->location, &i->binding);
}
default_block.layout_hash = compute_layout_hash(default_block.uniforms);
info.name = i->name;
info.tag = i->name;
info.location = i->location;
+ info.binding = i->binding;
info.array_size = i->array_size;
info.type = i->type;
}
block.uniforms.push_back(&uni);
uni.block = █
}
+ sort(block.uniforms, uniform_location_compare);
block.layout_hash = compute_layout_hash(block.uniforms);
}
unsigned offset = base_offset+i->offset;
if(i->struct_type)
{
- if(i->array_size)
+ unsigned array_size = i->array_size;
+ if(i->array_size_spec)
+ {
+ array_size = i->array_size_spec->i_value;
+ if(transient)
+ {
+ map<unsigned, int>::const_iterator j = transient->spec_values.find(i->array_size_spec->constant_id);
+ if(j!=transient->spec_values.end())
+ array_size = j->second;
+ }
+ }
+
+ if(array_size)
{
- for(unsigned j=0; j<i->array_size; ++j, offset+=i->array_stride)
+ for(unsigned j=0; j<array_size; ++j, offset+=i->array_stride)
collect_block_uniforms(*i->struct_type, format("%s%s[%d].", prefix, i->name, j), offset, uniform_names);
}
else
return i!=uniforms.end() && i->tag==tag && i->block->bind_point<0 ? i->location : -1;
}
+int Program::get_uniform_binding(Tag tag) const
+{
+ vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
+ return i!=uniforms.end() && i->tag==tag ? i->binding : -1;
+}
+
const Program::AttributeInfo &Program::get_attribute_info(const string &name) const
{
vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
array_size(0),
array_stride(0),
matrix_stride(0),
- type(VOID)
+ type(VOID),
+ binding(-1)
{ }