Cody Northrop | 0d5881e | 2014-09-17 14:06:55 -0600 | [diff] [blame^] | 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 | void |
| 30 | populate_symbol_table(gl_shader *sh); |
| 31 | |
| 32 | extern bool |
| 33 | link_function_calls(gl_shader_program *prog, gl_shader *main, |
| 34 | gl_shader **shader_list, unsigned num_shaders); |
| 35 | |
| 36 | extern void |
| 37 | link_invalidate_variable_locations(exec_list *ir); |
| 38 | |
| 39 | extern void |
| 40 | link_assign_uniform_locations(struct gl_shader_program *prog); |
| 41 | |
| 42 | extern void |
| 43 | link_set_uniform_initializers(struct gl_shader_program *prog); |
| 44 | |
| 45 | extern int |
| 46 | link_cross_validate_uniform_block(void *mem_ctx, |
| 47 | struct gl_uniform_block **linked_blocks, |
| 48 | unsigned int *num_linked_blocks, |
| 49 | struct gl_uniform_block *new_block); |
| 50 | |
| 51 | void |
| 52 | link_assign_uniform_block_offsets(struct gl_shader *shader); |
| 53 | |
| 54 | extern bool |
| 55 | link_uniform_blocks_are_compatible(const gl_uniform_block *a, |
| 56 | const gl_uniform_block *b); |
| 57 | |
| 58 | extern unsigned |
| 59 | link_uniform_blocks(void *mem_ctx, |
| 60 | struct gl_shader_program *prog, |
| 61 | struct gl_shader **shader_list, |
| 62 | unsigned num_shaders, |
| 63 | struct gl_uniform_block **blocks_ret); |
| 64 | |
| 65 | void |
| 66 | validate_intrastage_interface_blocks(struct gl_shader_program *prog, |
| 67 | const gl_shader **shader_list, |
| 68 | unsigned num_shaders); |
| 69 | |
| 70 | void |
| 71 | validate_interstage_inout_blocks(struct gl_shader_program *prog, |
| 72 | const gl_shader *producer, |
| 73 | const gl_shader *consumer); |
| 74 | |
| 75 | void |
| 76 | validate_interstage_uniform_blocks(struct gl_shader_program *prog, |
| 77 | gl_shader **stages, int num_stages); |
| 78 | |
| 79 | extern void |
| 80 | link_assign_atomic_counter_resources(struct gl_context *ctx, |
| 81 | struct gl_shader_program *prog); |
| 82 | |
| 83 | extern void |
| 84 | link_check_atomic_counter_resources(struct gl_context *ctx, |
| 85 | struct gl_shader_program *prog); |
| 86 | |
| 87 | /** |
| 88 | * Class for processing all of the leaf fields of a variable that corresponds |
| 89 | * to a program resource. |
| 90 | * |
| 91 | * The leaf fields are all the parts of the variable that the application |
| 92 | * could query using \c glGetProgramResourceIndex (or that could be returned |
| 93 | * by \c glGetProgramResourceName). |
| 94 | * |
| 95 | * Classes my derive from this class to implement specific functionality. |
| 96 | * This class only provides the mechanism to iterate over the leaves. Derived |
| 97 | * classes must implement \c ::visit_field and may override \c ::process. |
| 98 | */ |
| 99 | class program_resource_visitor { |
| 100 | public: |
| 101 | /** |
| 102 | * Begin processing a variable |
| 103 | * |
| 104 | * Classes that overload this function should call \c ::process from the |
| 105 | * base class to start the recursive processing of the variable. |
| 106 | * |
| 107 | * \param var The variable that is to be processed |
| 108 | * |
| 109 | * Calls \c ::visit_field for each leaf of the variable. |
| 110 | * |
| 111 | * \warning |
| 112 | * When processing a uniform block, this entry should only be used in cases |
| 113 | * where the row / column ordering of matrices in the block does not |
| 114 | * matter. For example, enumerating the names of members of the block, but |
| 115 | * not for determining the offsets of members. |
| 116 | */ |
| 117 | void process(ir_variable *var); |
| 118 | |
| 119 | /** |
| 120 | * Begin processing a variable of a structured type. |
| 121 | * |
| 122 | * This flavor of \c process should be used to handle structured types |
| 123 | * (i.e., structures, interfaces, or arrays there of) that need special |
| 124 | * name handling. A common usage is to handle cases where the block name |
| 125 | * (instead of the instance name) is used for an interface block. |
| 126 | * |
| 127 | * \param type Type that is to be processed, associated with \c name |
| 128 | * \param name Base name of the structured variable being processed |
| 129 | * |
| 130 | * \note |
| 131 | * \c type must be \c GLSL_TYPE_RECORD, \c GLSL_TYPE_INTERFACE, or an array |
| 132 | * there of. |
| 133 | */ |
| 134 | void process(const glsl_type *type, const char *name); |
| 135 | |
| 136 | protected: |
| 137 | /** |
| 138 | * Method invoked for each leaf of the variable |
| 139 | * |
| 140 | * \param type Type of the field. |
| 141 | * \param name Fully qualified name of the field. |
| 142 | * \param row_major For a matrix type, is it stored row-major. |
| 143 | * \param record_type Type of the record containing the field. |
| 144 | * |
| 145 | * The default implementation just calls the other \c visit_field method. |
| 146 | */ |
| 147 | virtual void visit_field(const glsl_type *type, const char *name, |
| 148 | bool row_major, const glsl_type *record_type); |
| 149 | |
| 150 | /** |
| 151 | * Method invoked for each leaf of the variable |
| 152 | * |
| 153 | * \param type Type of the field. |
| 154 | * \param name Fully qualified name of the field. |
| 155 | * \param row_major For a matrix type, is it stored row-major. |
| 156 | */ |
| 157 | virtual void visit_field(const glsl_type *type, const char *name, |
| 158 | bool row_major) = 0; |
| 159 | |
| 160 | /** |
| 161 | * Visit a record before visiting its fields |
| 162 | * |
| 163 | * For structures-of-structures or interfaces-of-structures, this visits |
| 164 | * the inner structure before visiting its fields. |
| 165 | * |
| 166 | * The default implementation does nothing. |
| 167 | */ |
| 168 | virtual void visit_field(const glsl_struct_field *field); |
| 169 | |
| 170 | private: |
| 171 | /** |
| 172 | * \param name_length Length of the current name \b not including the |
| 173 | * terminating \c NUL character. |
| 174 | */ |
| 175 | void recursion(const glsl_type *t, char **name, size_t name_length, |
| 176 | bool row_major, const glsl_type *record_type); |
| 177 | }; |
| 178 | |
| 179 | void |
| 180 | linker_error(gl_shader_program *prog, const char *fmt, ...); |
| 181 | |
| 182 | void |
| 183 | linker_warning(gl_shader_program *prog, const char *fmt, ...); |
| 184 | |
| 185 | #endif /* GLSL_LINKER_H */ |