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.
26 #include "ir_uniform.h"
27 #include "glsl_symbol_table.h"
29 #include "string_to_uint_map.h"
30 #include "ir_array_refcount.h"
31 #include "main/mtypes.h"
34 * \file link_uniforms.cpp
35 * Assign locations for GLSL uniforms.
37 * \author Ian Romanick <ian.d.romanick@intel.com>
41 * Used by linker to indicate uniforms that have no location set.
43 #define UNMAPPED_UNIFORM_LOC ~0u
46 program_resource_visitor::process(const glsl_type
*type
, const char *name
,
47 bool use_std430_as_default
)
49 assert(type
->without_array()->is_struct()
50 || type
->without_array()->is_interface());
52 unsigned record_array_count
= 1;
53 char *name_copy
= ralloc_strdup(NULL
, name
);
55 enum glsl_interface_packing packing
=
56 type
->get_internal_ifc_packing(use_std430_as_default
);
58 recursion(type
, &name_copy
, strlen(name
), false, NULL
, packing
, false,
59 record_array_count
, NULL
);
60 ralloc_free(name_copy
);
64 program_resource_visitor::process(ir_variable
*var
, bool use_std430_as_default
)
67 var
->data
.from_named_ifc_block
? var
->get_interface_type() : var
->type
;
68 process(var
, t
, use_std430_as_default
);
72 program_resource_visitor::process(ir_variable
*var
, const glsl_type
*var_type
,
73 bool use_std430_as_default
)
75 unsigned record_array_count
= 1;
76 const bool row_major
=
77 var
->data
.matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
;
79 enum glsl_interface_packing packing
= var
->get_interface_type() ?
80 var
->get_interface_type()->
81 get_internal_ifc_packing(use_std430_as_default
) :
82 var
->type
->get_internal_ifc_packing(use_std430_as_default
);
84 const glsl_type
*t
= var_type
;
85 const glsl_type
*t_without_array
= t
->without_array();
87 /* false is always passed for the row_major parameter to the other
88 * processing functions because no information is available to do
89 * otherwise. See the warning in linker.h.
91 if (t_without_array
->is_struct() ||
92 (t
->is_array() && t
->fields
.array
->is_array())) {
93 char *name
= ralloc_strdup(NULL
, var
->name
);
94 recursion(var
->type
, &name
, strlen(name
), row_major
, NULL
, packing
,
95 false, record_array_count
, NULL
);
97 } else if (t_without_array
->is_interface()) {
98 char *name
= ralloc_strdup(NULL
, t_without_array
->name
);
99 const glsl_struct_field
*ifc_member
= var
->data
.from_named_ifc_block
?
101 fields
.structure
[t_without_array
->field_index(var
->name
)] : NULL
;
103 recursion(t
, &name
, strlen(name
), row_major
, NULL
, packing
,
104 false, record_array_count
, ifc_member
);
107 this->set_record_array_count(record_array_count
);
108 this->visit_field(t
, var
->name
, row_major
, NULL
, packing
, false);
113 program_resource_visitor::recursion(const glsl_type
*t
, char **name
,
114 size_t name_length
, bool row_major
,
115 const glsl_type
*record_type
,
116 const enum glsl_interface_packing packing
,
118 unsigned record_array_count
,
119 const glsl_struct_field
*named_ifc_member
)
121 /* Records need to have each field processed individually.
123 * Arrays of records need to have each array element processed
124 * individually, then each field of the resulting array elements processed
127 if (t
->is_interface() && named_ifc_member
) {
128 ralloc_asprintf_rewrite_tail(name
, &name_length
, ".%s",
129 named_ifc_member
->name
);
130 recursion(named_ifc_member
->type
, name
, name_length
, row_major
, NULL
,
131 packing
, false, record_array_count
, NULL
);
132 } else if (t
->is_struct() || t
->is_interface()) {
133 if (record_type
== NULL
&& t
->is_struct())
137 this->enter_record(t
, *name
, row_major
, packing
);
139 for (unsigned i
= 0; i
< t
->length
; i
++) {
140 const char *field
= t
->fields
.structure
[i
].name
;
141 size_t new_length
= name_length
;
143 if (t
->is_interface() && t
->fields
.structure
[i
].offset
!= -1)
144 this->set_buffer_offset(t
->fields
.structure
[i
].offset
);
146 /* Append '.field' to the current variable name. */
147 if (name_length
== 0) {
148 ralloc_asprintf_rewrite_tail(name
, &new_length
, "%s", field
);
150 ralloc_asprintf_rewrite_tail(name
, &new_length
, ".%s", field
);
153 /* The layout of structures at the top level of the block is set
154 * during parsing. For matrices contained in multiple levels of
155 * structures in the block, the inner structures have no layout.
156 * These cases must potentially inherit the layout from the outer
159 bool field_row_major
= row_major
;
160 const enum glsl_matrix_layout matrix_layout
=
161 glsl_matrix_layout(t
->fields
.structure
[i
].matrix_layout
);
162 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
163 field_row_major
= true;
164 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
165 field_row_major
= false;
168 recursion(t
->fields
.structure
[i
].type
, name
, new_length
,
172 (i
+ 1) == t
->length
, record_array_count
, NULL
);
174 /* Only the first leaf-field of the record gets called with the
175 * record type pointer.
180 if (t
->is_struct()) {
181 (*name
)[name_length
] = '\0';
182 this->leave_record(t
, *name
, row_major
, packing
);
184 } else if (t
->without_array()->is_struct() ||
185 t
->without_array()->is_interface() ||
186 (t
->is_array() && t
->fields
.array
->is_array())) {
187 if (record_type
== NULL
&& t
->fields
.array
->is_struct())
188 record_type
= t
->fields
.array
;
190 unsigned length
= t
->length
;
192 /* Shader storage block unsized arrays: add subscript [0] to variable
195 if (t
->is_unsized_array())
198 record_array_count
*= length
;
200 for (unsigned i
= 0; i
< length
; i
++) {
201 size_t new_length
= name_length
;
203 /* Append the subscript to the current variable name */
204 ralloc_asprintf_rewrite_tail(name
, &new_length
, "[%u]", i
);
206 recursion(t
->fields
.array
, name
, new_length
, row_major
,
209 (i
+ 1) == t
->length
, record_array_count
,
212 /* Only the first leaf-field of the record gets called with the
213 * record type pointer.
218 this->set_record_array_count(record_array_count
);
219 this->visit_field(t
, *name
, row_major
, record_type
, packing
, last_field
);
224 program_resource_visitor::enter_record(const glsl_type
*, const char *, bool,
225 const enum glsl_interface_packing
)
230 program_resource_visitor::leave_record(const glsl_type
*, const char *, bool,
231 const enum glsl_interface_packing
)
236 program_resource_visitor::set_buffer_offset(unsigned)
241 program_resource_visitor::set_record_array_count(unsigned)
248 * Class to help calculate the storage requirements for a set of uniforms
250 * As uniforms are added to the active set the number of active uniforms and
251 * the storage requirements for those uniforms are accumulated. The active
252 * uniforms are added to the hash table supplied to the constructor.
254 * If the same uniform is added multiple times (i.e., once for each shader
255 * target), it will only be accounted once.
257 class count_uniform_size
: public program_resource_visitor
{
259 count_uniform_size(struct string_to_uint_map
*map
,
260 struct string_to_uint_map
*hidden_map
,
261 bool use_std430_as_default
)
262 : num_active_uniforms(0), num_hidden_uniforms(0), num_values(0),
263 num_shader_samplers(0), num_shader_images(0),
264 num_shader_uniform_components(0), num_shader_subroutines(0),
265 is_buffer_block(false), is_shader_storage(false), map(map
),
266 hidden_map(hidden_map
), current_var(NULL
),
267 use_std430_as_default(use_std430_as_default
)
274 this->num_shader_samplers
= 0;
275 this->num_shader_images
= 0;
276 this->num_shader_uniform_components
= 0;
277 this->num_shader_subroutines
= 0;
280 void process(ir_variable
*var
)
282 this->current_var
= var
;
283 this->is_buffer_block
= var
->is_in_buffer_block();
284 this->is_shader_storage
= var
->is_in_shader_storage_block();
285 if (var
->is_interface_instance())
286 program_resource_visitor::process(var
->get_interface_type(),
287 var
->get_interface_type()->name
,
288 use_std430_as_default
);
290 program_resource_visitor::process(var
, use_std430_as_default
);
294 * Total number of active uniforms counted
296 unsigned num_active_uniforms
;
298 unsigned num_hidden_uniforms
;
301 * Number of data values required to back the storage for the active uniforms
306 * Number of samplers used
308 unsigned num_shader_samplers
;
311 * Number of images used
313 unsigned num_shader_images
;
316 * Number of uniforms used in the current shader
318 unsigned num_shader_uniform_components
;
321 * Number of subroutine uniforms used
323 unsigned num_shader_subroutines
;
325 bool is_buffer_block
;
326 bool is_shader_storage
;
328 struct string_to_uint_map
*map
;
331 virtual void visit_field(const glsl_type
*type
, const char *name
,
332 bool /* row_major */,
333 const glsl_type
* /* record_type */,
334 const enum glsl_interface_packing
,
335 bool /* last_field */)
337 assert(!type
->without_array()->is_struct());
338 assert(!type
->without_array()->is_interface());
339 assert(!(type
->is_array() && type
->fields
.array
->is_array()));
341 /* Count the number of samplers regardless of whether the uniform is
342 * already in the hash table. The hash table prevents adding the same
343 * uniform for multiple shader targets, but in this case we want to
344 * count it for each shader target.
346 const unsigned values
= type
->component_slots();
347 if (type
->contains_subroutine()) {
348 this->num_shader_subroutines
+= values
;
349 } else if (type
->contains_sampler() && !current_var
->data
.bindless
) {
350 /* Samplers (bound or bindless) are counted as two components as
351 * specified by ARB_bindless_texture. */
352 this->num_shader_samplers
+= values
/ 2;
353 } else if (type
->contains_image() && !current_var
->data
.bindless
) {
354 /* Images (bound or bindless) are counted as two components as
355 * specified by ARB_bindless_texture. */
356 this->num_shader_images
+= values
/ 2;
358 /* As drivers are likely to represent image uniforms as
359 * scalar indices, count them against the limit of uniform
360 * components in the default block. The spec allows image
361 * uniforms to use up no more than one scalar slot.
363 if (!is_shader_storage
)
364 this->num_shader_uniform_components
+= values
;
366 /* Accumulate the total number of uniform slots used by this shader.
367 * Note that samplers do not count against this limit because they
368 * don't use any storage on current hardware.
370 if (!is_buffer_block
)
371 this->num_shader_uniform_components
+= values
;
374 /* If the uniform is already in the map, there's nothing more to do.
377 if (this->map
->get(id
, name
))
380 if (this->current_var
->data
.how_declared
== ir_var_hidden
) {
381 this->hidden_map
->put(this->num_hidden_uniforms
, name
);
382 this->num_hidden_uniforms
++;
384 this->map
->put(this->num_active_uniforms
-this->num_hidden_uniforms
,
388 /* Each leaf uniform occupies one entry in the list of active
391 this->num_active_uniforms
++;
393 if(!is_gl_identifier(name
) && !is_shader_storage
&& !is_buffer_block
)
394 this->num_values
+= values
;
397 struct string_to_uint_map
*hidden_map
;
400 * Current variable being processed.
402 ir_variable
*current_var
;
404 bool use_std430_as_default
;
407 } /* anonymous namespace */
410 link_calculate_matrix_stride(const glsl_type
*matrix
, bool row_major
,
411 enum glsl_interface_packing packing
)
413 const unsigned N
= matrix
->is_double() ? 8 : 4;
414 const unsigned items
=
415 row_major
? matrix
->matrix_columns
: matrix
->vector_elements
;
419 /* Matrix stride for std430 mat2xY matrices are not rounded up to
422 * Section 7.6.2.2 "Standard Uniform Block Layout" of the OpenGL 4.3 spec
425 * 2. If the member is a two- or four-component vector with components
426 * consuming N basic machine units, the base alignment is 2N or 4N,
429 * 4. If the member is an array of scalars or vectors, the base
430 * alignment and array stride are set to match the base alignment of
431 * a single array element, according to rules (1), (2), and (3), and
432 * rounded up to the base alignment of a vec4.
434 * 7. If the member is a row-major matrix with C columns and R rows, the
435 * matrix is stored identically to an array of R row vectors with C
436 * components each, according to rule (4).
439 * When using the std430 storage layout, shader storage blocks will be
440 * laid out in buffer storage identically to uniform and shader storage
441 * blocks using the std140 layout, except that the base alignment and
442 * stride of arrays of scalars and vectors in rule 4 and of structures
443 * in rule 9 are not rounded up a multiple of the base alignment of a
446 return packing
== GLSL_INTERFACE_PACKING_STD430
447 ? (items
< 3 ? items
* N
: glsl_align(items
* N
, 16))
448 : glsl_align(items
* N
, 16);
452 * Class to help parcel out pieces of backing storage to uniforms
454 * Each uniform processed has some range of the \c gl_constant_value
455 * structures associated with it. The association is done by finding
456 * the uniform in the \c string_to_uint_map and using the value from
457 * the map to connect that slot in the \c gl_uniform_storage table
458 * with the next available slot in the \c gl_constant_value array.
461 * This class assumes that every uniform that will be processed is
462 * already in the \c string_to_uint_map. In addition, it assumes that
463 * the \c gl_uniform_storage and \c gl_constant_value arrays are "big
466 class parcel_out_uniform_storage
: public program_resource_visitor
{
468 parcel_out_uniform_storage(struct gl_shader_program
*prog
,
469 struct string_to_uint_map
*map
,
470 struct gl_uniform_storage
*uniforms
,
471 union gl_constant_value
*values
,
472 bool use_std430_as_default
)
473 : prog(prog
), map(map
), uniforms(uniforms
),
474 use_std430_as_default(use_std430_as_default
), values(values
),
475 bindless_targets(NULL
), bindless_access(NULL
)
479 virtual ~parcel_out_uniform_storage()
481 free(this->bindless_targets
);
482 free(this->bindless_access
);
485 void start_shader(gl_shader_stage shader_type
)
487 assert(shader_type
< MESA_SHADER_STAGES
);
488 this->shader_type
= shader_type
;
490 this->shader_samplers_used
= 0;
491 this->shader_shadow_samplers
= 0;
492 this->next_sampler
= 0;
493 this->next_image
= 0;
494 this->next_subroutine
= 0;
495 this->record_array_count
= 1;
496 memset(this->targets
, 0, sizeof(this->targets
));
498 this->num_bindless_samplers
= 0;
499 this->next_bindless_sampler
= 0;
500 free(this->bindless_targets
);
501 this->bindless_targets
= NULL
;
503 this->num_bindless_images
= 0;
504 this->next_bindless_image
= 0;
505 free(this->bindless_access
);
506 this->bindless_access
= NULL
;
509 void set_and_process(ir_variable
*var
)
513 this->record_next_sampler
= new string_to_uint_map
;
514 this->record_next_bindless_sampler
= new string_to_uint_map
;
515 this->record_next_image
= new string_to_uint_map
;
516 this->record_next_bindless_image
= new string_to_uint_map
;
518 buffer_block_index
= -1;
519 if (var
->is_in_buffer_block()) {
520 struct gl_uniform_block
*blks
= var
->is_in_shader_storage_block() ?
521 prog
->data
->ShaderStorageBlocks
: prog
->data
->UniformBlocks
;
522 unsigned num_blks
= var
->is_in_shader_storage_block() ?
523 prog
->data
->NumShaderStorageBlocks
: prog
->data
->NumUniformBlocks
;
525 if (var
->is_interface_instance() && var
->type
->is_array()) {
526 unsigned l
= strlen(var
->get_interface_type()->name
);
528 for (unsigned i
= 0; i
< num_blks
; i
++) {
529 if (strncmp(var
->get_interface_type()->name
, blks
[i
].Name
, l
)
530 == 0 && blks
[i
].Name
[l
] == '[') {
531 buffer_block_index
= i
;
536 for (unsigned i
= 0; i
< num_blks
; i
++) {
537 if (strcmp(var
->get_interface_type()->name
, blks
[i
].Name
) == 0) {
538 buffer_block_index
= i
;
543 assert(buffer_block_index
!= -1);
545 /* Uniform blocks that were specified with an instance name must be
546 * handled a little bit differently. The name of the variable is the
547 * name used to reference the uniform block instead of being the name
548 * of a variable within the block. Therefore, searching for the name
549 * within the block will fail.
551 if (var
->is_interface_instance()) {
553 process(var
->get_interface_type(),
554 var
->get_interface_type()->name
,
555 use_std430_as_default
);
557 const struct gl_uniform_block
*const block
=
558 &blks
[buffer_block_index
];
560 assert(var
->data
.location
!= -1);
562 const struct gl_uniform_buffer_variable
*const ubo_var
=
563 &block
->Uniforms
[var
->data
.location
];
565 ubo_byte_offset
= ubo_var
->Offset
;
566 process(var
, use_std430_as_default
);
569 /* Store any explicit location and reset data location so we can
570 * reuse this variable for storing the uniform slot number.
572 this->explicit_location
= current_var
->data
.location
;
573 current_var
->data
.location
= -1;
575 process(var
, use_std430_as_default
);
577 delete this->record_next_sampler
;
578 delete this->record_next_bindless_sampler
;
579 delete this->record_next_image
;
580 delete this->record_next_bindless_image
;
583 int buffer_block_index
;
585 gl_shader_stage shader_type
;
588 bool set_opaque_indices(const glsl_type
*base_type
,
589 struct gl_uniform_storage
*uniform
,
590 const char *name
, unsigned &next_index
,
591 struct string_to_uint_map
*record_next_index
)
593 assert(base_type
->is_sampler() || base_type
->is_image());
595 if (this->record_array_count
> 1) {
596 unsigned inner_array_size
= MAX2(1, uniform
->array_elements
);
597 char *name_copy
= ralloc_strdup(NULL
, name
);
599 /* Remove all array subscripts from the sampler/image name */
602 while((str_start
= strchr(name_copy
, '[')) &&
603 (str_end
= strchr(name_copy
, ']'))) {
604 memmove(str_start
, str_end
+ 1, 1 + strlen(str_end
+ 1));
608 if (record_next_index
->get(index
, name_copy
)) {
609 /* In this case, we've already seen this uniform so we just use the
610 * next sampler/image index recorded the last time we visited.
612 uniform
->opaque
[shader_type
].index
= index
;
613 index
= inner_array_size
+ uniform
->opaque
[shader_type
].index
;
614 record_next_index
->put(index
, name_copy
);
616 ralloc_free(name_copy
);
617 /* Return as everything else has already been initialised in a
622 /* We've never seen this uniform before so we need to allocate
623 * enough indices to store it.
625 * Nested struct arrays behave like arrays of arrays so we need to
626 * increase the index by the total number of elements of the
627 * sampler/image in case there is more than one sampler/image
628 * inside the structs. This allows the offset to be easily
629 * calculated for indirect indexing.
631 uniform
->opaque
[shader_type
].index
= next_index
;
632 next_index
+= inner_array_size
* this->record_array_count
;
634 /* Store the next index for future passes over the struct array
636 index
= uniform
->opaque
[shader_type
].index
+ inner_array_size
;
637 record_next_index
->put(index
, name_copy
);
638 ralloc_free(name_copy
);
641 /* Increment the sampler/image by 1 for non-arrays and by the number
642 * of array elements for arrays.
644 uniform
->opaque
[shader_type
].index
= next_index
;
645 next_index
+= MAX2(1, uniform
->array_elements
);
650 void handle_samplers(const glsl_type
*base_type
,
651 struct gl_uniform_storage
*uniform
, const char *name
)
653 if (base_type
->is_sampler()) {
654 uniform
->opaque
[shader_type
].active
= true;
656 const gl_texture_index target
= base_type
->sampler_index();
657 const unsigned shadow
= base_type
->sampler_shadow
;
659 if (current_var
->data
.bindless
) {
660 if (!set_opaque_indices(base_type
, uniform
, name
,
661 this->next_bindless_sampler
,
662 this->record_next_bindless_sampler
))
665 this->num_bindless_samplers
= this->next_bindless_sampler
;
667 this->bindless_targets
= (gl_texture_index
*)
668 realloc(this->bindless_targets
,
669 this->num_bindless_samplers
* sizeof(gl_texture_index
));
671 for (unsigned i
= uniform
->opaque
[shader_type
].index
;
672 i
< this->num_bindless_samplers
;
674 this->bindless_targets
[i
] = target
;
677 if (!set_opaque_indices(base_type
, uniform
, name
,
679 this->record_next_sampler
))
682 for (unsigned i
= uniform
->opaque
[shader_type
].index
;
683 i
< MIN2(this->next_sampler
, MAX_SAMPLERS
);
685 this->targets
[i
] = target
;
686 this->shader_samplers_used
|= 1U << i
;
687 this->shader_shadow_samplers
|= shadow
<< i
;
693 void handle_images(const glsl_type
*base_type
,
694 struct gl_uniform_storage
*uniform
, const char *name
)
696 if (base_type
->is_image()) {
697 uniform
->opaque
[shader_type
].active
= true;
699 /* Set image access qualifiers */
700 const GLenum access
=
701 current_var
->data
.memory_read_only
?
702 (current_var
->data
.memory_write_only
? GL_NONE
:
704 (current_var
->data
.memory_write_only
? GL_WRITE_ONLY
:
707 if (current_var
->data
.bindless
) {
708 if (!set_opaque_indices(base_type
, uniform
, name
,
709 this->next_bindless_image
,
710 this->record_next_bindless_image
))
713 this->num_bindless_images
= this->next_bindless_image
;
715 this->bindless_access
= (GLenum
*)
716 realloc(this->bindless_access
,
717 this->num_bindless_images
* sizeof(GLenum
));
719 for (unsigned i
= uniform
->opaque
[shader_type
].index
;
720 i
< this->num_bindless_images
;
722 this->bindless_access
[i
] = access
;
725 if (!set_opaque_indices(base_type
, uniform
, name
,
727 this->record_next_image
))
730 for (unsigned i
= uniform
->opaque
[shader_type
].index
;
731 i
< MIN2(this->next_image
, MAX_IMAGE_UNIFORMS
);
733 prog
->_LinkedShaders
[shader_type
]->Program
->sh
.ImageAccess
[i
] = access
;
739 void handle_subroutines(const glsl_type
*base_type
,
740 struct gl_uniform_storage
*uniform
)
742 if (base_type
->is_subroutine()) {
743 uniform
->opaque
[shader_type
].index
= this->next_subroutine
;
744 uniform
->opaque
[shader_type
].active
= true;
746 prog
->_LinkedShaders
[shader_type
]->Program
->sh
.NumSubroutineUniforms
++;
748 /* Increment the subroutine index by 1 for non-arrays and by the
749 * number of array elements for arrays.
751 this->next_subroutine
+= MAX2(1, uniform
->array_elements
);
756 virtual void set_buffer_offset(unsigned offset
)
758 this->ubo_byte_offset
= offset
;
761 virtual void set_record_array_count(unsigned record_array_count
)
763 this->record_array_count
= record_array_count
;
766 virtual void enter_record(const glsl_type
*type
, const char *,
768 const enum glsl_interface_packing packing
)
770 assert(type
->is_struct());
771 if (this->buffer_block_index
== -1)
773 if (packing
== GLSL_INTERFACE_PACKING_STD430
)
774 this->ubo_byte_offset
= glsl_align(
775 this->ubo_byte_offset
, type
->std430_base_alignment(row_major
));
777 this->ubo_byte_offset
= glsl_align(
778 this->ubo_byte_offset
, type
->std140_base_alignment(row_major
));
781 virtual void leave_record(const glsl_type
*type
, const char *,
783 const enum glsl_interface_packing packing
)
785 assert(type
->is_struct());
786 if (this->buffer_block_index
== -1)
788 if (packing
== GLSL_INTERFACE_PACKING_STD430
)
789 this->ubo_byte_offset
= glsl_align(
790 this->ubo_byte_offset
, type
->std430_base_alignment(row_major
));
792 this->ubo_byte_offset
= glsl_align(
793 this->ubo_byte_offset
, type
->std140_base_alignment(row_major
));
796 virtual void visit_field(const glsl_type
*type
, const char *name
,
797 bool row_major
, const glsl_type
* /* record_type */,
798 const enum glsl_interface_packing packing
,
799 bool /* last_field */)
801 assert(!type
->without_array()->is_struct());
802 assert(!type
->without_array()->is_interface());
803 assert(!(type
->is_array() && type
->fields
.array
->is_array()));
806 bool found
= this->map
->get(id
, name
);
812 const glsl_type
*base_type
;
813 if (type
->is_array()) {
814 this->uniforms
[id
].array_elements
= type
->length
;
815 base_type
= type
->fields
.array
;
817 this->uniforms
[id
].array_elements
= 0;
821 /* Initialise opaque data */
822 this->uniforms
[id
].opaque
[shader_type
].index
= ~0;
823 this->uniforms
[id
].opaque
[shader_type
].active
= false;
825 this->uniforms
[id
].active_shader_mask
|= 1 << shader_type
;
827 /* This assigns uniform indices to sampler and image uniforms. */
828 handle_samplers(base_type
, &this->uniforms
[id
], name
);
829 handle_images(base_type
, &this->uniforms
[id
], name
);
830 handle_subroutines(base_type
, &this->uniforms
[id
]);
832 /* For array of arrays or struct arrays the base location may have
833 * already been set so don't set it again.
835 if (buffer_block_index
== -1 && current_var
->data
.location
== -1) {
836 current_var
->data
.location
= id
;
839 /* If there is already storage associated with this uniform or if the
840 * uniform is set as builtin, it means that it was set while processing
841 * an earlier shader stage. For example, we may be processing the
842 * uniform in the fragment shader, but the uniform was already processed
843 * in the vertex shader.
845 if (this->uniforms
[id
].storage
!= NULL
|| this->uniforms
[id
].builtin
) {
849 /* Assign explicit locations. */
850 if (current_var
->data
.explicit_location
) {
851 /* Set sequential locations for struct fields. */
852 if (current_var
->type
->without_array()->is_struct() ||
853 current_var
->type
->is_array_of_arrays()) {
854 const unsigned entries
= MAX2(1, this->uniforms
[id
].array_elements
);
855 this->uniforms
[id
].remap_location
=
856 this->explicit_location
+ field_counter
;
857 field_counter
+= entries
;
859 this->uniforms
[id
].remap_location
= this->explicit_location
;
862 /* Initialize to to indicate that no location is set */
863 this->uniforms
[id
].remap_location
= UNMAPPED_UNIFORM_LOC
;
866 this->uniforms
[id
].name
= ralloc_strdup(this->uniforms
, name
);
867 this->uniforms
[id
].type
= base_type
;
868 this->uniforms
[id
].num_driver_storage
= 0;
869 this->uniforms
[id
].driver_storage
= NULL
;
870 this->uniforms
[id
].atomic_buffer_index
= -1;
871 this->uniforms
[id
].hidden
=
872 current_var
->data
.how_declared
== ir_var_hidden
;
873 this->uniforms
[id
].builtin
= is_gl_identifier(name
);
875 this->uniforms
[id
].is_shader_storage
=
876 current_var
->is_in_shader_storage_block();
877 this->uniforms
[id
].is_bindless
= current_var
->data
.bindless
;
879 /* Do not assign storage if the uniform is a builtin or buffer object */
880 if (!this->uniforms
[id
].builtin
&&
881 !this->uniforms
[id
].is_shader_storage
&&
882 this->buffer_block_index
== -1)
883 this->uniforms
[id
].storage
= this->values
;
885 if (this->buffer_block_index
!= -1) {
886 this->uniforms
[id
].block_index
= this->buffer_block_index
;
888 unsigned alignment
= type
->std140_base_alignment(row_major
);
889 if (packing
== GLSL_INTERFACE_PACKING_STD430
)
890 alignment
= type
->std430_base_alignment(row_major
);
891 this->ubo_byte_offset
= glsl_align(this->ubo_byte_offset
, alignment
);
892 this->uniforms
[id
].offset
= this->ubo_byte_offset
;
893 if (packing
== GLSL_INTERFACE_PACKING_STD430
)
894 this->ubo_byte_offset
+= type
->std430_size(row_major
);
896 this->ubo_byte_offset
+= type
->std140_size(row_major
);
898 if (type
->is_array()) {
899 if (packing
== GLSL_INTERFACE_PACKING_STD430
)
900 this->uniforms
[id
].array_stride
=
901 type
->without_array()->std430_array_stride(row_major
);
903 this->uniforms
[id
].array_stride
=
904 glsl_align(type
->without_array()->std140_size(row_major
),
907 this->uniforms
[id
].array_stride
= 0;
910 if (type
->without_array()->is_matrix()) {
911 this->uniforms
[id
].matrix_stride
=
912 link_calculate_matrix_stride(type
->without_array(),
915 this->uniforms
[id
].row_major
= row_major
;
917 this->uniforms
[id
].matrix_stride
= 0;
918 this->uniforms
[id
].row_major
= false;
921 this->uniforms
[id
].block_index
= -1;
922 this->uniforms
[id
].offset
= -1;
923 this->uniforms
[id
].array_stride
= -1;
924 this->uniforms
[id
].matrix_stride
= -1;
925 this->uniforms
[id
].row_major
= false;
928 if (!this->uniforms
[id
].builtin
&&
929 !this->uniforms
[id
].is_shader_storage
&&
930 this->buffer_block_index
== -1)
931 this->values
+= type
->component_slots();
935 * Current program being processed.
937 struct gl_shader_program
*prog
;
939 struct string_to_uint_map
*map
;
941 struct gl_uniform_storage
*uniforms
;
942 unsigned next_sampler
;
943 unsigned next_bindless_sampler
;
945 unsigned next_bindless_image
;
946 unsigned next_subroutine
;
948 bool use_std430_as_default
;
951 * Field counter is used to take care that uniform structures
952 * with explicit locations get sequential locations.
954 unsigned field_counter
;
957 * Current variable being processed.
959 ir_variable
*current_var
;
961 /* Used to store the explicit location from current_var so that we can
962 * reuse the location field for storing the uniform slot id.
964 int explicit_location
;
966 /* Stores total struct array elements including nested structs */
967 unsigned record_array_count
;
969 /* Map for temporarily storing next sampler index when handling samplers in
972 struct string_to_uint_map
*record_next_sampler
;
974 /* Map for temporarily storing next imager index when handling images in
977 struct string_to_uint_map
*record_next_image
;
979 /* Map for temporarily storing next bindless sampler index when handling
980 * bindless samplers in struct arrays.
982 struct string_to_uint_map
*record_next_bindless_sampler
;
984 /* Map for temporarily storing next bindless image index when handling
985 * bindless images in struct arrays.
987 struct string_to_uint_map
*record_next_bindless_image
;
990 union gl_constant_value
*values
;
992 gl_texture_index targets
[MAX_SAMPLERS
];
995 * Mask of samplers used by the current shader stage.
997 unsigned shader_samplers_used
;
1000 * Mask of samplers used by the current shader stage for shadows.
1002 unsigned shader_shadow_samplers
;
1005 * Number of bindless samplers used by the current shader stage.
1007 unsigned num_bindless_samplers
;
1010 * Texture targets for bindless samplers used by the current stage.
1012 gl_texture_index
*bindless_targets
;
1015 * Number of bindless images used by the current shader stage.
1017 unsigned num_bindless_images
;
1020 * Access types for bindless images used by the current stage.
1022 GLenum
*bindless_access
;
1027 variable_is_referenced(ir_array_refcount_visitor
&v
, ir_variable
*var
)
1029 ir_array_refcount_entry
*const entry
= v
.get_variable_entry(var
);
1031 return entry
->is_referenced
;
1036 * Walks the IR and update the references to uniform blocks in the
1037 * ir_variables to point at linked shader's list (previously, they
1038 * would point at the uniform block list in one of the pre-linked
1042 link_update_uniform_buffer_variables(struct gl_linked_shader
*shader
,
1045 ir_array_refcount_visitor v
;
1049 foreach_in_list(ir_instruction
, node
, shader
->ir
) {
1050 ir_variable
*const var
= node
->as_variable();
1052 if (var
== NULL
|| !var
->is_in_buffer_block())
1055 assert(var
->data
.mode
== ir_var_uniform
||
1056 var
->data
.mode
== ir_var_shader_storage
);
1058 unsigned num_blocks
= var
->data
.mode
== ir_var_uniform
?
1059 shader
->Program
->info
.num_ubos
: shader
->Program
->info
.num_ssbos
;
1060 struct gl_uniform_block
**blks
= var
->data
.mode
== ir_var_uniform
?
1061 shader
->Program
->sh
.UniformBlocks
:
1062 shader
->Program
->sh
.ShaderStorageBlocks
;
1064 if (var
->is_interface_instance()) {
1065 const ir_array_refcount_entry
*const entry
= v
.get_variable_entry(var
);
1067 if (entry
->is_referenced
) {
1068 /* Since this is an interface instance, the instance type will be
1069 * same as the array-stripped variable type. If the variable type
1070 * is an array, then the block names will be suffixed with [0]
1071 * through [n-1]. Unlike for non-interface instances, there will
1072 * not be structure types here, so the only name sentinel that we
1073 * have to worry about is [.
1075 assert(var
->type
->without_array() == var
->get_interface_type());
1076 const char sentinel
= var
->type
->is_array() ? '[' : '\0';
1078 const ptrdiff_t len
= strlen(var
->get_interface_type()->name
);
1079 for (unsigned i
= 0; i
< num_blocks
; i
++) {
1080 const char *const begin
= blks
[i
]->Name
;
1081 const char *const end
= strchr(begin
, sentinel
);
1086 if (len
!= (end
- begin
))
1089 /* Even when a match is found, do not "break" here. This could
1090 * be an array of instances, and all elements of the array need
1091 * to be marked as referenced.
1093 if (strncmp(begin
, var
->get_interface_type()->name
, len
) == 0 &&
1094 (!var
->type
->is_array() ||
1095 entry
->is_linearized_index_referenced(blks
[i
]->linearized_array_index
))) {
1096 blks
[i
]->stageref
|= 1U << stage
;
1101 var
->data
.location
= 0;
1106 char sentinel
= '\0';
1108 if (var
->type
->is_struct()) {
1110 } else if (var
->type
->is_array() && (var
->type
->fields
.array
->is_array()
1111 || var
->type
->without_array()->is_struct())) {
1115 const unsigned l
= strlen(var
->name
);
1116 for (unsigned i
= 0; i
< num_blocks
; i
++) {
1117 for (unsigned j
= 0; j
< blks
[i
]->NumUniforms
; j
++) {
1119 const char *begin
= blks
[i
]->Uniforms
[j
].Name
;
1120 const char *end
= strchr(begin
, sentinel
);
1125 if ((ptrdiff_t) l
!= (end
- begin
))
1128 found
= strncmp(var
->name
, begin
, l
) == 0;
1130 found
= strcmp(var
->name
, blks
[i
]->Uniforms
[j
].Name
) == 0;
1134 var
->data
.location
= j
;
1136 if (variable_is_referenced(v
, var
))
1137 blks
[i
]->stageref
|= 1U << stage
;
1151 * Combine the hidden uniform hash map with the uniform hash map so that the
1152 * hidden uniforms will be given indicies at the end of the uniform storage
1156 assign_hidden_uniform_slot_id(const char *name
, unsigned hidden_id
,
1159 count_uniform_size
*uniform_size
= (count_uniform_size
*) closure
;
1160 unsigned hidden_uniform_start
= uniform_size
->num_active_uniforms
-
1161 uniform_size
->num_hidden_uniforms
;
1163 uniform_size
->map
->put(hidden_uniform_start
+ hidden_id
, name
);
1167 link_setup_uniform_remap_tables(struct gl_context
*ctx
,
1168 struct gl_shader_program
*prog
)
1170 unsigned total_entries
= prog
->NumExplicitUniformLocations
;
1171 unsigned empty_locs
= prog
->NumUniformRemapTable
- total_entries
;
1173 /* Reserve all the explicit locations of the active uniforms. */
1174 for (unsigned i
= 0; i
< prog
->data
->NumUniformStorage
; i
++) {
1175 if (prog
->data
->UniformStorage
[i
].type
->is_subroutine() ||
1176 prog
->data
->UniformStorage
[i
].is_shader_storage
)
1179 if (prog
->data
->UniformStorage
[i
].remap_location
!=
1180 UNMAPPED_UNIFORM_LOC
) {
1181 /* How many new entries for this uniform? */
1182 const unsigned entries
=
1183 MAX2(1, prog
->data
->UniformStorage
[i
].array_elements
);
1185 /* Set remap table entries point to correct gl_uniform_storage. */
1186 for (unsigned j
= 0; j
< entries
; j
++) {
1187 unsigned element_loc
=
1188 prog
->data
->UniformStorage
[i
].remap_location
+ j
;
1189 assert(prog
->UniformRemapTable
[element_loc
] ==
1190 INACTIVE_UNIFORM_EXPLICIT_LOCATION
);
1191 prog
->UniformRemapTable
[element_loc
] =
1192 &prog
->data
->UniformStorage
[i
];
1197 /* Reserve locations for rest of the uniforms. */
1198 for (unsigned i
= 0; i
< prog
->data
->NumUniformStorage
; i
++) {
1200 if (prog
->data
->UniformStorage
[i
].type
->is_subroutine() ||
1201 prog
->data
->UniformStorage
[i
].is_shader_storage
)
1204 /* Built-in uniforms should not get any location. */
1205 if (prog
->data
->UniformStorage
[i
].builtin
)
1208 /* Explicit ones have been set already. */
1209 if (prog
->data
->UniformStorage
[i
].remap_location
!= UNMAPPED_UNIFORM_LOC
)
1212 /* how many new entries for this uniform? */
1213 const unsigned entries
=
1214 MAX2(1, prog
->data
->UniformStorage
[i
].array_elements
);
1216 /* Find UniformRemapTable for empty blocks where we can fit this uniform. */
1217 int chosen_location
= -1;
1220 chosen_location
= link_util_find_empty_block(prog
, &prog
->data
->UniformStorage
[i
]);
1222 /* Add new entries to the total amount for checking against MAX_UNIFORM-
1223 * _LOCATIONS. This only applies to the default uniform block (-1),
1224 * because locations of uniform block entries are not assignable.
1226 if (prog
->data
->UniformStorage
[i
].block_index
== -1)
1227 total_entries
+= entries
;
1229 if (chosen_location
!= -1) {
1230 empty_locs
-= entries
;
1232 chosen_location
= prog
->NumUniformRemapTable
;
1234 /* resize remap table to fit new entries */
1235 prog
->UniformRemapTable
=
1237 prog
->UniformRemapTable
,
1238 gl_uniform_storage
*,
1239 prog
->NumUniformRemapTable
+ entries
);
1240 prog
->NumUniformRemapTable
+= entries
;
1243 /* set pointers for this uniform */
1244 for (unsigned j
= 0; j
< entries
; j
++)
1245 prog
->UniformRemapTable
[chosen_location
+ j
] =
1246 &prog
->data
->UniformStorage
[i
];
1248 /* set the base location in remap table for the uniform */
1249 prog
->data
->UniformStorage
[i
].remap_location
= chosen_location
;
1252 /* Verify that total amount of entries for explicit and implicit locations
1253 * is less than MAX_UNIFORM_LOCATIONS.
1256 if (total_entries
> ctx
->Const
.MaxUserAssignableUniformLocations
) {
1257 linker_error(prog
, "count of uniform locations > MAX_UNIFORM_LOCATIONS"
1258 "(%u > %u)", total_entries
,
1259 ctx
->Const
.MaxUserAssignableUniformLocations
);
1262 /* Reserve all the explicit locations of the active subroutine uniforms. */
1263 for (unsigned i
= 0; i
< prog
->data
->NumUniformStorage
; i
++) {
1264 if (!prog
->data
->UniformStorage
[i
].type
->is_subroutine())
1267 if (prog
->data
->UniformStorage
[i
].remap_location
== UNMAPPED_UNIFORM_LOC
)
1270 /* How many new entries for this uniform? */
1271 const unsigned entries
=
1272 MAX2(1, prog
->data
->UniformStorage
[i
].array_elements
);
1274 unsigned mask
= prog
->data
->linked_stages
;
1276 const int j
= u_bit_scan(&mask
);
1277 struct gl_program
*p
= prog
->_LinkedShaders
[j
]->Program
;
1279 if (!prog
->data
->UniformStorage
[i
].opaque
[j
].active
)
1282 /* Set remap table entries point to correct gl_uniform_storage. */
1283 for (unsigned k
= 0; k
< entries
; k
++) {
1284 unsigned element_loc
=
1285 prog
->data
->UniformStorage
[i
].remap_location
+ k
;
1286 assert(p
->sh
.SubroutineUniformRemapTable
[element_loc
] ==
1287 INACTIVE_UNIFORM_EXPLICIT_LOCATION
);
1288 p
->sh
.SubroutineUniformRemapTable
[element_loc
] =
1289 &prog
->data
->UniformStorage
[i
];
1294 /* reserve subroutine locations */
1295 for (unsigned i
= 0; i
< prog
->data
->NumUniformStorage
; i
++) {
1296 if (!prog
->data
->UniformStorage
[i
].type
->is_subroutine())
1299 if (prog
->data
->UniformStorage
[i
].remap_location
!=
1300 UNMAPPED_UNIFORM_LOC
)
1303 const unsigned entries
=
1304 MAX2(1, prog
->data
->UniformStorage
[i
].array_elements
);
1306 unsigned mask
= prog
->data
->linked_stages
;
1308 const int j
= u_bit_scan(&mask
);
1309 struct gl_program
*p
= prog
->_LinkedShaders
[j
]->Program
;
1311 if (!prog
->data
->UniformStorage
[i
].opaque
[j
].active
)
1314 p
->sh
.SubroutineUniformRemapTable
=
1316 p
->sh
.SubroutineUniformRemapTable
,
1317 gl_uniform_storage
*,
1318 p
->sh
.NumSubroutineUniformRemapTable
+ entries
);
1320 for (unsigned k
= 0; k
< entries
; k
++) {
1321 p
->sh
.SubroutineUniformRemapTable
[p
->sh
.NumSubroutineUniformRemapTable
+ k
] =
1322 &prog
->data
->UniformStorage
[i
];
1324 prog
->data
->UniformStorage
[i
].remap_location
=
1325 p
->sh
.NumSubroutineUniformRemapTable
;
1326 p
->sh
.NumSubroutineUniformRemapTable
+= entries
;
1332 link_assign_uniform_storage(struct gl_context
*ctx
,
1333 struct gl_shader_program
*prog
,
1334 const unsigned num_data_slots
)
1336 /* On the outside chance that there were no uniforms, bail out.
1338 if (prog
->data
->NumUniformStorage
== 0)
1341 unsigned int boolean_true
= ctx
->Const
.UniformBooleanTrue
;
1343 union gl_constant_value
*data
;
1344 if (prog
->data
->UniformStorage
== NULL
) {
1345 prog
->data
->UniformStorage
= rzalloc_array(prog
->data
,
1346 struct gl_uniform_storage
,
1347 prog
->data
->NumUniformStorage
);
1348 data
= rzalloc_array(prog
->data
->UniformStorage
,
1349 union gl_constant_value
, num_data_slots
);
1350 prog
->data
->UniformDataDefaults
=
1351 rzalloc_array(prog
->data
->UniformStorage
,
1352 union gl_constant_value
, num_data_slots
);
1354 data
= prog
->data
->UniformDataSlots
;
1358 union gl_constant_value
*data_end
= &data
[num_data_slots
];
1361 parcel_out_uniform_storage
parcel(prog
, prog
->UniformHash
,
1362 prog
->data
->UniformStorage
, data
,
1363 ctx
->Const
.UseSTD430AsDefaultPacking
);
1365 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
1366 struct gl_linked_shader
*shader
= prog
->_LinkedShaders
[i
];
1371 parcel
.start_shader((gl_shader_stage
)i
);
1373 foreach_in_list(ir_instruction
, node
, shader
->ir
) {
1374 ir_variable
*const var
= node
->as_variable();
1376 if ((var
== NULL
) || (var
->data
.mode
!= ir_var_uniform
&&
1377 var
->data
.mode
!= ir_var_shader_storage
))
1380 parcel
.set_and_process(var
);
1383 shader
->Program
->SamplersUsed
= parcel
.shader_samplers_used
;
1384 shader
->shadow_samplers
= parcel
.shader_shadow_samplers
;
1386 if (parcel
.num_bindless_samplers
> 0) {
1387 shader
->Program
->sh
.NumBindlessSamplers
= parcel
.num_bindless_samplers
;
1388 shader
->Program
->sh
.BindlessSamplers
=
1389 rzalloc_array(shader
->Program
, gl_bindless_sampler
,
1390 parcel
.num_bindless_samplers
);
1391 for (unsigned j
= 0; j
< parcel
.num_bindless_samplers
; j
++) {
1392 shader
->Program
->sh
.BindlessSamplers
[j
].target
=
1393 parcel
.bindless_targets
[j
];
1397 if (parcel
.num_bindless_images
> 0) {
1398 shader
->Program
->sh
.NumBindlessImages
= parcel
.num_bindless_images
;
1399 shader
->Program
->sh
.BindlessImages
=
1400 rzalloc_array(shader
->Program
, gl_bindless_image
,
1401 parcel
.num_bindless_images
);
1402 for (unsigned j
= 0; j
< parcel
.num_bindless_images
; j
++) {
1403 shader
->Program
->sh
.BindlessImages
[j
].access
=
1404 parcel
.bindless_access
[j
];
1408 STATIC_ASSERT(ARRAY_SIZE(shader
->Program
->sh
.SamplerTargets
) ==
1409 ARRAY_SIZE(parcel
.targets
));
1410 for (unsigned j
= 0; j
< ARRAY_SIZE(parcel
.targets
); j
++)
1411 shader
->Program
->sh
.SamplerTargets
[j
] = parcel
.targets
[j
];
1415 for (unsigned i
= 0; i
< prog
->data
->NumUniformStorage
; i
++) {
1416 assert(prog
->data
->UniformStorage
[i
].storage
!= NULL
||
1417 prog
->data
->UniformStorage
[i
].builtin
||
1418 prog
->data
->UniformStorage
[i
].is_shader_storage
||
1419 prog
->data
->UniformStorage
[i
].block_index
!= -1);
1422 assert(parcel
.values
== data_end
);
1425 link_setup_uniform_remap_tables(ctx
, prog
);
1427 /* Set shader cache fields */
1428 prog
->data
->NumUniformDataSlots
= num_data_slots
;
1429 prog
->data
->UniformDataSlots
= data
;
1431 link_set_uniform_initializers(prog
, boolean_true
);
1435 link_assign_uniform_locations(struct gl_shader_program
*prog
,
1436 struct gl_context
*ctx
)
1438 ralloc_free(prog
->data
->UniformStorage
);
1439 prog
->data
->UniformStorage
= NULL
;
1440 prog
->data
->NumUniformStorage
= 0;
1442 if (prog
->UniformHash
!= NULL
) {
1443 prog
->UniformHash
->clear();
1445 prog
->UniformHash
= new string_to_uint_map
;
1448 /* First pass: Count the uniform resources used by the user-defined
1449 * uniforms. While this happens, each active uniform will have an index
1452 * Note: this is *NOT* the index that is returned to the application by
1453 * glGetUniformLocation.
1455 struct string_to_uint_map
*hiddenUniforms
= new string_to_uint_map
;
1456 count_uniform_size
uniform_size(prog
->UniformHash
, hiddenUniforms
,
1457 ctx
->Const
.UseSTD430AsDefaultPacking
);
1458 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
1459 struct gl_linked_shader
*sh
= prog
->_LinkedShaders
[i
];
1464 link_update_uniform_buffer_variables(sh
, i
);
1466 /* Reset various per-shader target counts.
1468 uniform_size
.start_shader();
1470 foreach_in_list(ir_instruction
, node
, sh
->ir
) {
1471 ir_variable
*const var
= node
->as_variable();
1473 if ((var
== NULL
) || (var
->data
.mode
!= ir_var_uniform
&&
1474 var
->data
.mode
!= ir_var_shader_storage
))
1477 uniform_size
.process(var
);
1480 sh
->Program
->info
.num_textures
= uniform_size
.num_shader_samplers
;
1481 sh
->Program
->info
.num_images
= uniform_size
.num_shader_images
;
1482 sh
->num_uniform_components
= uniform_size
.num_shader_uniform_components
;
1483 sh
->num_combined_uniform_components
= sh
->num_uniform_components
;
1485 for (unsigned i
= 0; i
< sh
->Program
->info
.num_ubos
; i
++) {
1486 sh
->num_combined_uniform_components
+=
1487 sh
->Program
->sh
.UniformBlocks
[i
]->UniformBufferSize
/ 4;
1491 prog
->data
->NumUniformStorage
= uniform_size
.num_active_uniforms
;
1492 prog
->data
->NumHiddenUniforms
= uniform_size
.num_hidden_uniforms
;
1494 /* assign hidden uniforms a slot id */
1495 hiddenUniforms
->iterate(assign_hidden_uniform_slot_id
, &uniform_size
);
1496 delete hiddenUniforms
;
1498 link_assign_uniform_storage(ctx
, prog
, uniform_size
.num_values
);