]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/spirvwriter.h
Add a SPIR-V backend to the GLSL compiler
[libs/gl.git] / source / glsl / spirvwriter.h
diff --git a/source/glsl/spirvwriter.h b/source/glsl/spirvwriter.h
new file mode 100644 (file)
index 0000000..94f44e8
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef MSP_GL_SL_SPIRVWRITER_H_
+#define MSP_GL_SL_SPIRVWRITER_H_
+
+#include <string>
+#include <vector>
+#include <msp/core/inttypes.h>
+#include "spirvconstants.h"
+
+namespace Msp {
+namespace GL {
+namespace SL {
+
+struct SpirVContent
+{
+       typedef UInt32 Word;
+
+       std::vector<Word> code;
+       std::vector<Word> capabilities;
+       std::vector<Word> extensions;
+       std::vector<Word> entry_points;
+       std::vector<Word> exec_modes;
+       std::vector<Word> names;
+       std::vector<Word> decorations;
+       std::vector<Word> globals;
+       std::vector<Word> functions;
+       std::vector<Word> locals;
+       std::vector<Word> function_body;
+};
+
+class SpirVWriter
+{
+public:
+       typedef SpirVOpcode Opcode;
+       typedef SpirVDecoration Decoration;
+       typedef SpirVContent::Word Word;
+       typedef Word Id;
+
+private:
+       SpirVContent &content;
+       std::vector<Word> *op_target;
+       unsigned op_head_pos;
+       Id current_block_id;
+
+public:
+       SpirVWriter(SpirVContent &);
+
+       void append(std::vector<Word> &, const std::vector<Word> &);
+       void write(Word);
+       void write_float(float);
+       void write_string(const std::string &);
+       void begin_op(std::vector<Word> &, Opcode, unsigned = 0);
+       void end_op(SpirVOpcode);
+       void write_op(std::vector<Word> &, Opcode);
+       void write_op(std::vector<Word> &, Opcode, Word);
+       void write_op(std::vector<Word> &, Opcode, Word, Word);
+       void write_op(std::vector<Word> &, Opcode, Word, Word, Word);
+       void write_op_name(Id, const std::string &);
+       void write_op_member_name(Id, unsigned, const std::string &);
+       void write_op_decorate(Id, Decoration);
+       void write_op_decorate(Id, Decoration, Word);
+       void write_op_member_decorate(Id, unsigned, Decoration);
+       void write_op_member_decorate(Id, unsigned, Decoration, Word);
+       void write_op_label(Id);
+       bool has_current_block() const { return current_block_id; }
+       void begin_function_body(Id);
+       void end_function_body();
+       void finalize(Id);
+};
+
+} // namespace SL
+} // namespace GL
+} // namespace Msp
+
+#endif