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.
25 * \file shader_query.cpp
26 * C-to-C++ bridge functions to query GLSL shader data
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "main/context.h"
32 #include "main/core.h"
33 #include "main/enums.h"
34 #include "main/shaderapi.h"
35 #include "main/shaderobj.h"
36 #include "main/uniforms.h"
37 #include "glsl/glsl_symbol_table.h"
39 #include "glsl/program.h"
40 #include "program/hash_table.h"
41 #include "util/strndup.h"
45 program_resource_location(struct gl_shader_program
*shProg
,
46 struct gl_program_resource
*res
, const char *name
,
47 unsigned array_index
);
50 * Declare convenience functions to return resource data in a given type.
51 * Warning! this is not type safe so be *very* careful when using these.
53 #define DECL_RESOURCE_FUNC(name, type) \
54 const type * RESOURCE_ ## name (gl_program_resource *res) { \
56 return (type *) res->Data; \
59 DECL_RESOURCE_FUNC(VAR
, ir_variable
);
60 DECL_RESOURCE_FUNC(UBO
, gl_uniform_block
);
61 DECL_RESOURCE_FUNC(UNI
, gl_uniform_storage
);
62 DECL_RESOURCE_FUNC(ATC
, gl_active_atomic_buffer
);
63 DECL_RESOURCE_FUNC(XFB
, gl_transform_feedback_varying_info
);
64 DECL_RESOURCE_FUNC(SUB
, gl_subroutine_function
);
67 _mesa_BindAttribLocation(GLhandleARB program
, GLuint index
,
68 const GLcharARB
*name
)
70 GET_CURRENT_CONTEXT(ctx
);
72 struct gl_shader_program
*const shProg
=
73 _mesa_lookup_shader_program_err(ctx
, program
, "glBindAttribLocation");
80 if (strncmp(name
, "gl_", 3) == 0) {
81 _mesa_error(ctx
, GL_INVALID_OPERATION
,
82 "glBindAttribLocation(illegal name)");
86 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
87 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindAttribLocation(index)");
91 /* Replace the current value if it's already in the list. Add
92 * VERT_ATTRIB_GENERIC0 because that's how the linker differentiates
93 * between built-in attributes and user-defined attributes.
95 shProg
->AttributeBindings
->put(index
+ VERT_ATTRIB_GENERIC0
, name
);
98 * Note that this attribute binding won't go into effect until
99 * glLinkProgram is called again.
104 is_active_attrib(const ir_variable
*var
)
109 switch (var
->data
.mode
) {
110 case ir_var_shader_in
:
111 return var
->data
.location
!= -1;
113 case ir_var_system_value
:
114 /* From GL 4.3 core spec, section 11.1.1 (Vertex Attributes):
115 * "For GetActiveAttrib, all active vertex shader input variables
116 * are enumerated, including the special built-in inputs gl_VertexID
117 * and gl_InstanceID."
119 return var
->data
.location
== SYSTEM_VALUE_VERTEX_ID
||
120 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
||
121 var
->data
.location
== SYSTEM_VALUE_INSTANCE_ID
;
129 _mesa_GetActiveAttrib(GLhandleARB program
, GLuint desired_index
,
130 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
131 GLenum
* type
, GLcharARB
* name
)
133 GET_CURRENT_CONTEXT(ctx
);
134 struct gl_shader_program
*shProg
;
137 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(maxLength < 0)");
141 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveAttrib");
145 if (!shProg
->LinkStatus
) {
146 _mesa_error(ctx
, GL_INVALID_VALUE
,
147 "glGetActiveAttrib(program not linked)");
151 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
152 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(no vertex shader)");
156 struct gl_program_resource
*res
=
157 _mesa_program_resource_find_index(shProg
, GL_PROGRAM_INPUT
,
160 /* User asked for index that does not exist. */
162 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(index)");
166 const ir_variable
*const var
= RESOURCE_VAR(res
);
168 if (!is_active_attrib(var
))
171 const char *var_name
= var
->name
;
173 /* Since gl_VertexID may be lowered to gl_VertexIDMESA, we need to
174 * consider gl_VertexIDMESA as gl_VertexID for purposes of checking
177 if (var
->data
.mode
== ir_var_system_value
&&
178 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
179 var_name
= "gl_VertexID";
182 _mesa_copy_string(name
, maxLength
, length
, var_name
);
185 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_ARRAY_SIZE
,
186 size
, "glGetActiveAttrib");
189 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_TYPE
,
190 (GLint
*) type
, "glGetActiveAttrib");
194 _mesa_GetAttribLocation(GLhandleARB program
, const GLcharARB
* name
)
196 GET_CURRENT_CONTEXT(ctx
);
197 struct gl_shader_program
*const shProg
=
198 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
204 if (!shProg
->LinkStatus
) {
205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
206 "glGetAttribLocation(program not linked)");
213 /* Not having a vertex shader is not an error.
215 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)
218 unsigned array_index
= 0;
219 struct gl_program_resource
*res
=
220 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_INPUT
, name
,
226 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
228 /* The extra check against against 0 is made because of builtin-attribute
229 * locations that have offset applied. Function program_resource_location
230 * can return built-in attribute locations < 0 and glGetAttribLocation
231 * cannot be used on "conventional" attributes.
233 * From page 95 of the OpenGL 3.0 spec:
235 * "If name is not an active attribute, if name is a conventional
236 * attribute, or if an error occurs, -1 will be returned."
238 return (loc
>= 0) ? loc
: -1;
242 _mesa_count_active_attribs(struct gl_shader_program
*shProg
)
244 if (!shProg
->LinkStatus
245 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
249 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
251 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
252 if (res
->Type
== GL_PROGRAM_INPUT
&&
253 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
) &&
254 is_active_attrib(RESOURCE_VAR(res
)))
262 _mesa_longest_attribute_name_length(struct gl_shader_program
*shProg
)
264 if (!shProg
->LinkStatus
265 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
269 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
271 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
272 if (res
->Type
== GL_PROGRAM_INPUT
&&
273 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
)) {
275 const size_t length
= strlen(RESOURCE_VAR(res
)->name
);
276 if (length
>= longest
)
277 longest
= length
+ 1;
285 _mesa_BindFragDataLocation(GLuint program
, GLuint colorNumber
,
288 _mesa_BindFragDataLocationIndexed(program
, colorNumber
, 0, name
);
292 _mesa_BindFragDataLocationIndexed(GLuint program
, GLuint colorNumber
,
293 GLuint index
, const GLchar
*name
)
295 GET_CURRENT_CONTEXT(ctx
);
297 struct gl_shader_program
*const shProg
=
298 _mesa_lookup_shader_program_err(ctx
, program
, "glBindFragDataLocationIndexed");
305 if (strncmp(name
, "gl_", 3) == 0) {
306 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFragDataLocationIndexed(illegal name)");
311 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(index)");
315 if (index
== 0 && colorNumber
>= ctx
->Const
.MaxDrawBuffers
) {
316 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
320 if (index
== 1 && colorNumber
>= ctx
->Const
.MaxDualSourceDrawBuffers
) {
321 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
325 /* Replace the current value if it's already in the list. Add
326 * FRAG_RESULT_DATA0 because that's how the linker differentiates
327 * between built-in attributes and user-defined attributes.
329 shProg
->FragDataBindings
->put(colorNumber
+ FRAG_RESULT_DATA0
, name
);
330 shProg
->FragDataIndexBindings
->put(index
, name
);
332 * Note that this binding won't go into effect until
333 * glLinkProgram is called again.
339 _mesa_GetFragDataIndex(GLuint program
, const GLchar
*name
)
341 GET_CURRENT_CONTEXT(ctx
);
342 struct gl_shader_program
*const shProg
=
343 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataIndex");
349 if (!shProg
->LinkStatus
) {
350 _mesa_error(ctx
, GL_INVALID_OPERATION
,
351 "glGetFragDataIndex(program not linked)");
358 if (strncmp(name
, "gl_", 3) == 0) {
359 _mesa_error(ctx
, GL_INVALID_OPERATION
,
360 "glGetFragDataIndex(illegal name)");
364 /* Not having a fragment shader is not an error.
366 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
369 return _mesa_program_resource_location_index(shProg
, GL_PROGRAM_OUTPUT
,
374 _mesa_GetFragDataLocation(GLuint program
, const GLchar
*name
)
376 GET_CURRENT_CONTEXT(ctx
);
377 struct gl_shader_program
*const shProg
=
378 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataLocation");
384 if (!shProg
->LinkStatus
) {
385 _mesa_error(ctx
, GL_INVALID_OPERATION
,
386 "glGetFragDataLocation(program not linked)");
393 if (strncmp(name
, "gl_", 3) == 0) {
394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
395 "glGetFragDataLocation(illegal name)");
399 /* Not having a fragment shader is not an error.
401 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
404 unsigned array_index
= 0;
405 struct gl_program_resource
*res
=
406 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_OUTPUT
, name
,
412 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
414 /* The extra check against against 0 is made because of builtin-attribute
415 * locations that have offset applied. Function program_resource_location
416 * can return built-in attribute locations < 0 and glGetFragDataLocation
417 * cannot be used on "conventional" attributes.
419 * From page 95 of the OpenGL 3.0 spec:
421 * "If name is not an active attribute, if name is a conventional
422 * attribute, or if an error occurs, -1 will be returned."
424 return (loc
>= 0) ? loc
: -1;
428 _mesa_program_resource_name(struct gl_program_resource
*res
)
430 const ir_variable
*var
;
432 case GL_UNIFORM_BLOCK
:
433 case GL_SHADER_STORAGE_BLOCK
:
434 return RESOURCE_UBO(res
)->Name
;
435 case GL_TRANSFORM_FEEDBACK_VARYING
:
436 return RESOURCE_XFB(res
)->Name
;
437 case GL_PROGRAM_INPUT
:
438 var
= RESOURCE_VAR(res
);
439 /* Special case gl_VertexIDMESA -> gl_VertexID. */
440 if (var
->data
.mode
== ir_var_system_value
&&
441 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
442 return "gl_VertexID";
445 case GL_PROGRAM_OUTPUT
:
446 return RESOURCE_VAR(res
)->name
;
448 case GL_BUFFER_VARIABLE
:
449 return RESOURCE_UNI(res
)->name
;
450 case GL_VERTEX_SUBROUTINE_UNIFORM
:
451 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
452 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
453 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
454 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
455 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
456 return RESOURCE_UNI(res
)->name
+ MESA_SUBROUTINE_PREFIX_LEN
;
457 case GL_VERTEX_SUBROUTINE
:
458 case GL_GEOMETRY_SUBROUTINE
:
459 case GL_FRAGMENT_SUBROUTINE
:
460 case GL_COMPUTE_SUBROUTINE
:
461 case GL_TESS_CONTROL_SUBROUTINE
:
462 case GL_TESS_EVALUATION_SUBROUTINE
:
463 return RESOURCE_SUB(res
)->name
;
465 assert(!"support for resource type not implemented");
472 _mesa_program_resource_array_size(struct gl_program_resource
*res
)
475 case GL_TRANSFORM_FEEDBACK_VARYING
:
476 return RESOURCE_XFB(res
)->Size
> 1 ?
477 RESOURCE_XFB(res
)->Size
: 0;
478 case GL_PROGRAM_INPUT
:
479 case GL_PROGRAM_OUTPUT
:
480 return RESOURCE_VAR(res
)->type
->length
;
482 case GL_VERTEX_SUBROUTINE_UNIFORM
:
483 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
484 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
485 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
486 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
487 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
488 return RESOURCE_UNI(res
)->array_elements
;
489 case GL_BUFFER_VARIABLE
:
491 if (RESOURCE_UNI(res
)->array_stride
> 0 &&
492 RESOURCE_UNI(res
)->array_elements
== 0)
495 return RESOURCE_UNI(res
)->array_elements
;
496 case GL_VERTEX_SUBROUTINE
:
497 case GL_GEOMETRY_SUBROUTINE
:
498 case GL_FRAGMENT_SUBROUTINE
:
499 case GL_COMPUTE_SUBROUTINE
:
500 case GL_TESS_CONTROL_SUBROUTINE
:
501 case GL_TESS_EVALUATION_SUBROUTINE
:
502 case GL_ATOMIC_COUNTER_BUFFER
:
503 case GL_UNIFORM_BLOCK
:
504 case GL_SHADER_STORAGE_BLOCK
:
507 assert(!"support for resource type not implemented");
513 * Checks if array subscript is valid and if so sets array_index.
516 valid_array_index(const GLchar
*name
, unsigned *array_index
)
519 const GLchar
*out_base_name_end
;
521 idx
= parse_program_resource_name(name
, &out_base_name_end
);
531 /* Find a program resource with specific name in given interface.
533 struct gl_program_resource
*
534 _mesa_program_resource_find_name(struct gl_shader_program
*shProg
,
535 GLenum programInterface
, const char *name
,
536 unsigned *array_index
)
538 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
539 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
540 if (res
->Type
!= programInterface
)
543 /* Resource basename. */
544 const char *rname
= _mesa_program_resource_name(res
);
545 unsigned baselen
= strlen(rname
);
546 unsigned baselen_without_array_index
= baselen
;
547 const char *rname_last_square_bracket
= strrchr(rname
, '[');
549 bool rname_has_array_index_zero
= false;
550 /* From ARB_program_interface_query spec:
552 * "uint GetProgramResourceIndex(uint program, enum programInterface,
555 * If <name> exactly matches the name string of one of the active
556 * resources for <programInterface>, the index of the matched resource is
557 * returned. Additionally, if <name> would exactly match the name string
558 * of an active resource if "[0]" were appended to <name>, the index of
559 * the matched resource is returned. [...]"
561 * "A string provided to GetProgramResourceLocation or
562 * GetProgramResourceLocationIndex is considered to match an active variable
565 * * the string exactly matches the name of the active variable;
567 * * if the string identifies the base name of an active array, where the
568 * string would exactly match the name of the variable if the suffix
569 * "[0]" were appended to the string; [...]"
571 /* Remove array's index from interface block name comparison only if
572 * array's index is zero and the resulting string length is the same
573 * than the provided name's length.
575 if (rname_last_square_bracket
) {
576 baselen_without_array_index
-= strlen(rname_last_square_bracket
);
577 rname_has_array_index_zero
=
578 (strncmp(rname_last_square_bracket
, "[0]\0", 4) == 0) &&
579 (baselen_without_array_index
== strlen(name
));
582 if (strncmp(rname
, name
, baselen
) == 0)
584 else if (rname_has_array_index_zero
&&
585 strncmp(rname
, name
, baselen_without_array_index
) == 0)
589 switch (programInterface
) {
590 case GL_UNIFORM_BLOCK
:
591 case GL_SHADER_STORAGE_BLOCK
:
592 /* Basename match, check if array or struct. */
593 if (rname_has_array_index_zero
||
594 name
[baselen
] == '\0' ||
595 name
[baselen
] == '[' ||
596 name
[baselen
] == '.') {
600 case GL_TRANSFORM_FEEDBACK_VARYING
:
601 case GL_BUFFER_VARIABLE
:
603 case GL_VERTEX_SUBROUTINE_UNIFORM
:
604 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
605 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
606 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
607 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
608 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
609 case GL_VERTEX_SUBROUTINE
:
610 case GL_GEOMETRY_SUBROUTINE
:
611 case GL_FRAGMENT_SUBROUTINE
:
612 case GL_COMPUTE_SUBROUTINE
:
613 case GL_TESS_CONTROL_SUBROUTINE
:
614 case GL_TESS_EVALUATION_SUBROUTINE
:
615 if (name
[baselen
] == '.') {
619 case GL_PROGRAM_INPUT
:
620 case GL_PROGRAM_OUTPUT
:
621 if (name
[baselen
] == '\0') {
623 } else if (name
[baselen
] == '[' &&
624 valid_array_index(name
, array_index
)) {
629 assert(!"not implemented for given interface");
637 calc_resource_index(struct gl_shader_program
*shProg
,
638 struct gl_program_resource
*res
)
642 for (i
= 0; i
< shProg
->NumProgramResourceList
; i
++) {
643 if (&shProg
->ProgramResourceList
[i
] == res
)
645 if (shProg
->ProgramResourceList
[i
].Type
== res
->Type
)
648 return GL_INVALID_INDEX
;
652 * Calculate index for the given resource.
655 _mesa_program_resource_index(struct gl_shader_program
*shProg
,
656 struct gl_program_resource
*res
)
659 return GL_INVALID_INDEX
;
662 case GL_ATOMIC_COUNTER_BUFFER
:
663 return RESOURCE_ATC(res
) - shProg
->AtomicBuffers
;
664 case GL_VERTEX_SUBROUTINE
:
665 case GL_GEOMETRY_SUBROUTINE
:
666 case GL_FRAGMENT_SUBROUTINE
:
667 case GL_COMPUTE_SUBROUTINE
:
668 case GL_TESS_CONTROL_SUBROUTINE
:
669 case GL_TESS_EVALUATION_SUBROUTINE
:
670 return RESOURCE_SUB(res
)->index
;
671 case GL_UNIFORM_BLOCK
:
672 case GL_SHADER_STORAGE_BLOCK
:
673 case GL_TRANSFORM_FEEDBACK_VARYING
:
675 return calc_resource_index(shProg
, res
);
680 * Find a program resource that points to given data.
682 static struct gl_program_resource
*
683 program_resource_find_data(struct gl_shader_program
*shProg
, void *data
)
685 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
686 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
687 if (res
->Data
== data
)
693 /* Find a program resource with specific index in given interface.
695 struct gl_program_resource
*
696 _mesa_program_resource_find_index(struct gl_shader_program
*shProg
,
697 GLenum programInterface
, GLuint index
)
699 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
702 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
703 if (res
->Type
!= programInterface
)
707 case GL_UNIFORM_BLOCK
:
708 case GL_ATOMIC_COUNTER_BUFFER
:
709 case GL_SHADER_STORAGE_BLOCK
:
710 if (_mesa_program_resource_index(shProg
, res
) == index
)
713 case GL_TRANSFORM_FEEDBACK_VARYING
:
714 case GL_PROGRAM_INPUT
:
715 case GL_PROGRAM_OUTPUT
:
717 case GL_VERTEX_SUBROUTINE_UNIFORM
:
718 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
719 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
720 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
721 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
722 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
723 case GL_VERTEX_SUBROUTINE
:
724 case GL_GEOMETRY_SUBROUTINE
:
725 case GL_FRAGMENT_SUBROUTINE
:
726 case GL_COMPUTE_SUBROUTINE
:
727 case GL_TESS_CONTROL_SUBROUTINE
:
728 case GL_TESS_EVALUATION_SUBROUTINE
:
729 case GL_BUFFER_VARIABLE
:
730 if (++idx
== (int) index
)
734 assert(!"not implemented for given interface");
740 /* Function returns if resource name is expected to have index
744 * Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
747 * "If the active uniform is an array, the uniform name returned in
748 * name will always be the name of the uniform array appended with
751 * The same text also appears in the OpenGL 4.2 spec. It does not,
752 * however, appear in any previous spec. Previous specifications are
753 * ambiguous in this regard. However, either name can later be passed
754 * to glGetUniformLocation (and related APIs), so there shouldn't be any
755 * harm in always appending "[0]" to uniform array names.
757 * Geometry shader stage has different naming convention where the 'normal'
758 * condition is an array, therefore for variables referenced in geometry
759 * stage we do not add '[0]'.
761 * Note, that TCS outputs and TES inputs should not have index appended
765 add_index_to_name(struct gl_program_resource
*res
)
767 bool add_index
= !(((res
->Type
== GL_PROGRAM_INPUT
) &&
768 res
->StageReferences
& (1 << MESA_SHADER_GEOMETRY
)));
770 /* Transform feedback varyings have array index already appended
773 if (res
->Type
== GL_TRANSFORM_FEEDBACK_VARYING
)
779 /* Get name length of a program resource. This consists of
780 * base name + 3 for '[0]' if resource is an array.
783 _mesa_program_resource_name_len(struct gl_program_resource
*res
)
785 unsigned length
= strlen(_mesa_program_resource_name(res
));
786 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
))
791 /* Get full name of a program resource.
794 _mesa_get_program_resource_name(struct gl_shader_program
*shProg
,
795 GLenum programInterface
, GLuint index
,
796 GLsizei bufSize
, GLsizei
*length
,
797 GLchar
*name
, const char *caller
)
799 GET_CURRENT_CONTEXT(ctx
);
801 /* Find resource with given interface and index. */
802 struct gl_program_resource
*res
=
803 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
805 /* The error INVALID_VALUE is generated if <index> is greater than
806 * or equal to the number of entries in the active resource list for
807 * <programInterface>.
810 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index %u)", caller
, index
);
815 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize %d)", caller
, bufSize
);
822 length
= &localLength
;
824 _mesa_copy_string(name
, bufSize
, length
, _mesa_program_resource_name(res
));
826 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
)) {
829 /* The comparison is strange because *length does *NOT* include the
830 * terminating NUL, but maxLength does.
832 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < bufSize
; i
++)
833 name
[*length
+ i
] = "[0]"[i
];
835 name
[*length
+ i
] = '\0';
842 program_resource_location(struct gl_shader_program
*shProg
,
843 struct gl_program_resource
*res
, const char *name
,
844 unsigned array_index
)
846 /* Built-in locations should report GL_INVALID_INDEX. */
847 if (is_gl_identifier(name
))
848 return GL_INVALID_INDEX
;
850 /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
851 * offsets are used internally to differentiate between built-in attributes
852 * and user-defined attributes.
855 case GL_PROGRAM_INPUT
: {
856 const ir_variable
*var
= RESOURCE_VAR(res
);
858 /* If the input is an array, fail if the index is out of bounds. */
860 && array_index
>= var
->type
->length
) {
863 return (var
->data
.location
+
864 (array_index
* var
->type
->without_array()->matrix_columns
) -
865 VERT_ATTRIB_GENERIC0
);
867 case GL_PROGRAM_OUTPUT
:
868 /* If the output is an array, fail if the index is out of bounds. */
870 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
873 return RESOURCE_VAR(res
)->data
.location
+ array_index
- FRAG_RESULT_DATA0
;
875 /* If the uniform is built-in, fail. */
876 if (RESOURCE_UNI(res
)->builtin
)
879 /* From page 79 of the OpenGL 4.2 spec:
881 * "A valid name cannot be a structure, an array of structures, or any
882 * portion of a single vector or a matrix."
884 if (RESOURCE_UNI(res
)->type
->without_array()->is_record())
887 /* From the GL_ARB_uniform_buffer_object spec:
889 * "The value -1 will be returned if <name> does not correspond to an
890 * active uniform variable name in <program>, if <name> is associated
891 * with a named uniform block, or if <name> starts with the reserved
894 if (RESOURCE_UNI(res
)->block_index
!= -1 ||
895 RESOURCE_UNI(res
)->atomic_buffer_index
!= -1)
899 case GL_VERTEX_SUBROUTINE_UNIFORM
:
900 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
901 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
902 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
903 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
904 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
905 /* If the uniform is an array, fail if the index is out of bounds. */
907 && array_index
>= RESOURCE_UNI(res
)->array_elements
) {
911 /* location in remap table + array element offset */
912 return RESOURCE_UNI(res
)->remap_location
+ array_index
;
919 * Function implements following location queries:
920 * glGetUniformLocation
923 _mesa_program_resource_location(struct gl_shader_program
*shProg
,
924 GLenum programInterface
, const char *name
)
926 unsigned array_index
= 0;
927 struct gl_program_resource
*res
=
928 _mesa_program_resource_find_name(shProg
, programInterface
, name
,
931 /* Resource not found. */
935 return program_resource_location(shProg
, res
, name
, array_index
);
939 * Function implements following index queries:
943 _mesa_program_resource_location_index(struct gl_shader_program
*shProg
,
944 GLenum programInterface
, const char *name
)
946 struct gl_program_resource
*res
=
947 _mesa_program_resource_find_name(shProg
, programInterface
, name
, NULL
);
949 /* Non-existent variable or resource is not referenced by fragment stage. */
950 if (!res
|| !(res
->StageReferences
& (1 << MESA_SHADER_FRAGMENT
)))
953 return RESOURCE_VAR(res
)->data
.index
;
957 stage_from_enum(GLenum ref
)
960 case GL_REFERENCED_BY_VERTEX_SHADER
:
961 return MESA_SHADER_VERTEX
;
962 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
963 return MESA_SHADER_TESS_CTRL
;
964 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
965 return MESA_SHADER_TESS_EVAL
;
966 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
967 return MESA_SHADER_GEOMETRY
;
968 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
969 return MESA_SHADER_FRAGMENT
;
970 case GL_REFERENCED_BY_COMPUTE_SHADER
:
971 return MESA_SHADER_COMPUTE
;
973 assert(!"shader stage not supported");
974 return MESA_SHADER_STAGES
;
979 * Check if resource is referenced by given 'referenced by' stage enum.
980 * ATC and UBO resources hold stage references of their own.
983 is_resource_referenced(struct gl_shader_program
*shProg
,
984 struct gl_program_resource
*res
,
985 GLuint index
, uint8_t stage
)
987 /* First, check if we even have such a stage active. */
988 if (!shProg
->_LinkedShaders
[stage
])
991 if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
)
992 return RESOURCE_ATC(res
)->StageReferences
[stage
];
994 if (res
->Type
== GL_UNIFORM_BLOCK
|| res
->Type
== GL_SHADER_STORAGE_BLOCK
)
995 return shProg
->InterfaceBlockStageIndex
[stage
][index
] != -1;
997 return res
->StageReferences
& (1 << stage
);
1001 get_buffer_property(struct gl_shader_program
*shProg
,
1002 struct gl_program_resource
*res
, const GLenum prop
,
1003 GLint
*val
, const char *caller
)
1005 GET_CURRENT_CONTEXT(ctx
);
1006 if (res
->Type
!= GL_UNIFORM_BLOCK
&&
1007 res
->Type
!= GL_ATOMIC_COUNTER_BUFFER
&&
1008 res
->Type
!= GL_SHADER_STORAGE_BLOCK
)
1009 goto invalid_operation
;
1011 if (res
->Type
== GL_UNIFORM_BLOCK
) {
1013 case GL_BUFFER_BINDING
:
1014 *val
= RESOURCE_UBO(res
)->Binding
;
1016 case GL_BUFFER_DATA_SIZE
:
1017 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1019 case GL_NUM_ACTIVE_VARIABLES
:
1021 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1022 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1023 struct gl_program_resource
*uni
=
1024 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1031 case GL_ACTIVE_VARIABLES
: {
1032 unsigned num_values
= 0;
1033 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1034 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1035 struct gl_program_resource
*uni
=
1036 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1041 _mesa_program_resource_index(shProg
, uni
);
1047 } else if (res
->Type
== GL_SHADER_STORAGE_BLOCK
) {
1049 case GL_BUFFER_BINDING
:
1050 *val
= RESOURCE_UBO(res
)->Binding
;
1052 case GL_BUFFER_DATA_SIZE
:
1053 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1055 case GL_NUM_ACTIVE_VARIABLES
:
1057 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1058 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1059 struct gl_program_resource
*uni
=
1060 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1067 case GL_ACTIVE_VARIABLES
: {
1068 unsigned num_values
= 0;
1069 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1070 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1071 struct gl_program_resource
*uni
=
1072 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1077 _mesa_program_resource_index(shProg
, uni
);
1083 } else if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
) {
1085 case GL_BUFFER_BINDING
:
1086 *val
= RESOURCE_ATC(res
)->Binding
;
1088 case GL_BUFFER_DATA_SIZE
:
1089 *val
= RESOURCE_ATC(res
)->MinimumSize
;
1091 case GL_NUM_ACTIVE_VARIABLES
:
1092 *val
= RESOURCE_ATC(res
)->NumUniforms
;
1094 case GL_ACTIVE_VARIABLES
:
1095 for (unsigned i
= 0; i
< RESOURCE_ATC(res
)->NumUniforms
; i
++) {
1096 /* Active atomic buffer contains index to UniformStorage. Find
1097 * out gl_program_resource via data pointer and then calculate
1098 * index of that uniform.
1100 unsigned idx
= RESOURCE_ATC(res
)->Uniforms
[i
];
1101 struct gl_program_resource
*uni
=
1102 program_resource_find_data(shProg
,
1103 &shProg
->UniformStorage
[idx
]);
1105 *val
++ = _mesa_program_resource_index(shProg
, uni
);
1107 return RESOURCE_ATC(res
)->NumUniforms
;
1110 assert(!"support for property type not implemented");
1113 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1114 _mesa_enum_to_string(res
->Type
),
1115 _mesa_enum_to_string(prop
));
1121 _mesa_program_resource_prop(struct gl_shader_program
*shProg
,
1122 struct gl_program_resource
*res
, GLuint index
,
1123 const GLenum prop
, GLint
*val
, const char *caller
)
1125 GET_CURRENT_CONTEXT(ctx
);
1127 #define VALIDATE_TYPE(type)\
1128 if (res->Type != type)\
1129 goto invalid_operation;
1131 #define VALIDATE_TYPE_2(type1, type2)\
1132 if (res->Type != type1 && res->Type != type2)\
1133 goto invalid_operation;
1136 case GL_NAME_LENGTH
:
1137 switch (res
->Type
) {
1138 case GL_ATOMIC_COUNTER_BUFFER
:
1139 goto invalid_operation
;
1141 /* Resource name length + terminator. */
1142 *val
= _mesa_program_resource_name_len(res
) + 1;
1146 switch (res
->Type
) {
1148 case GL_BUFFER_VARIABLE
:
1149 *val
= RESOURCE_UNI(res
)->type
->gl_type
;
1151 case GL_PROGRAM_INPUT
:
1152 case GL_PROGRAM_OUTPUT
:
1153 *val
= RESOURCE_VAR(res
)->type
->gl_type
;
1155 case GL_TRANSFORM_FEEDBACK_VARYING
:
1156 *val
= RESOURCE_XFB(res
)->Type
;
1159 goto invalid_operation
;
1162 switch (res
->Type
) {
1164 case GL_BUFFER_VARIABLE
:
1165 /* Test if a buffer variable is an array or an unsized array.
1166 * Unsized arrays return zero as array size.
1168 if (RESOURCE_UNI(res
)->is_shader_storage
&&
1169 RESOURCE_UNI(res
)->array_stride
> 0)
1170 *val
= RESOURCE_UNI(res
)->array_elements
;
1172 *val
= MAX2(RESOURCE_UNI(res
)->array_elements
, 1);
1174 case GL_PROGRAM_INPUT
:
1175 case GL_PROGRAM_OUTPUT
:
1176 *val
= MAX2(_mesa_program_resource_array_size(res
), 1);
1178 case GL_TRANSFORM_FEEDBACK_VARYING
:
1179 *val
= MAX2(RESOURCE_XFB(res
)->Size
, 1);
1182 goto invalid_operation
;
1185 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1186 *val
= RESOURCE_UNI(res
)->offset
;
1188 case GL_BLOCK_INDEX
:
1189 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1190 *val
= RESOURCE_UNI(res
)->block_index
;
1192 case GL_ARRAY_STRIDE
:
1193 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1194 *val
= RESOURCE_UNI(res
)->array_stride
;
1196 case GL_MATRIX_STRIDE
:
1197 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1198 *val
= RESOURCE_UNI(res
)->matrix_stride
;
1200 case GL_IS_ROW_MAJOR
:
1201 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1202 *val
= RESOURCE_UNI(res
)->row_major
;
1204 case GL_ATOMIC_COUNTER_BUFFER_INDEX
:
1205 VALIDATE_TYPE(GL_UNIFORM
);
1206 *val
= RESOURCE_UNI(res
)->atomic_buffer_index
;
1208 case GL_BUFFER_BINDING
:
1209 case GL_BUFFER_DATA_SIZE
:
1210 case GL_NUM_ACTIVE_VARIABLES
:
1211 case GL_ACTIVE_VARIABLES
:
1212 return get_buffer_property(shProg
, res
, prop
, val
, caller
);
1213 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1214 if (!_mesa_has_compute_shaders(ctx
))
1217 case GL_REFERENCED_BY_VERTEX_SHADER
:
1218 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1219 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1220 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1221 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1222 switch (res
->Type
) {
1224 case GL_PROGRAM_INPUT
:
1225 case GL_PROGRAM_OUTPUT
:
1226 case GL_UNIFORM_BLOCK
:
1227 case GL_BUFFER_VARIABLE
:
1228 case GL_SHADER_STORAGE_BLOCK
:
1229 case GL_ATOMIC_COUNTER_BUFFER
:
1230 *val
= is_resource_referenced(shProg
, res
, index
,
1231 stage_from_enum(prop
));
1234 goto invalid_operation
;
1237 switch (res
->Type
) {
1239 case GL_PROGRAM_INPUT
:
1240 case GL_PROGRAM_OUTPUT
:
1241 *val
= program_resource_location(shProg
, res
,
1242 _mesa_program_resource_name(res
),
1246 goto invalid_operation
;
1248 case GL_LOCATION_INDEX
:
1249 if (res
->Type
!= GL_PROGRAM_OUTPUT
)
1250 goto invalid_operation
;
1251 *val
= RESOURCE_VAR(res
)->data
.index
;
1254 case GL_NUM_COMPATIBLE_SUBROUTINES
:
1255 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1256 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1257 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1258 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1259 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1260 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1261 goto invalid_operation
;
1262 *val
= RESOURCE_UNI(res
)->num_compatible_subroutines
;
1264 case GL_COMPATIBLE_SUBROUTINES
: {
1265 const struct gl_uniform_storage
*uni
;
1266 struct gl_shader
*sh
;
1270 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1271 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1272 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1273 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1274 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1275 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1276 goto invalid_operation
;
1277 uni
= RESOURCE_UNI(res
);
1279 sh
= shProg
->_LinkedShaders
[_mesa_shader_stage_from_subroutine_uniform(res
->Type
)];
1281 for (i
= 0; i
< sh
->NumSubroutineFunctions
; i
++) {
1282 struct gl_subroutine_function
*fn
= &sh
->SubroutineFunctions
[i
];
1283 for (j
= 0; j
< fn
->num_compat_types
; j
++) {
1284 if (fn
->types
[j
] == uni
->type
) {
1293 case GL_TOP_LEVEL_ARRAY_SIZE
:
1294 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1295 *val
= RESOURCE_UNI(res
)->top_level_array_size
;
1298 case GL_TOP_LEVEL_ARRAY_STRIDE
:
1299 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1300 *val
= RESOURCE_UNI(res
)->top_level_array_stride
;
1303 /* GL_ARB_tessellation_shader */
1304 case GL_IS_PER_PATCH
:
1305 switch (res
->Type
) {
1306 case GL_PROGRAM_INPUT
:
1307 case GL_PROGRAM_OUTPUT
:
1308 *val
= RESOURCE_VAR(res
)->data
.patch
;
1311 goto invalid_operation
;
1317 #undef VALIDATE_TYPE
1318 #undef VALIDATE_TYPE_2
1321 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(%s prop %s)", caller
,
1322 _mesa_enum_to_string(res
->Type
),
1323 _mesa_enum_to_string(prop
));
1327 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1328 _mesa_enum_to_string(res
->Type
),
1329 _mesa_enum_to_string(prop
));
1334 _mesa_get_program_resourceiv(struct gl_shader_program
*shProg
,
1335 GLenum programInterface
, GLuint index
, GLsizei propCount
,
1336 const GLenum
*props
, GLsizei bufSize
,
1337 GLsizei
*length
, GLint
*params
)
1339 GET_CURRENT_CONTEXT(ctx
);
1340 GLint
*val
= (GLint
*) params
;
1341 const GLenum
*prop
= props
;
1344 struct gl_program_resource
*res
=
1345 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
1347 /* No such resource found or bufSize negative. */
1348 if (!res
|| bufSize
< 0) {
1349 _mesa_error(ctx
, GL_INVALID_VALUE
,
1350 "glGetProgramResourceiv(%s index %d bufSize %d)",
1351 _mesa_enum_to_string(programInterface
), index
, bufSize
);
1355 /* Write propCount values until error occurs or bufSize reached. */
1356 for (int i
= 0; i
< propCount
&& i
< bufSize
; i
++, val
++, prop
++) {
1358 _mesa_program_resource_prop(shProg
, res
, index
, *prop
, val
,
1359 "glGetProgramResourceiv");
1361 /* Error happened. */
1362 if (props_written
== 0)
1365 amount
+= props_written
;
1368 /* If <length> is not NULL, the actual number of integer values
1369 * written to <params> will be written to <length>.
1376 validate_io(const struct gl_shader
*producer
,
1377 const struct gl_shader
*consumer
, bool isES
)
1379 assert(producer
&& consumer
);
1380 unsigned inputs
= 0, outputs
= 0;
1382 /* From OpenGL ES 3.1 spec (Interface matching):
1384 * "An output variable is considered to match an input variable in the
1385 * subsequent shader if:
1387 * - the two variables match in name, type, and qualification; or
1388 * - the two variables are declared with the same location qualifier and
1389 * match in type and qualification.
1393 * At an interface between program objects, the set of inputs and outputs
1394 * are considered to match exactly if and only if:
1396 * - Every declared input variable has a matching output, as described
1399 * - There are no user-defined output variables declared without a
1400 * matching input variable declaration.
1402 * - All matched input and output variables have identical precision
1405 * When the set of inputs and outputs on an interface between programs
1406 * matches exactly, all inputs are well-defined except when the
1407 * corresponding outputs were not written in the previous shader. However,
1408 * any mismatch between inputs and outputs will result in a validation
1411 * OpenGL Core 4.5 spec includes same paragraph as above but without check
1412 * for precision and the last 'validation failure' clause. Therefore
1413 * behaviour is more relaxed, input and output amount is not required by the
1414 * spec to be validated.
1416 * FIXME: Update once Khronos spec bug #15331 is resolved.
1417 * FIXME: Add validation by type, currently information loss during varying
1418 * packing makes this challenging.
1421 /* Currently no matching done for desktop. */
1425 /* For each output in a, find input in b and do any required checks. */
1426 foreach_in_list(ir_instruction
, out
, producer
->ir
) {
1427 ir_variable
*out_var
= out
->as_variable();
1428 if (!out_var
|| out_var
->data
.mode
!= ir_var_shader_out
||
1429 is_gl_identifier(out_var
->name
))
1435 foreach_in_list(ir_instruction
, in
, consumer
->ir
) {
1436 ir_variable
*in_var
= in
->as_variable();
1437 if (!in_var
|| in_var
->data
.mode
!= ir_var_shader_in
||
1438 is_gl_identifier(in_var
->name
))
1443 /* Match by location qualifier and precision.
1445 * FIXME: Add explicit location matching validation here. Be careful
1446 * not to match varyings with explicit locations to varyings without
1447 * explicit locations.
1449 if ((in_var
->data
.explicit_location
&&
1450 out_var
->data
.explicit_location
) &&
1451 in_var
->data
.location
== out_var
->data
.location
&&
1452 in_var
->data
.precision
== out_var
->data
.precision
)
1455 unsigned len
= strlen(in_var
->name
);
1457 /* Handle input swizzle in variable name. */
1458 const char *dot
= strchr(in_var
->name
, '.');
1460 len
= dot
- in_var
->name
;
1462 /* Match by name and precision. */
1463 if (strncmp(in_var
->name
, out_var
->name
, len
) == 0) {
1464 /* From OpenGL ES 3.1 spec:
1465 * "When both shaders are in separate programs, mismatched
1466 * precision qualifiers will result in a program interface
1467 * mismatch that will result in program pipeline validation
1468 * failures, as described in section 7.4.1 (“Shader Interface
1469 * Matching”) of the OpenGL ES 3.1 Specification."
1471 if (in_var
->data
.precision
!= out_var
->data
.precision
)
1476 return inputs
== outputs
;
1480 * Validate inputs against outputs in a program pipeline.
1483 _mesa_validate_pipeline_io(struct gl_pipeline_object
*pipeline
)
1485 struct gl_shader_program
**shProg
=
1486 (struct gl_shader_program
**) pipeline
->CurrentProgram
;
1488 /* Find first active stage in pipeline. */
1489 unsigned idx
, prev
= 0;
1490 for (idx
= 0; idx
< ARRAY_SIZE(pipeline
->CurrentProgram
); idx
++) {
1497 for (idx
= prev
+ 1; idx
< ARRAY_SIZE(pipeline
->CurrentProgram
); idx
++) {
1499 if (!validate_io(shProg
[prev
]->_LinkedShaders
[prev
],
1500 shProg
[idx
]->_LinkedShaders
[idx
],
1501 shProg
[prev
]->IsES
|| shProg
[idx
]->IsES
))