1 #ifndef MSP_GL_MODULE_H_
2 #define MSP_GL_MODULE_H_
5 #include <msp/io/base.h>
8 #include "glsl/compiler.h"
9 #include "glsl/sourcemap.h"
14 class invalid_module: public std::runtime_error
17 invalid_module(const std::string &w): runtime_error(w) { }
18 virtual ~invalid_module() throw() { }
37 virtual Format get_format() const = 0;
39 void set_source(const std::string &);
40 void load_source(IO::Base &, Resources *, const std::string &);
41 void load_source(IO::Base &, const std::string &);
43 virtual void compile(SL::Compiler &) = 0;
46 class GlslModule: public Module
49 std::string prepared_source;
50 SL::SourceMap source_map;
53 virtual Format get_format() const { return GLSL; }
56 virtual void compile(SL::Compiler &);
59 const std::string &get_prepared_source() const { return prepared_source; }
60 const SL::SourceMap &get_source_map() const { return source_map; }
63 class SpirVModule: public Module
89 std::vector<const Variable *> globals;
98 const Structure *struct_type;
101 const Constant *array_size_spec;
102 unsigned array_stride;
103 unsigned matrix_stride;
111 std::vector<StructMember> members;
118 StorageClass storage;
120 const Structure *struct_type;
121 const Constant *array_size_spec;
129 bool operator==(const Variable &) const;
148 const Structure *struct_type;
149 const Constant *array_size_spec;
151 unsigned array_stride;
152 StorageClass storage;
159 typedef std::vector<UInt32>::const_iterator CodeIterator;
161 std::map<unsigned, std::string> names;
162 std::map<unsigned, Constant> constants;
163 std::map<unsigned, TypeInfo> types;
164 std::map<unsigned, EntryPoint> entry_points;
165 std::map<unsigned, Structure> structs;
166 std::map<unsigned, Variable> variables;
168 static UInt32 get_opcode(UInt32);
169 static CodeIterator get_op_end(const CodeIterator &);
170 static std::string read_string(CodeIterator &, const CodeIterator &);
172 void reflect_code(const std::vector<UInt32> &);
173 void reflect_name(CodeIterator);
174 void reflect_member_name(CodeIterator);
175 void reflect_entry_point(CodeIterator);
176 void reflect_void_type(CodeIterator);
177 void reflect_bool_type(CodeIterator);
178 void reflect_int_type(CodeIterator);
179 void reflect_float_type(CodeIterator);
180 void reflect_vector_type(CodeIterator);
181 void reflect_matrix_type(CodeIterator);
182 void reflect_image_type(CodeIterator);
183 void reflect_sampled_image_type(CodeIterator);
184 void reflect_array_type(CodeIterator);
185 void reflect_struct_type(CodeIterator);
186 void reflect_pointer_type(CodeIterator);
187 void reflect_constant(CodeIterator);
188 void reflect_variable(CodeIterator);
189 void reflect_decorate(CodeIterator);
190 void reflect_member_decorate(CodeIterator);
193 std::vector<UInt32> code;
194 std::vector<EntryPoint> entry_points;
195 std::vector<Structure> structs;
196 std::vector<Variable> variables;
197 std::vector<Constant> spec_constants;
201 SpirVModule(const SpirVModule &);
202 SpirVModule &operator=(const SpirVModule &);
204 void remap_pointers_from(const SpirVModule &);
207 virtual Format get_format() const { return SPIR_V; }
209 void load_code(IO::Base &);
211 virtual void compile(SL::Compiler &);
215 const std::vector<UInt32> &get_code() const { return code; }
216 const std::vector<EntryPoint> &get_entry_points() const { return entry_points; }
217 const std::vector<Variable> &get_variables() const { return variables; }
218 const std::vector<Constant> &get_spec_constants() const { return spec_constants; }