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
36 Uniform(): location(-1), desc_set(-1), bind_point(-1) { }
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 &);
51 void allocate_locations(const std::string &);
52 void bind_uniform(RefPtr<Layout> &, const std::string &, unsigned);
53 void add_layout_value(RefPtr<Layout> &, const std::string &, unsigned);
55 bool visit_uniform(const std::string &, RefPtr<Layout> &);
56 virtual void visit(VariableDeclaration &);
57 virtual void visit(InterfaceBlock &);
58 virtual void visit(FunctionDeclaration &) { }
61 /** Generates default precision declarations or removes precision declarations
62 according to the requirements of the target API. */
63 class PrecisionConverter: private TraversingVisitor
67 std::set<std::string> have_default;
68 NodeList<Statement>::iterator insert_point;
69 std::set<Node *> nodes_to_remove;
75 virtual void visit(Block &);
76 virtual void visit(Precision &);
77 virtual void visit(VariableDeclaration &);
80 /** Base class for feature converters. */
81 class FeatureConverter: protected TraversingVisitor
87 FeatureConverter() = default;
90 void apply(Stage &, const Features &);
92 virtual void apply() = 0;
94 void unsupported(const std::string &);
96 bool check_version(const Version &) const;
97 bool check_extension(bool Features::*) const;
100 /** Converts structures of the syntax tree to match a particular set of
102 class StructuralFeatureConverter: public FeatureConverter
105 VariableDeclaration *frag_out = 0;
106 NodeList<Statement>::iterator uniform_insert_point;
107 std::set<Node *> nodes_to_remove;
108 RefPtr<Expression> r_replaced_reference;
109 bool r_flattened_interface = false;
112 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
114 virtual void apply();
116 virtual void visit(Block &);
117 virtual void visit(RefPtr<Expression> &);
118 bool supports_stage(Stage::Type) const;
119 bool supports_unified_interface_syntax() const;
120 virtual void visit(VariableReference &);
121 virtual void visit(InterfaceBlockReference &);
122 virtual void visit(MemberAccess &);
123 virtual void visit(Assignment &);
124 bool supports_unified_sampling_functions() const;
125 virtual void visit(FunctionCall &);
126 virtual void visit(VariableDeclaration &);
127 bool supports_interface_blocks(const std::string &) const;
128 virtual void visit(InterfaceBlock &);
131 /** Converts qualifiers on variables and blocksto match a particular set of
133 class QualifierConverter: private FeatureConverter
136 void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); }
138 virtual void apply();
140 bool supports_interface_layouts() const;
141 bool supports_stage_interface_layouts() const;
142 bool supports_centroid_sampling() const;
143 bool supports_sample_sampling() const;
144 bool supports_uniform_location() const;
145 bool supports_binding() const;
146 virtual void visit(VariableDeclaration &);
147 bool supports_interface_block_location() const;
148 virtual void visit(InterfaceBlock &);