glsl: use enum glsl_interface_packing in more places. (v2)
[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 #pragma once
26 #ifndef GLSL_LINKER_H
27 #define GLSL_LINKER_H
28
29 extern bool
30 link_function_calls(gl_shader_program *prog, gl_shader *main,
31 gl_shader **shader_list, unsigned num_shaders);
32
33 extern void
34 link_invalidate_variable_locations(exec_list *ir);
35
36 extern void
37 link_assign_uniform_locations(struct gl_shader_program *prog,
38 unsigned int boolean_true,
39 unsigned int num_explicit_uniform_locs,
40 unsigned int max_uniform_locs);
41
42 extern void
43 link_set_uniform_initializers(struct gl_shader_program *prog,
44 unsigned int boolean_true);
45
46 extern int
47 link_cross_validate_uniform_block(void *mem_ctx,
48 struct gl_uniform_block **linked_blocks,
49 unsigned int *num_linked_blocks,
50 struct gl_uniform_block *new_block);
51
52 extern bool
53 link_uniform_blocks_are_compatible(const gl_uniform_block *a,
54 const gl_uniform_block *b);
55
56 extern void
57 link_uniform_blocks(void *mem_ctx,
58 struct gl_context *ctx,
59 struct gl_shader_program *prog,
60 struct gl_shader **shader_list,
61 unsigned num_shaders,
62 struct gl_uniform_block **ubo_blocks,
63 unsigned *num_ubo_blocks,
64 struct gl_uniform_block **ssbo_blocks,
65 unsigned *num_ssbo_blocks);
66
67 bool
68 validate_intrastage_arrays(struct gl_shader_program *prog,
69 ir_variable *const var,
70 ir_variable *const existing);
71
72 void
73 validate_intrastage_interface_blocks(struct gl_shader_program *prog,
74 const gl_shader **shader_list,
75 unsigned num_shaders);
76
77 void
78 validate_interstage_inout_blocks(struct gl_shader_program *prog,
79 const gl_shader *producer,
80 const gl_shader *consumer);
81
82 void
83 validate_interstage_uniform_blocks(struct gl_shader_program *prog,
84 gl_shader **stages, int num_stages);
85
86 extern void
87 link_assign_atomic_counter_resources(struct gl_context *ctx,
88 struct gl_shader_program *prog);
89
90 extern void
91 link_check_atomic_counter_resources(struct gl_context *ctx,
92 struct gl_shader_program *prog);
93
94 /**
95 * Class for processing all of the leaf fields of a variable that corresponds
96 * to a program resource.
97 *
98 * The leaf fields are all the parts of the variable that the application
99 * could query using \c glGetProgramResourceIndex (or that could be returned
100 * by \c glGetProgramResourceName).
101 *
102 * Classes my derive from this class to implement specific functionality.
103 * This class only provides the mechanism to iterate over the leaves. Derived
104 * classes must implement \c ::visit_field and may override \c ::process.
105 */
106 class program_resource_visitor {
107 public:
108 /**
109 * Begin processing a variable
110 *
111 * Classes that overload this function should call \c ::process from the
112 * base class to start the recursive processing of the variable.
113 *
114 * \param var The variable that is to be processed
115 *
116 * Calls \c ::visit_field for each leaf of the variable.
117 *
118 * \warning
119 * When processing a uniform block, this entry should only be used in cases
120 * where the row / column ordering of matrices in the block does not
121 * matter. For example, enumerating the names of members of the block, but
122 * not for determining the offsets of members.
123 */
124 void process(ir_variable *var);
125
126 /**
127 * Begin processing a variable of a structured type.
128 *
129 * This flavor of \c process should be used to handle structured types
130 * (i.e., structures, interfaces, or arrays there of) that need special
131 * name handling. A common usage is to handle cases where the block name
132 * (instead of the instance name) is used for an interface block.
133 *
134 * \param type Type that is to be processed, associated with \c name
135 * \param name Base name of the structured variable being processed
136 *
137 * \note
138 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
139 * there of.
140 */
141 void process(const glsl_type *type, const char *name);
142
143 protected:
144 /**
145 * Method invoked for each leaf of the variable
146 *
147 * \param type Type of the field.
148 * \param name Fully qualified name of the field.
149 * \param row_major For a matrix type, is it stored row-major.
150 * \param record_type Type of the record containing the field.
151 * \param last_field Set if \c name is the last field of the structure
152 * containing it. This will always be false for items
153 * not contained in a structure or interface block.
154 *
155 * The default implementation just calls the other \c visit_field method.
156 */
157 virtual void visit_field(const glsl_type *type, const char *name,
158 bool row_major, const glsl_type *record_type,
159 const enum glsl_interface_packing packing,
160 bool last_field);
161
162 /**
163 * Method invoked for each leaf of the variable
164 *
165 * \param type Type of the field.
166 * \param name Fully qualified name of the field.
167 * \param row_major For a matrix type, is it stored row-major.
168 */
169 virtual void visit_field(const glsl_type *type, const char *name,
170 bool row_major) = 0;
171
172 /**
173 * Visit a record before visiting its fields
174 *
175 * For structures-of-structures or interfaces-of-structures, this visits
176 * the inner structure before visiting its fields.
177 *
178 * The default implementation does nothing.
179 */
180 virtual void visit_field(const glsl_struct_field *field);
181
182 virtual void enter_record(const glsl_type *type, const char *name,
183 bool row_major, const enum glsl_interface_packing packing);
184
185 virtual void leave_record(const glsl_type *type, const char *name,
186 bool row_major, const enum glsl_interface_packing packing);
187
188 virtual void set_buffer_offset(unsigned offset);
189
190 virtual void set_record_array_count(unsigned record_array_count);
191
192 private:
193 /**
194 * \param name_length Length of the current name \b not including the
195 * terminating \c NUL character.
196 * \param last_field Set if \c name is the last field of the structure
197 * containing it. This will always be false for items
198 * not contained in a structure or interface block.
199 */
200 void recursion(const glsl_type *t, char **name, size_t name_length,
201 bool row_major, const glsl_type *record_type,
202 const enum glsl_interface_packing packing,
203 bool last_field, unsigned record_array_count,
204 const glsl_struct_field *named_ifc_member);
205 };
206
207 void
208 linker_error(gl_shader_program *prog, const char *fmt, ...);
209
210 void
211 linker_warning(gl_shader_program *prog, const char *fmt, ...);
212
213 /**
214 * Sometimes there are empty slots left over in UniformRemapTable after we
215 * allocate slots to explicit locations. This struct represents a single
216 * continouous block of empty slots in UniformRemapTable.
217 */
218 struct empty_uniform_block {
219 struct exec_node link;
220 /* The start location of the block */
221 unsigned start;
222 /* The number of slots in the block */
223 unsigned slots;
224 };
225
226 #endif /* GLSL_LINKER_H */