3 #include <msp/core/algorithm.h>
4 #include <msp/core/hash.h>
5 #include <msp/core/maputils.h>
6 #include <msp/core/raii.h>
7 #include <msp/gl/extensions/arb_es2_compatibility.h>
8 #include <msp/gl/extensions/arb_fragment_shader.h>
9 #include <msp/gl/extensions/arb_gl_spirv.h>
10 #include <msp/gl/extensions/arb_geometry_shader4.h>
11 #include <msp/gl/extensions/arb_separate_shader_objects.h>
12 #include <msp/gl/extensions/arb_shader_objects.h>
13 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
14 #include <msp/gl/extensions/arb_vertex_shader.h>
15 #include <msp/gl/extensions/ext_gpu_shader4.h>
16 #include <msp/gl/extensions/nv_non_square_matrices.h>
17 #include <msp/io/print.h>
18 #include <msp/strings/format.h>
23 #include "resources.h"
25 #include "glsl/compiler.h"
37 Program::Program(const std::string &source)
42 mod.set_source(source);
49 Program::Program(const string &vert, const string &frag)
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
55 attach_shader_owned(new VertexShader(vert));
56 attach_shader_owned(new FragmentShader(frag));
57 #pragma GCC diagnostic pop
61 Program::Program(const Module &mod, const map<string, int> &spec_values)
64 add_stages(mod, spec_values);
70 static Require _req(ARB_shader_objects);
72 id = glCreateProgram();
80 for(vector<unsigned>::iterator i=stage_ids.begin(); i!=stage_ids.end(); ++i)
85 void Program::add_stages(const Module &mod, const map<string, int> &spec_values)
87 if(!stage_ids.empty())
88 throw invalid_operation("Program::add_stages");
90 switch(mod.get_format())
92 case Module::GLSL: return add_glsl_stages(static_cast<const GlslModule &>(mod), spec_values);
93 case Module::SPIR_V: return add_spirv_stages(static_cast<const SpirVModule &>(mod), spec_values);
94 default: throw invalid_argument("Program::add_stages");
98 unsigned Program::add_stage(GLenum type)
102 case GL_VERTEX_SHADER: { static Require _req(ARB_vertex_shader); } break;
103 case GL_GEOMETRY_SHADER: { static Require _req(ARB_geometry_shader4); } break;
104 case GL_FRAGMENT_SHADER: { static Require _req(ARB_fragment_shader); } break;
105 default: throw invalid_argument("Program::add_stage");
108 unsigned stage_id = glCreateShader(type);
109 stage_ids.push_back(stage_id);
110 glAttachShader(id, stage_id);
115 void Program::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values)
119 SL::Compiler compiler;
120 compiler.set_source(mod.get_prepared_source(), "<module>");
121 compiler.specialize(spec_values);
122 compiler.compile(SL::Compiler::PROGRAM);
124 string diagnostics = compiler.get_diagnostics();
125 if(!diagnostics.empty())
126 IO::print("Program diagnostics:\n%s\n", diagnostics);
129 vector<SL::Stage::Type> stages = compiler.get_stages();
130 for(vector<SL::Stage::Type>::const_iterator i=stages.begin(); i!=stages.end(); ++i)
132 unsigned stage_id = 0;
135 case SL::Stage::VERTEX: stage_id = add_stage(GL_VERTEX_SHADER); break;
136 case SL::Stage::GEOMETRY: stage_id = add_stage(GL_GEOMETRY_SHADER); break;
137 case SL::Stage::FRAGMENT: stage_id = add_stage(GL_FRAGMENT_SHADER); break;
138 default: throw invalid_operation("Program::add_glsl_stages");
141 string stage_src = compiler.get_stage_glsl(*i);
142 const char *src_ptr = stage_src.data();
143 int src_len = stage_src.size();
144 glShaderSource(stage_id, 1, &src_ptr, &src_len);
146 if(*i==SL::Stage::VERTEX)
148 const map<string, unsigned> &attribs = compiler.get_vertex_attributes();
149 for(map<string, unsigned>::const_iterator j=attribs.begin(); j!=attribs.end(); ++j)
150 glBindAttribLocation(id, j->second, j->first.c_str());
153 if(*i==SL::Stage::FRAGMENT && EXT_gpu_shader4)
155 const map<string, unsigned> &frag_outs = compiler.get_fragment_outputs();
156 for(map<string, unsigned>::const_iterator j=frag_outs.begin(); j!=frag_outs.end(); ++j)
157 glBindFragDataLocation(id, j->second, j->first.c_str());
160 compile_glsl_stage(stage_id);
164 bindings = new Bindings;
165 bindings->textures = compiler.get_texture_bindings();
166 bindings->blocks = compiler.get_uniform_block_bindings();
169 void Program::compile_glsl_stage(unsigned stage_id)
171 glCompileShader(stage_id);
172 bool compiled = get_shader_i(stage_id, GL_COMPILE_STATUS);
174 GLsizei info_log_len = get_shader_i(stage_id, GL_INFO_LOG_LENGTH);
175 string info_log(info_log_len+1, 0);
176 glGetShaderInfoLog(stage_id, info_log_len+1, &info_log_len, &info_log[0]);
177 info_log.erase(info_log_len);
178 if(module && module->get_format()==Module::GLSL)
179 info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
182 throw compile_error(info_log);
184 if(!info_log.empty())
185 IO::print("Shader compile info log:\n%s", info_log);
189 void Program::add_spirv_stages(const SpirVModule &mod, const map<string, int> &spec_values)
191 static Require _req(ARB_gl_spirv);
192 static Require _req2(ARB_ES2_compatibility);
196 const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
197 std::set<SpirVModule::Stage> stages;
198 for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
200 if(stages.count(i->stage))
201 throw invalid_argument("Program::add_spirv_stages");
205 case SpirVModule::VERTEX: add_stage(GL_VERTEX_SHADER); break;
206 case SpirVModule::GEOMETRY: add_stage(GL_GEOMETRY_SHADER); break;
207 case SpirVModule::FRAGMENT: add_stage(GL_FRAGMENT_SHADER); break;
208 default: throw invalid_operation("Program::add_spirv_stages");
211 stages.insert(i->stage);
214 const vector<UInt32> &code = mod.get_code();
215 glShaderBinary(stage_ids.size(), &stage_ids[0], GL_SHADER_BINARY_FORMAT_SPIR_V, &code[0], code.size()*4);
217 const vector<SpirVModule::SpecConstant> &spec_consts = mod.get_spec_constants();
218 vector<unsigned> spec_id_array;
219 vector<unsigned> spec_value_array;
220 spec_id_array.reserve(spec_consts.size());
221 spec_value_array.reserve(spec_consts.size());
222 for(vector<SpirVModule::SpecConstant>::const_iterator i=spec_consts.begin(); i!=spec_consts.end(); ++i)
224 map<string, int>::const_iterator j = spec_values.find(i->name);
225 if(j!=spec_values.end())
227 spec_id_array.push_back(i->constant_id);
228 spec_value_array.push_back(j->second);
232 vector<SpirVModule::EntryPoint>::const_iterator j=entry_points.begin();
233 for(vector<unsigned>::const_iterator i=stage_ids.begin(); i!=stage_ids.end(); ++i, ++j)
234 glSpecializeShader(*i, j->name.c_str(), spec_id_array.size(), &spec_id_array[0], &spec_value_array[0]);
237 #pragma GCC diagnostic push
238 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
239 void Program::attach_shader(Shader &shader)
241 unsigned shader_id = shader.steal_id();
243 throw invalid_argument("Program::attach_shader");
244 stage_ids.push_back(shader_id);
245 compile_glsl_stage(shader_id);
248 void Program::attach_shader_owned(Shader *shader)
250 attach_shader(*shader);
254 void Program::detach_shader(Shader &)
258 const vector<Shader *> &Program::get_attached_shaders() const
260 static vector<Shader *> dummy;
264 void Program::bind_attribute(unsigned index, const string &name)
266 static Require _req(ARB_vertex_shader);
267 glBindAttribLocation(id, index, name.c_str());
270 void Program::bind_attribute(VertexAttribute attr, const string &name)
272 bind_attribute(get_attribute_semantic(attr), name);
275 void Program::bind_fragment_data(unsigned index, const string &name)
277 static Require _req(EXT_gpu_shader4);
278 glBindFragDataLocation(id, index, name.c_str());
280 #pragma GCC diagnostic pop
284 if(stage_ids.empty())
285 throw invalid_operation("Program::link");
288 uniform_blocks.clear();
292 linked = get_program_i(id, GL_LINK_STATUS);
294 GLsizei info_log_len = get_program_i(id, GL_INFO_LOG_LENGTH);
295 string info_log(info_log_len+1, 0);
296 glGetProgramInfoLog(id, info_log_len+1, &info_log_len, &info_log[0]);
297 info_log.erase(info_log_len);
298 if(module && module->get_format()==Module::GLSL)
299 info_log = static_cast<const GlslModule *>(module)->get_source_map().translate_errors(info_log);
302 throw compile_error(info_log);
304 if(!info_log.empty())
305 IO::print("Program link info log:\n%s", info_log);
308 if(module->get_format()==Module::GLSL)
314 for(unsigned i=0; i<uniform_blocks.size(); ++i)
316 map<string, unsigned>::const_iterator j = bindings->blocks.find(uniform_blocks[i].name);
317 if(j!=bindings->blocks.end())
319 glUniformBlockBinding(id, i, j->second);
320 uniform_blocks[i].bind_point = j->second;
324 Conditional<BindRestore> _bind(!ARB_separate_shader_objects, this);
325 for(map<string, unsigned>::const_iterator i=bindings->textures.begin(); i!=bindings->textures.end(); ++i)
327 int location = get_uniform_location(i->first);
330 if(ARB_separate_shader_objects)
331 glProgramUniform1i(id, location, i->second);
333 glUniform1i(location, i->second);
341 else if(module->get_format()==Module::SPIR_V)
344 collect_attributes();
347 for(vector<UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
348 require_type(i->type);
349 for(vector<AttributeInfo>::const_iterator i=attributes.begin(); i!=attributes.end(); ++i)
350 require_type(i->type);
353 void Program::query_uniforms()
355 unsigned count = get_program_i(id, GL_ACTIVE_UNIFORMS);
356 uniforms.reserve(count);
357 vector<string> uniform_names(count);
358 for(unsigned i=0; i<count; ++i)
364 glGetActiveUniform(id, i, sizeof(name), &len, &size, &type, name);
365 if(len && strncmp(name, "gl_", 3))
367 /* Some implementations report the first element of a uniform array,
368 others report just the name of the array itself. */
369 if(len>3 && !strcmp(name+len-3, "[0]"))
372 uniforms.push_back(UniformInfo());
373 UniformInfo &info = uniforms.back();
376 info.array_size = size;
377 info.type = from_gl_type(type);
378 uniform_names[i] = name;
382 sort(uniforms, &uniform_tag_compare);
384 if(ARB_uniform_buffer_object)
386 vector<UniformInfo *> uniforms_by_index(count);
387 for(unsigned i=0; i<count; ++i)
388 if(!uniform_names[i].empty())
389 // The element is already known to be present
390 uniforms_by_index[i] = &*lower_bound(uniforms, Tag(uniform_names[i]), &search<UniformInfo, Tag, &UniformInfo::tag>);
391 query_uniform_blocks(uniforms_by_index);
394 uniform_blocks.push_back(UniformBlockInfo());
395 UniformBlockInfo &default_block = uniform_blocks.back();
397 for(vector<UniformInfo>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
400 i->location = glGetUniformLocation(id, i->name.c_str());
401 i->block = &default_block;
402 default_block.uniforms.push_back(&*i);
405 default_block.layout_hash = compute_layout_hash(default_block.uniforms);
407 update_layout_hash();
410 void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_index)
412 unsigned count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
413 // Reserve an extra index for the default block
414 uniform_blocks.reserve(count+1);
415 for(unsigned i=0; i<count; ++i)
419 glGetActiveUniformBlockName(id, i, sizeof(name), &len, name);
420 uniform_blocks.push_back(UniformBlockInfo());
421 UniformBlockInfo &info = uniform_blocks.back();
425 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_DATA_SIZE, &value);
426 info.data_size = value;
428 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_BINDING, &value);
429 info.bind_point = value;
431 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &value);
432 vector<int> indices(value);
433 glGetActiveUniformBlockiv(id, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, &indices[0]);
434 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
436 if(!uniforms_by_index[*j])
437 throw logic_error("Program::link");
438 info.uniforms.push_back(uniforms_by_index[*j]);
439 uniforms_by_index[*j]->block = &info;
442 vector<unsigned> query_indices(indices.begin(), indices.end());
443 vector<int> values(indices.size());
444 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_OFFSET, &values[0]);
445 for(unsigned j=0; j<indices.size(); ++j)
446 uniforms_by_index[indices[j]]->offset = values[j];
448 query_indices.clear();
449 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
450 if(uniforms_by_index[*j]->array_size>1)
451 query_indices.push_back(*j);
452 if(!query_indices.empty())
454 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_ARRAY_STRIDE, &values[0]);
455 for(unsigned j=0; j<query_indices.size(); ++j)
456 uniforms_by_index[query_indices[j]]->array_stride = values[j];
459 query_indices.clear();
460 for(vector<int>::iterator j=indices.begin(); j!=indices.end(); ++j)
462 DataType t = uniforms_by_index[*j]->type;
464 query_indices.push_back(*j);
466 if(!query_indices.empty())
468 glGetActiveUniformsiv(id, query_indices.size(), &query_indices[0], GL_UNIFORM_MATRIX_STRIDE, &values[0]);
469 for(unsigned j=0; j<query_indices.size(); ++j)
470 uniforms_by_index[query_indices[j]]->matrix_stride = values[j];
473 sort(info.uniforms.begin(), info.uniforms.end(), uniform_location_compare);
474 info.layout_hash = compute_layout_hash(info.uniforms);
478 void Program::query_attributes()
480 unsigned count = get_program_i(id, GL_ACTIVE_ATTRIBUTES);
481 attributes.reserve(count);
482 for(unsigned i=0; i<count; ++i)
488 glGetActiveAttrib(id, i, sizeof(name), &len, &size, &type, name);
489 if(len && strncmp(name, "gl_", 3))
491 if(len>3 && !strcmp(name+len-3, "[0]"))
494 attributes.push_back(AttributeInfo());
495 AttributeInfo &info = attributes.back();
497 info.location = glGetAttribLocation(id, name);
498 info.array_size = size;
499 info.type = from_gl_type(type);
504 void Program::collect_uniforms()
506 const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
508 // Prepare the default block
509 uniform_blocks.push_back(UniformBlockInfo());
510 vector<vector<string> > block_uniform_names(1);
512 const vector<SpirVModule::Variable> &variables = mod.get_variables();
513 for(vector<SpirVModule::Variable>::const_iterator i=variables.begin(); i!=variables.end(); ++i)
515 if(i->storage==SpirVModule::UNIFORM && i->struct_type)
517 uniform_blocks.push_back(UniformBlockInfo());
518 UniformBlockInfo &info = uniform_blocks.back();
519 info.name = i->struct_type->name;
520 info.bind_point = i->binding;
521 info.data_size = i->struct_type->size;
525 prefix = i->struct_type->name+".";
526 block_uniform_names.push_back(vector<string>());
527 collect_block_uniforms(*i->struct_type, prefix, 0, block_uniform_names.back());
529 else if(i->storage==SpirVModule::UNIFORM_CONSTANT && i->location>=0)
531 block_uniform_names[0].push_back(i->name);
532 uniforms.push_back(UniformInfo());
533 UniformInfo &info = uniforms.back();
536 info.location = i->location;
537 info.array_size = i->array_size;
542 sort(uniforms, &uniform_tag_compare);
544 for(unsigned i=0; i<uniform_blocks.size(); ++i)
546 UniformBlockInfo &block = uniform_blocks[i];
547 const vector<string> &names = block_uniform_names[i];
548 for(vector<string>::const_iterator j=names.begin(); j!=names.end(); ++j)
550 // The element is already known to be present
551 UniformInfo &uni = *lower_bound(uniforms, Tag(*j), &search<UniformInfo, Tag, &UniformInfo::tag>);
552 block.uniforms.push_back(&uni);
555 block.layout_hash = compute_layout_hash(block.uniforms);
558 update_layout_hash();
561 void Program::collect_block_uniforms(const SpirVModule::Structure &strct, const string &prefix, unsigned base_offset, vector<string> &uniform_names)
563 for(vector<SpirVModule::StructMember>::const_iterator i=strct.members.begin(); i!=strct.members.end(); ++i)
565 unsigned offset = base_offset+i->offset;
570 for(unsigned j=0; j<i->array_size; ++j, offset+=i->array_stride)
571 collect_block_uniforms(*i->struct_type, format("%s%s[%d].", prefix, i->name, j), offset, uniform_names);
574 collect_block_uniforms(*i->struct_type, prefix+i->name+".", offset, uniform_names);
578 string name = prefix+i->name;
579 uniform_names.push_back(name);
580 uniforms.push_back(UniformInfo());
581 UniformInfo &info = uniforms.back();
584 info.offset = offset;
585 info.array_size = i->array_size;
586 info.array_stride = i->array_stride;
587 info.matrix_stride = i->matrix_stride;
593 void Program::collect_attributes()
595 const SpirVModule &mod = static_cast<const SpirVModule &>(*module);
597 const vector<SpirVModule::EntryPoint> &entry_points = mod.get_entry_points();
598 for(vector<SpirVModule::EntryPoint>::const_iterator i=entry_points.begin(); i!=entry_points.end(); ++i)
599 if(i->stage==SpirVModule::VERTEX && i->name=="main")
601 for(vector<const SpirVModule::Variable *>::const_iterator j=i->globals.begin(); j!=i->globals.end(); ++j)
602 if((*j)->storage==SpirVModule::INPUT)
604 attributes.push_back(AttributeInfo());
605 AttributeInfo &info = attributes.back();
606 info.name = (*j)->name;
607 info.location = (*j)->location;
608 info.array_size = (*j)->array_size;
609 info.type = (*j)->type;
614 void Program::update_layout_hash()
616 string layout_descriptor;
617 for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
618 layout_descriptor += format("%d:%x\n", i->bind_point, i->layout_hash);
619 uniform_layout_hash = hash32(layout_descriptor);
622 Program::LayoutHash Program::compute_layout_hash(const vector<const UniformInfo *> &uniforms)
624 string layout_descriptor;
625 for(vector<const UniformInfo *>::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i)
626 layout_descriptor += format("%d:%s:%x:%d\n", (*i)->location, (*i)->name, (*i)->type, (*i)->array_size);
627 return hash32(layout_descriptor);
630 bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInfo *uni2)
632 return uni1->location<uni2->location;
635 bool Program::uniform_tag_compare(const UniformInfo &uni1, const UniformInfo &uni2)
637 return uni1.tag<uni2.tag;
640 template<typename T, typename A, A T::*member>
641 bool Program::search(const T &item, const A &key)
643 return item.*member<key;
646 string Program::get_info_log() const
648 GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH);
649 string log(len+1, 0);
650 glGetProgramInfoLog(id, len+1, &len, &log[0]);
655 const Program::UniformBlockInfo &Program::get_uniform_block_info(const string &name) const
657 for(vector<UniformBlockInfo>::const_iterator i=uniform_blocks.begin(); i!=uniform_blocks.end(); ++i)
660 throw key_error(name);
663 const Program::UniformInfo &Program::get_uniform_info(const string &name) const
665 vector<UniformInfo>::const_iterator i = lower_bound(uniforms, Tag(name), &search<UniformInfo, Tag, &UniformInfo::tag>);
666 if(i==uniforms.end() || i->name!=name)
667 throw key_error(name);
671 const Program::UniformInfo &Program::get_uniform_info(Tag tag) const
673 vector<UniformInfo>::const_iterator i = lower_bound(uniforms, tag, &search<UniformInfo, Tag, &UniformInfo::tag>);
674 if(i==uniforms.end() || i->tag!=tag)
675 throw key_error(tag);
679 int Program::get_uniform_location(const string &name) const
681 if(name[name.size()-1]==']')
682 throw invalid_argument("Program::get_uniform_location");
684 vector<UniformInfo>::const_iterator i = lower_bound(uniforms, Tag(name), &search<UniformInfo, Tag, &UniformInfo::tag>);
685 return i!=uniforms.end() && i->name==name && i->block->bind_point<0 ? i->location : -1;
688 int Program::get_uniform_location(Tag tag) const
690 vector<UniformInfo>::const_iterator i = lower_bound(uniforms, tag, &search<UniformInfo, Tag, &UniformInfo::tag>);
691 return i!=uniforms.end() && i->tag==tag && i->block->bind_point<0 ? i->location : -1;
694 const Program::AttributeInfo &Program::get_attribute_info(const string &name) const
696 vector<AttributeInfo>::const_iterator i = lower_bound(attributes, name, &search<AttributeInfo, string, &AttributeInfo::name>);
697 if(i==attributes.end() || i->name!=name)
698 throw key_error(name);
702 int Program::get_attribute_location(const string &name) const
704 if(name[name.size()-1]==']')
705 throw invalid_argument("Program::get_attribute_location");
707 vector<AttributeInfo>::const_iterator i = lower_bound(attributes, name, &search<AttributeInfo, string, &AttributeInfo::name>);
708 return i!=attributes.end() && i->name==name ? i->location : -1;
711 void Program::bind() const
714 throw invalid_operation("Program::bind");
716 if(!set_current(this))
722 void Program::unbind()
731 Program::UniformInfo::UniformInfo():
741 Program::UniformBlockInfo::UniformBlockInfo():
748 Program::AttributeInfo::AttributeInfo():
755 Program::Loader::Loader(Program &p, Collection &c):
756 DataFile::CollectionObjectLoader<Program>(p, &c)
758 add("module", &Loader::module);
761 add("attribute", &Loader::attribute);
762 add("fragment_shader", &Loader::fragment_shader);
763 add("geometry_shader", &Loader::geometry_shader);
764 add("vertex_shader", &Loader::vertex_shader);
767 void Program::Loader::finish()
772 void Program::Loader::module(const string &n)
774 map<string, int> spec_values;
775 SpecializationLoader ldr(spec_values);
777 obj.add_stages(get_collection().get<Module>(n), spec_values);
780 #pragma GCC diagnostic push
781 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
782 void Program::Loader::attribute(unsigned i, const string &n)
784 obj.bind_attribute(i, n);
787 void Program::Loader::fragment_shader(const string &src)
789 obj.attach_shader_owned(new FragmentShader(src));
792 void Program::Loader::geometry_shader(const string &src)
794 obj.attach_shader_owned(new GeometryShader(src));
797 void Program::Loader::vertex_shader(const string &src)
799 obj.attach_shader_owned(new VertexShader(src));
801 #pragma GCC diagnostic pop
804 DataFile::Loader::ActionMap Program::SpecializationLoader::shared_actions;
806 Program::SpecializationLoader::SpecializationLoader(map<string, int> &sv):
809 set_actions(shared_actions);
812 void Program::SpecializationLoader::init_actions()
814 add("specialize", &SpecializationLoader::specialize_bool);
815 add("specialize", &SpecializationLoader::specialize_int);
818 void Program::SpecializationLoader::specialize_bool(const string &name, bool value)
820 spec_values[name] = value;
823 void Program::SpecializationLoader::specialize_int(const string &name, int value)
825 spec_values[name] = value;