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 case GL_BUFFER_VARIABLE
:
489 return RESOURCE_UNI(res
)->array_elements
;
490 case GL_VERTEX_SUBROUTINE
:
491 case GL_GEOMETRY_SUBROUTINE
:
492 case GL_FRAGMENT_SUBROUTINE
:
493 case GL_COMPUTE_SUBROUTINE
:
494 case GL_TESS_CONTROL_SUBROUTINE
:
495 case GL_TESS_EVALUATION_SUBROUTINE
:
496 case GL_ATOMIC_COUNTER_BUFFER
:
497 case GL_UNIFORM_BLOCK
:
498 case GL_SHADER_STORAGE_BLOCK
:
501 assert(!"support for resource type not implemented");
507 * Checks if array subscript is valid and if so sets array_index.
510 valid_array_index(const GLchar
*name
, unsigned *array_index
)
513 const GLchar
*out_base_name_end
;
515 idx
= parse_program_resource_name(name
, &out_base_name_end
);
525 /* Find a program resource with specific name in given interface.
527 struct gl_program_resource
*
528 _mesa_program_resource_find_name(struct gl_shader_program
*shProg
,
529 GLenum programInterface
, const char *name
,
530 unsigned *array_index
)
532 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
533 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
534 if (res
->Type
!= programInterface
)
537 /* Resource basename. */
538 const char *rname
= _mesa_program_resource_name(res
);
539 unsigned baselen
= strlen(rname
);
541 if (strncmp(rname
, name
, baselen
) == 0) {
542 switch (programInterface
) {
543 case GL_UNIFORM_BLOCK
:
544 case GL_SHADER_STORAGE_BLOCK
:
545 /* Basename match, check if array or struct. */
546 if (name
[baselen
] == '\0' ||
547 name
[baselen
] == '[' ||
548 name
[baselen
] == '.') {
552 case GL_TRANSFORM_FEEDBACK_VARYING
:
553 case GL_BUFFER_VARIABLE
:
555 case GL_VERTEX_SUBROUTINE_UNIFORM
:
556 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
557 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
558 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
559 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
560 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
561 case GL_VERTEX_SUBROUTINE
:
562 case GL_GEOMETRY_SUBROUTINE
:
563 case GL_FRAGMENT_SUBROUTINE
:
564 case GL_COMPUTE_SUBROUTINE
:
565 case GL_TESS_CONTROL_SUBROUTINE
:
566 case GL_TESS_EVALUATION_SUBROUTINE
:
567 if (name
[baselen
] == '.') {
571 case GL_PROGRAM_INPUT
:
572 case GL_PROGRAM_OUTPUT
:
573 if (name
[baselen
] == '\0') {
575 } else if (name
[baselen
] == '[' &&
576 valid_array_index(name
, array_index
)) {
581 assert(!"not implemented for given interface");
589 calc_resource_index(struct gl_shader_program
*shProg
,
590 struct gl_program_resource
*res
)
594 for (i
= 0; i
< shProg
->NumProgramResourceList
; i
++) {
595 if (&shProg
->ProgramResourceList
[i
] == res
)
597 if (shProg
->ProgramResourceList
[i
].Type
== res
->Type
)
600 return GL_INVALID_INDEX
;
604 * Calculate index for the given resource.
607 _mesa_program_resource_index(struct gl_shader_program
*shProg
,
608 struct gl_program_resource
*res
)
611 return GL_INVALID_INDEX
;
614 case GL_ATOMIC_COUNTER_BUFFER
:
615 return RESOURCE_ATC(res
) - shProg
->AtomicBuffers
;
616 case GL_UNIFORM_BLOCK
:
617 case GL_SHADER_STORAGE_BLOCK
:
618 case GL_TRANSFORM_FEEDBACK_VARYING
:
620 return calc_resource_index(shProg
, res
);
624 /* Find a program resource with specific index in given interface.
626 struct gl_program_resource
*
627 _mesa_program_resource_find_index(struct gl_shader_program
*shProg
,
628 GLenum programInterface
, GLuint index
)
630 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
633 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
634 if (res
->Type
!= programInterface
)
638 case GL_UNIFORM_BLOCK
:
639 case GL_ATOMIC_COUNTER_BUFFER
:
640 case GL_SHADER_STORAGE_BLOCK
:
641 if (_mesa_program_resource_index(shProg
, res
) == index
)
644 case GL_TRANSFORM_FEEDBACK_VARYING
:
645 case GL_PROGRAM_INPUT
:
646 case GL_PROGRAM_OUTPUT
:
648 case GL_VERTEX_SUBROUTINE_UNIFORM
:
649 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
650 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
651 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
652 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
653 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
654 case GL_VERTEX_SUBROUTINE
:
655 case GL_GEOMETRY_SUBROUTINE
:
656 case GL_FRAGMENT_SUBROUTINE
:
657 case GL_COMPUTE_SUBROUTINE
:
658 case GL_TESS_CONTROL_SUBROUTINE
:
659 case GL_TESS_EVALUATION_SUBROUTINE
:
660 case GL_BUFFER_VARIABLE
:
661 if (++idx
== (int) index
)
665 assert(!"not implemented for given interface");
671 /* Function returns if resource name is expected to have index
675 * Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
678 * "If the active uniform is an array, the uniform name returned in
679 * name will always be the name of the uniform array appended with
682 * The same text also appears in the OpenGL 4.2 spec. It does not,
683 * however, appear in any previous spec. Previous specifications are
684 * ambiguous in this regard. However, either name can later be passed
685 * to glGetUniformLocation (and related APIs), so there shouldn't be any
686 * harm in always appending "[0]" to uniform array names.
688 * Geometry shader stage has different naming convention where the 'normal'
689 * condition is an array, therefore for variables referenced in geometry
690 * stage we do not add '[0]'.
692 * Note, that TCS outputs and TES inputs should not have index appended
696 add_index_to_name(struct gl_program_resource
*res
)
698 bool add_index
= !(((res
->Type
== GL_PROGRAM_INPUT
) &&
699 res
->StageReferences
& (1 << MESA_SHADER_GEOMETRY
)));
701 /* Transform feedback varyings have array index already appended
704 if (res
->Type
== GL_TRANSFORM_FEEDBACK_VARYING
)
710 /* Get name length of a program resource. This consists of
711 * base name + 3 for '[0]' if resource is an array.
714 _mesa_program_resource_name_len(struct gl_program_resource
*res
)
716 unsigned length
= strlen(_mesa_program_resource_name(res
));
717 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
))
722 /* Get full name of a program resource.
725 _mesa_get_program_resource_name(struct gl_shader_program
*shProg
,
726 GLenum programInterface
, GLuint index
,
727 GLsizei bufSize
, GLsizei
*length
,
728 GLchar
*name
, const char *caller
)
730 GET_CURRENT_CONTEXT(ctx
);
732 /* Find resource with given interface and index. */
733 struct gl_program_resource
*res
=
734 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
736 /* The error INVALID_VALUE is generated if <index> is greater than
737 * or equal to the number of entries in the active resource list for
738 * <programInterface>.
741 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index %u)", caller
, index
);
746 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize %d)", caller
, bufSize
);
753 length
= &localLength
;
755 _mesa_copy_string(name
, bufSize
, length
, _mesa_program_resource_name(res
));
757 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
)) {
760 /* The comparison is strange because *length does *NOT* include the
761 * terminating NUL, but maxLength does.
763 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < bufSize
; i
++)
764 name
[*length
+ i
] = "[0]"[i
];
766 name
[*length
+ i
] = '\0';
773 program_resource_location(struct gl_shader_program
*shProg
,
774 struct gl_program_resource
*res
, const char *name
,
775 unsigned array_index
)
777 /* Built-in locations should report GL_INVALID_INDEX. */
778 if (is_gl_identifier(name
))
779 return GL_INVALID_INDEX
;
781 /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
782 * offsets are used internally to differentiate between built-in attributes
783 * and user-defined attributes.
786 case GL_PROGRAM_INPUT
:
787 /* If the input is an array, fail if the index is out of bounds. */
789 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
792 return RESOURCE_VAR(res
)->data
.location
+ array_index
- VERT_ATTRIB_GENERIC0
;
793 case GL_PROGRAM_OUTPUT
:
794 /* If the output is an array, fail if the index is out of bounds. */
796 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
799 return RESOURCE_VAR(res
)->data
.location
+ array_index
- FRAG_RESULT_DATA0
;
801 /* If the uniform is built-in, fail. */
802 if (RESOURCE_UNI(res
)->builtin
)
805 /* From the GL_ARB_uniform_buffer_object spec:
807 * "The value -1 will be returned if <name> does not correspond to an
808 * active uniform variable name in <program>, if <name> is associated
809 * with a named uniform block, or if <name> starts with the reserved
812 if (RESOURCE_UNI(res
)->block_index
!= -1 ||
813 RESOURCE_UNI(res
)->atomic_buffer_index
!= -1)
817 case GL_VERTEX_SUBROUTINE_UNIFORM
:
818 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
819 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
820 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
821 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
822 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
823 /* If the uniform is an array, fail if the index is out of bounds. */
825 && array_index
>= RESOURCE_UNI(res
)->array_elements
) {
829 /* location in remap table + array element offset */
830 return RESOURCE_UNI(res
)->remap_location
+ array_index
;
837 get_top_level_name(const char *name
)
839 const char *first_dot
= strchr(name
, '.');
840 const char *first_square_bracket
= strchr(name
, '[');
842 /* From ARB_program_interface_query spec:
844 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer identifying the
845 * number of active array elements of the top-level shader storage block
846 * member containing to the active variable is written to <params>. If the
847 * top-level block member is not declared as an array, the value one is
848 * written to <params>. If the top-level block member is an array with no
849 * declared size, the value zero is written to <params>.
852 /* The buffer variable is on top level.*/
853 if (!first_square_bracket
&& !first_dot
)
854 name_size
= strlen(name
);
855 else if ((!first_square_bracket
||
856 (first_dot
&& first_dot
< first_square_bracket
)))
857 name_size
= first_dot
- name
;
859 name_size
= first_square_bracket
- name
;
861 return strndup(name
, name_size
);
865 get_var_name(const char *name
)
867 const char *first_dot
= strchr(name
, '.');
872 return strndup(first_dot
+1, strlen(first_dot
) - 1);
876 program_resource_top_level_array_size(struct gl_shader_program
*shProg
,
877 struct gl_program_resource
*res
,
880 int block_index
= RESOURCE_UNI(res
)->block_index
;
882 char *var_name
= get_top_level_name(name
);
883 char *interface_name
=
884 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
886 if (strcmp(var_name
, interface_name
) == 0) {
887 /* Deal with instanced array of SSBOs */
888 char *temp_name
= get_var_name(name
);
890 var_name
= get_top_level_name(temp_name
);
894 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
895 if (shProg
->Shaders
[i
] == NULL
)
898 const gl_shader
*stage
= shProg
->Shaders
[i
];
899 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
900 ir_variable
*var
= node
->as_variable();
901 if (!var
|| !var
->get_interface_type() ||
902 var
->data
.mode
!= ir_var_shader_storage
)
905 const glsl_type
*interface
= var
->get_interface_type();
907 if (strcmp(interface_name
, interface
->name
) != 0)
910 for (unsigned i
= 0; i
< interface
->length
; i
++) {
911 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
912 if (strcmp(field
->name
, var_name
) != 0)
914 /* From GL_ARB_program_interface_query spec:
916 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer
917 * identifying the number of active array elements of the top-level
918 * shader storage block member containing to the active variable is
919 * written to <params>. If the top-level block member is not
920 * declared as an array, the value one is written to <params>. If
921 * the top-level block member is an array with no declared size,
922 * the value zero is written to <params>.
924 if (field
->type
->is_unsized_array())
926 else if (field
->type
->is_array())
927 array_size
= field
->type
->length
;
930 goto found_top_level_array_size
;
934 found_top_level_array_size
:
935 free(interface_name
);
941 program_resource_top_level_array_stride(struct gl_shader_program
*shProg
,
942 struct gl_program_resource
*res
,
945 int block_index
= RESOURCE_UNI(res
)->block_index
;
946 int array_stride
= -1;
947 char *var_name
= get_top_level_name(name
);
948 char *interface_name
=
949 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
951 if (strcmp(var_name
, interface_name
) == 0) {
952 /* Deal with instanced array of SSBOs */
953 char *temp_name
= get_var_name(name
);
955 var_name
= get_top_level_name(temp_name
);
959 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
960 if (shProg
->Shaders
[i
] == NULL
)
963 const gl_shader
*stage
= shProg
->Shaders
[i
];
964 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
965 ir_variable
*var
= node
->as_variable();
966 if (!var
|| !var
->get_interface_type() ||
967 var
->data
.mode
!= ir_var_shader_storage
)
970 const glsl_type
*interface
= var
->get_interface_type();
972 if (strcmp(interface_name
, interface
->name
) != 0) {
976 for (unsigned i
= 0; i
< interface
->length
; i
++) {
977 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
978 if (strcmp(field
->name
, var_name
) != 0)
980 /* From GL_ARB_program_interface_query:
982 * "For the property TOP_LEVEL_ARRAY_STRIDE, a single integer
983 * identifying the stride between array elements of the top-level
984 * shader storage block member containing the active variable is
985 * written to <params>. For top-level block members declared as
986 * arrays, the value written is the difference, in basic machine
987 * units, between the offsets of the active variable for
988 * consecutive elements in the top-level array. For top-level
989 * block members not declared as an array, zero is written to
992 if (field
->type
->is_array()) {
993 const enum glsl_matrix_layout matrix_layout
=
994 glsl_matrix_layout(field
->matrix_layout
);
995 bool row_major
= matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
;
996 const glsl_type
*array_type
= field
->type
->fields
.array
;
998 if (interface
->interface_packing
!= GLSL_INTERFACE_PACKING_STD430
) {
999 if (array_type
->is_record()) {
1000 array_stride
= array_type
->std140_size(row_major
);
1001 array_stride
= glsl_align(array_stride
, 16);
1003 unsigned element_base_align
= 0;
1004 element_base_align
= array_type
->std140_base_alignment(row_major
);
1005 array_stride
= MAX2(element_base_align
, 16);
1008 array_stride
= array_type
->std430_array_stride(row_major
);
1013 goto found_top_level_array_size
;
1017 found_top_level_array_size
:
1018 free(interface_name
);
1020 return array_stride
;
1024 * Function implements following location queries:
1025 * glGetUniformLocation
1028 _mesa_program_resource_location(struct gl_shader_program
*shProg
,
1029 GLenum programInterface
, const char *name
)
1031 unsigned array_index
= 0;
1032 struct gl_program_resource
*res
=
1033 _mesa_program_resource_find_name(shProg
, programInterface
, name
,
1036 /* Resource not found. */
1040 return program_resource_location(shProg
, res
, name
, array_index
);
1044 * Function implements following index queries:
1045 * glGetFragDataIndex
1048 _mesa_program_resource_location_index(struct gl_shader_program
*shProg
,
1049 GLenum programInterface
, const char *name
)
1051 struct gl_program_resource
*res
=
1052 _mesa_program_resource_find_name(shProg
, programInterface
, name
, NULL
);
1054 /* Non-existent variable or resource is not referenced by fragment stage. */
1055 if (!res
|| !(res
->StageReferences
& (1 << MESA_SHADER_FRAGMENT
)))
1058 return RESOURCE_VAR(res
)->data
.index
;
1062 stage_from_enum(GLenum ref
)
1065 case GL_REFERENCED_BY_VERTEX_SHADER
:
1066 return MESA_SHADER_VERTEX
;
1067 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1068 return MESA_SHADER_TESS_CTRL
;
1069 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1070 return MESA_SHADER_TESS_EVAL
;
1071 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1072 return MESA_SHADER_GEOMETRY
;
1073 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1074 return MESA_SHADER_FRAGMENT
;
1075 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1076 return MESA_SHADER_COMPUTE
;
1078 assert(!"shader stage not supported");
1079 return MESA_SHADER_STAGES
;
1084 * Check if resource is referenced by given 'referenced by' stage enum.
1085 * ATC and UBO resources hold stage references of their own.
1088 is_resource_referenced(struct gl_shader_program
*shProg
,
1089 struct gl_program_resource
*res
,
1090 GLuint index
, uint8_t stage
)
1092 /* First, check if we even have such a stage active. */
1093 if (!shProg
->_LinkedShaders
[stage
])
1096 if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
)
1097 return RESOURCE_ATC(res
)->StageReferences
[stage
];
1099 if (res
->Type
== GL_UNIFORM_BLOCK
|| res
->Type
== GL_SHADER_STORAGE_BLOCK
)
1100 return shProg
->UniformBlockStageIndex
[stage
][index
] != -1;
1102 return res
->StageReferences
& (1 << stage
);
1106 get_buffer_property(struct gl_shader_program
*shProg
,
1107 struct gl_program_resource
*res
, const GLenum prop
,
1108 GLint
*val
, const char *caller
)
1110 GET_CURRENT_CONTEXT(ctx
);
1111 if (res
->Type
!= GL_UNIFORM_BLOCK
&&
1112 res
->Type
!= GL_ATOMIC_COUNTER_BUFFER
&&
1113 res
->Type
!= GL_SHADER_STORAGE_BLOCK
)
1114 goto invalid_operation
;
1116 if (res
->Type
== GL_UNIFORM_BLOCK
) {
1118 case GL_BUFFER_BINDING
:
1119 *val
= RESOURCE_UBO(res
)->Binding
;
1121 case GL_BUFFER_DATA_SIZE
:
1122 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1124 case GL_NUM_ACTIVE_VARIABLES
:
1126 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1127 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1128 struct gl_program_resource
*uni
=
1129 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1136 case GL_ACTIVE_VARIABLES
:
1137 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1138 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1139 struct gl_program_resource
*uni
=
1140 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1145 _mesa_program_resource_index(shProg
, uni
);
1147 return RESOURCE_UBO(res
)->NumUniforms
;
1149 } else if (res
->Type
== GL_SHADER_STORAGE_BLOCK
) {
1151 case GL_BUFFER_BINDING
:
1152 *val
= RESOURCE_UBO(res
)->Binding
;
1154 case GL_BUFFER_DATA_SIZE
:
1155 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1157 case GL_NUM_ACTIVE_VARIABLES
:
1159 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1160 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1161 struct gl_program_resource
*uni
=
1162 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1169 case GL_ACTIVE_VARIABLES
:
1170 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1171 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1172 struct gl_program_resource
*uni
=
1173 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1178 _mesa_program_resource_index(shProg
, uni
);
1180 return RESOURCE_UBO(res
)->NumUniforms
;
1182 } else if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
) {
1184 case GL_BUFFER_BINDING
:
1185 *val
= RESOURCE_ATC(res
)->Binding
;
1187 case GL_BUFFER_DATA_SIZE
:
1188 *val
= RESOURCE_ATC(res
)->MinimumSize
;
1190 case GL_NUM_ACTIVE_VARIABLES
:
1191 *val
= RESOURCE_ATC(res
)->NumUniforms
;
1193 case GL_ACTIVE_VARIABLES
:
1194 for (unsigned i
= 0; i
< RESOURCE_ATC(res
)->NumUniforms
; i
++)
1195 *val
++ = RESOURCE_ATC(res
)->Uniforms
[i
];
1196 return RESOURCE_ATC(res
)->NumUniforms
;
1199 assert(!"support for property type not implemented");
1202 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1203 _mesa_enum_to_string(res
->Type
),
1204 _mesa_enum_to_string(prop
));
1210 _mesa_program_resource_prop(struct gl_shader_program
*shProg
,
1211 struct gl_program_resource
*res
, GLuint index
,
1212 const GLenum prop
, GLint
*val
, const char *caller
)
1214 GET_CURRENT_CONTEXT(ctx
);
1216 #define VALIDATE_TYPE(type)\
1217 if (res->Type != type)\
1218 goto invalid_operation;
1220 #define VALIDATE_TYPE_2(type1, type2)\
1221 if (res->Type != type1 && res->Type != type2)\
1222 goto invalid_operation;
1225 case GL_NAME_LENGTH
:
1226 switch (res
->Type
) {
1227 case GL_ATOMIC_COUNTER_BUFFER
:
1228 goto invalid_operation
;
1230 /* Resource name length + terminator. */
1231 *val
= _mesa_program_resource_name_len(res
) + 1;
1235 switch (res
->Type
) {
1237 case GL_BUFFER_VARIABLE
:
1238 *val
= RESOURCE_UNI(res
)->type
->gl_type
;
1240 case GL_PROGRAM_INPUT
:
1241 case GL_PROGRAM_OUTPUT
:
1242 *val
= RESOURCE_VAR(res
)->type
->gl_type
;
1244 case GL_TRANSFORM_FEEDBACK_VARYING
:
1245 *val
= RESOURCE_XFB(res
)->Type
;
1248 goto invalid_operation
;
1251 switch (res
->Type
) {
1253 case GL_BUFFER_VARIABLE
:
1254 *val
= MAX2(RESOURCE_UNI(res
)->array_elements
, 1);
1256 case GL_PROGRAM_INPUT
:
1257 case GL_PROGRAM_OUTPUT
:
1258 *val
= MAX2(_mesa_program_resource_array_size(res
), 1);
1260 case GL_TRANSFORM_FEEDBACK_VARYING
:
1261 *val
= MAX2(RESOURCE_XFB(res
)->Size
, 1);
1264 goto invalid_operation
;
1267 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1268 *val
= RESOURCE_UNI(res
)->offset
;
1270 case GL_BLOCK_INDEX
:
1271 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1272 *val
= RESOURCE_UNI(res
)->block_index
;
1274 case GL_ARRAY_STRIDE
:
1275 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1276 *val
= RESOURCE_UNI(res
)->array_stride
;
1278 case GL_MATRIX_STRIDE
:
1279 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1280 *val
= RESOURCE_UNI(res
)->matrix_stride
;
1282 case GL_IS_ROW_MAJOR
:
1283 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1284 *val
= RESOURCE_UNI(res
)->row_major
;
1286 case GL_ATOMIC_COUNTER_BUFFER_INDEX
:
1287 VALIDATE_TYPE(GL_UNIFORM
);
1288 *val
= RESOURCE_UNI(res
)->atomic_buffer_index
;
1290 case GL_BUFFER_BINDING
:
1291 case GL_BUFFER_DATA_SIZE
:
1292 case GL_NUM_ACTIVE_VARIABLES
:
1293 case GL_ACTIVE_VARIABLES
:
1294 return get_buffer_property(shProg
, res
, prop
, val
, caller
);
1295 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1296 if (!_mesa_has_compute_shaders(ctx
))
1299 case GL_REFERENCED_BY_VERTEX_SHADER
:
1300 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1301 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1302 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1303 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1304 switch (res
->Type
) {
1306 case GL_PROGRAM_INPUT
:
1307 case GL_PROGRAM_OUTPUT
:
1308 case GL_UNIFORM_BLOCK
:
1309 case GL_BUFFER_VARIABLE
:
1310 case GL_SHADER_STORAGE_BLOCK
:
1311 case GL_ATOMIC_COUNTER_BUFFER
:
1312 *val
= is_resource_referenced(shProg
, res
, index
,
1313 stage_from_enum(prop
));
1316 goto invalid_operation
;
1319 switch (res
->Type
) {
1321 case GL_PROGRAM_INPUT
:
1322 case GL_PROGRAM_OUTPUT
:
1323 *val
= program_resource_location(shProg
, res
,
1324 _mesa_program_resource_name(res
),
1328 goto invalid_operation
;
1330 case GL_LOCATION_INDEX
:
1331 if (res
->Type
!= GL_PROGRAM_OUTPUT
)
1332 goto invalid_operation
;
1333 *val
= RESOURCE_VAR(res
)->data
.index
;
1336 case GL_NUM_COMPATIBLE_SUBROUTINES
:
1337 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1338 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1339 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1340 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1341 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1342 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1343 goto invalid_operation
;
1344 *val
= RESOURCE_UNI(res
)->num_compatible_subroutines
;
1346 case GL_COMPATIBLE_SUBROUTINES
: {
1347 const struct gl_uniform_storage
*uni
;
1348 struct gl_shader
*sh
;
1352 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1353 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1354 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1355 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1356 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1357 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1358 goto invalid_operation
;
1359 uni
= RESOURCE_UNI(res
);
1361 sh
= shProg
->_LinkedShaders
[_mesa_shader_stage_from_subroutine_uniform(res
->Type
)];
1363 for (i
= 0; i
< sh
->NumSubroutineFunctions
; i
++) {
1364 struct gl_subroutine_function
*fn
= &sh
->SubroutineFunctions
[i
];
1365 for (j
= 0; j
< fn
->num_compat_types
; j
++) {
1366 if (fn
->types
[j
] == uni
->type
) {
1375 case GL_TOP_LEVEL_ARRAY_SIZE
:
1376 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1377 *val
= program_resource_top_level_array_size(shProg
, res
,
1378 _mesa_program_resource_name(res
));
1381 case GL_TOP_LEVEL_ARRAY_STRIDE
:
1382 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1383 *val
= program_resource_top_level_array_stride(shProg
, res
,
1384 _mesa_program_resource_name(res
));
1387 /* GL_ARB_tessellation_shader */
1388 case GL_IS_PER_PATCH
:
1389 switch (res
->Type
) {
1390 case GL_PROGRAM_INPUT
:
1391 case GL_PROGRAM_OUTPUT
:
1392 *val
= RESOURCE_VAR(res
)->data
.patch
;
1395 goto invalid_operation
;
1401 #undef VALIDATE_TYPE
1402 #undef VALIDATE_TYPE_2
1405 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(%s prop %s)", caller
,
1406 _mesa_enum_to_string(res
->Type
),
1407 _mesa_enum_to_string(prop
));
1411 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1412 _mesa_enum_to_string(res
->Type
),
1413 _mesa_enum_to_string(prop
));
1418 _mesa_get_program_resourceiv(struct gl_shader_program
*shProg
,
1419 GLenum programInterface
, GLuint index
, GLsizei propCount
,
1420 const GLenum
*props
, GLsizei bufSize
,
1421 GLsizei
*length
, GLint
*params
)
1423 GET_CURRENT_CONTEXT(ctx
);
1424 GLint
*val
= (GLint
*) params
;
1425 const GLenum
*prop
= props
;
1428 struct gl_program_resource
*res
=
1429 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
1431 /* No such resource found or bufSize negative. */
1432 if (!res
|| bufSize
< 0) {
1433 _mesa_error(ctx
, GL_INVALID_VALUE
,
1434 "glGetProgramResourceiv(%s index %d bufSize %d)",
1435 _mesa_enum_to_string(programInterface
), index
, bufSize
);
1439 /* Write propCount values until error occurs or bufSize reached. */
1440 for (int i
= 0; i
< propCount
&& i
< bufSize
; i
++, val
++, prop
++) {
1442 _mesa_program_resource_prop(shProg
, res
, index
, *prop
, val
,
1443 "glGetProgramResourceiv");
1445 /* Error happened. */
1446 if (props_written
== 0)
1449 amount
+= props_written
;
1452 /* If <length> is not NULL, the actual number of integer values
1453 * written to <params> will be written to <length>.