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;
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(FunctionDeclaration &) { }
60 Converts the output depth range to match expectations of the target API.
62 class DepthRangeConverter: private TraversingVisitor
65 bool assignment_target = false;
66 bool r_gl_pervertex = false;
67 bool r_gl_position = false;
68 bool r_position_z_assigned = false;
71 void apply(Stage &, const Features &);
74 virtual void visit(VariableReference &);
75 virtual void visit(MemberAccess &);
76 virtual void visit(Swizzle &);
77 virtual void visit(Assignment &);
78 virtual void visit(FunctionDeclaration &);
81 /** Generates default precision declarations or removes precision declarations
82 according to the requirements of the target API. */
83 class PrecisionConverter: private TraversingVisitor
87 std::set<std::string> have_default;
88 NodeList<Statement>::iterator insert_point;
89 std::set<Node *> nodes_to_remove;
95 virtual void visit(Block &);
96 virtual void visit(Precision &);
97 virtual void visit(VariableDeclaration &);
100 /** Base class for feature converters. */
101 class FeatureConverter: protected TraversingVisitor
107 FeatureConverter() = default;
110 void apply(Stage &, const Features &);
112 virtual void apply() = 0;
114 void unsupported(const std::string &);
116 bool check_version(const Version &) const;
117 bool check_extension(bool Features::*) const;
120 /** Converts structures of the syntax tree to match a particular set of
122 class StructuralFeatureConverter: public FeatureConverter
125 VariableDeclaration *frag_out = 0;
126 NodeList<Statement>::iterator uniform_insert_point;
127 std::set<Node *> nodes_to_remove;
128 RefPtr<Expression> r_replaced_reference;
129 bool r_flattened_interface = false;
132 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
134 virtual void apply();
136 virtual void visit(Block &);
137 virtual void visit(RefPtr<Expression> &);
138 bool supports_stage(Stage::Type) const;
139 bool supports_unified_interface_syntax() const;
140 virtual void visit(VariableReference &);
141 virtual void visit(MemberAccess &);
142 virtual void visit(Assignment &);
143 bool supports_unified_sampling_functions() const;
144 virtual void visit(FunctionCall &);
145 bool supports_interface_blocks(const std::string &) const;
146 virtual void visit(VariableDeclaration &);
149 /** Converts qualifiers on variables and blocksto match a particular set of
151 class QualifierConverter: private FeatureConverter
154 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
156 virtual void apply();
158 bool supports_interface_layouts() const;
159 bool supports_stage_interface_layouts() const;
160 bool supports_centroid_sampling() const;
161 bool supports_sample_sampling() const;
162 bool supports_uniform_location() const;
163 bool supports_binding() const;
164 bool supports_interface_block_location() const;
165 virtual void visit(VariableDeclaration &);