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