mesa: include mtypes.h less
[mesa.git] / src / compiler / glsl / linker.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2010 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef GLSL_LINKER_H
26 #define GLSL_LINKER_H
27
28 struct gl_shader_program;
29 struct gl_shader;
30 struct gl_linked_shader;
31
32 extern bool
33 link_function_calls(gl_shader_program *prog, gl_linked_shader *main,
34 gl_shader **shader_list, unsigned num_shaders);
35
36 extern void
37 link_invalidate_variable_locations(exec_list *ir);
38
39 extern void
40 link_assign_uniform_locations(struct gl_shader_program *prog,
41 struct gl_context *ctx);
42
43 extern void
44 link_set_uniform_initializers(struct gl_shader_program *prog,
45 unsigned int boolean_true);
46
47 extern int
48 link_cross_validate_uniform_block(void *mem_ctx,
49 struct gl_uniform_block **linked_blocks,
50 unsigned int *num_linked_blocks,
51 struct gl_uniform_block *new_block);
52
53 extern void
54 link_uniform_blocks(void *mem_ctx,
55 struct gl_context *ctx,
56 struct gl_shader_program *prog,
57 struct gl_linked_shader *shader,
58 struct gl_uniform_block **ubo_blocks,
59 unsigned *num_ubo_blocks,
60 struct gl_uniform_block **ssbo_blocks,
61 unsigned *num_ssbo_blocks);
62
63 bool
64 validate_intrastage_arrays(struct gl_shader_program *prog,
65 ir_variable *const var,
66 ir_variable *const existing);
67
68 void
69 validate_intrastage_interface_blocks(struct gl_shader_program *prog,
70 const gl_shader **shader_list,
71 unsigned num_shaders);
72
73 void
74 validate_interstage_inout_blocks(struct gl_shader_program *prog,
75 const gl_linked_shader *producer,
76 const gl_linked_shader *consumer);
77
78 void
79 validate_interstage_uniform_blocks(struct gl_shader_program *prog,
80 gl_linked_shader **stages);
81
82 extern void
83 link_assign_atomic_counter_resources(struct gl_context *ctx,
84 struct gl_shader_program *prog);
85
86 extern void
87 link_check_atomic_counter_resources(struct gl_context *ctx,
88 struct gl_shader_program *prog);
89
90
91 extern struct gl_linked_shader *
92 link_intrastage_shaders(void *mem_ctx,
93 struct gl_context *ctx,
94 struct gl_shader_program *prog,
95 struct gl_shader **shader_list,
96 unsigned num_shaders,
97 bool allow_missing_main);
98
99 extern unsigned
100 link_calculate_matrix_stride(const glsl_type *matrix, bool row_major,
101 enum glsl_interface_packing packing);
102
103 /**
104 * Class for processing all of the leaf fields of a variable that corresponds
105 * to a program resource.
106 *
107 * The leaf fields are all the parts of the variable that the application
108 * could query using \c glGetProgramResourceIndex (or that could be returned
109 * by \c glGetProgramResourceName).
110 *
111 * Classes my derive from this class to implement specific functionality.
112 * This class only provides the mechanism to iterate over the leaves. Derived
113 * classes must implement \c ::visit_field and may override \c ::process.
114 */
115 class program_resource_visitor {
116 public:
117 /**
118 * Begin processing a variable
119 *
120 * Classes that overload this function should call \c ::process from the
121 * base class to start the recursive processing of the variable.
122 *
123 * \param var The variable that is to be processed
124 *
125 * Calls \c ::visit_field for each leaf of the variable.
126 *
127 * \warning
128 * When processing a uniform block, this entry should only be used in cases
129 * where the row / column ordering of matrices in the block does not
130 * matter. For example, enumerating the names of members of the block, but
131 * not for determining the offsets of members.
132 */
133 void process(ir_variable *var, bool use_std430_as_default);
134
135 /**
136 * Begin processing a variable of a structured type.
137 *
138 * This flavor of \c process should be used to handle structured types
139 * (i.e., structures, interfaces, or arrays there of) that need special
140 * name handling. A common usage is to handle cases where the block name
141 * (instead of the instance name) is used for an interface block.
142 *
143 * \param type Type that is to be processed, associated with \c name
144 * \param name Base name of the structured variable being processed
145 *
146 * \note
147 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
148 * there of.
149 */
150 void process(const glsl_type *type, const char *name,
151 bool use_std430_as_default);
152
153 protected:
154 /**
155 * Method invoked for each leaf of the variable
156 *
157 * \param type Type of the field.
158 * \param name Fully qualified name of the field.
159 * \param row_major For a matrix type, is it stored row-major.
160 * \param record_type Type of the record containing the field.
161 * \param last_field Set if \c name is the last field of the structure
162 * containing it. This will always be false for items
163 * not contained in a structure or interface block.
164 */
165 virtual void visit_field(const glsl_type *type, const char *name,
166 bool row_major, const glsl_type *record_type,
167 const enum glsl_interface_packing packing,
168 bool last_field) = 0;
169
170 virtual void enter_record(const glsl_type *type, const char *name,
171 bool row_major, const enum glsl_interface_packing packing);
172
173 virtual void leave_record(const glsl_type *type, const char *name,
174 bool row_major, const enum glsl_interface_packing packing);
175
176 virtual void set_buffer_offset(unsigned offset);
177
178 virtual void set_record_array_count(unsigned record_array_count);
179
180 private:
181 /**
182 * \param name_length Length of the current name \b not including the
183 * terminating \c NUL character.
184 * \param last_field Set if \c name is the last field of the structure
185 * containing it. This will always be false for items
186 * not contained in a structure or interface block.
187 */
188 void recursion(const glsl_type *t, char **name, size_t name_length,
189 bool row_major, const glsl_type *record_type,
190 const enum glsl_interface_packing packing,
191 bool last_field, unsigned record_array_count,
192 const glsl_struct_field *named_ifc_member);
193 };
194
195 void
196 linker_error(gl_shader_program *prog, const char *fmt, ...);
197
198 void
199 linker_warning(gl_shader_program *prog, const char *fmt, ...);
200
201 /**
202 * Sometimes there are empty slots left over in UniformRemapTable after we
203 * allocate slots to explicit locations. This struct represents a single
204 * continouous block of empty slots in UniformRemapTable.
205 */
206 struct empty_uniform_block {
207 struct exec_node link;
208 /* The start location of the block */
209 unsigned start;
210 /* The number of slots in the block */
211 unsigned slots;
212 };
213
214 #endif /* GLSL_LINKER_H */