1bf215546Sopenharmony_ci/* -*- c++ -*- */
2bf215546Sopenharmony_ci/*
3bf215546Sopenharmony_ci * Copyright © 2010 Intel Corporation
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
10bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci#ifndef GLSL_LINKER_H
26bf215546Sopenharmony_ci#define GLSL_LINKER_H
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "linker_util.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_cistruct gl_shader_program;
31bf215546Sopenharmony_cistruct gl_shader;
32bf215546Sopenharmony_cistruct gl_linked_shader;
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ciextern bool
35bf215546Sopenharmony_cilink_function_calls(gl_shader_program *prog, gl_linked_shader *main,
36bf215546Sopenharmony_ci                    gl_shader **shader_list, unsigned num_shaders);
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ciextern int
39bf215546Sopenharmony_cilink_cross_validate_uniform_block(void *mem_ctx,
40bf215546Sopenharmony_ci                                  struct gl_uniform_block **linked_blocks,
41bf215546Sopenharmony_ci                                  unsigned int *num_linked_blocks,
42bf215546Sopenharmony_ci                                  struct gl_uniform_block *new_block);
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ciextern void
45bf215546Sopenharmony_cilink_uniform_blocks(void *mem_ctx,
46bf215546Sopenharmony_ci                    const struct gl_constants *consts,
47bf215546Sopenharmony_ci                    struct gl_shader_program *prog,
48bf215546Sopenharmony_ci                    struct gl_linked_shader *shader,
49bf215546Sopenharmony_ci                    struct gl_uniform_block **ubo_blocks,
50bf215546Sopenharmony_ci                    unsigned *num_ubo_blocks,
51bf215546Sopenharmony_ci                    struct gl_uniform_block **ssbo_blocks,
52bf215546Sopenharmony_ci                    unsigned *num_ssbo_blocks);
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_cibool
55bf215546Sopenharmony_civalidate_intrastage_arrays(struct gl_shader_program *prog,
56bf215546Sopenharmony_ci                           ir_variable *const var,
57bf215546Sopenharmony_ci                           ir_variable *const existing,
58bf215546Sopenharmony_ci                           bool match_precision = true);
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_civoid
61bf215546Sopenharmony_civalidate_intrastage_interface_blocks(struct gl_shader_program *prog,
62bf215546Sopenharmony_ci                                     const gl_shader **shader_list,
63bf215546Sopenharmony_ci                                     unsigned num_shaders);
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_civoid
66bf215546Sopenharmony_civalidate_interstage_inout_blocks(struct gl_shader_program *prog,
67bf215546Sopenharmony_ci                                 const gl_linked_shader *producer,
68bf215546Sopenharmony_ci                                 const gl_linked_shader *consumer);
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_civoid
71bf215546Sopenharmony_civalidate_interstage_uniform_blocks(struct gl_shader_program *prog,
72bf215546Sopenharmony_ci                                   gl_linked_shader **stages);
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ciextern struct gl_linked_shader *
75bf215546Sopenharmony_cilink_intrastage_shaders(void *mem_ctx,
76bf215546Sopenharmony_ci                        struct gl_context *ctx,
77bf215546Sopenharmony_ci                        struct gl_shader_program *prog,
78bf215546Sopenharmony_ci                        struct gl_shader **shader_list,
79bf215546Sopenharmony_ci                        unsigned num_shaders,
80bf215546Sopenharmony_ci                        bool allow_missing_main);
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ciextern unsigned
83bf215546Sopenharmony_cilink_calculate_matrix_stride(const glsl_type *matrix, bool row_major,
84bf215546Sopenharmony_ci                             enum glsl_interface_packing packing);
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci/**
87bf215546Sopenharmony_ci * Class for processing all of the leaf fields of a variable that corresponds
88bf215546Sopenharmony_ci * to a program resource.
89bf215546Sopenharmony_ci *
90bf215546Sopenharmony_ci * The leaf fields are all the parts of the variable that the application
91bf215546Sopenharmony_ci * could query using \c glGetProgramResourceIndex (or that could be returned
92bf215546Sopenharmony_ci * by \c glGetProgramResourceName).
93bf215546Sopenharmony_ci *
94bf215546Sopenharmony_ci * Classes my derive from this class to implement specific functionality.
95bf215546Sopenharmony_ci * This class only provides the mechanism to iterate over the leaves.  Derived
96bf215546Sopenharmony_ci * classes must implement \c ::visit_field and may override \c ::process.
97bf215546Sopenharmony_ci */
98bf215546Sopenharmony_ciclass program_resource_visitor {
99bf215546Sopenharmony_cipublic:
100bf215546Sopenharmony_ci   /**
101bf215546Sopenharmony_ci    * Begin processing a variable
102bf215546Sopenharmony_ci    *
103bf215546Sopenharmony_ci    * Classes that overload this function should call \c ::process from the
104bf215546Sopenharmony_ci    * base class to start the recursive processing of the variable.
105bf215546Sopenharmony_ci    *
106bf215546Sopenharmony_ci    * \param var  The variable that is to be processed
107bf215546Sopenharmony_ci    *
108bf215546Sopenharmony_ci    * Calls \c ::visit_field for each leaf of the variable.
109bf215546Sopenharmony_ci    *
110bf215546Sopenharmony_ci    * \warning
111bf215546Sopenharmony_ci    * When processing a uniform block, this entry should only be used in cases
112bf215546Sopenharmony_ci    * where the row / column ordering of matrices in the block does not
113bf215546Sopenharmony_ci    * matter.  For example, enumerating the names of members of the block, but
114bf215546Sopenharmony_ci    * not for determining the offsets of members.
115bf215546Sopenharmony_ci    */
116bf215546Sopenharmony_ci   void process(ir_variable *var, bool use_std430_as_default);
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci   /**
119bf215546Sopenharmony_ci    * Begin processing a variable
120bf215546Sopenharmony_ci    *
121bf215546Sopenharmony_ci    * Classes that overload this function should call \c ::process from the
122bf215546Sopenharmony_ci    * base class to start the recursive processing of the variable.
123bf215546Sopenharmony_ci    *
124bf215546Sopenharmony_ci    * \param var  The variable that is to be processed
125bf215546Sopenharmony_ci    * \param var_type The glsl_type reference of the variable
126bf215546Sopenharmony_ci    *
127bf215546Sopenharmony_ci    * Calls \c ::visit_field for each leaf of the variable.
128bf215546Sopenharmony_ci    *
129bf215546Sopenharmony_ci    * \warning
130bf215546Sopenharmony_ci    * When processing a uniform block, this entry should only be used in cases
131bf215546Sopenharmony_ci    * where the row / column ordering of matrices in the block does not
132bf215546Sopenharmony_ci    * matter.  For example, enumerating the names of members of the block, but
133bf215546Sopenharmony_ci    * not for determining the offsets of members.
134bf215546Sopenharmony_ci    */
135bf215546Sopenharmony_ci   void process(ir_variable *var, const glsl_type *var_type,
136bf215546Sopenharmony_ci                bool use_std430_as_default);
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci   /**
139bf215546Sopenharmony_ci    * Begin processing a variable of a structured type.
140bf215546Sopenharmony_ci    *
141bf215546Sopenharmony_ci    * This flavor of \c process should be used to handle structured types
142bf215546Sopenharmony_ci    * (i.e., structures, interfaces, or arrays there of) that need special
143bf215546Sopenharmony_ci    * name handling.  A common usage is to handle cases where the block name
144bf215546Sopenharmony_ci    * (instead of the instance name) is used for an interface block.
145bf215546Sopenharmony_ci    *
146bf215546Sopenharmony_ci    * \param type  Type that is to be processed, associated with \c name
147bf215546Sopenharmony_ci    * \param name  Base name of the structured variable being processed
148bf215546Sopenharmony_ci    *
149bf215546Sopenharmony_ci    * \note
150bf215546Sopenharmony_ci    * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array
151bf215546Sopenharmony_ci    * there of.
152bf215546Sopenharmony_ci    */
153bf215546Sopenharmony_ci   void process(const glsl_type *type, const char *name,
154bf215546Sopenharmony_ci                bool use_std430_as_default);
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ciprotected:
157bf215546Sopenharmony_ci   /**
158bf215546Sopenharmony_ci    * Method invoked for each leaf of the variable
159bf215546Sopenharmony_ci    *
160bf215546Sopenharmony_ci    * \param type  Type of the field.
161bf215546Sopenharmony_ci    * \param name  Fully qualified name of the field.
162bf215546Sopenharmony_ci    * \param row_major  For a matrix type, is it stored row-major.
163bf215546Sopenharmony_ci    * \param record_type  Type of the record containing the field.
164bf215546Sopenharmony_ci    * \param last_field   Set if \c name is the last field of the structure
165bf215546Sopenharmony_ci    *                     containing it.  This will always be false for items
166bf215546Sopenharmony_ci    *                     not contained in a structure or interface block.
167bf215546Sopenharmony_ci    */
168bf215546Sopenharmony_ci   virtual void visit_field(const glsl_type *type, const char *name,
169bf215546Sopenharmony_ci                            bool row_major, const glsl_type *record_type,
170bf215546Sopenharmony_ci                            const enum glsl_interface_packing packing,
171bf215546Sopenharmony_ci                            bool last_field) = 0;
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   virtual void enter_record(const glsl_type *type, const char *name,
174bf215546Sopenharmony_ci                             bool row_major, const enum glsl_interface_packing packing);
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   virtual void leave_record(const glsl_type *type, const char *name,
177bf215546Sopenharmony_ci                             bool row_major, const enum glsl_interface_packing packing);
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   virtual void set_buffer_offset(unsigned offset);
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci   virtual void set_record_array_count(unsigned record_array_count);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ciprivate:
184bf215546Sopenharmony_ci   /**
185bf215546Sopenharmony_ci    * \param name_length  Length of the current name \b not including the
186bf215546Sopenharmony_ci    *                     terminating \c NUL character.
187bf215546Sopenharmony_ci    * \param last_field   Set if \c name is the last field of the structure
188bf215546Sopenharmony_ci    *                     containing it.  This will always be false for items
189bf215546Sopenharmony_ci    *                     not contained in a structure or interface block.
190bf215546Sopenharmony_ci    */
191bf215546Sopenharmony_ci   void recursion(const glsl_type *t, char **name, size_t name_length,
192bf215546Sopenharmony_ci                  bool row_major, const glsl_type *record_type,
193bf215546Sopenharmony_ci                  const enum glsl_interface_packing packing,
194bf215546Sopenharmony_ci                  bool last_field, unsigned record_array_count,
195bf215546Sopenharmony_ci                  const glsl_struct_field *named_ifc_member);
196bf215546Sopenharmony_ci};
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci#endif /* GLSL_LINKER_H */
199