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