glsl: move uniform calculation to link_uniforms
[mesa.git] / src / 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 max_locations);
40
41 extern void
42 link_set_uniform_initializers(struct gl_shader_program *prog,
43 unsigned int boolean_true);
44
45 extern int
46 link_cross_validate_uniform_block(void *mem_ctx,
47 struct gl_uniform_block **linked_blocks,
48 unsigned int *num_linked_blocks,
49 struct gl_uniform_block *new_block);
50
51 extern bool
52 link_uniform_blocks_are_compatible(const gl_uniform_block *a,
53 const gl_uniform_block *b);
54
55 extern unsigned
56 link_uniform_blocks(void *mem_ctx,
57 struct gl_context *ctx,
58 struct gl_shader_program *prog,
59 struct gl_shader **shader_list,
60 unsigned num_shaders,
61 struct gl_uniform_block **blocks_ret);
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_shader *producer,
76 const gl_shader *consumer);
77
78 void
79 validate_interstage_uniform_blocks(struct gl_shader_program *prog,
80 gl_shader **stages, int num_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 * Class for processing all of the leaf fields of a variable that corresponds
92 * to a program resource.
93 *
94 * The leaf fields are all the parts of the variable that the application
95 * could query using \c glGetProgramResourceIndex (or that could be returned
96 * by \c glGetProgramResourceName).
97 *
98 * Classes my derive from this class to implement specific functionality.
99 * This class only provides the mechanism to iterate over the leaves. Derived
100 * classes must implement \c ::visit_field and may override \c ::process.
101 */
102 class program_resource_visitor {
103 public:
104 /**
105 * Begin processing a variable
106 *
107 * Classes that overload this function should call \c ::process from the
108 * base class to start the recursive processing of the variable.
109 *
110 * \param var The variable that is to be processed
111 *
112 * Calls \c ::visit_field for each leaf of the variable.
113 *
114 * \warning
115 * When processing a uniform block, this entry should only be used in cases
116 * where the row / column ordering of matrices in the block does not
117 * matter. For example, enumerating the names of members of the block, but
118 * not for determining the offsets of members.
119 */
120 void process(ir_variable *var);
121
122 /**
123 * Begin processing a variable of a structured type.
124 *
125 * This flavor of \c process should be used to handle structured types
126 * (i.e., structures, interfaces, or arrays there of) that need special
127 * name handling. A common usage is to handle cases where the block name
128 * (instead of the instance name) is used for an interface block.
129 *
130 * \param type Type that is to be processed, associated with \c name
131 * \param name Base name of the structured variable being processed
132 *
133 * \note
134 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
135 * there of.
136 */
137 void process(const glsl_type *type, const char *name);
138
139 protected:
140 /**
141 * Method invoked for each leaf of the variable
142 *
143 * \param type Type of the field.
144 * \param name Fully qualified name of the field.
145 * \param row_major For a matrix type, is it stored row-major.
146 * \param record_type Type of the record containing the field.
147 * \param last_field Set if \c name is the last field of the structure
148 * containing it. This will always be false for items
149 * not contained in a structure or interface block.
150 *
151 * The default implementation just calls the other \c visit_field method.
152 */
153 virtual void visit_field(const glsl_type *type, const char *name,
154 bool row_major, const glsl_type *record_type,
155 const unsigned packing,
156 bool last_field);
157
158 /**
159 * Method invoked for each leaf of the variable
160 *
161 * \param type Type of the field.
162 * \param name Fully qualified name of the field.
163 * \param row_major For a matrix type, is it stored row-major.
164 */
165 virtual void visit_field(const glsl_type *type, const char *name,
166 bool row_major) = 0;
167
168 /**
169 * Visit a record before visiting its fields
170 *
171 * For structures-of-structures or interfaces-of-structures, this visits
172 * the inner structure before visiting its fields.
173 *
174 * The default implementation does nothing.
175 */
176 virtual void visit_field(const glsl_struct_field *field);
177
178 virtual void enter_record(const glsl_type *type, const char *name,
179 bool row_major, const unsigned packing);
180
181 virtual void leave_record(const glsl_type *type, const char *name,
182 bool row_major, const unsigned packing);
183
184 virtual void set_record_array_count(unsigned record_array_count);
185
186 private:
187 /**
188 * \param name_length Length of the current name \b not including the
189 * terminating \c NUL character.
190 * \param last_field Set if \c name is the last field of the structure
191 * containing it. This will always be false for items
192 * not contained in a structure or interface block.
193 */
194 void recursion(const glsl_type *t, char **name, size_t name_length,
195 bool row_major, const glsl_type *record_type,
196 const unsigned packing,
197 bool last_field, unsigned record_array_count);
198 };
199
200 void
201 linker_error(gl_shader_program *prog, const char *fmt, ...);
202
203 void
204 linker_warning(gl_shader_program *prog, const char *fmt, ...);
205
206 #endif /* GLSL_LINKER_H */