Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * \file linker.cpp |
| 26 | * GLSL linker implementation |
| 27 | * |
| 28 | * Given a set of shaders that are to be linked to generate a final program, |
| 29 | * there are three distinct stages. |
| 30 | * |
| 31 | * In the first stage shaders are partitioned into groups based on the shader |
| 32 | * type. All shaders of a particular type (e.g., vertex shaders) are linked |
| 33 | * together. |
| 34 | * |
| 35 | * - Undefined references in each shader are resolve to definitions in |
| 36 | * another shader. |
| 37 | * - Types and qualifiers of uniforms, outputs, and global variables defined |
| 38 | * in multiple shaders with the same name are verified to be the same. |
| 39 | * - Initializers for uniforms and global variables defined |
| 40 | * in multiple shaders with the same name are verified to be the same. |
| 41 | * |
| 42 | * The result, in the terminology of the GLSL spec, is a set of shader |
| 43 | * executables for each processing unit. |
| 44 | * |
| 45 | * After the first stage is complete, a series of semantic checks are performed |
| 46 | * on each of the shader executables. |
| 47 | * |
| 48 | * - Each shader executable must define a \c main function. |
| 49 | * - Each vertex shader executable must write to \c gl_Position. |
| 50 | * - Each fragment shader executable must write to either \c gl_FragData or |
| 51 | * \c gl_FragColor. |
| 52 | * |
| 53 | * In the final stage individual shader executables are linked to create a |
| 54 | * complete exectuable. |
| 55 | * |
| 56 | * - Types of uniforms defined in multiple shader stages with the same name |
| 57 | * are verified to be the same. |
| 58 | * - Initializers for uniforms defined in multiple shader stages with the |
| 59 | * same name are verified to be the same. |
| 60 | * - Types and qualifiers of outputs defined in one stage are verified to |
| 61 | * be the same as the types and qualifiers of inputs defined with the same |
| 62 | * name in a later stage. |
| 63 | * |
| 64 | * \author Ian Romanick <ian.d.romanick@intel.com> |
| 65 | */ |
| 66 | #include <cstdlib> |
| 67 | #include <cstdio> |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 68 | #include <cstdarg> |
| 69 | |
| 70 | extern "C" { |
| 71 | #include <talloc.h> |
| 72 | } |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 73 | |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 74 | #include "main/mtypes.h" |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 75 | #include "glsl_symbol_table.h" |
| 76 | #include "glsl_parser_extras.h" |
| 77 | #include "ir.h" |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 78 | #include "ir_optimization.h" |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 79 | #include "program.h" |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 80 | #include "hash_table.h" |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Visitor that determines whether or not a variable is ever written. |
| 84 | */ |
| 85 | class find_assignment_visitor : public ir_hierarchical_visitor { |
| 86 | public: |
| 87 | find_assignment_visitor(const char *name) |
| 88 | : name(name), found(false) |
| 89 | { |
| 90 | /* empty */ |
| 91 | } |
| 92 | |
| 93 | virtual ir_visitor_status visit_enter(ir_assignment *ir) |
| 94 | { |
| 95 | ir_variable *const var = ir->lhs->variable_referenced(); |
| 96 | |
| 97 | if (strcmp(name, var->name) == 0) { |
| 98 | found = true; |
| 99 | return visit_stop; |
| 100 | } |
| 101 | |
| 102 | return visit_continue_with_parent; |
| 103 | } |
| 104 | |
| 105 | bool variable_found() |
| 106 | { |
| 107 | return found; |
| 108 | } |
| 109 | |
| 110 | private: |
| 111 | const char *name; /**< Find writes to a variable with this name. */ |
| 112 | bool found; /**< Was a write to the variable found? */ |
| 113 | }; |
| 114 | |
Ian Romanick | c93b8f1 | 2010-06-17 15:20:22 -0700 | [diff] [blame] | 115 | |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 116 | void |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 117 | linker_error_printf(glsl_program *prog, const char *fmt, ...) |
| 118 | { |
| 119 | va_list ap; |
| 120 | |
| 121 | prog->InfoLog = talloc_strdup_append(prog->InfoLog, "error: "); |
| 122 | va_start(ap, fmt); |
| 123 | prog->InfoLog = talloc_vasprintf_append(prog->InfoLog, fmt, ap); |
| 124 | va_end(ap); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | void |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 129 | invalidate_variable_locations(glsl_shader *sh, enum ir_variable_mode mode, |
| 130 | int generic_base) |
| 131 | { |
| 132 | foreach_list(node, &sh->ir) { |
| 133 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 134 | |
| 135 | if ((var == NULL) || (var->mode != (unsigned) mode)) |
| 136 | continue; |
| 137 | |
| 138 | /* Only assign locations for generic attributes / varyings / etc. |
| 139 | */ |
| 140 | if (var->location >= generic_base) |
| 141 | var->location = -1; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | |
Ian Romanick | c93b8f1 | 2010-06-17 15:20:22 -0700 | [diff] [blame] | 146 | /** |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 147 | * Determine the number of attribute slots required for a particular type |
| 148 | * |
| 149 | * This code is here because it implements the language rules of a specific |
| 150 | * GLSL version. Since it's a property of the language and not a property of |
| 151 | * types in general, it doesn't really belong in glsl_type. |
| 152 | */ |
| 153 | unsigned |
| 154 | count_attribute_slots(const glsl_type *t) |
| 155 | { |
| 156 | /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec: |
| 157 | * |
| 158 | * "A scalar input counts the same amount against this limit as a vec4, |
| 159 | * so applications may want to consider packing groups of four |
| 160 | * unrelated float inputs together into a vector to better utilize the |
| 161 | * capabilities of the underlying hardware. A matrix input will use up |
| 162 | * multiple locations. The number of locations used will equal the |
| 163 | * number of columns in the matrix." |
| 164 | * |
| 165 | * The spec does not explicitly say how arrays are counted. However, it |
| 166 | * should be safe to assume the total number of slots consumed by an array |
| 167 | * is the number of entries in the array multiplied by the number of slots |
| 168 | * consumed by a single element of the array. |
| 169 | */ |
| 170 | |
| 171 | if (t->is_array()) |
| 172 | return t->array_size() * count_attribute_slots(t->element_type()); |
| 173 | |
| 174 | if (t->is_matrix()) |
| 175 | return t->matrix_columns; |
| 176 | |
| 177 | return 1; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /** |
Ian Romanick | c93b8f1 | 2010-06-17 15:20:22 -0700 | [diff] [blame] | 182 | * Verify that a vertex shader executable meets all semantic requirements |
| 183 | * |
| 184 | * \param shader Vertex shader executable to be verified |
| 185 | */ |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 186 | bool |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 187 | validate_vertex_shader_executable(struct glsl_program *prog, |
| 188 | struct glsl_shader *shader) |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 189 | { |
| 190 | if (shader == NULL) |
| 191 | return true; |
| 192 | |
| 193 | if (!shader->symbols->get_function("main")) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 194 | linker_error_printf(prog, "vertex shader lacks `main'\n"); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
| 198 | find_assignment_visitor find("gl_Position"); |
| 199 | find.run(&shader->ir); |
| 200 | if (!find.variable_found()) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 201 | linker_error_printf(prog, |
| 202 | "vertex shader does not write to `gl_Position'\n"); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | |
Ian Romanick | c93b8f1 | 2010-06-17 15:20:22 -0700 | [diff] [blame] | 210 | /** |
| 211 | * Verify that a fragment shader executable meets all semantic requirements |
| 212 | * |
| 213 | * \param shader Fragment shader executable to be verified |
| 214 | */ |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 215 | bool |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 216 | validate_fragment_shader_executable(struct glsl_program *prog, |
| 217 | struct glsl_shader *shader) |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 218 | { |
| 219 | if (shader == NULL) |
| 220 | return true; |
| 221 | |
| 222 | if (!shader->symbols->get_function("main")) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 223 | linker_error_printf(prog, "fragment shader lacks `main'\n"); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 224 | return false; |
| 225 | } |
| 226 | |
| 227 | find_assignment_visitor frag_color("gl_FragColor"); |
| 228 | find_assignment_visitor frag_data("gl_FragData"); |
| 229 | |
| 230 | frag_color.run(&shader->ir); |
| 231 | frag_data.run(&shader->ir); |
| 232 | |
| 233 | if (!frag_color.variable_found() && !frag_data.variable_found()) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 234 | linker_error_printf(prog, "fragment shader does not write to " |
| 235 | "`gl_FragColor' or `gl_FragData'\n"); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | |
| 239 | if (frag_color.variable_found() && frag_data.variable_found()) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 240 | linker_error_printf(prog, "fragment shader writes to both " |
| 241 | "`gl_FragColor' and `gl_FragData'\n"); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 249 | /** |
| 250 | * Perform validation of uniforms used across multiple shader stages |
| 251 | */ |
| 252 | bool |
Ian Romanick | ed1fe3d | 2010-06-23 12:09:14 -0700 | [diff] [blame] | 253 | cross_validate_uniforms(struct glsl_program *prog) |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 254 | { |
| 255 | /* Examine all of the uniforms in all of the shaders and cross validate |
| 256 | * them. |
| 257 | */ |
| 258 | glsl_symbol_table uniforms; |
Ian Romanick | ed1fe3d | 2010-06-23 12:09:14 -0700 | [diff] [blame] | 259 | for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { |
| 260 | foreach_list(node, &prog->_LinkedShaders[i]->ir) { |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 261 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 262 | |
| 263 | if ((var == NULL) || (var->mode != ir_var_uniform)) |
| 264 | continue; |
| 265 | |
| 266 | /* If a uniform with this name has already been seen, verify that the |
| 267 | * new instance has the same type. In addition, if the uniforms have |
| 268 | * initializers, the values of the initializers must be the same. |
| 269 | */ |
| 270 | ir_variable *const existing = uniforms.get_variable(var->name); |
| 271 | if (existing != NULL) { |
| 272 | if (var->type != existing->type) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 273 | linker_error_printf(prog, "uniform `%s' declared as type " |
| 274 | "`%s' and type `%s'\n", |
| 275 | var->name, var->type->name, |
| 276 | existing->type->name); |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | |
| 280 | if (var->constant_value != NULL) { |
| 281 | if (existing->constant_value != NULL) { |
| 282 | if (!var->constant_value->has_value(existing->constant_value)) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 283 | linker_error_printf(prog, "initializers for uniform " |
| 284 | "`%s' have differing values\n", |
| 285 | var->name); |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 286 | return false; |
| 287 | } |
| 288 | } else |
| 289 | /* If the first-seen instance of a particular uniform did not |
| 290 | * have an initializer but a later instance does, copy the |
| 291 | * initializer to the version stored in the symbol table. |
| 292 | */ |
| 293 | existing->constant_value = var->constant_value->clone(); |
| 294 | } |
| 295 | } else |
| 296 | uniforms.add_variable(var->name, var); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 304 | /** |
| 305 | * Validate that outputs from one stage match inputs of another |
| 306 | */ |
| 307 | bool |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 308 | cross_validate_outputs_to_inputs(struct glsl_program *prog, |
| 309 | glsl_shader *producer, glsl_shader *consumer) |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 310 | { |
| 311 | glsl_symbol_table parameters; |
| 312 | /* FINISHME: Figure these out dynamically. */ |
| 313 | const char *const producer_stage = "vertex"; |
| 314 | const char *const consumer_stage = "fragment"; |
| 315 | |
| 316 | /* Find all shader outputs in the "producer" stage. |
| 317 | */ |
| 318 | foreach_list(node, &producer->ir) { |
| 319 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 320 | |
| 321 | /* FINISHME: For geometry shaders, this should also look for inout |
| 322 | * FINISHME: variables. |
| 323 | */ |
| 324 | if ((var == NULL) || (var->mode != ir_var_out)) |
| 325 | continue; |
| 326 | |
| 327 | parameters.add_variable(var->name, var); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | /* Find all shader inputs in the "consumer" stage. Any variables that have |
| 332 | * matching outputs already in the symbol table must have the same type and |
| 333 | * qualifiers. |
| 334 | */ |
| 335 | foreach_list(node, &consumer->ir) { |
| 336 | ir_variable *const input = ((ir_instruction *) node)->as_variable(); |
| 337 | |
| 338 | /* FINISHME: For geometry shaders, this should also look for inout |
| 339 | * FINISHME: variables. |
| 340 | */ |
| 341 | if ((input == NULL) || (input->mode != ir_var_in)) |
| 342 | continue; |
| 343 | |
| 344 | ir_variable *const output = parameters.get_variable(input->name); |
| 345 | if (output != NULL) { |
| 346 | /* Check that the types match between stages. |
| 347 | */ |
| 348 | if (input->type != output->type) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 349 | linker_error_printf(prog, |
| 350 | "%s shader output `%s' delcared as " |
| 351 | "type `%s', but %s shader input declared " |
| 352 | "as type `%s'\n", |
| 353 | producer_stage, output->name, |
| 354 | output->type->name, |
| 355 | consumer_stage, input->type->name); |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
| 359 | /* Check that all of the qualifiers match between stages. |
| 360 | */ |
| 361 | if (input->centroid != output->centroid) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 362 | linker_error_printf(prog, |
| 363 | "%s shader output `%s' %s centroid qualifier, " |
| 364 | "but %s shader input %s centroid qualifier\n", |
| 365 | producer_stage, |
| 366 | output->name, |
| 367 | (output->centroid) ? "has" : "lacks", |
| 368 | consumer_stage, |
| 369 | (input->centroid) ? "has" : "lacks"); |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 370 | return false; |
| 371 | } |
| 372 | |
| 373 | if (input->invariant != output->invariant) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 374 | linker_error_printf(prog, |
| 375 | "%s shader output `%s' %s invariant qualifier, " |
| 376 | "but %s shader input %s invariant qualifier\n", |
| 377 | producer_stage, |
| 378 | output->name, |
| 379 | (output->invariant) ? "has" : "lacks", |
| 380 | consumer_stage, |
| 381 | (input->invariant) ? "has" : "lacks"); |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 382 | return false; |
| 383 | } |
| 384 | |
| 385 | if (input->interpolation != output->interpolation) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 386 | linker_error_printf(prog, |
| 387 | "%s shader output `%s' specifies %s " |
| 388 | "interpolation qualifier, " |
| 389 | "but %s shader input specifies %s " |
| 390 | "interpolation qualifier\n", |
| 391 | producer_stage, |
| 392 | output->name, |
| 393 | output->interpolation_string(), |
| 394 | consumer_stage, |
| 395 | input->interpolation_string()); |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 396 | return false; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 405 | struct uniform_node { |
| 406 | exec_node link; |
| 407 | struct gl_uniform *u; |
| 408 | unsigned slots; |
| 409 | }; |
| 410 | |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 411 | void |
| 412 | assign_uniform_locations(struct glsl_program *prog) |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 413 | { |
| 414 | /* */ |
| 415 | exec_list uniforms; |
| 416 | unsigned total_uniforms = 0; |
| 417 | hash_table *ht = hash_table_ctor(32, hash_table_string_hash, |
| 418 | hash_table_string_compare); |
| 419 | |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 420 | for (unsigned i = 0; i < prog->_NumLinkedShaders; i++) { |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 421 | unsigned next_position = 0; |
| 422 | |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 423 | foreach_list(node, &prog->_LinkedShaders[i]->ir) { |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 424 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 425 | |
| 426 | if ((var == NULL) || (var->mode != ir_var_uniform)) |
| 427 | continue; |
| 428 | |
| 429 | const unsigned vec4_slots = (var->component_slots() + 3) / 4; |
| 430 | assert(vec4_slots != 0); |
| 431 | |
| 432 | uniform_node *n = (uniform_node *) hash_table_find(ht, var->name); |
| 433 | if (n == NULL) { |
| 434 | n = (uniform_node *) calloc(1, sizeof(struct uniform_node)); |
| 435 | n->u = (gl_uniform *) calloc(vec4_slots, sizeof(struct gl_uniform)); |
| 436 | n->slots = vec4_slots; |
| 437 | |
| 438 | n->u[0].Name = strdup(var->name); |
| 439 | for (unsigned j = 1; j < vec4_slots; j++) |
| 440 | n->u[j].Name = n->u[0].Name; |
| 441 | |
| 442 | hash_table_insert(ht, n, n->u[0].Name); |
| 443 | uniforms.push_tail(& n->link); |
| 444 | total_uniforms += vec4_slots; |
| 445 | } |
| 446 | |
| 447 | if (var->constant_value != NULL) |
| 448 | for (unsigned j = 0; j < vec4_slots; j++) |
| 449 | n->u[j].Initialized = true; |
| 450 | |
| 451 | var->location = next_position; |
| 452 | |
| 453 | for (unsigned j = 0; j < vec4_slots; j++) { |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 454 | switch (prog->_LinkedShaders[i]->Type) { |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 455 | case GL_VERTEX_SHADER: |
| 456 | n->u[j].VertPos = next_position; |
| 457 | break; |
| 458 | case GL_FRAGMENT_SHADER: |
| 459 | n->u[j].FragPos = next_position; |
| 460 | break; |
| 461 | case GL_GEOMETRY_SHADER: |
| 462 | /* FINISHME: Support geometry shaders. */ |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 463 | assert(prog->_LinkedShaders[i]->Type != GL_GEOMETRY_SHADER); |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 464 | break; |
| 465 | } |
| 466 | |
| 467 | next_position++; |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | gl_uniform_list *ul = (gl_uniform_list *) |
| 473 | calloc(1, sizeof(gl_uniform_list)); |
| 474 | |
| 475 | ul->Size = total_uniforms; |
| 476 | ul->NumUniforms = total_uniforms; |
| 477 | ul->Uniforms = (gl_uniform *) calloc(total_uniforms, sizeof(gl_uniform)); |
| 478 | |
| 479 | unsigned idx = 0; |
| 480 | uniform_node *next; |
| 481 | for (uniform_node *node = (uniform_node *) uniforms.head |
| 482 | ; node->link.next != NULL |
| 483 | ; node = next) { |
| 484 | next = (uniform_node *) node->link.next; |
| 485 | |
| 486 | node->link.remove(); |
| 487 | memcpy(&ul->Uniforms[idx], node->u, sizeof(gl_uniform) * node->slots); |
| 488 | idx += node->slots; |
| 489 | |
| 490 | free(node->u); |
| 491 | free(node); |
| 492 | } |
| 493 | |
| 494 | hash_table_dtor(ht); |
| 495 | |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 496 | prog->Uniforms = ul; |
Ian Romanick | 019a59b | 2010-06-21 16:10:42 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 500 | /** |
| 501 | * Find a contiguous set of available bits in a bitmask |
| 502 | * |
| 503 | * \param used_mask Bits representing used (1) and unused (0) locations |
| 504 | * \param needed_count Number of contiguous bits needed. |
| 505 | * |
| 506 | * \return |
| 507 | * Base location of the available bits on success or -1 on failure. |
| 508 | */ |
| 509 | int |
| 510 | find_available_slots(unsigned used_mask, unsigned needed_count) |
| 511 | { |
| 512 | unsigned needed_mask = (1 << needed_count) - 1; |
| 513 | const int max_bit_to_test = (8 * sizeof(used_mask)) - needed_count; |
| 514 | |
| 515 | /* The comparison to 32 is redundant, but without it GCC emits "warning: |
| 516 | * cannot optimize possibly infinite loops" for the loop below. |
| 517 | */ |
| 518 | if ((needed_count == 0) || (max_bit_to_test < 0) || (max_bit_to_test > 32)) |
| 519 | return -1; |
| 520 | |
| 521 | for (int i = 0; i <= max_bit_to_test; i++) { |
| 522 | if ((needed_mask & ~used_mask) == needed_mask) |
| 523 | return i; |
| 524 | |
| 525 | needed_mask <<= 1; |
| 526 | } |
| 527 | |
| 528 | return -1; |
| 529 | } |
| 530 | |
| 531 | |
| 532 | bool |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 533 | assign_attribute_locations(glsl_program *prog, unsigned max_attribute_index) |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 534 | { |
Ian Romanick | 9342d26 | 2010-06-22 17:41:37 -0700 | [diff] [blame] | 535 | /* Mark invalid attribute locations as being used. |
| 536 | */ |
| 537 | unsigned used_locations = (max_attribute_index >= 32) |
| 538 | ? ~0 : ~((1 << max_attribute_index) - 1); |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 539 | |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 540 | glsl_shader *const sh = prog->_LinkedShaders[0]; |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 541 | assert(sh->Type == GL_VERTEX_SHADER); |
| 542 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 543 | /* Operate in a total of four passes. |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 544 | * |
| 545 | * 1. Invalidate the location assignments for all vertex shader inputs. |
| 546 | * |
| 547 | * 2. Assign locations for inputs that have user-defined (via |
| 548 | * glBindVertexAttribLocation) locatoins. |
| 549 | * |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 550 | * 3. Sort the attributes without assigned locations by number of slots |
| 551 | * required in decreasing order. Fragmentation caused by attribute |
| 552 | * locations assigned by the application may prevent large attributes |
| 553 | * from having enough contiguous space. |
| 554 | * |
| 555 | * 4. Assign locations to any inputs without assigned locations. |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 556 | */ |
| 557 | |
| 558 | invalidate_variable_locations(sh, ir_var_in, VERT_ATTRIB_GENERIC0); |
| 559 | |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 560 | if (prog->Attributes != NULL) { |
| 561 | for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) { |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 562 | ir_variable *const var = |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 563 | sh->symbols->get_variable(prog->Attributes->Parameters[i].Name); |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 564 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 565 | /* Note: attributes that occupy multiple slots, such as arrays or |
| 566 | * matrices, may appear in the attrib array multiple times. |
| 567 | */ |
| 568 | if ((var == NULL) || (var->location != -1)) |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 569 | continue; |
| 570 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 571 | /* From page 61 of the OpenGL 4.0 spec: |
| 572 | * |
| 573 | * "LinkProgram will fail if the attribute bindings assigned by |
| 574 | * BindAttribLocation do not leave not enough space to assign a |
| 575 | * location for an active matrix attribute or an active attribute |
| 576 | * array, both of which require multiple contiguous generic |
| 577 | * attributes." |
| 578 | * |
| 579 | * Previous versions of the spec contain similar language but omit the |
| 580 | * bit about attribute arrays. |
| 581 | * |
| 582 | * Page 61 of the OpenGL 4.0 spec also says: |
| 583 | * |
| 584 | * "It is possible for an application to bind more than one |
| 585 | * attribute name to the same location. This is referred to as |
| 586 | * aliasing. This will only work if only one of the aliased |
| 587 | * attributes is active in the executable program, or if no path |
| 588 | * through the shader consumes more than one attribute of a set |
| 589 | * of attributes aliased to the same location. A link error can |
| 590 | * occur if the linker determines that every path through the |
| 591 | * shader consumes multiple aliased attributes, but |
| 592 | * implementations are not required to generate an error in this |
| 593 | * case." |
| 594 | * |
| 595 | * These two paragraphs are either somewhat contradictory, or I don't |
| 596 | * fully understand one or both of them. |
| 597 | */ |
| 598 | /* FINISHME: The code as currently written does not support attribute |
| 599 | * FINISHME: location aliasing (see comment above). |
| 600 | */ |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 601 | const int attr = prog->Attributes->Parameters[i].StateIndexes[0]; |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 602 | const unsigned slots = count_attribute_slots(var->type); |
| 603 | |
| 604 | /* Mask representing the contiguous slots that will be used by this |
| 605 | * attribute. |
| 606 | */ |
| 607 | const unsigned use_mask = (1 << slots) - 1; |
| 608 | |
| 609 | /* Generate a link error if the set of bits requested for this |
| 610 | * attribute overlaps any previously allocated bits. |
| 611 | */ |
| 612 | if ((~(use_mask << attr) & used_locations) != used_locations) { |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 613 | linker_error_printf(prog, |
| 614 | "insufficient contiguous attribute locations " |
| 615 | "available for vertex shader input `%s'", |
| 616 | var->name); |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 617 | return false; |
| 618 | } |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 619 | |
| 620 | var->location = VERT_ATTRIB_GENERIC0 + attr; |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 621 | used_locations |= (use_mask << attr); |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
| 624 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 625 | /* Temporary storage for the set of attributes that need locations assigned. |
| 626 | */ |
| 627 | struct temp_attr { |
| 628 | unsigned slots; |
| 629 | ir_variable *var; |
| 630 | |
| 631 | /* Used below in the call to qsort. */ |
| 632 | static int compare(const void *a, const void *b) |
| 633 | { |
| 634 | const temp_attr *const l = (const temp_attr *) a; |
| 635 | const temp_attr *const r = (const temp_attr *) b; |
| 636 | |
| 637 | /* Reversed because we want a descending order sort below. */ |
| 638 | return r->slots - l->slots; |
| 639 | } |
| 640 | } to_assign[16]; |
| 641 | |
| 642 | unsigned num_attr = 0; |
| 643 | |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 644 | foreach_list(node, &sh->ir) { |
| 645 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 646 | |
| 647 | if ((var == NULL) || (var->mode != ir_var_in)) |
| 648 | continue; |
| 649 | |
| 650 | /* The location was explicitly assigned, nothing to do here. |
| 651 | */ |
| 652 | if (var->location != -1) |
| 653 | continue; |
| 654 | |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 655 | to_assign[num_attr].slots = count_attribute_slots(var->type); |
| 656 | to_assign[num_attr].var = var; |
| 657 | num_attr++; |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 658 | } |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 659 | |
| 660 | /* If all of the attributes were assigned locations by the application (or |
| 661 | * are built-in attributes with fixed locations), return early. This should |
| 662 | * be the common case. |
| 663 | */ |
| 664 | if (num_attr == 0) |
| 665 | return true; |
| 666 | |
| 667 | qsort(to_assign, num_attr, sizeof(to_assign[0]), temp_attr::compare); |
| 668 | |
| 669 | for (unsigned i = 0; i < num_attr; i++) { |
| 670 | /* Mask representing the contiguous slots that will be used by this |
| 671 | * attribute. |
| 672 | */ |
| 673 | const unsigned use_mask = (1 << to_assign[i].slots) - 1; |
| 674 | |
| 675 | int location = find_available_slots(used_locations, to_assign[i].slots); |
| 676 | |
| 677 | if (location < 0) { |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 678 | linker_error_printf(prog, |
| 679 | "insufficient contiguous attribute locations " |
| 680 | "available for vertex shader input `%s'", |
| 681 | to_assign[i].var->name); |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 682 | return false; |
| 683 | } |
| 684 | |
| 685 | to_assign[i].var->location = VERT_ATTRIB_GENERIC0 + location; |
| 686 | used_locations |= (use_mask << location); |
| 687 | } |
| 688 | |
| 689 | return true; |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | |
| 693 | void |
Ian Romanick | 0e59b26 | 2010-06-23 11:23:01 -0700 | [diff] [blame] | 694 | assign_varying_locations(glsl_shader *producer, glsl_shader *consumer) |
| 695 | { |
| 696 | /* FINISHME: Set dynamically when geometry shader support is added. */ |
| 697 | unsigned output_index = VERT_RESULT_VAR0; |
| 698 | unsigned input_index = FRAG_ATTRIB_VAR0; |
| 699 | |
| 700 | /* Operate in a total of three passes. |
| 701 | * |
| 702 | * 1. Assign locations for any matching inputs and outputs. |
| 703 | * |
| 704 | * 2. Mark output variables in the producer that do not have locations as |
| 705 | * not being outputs. This lets the optimizer eliminate them. |
| 706 | * |
| 707 | * 3. Mark input variables in the consumer that do not have locations as |
| 708 | * not being inputs. This lets the optimizer eliminate them. |
| 709 | */ |
| 710 | |
| 711 | invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0); |
| 712 | invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0); |
| 713 | |
| 714 | foreach_list(node, &producer->ir) { |
| 715 | ir_variable *const output_var = ((ir_instruction *) node)->as_variable(); |
| 716 | |
| 717 | if ((output_var == NULL) || (output_var->mode != ir_var_out) |
| 718 | || (output_var->location != -1)) |
| 719 | continue; |
| 720 | |
| 721 | ir_variable *const input_var = |
| 722 | consumer->symbols->get_variable(output_var->name); |
| 723 | |
| 724 | if ((input_var == NULL) || (input_var->mode != ir_var_in)) |
| 725 | continue; |
| 726 | |
| 727 | assert(input_var->location == -1); |
| 728 | |
| 729 | /* FINISHME: Location assignment will need some changes when arrays, |
| 730 | * FINISHME: matrices, and structures are allowed as shader inputs / |
| 731 | * FINISHME: outputs. |
| 732 | */ |
| 733 | output_var->location = output_index; |
| 734 | input_var->location = input_index; |
| 735 | |
| 736 | output_index++; |
| 737 | input_index++; |
| 738 | } |
| 739 | |
| 740 | foreach_list(node, &producer->ir) { |
| 741 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 742 | |
| 743 | if ((var == NULL) || (var->mode != ir_var_out)) |
| 744 | continue; |
| 745 | |
| 746 | /* An 'out' variable is only really a shader output if its value is read |
| 747 | * by the following stage. |
| 748 | */ |
| 749 | var->shader_out = (var->location != -1); |
| 750 | } |
| 751 | |
| 752 | foreach_list(node, &consumer->ir) { |
| 753 | ir_variable *const var = ((ir_instruction *) node)->as_variable(); |
| 754 | |
| 755 | if ((var == NULL) || (var->mode != ir_var_in)) |
| 756 | continue; |
| 757 | |
| 758 | /* An 'in' variable is only really a shader input if its value is written |
| 759 | * by the previous stage. |
| 760 | */ |
| 761 | var->shader_in = (var->location != -1); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | |
| 766 | void |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 767 | link_shaders(struct glsl_program *prog) |
| 768 | { |
| 769 | prog->LinkStatus = false; |
| 770 | prog->Validated = false; |
| 771 | prog->_Used = false; |
| 772 | |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 773 | if (prog->InfoLog != NULL) |
| 774 | talloc_free(prog->InfoLog); |
| 775 | |
| 776 | prog->InfoLog = talloc_strdup(NULL, ""); |
| 777 | |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 778 | /* Separate the shaders into groups based on their type. |
| 779 | */ |
| 780 | struct glsl_shader **vert_shader_list; |
| 781 | unsigned num_vert_shaders = 0; |
| 782 | struct glsl_shader **frag_shader_list; |
| 783 | unsigned num_frag_shaders = 0; |
| 784 | |
| 785 | vert_shader_list = (struct glsl_shader **) |
Kenneth Graunke | c186b3f | 2010-06-17 15:37:26 -0700 | [diff] [blame] | 786 | calloc(2 * prog->NumShaders, sizeof(struct glsl_shader *)); |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 787 | frag_shader_list = &vert_shader_list[prog->NumShaders]; |
| 788 | |
| 789 | for (unsigned i = 0; i < prog->NumShaders; i++) { |
| 790 | switch (prog->Shaders[i]->Type) { |
| 791 | case GL_VERTEX_SHADER: |
| 792 | vert_shader_list[num_vert_shaders] = prog->Shaders[i]; |
| 793 | num_vert_shaders++; |
| 794 | break; |
| 795 | case GL_FRAGMENT_SHADER: |
| 796 | frag_shader_list[num_frag_shaders] = prog->Shaders[i]; |
| 797 | num_frag_shaders++; |
| 798 | break; |
| 799 | case GL_GEOMETRY_SHADER: |
| 800 | /* FINISHME: Support geometry shaders. */ |
| 801 | assert(prog->Shaders[i]->Type != GL_GEOMETRY_SHADER); |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | /* FINISHME: Implement intra-stage linking. */ |
| 807 | assert(num_vert_shaders <= 1); |
| 808 | assert(num_frag_shaders <= 1); |
| 809 | |
| 810 | /* Verify that each of the per-target executables is valid. |
| 811 | */ |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 812 | if (!validate_vertex_shader_executable(prog, vert_shader_list[0]) |
| 813 | || !validate_fragment_shader_executable(prog, frag_shader_list[0])) |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 814 | goto done; |
| 815 | |
| 816 | |
| 817 | /* FINISHME: Perform inter-stage linking. */ |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 818 | prog->_LinkedShaders = (struct glsl_shader **) |
| 819 | calloc(2, sizeof(struct glsl_shader *)); |
| 820 | prog->_NumLinkedShaders = 0; |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 821 | |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 822 | if (num_vert_shaders > 0) { |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 823 | prog->_LinkedShaders[prog->_NumLinkedShaders] = vert_shader_list[0]; |
| 824 | prog->_NumLinkedShaders++; |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | if (num_frag_shaders > 0) { |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 828 | prog->_LinkedShaders[prog->_NumLinkedShaders] = frag_shader_list[0]; |
| 829 | prog->_NumLinkedShaders++; |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Ian Romanick | ed1fe3d | 2010-06-23 12:09:14 -0700 | [diff] [blame] | 832 | if (cross_validate_uniforms(prog)) { |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 833 | /* Validate the inputs of each stage with the output of the preceeding |
| 834 | * stage. |
| 835 | */ |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 836 | for (unsigned i = 1; i < prog->_NumLinkedShaders; i++) { |
Ian Romanick | f36460e | 2010-06-23 12:07:22 -0700 | [diff] [blame] | 837 | if (!cross_validate_outputs_to_inputs(prog, |
| 838 | prog->_LinkedShaders[i - 1], |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 839 | prog->_LinkedShaders[i])) |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 840 | goto done; |
| 841 | } |
| 842 | |
Ian Romanick | cc22c5a | 2010-06-18 17:13:42 -0700 | [diff] [blame] | 843 | prog->LinkStatus = true; |
Ian Romanick | 3710192 | 2010-06-18 19:02:10 -0700 | [diff] [blame] | 844 | } |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 845 | |
Ian Romanick | 13e10e4 | 2010-06-21 12:03:24 -0700 | [diff] [blame] | 846 | /* FINISHME: Perform whole-program optimization here. */ |
| 847 | |
Ian Romanick | abee16e | 2010-06-21 16:16:05 -0700 | [diff] [blame] | 848 | assign_uniform_locations(prog); |
Ian Romanick | 13e10e4 | 2010-06-21 12:03:24 -0700 | [diff] [blame] | 849 | |
Ian Romanick | 0ad22cd | 2010-06-21 17:18:31 -0700 | [diff] [blame] | 850 | if (prog->_LinkedShaders[0]->Type == GL_VERTEX_SHADER) |
Ian Romanick | 9342d26 | 2010-06-22 17:41:37 -0700 | [diff] [blame] | 851 | /* FINISHME: The value of the max_attribute_index parameter is |
| 852 | * FINISHME: implementation dependent based on the value of |
| 853 | * FINISHME: GL_MAX_VERTEX_ATTRIBS. GL_MAX_VERTEX_ATTRIBS must be |
| 854 | * FINISHME: at least 16, so hardcode 16 for now. |
| 855 | */ |
Ian Romanick | 553dcdc | 2010-06-23 12:14:02 -0700 | [diff] [blame^] | 856 | if (!assign_attribute_locations(prog, 16)) |
Ian Romanick | 6984670 | 2010-06-22 17:29:19 -0700 | [diff] [blame] | 857 | goto done; |
Ian Romanick | 13e10e4 | 2010-06-21 12:03:24 -0700 | [diff] [blame] | 858 | |
Ian Romanick | 0e59b26 | 2010-06-23 11:23:01 -0700 | [diff] [blame] | 859 | for (unsigned i = 1; i < prog->_NumLinkedShaders; i++) |
| 860 | assign_varying_locations(prog->_LinkedShaders[i - 1], |
| 861 | prog->_LinkedShaders[i]); |
Ian Romanick | 13e10e4 | 2010-06-21 12:03:24 -0700 | [diff] [blame] | 862 | |
| 863 | /* FINISHME: Assign fragment shader output locations. */ |
| 864 | |
| 865 | /* FINISHME: Generate code here. */ |
| 866 | |
Ian Romanick | 832dfa5 | 2010-06-17 15:04:20 -0700 | [diff] [blame] | 867 | done: |
| 868 | free(vert_shader_list); |
| 869 | } |