glsl: Use a consistent technique for tracking link success/failure.
[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(gl_shader *sh, enum ir_variable_mode mode,
35 int generic_base);
36
37 extern void
38 link_assign_uniform_locations(struct gl_shader_program *prog);
39
40 extern void
41 link_set_uniform_initializers(struct gl_shader_program *prog);
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 void
50 link_assign_uniform_block_offsets(struct gl_shader *shader);
51
52 extern bool
53 link_uniform_blocks_are_compatible(const gl_uniform_block *a,
54 const gl_uniform_block *b);
55
56 extern unsigned
57 link_uniform_blocks(void *mem_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 void
64 validate_intrastage_interface_blocks(struct gl_shader_program *prog,
65 const gl_shader **shader_list,
66 unsigned num_shaders);
67
68 void
69 validate_interstage_interface_blocks(struct gl_shader_program *prog,
70 const gl_shader *producer,
71 const gl_shader *consumer);
72
73 /**
74 * Class for processing all of the leaf fields of a variable that corresponds
75 * to a program resource.
76 *
77 * The leaf fields are all the parts of the variable that the application
78 * could query using \c glGetProgramResourceIndex (or that could be returned
79 * by \c glGetProgramResourceName).
80 *
81 * Classes my derive from this class to implement specific functionality.
82 * This class only provides the mechanism to iterate over the leaves. Derived
83 * classes must implement \c ::visit_field and may override \c ::process.
84 */
85 class program_resource_visitor {
86 public:
87 /**
88 * Begin processing a variable
89 *
90 * Classes that overload this function should call \c ::process from the
91 * base class to start the recursive processing of the variable.
92 *
93 * \param var The variable that is to be processed
94 *
95 * Calls \c ::visit_field for each leaf of the variable.
96 *
97 * \warning
98 * When processing a uniform block, this entry should only be used in cases
99 * where the row / column ordering of matrices in the block does not
100 * matter. For example, enumerating the names of members of the block, but
101 * not for determining the offsets of members.
102 */
103 void process(ir_variable *var);
104
105 /**
106 * Begin processing a variable of a structured type.
107 *
108 * This flavor of \c process should be used to handle structured types
109 * (i.e., structures, interfaces, or arrays there of) that need special
110 * name handling. A common usage is to handle cases where the block name
111 * (instead of the instance name) is used for an interface block.
112 *
113 * \param type Type that is to be processed, associated with \c name
114 * \param name Base name of the structured variable being processed
115 *
116 * \note
117 * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
118 * there of.
119 */
120 void process(const glsl_type *type, const char *name);
121
122 protected:
123 /**
124 * Method invoked for each leaf of the variable
125 *
126 * \param type Type of the field.
127 * \param name Fully qualified name of the field.
128 * \param row_major For a matrix type, is it stored row-major.
129 */
130 virtual void visit_field(const glsl_type *type, const char *name,
131 bool row_major) = 0;
132
133 /**
134 * Visit a record before visiting its fields
135 *
136 * For structures-of-structures or interfaces-of-structures, this visits
137 * the inner structure before visiting its fields.
138 *
139 * The default implementation does nothing.
140 */
141 virtual void visit_field(const glsl_struct_field *field);
142
143 private:
144 /**
145 * \param name_length Length of the current name \b not including the
146 * terminating \c NUL character.
147 */
148 void recursion(const glsl_type *t, char **name, size_t name_length,
149 bool row_major);
150 };
151
152 void
153 linker_error(gl_shader_program *prog, const char *fmt, ...);
154
155 void
156 linker_warning(gl_shader_program *prog, const char *fmt, ...);
157
158 unsigned
159 count_attribute_slots(const glsl_type *t);
160
161 #endif /* GLSL_LINKER_H */