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
88 std::vector<const Variable *> globals;
97 const Structure *struct_type;
100 unsigned array_stride;
101 unsigned matrix_stride;
109 std::vector<StructMember> members;
116 StorageClass storage;
118 const Structure *struct_type;
126 bool operator==(const Variable &) const;
145 const Structure *struct_type;
147 unsigned array_stride;
148 StorageClass storage;
155 typedef std::vector<UInt32>::const_iterator CodeIterator;
157 std::map<unsigned, std::string> names;
158 std::map<unsigned, Constant> constants;
159 std::map<unsigned, TypeInfo> types;
160 std::map<unsigned, EntryPoint> entry_points;
161 std::map<unsigned, Structure> structs;
162 std::map<unsigned, Variable> variables;
164 static UInt32 get_opcode(UInt32);
165 static CodeIterator get_op_end(const CodeIterator &);
166 static std::string read_string(CodeIterator &, const CodeIterator &);
168 void reflect_code(const std::vector<UInt32> &);
169 void reflect_name(CodeIterator);
170 void reflect_member_name(CodeIterator);
171 void reflect_entry_point(CodeIterator);
172 void reflect_void_type(CodeIterator);
173 void reflect_bool_type(CodeIterator);
174 void reflect_int_type(CodeIterator);
175 void reflect_float_type(CodeIterator);
176 void reflect_vector_type(CodeIterator);
177 void reflect_matrix_type(CodeIterator);
178 void reflect_image_type(CodeIterator);
179 void reflect_sampled_image_type(CodeIterator);
180 void reflect_array_type(CodeIterator);
181 void reflect_struct_type(CodeIterator);
182 void reflect_pointer_type(CodeIterator);
183 void reflect_constant(CodeIterator);
184 void reflect_variable(CodeIterator);
185 void reflect_decorate(CodeIterator);
186 void reflect_member_decorate(CodeIterator);
189 std::vector<UInt32> code;
190 std::vector<EntryPoint> entry_points;
191 std::vector<Structure> structs;
192 std::vector<Variable> variables;
193 std::vector<Constant> spec_constants;
197 SpirVModule(const SpirVModule &);
198 SpirVModule &operator=(const SpirVModule &);
200 void remap_pointers_from(const SpirVModule &);
203 virtual Format get_format() const { return SPIR_V; }
205 void load_code(IO::Base &);
207 virtual void compile(SL::Compiler &);
211 const std::vector<UInt32> &get_code() const { return code; }
212 const std::vector<EntryPoint> &get_entry_points() const { return entry_points; }
213 const std::vector<Variable> &get_variables() const { return variables; }
214 const std::vector<Constant> &get_spec_constants() const { return spec_constants; }