]> git.tdb.fi Git - libs/gl.git/blob - source/glsl/generate.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / glsl / generate.h
1 #ifndef MSP_GL_SL_GENERATE_H_
2 #define MSP_GL_SL_GENERATE_H_
3
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <vector>
8 #include "visitor.h"
9
10 namespace Msp {
11 namespace GL {
12 namespace SL {
13
14 /** Assigns IDs to specialization constants with an automatic ID. */
15 class ConstantIdAssigner: private TraversingVisitor
16 {
17 private:
18         std::set<unsigned> used_ids;
19         std::map<std::string, unsigned> existing_constants;
20         std::vector<VariableDeclaration *> auto_constants;
21
22 public:
23         void apply(Module &, const Features &);
24
25 private:
26         virtual void visit(VariableDeclaration &);
27 };
28
29 /** Materializes implicitly declared interfaces.
30
31 Out variable declarations inside functions are moved to the global scope.
32
33 Passthrough statements are processed, generating out variables to match in
34 variables and copying values.
35
36 Unresolved variables are looked up in the previous stage's out variables. */
37 class InterfaceGenerator: private TraversingVisitor
38 {
39 private:
40         Stage *stage = 0;
41         std::string in_prefix;
42         std::string out_prefix;
43         bool function_scope = false;
44         bool copy_block = false;
45         std::vector<VariableDeclaration *> declared_inputs;
46         Block *iface_target_block = 0;
47         NodeList<Statement>::iterator iface_insert_point;
48         NodeList<Statement>::iterator assignment_insert_point;
49         std::set<Node *> nodes_to_remove;
50
51 public:
52         void apply(Stage &);
53
54 private:
55         static std::string get_out_prefix(Stage::Type);
56         std::string change_prefix(const std::string &, const std::string &) const;
57         virtual void visit(Block &);
58         VariableDeclaration *generate_interface(VariableDeclaration &, const std::string &, const std::string &);
59         ExpressionStatement &insert_assignment(const std::string &, Expression *);
60         virtual void visit(VariableReference &);
61         virtual void visit(VariableDeclaration &);
62         virtual void visit(FunctionDeclaration &);
63         virtual void visit(Passthrough &);
64 };
65
66 /**
67 Assigns sizes to arrays which don't have a size.  Geometry shader inputs are
68 sized by topology.  Other arrays are sized by their use with literal indices.
69 */
70 class ArraySizer: private TraversingVisitor
71 {
72 private:
73         std::map<VariableDeclaration *, int> max_indices;
74         unsigned input_size = 0;
75         VariableDeclaration *r_declaration;
76
77 public:
78         void apply(Stage &);
79
80 private:
81         virtual void visit(VariableReference &);
82         virtual void visit(MemberAccess &);
83         virtual void visit(Swizzle &);
84         virtual void visit(UnaryExpression&);
85         virtual void visit(BinaryExpression &);
86         virtual void visit(TernaryExpression &);
87         virtual void visit(FunctionCall &);
88         virtual void visit(InterfaceLayout &);
89         virtual void visit(VariableDeclaration &);
90 };
91
92 } // namespace SL
93 } // namespace GL
94 } // namespace Msp
95
96 #endif