abcfdb15971f265e3a4ffc0ad908c6be69a5e7cf
[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_linked_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 struct gl_context *ctx);
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 void
51 link_uniform_blocks(void *mem_ctx,
52 struct gl_context *ctx,
53 struct gl_shader_program *prog,
54 struct gl_linked_shader *shader,
55 struct gl_uniform_block **ubo_blocks,
56 unsigned *num_ubo_blocks,
57 struct gl_uniform_block **ssbo_blocks,
58 unsigned *num_ssbo_blocks);
59
60 bool
61 validate_intrastage_arrays(struct gl_shader_program *prog,
62 ir_variable *const var,
63 ir_variable *const existing);
64
65 void
66 validate_intrastage_interface_blocks(struct gl_shader_program *prog,
67 const gl_shader **shader_list,
68 unsigned num_shaders);
69
70 void
71 validate_interstage_inout_blocks(struct gl_shader_program *prog,
72 const gl_linked_shader *producer,
73 const gl_linked_shader *consumer);
74
75 void
76 validate_interstage_uniform_blocks(struct gl_shader_program *prog,
77 gl_linked_shader **stages);
78
79 unsigned
80 values_for_type(const glsl_type *type);
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 /**
100 * Class for processing all of the leaf fields of a variable that corresponds
101 * to a program resource.
102 *
103 * The leaf fields are all the parts of the variable that the application
104 * could query using \c glGetProgramResourceIndex (or that could be returned
105 * by \c glGetProgramResourceName).
106 *
107 * Classes my derive from this class to implement specific functionality.
108 * This class only provides the mechanism to iterate over the leaves. Derived
109 * classes must implement \c ::visit_field and may override \c ::process.
110 */
111 class program_resource_visitor {
112 public:
113 /**
114 * Begin processing a variable
115 *
116 * Classes that overload this function should call \c ::process from the
117 * base class to start the recursive processing of the variable.
118 *
119 * \param var The variable that is to be processed
120 *
121 * Calls \c ::visit_field for each leaf of the variable.
122 *
123 * \warning
124 * When processing a uniform block, this entry should only be used in cases
125 * where the row / column ordering of matrices in the block does not
126 * matter. For example, enumerating the names of members of the block, but
127 * not for determining the offsets of members.
128 */
129 void process(ir_variable *var);
130
131 /**
132 * Begin processing a variable of a structured type.
133 *
134 * This flavor of \c process should be used to handle structured types
135 * (i.e., structures, interfaces, or arrays there of) that need special
136 * name handling. A common usage is to handle cases where the block name
137 * (instead of the instance name) is used for an interface block.
138 *
139 * \param type Type that is to be processed, associated with \c name
140 * \param name Base name of the structured variable being processed
141 *
142 * \note
143 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
144 * there of.
145 */
146 void process(const glsl_type *type, const char *name);
147
148 protected:
149 /**
150 * Method invoked for each leaf of the variable
151 *
152 * \param type Type of the field.
153 * \param name Fully qualified name of the field.
154 * \param row_major For a matrix type, is it stored row-major.
155 * \param record_type Type of the record containing the field.
156 * \param last_field Set if \c name is the last field of the structure
157 * containing it. This will always be false for items
158 * not contained in a structure or interface block.
159 */
160 virtual void visit_field(const glsl_type *type, const char *name,
161 bool row_major, const glsl_type *record_type,
162 const enum glsl_interface_packing packing,
163 bool last_field) = 0;
164
165 /**
166 * Visit a record before visiting its fields
167 *
168 * For structures-of-structures or interfaces-of-structures, this visits
169 * the inner structure before visiting its fields.
170 *
171 * The default implementation does nothing.
172 */
173 virtual void visit_field(const glsl_struct_field *field);
174
175 virtual void enter_record(const glsl_type *type, const char *name,
176 bool row_major, const enum glsl_interface_packing packing);
177
178 virtual void leave_record(const glsl_type *type, const char *name,
179 bool row_major, const enum glsl_interface_packing packing);
180
181 virtual void set_buffer_offset(unsigned offset);
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 enum glsl_interface_packing packing,
196 bool last_field, unsigned record_array_count,
197 const glsl_struct_field *named_ifc_member);
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 /**
207 * Sometimes there are empty slots left over in UniformRemapTable after we
208 * allocate slots to explicit locations. This struct represents a single
209 * continouous block of empty slots in UniformRemapTable.
210 */
211 struct empty_uniform_block {
212 struct exec_node link;
213 /* The start location of the block */
214 unsigned start;
215 /* The number of slots in the block */
216 unsigned slots;
217 };
218
219 #endif /* GLSL_LINKER_H */