glsl: Rename uniform_field_visitor to program_resource_visitor.
[mesa.git] / src / glsl / link_uniforms.cpp
1 /*
2 * Copyright © 2011 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 #include "main/core.h"
25 #include "ir.h"
26 #include "linker.h"
27 #include "ir_uniform.h"
28 #include "glsl_symbol_table.h"
29 #include "program/hash_table.h"
30 #include "program.h"
31
32 /**
33 * \file link_uniforms.cpp
34 * Assign locations for GLSL uniforms.
35 *
36 * \author Ian Romanick <ian.d.romanick@intel.com>
37 */
38
39 /**
40 * Count the backing storage requirements for a type
41 */
42 static unsigned
43 values_for_type(const glsl_type *type)
44 {
45 if (type->is_sampler()) {
46 return 1;
47 } else if (type->is_array() && type->fields.array->is_sampler()) {
48 return type->array_size();
49 } else {
50 return type->component_slots();
51 }
52 }
53
54 void
55 program_resource_visitor::process(const glsl_type *type, const char *name)
56 {
57 assert(type->is_record()
58 || (type->is_array() && type->fields.array->is_record())
59 || type->is_interface()
60 || (type->is_array() && type->fields.array->is_interface()));
61
62 char *name_copy = ralloc_strdup(NULL, name);
63 recursion(type, &name_copy, strlen(name), false);
64 ralloc_free(name_copy);
65 }
66
67 void
68 program_resource_visitor::process(ir_variable *var)
69 {
70 const glsl_type *t = var->type;
71
72 /* false is always passed for the row_major parameter to the other
73 * processing functions because no information is available to do
74 * otherwise. See the warning in linker.h.
75 */
76
77 /* Only strdup the name if we actually will need to modify it. */
78 if (t->is_record() || (t->is_array() && t->fields.array->is_record())) {
79 char *name = ralloc_strdup(NULL, var->name);
80 recursion(var->type, &name, strlen(name), false);
81 ralloc_free(name);
82 } else if (t->is_interface()) {
83 char *name = ralloc_strdup(NULL, var->type->name);
84 recursion(var->type, &name, strlen(name), false);
85 ralloc_free(name);
86 } else if (t->is_array() && t->fields.array->is_interface()) {
87 char *name = ralloc_strdup(NULL, var->type->fields.array->name);
88 recursion(var->type, &name, strlen(name), false);
89 ralloc_free(name);
90 } else {
91 this->visit_field(t, var->name, false);
92 }
93 }
94
95 void
96 program_resource_visitor::recursion(const glsl_type *t, char **name,
97 size_t name_length, bool row_major)
98 {
99 /* Records need to have each field processed individually.
100 *
101 * Arrays of records need to have each array element processed
102 * individually, then each field of the resulting array elements processed
103 * individually.
104 */
105 if (t->is_record() || t->is_interface()) {
106 for (unsigned i = 0; i < t->length; i++) {
107 const char *field = t->fields.structure[i].name;
108 size_t new_length = name_length;
109
110 if (t->fields.structure[i].type->is_record())
111 this->visit_field(&t->fields.structure[i]);
112
113 /* Append '.field' to the current variable name. */
114 if (name_length == 0) {
115 ralloc_asprintf_rewrite_tail(name, &new_length, "%s", field);
116 } else {
117 ralloc_asprintf_rewrite_tail(name, &new_length, ".%s", field);
118 }
119
120 recursion(t->fields.structure[i].type, name, new_length,
121 t->fields.structure[i].row_major);
122 }
123 } else if (t->is_array() && (t->fields.array->is_record()
124 || t->fields.array->is_interface())) {
125 for (unsigned i = 0; i < t->length; i++) {
126 size_t new_length = name_length;
127
128 /* Append the subscript to the current variable name */
129 ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", i);
130
131 recursion(t->fields.array, name, new_length,
132 t->fields.structure[i].row_major);
133 }
134 } else {
135 this->visit_field(t, *name, row_major);
136 }
137 }
138
139 void
140 program_resource_visitor::visit_field(const glsl_struct_field *field)
141 {
142 (void) field;
143 /* empty */
144 }
145
146 /**
147 * Class to help calculate the storage requirements for a set of uniforms
148 *
149 * As uniforms are added to the active set the number of active uniforms and
150 * the storage requirements for those uniforms are accumulated. The active
151 * uniforms are added the the hash table supplied to the constructor.
152 *
153 * If the same uniform is added multiple times (i.e., once for each shader
154 * target), it will only be accounted once.
155 */
156 class count_uniform_size : public program_resource_visitor {
157 public:
158 count_uniform_size(struct string_to_uint_map *map)
159 : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
160 num_shader_uniform_components(0), map(map)
161 {
162 /* empty */
163 }
164
165 void start_shader()
166 {
167 this->num_shader_samplers = 0;
168 this->num_shader_uniform_components = 0;
169 }
170
171 void process(ir_variable *var)
172 {
173 if (var->is_interface_instance())
174 program_resource_visitor::process(var->interface_type,
175 var->interface_type->name);
176 else
177 program_resource_visitor::process(var);
178 }
179
180 /**
181 * Total number of active uniforms counted
182 */
183 unsigned num_active_uniforms;
184
185 /**
186 * Number of data values required to back the storage for the active uniforms
187 */
188 unsigned num_values;
189
190 /**
191 * Number of samplers used
192 */
193 unsigned num_shader_samplers;
194
195 /**
196 * Number of uniforms used in the current shader
197 */
198 unsigned num_shader_uniform_components;
199
200 private:
201 virtual void visit_field(const glsl_type *type, const char *name,
202 bool row_major)
203 {
204 assert(!type->is_record());
205 assert(!(type->is_array() && type->fields.array->is_record()));
206 assert(!type->is_interface());
207 assert(!(type->is_array() && type->fields.array->is_interface()));
208
209 (void) row_major;
210
211 /* Count the number of samplers regardless of whether the uniform is
212 * already in the hash table. The hash table prevents adding the same
213 * uniform for multiple shader targets, but in this case we want to
214 * count it for each shader target.
215 */
216 const unsigned values = values_for_type(type);
217 if (type->contains_sampler()) {
218 this->num_shader_samplers +=
219 type->is_array() ? type->array_size() : 1;
220 } else {
221 /* Accumulate the total number of uniform slots used by this shader.
222 * Note that samplers do not count against this limit because they
223 * don't use any storage on current hardware.
224 */
225 this->num_shader_uniform_components += values;
226 }
227
228 /* If the uniform is already in the map, there's nothing more to do.
229 */
230 unsigned id;
231 if (this->map->get(id, name))
232 return;
233
234 this->map->put(this->num_active_uniforms, name);
235
236 /* Each leaf uniform occupies one entry in the list of active
237 * uniforms.
238 */
239 this->num_active_uniforms++;
240 this->num_values += values;
241 }
242
243 struct string_to_uint_map *map;
244 };
245
246 /**
247 * Class to help parcel out pieces of backing storage to uniforms
248 *
249 * Each uniform processed has some range of the \c gl_constant_value
250 * structures associated with it. The association is done by finding
251 * the uniform in the \c string_to_uint_map and using the value from
252 * the map to connect that slot in the \c gl_uniform_storage table
253 * with the next available slot in the \c gl_constant_value array.
254 *
255 * \warning
256 * This class assumes that every uniform that will be processed is
257 * already in the \c string_to_uint_map. In addition, it assumes that
258 * the \c gl_uniform_storage and \c gl_constant_value arrays are "big
259 * enough."
260 */
261 class parcel_out_uniform_storage : public program_resource_visitor {
262 public:
263 parcel_out_uniform_storage(struct string_to_uint_map *map,
264 struct gl_uniform_storage *uniforms,
265 union gl_constant_value *values)
266 : map(map), uniforms(uniforms), next_sampler(0), values(values)
267 {
268 memset(this->targets, 0, sizeof(this->targets));
269 }
270
271 void start_shader()
272 {
273 this->shader_samplers_used = 0;
274 this->shader_shadow_samplers = 0;
275 }
276
277 void set_and_process(struct gl_shader_program *prog,
278 ir_variable *var)
279 {
280 ubo_block_index = -1;
281 if (var->is_in_uniform_block()) {
282 if (var->is_interface_instance() && var->type->is_array()) {
283 unsigned l = strlen(var->interface_type->name);
284
285 for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
286 if (strncmp(var->interface_type->name,
287 prog->UniformBlocks[i].Name,
288 l) == 0
289 && prog->UniformBlocks[i].Name[l] == '[') {
290 ubo_block_index = i;
291 break;
292 }
293 }
294 } else {
295 for (unsigned i = 0; i < prog->NumUniformBlocks; i++) {
296 if (strcmp(var->interface_type->name,
297 prog->UniformBlocks[i].Name) == 0) {
298 ubo_block_index = i;
299 break;
300 }
301 }
302 }
303 assert(ubo_block_index != -1);
304
305 /* Uniform blocks that were specified with an instance name must be
306 * handled a little bit differently. The name of the variable is the
307 * name used to reference the uniform block instead of being the name
308 * of a variable within the block. Therefore, searching for the name
309 * within the block will fail.
310 */
311 if (var->is_interface_instance()) {
312 ubo_byte_offset = 0;
313 ubo_row_major = false;
314 } else {
315 const struct gl_uniform_block *const block =
316 &prog->UniformBlocks[ubo_block_index];
317
318 assert(var->location != -1);
319
320 const struct gl_uniform_buffer_variable *const ubo_var =
321 &block->Uniforms[var->location];
322
323 ubo_row_major = ubo_var->RowMajor;
324 ubo_byte_offset = ubo_var->Offset;
325 }
326
327 if (var->is_interface_instance())
328 process(var->interface_type, var->interface_type->name);
329 else
330 process(var);
331 } else
332 process(var);
333 }
334
335 int ubo_block_index;
336 int ubo_byte_offset;
337 bool ubo_row_major;
338
339 private:
340 virtual void visit_field(const glsl_type *type, const char *name,
341 bool row_major)
342 {
343 assert(!type->is_record());
344 assert(!(type->is_array() && type->fields.array->is_record()));
345 assert(!type->is_interface());
346 assert(!(type->is_array() && type->fields.array->is_interface()));
347
348 (void) row_major;
349
350 unsigned id;
351 bool found = this->map->get(id, name);
352 assert(found);
353
354 if (!found)
355 return;
356
357 /* If there is already storage associated with this uniform, it means
358 * that it was set while processing an earlier shader stage. For
359 * example, we may be processing the uniform in the fragment shader, but
360 * the uniform was already processed in the vertex shader.
361 */
362 if (this->uniforms[id].storage != NULL) {
363 /* If the uniform already has storage set from another shader stage,
364 * mark the samplers used for this shader stage.
365 */
366 if (type->contains_sampler()) {
367 const unsigned count = MAX2(1, this->uniforms[id].array_elements);
368 const unsigned shadow = (type->is_array())
369 ? type->fields.array->sampler_shadow : type->sampler_shadow;
370
371 for (unsigned i = 0; i < count; i++) {
372 const unsigned s = this->uniforms[id].sampler + i;
373
374 this->shader_samplers_used |= 1U << s;
375 this->shader_shadow_samplers |= shadow << s;
376 }
377 }
378
379 return;
380 }
381
382 const glsl_type *base_type;
383 if (type->is_array()) {
384 this->uniforms[id].array_elements = type->length;
385 base_type = type->fields.array;
386 } else {
387 this->uniforms[id].array_elements = 0;
388 base_type = type;
389 }
390
391 if (base_type->is_sampler()) {
392 this->uniforms[id].sampler = this->next_sampler;
393
394 /* Increment the sampler by 1 for non-arrays and by the number of
395 * array elements for arrays.
396 */
397 this->next_sampler += MAX2(1, this->uniforms[id].array_elements);
398
399 const gl_texture_index target = base_type->sampler_index();
400 const unsigned shadow = base_type->sampler_shadow;
401 for (unsigned i = this->uniforms[id].sampler
402 ; i < MIN2(this->next_sampler, MAX_SAMPLERS)
403 ; i++) {
404 this->targets[i] = target;
405 this->shader_samplers_used |= 1U << i;
406 this->shader_shadow_samplers |= shadow << i;
407 }
408
409 } else {
410 this->uniforms[id].sampler = ~0;
411 }
412
413 this->uniforms[id].name = ralloc_strdup(this->uniforms, name);
414 this->uniforms[id].type = base_type;
415 this->uniforms[id].initialized = 0;
416 this->uniforms[id].num_driver_storage = 0;
417 this->uniforms[id].driver_storage = NULL;
418 this->uniforms[id].storage = this->values;
419 if (this->ubo_block_index != -1) {
420 this->uniforms[id].block_index = this->ubo_block_index;
421
422 unsigned alignment = type->std140_base_alignment(ubo_row_major);
423 this->ubo_byte_offset = glsl_align(this->ubo_byte_offset, alignment);
424 this->uniforms[id].offset = this->ubo_byte_offset;
425 this->ubo_byte_offset += type->std140_size(ubo_row_major);
426
427 if (type->is_array()) {
428 this->uniforms[id].array_stride =
429 glsl_align(type->fields.array->std140_size(ubo_row_major), 16);
430 } else {
431 this->uniforms[id].array_stride = 0;
432 }
433
434 if (type->is_matrix() ||
435 (type->is_array() && type->fields.array->is_matrix())) {
436 this->uniforms[id].matrix_stride = 16;
437 this->uniforms[id].row_major = ubo_row_major;
438 } else {
439 this->uniforms[id].matrix_stride = 0;
440 this->uniforms[id].row_major = false;
441 }
442 } else {
443 this->uniforms[id].block_index = -1;
444 this->uniforms[id].offset = -1;
445 this->uniforms[id].array_stride = -1;
446 this->uniforms[id].matrix_stride = -1;
447 this->uniforms[id].row_major = false;
448 }
449
450 this->values += values_for_type(type);
451 }
452
453 struct string_to_uint_map *map;
454
455 struct gl_uniform_storage *uniforms;
456 unsigned next_sampler;
457
458 public:
459 union gl_constant_value *values;
460
461 gl_texture_index targets[MAX_SAMPLERS];
462
463 /**
464 * Mask of samplers used by the current shader stage.
465 */
466 unsigned shader_samplers_used;
467
468 /**
469 * Mask of samplers used by the current shader stage for shadows.
470 */
471 unsigned shader_shadow_samplers;
472 };
473
474 /**
475 * Merges a uniform block into an array of uniform blocks that may or
476 * may not already contain a copy of it.
477 *
478 * Returns the index of the new block in the array.
479 */
480 int
481 link_cross_validate_uniform_block(void *mem_ctx,
482 struct gl_uniform_block **linked_blocks,
483 unsigned int *num_linked_blocks,
484 struct gl_uniform_block *new_block)
485 {
486 for (unsigned int i = 0; i < *num_linked_blocks; i++) {
487 struct gl_uniform_block *old_block = &(*linked_blocks)[i];
488
489 if (strcmp(old_block->Name, new_block->Name) == 0)
490 return link_uniform_blocks_are_compatible(old_block, new_block)
491 ? i : -1;
492 }
493
494 *linked_blocks = reralloc(mem_ctx, *linked_blocks,
495 struct gl_uniform_block,
496 *num_linked_blocks + 1);
497 int linked_block_index = (*num_linked_blocks)++;
498 struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index];
499
500 memcpy(linked_block, new_block, sizeof(*new_block));
501 linked_block->Uniforms = ralloc_array(*linked_blocks,
502 struct gl_uniform_buffer_variable,
503 linked_block->NumUniforms);
504
505 memcpy(linked_block->Uniforms,
506 new_block->Uniforms,
507 sizeof(*linked_block->Uniforms) * linked_block->NumUniforms);
508
509 for (unsigned int i = 0; i < linked_block->NumUniforms; i++) {
510 struct gl_uniform_buffer_variable *ubo_var =
511 &linked_block->Uniforms[i];
512
513 if (ubo_var->Name == ubo_var->IndexName) {
514 ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
515 ubo_var->IndexName = ubo_var->Name;
516 } else {
517 ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name);
518 ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName);
519 }
520 }
521
522 return linked_block_index;
523 }
524
525 /**
526 * Walks the IR and update the references to uniform blocks in the
527 * ir_variables to point at linked shader's list (previously, they
528 * would point at the uniform block list in one of the pre-linked
529 * shaders).
530 */
531 static void
532 link_update_uniform_buffer_variables(struct gl_shader *shader)
533 {
534 foreach_list(node, shader->ir) {
535 ir_variable *const var = ((ir_instruction *) node)->as_variable();
536
537 if ((var == NULL) || !var->is_in_uniform_block())
538 continue;
539
540 assert(var->mode == ir_var_uniform);
541
542 if (var->is_interface_instance()) {
543 var->location = 0;
544 continue;
545 }
546
547 bool found = false;
548 char sentinel = '\0';
549
550 if (var->type->is_record()) {
551 sentinel = '.';
552 } else if (var->type->is_array()
553 && var->type->fields.array->is_record()) {
554 sentinel = '[';
555 }
556
557 const unsigned l = strlen(var->name);
558 for (unsigned i = 0; i < shader->NumUniformBlocks; i++) {
559 for (unsigned j = 0; j < shader->UniformBlocks[i].NumUniforms; j++) {
560 if (sentinel) {
561 const char *begin = shader->UniformBlocks[i].Uniforms[j].Name;
562 const char *end = strchr(begin, sentinel);
563
564 if (end == NULL)
565 continue;
566
567 if (l != (end - begin))
568 continue;
569
570 if (strncmp(var->name, begin, l) == 0) {
571 found = true;
572 var->location = j;
573 break;
574 }
575 } else if (!strcmp(var->name,
576 shader->UniformBlocks[i].Uniforms[j].Name)) {
577 found = true;
578 var->location = j;
579 break;
580 }
581 }
582 if (found)
583 break;
584 }
585 assert(found);
586 }
587 }
588
589 void
590 link_assign_uniform_block_offsets(struct gl_shader *shader)
591 {
592 for (unsigned b = 0; b < shader->NumUniformBlocks; b++) {
593 struct gl_uniform_block *block = &shader->UniformBlocks[b];
594
595 unsigned offset = 0;
596 for (unsigned int i = 0; i < block->NumUniforms; i++) {
597 struct gl_uniform_buffer_variable *ubo_var = &block->Uniforms[i];
598 const struct glsl_type *type = ubo_var->Type;
599
600 unsigned alignment = type->std140_base_alignment(ubo_var->RowMajor);
601 unsigned size = type->std140_size(ubo_var->RowMajor);
602
603 offset = glsl_align(offset, alignment);
604 ubo_var->Offset = offset;
605 offset += size;
606 }
607
608 /* From the GL_ARB_uniform_buffer_object spec:
609 *
610 * "For uniform blocks laid out according to [std140] rules,
611 * the minimum buffer object size returned by the
612 * UNIFORM_BLOCK_DATA_SIZE query is derived by taking the
613 * offset of the last basic machine unit consumed by the
614 * last uniform of the uniform block (including any
615 * end-of-array or end-of-structure padding), adding one,
616 * and rounding up to the next multiple of the base
617 * alignment required for a vec4."
618 */
619 block->UniformBufferSize = glsl_align(offset, 16);
620 }
621 }
622
623 void
624 link_assign_uniform_locations(struct gl_shader_program *prog)
625 {
626 ralloc_free(prog->UniformStorage);
627 prog->UniformStorage = NULL;
628 prog->NumUserUniformStorage = 0;
629
630 if (prog->UniformHash != NULL) {
631 prog->UniformHash->clear();
632 } else {
633 prog->UniformHash = new string_to_uint_map;
634 }
635
636 /* Uniforms that lack an initializer in the shader code have an initial
637 * value of zero. This includes sampler uniforms.
638 *
639 * Page 24 (page 30 of the PDF) of the GLSL 1.20 spec says:
640 *
641 * "The link time initial value is either the value of the variable's
642 * initializer, if present, or 0 if no initializer is present. Sampler
643 * types cannot have initializers."
644 */
645 memset(prog->SamplerUnits, 0, sizeof(prog->SamplerUnits));
646
647 /* First pass: Count the uniform resources used by the user-defined
648 * uniforms. While this happens, each active uniform will have an index
649 * assigned to it.
650 *
651 * Note: this is *NOT* the index that is returned to the application by
652 * glGetUniformLocation.
653 */
654 count_uniform_size uniform_size(prog->UniformHash);
655 for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
656 if (prog->_LinkedShaders[i] == NULL)
657 continue;
658
659 link_update_uniform_buffer_variables(prog->_LinkedShaders[i]);
660
661 /* Reset various per-shader target counts.
662 */
663 uniform_size.start_shader();
664
665 foreach_list(node, prog->_LinkedShaders[i]->ir) {
666 ir_variable *const var = ((ir_instruction *) node)->as_variable();
667
668 if ((var == NULL) || (var->mode != ir_var_uniform))
669 continue;
670
671 /* FINISHME: Update code to process built-in uniforms!
672 */
673 if (strncmp("gl_", var->name, 3) == 0) {
674 uniform_size.num_shader_uniform_components +=
675 var->type->component_slots();
676 continue;
677 }
678
679 uniform_size.process(var);
680 }
681
682 prog->_LinkedShaders[i]->num_samplers = uniform_size.num_shader_samplers;
683 prog->_LinkedShaders[i]->num_uniform_components =
684 uniform_size.num_shader_uniform_components;
685 }
686
687 const unsigned num_user_uniforms = uniform_size.num_active_uniforms;
688 const unsigned num_data_slots = uniform_size.num_values;
689
690 /* On the outside chance that there were no uniforms, bail out.
691 */
692 if (num_user_uniforms == 0)
693 return;
694
695 struct gl_uniform_storage *uniforms =
696 rzalloc_array(prog, struct gl_uniform_storage, num_user_uniforms);
697 union gl_constant_value *data =
698 rzalloc_array(uniforms, union gl_constant_value, num_data_slots);
699 #ifndef NDEBUG
700 union gl_constant_value *data_end = &data[num_data_slots];
701 #endif
702
703 parcel_out_uniform_storage parcel(prog->UniformHash, uniforms, data);
704
705 for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
706 if (prog->_LinkedShaders[i] == NULL)
707 continue;
708
709 /* Reset various per-shader target counts.
710 */
711 parcel.start_shader();
712
713 foreach_list(node, prog->_LinkedShaders[i]->ir) {
714 ir_variable *const var = ((ir_instruction *) node)->as_variable();
715
716 if ((var == NULL) || (var->mode != ir_var_uniform))
717 continue;
718
719 /* FINISHME: Update code to process built-in uniforms!
720 */
721 if (strncmp("gl_", var->name, 3) == 0)
722 continue;
723
724 parcel.set_and_process(prog, var);
725 }
726
727 prog->_LinkedShaders[i]->active_samplers = parcel.shader_samplers_used;
728 prog->_LinkedShaders[i]->shadow_samplers = parcel.shader_shadow_samplers;
729 }
730
731 assert(sizeof(prog->SamplerTargets) == sizeof(parcel.targets));
732 memcpy(prog->SamplerTargets, parcel.targets, sizeof(prog->SamplerTargets));
733
734 #ifndef NDEBUG
735 for (unsigned i = 0; i < num_user_uniforms; i++) {
736 assert(uniforms[i].storage != NULL);
737 }
738
739 assert(parcel.values == data_end);
740 #endif
741
742 prog->NumUserUniformStorage = num_user_uniforms;
743 prog->UniformStorage = uniforms;
744
745 link_set_uniform_initializers(prog);
746
747 return;
748 }