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<VariableDeclaration *> unbound_blocks;
46 /* Dirty hack to work around an issue where vertex attributes prevent the
47 flat qualifier from working on the same location. */
48 std::set<unsigned> used_vertex_attribs;
51 void apply(Module &, const Features &, bool = true);
55 void allocate_locations(const std::string &);
56 void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
58 bool visit_uniform(const std::string &, RefPtr<Layout> &);
59 virtual void visit(VariableDeclaration &);
60 virtual void visit(FunctionDeclaration &) { }
64 Converts the output depth range to match expectations of the target API.
66 class DepthRangeConverter: private TraversingVisitor
69 bool assignment_target = false;
70 bool r_gl_pervertex = false;
71 bool r_gl_position = false;
72 bool r_position_z_assigned = false;
75 void apply(Stage &, const Features &);
78 virtual void visit(VariableReference &);
79 virtual void visit(MemberAccess &);
80 virtual void visit(Swizzle &);
81 virtual void visit(Assignment &);
82 virtual void visit(FunctionDeclaration &);
85 /** Generates default precision declarations or removes precision declarations
86 according to the requirements of the target API. */
87 class PrecisionConverter: private TraversingVisitor
91 std::set<std::string> have_default;
92 NodeList<Statement>::iterator insert_point;
93 std::set<Node *> nodes_to_remove;
99 virtual void visit(Block &);
100 virtual void visit(Precision &);
101 virtual void visit(VariableDeclaration &);
104 /** Base class for feature converters. */
105 class FeatureConverter: protected TraversingVisitor
111 FeatureConverter() = default;
114 void apply(Stage &, const Features &);
116 virtual void apply() = 0;
118 void unsupported(const std::string &);
120 bool check_version(const Version &) const;
121 bool check_extension(bool Features::*) const;
124 /** Converts structures of the syntax tree to match a particular set of
126 class StructuralFeatureConverter: public FeatureConverter
129 VariableDeclaration *frag_out = 0;
130 NodeList<Statement>::iterator uniform_insert_point;
131 std::set<Node *> nodes_to_remove;
132 RefPtr<Expression> r_replaced_reference;
133 bool r_flattened_interface = false;
136 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
138 virtual void apply();
140 virtual void visit(Block &);
141 virtual void visit(RefPtr<Expression> &);
142 bool supports_stage(Stage::Type) const;
143 bool supports_unified_interface_syntax() const;
144 virtual void visit(VariableReference &);
145 virtual void visit(MemberAccess &);
146 virtual void visit(Assignment &);
147 bool supports_unified_sampling_functions() const;
148 virtual void visit(FunctionCall &);
149 bool supports_interface_blocks(const std::string &) const;
150 virtual void visit(VariableDeclaration &);
153 /** Converts qualifiers on variables and blocksto match a particular set of
155 class QualifierConverter: private FeatureConverter
158 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
160 virtual void apply();
162 bool supports_interface_layouts() const;
163 bool supports_stage_interface_layouts() const;
164 bool supports_centroid_sampling() const;
165 bool supports_sample_sampling() const;
166 bool supports_uniform_location() const;
167 bool supports_binding() const;
168 bool supports_interface_block_location() const;
169 virtual void visit(VariableDeclaration &);