1 #ifndef MSP_GL_MODULE_H_
2 #define MSP_GL_MODULE_H_
7 #include <msp/io/base.h>
9 #include "glsl/compiler.h"
10 #include "glsl/sourcemap.h"
15 class invalid_module: public std::runtime_error
18 invalid_module(const std::string &w): runtime_error(w) { }
19 virtual ~invalid_module() throw() { }
38 virtual Format get_format() const = 0;
40 void set_source(const std::string &);
41 void load_source(IO::Base &, Resources *, const std::string &);
42 void load_source(IO::Base &, const std::string &);
44 virtual void compile(SL::Compiler &) = 0;
47 class GlslModule: public Module
50 std::string prepared_source;
51 SL::SourceMap source_map;
54 virtual Format get_format() const { return GLSL; }
57 virtual void compile(SL::Compiler &);
60 const std::string &get_prepared_source() const { return prepared_source; }
61 const SL::SourceMap &get_source_map() const { return source_map; }
64 class SpirVModule: public Module
90 std::vector<const Variable *> globals;
99 const Structure *struct_type;
102 const Constant *array_size_spec;
103 unsigned array_stride;
104 unsigned matrix_stride;
112 std::vector<StructMember> members;
119 StorageClass storage;
121 const Structure *struct_type;
122 const Constant *array_size_spec;
130 bool operator==(const Variable &) const;
149 const Structure *struct_type;
150 const Constant *array_size_spec;
152 unsigned array_stride;
153 StorageClass storage;
160 typedef std::vector<std::uint32_t>::const_iterator CodeIterator;
162 std::map<unsigned, std::string> names;
163 std::map<unsigned, Constant> constants;
164 std::map<unsigned, TypeInfo> types;
165 std::map<unsigned, EntryPoint> entry_points;
166 std::map<unsigned, Structure> structs;
167 std::map<unsigned, Variable> variables;
169 static std::uint32_t get_opcode(std::uint32_t);
170 static CodeIterator get_op_end(const CodeIterator &);
171 static std::string read_string(CodeIterator &, const CodeIterator &);
173 void reflect_code(const std::vector<std::uint32_t> &);
174 void reflect_name(CodeIterator);
175 void reflect_member_name(CodeIterator);
176 void reflect_entry_point(CodeIterator);
177 void reflect_void_type(CodeIterator);
178 void reflect_bool_type(CodeIterator);
179 void reflect_int_type(CodeIterator);
180 void reflect_float_type(CodeIterator);
181 void reflect_vector_type(CodeIterator);
182 void reflect_matrix_type(CodeIterator);
183 void reflect_image_type(CodeIterator);
184 void reflect_sampled_image_type(CodeIterator);
185 void reflect_array_type(CodeIterator);
186 void reflect_struct_type(CodeIterator);
187 void reflect_pointer_type(CodeIterator);
188 void reflect_constant(CodeIterator);
189 void reflect_variable(CodeIterator);
190 void reflect_decorate(CodeIterator);
191 void reflect_member_decorate(CodeIterator);
194 std::vector<std::uint32_t> code;
195 std::vector<EntryPoint> entry_points;
196 std::vector<Structure> structs;
197 std::vector<Variable> variables;
198 std::vector<Constant> spec_constants;
202 SpirVModule(const SpirVModule &);
203 SpirVModule &operator=(const SpirVModule &);
205 void remap_pointers_from(const SpirVModule &);
208 virtual Format get_format() const { return SPIR_V; }
210 void load_code(IO::Base &);
212 virtual void compile(SL::Compiler &);
216 const std::vector<std::uint32_t> &get_code() const { return code; }
217 const std::vector<EntryPoint> &get_entry_points() const { return entry_points; }
218 const std::vector<Variable> &get_variables() const { return variables; }
219 const std::vector<Constant> &get_spec_constants() const { return spec_constants; }