2 * Copyright © 2012 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.
25 * \file link_varyings.cpp
27 * Linker functions related specifically to linking varyings between shader
32 #include "main/mtypes.h"
33 #include "glsl_symbol_table.h"
34 #include "glsl_parser_extras.h"
35 #include "ir_optimization.h"
37 #include "link_varyings.h"
38 #include "main/macros.h"
39 #include "program/hash_table.h"
44 * Validate the types and qualifiers of an output from one stage against the
45 * matching input to another stage.
48 cross_validate_types_and_qualifiers(struct gl_shader_program
*prog
,
49 const ir_variable
*input
,
50 const ir_variable
*output
,
51 gl_shader_stage consumer_stage
,
52 gl_shader_stage producer_stage
)
54 /* Check that the types match between stages.
56 const glsl_type
*type_to_match
= input
->type
;
57 if (consumer_stage
== MESA_SHADER_GEOMETRY
) {
58 assert(type_to_match
->is_array()); /* Enforced by ast_to_hir */
59 type_to_match
= type_to_match
->element_type();
61 if (type_to_match
!= output
->type
) {
62 /* There is a bit of a special case for gl_TexCoord. This
63 * built-in is unsized by default. Applications that variable
64 * access it must redeclare it with a size. There is some
65 * language in the GLSL spec that implies the fragment shader
66 * and vertex shader do not have to agree on this size. Other
67 * driver behave this way, and one or two applications seem to
70 * Neither declaration needs to be modified here because the array
71 * sizes are fixed later when update_array_sizes is called.
73 * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:
75 * "Unlike user-defined varying variables, the built-in
76 * varying variables don't have a strict one-to-one
77 * correspondence between the vertex language and the
80 if (!output
->type
->is_array() || !is_gl_identifier(output
->name
)) {
82 "%s shader output `%s' declared as type `%s', "
83 "but %s shader input declared as type `%s'\n",
84 _mesa_shader_stage_to_string(producer_stage
),
87 _mesa_shader_stage_to_string(consumer_stage
),
93 /* Check that all of the qualifiers match between stages.
95 if (input
->data
.centroid
!= output
->data
.centroid
) {
97 "%s shader output `%s' %s centroid qualifier, "
98 "but %s shader input %s centroid qualifier\n",
99 _mesa_shader_stage_to_string(producer_stage
),
101 (output
->data
.centroid
) ? "has" : "lacks",
102 _mesa_shader_stage_to_string(consumer_stage
),
103 (input
->data
.centroid
) ? "has" : "lacks");
107 if (input
->data
.sample
!= output
->data
.sample
) {
109 "%s shader output `%s' %s sample qualifier, "
110 "but %s shader input %s sample qualifier\n",
111 _mesa_shader_stage_to_string(producer_stage
),
113 (output
->data
.sample
) ? "has" : "lacks",
114 _mesa_shader_stage_to_string(consumer_stage
),
115 (input
->data
.sample
) ? "has" : "lacks");
119 if (input
->data
.invariant
!= output
->data
.invariant
) {
121 "%s shader output `%s' %s invariant qualifier, "
122 "but %s shader input %s invariant qualifier\n",
123 _mesa_shader_stage_to_string(producer_stage
),
125 (output
->data
.invariant
) ? "has" : "lacks",
126 _mesa_shader_stage_to_string(consumer_stage
),
127 (input
->data
.invariant
) ? "has" : "lacks");
131 if (input
->data
.interpolation
!= output
->data
.interpolation
) {
133 "%s shader output `%s' specifies %s "
134 "interpolation qualifier, "
135 "but %s shader input specifies %s "
136 "interpolation qualifier\n",
137 _mesa_shader_stage_to_string(producer_stage
),
139 interpolation_string(output
->data
.interpolation
),
140 _mesa_shader_stage_to_string(consumer_stage
),
141 interpolation_string(input
->data
.interpolation
));
147 * Validate front and back color outputs against single color input
150 cross_validate_front_and_back_color(struct gl_shader_program
*prog
,
151 const ir_variable
*input
,
152 const ir_variable
*front_color
,
153 const ir_variable
*back_color
,
154 gl_shader_stage consumer_stage
,
155 gl_shader_stage producer_stage
)
157 if (front_color
!= NULL
&& front_color
->data
.assigned
)
158 cross_validate_types_and_qualifiers(prog
, input
, front_color
,
159 consumer_stage
, producer_stage
);
161 if (back_color
!= NULL
&& back_color
->data
.assigned
)
162 cross_validate_types_and_qualifiers(prog
, input
, back_color
,
163 consumer_stage
, producer_stage
);
167 * Validate that outputs from one stage match inputs of another
170 cross_validate_outputs_to_inputs(struct gl_shader_program
*prog
,
171 gl_shader
*producer
, gl_shader
*consumer
)
173 glsl_symbol_table parameters
;
174 ir_variable
*explicit_locations
[MAX_VARYING
] = { NULL
, };
176 /* Find all shader outputs in the "producer" stage.
178 foreach_in_list(ir_instruction
, node
, producer
->ir
) {
179 ir_variable
*const var
= node
->as_variable();
181 if ((var
== NULL
) || (var
->data
.mode
!= ir_var_shader_out
))
184 if (!var
->data
.explicit_location
185 || var
->data
.location
< VARYING_SLOT_VAR0
)
186 parameters
.add_variable(var
);
188 /* User-defined varyings with explicit locations are handled
189 * differently because they do not need to have matching names.
191 const unsigned idx
= var
->data
.location
- VARYING_SLOT_VAR0
;
193 if (explicit_locations
[idx
] != NULL
) {
195 "%s shader has multiple outputs explicitly "
196 "assigned to location %d\n",
197 _mesa_shader_stage_to_string(producer
->Stage
),
202 explicit_locations
[idx
] = var
;
207 /* Find all shader inputs in the "consumer" stage. Any variables that have
208 * matching outputs already in the symbol table must have the same type and
211 * Exception: if the consumer is the geometry shader, then the inputs
212 * should be arrays and the type of the array element should match the type
213 * of the corresponding producer output.
215 foreach_in_list(ir_instruction
, node
, consumer
->ir
) {
216 ir_variable
*const input
= node
->as_variable();
218 if ((input
== NULL
) || (input
->data
.mode
!= ir_var_shader_in
))
221 if (strcmp(input
->name
, "gl_Color") == 0 && input
->data
.used
) {
222 const ir_variable
*const front_color
=
223 parameters
.get_variable("gl_FrontColor");
225 const ir_variable
*const back_color
=
226 parameters
.get_variable("gl_BackColor");
228 cross_validate_front_and_back_color(prog
, input
,
229 front_color
, back_color
,
230 consumer
->Stage
, producer
->Stage
);
231 } else if (strcmp(input
->name
, "gl_SecondaryColor") == 0 && input
->data
.used
) {
232 const ir_variable
*const front_color
=
233 parameters
.get_variable("gl_FrontSecondaryColor");
235 const ir_variable
*const back_color
=
236 parameters
.get_variable("gl_BackSecondaryColor");
238 cross_validate_front_and_back_color(prog
, input
,
239 front_color
, back_color
,
240 consumer
->Stage
, producer
->Stage
);
242 /* The rules for connecting inputs and outputs change in the presence
243 * of explicit locations. In this case, we no longer care about the
244 * names of the variables. Instead, we care only about the
245 * explicitly assigned location.
247 ir_variable
*output
= NULL
;
248 if (input
->data
.explicit_location
249 && input
->data
.location
>= VARYING_SLOT_VAR0
) {
250 output
= explicit_locations
[input
->data
.location
- VARYING_SLOT_VAR0
];
252 if (output
== NULL
) {
254 "%s shader input `%s' with explicit location "
255 "has no matching output\n",
256 _mesa_shader_stage_to_string(consumer
->Stage
),
260 output
= parameters
.get_variable(input
->name
);
263 if (output
!= NULL
) {
264 cross_validate_types_and_qualifiers(prog
, input
, output
,
265 consumer
->Stage
, producer
->Stage
);
273 * Initialize this object based on a string that was passed to
274 * glTransformFeedbackVaryings.
276 * If the input is mal-formed, this call still succeeds, but it sets
277 * this->var_name to a mal-formed input, so tfeedback_decl::find_output_var()
278 * will fail to find any matching variable.
281 tfeedback_decl::init(struct gl_context
*ctx
, const void *mem_ctx
,
284 /* We don't have to be pedantic about what is a valid GLSL variable name,
285 * because any variable with an invalid name can't exist in the IR anyway.
289 this->orig_name
= input
;
290 this->is_clip_distance_mesa
= false;
291 this->skip_components
= 0;
292 this->next_buffer_separator
= false;
293 this->matched_candidate
= NULL
;
296 if (ctx
->Extensions
.ARB_transform_feedback3
) {
297 /* Parse gl_NextBuffer. */
298 if (strcmp(input
, "gl_NextBuffer") == 0) {
299 this->next_buffer_separator
= true;
303 /* Parse gl_SkipComponents. */
304 if (strcmp(input
, "gl_SkipComponents1") == 0)
305 this->skip_components
= 1;
306 else if (strcmp(input
, "gl_SkipComponents2") == 0)
307 this->skip_components
= 2;
308 else if (strcmp(input
, "gl_SkipComponents3") == 0)
309 this->skip_components
= 3;
310 else if (strcmp(input
, "gl_SkipComponents4") == 0)
311 this->skip_components
= 4;
313 if (this->skip_components
)
317 /* Parse a declaration. */
318 const char *base_name_end
;
319 long subscript
= parse_program_resource_name(input
, &base_name_end
);
320 this->var_name
= ralloc_strndup(mem_ctx
, input
, base_name_end
- input
);
321 if (subscript
>= 0) {
322 this->array_subscript
= subscript
;
323 this->is_subscripted
= true;
325 this->is_subscripted
= false;
328 /* For drivers that lower gl_ClipDistance to gl_ClipDistanceMESA, this
329 * class must behave specially to account for the fact that gl_ClipDistance
330 * is converted from a float[8] to a vec4[2].
332 if (ctx
->Const
.ShaderCompilerOptions
[MESA_SHADER_VERTEX
].LowerClipDistance
&&
333 strcmp(this->var_name
, "gl_ClipDistance") == 0) {
334 this->is_clip_distance_mesa
= true;
340 * Determine whether two tfeedback_decl objects refer to the same variable and
341 * array index (if applicable).
344 tfeedback_decl::is_same(const tfeedback_decl
&x
, const tfeedback_decl
&y
)
346 assert(x
.is_varying() && y
.is_varying());
348 if (strcmp(x
.var_name
, y
.var_name
) != 0)
350 if (x
.is_subscripted
!= y
.is_subscripted
)
352 if (x
.is_subscripted
&& x
.array_subscript
!= y
.array_subscript
)
359 * Assign a location and stream ID for this tfeedback_decl object based on the
360 * transform feedback candidate found by find_candidate.
362 * If an error occurs, the error is reported through linker_error() and false
366 tfeedback_decl::assign_location(struct gl_context
*ctx
,
367 struct gl_shader_program
*prog
)
369 assert(this->is_varying());
371 unsigned fine_location
372 = this->matched_candidate
->toplevel_var
->data
.location
* 4
373 + this->matched_candidate
->toplevel_var
->data
.location_frac
374 + this->matched_candidate
->offset
;
376 if (this->matched_candidate
->type
->is_array()) {
378 const unsigned matrix_cols
=
379 this->matched_candidate
->type
->fields
.array
->matrix_columns
;
380 const unsigned vector_elements
=
381 this->matched_candidate
->type
->fields
.array
->vector_elements
;
382 unsigned actual_array_size
= this->is_clip_distance_mesa
?
383 prog
->LastClipDistanceArraySize
:
384 this->matched_candidate
->type
->array_size();
386 if (this->is_subscripted
) {
387 /* Check array bounds. */
388 if (this->array_subscript
>= actual_array_size
) {
389 linker_error(prog
, "Transform feedback varying %s has index "
390 "%i, but the array size is %u.",
391 this->orig_name
, this->array_subscript
,
395 unsigned array_elem_size
= this->is_clip_distance_mesa
?
396 1 : vector_elements
* matrix_cols
;
397 fine_location
+= array_elem_size
* this->array_subscript
;
400 this->size
= actual_array_size
;
402 this->vector_elements
= vector_elements
;
403 this->matrix_columns
= matrix_cols
;
404 if (this->is_clip_distance_mesa
)
405 this->type
= GL_FLOAT
;
407 this->type
= this->matched_candidate
->type
->fields
.array
->gl_type
;
409 /* Regular variable (scalar, vector, or matrix) */
410 if (this->is_subscripted
) {
411 linker_error(prog
, "Transform feedback varying %s requested, "
412 "but %s is not an array.",
413 this->orig_name
, this->var_name
);
417 this->vector_elements
= this->matched_candidate
->type
->vector_elements
;
418 this->matrix_columns
= this->matched_candidate
->type
->matrix_columns
;
419 this->type
= this->matched_candidate
->type
->gl_type
;
421 this->location
= fine_location
/ 4;
422 this->location_frac
= fine_location
% 4;
424 /* From GL_EXT_transform_feedback:
425 * A program will fail to link if:
427 * * the total number of components to capture in any varying
428 * variable in <varyings> is greater than the constant
429 * MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT and the
430 * buffer mode is SEPARATE_ATTRIBS_EXT;
432 if (prog
->TransformFeedback
.BufferMode
== GL_SEPARATE_ATTRIBS
&&
433 this->num_components() >
434 ctx
->Const
.MaxTransformFeedbackSeparateComponents
) {
435 linker_error(prog
, "Transform feedback varying %s exceeds "
436 "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS.",
441 /* Only transform feedback varyings can be assigned to non-zero streams,
442 * so assign the stream id here.
444 this->stream_id
= this->matched_candidate
->toplevel_var
->data
.stream
;
451 tfeedback_decl::get_num_outputs() const
453 if (!this->is_varying()) {
457 return (this->num_components() + this->location_frac
+ 3)/4;
462 * Update gl_transform_feedback_info to reflect this tfeedback_decl.
464 * If an error occurs, the error is reported through linker_error() and false
468 tfeedback_decl::store(struct gl_context
*ctx
, struct gl_shader_program
*prog
,
469 struct gl_transform_feedback_info
*info
,
470 unsigned buffer
, const unsigned max_outputs
) const
472 assert(!this->next_buffer_separator
);
474 /* Handle gl_SkipComponents. */
475 if (this->skip_components
) {
476 info
->BufferStride
[buffer
] += this->skip_components
;
480 /* From GL_EXT_transform_feedback:
481 * A program will fail to link if:
483 * * the total number of components to capture is greater than
484 * the constant MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT
485 * and the buffer mode is INTERLEAVED_ATTRIBS_EXT.
487 if (prog
->TransformFeedback
.BufferMode
== GL_INTERLEAVED_ATTRIBS
&&
488 info
->BufferStride
[buffer
] + this->num_components() >
489 ctx
->Const
.MaxTransformFeedbackInterleavedComponents
) {
490 linker_error(prog
, "The MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS "
491 "limit has been exceeded.");
495 unsigned location
= this->location
;
496 unsigned location_frac
= this->location_frac
;
497 unsigned num_components
= this->num_components();
498 while (num_components
> 0) {
499 unsigned output_size
= MIN2(num_components
, 4 - location_frac
);
500 assert(info
->NumOutputs
< max_outputs
);
501 info
->Outputs
[info
->NumOutputs
].ComponentOffset
= location_frac
;
502 info
->Outputs
[info
->NumOutputs
].OutputRegister
= location
;
503 info
->Outputs
[info
->NumOutputs
].NumComponents
= output_size
;
504 info
->Outputs
[info
->NumOutputs
].StreamId
= stream_id
;
505 info
->Outputs
[info
->NumOutputs
].OutputBuffer
= buffer
;
506 info
->Outputs
[info
->NumOutputs
].DstOffset
= info
->BufferStride
[buffer
];
508 info
->BufferStride
[buffer
] += output_size
;
509 num_components
-= output_size
;
514 info
->Varyings
[info
->NumVarying
].Name
= ralloc_strdup(prog
, this->orig_name
);
515 info
->Varyings
[info
->NumVarying
].Type
= this->type
;
516 info
->Varyings
[info
->NumVarying
].Size
= this->size
;
523 const tfeedback_candidate
*
524 tfeedback_decl::find_candidate(gl_shader_program
*prog
,
525 hash_table
*tfeedback_candidates
)
527 const char *name
= this->is_clip_distance_mesa
528 ? "gl_ClipDistanceMESA" : this->var_name
;
529 this->matched_candidate
= (const tfeedback_candidate
*)
530 hash_table_find(tfeedback_candidates
, name
);
531 if (!this->matched_candidate
) {
532 /* From GL_EXT_transform_feedback:
533 * A program will fail to link if:
535 * * any variable name specified in the <varyings> array is not
536 * declared as an output in the geometry shader (if present) or
537 * the vertex shader (if no geometry shader is present);
539 linker_error(prog
, "Transform feedback varying %s undeclared.",
542 return this->matched_candidate
;
547 * Parse all the transform feedback declarations that were passed to
548 * glTransformFeedbackVaryings() and store them in tfeedback_decl objects.
550 * If an error occurs, the error is reported through linker_error() and false
554 parse_tfeedback_decls(struct gl_context
*ctx
, struct gl_shader_program
*prog
,
555 const void *mem_ctx
, unsigned num_names
,
556 char **varying_names
, tfeedback_decl
*decls
)
558 for (unsigned i
= 0; i
< num_names
; ++i
) {
559 decls
[i
].init(ctx
, mem_ctx
, varying_names
[i
]);
561 if (!decls
[i
].is_varying())
564 /* From GL_EXT_transform_feedback:
565 * A program will fail to link if:
567 * * any two entries in the <varyings> array specify the same varying
570 * We interpret this to mean "any two entries in the <varyings> array
571 * specify the same varying variable and array index", since transform
572 * feedback of arrays would be useless otherwise.
574 for (unsigned j
= 0; j
< i
; ++j
) {
575 if (!decls
[j
].is_varying())
578 if (tfeedback_decl::is_same(decls
[i
], decls
[j
])) {
579 linker_error(prog
, "Transform feedback varying %s specified "
580 "more than once.", varying_names
[i
]);
590 * Store transform feedback location assignments into
591 * prog->LinkedTransformFeedback based on the data stored in tfeedback_decls.
593 * If an error occurs, the error is reported through linker_error() and false
597 store_tfeedback_info(struct gl_context
*ctx
, struct gl_shader_program
*prog
,
598 unsigned num_tfeedback_decls
,
599 tfeedback_decl
*tfeedback_decls
)
601 bool separate_attribs_mode
=
602 prog
->TransformFeedback
.BufferMode
== GL_SEPARATE_ATTRIBS
;
604 ralloc_free(prog
->LinkedTransformFeedback
.Varyings
);
605 ralloc_free(prog
->LinkedTransformFeedback
.Outputs
);
607 memset(&prog
->LinkedTransformFeedback
, 0,
608 sizeof(prog
->LinkedTransformFeedback
));
610 prog
->LinkedTransformFeedback
.Varyings
=
612 struct gl_transform_feedback_varying_info
,
613 num_tfeedback_decls
);
615 unsigned num_outputs
= 0;
616 for (unsigned i
= 0; i
< num_tfeedback_decls
; ++i
)
617 num_outputs
+= tfeedback_decls
[i
].get_num_outputs();
619 prog
->LinkedTransformFeedback
.Outputs
=
621 struct gl_transform_feedback_output
,
624 unsigned num_buffers
= 0;
626 if (separate_attribs_mode
) {
627 /* GL_SEPARATE_ATTRIBS */
628 for (unsigned i
= 0; i
< num_tfeedback_decls
; ++i
) {
629 if (!tfeedback_decls
[i
].store(ctx
, prog
, &prog
->LinkedTransformFeedback
,
630 num_buffers
, num_outputs
))
637 /* GL_INVERLEAVED_ATTRIBS */
638 int buffer_stream_id
= -1;
639 for (unsigned i
= 0; i
< num_tfeedback_decls
; ++i
) {
640 if (tfeedback_decls
[i
].is_next_buffer_separator()) {
642 buffer_stream_id
= -1;
644 } else if (buffer_stream_id
== -1) {
645 /* First varying writing to this buffer: remember its stream */
646 buffer_stream_id
= (int) tfeedback_decls
[i
].get_stream_id();
647 } else if (buffer_stream_id
!=
648 (int) tfeedback_decls
[i
].get_stream_id()) {
649 /* Varying writes to the same buffer from a different stream */
651 "Transform feedback can't capture varyings belonging "
652 "to different vertex streams in a single buffer. "
653 "Varying %s writes to buffer from stream %u, other "
654 "varyings in the same buffer write from stream %u.",
655 tfeedback_decls
[i
].name(),
656 tfeedback_decls
[i
].get_stream_id(),
661 if (!tfeedback_decls
[i
].store(ctx
, prog
,
662 &prog
->LinkedTransformFeedback
,
663 num_buffers
, num_outputs
))
669 assert(prog
->LinkedTransformFeedback
.NumOutputs
== num_outputs
);
671 prog
->LinkedTransformFeedback
.NumBuffers
= num_buffers
;
678 * Data structure recording the relationship between outputs of one shader
679 * stage (the "producer") and inputs of another (the "consumer").
681 class varying_matches
684 varying_matches(bool disable_varying_packing
, bool consumer_is_fs
);
686 void record(ir_variable
*producer_var
, ir_variable
*consumer_var
);
687 unsigned assign_locations();
688 void store_locations() const;
692 * If true, this driver disables varying packing, so all varyings need to
693 * be aligned on slot boundaries, and take up a number of slots equal to
694 * their number of matrix columns times their array size.
696 const bool disable_varying_packing
;
699 * Enum representing the order in which varyings are packed within a
702 * Currently we pack vec4's first, then vec2's, then scalar values, then
703 * vec3's. This order ensures that the only vectors that are at risk of
704 * having to be "double parked" (split between two adjacent varying slots)
707 enum packing_order_enum
{
710 PACKING_ORDER_SCALAR
,
714 static unsigned compute_packing_class(const ir_variable
*var
);
715 static packing_order_enum
compute_packing_order(const ir_variable
*var
);
716 static int match_comparator(const void *x_generic
, const void *y_generic
);
719 * Structure recording the relationship between a single producer output
720 * and a single consumer input.
724 * Packing class for this varying, computed by compute_packing_class().
726 unsigned packing_class
;
729 * Packing order for this varying, computed by compute_packing_order().
731 packing_order_enum packing_order
;
732 unsigned num_components
;
735 * The output variable in the producer stage.
737 ir_variable
*producer_var
;
740 * The input variable in the consumer stage.
742 ir_variable
*consumer_var
;
745 * The location which has been assigned for this varying. This is
746 * expressed in multiples of a float, with the first generic varying
747 * (i.e. the one referred to by VARYING_SLOT_VAR0) represented by the
750 unsigned generic_location
;
754 * The number of elements in the \c matches array that are currently in
757 unsigned num_matches
;
760 * The number of elements that were set aside for the \c matches array when
763 unsigned matches_capacity
;
765 const bool consumer_is_fs
;
768 } /* anonymous namespace */
770 varying_matches::varying_matches(bool disable_varying_packing
,
772 : disable_varying_packing(disable_varying_packing
),
773 consumer_is_fs(consumer_is_fs
)
775 /* Note: this initial capacity is rather arbitrarily chosen to be large
776 * enough for many cases without wasting an unreasonable amount of space.
777 * varying_matches::record() will resize the array if there are more than
778 * this number of varyings.
780 this->matches_capacity
= 8;
781 this->matches
= (match
*)
782 malloc(sizeof(*this->matches
) * this->matches_capacity
);
783 this->num_matches
= 0;
787 varying_matches::~varying_matches()
794 * Record the given producer/consumer variable pair in the list of variables
795 * that should later be assigned locations.
797 * It is permissible for \c consumer_var to be NULL (this happens if a
798 * variable is output by the producer and consumed by transform feedback, but
799 * not consumed by the consumer).
801 * If \c producer_var has already been paired up with a consumer_var, or
802 * producer_var is part of fixed pipeline functionality (and hence already has
803 * a location assigned), this function has no effect.
805 * Note: as a side effect this function may change the interpolation type of
806 * \c producer_var, but only when the change couldn't possibly affect
810 varying_matches::record(ir_variable
*producer_var
, ir_variable
*consumer_var
)
812 assert(producer_var
!= NULL
|| consumer_var
!= NULL
);
814 if ((producer_var
&& !producer_var
->data
.is_unmatched_generic_inout
)
815 || (consumer_var
&& !consumer_var
->data
.is_unmatched_generic_inout
)) {
816 /* Either a location already exists for this variable (since it is part
817 * of fixed functionality), or it has already been recorded as part of a
823 if ((consumer_var
== NULL
&& producer_var
->type
->contains_integer()) ||
825 /* Since this varying is not being consumed by the fragment shader, its
826 * interpolation type varying cannot possibly affect rendering. Also,
827 * this variable is non-flat and is (or contains) an integer.
829 * lower_packed_varyings requires all integer varyings to flat,
830 * regardless of where they appear. We can trivially satisfy that
831 * requirement by changing the interpolation type to flat here.
833 producer_var
->data
.centroid
= false;
834 producer_var
->data
.sample
= false;
835 producer_var
->data
.interpolation
= INTERP_QUALIFIER_FLAT
;
838 consumer_var
->data
.centroid
= false;
839 consumer_var
->data
.sample
= false;
840 consumer_var
->data
.interpolation
= INTERP_QUALIFIER_FLAT
;
844 if (this->num_matches
== this->matches_capacity
) {
845 this->matches_capacity
*= 2;
846 this->matches
= (match
*)
847 realloc(this->matches
,
848 sizeof(*this->matches
) * this->matches_capacity
);
851 const ir_variable
*const var
= (producer_var
!= NULL
)
852 ? producer_var
: consumer_var
;
854 this->matches
[this->num_matches
].packing_class
855 = this->compute_packing_class(var
);
856 this->matches
[this->num_matches
].packing_order
857 = this->compute_packing_order(var
);
858 if (this->disable_varying_packing
) {
859 unsigned slots
= var
->type
->is_array()
860 ? (var
->type
->length
* var
->type
->fields
.array
->matrix_columns
)
861 : var
->type
->matrix_columns
;
862 this->matches
[this->num_matches
].num_components
= 4 * slots
;
864 this->matches
[this->num_matches
].num_components
865 = var
->type
->component_slots();
867 this->matches
[this->num_matches
].producer_var
= producer_var
;
868 this->matches
[this->num_matches
].consumer_var
= consumer_var
;
871 producer_var
->data
.is_unmatched_generic_inout
= 0;
873 consumer_var
->data
.is_unmatched_generic_inout
= 0;
878 * Choose locations for all of the variable matches that were previously
879 * passed to varying_matches::record().
882 varying_matches::assign_locations()
884 /* Sort varying matches into an order that makes them easy to pack. */
885 qsort(this->matches
, this->num_matches
, sizeof(*this->matches
),
886 &varying_matches::match_comparator
);
888 unsigned generic_location
= 0;
890 for (unsigned i
= 0; i
< this->num_matches
; i
++) {
891 /* Advance to the next slot if this varying has a different packing
892 * class than the previous one, and we're not already on a slot
896 this->matches
[i
- 1].packing_class
897 != this->matches
[i
].packing_class
) {
898 generic_location
= ALIGN(generic_location
, 4);
901 this->matches
[i
].generic_location
= generic_location
;
903 generic_location
+= this->matches
[i
].num_components
;
906 return (generic_location
+ 3) / 4;
911 * Update the producer and consumer shaders to reflect the locations
912 * assignments that were made by varying_matches::assign_locations().
915 varying_matches::store_locations() const
917 for (unsigned i
= 0; i
< this->num_matches
; i
++) {
918 ir_variable
*producer_var
= this->matches
[i
].producer_var
;
919 ir_variable
*consumer_var
= this->matches
[i
].consumer_var
;
920 unsigned generic_location
= this->matches
[i
].generic_location
;
921 unsigned slot
= generic_location
/ 4;
922 unsigned offset
= generic_location
% 4;
925 producer_var
->data
.location
= VARYING_SLOT_VAR0
+ slot
;
926 producer_var
->data
.location_frac
= offset
;
930 assert(consumer_var
->data
.location
== -1);
931 consumer_var
->data
.location
= VARYING_SLOT_VAR0
+ slot
;
932 consumer_var
->data
.location_frac
= offset
;
939 * Compute the "packing class" of the given varying. This is an unsigned
940 * integer with the property that two variables in the same packing class can
941 * be safely backed into the same vec4.
944 varying_matches::compute_packing_class(const ir_variable
*var
)
946 /* Without help from the back-end, there is no way to pack together
947 * variables with different interpolation types, because
948 * lower_packed_varyings must choose exactly one interpolation type for
949 * each packed varying it creates.
951 * However, we can safely pack together floats, ints, and uints, because:
953 * - varyings of base type "int" and "uint" must use the "flat"
954 * interpolation type, which can only occur in GLSL 1.30 and above.
956 * - On platforms that support GLSL 1.30 and above, lower_packed_varyings
957 * can store flat floats as ints without losing any information (using
958 * the ir_unop_bitcast_* opcodes).
960 * Therefore, the packing class depends only on the interpolation type.
962 unsigned packing_class
= var
->data
.centroid
| (var
->data
.sample
<< 1);
964 packing_class
+= var
->data
.interpolation
;
965 return packing_class
;
970 * Compute the "packing order" of the given varying. This is a sort key we
971 * use to determine when to attempt to pack the given varying relative to
972 * other varyings in the same packing class.
974 varying_matches::packing_order_enum
975 varying_matches::compute_packing_order(const ir_variable
*var
)
977 const glsl_type
*element_type
= var
->type
;
979 while (element_type
->base_type
== GLSL_TYPE_ARRAY
) {
980 element_type
= element_type
->fields
.array
;
983 switch (element_type
->component_slots() % 4) {
984 case 1: return PACKING_ORDER_SCALAR
;
985 case 2: return PACKING_ORDER_VEC2
;
986 case 3: return PACKING_ORDER_VEC3
;
987 case 0: return PACKING_ORDER_VEC4
;
989 assert(!"Unexpected value of vector_elements");
990 return PACKING_ORDER_VEC4
;
996 * Comparison function passed to qsort() to sort varyings by packing_class and
997 * then by packing_order.
1000 varying_matches::match_comparator(const void *x_generic
, const void *y_generic
)
1002 const match
*x
= (const match
*) x_generic
;
1003 const match
*y
= (const match
*) y_generic
;
1005 if (x
->packing_class
!= y
->packing_class
)
1006 return x
->packing_class
- y
->packing_class
;
1007 return x
->packing_order
- y
->packing_order
;
1012 * Is the given variable a varying variable to be counted against the
1013 * limit in ctx->Const.MaxVarying?
1014 * This includes variables such as texcoords, colors and generic
1015 * varyings, but excludes variables such as gl_FrontFacing and gl_FragCoord.
1018 var_counts_against_varying_limit(gl_shader_stage stage
, const ir_variable
*var
)
1020 /* Only fragment shaders will take a varying variable as an input */
1021 if (stage
== MESA_SHADER_FRAGMENT
&&
1022 var
->data
.mode
== ir_var_shader_in
) {
1023 switch (var
->data
.location
) {
1024 case VARYING_SLOT_POS
:
1025 case VARYING_SLOT_FACE
:
1026 case VARYING_SLOT_PNTC
:
1037 * Visitor class that generates tfeedback_candidate structs describing all
1038 * possible targets of transform feedback.
1040 * tfeedback_candidate structs are stored in the hash table
1041 * tfeedback_candidates, which is passed to the constructor. This hash table
1042 * maps varying names to instances of the tfeedback_candidate struct.
1044 class tfeedback_candidate_generator
: public program_resource_visitor
1047 tfeedback_candidate_generator(void *mem_ctx
,
1048 hash_table
*tfeedback_candidates
)
1050 tfeedback_candidates(tfeedback_candidates
),
1056 void process(ir_variable
*var
)
1058 this->toplevel_var
= var
;
1059 this->varying_floats
= 0;
1060 if (var
->is_interface_instance())
1061 program_resource_visitor::process(var
->get_interface_type(),
1062 var
->get_interface_type()->name
);
1064 program_resource_visitor::process(var
);
1068 virtual void visit_field(const glsl_type
*type
, const char *name
,
1071 assert(!type
->without_array()->is_record());
1072 assert(!type
->without_array()->is_interface());
1076 tfeedback_candidate
*candidate
1077 = rzalloc(this->mem_ctx
, tfeedback_candidate
);
1078 candidate
->toplevel_var
= this->toplevel_var
;
1079 candidate
->type
= type
;
1080 candidate
->offset
= this->varying_floats
;
1081 hash_table_insert(this->tfeedback_candidates
, candidate
,
1082 ralloc_strdup(this->mem_ctx
, name
));
1083 this->varying_floats
+= type
->component_slots();
1087 * Memory context used to allocate hash table keys and values.
1089 void * const mem_ctx
;
1092 * Hash table in which tfeedback_candidate objects should be stored.
1094 hash_table
* const tfeedback_candidates
;
1097 * Pointer to the toplevel variable that is being traversed.
1099 ir_variable
*toplevel_var
;
1102 * Total number of varying floats that have been visited so far. This is
1103 * used to determine the offset to each varying within the toplevel
1106 unsigned varying_floats
;
1113 populate_consumer_input_sets(void *mem_ctx
, exec_list
*ir
,
1114 hash_table
*consumer_inputs
,
1115 hash_table
*consumer_interface_inputs
,
1116 ir_variable
*consumer_inputs_with_locations
[VARYING_SLOT_MAX
])
1118 memset(consumer_inputs_with_locations
,
1120 sizeof(consumer_inputs_with_locations
[0]) * VARYING_SLOT_MAX
);
1122 foreach_in_list(ir_instruction
, node
, ir
) {
1123 ir_variable
*const input_var
= node
->as_variable();
1125 if ((input_var
!= NULL
) && (input_var
->data
.mode
== ir_var_shader_in
)) {
1126 if (input_var
->type
->is_interface())
1129 if (input_var
->data
.explicit_location
) {
1130 /* assign_varying_locations only cares about finding the
1131 * ir_variable at the start of a contiguous location block.
1133 * - For !producer, consumer_inputs_with_locations isn't used.
1135 * - For !consumer, consumer_inputs_with_locations is empty.
1137 * For consumer && producer, if you were trying to set some
1138 * ir_variable to the middle of a location block on the other side
1139 * of producer/consumer, cross_validate_outputs_to_inputs() should
1140 * be link-erroring due to either type mismatch or location
1141 * overlaps. If the variables do match up, then they've got a
1142 * matching data.location and you only looked at
1143 * consumer_inputs_with_locations[var->data.location], not any
1144 * following entries for the array/structure.
1146 consumer_inputs_with_locations
[input_var
->data
.location
] =
1148 } else if (input_var
->get_interface_type() != NULL
) {
1149 char *const iface_field_name
=
1150 ralloc_asprintf(mem_ctx
, "%s.%s",
1151 input_var
->get_interface_type()->name
,
1153 hash_table_insert(consumer_interface_inputs
, input_var
,
1156 hash_table_insert(consumer_inputs
, input_var
,
1157 ralloc_strdup(mem_ctx
, input_var
->name
));
1166 * Find a variable from the consumer that "matches" the specified variable
1168 * This function only finds inputs with names that match. There is no
1169 * validation (here) that the types, etc. are compatible.
1172 get_matching_input(void *mem_ctx
,
1173 const ir_variable
*output_var
,
1174 hash_table
*consumer_inputs
,
1175 hash_table
*consumer_interface_inputs
,
1176 ir_variable
*consumer_inputs_with_locations
[VARYING_SLOT_MAX
])
1178 ir_variable
*input_var
;
1180 if (output_var
->data
.explicit_location
) {
1181 input_var
= consumer_inputs_with_locations
[output_var
->data
.location
];
1182 } else if (output_var
->get_interface_type() != NULL
) {
1183 char *const iface_field_name
=
1184 ralloc_asprintf(mem_ctx
, "%s.%s",
1185 output_var
->get_interface_type()->name
,
1188 (ir_variable
*) hash_table_find(consumer_interface_inputs
,
1192 (ir_variable
*) hash_table_find(consumer_inputs
, output_var
->name
);
1195 return (input_var
== NULL
|| input_var
->data
.mode
!= ir_var_shader_in
)
1202 io_variable_cmp(const void *_a
, const void *_b
)
1204 const ir_variable
*const a
= *(const ir_variable
**) _a
;
1205 const ir_variable
*const b
= *(const ir_variable
**) _b
;
1207 if (a
->data
.explicit_location
&& b
->data
.explicit_location
)
1208 return b
->data
.location
- a
->data
.location
;
1210 if (a
->data
.explicit_location
&& !b
->data
.explicit_location
)
1213 if (!a
->data
.explicit_location
&& b
->data
.explicit_location
)
1216 return -strcmp(a
->name
, b
->name
);
1220 * Sort the shader IO variables into canonical order
1223 canonicalize_shader_io(exec_list
*ir
, enum ir_variable_mode io_mode
)
1225 ir_variable
*var_table
[MAX_PROGRAM_OUTPUTS
* 4];
1226 unsigned num_variables
= 0;
1228 foreach_in_list(ir_instruction
, node
, ir
) {
1229 ir_variable
*const var
= node
->as_variable();
1231 if (var
== NULL
|| var
->data
.mode
!= io_mode
)
1234 /* If we have already encountered more I/O variables that could
1235 * successfully link, bail.
1237 if (num_variables
== ARRAY_SIZE(var_table
))
1240 var_table
[num_variables
++] = var
;
1243 if (num_variables
== 0)
1246 /* Sort the list in reverse order (io_variable_cmp handles this). Later
1247 * we're going to push the variables on to the IR list as a stack, so we
1248 * want the last variable (in canonical order) to be first in the list.
1250 qsort(var_table
, num_variables
, sizeof(var_table
[0]), io_variable_cmp
);
1252 /* Remove the variable from it's current location in the IR, and put it at
1255 for (unsigned i
= 0; i
< num_variables
; i
++) {
1256 var_table
[i
]->remove();
1257 ir
->push_head(var_table
[i
]);
1262 * Assign locations for all variables that are produced in one pipeline stage
1263 * (the "producer") and consumed in the next stage (the "consumer").
1265 * Variables produced by the producer may also be consumed by transform
1268 * \param num_tfeedback_decls is the number of declarations indicating
1269 * variables that may be consumed by transform feedback.
1271 * \param tfeedback_decls is a pointer to an array of tfeedback_decl objects
1272 * representing the result of parsing the strings passed to
1273 * glTransformFeedbackVaryings(). assign_location() will be called for
1274 * each of these objects that matches one of the outputs of the
1277 * \param gs_input_vertices: if \c consumer is a geometry shader, this is the
1278 * number of input vertices it accepts. Otherwise zero.
1280 * When num_tfeedback_decls is nonzero, it is permissible for the consumer to
1281 * be NULL. In this case, varying locations are assigned solely based on the
1282 * requirements of transform feedback.
1285 assign_varying_locations(struct gl_context
*ctx
,
1287 struct gl_shader_program
*prog
,
1288 gl_shader
*producer
, gl_shader
*consumer
,
1289 unsigned num_tfeedback_decls
,
1290 tfeedback_decl
*tfeedback_decls
,
1291 unsigned gs_input_vertices
)
1293 varying_matches
matches(ctx
->Const
.DisableVaryingPacking
,
1294 consumer
&& consumer
->Stage
== MESA_SHADER_FRAGMENT
);
1295 hash_table
*tfeedback_candidates
1296 = hash_table_ctor(0, hash_table_string_hash
, hash_table_string_compare
);
1297 hash_table
*consumer_inputs
1298 = hash_table_ctor(0, hash_table_string_hash
, hash_table_string_compare
);
1299 hash_table
*consumer_interface_inputs
1300 = hash_table_ctor(0, hash_table_string_hash
, hash_table_string_compare
);
1301 ir_variable
*consumer_inputs_with_locations
[VARYING_SLOT_MAX
] = {
1305 /* Operate in a total of four passes.
1307 * 1. Sort inputs / outputs into a canonical order. This is necessary so
1308 * that inputs / outputs of separable shaders will be assigned
1309 * predictable locations regardless of the order in which declarations
1310 * appeared in the shader source.
1312 * 2. Assign locations for any matching inputs and outputs.
1314 * 3. Mark output variables in the producer that do not have locations as
1315 * not being outputs. This lets the optimizer eliminate them.
1317 * 4. Mark input variables in the consumer that do not have locations as
1318 * not being inputs. This lets the optimizer eliminate them.
1321 canonicalize_shader_io(consumer
->ir
, ir_var_shader_in
);
1324 canonicalize_shader_io(producer
->ir
, ir_var_shader_out
);
1327 && !linker::populate_consumer_input_sets(mem_ctx
,
1330 consumer_interface_inputs
,
1331 consumer_inputs_with_locations
)) {
1332 assert(!"populate_consumer_input_sets failed");
1333 hash_table_dtor(tfeedback_candidates
);
1334 hash_table_dtor(consumer_inputs
);
1335 hash_table_dtor(consumer_interface_inputs
);
1340 foreach_in_list(ir_instruction
, node
, producer
->ir
) {
1341 ir_variable
*const output_var
= node
->as_variable();
1343 if ((output_var
== NULL
) ||
1344 (output_var
->data
.mode
!= ir_var_shader_out
))
1347 /* Only geometry shaders can use non-zero streams */
1348 assert(output_var
->data
.stream
== 0 ||
1349 (output_var
->data
.stream
< MAX_VERTEX_STREAMS
&&
1350 producer
->Stage
== MESA_SHADER_GEOMETRY
));
1352 tfeedback_candidate_generator
g(mem_ctx
, tfeedback_candidates
);
1353 g
.process(output_var
);
1355 ir_variable
*const input_var
=
1356 linker::get_matching_input(mem_ctx
, output_var
, consumer_inputs
,
1357 consumer_interface_inputs
,
1358 consumer_inputs_with_locations
);
1360 /* If a matching input variable was found, add this ouptut (and the
1361 * input) to the set. If this is a separable program and there is no
1362 * consumer stage, add the output.
1364 if (input_var
|| (prog
->SeparateShader
&& consumer
== NULL
)) {
1365 matches
.record(output_var
, input_var
);
1368 /* Only stream 0 outputs can be consumed in the next stage */
1369 if (input_var
&& output_var
->data
.stream
!= 0) {
1370 linker_error(prog
, "output %s is assigned to stream=%d but "
1371 "is linked to an input, which requires stream=0",
1372 output_var
->name
, output_var
->data
.stream
);
1377 /* If there's no producer stage, then this must be a separable program.
1378 * For example, we may have a program that has just a fragment shader.
1379 * Later this program will be used with some arbitrary vertex (or
1380 * geometry) shader program. This means that locations must be assigned
1381 * for all the inputs.
1383 foreach_in_list(ir_instruction
, node
, consumer
->ir
) {
1384 ir_variable
*const input_var
= node
->as_variable();
1386 if ((input_var
== NULL
) ||
1387 (input_var
->data
.mode
!= ir_var_shader_in
))
1390 matches
.record(NULL
, input_var
);
1394 for (unsigned i
= 0; i
< num_tfeedback_decls
; ++i
) {
1395 if (!tfeedback_decls
[i
].is_varying())
1398 const tfeedback_candidate
*matched_candidate
1399 = tfeedback_decls
[i
].find_candidate(prog
, tfeedback_candidates
);
1401 if (matched_candidate
== NULL
) {
1402 hash_table_dtor(tfeedback_candidates
);
1403 hash_table_dtor(consumer_inputs
);
1404 hash_table_dtor(consumer_interface_inputs
);
1408 if (matched_candidate
->toplevel_var
->data
.is_unmatched_generic_inout
)
1409 matches
.record(matched_candidate
->toplevel_var
, NULL
);
1412 const unsigned slots_used
= matches
.assign_locations();
1413 matches
.store_locations();
1415 for (unsigned i
= 0; i
< num_tfeedback_decls
; ++i
) {
1416 if (!tfeedback_decls
[i
].is_varying())
1419 if (!tfeedback_decls
[i
].assign_location(ctx
, prog
)) {
1420 hash_table_dtor(tfeedback_candidates
);
1421 hash_table_dtor(consumer_inputs
);
1422 hash_table_dtor(consumer_interface_inputs
);
1427 hash_table_dtor(tfeedback_candidates
);
1428 hash_table_dtor(consumer_inputs
);
1429 hash_table_dtor(consumer_interface_inputs
);
1431 if (ctx
->Const
.DisableVaryingPacking
) {
1432 /* Transform feedback code assumes varyings are packed, so if the driver
1433 * has disabled varying packing, make sure it does not support transform
1436 assert(!ctx
->Extensions
.EXT_transform_feedback
);
1439 lower_packed_varyings(mem_ctx
, slots_used
, ir_var_shader_out
,
1443 lower_packed_varyings(mem_ctx
, slots_used
, ir_var_shader_in
,
1444 gs_input_vertices
, consumer
);
1448 if (consumer
&& producer
) {
1449 foreach_in_list(ir_instruction
, node
, consumer
->ir
) {
1450 ir_variable
*const var
= node
->as_variable();
1452 if (var
&& var
->data
.mode
== ir_var_shader_in
&&
1453 var
->data
.is_unmatched_generic_inout
) {
1454 if (prog
->Version
<= 120) {
1455 /* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
1457 * Only those varying variables used (i.e. read) in
1458 * the fragment shader executable must be written to
1459 * by the vertex shader executable; declaring
1460 * superfluous varying variables in a vertex shader is
1463 * We interpret this text as meaning that the VS must
1464 * write the variable for the FS to read it. See
1465 * "glsl1-varying read but not written" in piglit.
1468 linker_error(prog
, "%s shader varying %s not written "
1470 _mesa_shader_stage_to_string(consumer
->Stage
),
1472 _mesa_shader_stage_to_string(producer
->Stage
));
1475 /* An 'in' variable is only really a shader input if its
1476 * value is written by the previous stage.
1478 var
->data
.mode
= ir_var_auto
;
1487 check_against_output_limit(struct gl_context
*ctx
,
1488 struct gl_shader_program
*prog
,
1489 gl_shader
*producer
)
1491 unsigned output_vectors
= 0;
1493 foreach_in_list(ir_instruction
, node
, producer
->ir
) {
1494 ir_variable
*const var
= node
->as_variable();
1496 if (var
&& var
->data
.mode
== ir_var_shader_out
&&
1497 var_counts_against_varying_limit(producer
->Stage
, var
)) {
1498 output_vectors
+= var
->type
->count_attribute_slots();
1502 assert(producer
->Stage
!= MESA_SHADER_FRAGMENT
);
1503 unsigned max_output_components
=
1504 ctx
->Const
.Program
[producer
->Stage
].MaxOutputComponents
;
1506 const unsigned output_components
= output_vectors
* 4;
1507 if (output_components
> max_output_components
) {
1508 if (ctx
->API
== API_OPENGLES2
|| prog
->IsES
)
1509 linker_error(prog
, "shader uses too many output vectors "
1512 max_output_components
/ 4);
1514 linker_error(prog
, "shader uses too many output components "
1517 max_output_components
);
1526 check_against_input_limit(struct gl_context
*ctx
,
1527 struct gl_shader_program
*prog
,
1528 gl_shader
*consumer
)
1530 unsigned input_vectors
= 0;
1532 foreach_in_list(ir_instruction
, node
, consumer
->ir
) {
1533 ir_variable
*const var
= node
->as_variable();
1535 if (var
&& var
->data
.mode
== ir_var_shader_in
&&
1536 var_counts_against_varying_limit(consumer
->Stage
, var
)) {
1537 input_vectors
+= var
->type
->count_attribute_slots();
1541 assert(consumer
->Stage
!= MESA_SHADER_VERTEX
);
1542 unsigned max_input_components
=
1543 ctx
->Const
.Program
[consumer
->Stage
].MaxInputComponents
;
1545 const unsigned input_components
= input_vectors
* 4;
1546 if (input_components
> max_input_components
) {
1547 if (ctx
->API
== API_OPENGLES2
|| prog
->IsES
)
1548 linker_error(prog
, "shader uses too many input vectors "
1551 max_input_components
/ 4);
1553 linker_error(prog
, "shader uses too many input components "
1556 max_input_components
);