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