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;
132 unsigned constant_id;
140 const Structure *struct_type;
142 unsigned array_stride;
143 StorageClass storage;
150 typedef std::vector<UInt32>::const_iterator CodeIterator;
152 std::map<unsigned, std::string> names;
153 std::map<unsigned, Variant> constants;
154 std::map<unsigned, TypeInfo> types;
155 std::map<unsigned, EntryPoint> entry_points;
156 std::map<unsigned, Structure> structs;
157 std::map<unsigned, Variable> variables;
158 std::map<unsigned, SpecConstant> spec_constants;
160 static UInt32 get_opcode(UInt32);
161 static CodeIterator get_op_end(const CodeIterator &);
162 static std::string read_string(CodeIterator &, const CodeIterator &);
164 void reflect_code(const std::vector<UInt32> &);
165 void reflect_name(CodeIterator);
166 void reflect_member_name(CodeIterator);
167 void reflect_entry_point(CodeIterator);
168 void reflect_void_type(CodeIterator);
169 void reflect_bool_type(CodeIterator);
170 void reflect_int_type(CodeIterator);
171 void reflect_float_type(CodeIterator);
172 void reflect_vector_type(CodeIterator);
173 void reflect_matrix_type(CodeIterator);
174 void reflect_image_type(CodeIterator);
175 void reflect_sampled_image_type(CodeIterator);
176 void reflect_array_type(CodeIterator);
177 void reflect_struct_type(CodeIterator);
178 void reflect_pointer_type(CodeIterator);
179 void reflect_constant(CodeIterator);
180 void reflect_spec_constant_bool(CodeIterator);
181 void reflect_spec_constant(CodeIterator);
182 void reflect_variable(CodeIterator);
183 void reflect_decorate(CodeIterator);
184 void reflect_member_decorate(CodeIterator);
187 std::vector<UInt32> code;
188 std::vector<EntryPoint> entry_points;
189 std::vector<Structure> structs;
190 std::vector<Variable> variables;
191 std::vector<SpecConstant> spec_constants;
195 SpirVModule(const SpirVModule &);
196 SpirVModule &operator=(const SpirVModule &);
198 void remap_pointers_from(const SpirVModule &);
201 virtual Format get_format() const { return SPIR_V; }
203 void load_code(IO::Base &);
205 virtual void compile(SL::Compiler &);
208 const std::vector<UInt32> &get_code() const { return code; }
209 const std::vector<EntryPoint> &get_entry_points() const { return entry_points; }
210 const std::vector<Variable> &get_variables() const { return variables; }
211 const std::vector<SpecConstant> &get_spec_constants() const { return spec_constants; }