1 #ifndef MSP_GL_PROGRAM_H_
2 #define MSP_GL_PROGRAM_H_
6 #include <msp/datafile/objectloader.h>
11 #include "vertexformat.h"
17 A complete shader program. Programs can be assembled of individual Shaders or
18 generated with a set of standard features.
22 friend class PipelineState;
25 class Loader: public DataFile::CollectionObjectLoader<Program>
28 Loader(Program &, Collection &);
31 virtual void finish();
33 void module(const std::string &);
37 class SpecializationLoader: public DataFile::Loader
40 std::map<std::string, int> &spec_values;
42 static ActionMap shared_actions;
45 SpecializationLoader(std::map<std::string, int> &);
48 virtual void init_actions();
50 void specialize_bool(const std::string &, bool);
51 void specialize_int(const std::string &, int);
55 typedef unsigned LayoutHash;
56 struct UniformBlockInfo;
61 const UniformBlockInfo *block;
68 unsigned array_stride;
69 unsigned matrix_stride;
77 struct UniformBlockInfo
82 std::vector<const UniformInfo *> uniforms;
83 LayoutHash layout_hash;
109 std::map<std::string, unsigned> textures;
110 std::map<std::string, unsigned> blocks;
111 std::map<unsigned, int> spec_values;
115 unsigned stage_ids[MAX_STAGES];
116 const Module *module;
117 TransientData *transient;
119 std::vector<UniformBlockInfo> uniform_blocks;
120 std::vector<UniformInfo> uniforms;
121 LayoutHash uniform_layout_hash;
122 std::vector<AttributeInfo> attributes;
123 std::string debug_name;
126 /// Constructs an empty Program with no shader stages attached.
129 /// Constructs a Program from a Module, with specialization constants.
130 Program(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
137 void add_stages(const Module &, const std::map<std::string, int> & = std::map<std::string, int>());
139 bool has_stages() const;
140 unsigned add_stage(Stage);
141 void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
142 void compile_glsl_stage(unsigned);
143 void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
148 void query_uniforms();
149 void query_uniform_blocks(const std::vector<UniformInfo *> &);
150 void query_attributes();
151 void collect_uniforms();
152 void collect_block_uniforms(const SpirVModule::Structure &, const std::string &, unsigned, std::vector<std::string> &);
153 void collect_attributes();
154 void update_layout_hash();
155 static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
156 static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
158 bool is_linked() const { return linked; }
160 LayoutHash get_uniform_layout_hash() const { return uniform_layout_hash; }
161 const std::vector<UniformBlockInfo> &get_uniform_blocks() const { return uniform_blocks; }
162 const UniformBlockInfo &get_uniform_block_info(const std::string &) const;
163 const std::vector<UniformInfo> &get_uniforms() const { return uniforms; }
164 const UniformInfo &get_uniform_info(const std::string &) const;
165 const UniformInfo &get_uniform_info(Tag) const;
166 int get_uniform_location(const std::string &) const;
167 int get_uniform_location(Tag) const;
168 int get_uniform_binding(Tag) const;
169 const std::vector<AttributeInfo> &get_attributes() const { return attributes; }
170 const AttributeInfo &get_attribute_info(const std::string &) const;
171 int get_attribute_location(const std::string &) const;
173 void set_debug_name(const std::string &);
175 void set_stage_debug_name(unsigned, Stage);