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 "glsl_symbol_table.h"
35 #include "shaderobj.h"
36 #include "program/hash_table.h"
37 #include "../glsl/program.h"
39 #include "main/enums.h"
40 #include "util/strndup.h"
43 #include "shaderapi.h"
47 program_resource_location(struct gl_shader_program
*shProg
,
48 struct gl_program_resource
*res
, const char *name
,
49 unsigned array_index
);
52 * Declare convenience functions to return resource data in a given type.
53 * Warning! this is not type safe so be *very* careful when using these.
55 #define DECL_RESOURCE_FUNC(name, type) \
56 const type * RESOURCE_ ## name (gl_program_resource *res) { \
58 return (type *) res->Data; \
61 DECL_RESOURCE_FUNC(VAR
, ir_variable
);
62 DECL_RESOURCE_FUNC(UBO
, gl_uniform_block
);
63 DECL_RESOURCE_FUNC(UNI
, gl_uniform_storage
);
64 DECL_RESOURCE_FUNC(ATC
, gl_active_atomic_buffer
);
65 DECL_RESOURCE_FUNC(XFB
, gl_transform_feedback_varying_info
);
66 DECL_RESOURCE_FUNC(SUB
, gl_subroutine_function
);
69 _mesa_BindAttribLocation(GLhandleARB program
, GLuint index
,
70 const GLcharARB
*name
)
72 GET_CURRENT_CONTEXT(ctx
);
74 struct gl_shader_program
*const shProg
=
75 _mesa_lookup_shader_program_err(ctx
, program
, "glBindAttribLocation");
82 if (strncmp(name
, "gl_", 3) == 0) {
83 _mesa_error(ctx
, GL_INVALID_OPERATION
,
84 "glBindAttribLocation(illegal name)");
88 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
89 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindAttribLocation(index)");
93 /* Replace the current value if it's already in the list. Add
94 * VERT_ATTRIB_GENERIC0 because that's how the linker differentiates
95 * between built-in attributes and user-defined attributes.
97 shProg
->AttributeBindings
->put(index
+ VERT_ATTRIB_GENERIC0
, name
);
100 * Note that this attribute binding won't go into effect until
101 * glLinkProgram is called again.
106 is_active_attrib(const ir_variable
*var
)
111 switch (var
->data
.mode
) {
112 case ir_var_shader_in
:
113 return var
->data
.location
!= -1;
115 case ir_var_system_value
:
116 /* From GL 4.3 core spec, section 11.1.1 (Vertex Attributes):
117 * "For GetActiveAttrib, all active vertex shader input variables
118 * are enumerated, including the special built-in inputs gl_VertexID
119 * and gl_InstanceID."
121 return var
->data
.location
== SYSTEM_VALUE_VERTEX_ID
||
122 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
||
123 var
->data
.location
== SYSTEM_VALUE_INSTANCE_ID
;
131 _mesa_GetActiveAttrib(GLhandleARB program
, GLuint desired_index
,
132 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
133 GLenum
* type
, GLcharARB
* name
)
135 GET_CURRENT_CONTEXT(ctx
);
136 struct gl_shader_program
*shProg
;
139 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(maxLength < 0)");
143 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveAttrib");
147 if (!shProg
->LinkStatus
) {
148 _mesa_error(ctx
, GL_INVALID_VALUE
,
149 "glGetActiveAttrib(program not linked)");
153 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
154 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(no vertex shader)");
158 struct gl_program_resource
*res
=
159 _mesa_program_resource_find_index(shProg
, GL_PROGRAM_INPUT
,
162 /* User asked for index that does not exist. */
164 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(index)");
168 const ir_variable
*const var
= RESOURCE_VAR(res
);
170 if (!is_active_attrib(var
))
173 const char *var_name
= var
->name
;
175 /* Since gl_VertexID may be lowered to gl_VertexIDMESA, we need to
176 * consider gl_VertexIDMESA as gl_VertexID for purposes of checking
179 if (var
->data
.mode
== ir_var_system_value
&&
180 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
181 var_name
= "gl_VertexID";
184 _mesa_copy_string(name
, maxLength
, length
, var_name
);
187 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_ARRAY_SIZE
,
188 size
, "glGetActiveAttrib");
191 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_TYPE
,
192 (GLint
*) type
, "glGetActiveAttrib");
196 _mesa_GetAttribLocation(GLhandleARB program
, const GLcharARB
* name
)
198 GET_CURRENT_CONTEXT(ctx
);
199 struct gl_shader_program
*const shProg
=
200 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
206 if (!shProg
->LinkStatus
) {
207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
208 "glGetAttribLocation(program not linked)");
215 /* Not having a vertex shader is not an error.
217 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)
220 unsigned array_index
= 0;
221 struct gl_program_resource
*res
=
222 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_INPUT
, name
,
228 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
230 /* The extra check against against 0 is made because of builtin-attribute
231 * locations that have offset applied. Function program_resource_location
232 * can return built-in attribute locations < 0 and glGetAttribLocation
233 * cannot be used on "conventional" attributes.
235 * From page 95 of the OpenGL 3.0 spec:
237 * "If name is not an active attribute, if name is a conventional
238 * attribute, or if an error occurs, -1 will be returned."
240 return (loc
>= 0) ? loc
: -1;
244 _mesa_count_active_attribs(struct gl_shader_program
*shProg
)
246 if (!shProg
->LinkStatus
247 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
251 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
253 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
254 if (res
->Type
== GL_PROGRAM_INPUT
&&
255 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
) &&
256 is_active_attrib(RESOURCE_VAR(res
)))
264 _mesa_longest_attribute_name_length(struct gl_shader_program
*shProg
)
266 if (!shProg
->LinkStatus
267 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
271 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
273 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
274 if (res
->Type
== GL_PROGRAM_INPUT
&&
275 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
)) {
277 const size_t length
= strlen(RESOURCE_VAR(res
)->name
);
278 if (length
>= longest
)
279 longest
= length
+ 1;
287 _mesa_BindFragDataLocation(GLuint program
, GLuint colorNumber
,
290 _mesa_BindFragDataLocationIndexed(program
, colorNumber
, 0, name
);
294 _mesa_BindFragDataLocationIndexed(GLuint program
, GLuint colorNumber
,
295 GLuint index
, const GLchar
*name
)
297 GET_CURRENT_CONTEXT(ctx
);
299 struct gl_shader_program
*const shProg
=
300 _mesa_lookup_shader_program_err(ctx
, program
, "glBindFragDataLocationIndexed");
307 if (strncmp(name
, "gl_", 3) == 0) {
308 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFragDataLocationIndexed(illegal name)");
313 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(index)");
317 if (index
== 0 && colorNumber
>= ctx
->Const
.MaxDrawBuffers
) {
318 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
322 if (index
== 1 && colorNumber
>= ctx
->Const
.MaxDualSourceDrawBuffers
) {
323 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
327 /* Replace the current value if it's already in the list. Add
328 * FRAG_RESULT_DATA0 because that's how the linker differentiates
329 * between built-in attributes and user-defined attributes.
331 shProg
->FragDataBindings
->put(colorNumber
+ FRAG_RESULT_DATA0
, name
);
332 shProg
->FragDataIndexBindings
->put(index
, name
);
334 * Note that this binding won't go into effect until
335 * glLinkProgram is called again.
341 _mesa_GetFragDataIndex(GLuint program
, const GLchar
*name
)
343 GET_CURRENT_CONTEXT(ctx
);
344 struct gl_shader_program
*const shProg
=
345 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataIndex");
351 if (!shProg
->LinkStatus
) {
352 _mesa_error(ctx
, GL_INVALID_OPERATION
,
353 "glGetFragDataIndex(program not linked)");
360 if (strncmp(name
, "gl_", 3) == 0) {
361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
362 "glGetFragDataIndex(illegal name)");
366 /* Not having a fragment shader is not an error.
368 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
371 return _mesa_program_resource_location_index(shProg
, GL_PROGRAM_OUTPUT
,
376 _mesa_GetFragDataLocation(GLuint program
, const GLchar
*name
)
378 GET_CURRENT_CONTEXT(ctx
);
379 struct gl_shader_program
*const shProg
=
380 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataLocation");
386 if (!shProg
->LinkStatus
) {
387 _mesa_error(ctx
, GL_INVALID_OPERATION
,
388 "glGetFragDataLocation(program not linked)");
395 if (strncmp(name
, "gl_", 3) == 0) {
396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
397 "glGetFragDataLocation(illegal name)");
401 /* Not having a fragment shader is not an error.
403 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
406 unsigned array_index
= 0;
407 struct gl_program_resource
*res
=
408 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_OUTPUT
, name
,
414 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
416 /* The extra check against against 0 is made because of builtin-attribute
417 * locations that have offset applied. Function program_resource_location
418 * can return built-in attribute locations < 0 and glGetFragDataLocation
419 * cannot be used on "conventional" attributes.
421 * From page 95 of the OpenGL 3.0 spec:
423 * "If name is not an active attribute, if name is a conventional
424 * attribute, or if an error occurs, -1 will be returned."
426 return (loc
>= 0) ? loc
: -1;
430 _mesa_program_resource_name(struct gl_program_resource
*res
)
432 const ir_variable
*var
;
434 case GL_UNIFORM_BLOCK
:
435 case GL_SHADER_STORAGE_BLOCK
:
436 return RESOURCE_UBO(res
)->Name
;
437 case GL_TRANSFORM_FEEDBACK_VARYING
:
438 return RESOURCE_XFB(res
)->Name
;
439 case GL_PROGRAM_INPUT
:
440 var
= RESOURCE_VAR(res
);
441 /* Special case gl_VertexIDMESA -> gl_VertexID. */
442 if (var
->data
.mode
== ir_var_system_value
&&
443 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
444 return "gl_VertexID";
447 case GL_PROGRAM_OUTPUT
:
448 return RESOURCE_VAR(res
)->name
;
450 case GL_BUFFER_VARIABLE
:
451 return RESOURCE_UNI(res
)->name
;
452 case GL_VERTEX_SUBROUTINE_UNIFORM
:
453 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
454 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
455 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
456 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
457 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
458 return RESOURCE_UNI(res
)->name
+ MESA_SUBROUTINE_PREFIX_LEN
;
459 case GL_VERTEX_SUBROUTINE
:
460 case GL_GEOMETRY_SUBROUTINE
:
461 case GL_FRAGMENT_SUBROUTINE
:
462 case GL_COMPUTE_SUBROUTINE
:
463 case GL_TESS_CONTROL_SUBROUTINE
:
464 case GL_TESS_EVALUATION_SUBROUTINE
:
465 return RESOURCE_SUB(res
)->name
;
467 assert(!"support for resource type not implemented");
474 _mesa_program_resource_array_size(struct gl_program_resource
*res
)
477 case GL_TRANSFORM_FEEDBACK_VARYING
:
478 return RESOURCE_XFB(res
)->Size
> 1 ?
479 RESOURCE_XFB(res
)->Size
: 0;
480 case GL_PROGRAM_INPUT
:
481 case GL_PROGRAM_OUTPUT
:
482 return RESOURCE_VAR(res
)->type
->length
;
484 case GL_VERTEX_SUBROUTINE_UNIFORM
:
485 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
486 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
487 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
488 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
489 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
490 case GL_BUFFER_VARIABLE
:
491 return RESOURCE_UNI(res
)->array_elements
;
492 case GL_VERTEX_SUBROUTINE
:
493 case GL_GEOMETRY_SUBROUTINE
:
494 case GL_FRAGMENT_SUBROUTINE
:
495 case GL_COMPUTE_SUBROUTINE
:
496 case GL_TESS_CONTROL_SUBROUTINE
:
497 case GL_TESS_EVALUATION_SUBROUTINE
:
498 case GL_ATOMIC_COUNTER_BUFFER
:
499 case GL_UNIFORM_BLOCK
:
500 case GL_SHADER_STORAGE_BLOCK
:
503 assert(!"support for resource type not implemented");
509 * Checks if array subscript is valid and if so sets array_index.
512 valid_array_index(const GLchar
*name
, unsigned *array_index
)
515 const GLchar
*out_base_name_end
;
517 idx
= parse_program_resource_name(name
, &out_base_name_end
);
527 /* Find a program resource with specific name in given interface.
529 struct gl_program_resource
*
530 _mesa_program_resource_find_name(struct gl_shader_program
*shProg
,
531 GLenum programInterface
, const char *name
,
532 unsigned *array_index
)
534 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
535 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
536 if (res
->Type
!= programInterface
)
539 /* Resource basename. */
540 const char *rname
= _mesa_program_resource_name(res
);
541 unsigned baselen
= strlen(rname
);
543 if (strncmp(rname
, name
, baselen
) == 0) {
544 switch (programInterface
) {
545 case GL_UNIFORM_BLOCK
:
546 case GL_SHADER_STORAGE_BLOCK
:
547 /* Basename match, check if array or struct. */
548 if (name
[baselen
] == '\0' ||
549 name
[baselen
] == '[' ||
550 name
[baselen
] == '.') {
554 case GL_TRANSFORM_FEEDBACK_VARYING
:
555 case GL_BUFFER_VARIABLE
:
557 case GL_VERTEX_SUBROUTINE_UNIFORM
:
558 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
559 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
560 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
561 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
562 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
563 case GL_VERTEX_SUBROUTINE
:
564 case GL_GEOMETRY_SUBROUTINE
:
565 case GL_FRAGMENT_SUBROUTINE
:
566 case GL_COMPUTE_SUBROUTINE
:
567 case GL_TESS_CONTROL_SUBROUTINE
:
568 case GL_TESS_EVALUATION_SUBROUTINE
:
569 if (name
[baselen
] == '.') {
573 case GL_PROGRAM_INPUT
:
574 case GL_PROGRAM_OUTPUT
:
575 if (name
[baselen
] == '\0') {
577 } else if (name
[baselen
] == '[' &&
578 valid_array_index(name
, array_index
)) {
583 assert(!"not implemented for given interface");
591 calc_resource_index(struct gl_shader_program
*shProg
,
592 struct gl_program_resource
*res
)
596 for (i
= 0; i
< shProg
->NumProgramResourceList
; i
++) {
597 if (&shProg
->ProgramResourceList
[i
] == res
)
599 if (shProg
->ProgramResourceList
[i
].Type
== res
->Type
)
602 return GL_INVALID_INDEX
;
606 * Calculate index for the given resource.
609 _mesa_program_resource_index(struct gl_shader_program
*shProg
,
610 struct gl_program_resource
*res
)
613 return GL_INVALID_INDEX
;
616 case GL_UNIFORM_BLOCK
:
617 case GL_SHADER_STORAGE_BLOCK
:
618 return RESOURCE_UBO(res
)- shProg
->UniformBlocks
;
619 case GL_ATOMIC_COUNTER_BUFFER
:
620 return RESOURCE_ATC(res
) - shProg
->AtomicBuffers
;
621 case GL_TRANSFORM_FEEDBACK_VARYING
:
623 return calc_resource_index(shProg
, res
);
627 /* Find a program resource with specific index in given interface.
629 struct gl_program_resource
*
630 _mesa_program_resource_find_index(struct gl_shader_program
*shProg
,
631 GLenum programInterface
, GLuint index
)
633 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
636 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
637 if (res
->Type
!= programInterface
)
641 case GL_UNIFORM_BLOCK
:
642 case GL_ATOMIC_COUNTER_BUFFER
:
643 case GL_SHADER_STORAGE_BLOCK
:
644 if (_mesa_program_resource_index(shProg
, res
) == index
)
647 case GL_TRANSFORM_FEEDBACK_VARYING
:
648 case GL_PROGRAM_INPUT
:
649 case GL_PROGRAM_OUTPUT
:
651 case GL_VERTEX_SUBROUTINE_UNIFORM
:
652 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
653 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
654 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
655 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
656 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
657 case GL_VERTEX_SUBROUTINE
:
658 case GL_GEOMETRY_SUBROUTINE
:
659 case GL_FRAGMENT_SUBROUTINE
:
660 case GL_COMPUTE_SUBROUTINE
:
661 case GL_TESS_CONTROL_SUBROUTINE
:
662 case GL_TESS_EVALUATION_SUBROUTINE
:
663 case GL_BUFFER_VARIABLE
:
664 if (++idx
== (int) index
)
668 assert(!"not implemented for given interface");
674 /* Function returns if resource name is expected to have index
678 * Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
681 * "If the active uniform is an array, the uniform name returned in
682 * name will always be the name of the uniform array appended with
685 * The same text also appears in the OpenGL 4.2 spec. It does not,
686 * however, appear in any previous spec. Previous specifications are
687 * ambiguous in this regard. However, either name can later be passed
688 * to glGetUniformLocation (and related APIs), so there shouldn't be any
689 * harm in always appending "[0]" to uniform array names.
691 * Geometry shader stage has different naming convention where the 'normal'
692 * condition is an array, therefore for variables referenced in geometry
693 * stage we do not add '[0]'.
695 * Note, that TCS outputs and TES inputs should not have index appended
699 add_index_to_name(struct gl_program_resource
*res
)
701 bool add_index
= !(((res
->Type
== GL_PROGRAM_INPUT
) &&
702 res
->StageReferences
& (1 << MESA_SHADER_GEOMETRY
)));
704 /* Transform feedback varyings have array index already appended
707 if (res
->Type
== GL_TRANSFORM_FEEDBACK_VARYING
)
713 /* Get name length of a program resource. This consists of
714 * base name + 3 for '[0]' if resource is an array.
717 _mesa_program_resource_name_len(struct gl_program_resource
*res
)
719 unsigned length
= strlen(_mesa_program_resource_name(res
));
720 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
))
725 /* Get full name of a program resource.
728 _mesa_get_program_resource_name(struct gl_shader_program
*shProg
,
729 GLenum programInterface
, GLuint index
,
730 GLsizei bufSize
, GLsizei
*length
,
731 GLchar
*name
, const char *caller
)
733 GET_CURRENT_CONTEXT(ctx
);
735 /* Find resource with given interface and index. */
736 struct gl_program_resource
*res
=
737 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
739 /* The error INVALID_VALUE is generated if <index> is greater than
740 * or equal to the number of entries in the active resource list for
741 * <programInterface>.
744 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index %u)", caller
, index
);
749 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize %d)", caller
, bufSize
);
756 length
= &localLength
;
758 _mesa_copy_string(name
, bufSize
, length
, _mesa_program_resource_name(res
));
760 if (_mesa_program_resource_array_size(res
) && add_index_to_name(res
)) {
763 /* The comparison is strange because *length does *NOT* include the
764 * terminating NUL, but maxLength does.
766 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < bufSize
; i
++)
767 name
[*length
+ i
] = "[0]"[i
];
769 name
[*length
+ i
] = '\0';
776 program_resource_location(struct gl_shader_program
*shProg
,
777 struct gl_program_resource
*res
, const char *name
,
778 unsigned array_index
)
780 /* Built-in locations should report GL_INVALID_INDEX. */
781 if (is_gl_identifier(name
))
782 return GL_INVALID_INDEX
;
784 /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
785 * offsets are used internally to differentiate between built-in attributes
786 * and user-defined attributes.
789 case GL_PROGRAM_INPUT
:
790 /* If the input is an array, fail if the index is out of bounds. */
792 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
795 return RESOURCE_VAR(res
)->data
.location
+ array_index
- VERT_ATTRIB_GENERIC0
;
796 case GL_PROGRAM_OUTPUT
:
797 /* If the output is an array, fail if the index is out of bounds. */
799 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
802 return RESOURCE_VAR(res
)->data
.location
+ array_index
- FRAG_RESULT_DATA0
;
804 /* If the uniform is built-in, fail. */
805 if (RESOURCE_UNI(res
)->builtin
)
808 /* From the GL_ARB_uniform_buffer_object spec:
810 * "The value -1 will be returned if <name> does not correspond to an
811 * active uniform variable name in <program>, if <name> is associated
812 * with a named uniform block, or if <name> starts with the reserved
815 if (RESOURCE_UNI(res
)->block_index
!= -1 ||
816 RESOURCE_UNI(res
)->atomic_buffer_index
!= -1)
820 case GL_VERTEX_SUBROUTINE_UNIFORM
:
821 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
822 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
823 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
824 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
825 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
826 /* If the uniform is an array, fail if the index is out of bounds. */
828 && array_index
>= RESOURCE_UNI(res
)->array_elements
) {
832 /* location in remap table + array element offset */
833 return RESOURCE_UNI(res
)->remap_location
+ array_index
;
840 get_top_level_name(const char *name
)
842 const char *first_dot
= strchr(name
, '.');
843 const char *first_square_bracket
= strchr(name
, '[');
845 /* From ARB_program_interface_query spec:
847 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer identifying the
848 * number of active array elements of the top-level shader storage block
849 * member containing to the active variable is written to <params>. If the
850 * top-level block member is not declared as an array, the value one is
851 * written to <params>. If the top-level block member is an array with no
852 * declared size, the value zero is written to <params>.
855 /* The buffer variable is on top level.*/
856 if (!first_square_bracket
&& !first_dot
)
857 name_size
= strlen(name
);
858 else if ((!first_square_bracket
||
859 (first_dot
&& first_dot
< first_square_bracket
)))
860 name_size
= first_dot
- name
;
862 name_size
= first_square_bracket
- name
;
864 return strndup(name
, name_size
);
868 get_var_name(const char *name
)
870 const char *first_dot
= strchr(name
, '.');
875 return strndup(first_dot
+1, strlen(first_dot
) - 1);
879 program_resource_top_level_array_size(struct gl_shader_program
*shProg
,
880 struct gl_program_resource
*res
,
883 int block_index
= RESOURCE_UNI(res
)->block_index
;
885 char *var_name
= get_top_level_name(name
);
886 char *interface_name
=
887 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
889 if (strcmp(var_name
, interface_name
) == 0) {
890 /* Deal with instanced array of SSBOs */
891 char *temp_name
= get_var_name(name
);
893 var_name
= get_top_level_name(temp_name
);
897 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
898 if (shProg
->Shaders
[i
] == NULL
)
901 const gl_shader
*stage
= shProg
->Shaders
[i
];
902 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
903 ir_variable
*var
= node
->as_variable();
904 if (!var
|| !var
->get_interface_type() ||
905 var
->data
.mode
!= ir_var_shader_storage
)
908 const glsl_type
*interface
= var
->get_interface_type();
910 if (strcmp(interface_name
, interface
->name
) != 0)
913 for (unsigned i
= 0; i
< interface
->length
; i
++) {
914 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
915 if (strcmp(field
->name
, var_name
) != 0)
917 /* From GL_ARB_program_interface_query spec:
919 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer
920 * identifying the number of active array elements of the top-level
921 * shader storage block member containing to the active variable is
922 * written to <params>. If the top-level block member is not
923 * declared as an array, the value one is written to <params>. If
924 * the top-level block member is an array with no declared size,
925 * the value zero is written to <params>.
927 if (field
->type
->is_unsized_array())
929 else if (field
->type
->is_array())
930 array_size
= field
->type
->length
;
933 goto found_top_level_array_size
;
937 found_top_level_array_size
:
938 free(interface_name
);
944 program_resource_top_level_array_stride(struct gl_shader_program
*shProg
,
945 struct gl_program_resource
*res
,
948 int block_index
= RESOURCE_UNI(res
)->block_index
;
949 int array_stride
= -1;
950 char *var_name
= get_top_level_name(name
);
951 char *interface_name
=
952 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
954 if (strcmp(var_name
, interface_name
) == 0) {
955 /* Deal with instanced array of SSBOs */
956 char *temp_name
= get_var_name(name
);
958 var_name
= get_top_level_name(temp_name
);
962 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
963 if (shProg
->Shaders
[i
] == NULL
)
966 const gl_shader
*stage
= shProg
->Shaders
[i
];
967 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
968 ir_variable
*var
= node
->as_variable();
969 if (!var
|| !var
->get_interface_type() ||
970 var
->data
.mode
!= ir_var_shader_storage
)
973 const glsl_type
*interface
= var
->get_interface_type();
975 if (strcmp(interface_name
, interface
->name
) != 0) {
979 for (unsigned i
= 0; i
< interface
->length
; i
++) {
980 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
981 if (strcmp(field
->name
, var_name
) != 0)
983 /* From GL_ARB_program_interface_query:
985 * "For the property TOP_LEVEL_ARRAY_STRIDE, a single integer
986 * identifying the stride between array elements of the top-level
987 * shader storage block member containing the active variable is
988 * written to <params>. For top-level block members declared as
989 * arrays, the value written is the difference, in basic machine
990 * units, between the offsets of the active variable for
991 * consecutive elements in the top-level array. For top-level
992 * block members not declared as an array, zero is written to
995 if (field
->type
->is_array()) {
996 const enum glsl_matrix_layout matrix_layout
=
997 glsl_matrix_layout(field
->matrix_layout
);
998 bool row_major
= matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
;
999 const glsl_type
*array_type
= field
->type
->fields
.array
;
1001 if (interface
->interface_packing
!= GLSL_INTERFACE_PACKING_STD430
) {
1002 if (array_type
->is_record()) {
1003 array_stride
= array_type
->std140_size(row_major
);
1004 array_stride
= glsl_align(array_stride
, 16);
1006 unsigned element_base_align
= 0;
1007 element_base_align
= array_type
->std140_base_alignment(row_major
);
1008 array_stride
= MAX2(element_base_align
, 16);
1011 array_stride
= array_type
->std430_array_stride(row_major
);
1016 goto found_top_level_array_size
;
1020 found_top_level_array_size
:
1021 free(interface_name
);
1023 return array_stride
;
1027 * Function implements following location queries:
1028 * glGetUniformLocation
1031 _mesa_program_resource_location(struct gl_shader_program
*shProg
,
1032 GLenum programInterface
, const char *name
)
1034 unsigned array_index
= 0;
1035 struct gl_program_resource
*res
=
1036 _mesa_program_resource_find_name(shProg
, programInterface
, name
,
1039 /* Resource not found. */
1043 return program_resource_location(shProg
, res
, name
, array_index
);
1047 * Function implements following index queries:
1048 * glGetFragDataIndex
1051 _mesa_program_resource_location_index(struct gl_shader_program
*shProg
,
1052 GLenum programInterface
, const char *name
)
1054 struct gl_program_resource
*res
=
1055 _mesa_program_resource_find_name(shProg
, programInterface
, name
, NULL
);
1057 /* Non-existent variable or resource is not referenced by fragment stage. */
1058 if (!res
|| !(res
->StageReferences
& (1 << MESA_SHADER_FRAGMENT
)))
1061 return RESOURCE_VAR(res
)->data
.index
;
1065 stage_from_enum(GLenum ref
)
1068 case GL_REFERENCED_BY_VERTEX_SHADER
:
1069 return MESA_SHADER_VERTEX
;
1070 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1071 return MESA_SHADER_TESS_CTRL
;
1072 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1073 return MESA_SHADER_TESS_EVAL
;
1074 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1075 return MESA_SHADER_GEOMETRY
;
1076 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1077 return MESA_SHADER_FRAGMENT
;
1078 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1079 return MESA_SHADER_COMPUTE
;
1081 assert(!"shader stage not supported");
1082 return MESA_SHADER_STAGES
;
1087 * Check if resource is referenced by given 'referenced by' stage enum.
1088 * ATC and UBO resources hold stage references of their own.
1091 is_resource_referenced(struct gl_shader_program
*shProg
,
1092 struct gl_program_resource
*res
,
1093 GLuint index
, uint8_t stage
)
1095 /* First, check if we even have such a stage active. */
1096 if (!shProg
->_LinkedShaders
[stage
])
1099 if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
)
1100 return RESOURCE_ATC(res
)->StageReferences
[stage
];
1102 if (res
->Type
== GL_UNIFORM_BLOCK
|| res
->Type
== GL_SHADER_STORAGE_BLOCK
)
1103 return shProg
->UniformBlockStageIndex
[stage
][index
] != -1;
1105 return res
->StageReferences
& (1 << stage
);
1109 get_buffer_property(struct gl_shader_program
*shProg
,
1110 struct gl_program_resource
*res
, const GLenum prop
,
1111 GLint
*val
, const char *caller
)
1113 GET_CURRENT_CONTEXT(ctx
);
1114 if (res
->Type
!= GL_UNIFORM_BLOCK
&&
1115 res
->Type
!= GL_ATOMIC_COUNTER_BUFFER
&&
1116 res
->Type
!= GL_SHADER_STORAGE_BLOCK
)
1117 goto invalid_operation
;
1119 if (res
->Type
== GL_UNIFORM_BLOCK
) {
1121 case GL_BUFFER_BINDING
:
1122 *val
= RESOURCE_UBO(res
)->Binding
;
1124 case GL_BUFFER_DATA_SIZE
:
1125 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1127 case GL_NUM_ACTIVE_VARIABLES
:
1129 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1130 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1131 struct gl_program_resource
*uni
=
1132 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1139 case GL_ACTIVE_VARIABLES
:
1140 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1141 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1142 struct gl_program_resource
*uni
=
1143 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1148 _mesa_program_resource_index(shProg
, uni
);
1150 return RESOURCE_UBO(res
)->NumUniforms
;
1152 } else if (res
->Type
== GL_SHADER_STORAGE_BLOCK
) {
1154 case GL_BUFFER_BINDING
:
1155 *val
= RESOURCE_UBO(res
)->Binding
;
1157 case GL_BUFFER_DATA_SIZE
:
1158 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1160 case GL_NUM_ACTIVE_VARIABLES
:
1162 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1163 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1164 struct gl_program_resource
*uni
=
1165 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1172 case GL_ACTIVE_VARIABLES
:
1173 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1174 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1175 struct gl_program_resource
*uni
=
1176 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1181 _mesa_program_resource_index(shProg
, uni
);
1183 return RESOURCE_UBO(res
)->NumUniforms
;
1185 } else if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
) {
1187 case GL_BUFFER_BINDING
:
1188 *val
= RESOURCE_ATC(res
)->Binding
;
1190 case GL_BUFFER_DATA_SIZE
:
1191 *val
= RESOURCE_ATC(res
)->MinimumSize
;
1193 case GL_NUM_ACTIVE_VARIABLES
:
1194 *val
= RESOURCE_ATC(res
)->NumUniforms
;
1196 case GL_ACTIVE_VARIABLES
:
1197 for (unsigned i
= 0; i
< RESOURCE_ATC(res
)->NumUniforms
; i
++)
1198 *val
++ = RESOURCE_ATC(res
)->Uniforms
[i
];
1199 return RESOURCE_ATC(res
)->NumUniforms
;
1202 assert(!"support for property type not implemented");
1205 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1206 _mesa_enum_to_string(res
->Type
),
1207 _mesa_enum_to_string(prop
));
1213 _mesa_program_resource_prop(struct gl_shader_program
*shProg
,
1214 struct gl_program_resource
*res
, GLuint index
,
1215 const GLenum prop
, GLint
*val
, const char *caller
)
1217 GET_CURRENT_CONTEXT(ctx
);
1219 #define VALIDATE_TYPE(type)\
1220 if (res->Type != type)\
1221 goto invalid_operation;
1223 #define VALIDATE_TYPE_2(type1, type2)\
1224 if (res->Type != type1 && res->Type != type2)\
1225 goto invalid_operation;
1228 case GL_NAME_LENGTH
:
1229 switch (res
->Type
) {
1230 case GL_ATOMIC_COUNTER_BUFFER
:
1231 goto invalid_operation
;
1233 /* Resource name length + terminator. */
1234 *val
= _mesa_program_resource_name_len(res
) + 1;
1238 switch (res
->Type
) {
1240 case GL_BUFFER_VARIABLE
:
1241 *val
= RESOURCE_UNI(res
)->type
->gl_type
;
1243 case GL_PROGRAM_INPUT
:
1244 case GL_PROGRAM_OUTPUT
:
1245 *val
= RESOURCE_VAR(res
)->type
->gl_type
;
1247 case GL_TRANSFORM_FEEDBACK_VARYING
:
1248 *val
= RESOURCE_XFB(res
)->Type
;
1251 goto invalid_operation
;
1254 switch (res
->Type
) {
1256 case GL_BUFFER_VARIABLE
:
1257 *val
= MAX2(RESOURCE_UNI(res
)->array_elements
, 1);
1259 case GL_PROGRAM_INPUT
:
1260 case GL_PROGRAM_OUTPUT
:
1261 *val
= MAX2(_mesa_program_resource_array_size(res
), 1);
1263 case GL_TRANSFORM_FEEDBACK_VARYING
:
1264 *val
= MAX2(RESOURCE_XFB(res
)->Size
, 1);
1267 goto invalid_operation
;
1270 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1271 *val
= RESOURCE_UNI(res
)->offset
;
1273 case GL_BLOCK_INDEX
:
1274 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1275 *val
= RESOURCE_UNI(res
)->block_index
;
1277 case GL_ARRAY_STRIDE
:
1278 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1279 *val
= RESOURCE_UNI(res
)->array_stride
;
1281 case GL_MATRIX_STRIDE
:
1282 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1283 *val
= RESOURCE_UNI(res
)->matrix_stride
;
1285 case GL_IS_ROW_MAJOR
:
1286 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1287 *val
= RESOURCE_UNI(res
)->row_major
;
1289 case GL_ATOMIC_COUNTER_BUFFER_INDEX
:
1290 VALIDATE_TYPE(GL_UNIFORM
);
1291 *val
= RESOURCE_UNI(res
)->atomic_buffer_index
;
1293 case GL_BUFFER_BINDING
:
1294 case GL_BUFFER_DATA_SIZE
:
1295 case GL_NUM_ACTIVE_VARIABLES
:
1296 case GL_ACTIVE_VARIABLES
:
1297 return get_buffer_property(shProg
, res
, prop
, val
, caller
);
1298 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1299 if (!_mesa_has_compute_shaders(ctx
))
1302 case GL_REFERENCED_BY_VERTEX_SHADER
:
1303 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1304 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1305 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1306 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1307 switch (res
->Type
) {
1309 case GL_PROGRAM_INPUT
:
1310 case GL_PROGRAM_OUTPUT
:
1311 case GL_UNIFORM_BLOCK
:
1312 case GL_BUFFER_VARIABLE
:
1313 case GL_SHADER_STORAGE_BLOCK
:
1314 case GL_ATOMIC_COUNTER_BUFFER
:
1315 *val
= is_resource_referenced(shProg
, res
, index
,
1316 stage_from_enum(prop
));
1319 goto invalid_operation
;
1322 switch (res
->Type
) {
1324 case GL_PROGRAM_INPUT
:
1325 case GL_PROGRAM_OUTPUT
:
1326 *val
= program_resource_location(shProg
, res
,
1327 _mesa_program_resource_name(res
),
1331 goto invalid_operation
;
1333 case GL_LOCATION_INDEX
:
1334 if (res
->Type
!= GL_PROGRAM_OUTPUT
)
1335 goto invalid_operation
;
1336 *val
= RESOURCE_VAR(res
)->data
.index
;
1339 case GL_NUM_COMPATIBLE_SUBROUTINES
:
1340 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1341 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1342 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1343 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1344 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1345 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1346 goto invalid_operation
;
1347 *val
= RESOURCE_UNI(res
)->num_compatible_subroutines
;
1349 case GL_COMPATIBLE_SUBROUTINES
: {
1350 const struct gl_uniform_storage
*uni
;
1351 struct gl_shader
*sh
;
1355 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1356 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1357 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1358 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1359 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1360 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1361 goto invalid_operation
;
1362 uni
= RESOURCE_UNI(res
);
1364 sh
= shProg
->_LinkedShaders
[_mesa_shader_stage_from_subroutine_uniform(res
->Type
)];
1366 for (i
= 0; i
< sh
->NumSubroutineFunctions
; i
++) {
1367 struct gl_subroutine_function
*fn
= &sh
->SubroutineFunctions
[i
];
1368 for (j
= 0; j
< fn
->num_compat_types
; j
++) {
1369 if (fn
->types
[j
] == uni
->type
) {
1378 case GL_TOP_LEVEL_ARRAY_SIZE
:
1379 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1380 *val
= program_resource_top_level_array_size(shProg
, res
,
1381 _mesa_program_resource_name(res
));
1384 case GL_TOP_LEVEL_ARRAY_STRIDE
:
1385 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1386 *val
= program_resource_top_level_array_stride(shProg
, res
,
1387 _mesa_program_resource_name(res
));
1390 /* GL_ARB_tessellation_shader */
1391 case GL_IS_PER_PATCH
:
1392 switch (res
->Type
) {
1393 case GL_PROGRAM_INPUT
:
1394 case GL_PROGRAM_OUTPUT
:
1395 *val
= RESOURCE_VAR(res
)->data
.patch
;
1398 goto invalid_operation
;
1404 #undef VALIDATE_TYPE
1405 #undef VALIDATE_TYPE_2
1408 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(%s prop %s)", caller
,
1409 _mesa_enum_to_string(res
->Type
),
1410 _mesa_enum_to_string(prop
));
1414 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1415 _mesa_enum_to_string(res
->Type
),
1416 _mesa_enum_to_string(prop
));
1421 _mesa_get_program_resourceiv(struct gl_shader_program
*shProg
,
1422 GLenum programInterface
, GLuint index
, GLsizei propCount
,
1423 const GLenum
*props
, GLsizei bufSize
,
1424 GLsizei
*length
, GLint
*params
)
1426 GET_CURRENT_CONTEXT(ctx
);
1427 GLint
*val
= (GLint
*) params
;
1428 const GLenum
*prop
= props
;
1431 struct gl_program_resource
*res
=
1432 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
1434 /* No such resource found or bufSize negative. */
1435 if (!res
|| bufSize
< 0) {
1436 _mesa_error(ctx
, GL_INVALID_VALUE
,
1437 "glGetProgramResourceiv(%s index %d bufSize %d)",
1438 _mesa_enum_to_string(programInterface
), index
, bufSize
);
1442 /* Write propCount values until error occurs or bufSize reached. */
1443 for (int i
= 0; i
< propCount
&& i
< bufSize
; i
++, val
++, prop
++) {
1445 _mesa_program_resource_prop(shProg
, res
, index
, *prop
, val
,
1446 "glGetProgramResourceiv");
1448 /* Error happened. */
1449 if (props_written
== 0)
1452 amount
+= props_written
;
1455 /* If <length> is not NULL, the actual number of integer values
1456 * written to <params> will be written to <length>.