glsl: consistently use ifndef guards over pragma once
[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 unsigned
79 values_for_type(const glsl_type *type);
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 extern struct gl_linked_shader *
91 link_intrastage_shaders(void *mem_ctx,
92 struct gl_context *ctx,
93 struct gl_shader_program *prog,
94 struct gl_shader **shader_list,
95 unsigned num_shaders,
96 bool allow_missing_main);
97
98 /**
99 * Class for processing all of the leaf fields of a variable that corresponds
100 * to a program resource.
101 *
102 * The leaf fields are all the parts of the variable that the application
103 * could query using \c glGetProgramResourceIndex (or that could be returned
104 * by \c glGetProgramResourceName).
105 *
106 * Classes my derive from this class to implement specific functionality.
107 * This class only provides the mechanism to iterate over the leaves. Derived
108 * classes must implement \c ::visit_field and may override \c ::process.
109 */
110 class program_resource_visitor {
111 public:
112 /**
113 * Begin processing a variable
114 *
115 * Classes that overload this function should call \c ::process from the
116 * base class to start the recursive processing of the variable.
117 *
118 * \param var The variable that is to be processed
119 *
120 * Calls \c ::visit_field for each leaf of the variable.
121 *
122 * \warning
123 * When processing a uniform block, this entry should only be used in cases
124 * where the row / column ordering of matrices in the block does not
125 * matter. For example, enumerating the names of members of the block, but
126 * not for determining the offsets of members.
127 */
128 void process(ir_variable *var);
129
130 /**
131 * Begin processing a variable of a structured type.
132 *
133 * This flavor of \c process should be used to handle structured types
134 * (i.e., structures, interfaces, or arrays there of) that need special
135 * name handling. A common usage is to handle cases where the block name
136 * (instead of the instance name) is used for an interface block.
137 *
138 * \param type Type that is to be processed, associated with \c name
139 * \param name Base name of the structured variable being processed
140 *
141 * \note
142 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
143 * there of.
144 */
145 void process(const glsl_type *type, const char *name);
146
147 protected:
148 /**
149 * Method invoked for each leaf of the variable
150 *
151 * \param type Type of the field.
152 * \param name Fully qualified name of the field.
153 * \param row_major For a matrix type, is it stored row-major.
154 * \param record_type Type of the record containing the field.
155 * \param last_field Set if \c name is the last field of the structure
156 * containing it. This will always be false for items
157 * not contained in a structure or interface block.
158 */
159 virtual void visit_field(const glsl_type *type, const char *name,
160 bool row_major, const glsl_type *record_type,
161 const enum glsl_interface_packing packing,
162 bool last_field) = 0;
163
164 /**
165 * Visit a record before visiting its fields
166 *
167 * For structures-of-structures or interfaces-of-structures, this visits
168 * the inner structure before visiting its fields.
169 *
170 * The default implementation does nothing.
171 */
172 virtual void visit_field(const glsl_struct_field *field);
173
174 virtual void enter_record(const glsl_type *type, const char *name,
175 bool row_major, const enum glsl_interface_packing packing);
176
177 virtual void leave_record(const glsl_type *type, const char *name,
178 bool row_major, const enum glsl_interface_packing packing);
179
180 virtual void set_buffer_offset(unsigned offset);
181
182 virtual void set_record_array_count(unsigned record_array_count);
183
184 private:
185 /**
186 * \param name_length Length of the current name \b not including the
187 * terminating \c NUL character.
188 * \param last_field Set if \c name is the last field of the structure
189 * containing it. This will always be false for items
190 * not contained in a structure or interface block.
191 */
192 void recursion(const glsl_type *t, char **name, size_t name_length,
193 bool row_major, const glsl_type *record_type,
194 const enum glsl_interface_packing packing,
195 bool last_field, unsigned record_array_count,
196 const glsl_struct_field *named_ifc_member);
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 /**
206 * Sometimes there are empty slots left over in UniformRemapTable after we
207 * allocate slots to explicit locations. This struct represents a single
208 * continouous block of empty slots in UniformRemapTable.
209 */
210 struct empty_uniform_block {
211 struct exec_node link;
212 /* The start location of the block */
213 unsigned start;
214 /* The number of slots in the block */
215 unsigned slots;
216 };
217
218 #endif /* GLSL_LINKER_H */