]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/generate.cpp
Create array type declarations as necessary
[libs/gl.git] / source / glsl / generate.cpp
1 #include <msp/core/hash.h>
2 #include <msp/core/raii.h>
3 #include <msp/strings/lexicalcast.h>
4 #include "builtin.h"
5 #include "generate.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11 namespace SL {
12
13 void DeclarationCombiner::apply(Stage &stage)
14 {
15         stage.content.visit(*this);
16         NodeRemover().apply(stage, nodes_to_remove);
17 }
18
19 void DeclarationCombiner::visit(Block &block)
20 {
21         if(current_block)
22                 return;
23
24         TraversingVisitor::visit(block);
25 }
26
27 void DeclarationCombiner::visit(VariableDeclaration &var)
28 {
29         VariableDeclaration *&ptr = variables[var.name];
30         if(ptr)
31         {
32                 ptr->type = var.type;
33                 if(var.init_expression)
34                         ptr->init_expression = var.init_expression;
35                 if(var.layout)
36                 {
37                         if(ptr->layout)
38                         {
39                                 for(vector<Layout::Qualifier>::iterator i=var.layout->qualifiers.begin(); i!=var.layout->qualifiers.end(); ++i)
40                                 {
41                                         bool found = false;
42                                         for(vector<Layout::Qualifier>::iterator j=ptr->layout->qualifiers.begin(); (!found && j!=ptr->layout->qualifiers.end()); ++j)
43                                                 if(j->name==i->name)
44                                                 {
45                                                         j->has_value = i->value;
46                                                         j->value = i->value;
47                                                         found = true;
48                                                 }
49
50                                         if(!found)
51                                                 ptr->layout->qualifiers.push_back(*i);
52                                 }
53                         }
54                         else
55                                 ptr->layout = var.layout;
56                 }
57                 nodes_to_remove.insert(&var);
58         }
59         else
60                 ptr = &var;
61 }
62
63
64 ConstantSpecializer::ConstantSpecializer():
65         values(0)
66 { }
67
68 void ConstantSpecializer::apply(Stage &stage, const map<string, int> *v)
69 {
70         values = v;
71         stage.content.visit(*this);
72 }
73
74 void ConstantSpecializer::visit(VariableDeclaration &var)
75 {
76         bool specializable = false;
77         if(var.layout)
78         {
79                 vector<Layout::Qualifier> &qualifiers = var.layout->qualifiers;
80                 for(vector<Layout::Qualifier>::iterator i=qualifiers.begin(); i!=qualifiers.end(); ++i)
81                         if(i->name=="constant_id")
82                         {
83                                 specializable = true;
84                                 if(values)
85                                         qualifiers.erase(i);
86                                 else if(i->value==-1)
87                                         i->value = hash32(var.name)&0x7FFFFFFF;
88                                 break;
89                         }
90
91                 if(qualifiers.empty())
92                         var.layout = 0;
93         }
94
95         if(specializable && values)
96         {
97                 map<string, int>::const_iterator i = values->find(var.name);
98                 if(i!=values->end())
99                 {
100                         RefPtr<Literal> literal = new Literal;
101                         if(var.type=="bool")
102                         {
103                                 literal->token = (i->second ? "true" : "false");
104                                 literal->value = static_cast<bool>(i->second);
105                         }
106                         else if(var.type=="int")
107                         {
108                                 literal->token = lexical_cast<string>(i->second);
109                                 literal->value = i->second;
110                         }
111                         var.init_expression = literal;
112                 }
113         }
114 }
115
116
117 void BlockHierarchyResolver::enter(Block &block)
118 {
119         block.parent = current_block;
120 }
121
122
123 TypeResolver::TypeResolver():
124         stage(0)
125 { }
126
127 void TypeResolver::apply(Stage &s)
128 {
129         stage = &s;
130         s.types.clear();
131         s.content.visit(*this);
132 }
133
134 TypeDeclaration *TypeResolver::resolve_type(const string &name)
135 {
136         map<string, TypeDeclaration *>::iterator i = stage->types.find(name);
137         if(i!=stage->types.end())
138         {
139                 map<TypeDeclaration *, TypeDeclaration *>::iterator j = alias_map.find(i->second);
140                 return (j!=alias_map.end() ? j->second : i->second);
141         }
142         else
143                 return 0;
144 }
145
146 void TypeResolver::visit(Block &block)
147 {
148         for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
149         {
150                 if(!block.parent)
151                         type_insert_point = i;
152                 (*i)->visit(*this);
153         }
154 }
155
156 void TypeResolver::visit(BasicTypeDeclaration &type)
157 {
158         type.base_type = resolve_type(type.base);
159
160         if(type.kind==BasicTypeDeclaration::VECTOR && type.base_type)
161                 if(BasicTypeDeclaration *basic_base = dynamic_cast<BasicTypeDeclaration *>(type.base_type))
162                         if(basic_base->kind==BasicTypeDeclaration::VECTOR)
163                         {
164                                 type.kind = BasicTypeDeclaration::MATRIX;
165                                 type.size |= basic_base->size<<16;
166                         }
167
168         if(type.kind==BasicTypeDeclaration::ALIAS && type.base_type)
169                 alias_map[&type] = type.base_type;
170         else if(type.kind==BasicTypeDeclaration::ARRAY && type.base_type)
171                 array_types[type.base_type] = &type;
172
173         stage->types.insert(make_pair(type.name, &type));
174 }
175
176 void TypeResolver::visit(ImageTypeDeclaration &type)
177 {
178         type.base_type = resolve_type(type.base);
179         stage->types.insert(make_pair(type.name, &type));
180 }
181
182 void TypeResolver::visit(StructDeclaration &strct)
183 {
184         stage->types.insert(make_pair(strct.name, &strct));
185         TraversingVisitor::visit(strct);
186 }
187
188 void TypeResolver::visit(VariableDeclaration &var)
189 {
190         TypeDeclaration *type = resolve_type(var.type);
191         if(var.array && type)
192         {
193                 map<TypeDeclaration *, TypeDeclaration *>::iterator i = array_types.find(type);
194                 if(i==array_types.end())
195                 {
196                         BasicTypeDeclaration *array = new BasicTypeDeclaration;
197                         array->source = BUILTIN_SOURCE;
198                         array->name = type->name+"[]";
199                         array->kind = BasicTypeDeclaration::ARRAY;
200                         array->base = type->name;
201                         array->base_type = type;
202                         stage->content.body.insert(type_insert_point, array);
203                         array->visit(*this);
204                         type = array;
205                 }
206                 else
207                         type = i->second;
208         }
209         var.type_declaration = type;
210 }
211
212 void TypeResolver::visit(FunctionDeclaration &func)
213 {
214         func.return_type_declaration = resolve_type(func.return_type);
215         TraversingVisitor::visit(func);
216 }
217
218
219 VariableResolver::VariableResolver():
220         stage(0),
221         r_members(0),
222         record_target(false),
223         r_self_referencing(false),
224         r_assignment_target(0)
225 { }
226
227 void VariableResolver::apply(Stage &s)
228 {
229         stage = &s;
230         s.interface_blocks.clear();
231         s.content.visit(*this);
232 }
233
234 void VariableResolver::enter(Block &block)
235 {
236         block.variables.clear();
237 }
238
239 void VariableResolver::visit(VariableReference &var)
240 {
241         var.declaration = 0;
242         r_members = 0;
243         /* Look for variable declarations in the block hierarchy first.  Interface
244         blocks are always defined in the top level so we can't accidentally skip
245         one. */
246         for(Block *block=current_block; (!var.declaration && block); block=block->parent)
247         {
248                 map<string, VariableDeclaration *>::iterator i = block->variables.find(var.name);
249                 if(i!=block->variables.end())
250                         var.declaration = i->second;
251         }
252
253         if(!var.declaration)
254         {
255                 const map<string, InterfaceBlock *> &blocks = stage->interface_blocks;
256                 map<string, InterfaceBlock *>::const_iterator i = blocks.find("_"+var.name);
257                 if(i!=blocks.end())
258                 {
259                         /* The name refers to an interface block with an instance name rather
260                         than a variable.  Prepare a new syntax tree node accordingly. */
261                         r_iface_ref = new InterfaceBlockReference;
262                         r_iface_ref->source = var.source;
263                         r_iface_ref->line = var.line;
264                         r_iface_ref->name = var.name;
265                         r_iface_ref->declaration = i->second;
266                         r_members = &i->second->members.variables;
267                 }
268                 else
269                 {
270                         // Look for the variable in anonymous interface blocks.
271                         for(i=blocks.begin(); (!var.declaration && i!=blocks.end()); ++i)
272                                 if(i->second->instance_name.empty())
273                                 {
274                                         map<string, VariableDeclaration *>::iterator j = i->second->members.variables.find(var.name);
275                                         if(j!=i->second->members.variables.end())
276                                                 var.declaration = j->second;
277                                 }
278                 }
279         }
280
281         if(var.declaration)
282                 if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(var.declaration->type_declaration))
283                         r_members = &strct->members.variables;
284
285         if(record_target)
286         {
287                 if(r_assignment_target)
288                 {
289                         /* More than one variable reference found in assignment target.
290                         Unable to determine what the primary target is. */
291                         record_target = false;
292                         r_assignment_target = 0;
293                 }
294                 else
295                         r_assignment_target = var.declaration;
296         }
297         else if(var.declaration && var.declaration==r_assignment_target)
298                 r_self_referencing = true;
299 }
300
301 void VariableResolver::visit(InterfaceBlockReference &iface)
302 {
303         iface.declaration = 0;
304         for(Block *block=current_block; block; block=block->parent)
305         {
306                 map<string, InterfaceBlock *>::iterator i = stage->interface_blocks.find("_"+iface.name);
307                 if(i!=stage->interface_blocks.end())
308                 {
309                         iface.declaration = i->second;
310                         r_members = &i->second->members.variables;
311                         break;
312                 }
313         }
314 }
315
316 void VariableResolver::visit(MemberAccess &memacc)
317 {
318         r_members = 0;
319         r_iface_ref = 0;
320         memacc.left->visit(*this);
321
322         if(r_iface_ref)
323                 memacc.left = r_iface_ref;
324         r_iface_ref = 0;
325
326         memacc.declaration = 0;
327         if(r_members)
328         {
329                 map<string, VariableDeclaration *>::iterator i = r_members->find(memacc.member);
330                 if(i!=r_members->end())
331                 {
332                         memacc.declaration = i->second;
333                         if(StructDeclaration *strct = dynamic_cast<StructDeclaration *>(i->second->type_declaration))
334                                 r_members = &strct->members.variables;
335                 }
336                 else
337                         r_members = 0;
338         }
339 }
340
341 void VariableResolver::visit(UnaryExpression &unary)
342 {
343         TraversingVisitor::visit(unary);
344         r_members = 0;
345         r_iface_ref = 0;
346 }
347
348 void VariableResolver::visit(BinaryExpression &binary)
349 {
350         if(binary.oper->token[0]=='[')
351         {
352                 {
353                         /* The subscript expression is not a part of the primary assignment
354                         target. */
355                         SetFlag set(record_target, false);
356                         binary.right->visit(*this);
357                 }
358                 r_members = 0;
359                 r_iface_ref = 0;
360                 binary.left->visit(*this);
361                 if(r_iface_ref)
362                         binary.left = r_iface_ref;
363         }
364         else
365         {
366                 TraversingVisitor::visit(binary);
367                 r_members = 0;
368         }
369
370         r_iface_ref = 0;
371 }
372
373 void VariableResolver::visit(Assignment &assign)
374 {
375         {
376                 SetFlag set(record_target);
377                 r_assignment_target = 0;
378                 assign.left->visit(*this);
379                 assign.target_declaration = r_assignment_target;
380         }
381
382         r_self_referencing = false;
383         assign.right->visit(*this);
384         assign.self_referencing = (r_self_referencing || assign.oper->token[0]!='=');
385
386         r_members = 0;
387         r_iface_ref = 0;
388 }
389
390 void VariableResolver::visit(FunctionCall &call)
391 {
392         TraversingVisitor::visit(call);
393         r_members = 0;
394         r_iface_ref = 0;
395 }
396
397 void VariableResolver::visit(VariableDeclaration &var)
398 {
399         if(!block_interface.empty() && var.interface.empty())
400                 var.interface = block_interface;
401
402         TraversingVisitor::visit(var);
403         current_block->variables.insert(make_pair(var.name, &var));
404 }
405
406 void VariableResolver::visit(InterfaceBlock &iface)
407 {
408         /* Block names can be reused in different interfaces.  Prefix the name with
409         the first character of the interface to avoid conflicts. */
410         stage->interface_blocks.insert(make_pair(iface.interface+iface.name, &iface));
411         if(!iface.instance_name.empty())
412                 stage->interface_blocks.insert(make_pair("_"+iface.instance_name, &iface));
413
414         SetForScope<string> set_iface(block_interface, iface.interface);
415         TraversingVisitor::visit(iface);
416 }
417
418
419 void FunctionResolver::apply(Stage &s)
420 {
421         stage = &s;
422         s.functions.clear();
423         s.content.visit(*this);
424 }
425
426 void FunctionResolver::visit(FunctionCall &call)
427 {
428         map<string, FunctionDeclaration *>::iterator i = stage->functions.find(call.name);
429         if(i!=stage->functions.end())
430                 call.declaration = i->second;
431
432         TraversingVisitor::visit(call);
433 }
434
435 void FunctionResolver::visit(FunctionDeclaration &func)
436 {
437         FunctionDeclaration *&stage_decl = stage->functions[func.name];
438         vector<FunctionDeclaration *> &decls = declarations[func.name];
439         if(func.definition==&func)
440         {
441                 stage_decl = &func;
442
443                 // Set all previous declarations to use this definition.
444                 for(vector<FunctionDeclaration *>::iterator i=decls.begin(); i!=decls.end(); ++i)
445                 {
446                         (*i)->definition = func.definition;
447                         (*i)->body.body.clear();
448                 }
449         }
450         else
451         {
452                 func.definition = 0;
453                 if(!stage_decl)
454                         stage_decl = &func;
455                 else
456                         func.definition = stage_decl->definition;
457         }
458         decls.push_back(&func);
459
460         TraversingVisitor::visit(func);
461 }
462
463
464 InterfaceGenerator::InterfaceGenerator():
465         stage(0),
466         function_scope(false),
467         iface_block(0),
468         copy_block(false),
469         iface_target_block(0)
470 { }
471
472 string InterfaceGenerator::get_out_prefix(Stage::Type type)
473 {
474         if(type==Stage::VERTEX)
475                 return "_vs_out_";
476         else if(type==Stage::GEOMETRY)
477                 return "_gs_out_";
478         else
479                 return string();
480 }
481
482 void InterfaceGenerator::apply(Stage &s)
483 {
484         stage = &s;
485         iface_target_block = &stage->content;
486         if(stage->previous)
487                 in_prefix = get_out_prefix(stage->previous->type);
488         out_prefix = get_out_prefix(stage->type);
489         s.content.visit(*this);
490         NodeRemover().apply(s, nodes_to_remove);
491 }
492
493 void InterfaceGenerator::visit(Block &block)
494 {
495         SetForScope<Block *> set_block(current_block, &block);
496         for(NodeList<Statement>::iterator i=block.body.begin(); i!=block.body.end(); ++i)
497         {
498                 assignment_insert_point = i;
499                 if(&block==&stage->content)
500                         iface_insert_point = i;
501
502                 (*i)->visit(*this);
503         }
504 }
505
506 string InterfaceGenerator::change_prefix(const string &name, const string &prefix) const
507 {
508         unsigned offset = (name.compare(0, in_prefix.size(), in_prefix) ? 0 : in_prefix.size());
509         return prefix+name.substr(offset);
510 }
511
512 VariableDeclaration *InterfaceGenerator::generate_interface(VariableDeclaration &var, const string &iface, const string &name)
513 {
514         if(stage->content.variables.count(name))
515                 return 0;
516
517         VariableDeclaration* iface_var = new VariableDeclaration;
518         iface_var->sampling = var.sampling;
519         iface_var->interface = iface;
520         iface_var->type = var.type;
521         iface_var->name = name;
522         /* Geometry shader inputs are always arrays.  But if we're bringing in an
523         entire block, the array is on the block and not individual variables. */
524         if(stage->type==Stage::GEOMETRY && !copy_block)
525                 iface_var->array = ((var.array && var.interface!="in") || iface=="in");
526         else
527                 iface_var->array = var.array;
528         if(iface_var->array)
529                 iface_var->array_size = var.array_size;
530         if(iface=="in")
531         {
532                 iface_var->layout = var.layout;
533                 iface_var->linked_declaration = &var;
534                 var.linked_declaration = iface_var;
535         }
536
537         iface_target_block->body.insert(iface_insert_point, iface_var);
538         iface_target_block->variables.insert(make_pair(name, iface_var));
539
540         return iface_var;
541 }
542
543 InterfaceBlock *InterfaceGenerator::generate_interface(InterfaceBlock &out_block)
544 {
545         if(stage->interface_blocks.count("in"+out_block.name))
546                 return 0;
547
548         InterfaceBlock *in_block = new InterfaceBlock;
549         in_block->interface = "in";
550         in_block->name = out_block.name;
551         in_block->instance_name = out_block.instance_name;
552         if(stage->type==Stage::GEOMETRY)
553                 in_block->array = true;
554         else
555                 in_block->array = out_block.array;
556         in_block->linked_block = &out_block;
557         out_block.linked_block = in_block;
558
559         {
560                 SetFlag set_copy(copy_block, true);
561                 SetForScope<Block *> set_target(iface_target_block, &in_block->members);
562                 SetForScope<NodeList<Statement>::iterator> set_ins_pt(iface_insert_point, in_block->members.body.end());
563                 out_block.members.visit(*this);
564         }
565
566         iface_target_block->body.insert(iface_insert_point, in_block);
567         stage->interface_blocks.insert(make_pair("in"+in_block->name, in_block));
568         if(!in_block->instance_name.empty())
569                 stage->interface_blocks.insert(make_pair("_"+in_block->instance_name, in_block));
570
571         SetFlag set_scope(function_scope, false);
572         SetForScope<Block *> set_block(current_block, &stage->content);
573         in_block->visit(*this);
574
575         return in_block;
576 }
577
578 ExpressionStatement &InterfaceGenerator::insert_assignment(const string &left, Expression *right)
579 {
580         Assignment *assign = new Assignment;
581         VariableReference *ref = new VariableReference;
582         ref->name = left;
583         assign->left = ref;
584         assign->oper = &Operator::get_operator("=", Operator::BINARY);
585         assign->right = right;
586
587         ExpressionStatement *stmt = new ExpressionStatement;
588         stmt->expression = assign;
589         current_block->body.insert(assignment_insert_point, stmt);
590         stmt->visit(*this);
591
592         return *stmt;
593 }
594
595 void InterfaceGenerator::visit(VariableReference &var)
596 {
597         if(var.declaration || !stage->previous)
598                 return;
599         /* Don't pull a variable from previous stage if we just generated an output
600         interface in this stage */
601         if(stage->content.variables.count(var.name))
602                 return;
603
604         const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
605         map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
606         if(i==prev_vars.end() || i->second->interface!="out")
607                 i = prev_vars.find(in_prefix+var.name);
608         if(i!=prev_vars.end() && i->second->interface=="out")
609         {
610                 generate_interface(*i->second, "in", i->second->name);
611                 var.name = i->second->name;
612                 return;
613         }
614
615         const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
616         map<string, InterfaceBlock *>::const_iterator j = prev_blocks.find("_"+var.name);
617         if(j!=prev_blocks.end() && j->second->interface=="out")
618         {
619                 generate_interface(*j->second);
620                 /* Let VariableResolver convert the variable reference into an interface
621                 block reference. */
622                 return;
623         }
624
625         for(j=prev_blocks.begin(); j!=prev_blocks.end(); ++j)
626                 if(j->second->instance_name.empty())
627                 {
628                         i = j->second->members.variables.find(var.name);
629                         if(i!=j->second->members.variables.end())
630                         {
631                                 generate_interface(*j->second);
632                                 return;
633                         }
634                 }
635 }
636
637 void InterfaceGenerator::visit(VariableDeclaration &var)
638 {
639         if(copy_block)
640         {
641                 generate_interface(var, "in", var.name);
642                 return;
643         }
644
645         if(iface_block)
646         {
647                 if(iface_block->linked_block)
648                 {
649                         // Link all variables to their counterparts in the linked block.
650                         const map<string, VariableDeclaration *> &linked_vars = iface_block->linked_block->members.variables;
651                         map<string, VariableDeclaration *>::const_iterator i = linked_vars.find(var.name);
652                         if(i!=linked_vars.end())
653                         {
654                                 var.linked_declaration = i->second;
655                                 var.linked_declaration->linked_declaration = &var;
656                         }
657                 }
658                 return;
659         }
660
661         if(var.interface=="out")
662         {
663                 /* For output variables in function scope, generate a global interface
664                 and replace the local declaration with an assignment. */
665                 VariableDeclaration *out_var = 0;
666                 if(function_scope && (out_var=generate_interface(var, "out", var.name)))
667                 {
668                         out_var->source = var.source;
669                         out_var->line = var.line;
670                         nodes_to_remove.insert(&var);
671                         if(var.init_expression)
672                         {
673                                 ExpressionStatement &stmt = insert_assignment(var.name, var.init_expression->clone());
674                                 stmt.source = var.source;
675                                 stmt.line = var.line;
676                                 return;
677                         }
678                 }
679         }
680         else if(var.interface=="in")
681         {
682                 /* Try to link input variables in global scope with output variables from
683                 previous stage. */
684                 if(current_block==&stage->content && !var.linked_declaration && stage->previous)
685                 {
686                         const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
687                         map<string, VariableDeclaration *>::const_iterator i = prev_vars.find(var.name);
688                         if(i!=prev_vars.end() && i->second->interface=="out")
689                         {
690                                 var.linked_declaration = i->second;
691                                 i->second->linked_declaration = &var;
692                         }
693                 }
694         }
695
696         TraversingVisitor::visit(var);
697 }
698
699 void InterfaceGenerator::visit(InterfaceBlock &iface)
700 {
701         if(iface.interface=="in")
702         {
703                 /* Try to link input blocks with output blocks sharing the same block
704                 name from previous stage. */
705                 if(!iface.linked_block && stage->previous)
706                 {
707                         const map<string, InterfaceBlock *> &prev_blocks = stage->previous->interface_blocks;
708                         map<string, InterfaceBlock *>::const_iterator i = prev_blocks.find("out"+iface.name);
709                         if(i!=prev_blocks.end())
710                         {
711                                 iface.linked_block = i->second;
712                                 i->second->linked_block = &iface;
713                         }
714                 }
715         }
716
717         SetForScope<InterfaceBlock *> set_iface(iface_block, &iface);
718         TraversingVisitor::visit(iface);
719 }
720
721 void InterfaceGenerator::visit(FunctionDeclaration &func)
722 {
723         SetFlag set_scope(function_scope, true);
724         // Skip parameters because they're not useful here
725         func.body.visit(*this);
726 }
727
728 void InterfaceGenerator::visit(Passthrough &pass)
729 {
730         vector<VariableDeclaration *> pass_vars;
731
732         // Pass through all input variables of this stage.
733         for(map<string, VariableDeclaration *>::const_iterator i=stage->content.variables.begin(); i!=stage->content.variables.end(); ++i)
734                 if(i->second->interface=="in")
735                         pass_vars.push_back(i->second);
736
737         if(stage->previous)
738         {
739                 const map<string, VariableDeclaration *> &prev_vars = stage->previous->content.variables;
740                 for(map<string, VariableDeclaration *>::const_iterator i=prev_vars.begin(); i!=prev_vars.end(); ++i)
741                 {
742                         if(i->second->interface!="out")
743                                 continue;
744
745                         /* Pass through output variables from the previous stage, but only
746                         those which are not already linked to an input here. */
747                         if(!i->second->linked_declaration && generate_interface(*i->second, "in", i->second->name))
748                                 pass_vars.push_back(i->second);
749                 }
750         }
751
752         if(stage->type==Stage::GEOMETRY)
753         {
754                 /* Special case for geometry shader: copy gl_Position from input to
755                 output. */
756                 InterfaceBlockReference *ref = new InterfaceBlockReference;
757                 ref->name = "gl_in";
758
759                 BinaryExpression *subscript = new BinaryExpression;
760                 subscript->left = ref;
761                 subscript->oper = &Operator::get_operator("[", Operator::BINARY);
762                 subscript->right = pass.subscript;
763
764                 MemberAccess *memacc = new MemberAccess;
765                 memacc->left = subscript;
766                 memacc->member = "gl_Position";
767
768                 insert_assignment("gl_Position", memacc);
769         }
770
771         for(vector<VariableDeclaration *>::const_iterator i=pass_vars.begin(); i!=pass_vars.end(); ++i)
772         {
773                 string out_name = change_prefix((*i)->name, out_prefix);
774                 generate_interface(**i, "out", out_name);
775
776                 VariableReference *ref = new VariableReference;
777                 ref->name = (*i)->name;
778                 if(pass.subscript)
779                 {
780                         BinaryExpression *subscript = new BinaryExpression;
781                         subscript->left = ref;
782                         subscript->oper = &Operator::get_operator("[", Operator::BINARY);
783                         subscript->right = pass.subscript;
784                         insert_assignment(out_name, subscript);
785                 }
786                 else
787                         insert_assignment(out_name, ref);
788         }
789
790         nodes_to_remove.insert(&pass);
791 }
792
793 } // namespace SL
794 } // namespace GL
795 } // namespace Msp