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