summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d9d7ab4)
GlslangValidator apparently only allows IDs up to 2047. I've yet to find
out if there's a limit in SPIR-V itself.
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
generate(*i);
{
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
generate(*i);
+ ConstantIdAssigner().apply(*module, features);
bool valid = true;
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
bool valid = true;
for(list<Stage>::iterator i=module->stages.begin(); i!=module->stages.end(); ++i)
variables through interfaces. */
InterfaceGenerator().apply(stage);
resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES);
variables through interfaces. */
InterfaceGenerator().apply(stage);
resolve(stage, RESOLVE_BLOCKS|RESOLVE_TYPES|RESOLVE_VARIABLES);
-
- ConstantIdAssigner().apply(stage);
arb_gpu_shader5(false),
arb_uniform_buffer_object(false),
ext_gpu_shader4(false),
arb_gpu_shader5(false),
arb_uniform_buffer_object(false),
ext_gpu_shader4(false),
- ext_texture_array(false)
+ ext_texture_array(false),
+ max_constant_id(0x7FFFFFFF)
{ }
Features Features::from_context()
{ }
Features Features::from_context()
bool arb_uniform_buffer_object;
bool ext_gpu_shader4;
bool ext_texture_array;
bool arb_uniform_buffer_object;
bool ext_gpu_shader4;
bool ext_texture_array;
+ unsigned max_constant_id;
namespace GL {
namespace SL {
namespace GL {
namespace SL {
-void ConstantIdAssigner::apply(Stage &stage)
+void ConstantIdAssigner::apply(Module &module, const Features &features)
- stage.content.visit(*this);
+ for(list<Stage>::iterator i=module.stages.begin(); i!=module.stages.end(); ++i)
+ i->content.visit(*this);
+
+ unsigned max_id = features.max_constant_id;
+ for(vector<VariableDeclaration *>::iterator i=auto_constants.begin(); i!=auto_constants.end(); ++i)
+ {
+ unsigned id = hash32((*i)->name)%(max_id+1);
+ while(used_ids.count(id))
+ ++id;
+
+ vector<Layout::Qualifier> &qualifiers = (*i)->layout->qualifiers;
+ for(vector<Layout::Qualifier>::iterator j=qualifiers.begin(); j!=qualifiers.end(); ++j)
+ if(j->name=="constant_id")
+ {
+ j->value = id;
+ break;
+ }
+
+ used_ids.insert(id);
+ }
}
void ConstantIdAssigner::visit(VariableDeclaration &var)
}
void ConstantIdAssigner::visit(VariableDeclaration &var)
if(i->name=="constant_id" && i->has_value)
{
if(i->value==-1)
if(i->name=="constant_id" && i->has_value)
{
if(i->value==-1)
- i->value = hash32(var.name)&0x7FFFFFFF;
+ auto_constants.push_back(&var);
+ else
+ used_ids.insert(i->value);
/** Assigns IDs to specialization constants with an automatic ID. */
class ConstantIdAssigner: private TraversingVisitor
{
/** Assigns IDs to specialization constants with an automatic ID. */
class ConstantIdAssigner: private TraversingVisitor
{
+private:
+ std::set<unsigned> used_ids;
+ std::vector<VariableDeclaration *> auto_constants;
+
+ void apply(Module &, const Features &);
private:
virtual void visit(VariableDeclaration &);
private:
virtual void visit(VariableDeclaration &);