1 #ifndef MSP_GL_SL_FINALIZE_H_
2 #define MSP_GL_SL_FINALIZE_H_
11 /** Assigns offset layout qualifiers to struct members. */
12 class StructOrganizer: private TraversingVisitor
18 void apply(Stage &s) { s.content.visit(*this); }
21 virtual void visit(StructDeclaration &);
22 virtual void visit(VariableDeclaration &);
25 /** Assigns location and binding layout qualifiers to interface variables and
27 class LocationAllocator: private TraversingVisitor
38 bool alloc_new = true;
39 std::map<std::string, std::set<unsigned> > used_locations;
40 std::map<std::string, Uniform> uniforms;
41 std::map<unsigned, std::set<unsigned> > used_bindings;
42 std::vector<VariableDeclaration *> unplaced_variables;
43 std::vector<VariableDeclaration *> unbound_textures;
44 std::vector<InterfaceBlock *> unbound_blocks;
47 void apply(Module &, const Features &, bool = true);
51 void allocate_locations(const std::string &);
52 void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
54 bool visit_uniform(const std::string &, RefPtr<Layout> &);
55 virtual void visit(VariableDeclaration &);
56 virtual void visit(InterfaceBlock &);
57 virtual void visit(FunctionDeclaration &) { }
60 /** Generates default precision declarations or removes precision declarations
61 according to the requirements of the target API. */
62 class PrecisionConverter: private TraversingVisitor
66 std::set<std::string> have_default;
67 NodeList<Statement>::iterator insert_point;
68 std::set<Node *> nodes_to_remove;
74 virtual void visit(Block &);
75 virtual void visit(Precision &);
76 virtual void visit(VariableDeclaration &);
79 /** Base class for feature converters. */
80 class FeatureConverter: protected TraversingVisitor
86 FeatureConverter() = default;
89 void apply(Stage &, const Features &);
91 virtual void apply() = 0;
93 void unsupported(const std::string &);
95 bool check_version(const Version &) const;
96 bool check_extension(bool Features::*) const;
99 /** Converts structures of the syntax tree to match a particular set of
101 class StructuralFeatureConverter: public FeatureConverter
104 VariableDeclaration *frag_out = 0;
105 NodeList<Statement>::iterator uniform_insert_point;
106 std::set<Node *> nodes_to_remove;
107 RefPtr<Expression> r_replaced_reference;
108 bool r_flattened_interface = false;
111 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
113 virtual void apply();
115 virtual void visit(Block &);
116 virtual void visit(RefPtr<Expression> &);
117 bool supports_stage(Stage::Type) const;
118 bool supports_unified_interface_syntax() const;
119 virtual void visit(VariableReference &);
120 virtual void visit(InterfaceBlockReference &);
121 virtual void visit(MemberAccess &);
122 virtual void visit(Assignment &);
123 bool supports_unified_sampling_functions() const;
124 virtual void visit(FunctionCall &);
125 virtual void visit(VariableDeclaration &);
126 bool supports_interface_blocks(const std::string &) const;
127 virtual void visit(InterfaceBlock &);
130 /** Converts qualifiers on variables and blocksto match a particular set of
132 class QualifierConverter: private FeatureConverter
135 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
137 virtual void apply();
139 bool supports_interface_layouts() const;
140 bool supports_stage_interface_layouts() const;
141 bool supports_centroid_sampling() const;
142 bool supports_sample_sampling() const;
143 bool supports_uniform_location() const;
144 bool supports_binding() const;
145 virtual void visit(VariableDeclaration &);
146 bool supports_interface_block_location() const;
147 virtual void visit(InterfaceBlock &);