2 * Copyright © 2011 Intel Corporation
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:
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
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.
24 #include "main/core.h"
27 #include "ir_uniform.h"
28 #include "glsl_symbol_table.h"
29 #include "program/hash_table.h"
33 * \file link_uniforms.cpp
34 * Assign locations for GLSL uniforms.
36 * \author Ian Romanick <ian.d.romanick@intel.com>
40 * Count the backing storage requirements for a type
43 values_for_type(const glsl_type
*type
)
45 if (type
->is_sampler()) {
47 } else if (type
->is_array() && type
->fields
.array
->is_sampler()) {
48 return type
->array_size();
50 return type
->component_slots();
55 program_resource_visitor::process(const glsl_type
*type
, const char *name
)
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()));
62 char *name_copy
= ralloc_strdup(NULL
, name
);
63 recursion(type
, &name_copy
, strlen(name
), false, NULL
);
64 ralloc_free(name_copy
);
68 program_resource_visitor::process(ir_variable
*var
)
70 const glsl_type
*t
= var
->type
;
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.
77 /* Only strdup the name if we actually will need to modify it. */
78 if (var
->data
.from_named_ifc_block_array
) {
79 /* lower_named_interface_blocks created this variable by lowering an
80 * interface block array to an array variable. For example if the
81 * original source code was:
83 * out Blk { vec4 bar } foo[3];
85 * Then the variable is now:
89 * We need to visit each array element using the names constructed like
96 assert(t
->is_array());
97 const glsl_type
*ifc_type
= var
->get_interface_type();
98 char *name
= ralloc_strdup(NULL
, ifc_type
->name
);
99 size_t name_length
= strlen(name
);
100 for (unsigned i
= 0; i
< t
->length
; i
++) {
101 size_t new_length
= name_length
;
102 ralloc_asprintf_rewrite_tail(&name
, &new_length
, "[%u].%s", i
,
104 /* Note: row_major is only meaningful for uniform blocks, and
105 * lowering is only applied to non-uniform interface blocks, so we
106 * can safely pass false for row_major.
108 recursion(var
->type
, &name
, new_length
, false, NULL
);
111 } else if (var
->data
.from_named_ifc_block_nonarray
) {
112 /* lower_named_interface_blocks created this variable by lowering a
113 * named interface block (non-array) to an ordinary variable. For
114 * example if the original source code was:
116 * out Blk { vec4 bar } foo;
118 * Then the variable is now:
122 * We need to visit this variable using the name:
126 const glsl_type
*ifc_type
= var
->get_interface_type();
127 char *name
= ralloc_asprintf(NULL
, "%s.%s", ifc_type
->name
, var
->name
);
128 /* Note: row_major is only meaningful for uniform blocks, and lowering
129 * is only applied to non-uniform interface blocks, so we can safely
130 * pass false for row_major.
132 recursion(var
->type
, &name
, strlen(name
), false, NULL
);
134 } else if (t
->is_record() || (t
->is_array() && t
->fields
.array
->is_record())) {
135 char *name
= ralloc_strdup(NULL
, var
->name
);
136 recursion(var
->type
, &name
, strlen(name
), false, NULL
);
138 } else if (t
->is_interface()) {
139 char *name
= ralloc_strdup(NULL
, var
->type
->name
);
140 recursion(var
->type
, &name
, strlen(name
), false, NULL
);
142 } else if (t
->is_array() && t
->fields
.array
->is_interface()) {
143 char *name
= ralloc_strdup(NULL
, var
->type
->fields
.array
->name
);
144 recursion(var
->type
, &name
, strlen(name
), false, NULL
);
147 this->visit_field(t
, var
->name
, false, NULL
);
152 program_resource_visitor::recursion(const glsl_type
*t
, char **name
,
153 size_t name_length
, bool row_major
,
154 const glsl_type
*record_type
)
156 /* Records need to have each field processed individually.
158 * Arrays of records need to have each array element processed
159 * individually, then each field of the resulting array elements processed
162 if (t
->is_record() || t
->is_interface()) {
163 if (record_type
== NULL
&& t
->is_record())
166 for (unsigned i
= 0; i
< t
->length
; i
++) {
167 const char *field
= t
->fields
.structure
[i
].name
;
168 size_t new_length
= name_length
;
170 if (t
->fields
.structure
[i
].type
->is_record())
171 this->visit_field(&t
->fields
.structure
[i
]);
173 /* Append '.field' to the current variable name. */
174 if (name_length
== 0) {
175 ralloc_asprintf_rewrite_tail(name
, &new_length
, "%s", field
);
177 ralloc_asprintf_rewrite_tail(name
, &new_length
, ".%s", field
);
180 recursion(t
->fields
.structure
[i
].type
, name
, new_length
,
181 t
->fields
.structure
[i
].row_major
, record_type
);
183 /* Only the first leaf-field of the record gets called with the
184 * record type pointer.
188 } else if (t
->is_array() && (t
->fields
.array
->is_record()
189 || t
->fields
.array
->is_interface())) {
190 if (record_type
== NULL
&& t
->fields
.array
->is_record())
191 record_type
= t
->fields
.array
;
193 for (unsigned i
= 0; i
< t
->length
; i
++) {
194 size_t new_length
= name_length
;
196 /* Append the subscript to the current variable name */
197 ralloc_asprintf_rewrite_tail(name
, &new_length
, "[%u]", i
);
199 recursion(t
->fields
.array
, name
, new_length
, row_major
,
202 /* Only the first leaf-field of the record gets called with the
203 * record type pointer.
208 this->visit_field(t
, *name
, row_major
, record_type
);
213 program_resource_visitor::visit_field(const glsl_type
*type
, const char *name
,
215 const glsl_type
*record_type
)
217 visit_field(type
, name
, row_major
);
221 program_resource_visitor::visit_field(const glsl_struct_field
*field
)
230 * Class to help calculate the storage requirements for a set of uniforms
232 * As uniforms are added to the active set the number of active uniforms and
233 * the storage requirements for those uniforms are accumulated. The active
234 * uniforms are added the the hash table supplied to the constructor.
236 * If the same uniform is added multiple times (i.e., once for each shader
237 * target), it will only be accounted once.
239 class count_uniform_size
: public program_resource_visitor
{
241 count_uniform_size(struct string_to_uint_map
*map
)
242 : num_active_uniforms(0), num_values(0), num_shader_samplers(0),
243 num_shader_uniform_components(0), is_ubo_var(false), map(map
)
250 this->num_shader_samplers
= 0;
251 this->num_shader_uniform_components
= 0;
254 void process(ir_variable
*var
)
256 this->is_ubo_var
= var
->is_in_uniform_block();
257 if (var
->is_interface_instance())
258 program_resource_visitor::process(var
->get_interface_type(),
259 var
->get_interface_type()->name
);
261 program_resource_visitor::process(var
);
265 * Total number of active uniforms counted
267 unsigned num_active_uniforms
;
270 * Number of data values required to back the storage for the active uniforms
275 * Number of samplers used
277 unsigned num_shader_samplers
;
280 * Number of uniforms used in the current shader
282 unsigned num_shader_uniform_components
;
287 virtual void visit_field(const glsl_type
*type
, const char *name
,
290 assert(!type
->is_record());
291 assert(!(type
->is_array() && type
->fields
.array
->is_record()));
292 assert(!type
->is_interface());
293 assert(!(type
->is_array() && type
->fields
.array
->is_interface()));
297 /* Count the number of samplers regardless of whether the uniform is
298 * already in the hash table. The hash table prevents adding the same
299 * uniform for multiple shader targets, but in this case we want to
300 * count it for each shader target.
302 const unsigned values
= values_for_type(type
);
303 if (type
->contains_sampler()) {
304 this->num_shader_samplers
+=
305 type
->is_array() ? type
->array_size() : 1;
307 /* Accumulate the total number of uniform slots used by this shader.
308 * Note that samplers do not count against this limit because they
309 * don't use any storage on current hardware.
312 this->num_shader_uniform_components
+= values
;
315 /* If the uniform is already in the map, there's nothing more to do.
318 if (this->map
->get(id
, name
))
321 this->map
->put(this->num_active_uniforms
, name
);
323 /* Each leaf uniform occupies one entry in the list of active
326 this->num_active_uniforms
++;
327 this->num_values
+= values
;
330 struct string_to_uint_map
*map
;
333 } /* anonymous namespace */
336 * Class to help parcel out pieces of backing storage to uniforms
338 * Each uniform processed has some range of the \c gl_constant_value
339 * structures associated with it. The association is done by finding
340 * the uniform in the \c string_to_uint_map and using the value from
341 * the map to connect that slot in the \c gl_uniform_storage table
342 * with the next available slot in the \c gl_constant_value array.
345 * This class assumes that every uniform that will be processed is
346 * already in the \c string_to_uint_map. In addition, it assumes that
347 * the \c gl_uniform_storage and \c gl_constant_value arrays are "big
350 class parcel_out_uniform_storage
: public program_resource_visitor
{
352 parcel_out_uniform_storage(struct string_to_uint_map
*map
,
353 struct gl_uniform_storage
*uniforms
,
354 union gl_constant_value
*values
)
355 : map(map
), uniforms(uniforms
), values(values
)
359 void start_shader(gl_shader_type shader_type
)
361 assert(shader_type
< MESA_SHADER_TYPES
);
362 this->shader_type
= shader_type
;
364 this->shader_samplers_used
= 0;
365 this->shader_shadow_samplers
= 0;
366 this->next_sampler
= 0;
367 memset(this->targets
, 0, sizeof(this->targets
));
370 void set_and_process(struct gl_shader_program
*prog
,
373 ubo_block_index
= -1;
374 if (var
->is_in_uniform_block()) {
375 if (var
->is_interface_instance() && var
->type
->is_array()) {
376 unsigned l
= strlen(var
->get_interface_type()->name
);
378 for (unsigned i
= 0; i
< prog
->NumUniformBlocks
; i
++) {
379 if (strncmp(var
->get_interface_type()->name
,
380 prog
->UniformBlocks
[i
].Name
,
382 && prog
->UniformBlocks
[i
].Name
[l
] == '[') {
388 for (unsigned i
= 0; i
< prog
->NumUniformBlocks
; i
++) {
389 if (strcmp(var
->get_interface_type()->name
,
390 prog
->UniformBlocks
[i
].Name
) == 0) {
396 assert(ubo_block_index
!= -1);
398 /* Uniform blocks that were specified with an instance name must be
399 * handled a little bit differently. The name of the variable is the
400 * name used to reference the uniform block instead of being the name
401 * of a variable within the block. Therefore, searching for the name
402 * within the block will fail.
404 if (var
->is_interface_instance()) {
406 ubo_row_major
= false;
408 const struct gl_uniform_block
*const block
=
409 &prog
->UniformBlocks
[ubo_block_index
];
411 assert(var
->data
.location
!= -1);
413 const struct gl_uniform_buffer_variable
*const ubo_var
=
414 &block
->Uniforms
[var
->data
.location
];
416 ubo_row_major
= ubo_var
->RowMajor
;
417 ubo_byte_offset
= ubo_var
->Offset
;
420 if (var
->is_interface_instance())
421 process(var
->get_interface_type(),
422 var
->get_interface_type()->name
);
432 gl_shader_type shader_type
;
435 void handle_samplers(const glsl_type
*base_type
,
436 struct gl_uniform_storage
*uniform
)
438 if (base_type
->is_sampler()) {
439 uniform
->sampler
[shader_type
].index
= this->next_sampler
;
440 uniform
->sampler
[shader_type
].active
= true;
442 /* Increment the sampler by 1 for non-arrays and by the number of
443 * array elements for arrays.
445 this->next_sampler
+=
446 MAX2(1, uniform
->array_elements
);
448 const gl_texture_index target
= base_type
->sampler_index();
449 const unsigned shadow
= base_type
->sampler_shadow
;
450 for (unsigned i
= uniform
->sampler
[shader_type
].index
;
451 i
< MIN2(this->next_sampler
, MAX_SAMPLERS
);
453 this->targets
[i
] = target
;
454 this->shader_samplers_used
|= 1U << i
;
455 this->shader_shadow_samplers
|= shadow
<< i
;
458 uniform
->sampler
[shader_type
].index
= ~0;
459 uniform
->sampler
[shader_type
].active
= false;
463 virtual void visit_field(const glsl_type
*type
, const char *name
,
469 assert(!"Should not get here.");
472 virtual void visit_field(const glsl_type
*type
, const char *name
,
473 bool row_major
, const glsl_type
*record_type
)
475 assert(!type
->is_record());
476 assert(!(type
->is_array() && type
->fields
.array
->is_record()));
477 assert(!type
->is_interface());
478 assert(!(type
->is_array() && type
->fields
.array
->is_interface()));
483 bool found
= this->map
->get(id
, name
);
489 const glsl_type
*base_type
;
490 if (type
->is_array()) {
491 this->uniforms
[id
].array_elements
= type
->length
;
492 base_type
= type
->fields
.array
;
494 this->uniforms
[id
].array_elements
= 0;
498 /* This assigns sampler uniforms to sampler units. */
499 handle_samplers(base_type
, &this->uniforms
[id
]);
501 /* If there is already storage associated with this uniform, it means
502 * that it was set while processing an earlier shader stage. For
503 * example, we may be processing the uniform in the fragment shader, but
504 * the uniform was already processed in the vertex shader.
506 if (this->uniforms
[id
].storage
!= NULL
) {
510 this->uniforms
[id
].name
= ralloc_strdup(this->uniforms
, name
);
511 this->uniforms
[id
].type
= base_type
;
512 this->uniforms
[id
].initialized
= 0;
513 this->uniforms
[id
].num_driver_storage
= 0;
514 this->uniforms
[id
].driver_storage
= NULL
;
515 this->uniforms
[id
].storage
= this->values
;
516 this->uniforms
[id
].atomic_buffer_index
= -1;
517 if (this->ubo_block_index
!= -1) {
518 this->uniforms
[id
].block_index
= this->ubo_block_index
;
520 const unsigned alignment
= record_type
521 ? record_type
->std140_base_alignment(ubo_row_major
)
522 : type
->std140_base_alignment(ubo_row_major
);
523 this->ubo_byte_offset
= glsl_align(this->ubo_byte_offset
, alignment
);
524 this->uniforms
[id
].offset
= this->ubo_byte_offset
;
525 this->ubo_byte_offset
+= type
->std140_size(ubo_row_major
);
527 if (type
->is_array()) {
528 this->uniforms
[id
].array_stride
=
529 glsl_align(type
->fields
.array
->std140_size(ubo_row_major
), 16);
531 this->uniforms
[id
].array_stride
= 0;
534 if (type
->is_matrix() ||
535 (type
->is_array() && type
->fields
.array
->is_matrix())) {
536 this->uniforms
[id
].matrix_stride
= 16;
537 this->uniforms
[id
].row_major
= ubo_row_major
;
539 this->uniforms
[id
].matrix_stride
= 0;
540 this->uniforms
[id
].row_major
= false;
543 this->uniforms
[id
].block_index
= -1;
544 this->uniforms
[id
].offset
= -1;
545 this->uniforms
[id
].array_stride
= -1;
546 this->uniforms
[id
].matrix_stride
= -1;
547 this->uniforms
[id
].row_major
= false;
550 this->values
+= values_for_type(type
);
553 struct string_to_uint_map
*map
;
555 struct gl_uniform_storage
*uniforms
;
556 unsigned next_sampler
;
559 union gl_constant_value
*values
;
561 gl_texture_index targets
[MAX_SAMPLERS
];
564 * Mask of samplers used by the current shader stage.
566 unsigned shader_samplers_used
;
569 * Mask of samplers used by the current shader stage for shadows.
571 unsigned shader_shadow_samplers
;
575 * Merges a uniform block into an array of uniform blocks that may or
576 * may not already contain a copy of it.
578 * Returns the index of the new block in the array.
581 link_cross_validate_uniform_block(void *mem_ctx
,
582 struct gl_uniform_block
**linked_blocks
,
583 unsigned int *num_linked_blocks
,
584 struct gl_uniform_block
*new_block
)
586 for (unsigned int i
= 0; i
< *num_linked_blocks
; i
++) {
587 struct gl_uniform_block
*old_block
= &(*linked_blocks
)[i
];
589 if (strcmp(old_block
->Name
, new_block
->Name
) == 0)
590 return link_uniform_blocks_are_compatible(old_block
, new_block
)
594 *linked_blocks
= reralloc(mem_ctx
, *linked_blocks
,
595 struct gl_uniform_block
,
596 *num_linked_blocks
+ 1);
597 int linked_block_index
= (*num_linked_blocks
)++;
598 struct gl_uniform_block
*linked_block
= &(*linked_blocks
)[linked_block_index
];
600 memcpy(linked_block
, new_block
, sizeof(*new_block
));
601 linked_block
->Uniforms
= ralloc_array(*linked_blocks
,
602 struct gl_uniform_buffer_variable
,
603 linked_block
->NumUniforms
);
605 memcpy(linked_block
->Uniforms
,
607 sizeof(*linked_block
->Uniforms
) * linked_block
->NumUniforms
);
609 for (unsigned int i
= 0; i
< linked_block
->NumUniforms
; i
++) {
610 struct gl_uniform_buffer_variable
*ubo_var
=
611 &linked_block
->Uniforms
[i
];
613 if (ubo_var
->Name
== ubo_var
->IndexName
) {
614 ubo_var
->Name
= ralloc_strdup(*linked_blocks
, ubo_var
->Name
);
615 ubo_var
->IndexName
= ubo_var
->Name
;
617 ubo_var
->Name
= ralloc_strdup(*linked_blocks
, ubo_var
->Name
);
618 ubo_var
->IndexName
= ralloc_strdup(*linked_blocks
, ubo_var
->IndexName
);
622 return linked_block_index
;
626 * Walks the IR and update the references to uniform blocks in the
627 * ir_variables to point at linked shader's list (previously, they
628 * would point at the uniform block list in one of the pre-linked
632 link_update_uniform_buffer_variables(struct gl_shader
*shader
)
634 foreach_list(node
, shader
->ir
) {
635 ir_variable
*const var
= ((ir_instruction
*) node
)->as_variable();
637 if ((var
== NULL
) || !var
->is_in_uniform_block())
640 assert(var
->data
.mode
== ir_var_uniform
);
642 if (var
->is_interface_instance()) {
643 var
->data
.location
= 0;
648 char sentinel
= '\0';
650 if (var
->type
->is_record()) {
652 } else if (var
->type
->is_array()
653 && var
->type
->fields
.array
->is_record()) {
657 const unsigned l
= strlen(var
->name
);
658 for (unsigned i
= 0; i
< shader
->NumUniformBlocks
; i
++) {
659 for (unsigned j
= 0; j
< shader
->UniformBlocks
[i
].NumUniforms
; j
++) {
661 const char *begin
= shader
->UniformBlocks
[i
].Uniforms
[j
].Name
;
662 const char *end
= strchr(begin
, sentinel
);
667 if (l
!= (end
- begin
))
670 if (strncmp(var
->name
, begin
, l
) == 0) {
672 var
->data
.location
= j
;
675 } else if (!strcmp(var
->name
,
676 shader
->UniformBlocks
[i
].Uniforms
[j
].Name
)) {
678 var
->data
.location
= j
;
690 link_assign_uniform_block_offsets(struct gl_shader
*shader
)
692 for (unsigned b
= 0; b
< shader
->NumUniformBlocks
; b
++) {
693 struct gl_uniform_block
*block
= &shader
->UniformBlocks
[b
];
696 for (unsigned int i
= 0; i
< block
->NumUniforms
; i
++) {
697 struct gl_uniform_buffer_variable
*ubo_var
= &block
->Uniforms
[i
];
698 const struct glsl_type
*type
= ubo_var
->Type
;
700 unsigned alignment
= type
->std140_base_alignment(ubo_var
->RowMajor
);
701 unsigned size
= type
->std140_size(ubo_var
->RowMajor
);
703 offset
= glsl_align(offset
, alignment
);
704 ubo_var
->Offset
= offset
;
708 /* From the GL_ARB_uniform_buffer_object spec:
710 * "For uniform blocks laid out according to [std140] rules,
711 * the minimum buffer object size returned by the
712 * UNIFORM_BLOCK_DATA_SIZE query is derived by taking the
713 * offset of the last basic machine unit consumed by the
714 * last uniform of the uniform block (including any
715 * end-of-array or end-of-structure padding), adding one,
716 * and rounding up to the next multiple of the base
717 * alignment required for a vec4."
719 block
->UniformBufferSize
= glsl_align(offset
, 16);
724 link_assign_uniform_locations(struct gl_shader_program
*prog
)
726 ralloc_free(prog
->UniformStorage
);
727 prog
->UniformStorage
= NULL
;
728 prog
->NumUserUniformStorage
= 0;
730 if (prog
->UniformHash
!= NULL
) {
731 prog
->UniformHash
->clear();
733 prog
->UniformHash
= new string_to_uint_map
;
736 /* First pass: Count the uniform resources used by the user-defined
737 * uniforms. While this happens, each active uniform will have an index
740 * Note: this is *NOT* the index that is returned to the application by
741 * glGetUniformLocation.
743 count_uniform_size
uniform_size(prog
->UniformHash
);
744 for (unsigned i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
745 struct gl_shader
*sh
= prog
->_LinkedShaders
[i
];
750 /* Uniforms that lack an initializer in the shader code have an initial
751 * value of zero. This includes sampler uniforms.
753 * Page 24 (page 30 of the PDF) of the GLSL 1.20 spec says:
755 * "The link time initial value is either the value of the variable's
756 * initializer, if present, or 0 if no initializer is present. Sampler
757 * types cannot have initializers."
759 memset(sh
->SamplerUnits
, 0, sizeof(sh
->SamplerUnits
));
761 link_update_uniform_buffer_variables(sh
);
763 /* Reset various per-shader target counts.
765 uniform_size
.start_shader();
767 foreach_list(node
, sh
->ir
) {
768 ir_variable
*const var
= ((ir_instruction
*) node
)->as_variable();
770 if ((var
== NULL
) || (var
->data
.mode
!= ir_var_uniform
))
773 /* FINISHME: Update code to process built-in uniforms!
775 if (strncmp("gl_", var
->name
, 3) == 0) {
776 uniform_size
.num_shader_uniform_components
+=
777 var
->type
->component_slots();
781 uniform_size
.process(var
);
784 sh
->num_samplers
= uniform_size
.num_shader_samplers
;
785 sh
->num_uniform_components
= uniform_size
.num_shader_uniform_components
;
787 sh
->num_combined_uniform_components
= sh
->num_uniform_components
;
788 for (unsigned i
= 0; i
< sh
->NumUniformBlocks
; i
++) {
789 sh
->num_combined_uniform_components
+=
790 sh
->UniformBlocks
[i
].UniformBufferSize
/ 4;
794 const unsigned num_user_uniforms
= uniform_size
.num_active_uniforms
;
795 const unsigned num_data_slots
= uniform_size
.num_values
;
797 /* On the outside chance that there were no uniforms, bail out.
799 if (num_user_uniforms
== 0)
802 struct gl_uniform_storage
*uniforms
=
803 rzalloc_array(prog
, struct gl_uniform_storage
, num_user_uniforms
);
804 union gl_constant_value
*data
=
805 rzalloc_array(uniforms
, union gl_constant_value
, num_data_slots
);
807 union gl_constant_value
*data_end
= &data
[num_data_slots
];
810 parcel_out_uniform_storage
parcel(prog
->UniformHash
, uniforms
, data
);
812 for (unsigned i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
813 if (prog
->_LinkedShaders
[i
] == NULL
)
816 parcel
.start_shader((gl_shader_type
)i
);
818 foreach_list(node
, prog
->_LinkedShaders
[i
]->ir
) {
819 ir_variable
*const var
= ((ir_instruction
*) node
)->as_variable();
821 if ((var
== NULL
) || (var
->data
.mode
!= ir_var_uniform
))
824 /* FINISHME: Update code to process built-in uniforms!
826 if (strncmp("gl_", var
->name
, 3) == 0)
829 parcel
.set_and_process(prog
, var
);
832 prog
->_LinkedShaders
[i
]->active_samplers
= parcel
.shader_samplers_used
;
833 prog
->_LinkedShaders
[i
]->shadow_samplers
= parcel
.shader_shadow_samplers
;
835 STATIC_ASSERT(sizeof(prog
->_LinkedShaders
[i
]->SamplerTargets
) == sizeof(parcel
.targets
));
836 memcpy(prog
->_LinkedShaders
[i
]->SamplerTargets
, parcel
.targets
,
837 sizeof(prog
->_LinkedShaders
[i
]->SamplerTargets
));
840 /* Determine the size of the largest uniform array queryable via
841 * glGetUniformLocation. Using this as the location scale guarantees that
842 * there is enough "room" for the array index to be stored in the low order
843 * part of the uniform location. It also makes the locations be more
846 unsigned max_array_size
= 1;
847 for (unsigned i
= 0; i
< num_user_uniforms
; i
++) {
848 if (uniforms
[i
].array_elements
> max_array_size
)
849 max_array_size
= uniforms
[i
].array_elements
;
852 prog
->UniformLocationBaseScale
= max_array_size
;
855 for (unsigned i
= 0; i
< num_user_uniforms
; i
++) {
856 assert(uniforms
[i
].storage
!= NULL
);
859 assert(parcel
.values
== data_end
);
862 prog
->NumUserUniformStorage
= num_user_uniforms
;
863 prog
->UniformStorage
= uniforms
;
865 link_set_uniform_initializers(prog
);