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"
42 #include "shaderapi.h"
46 program_resource_location(struct gl_shader_program
*shProg
,
47 struct gl_program_resource
*res
, const char *name
,
48 unsigned array_index
);
51 * Declare convenience functions to return resource data in a given type.
52 * Warning! this is not type safe so be *very* careful when using these.
54 #define DECL_RESOURCE_FUNC(name, type) \
55 const type * RESOURCE_ ## name (gl_program_resource *res) { \
57 return (type *) res->Data; \
60 DECL_RESOURCE_FUNC(VAR
, ir_variable
);
61 DECL_RESOURCE_FUNC(UBO
, gl_uniform_block
);
62 DECL_RESOURCE_FUNC(UNI
, gl_uniform_storage
);
63 DECL_RESOURCE_FUNC(ATC
, gl_active_atomic_buffer
);
64 DECL_RESOURCE_FUNC(XFB
, gl_transform_feedback_varying_info
);
65 DECL_RESOURCE_FUNC(SUB
, gl_subroutine_function
);
68 _mesa_BindAttribLocation(GLhandleARB program
, GLuint index
,
69 const GLcharARB
*name
)
71 GET_CURRENT_CONTEXT(ctx
);
73 struct gl_shader_program
*const shProg
=
74 _mesa_lookup_shader_program_err(ctx
, program
, "glBindAttribLocation");
81 if (strncmp(name
, "gl_", 3) == 0) {
82 _mesa_error(ctx
, GL_INVALID_OPERATION
,
83 "glBindAttribLocation(illegal name)");
87 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
) {
88 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindAttribLocation(index)");
92 /* Replace the current value if it's already in the list. Add
93 * VERT_ATTRIB_GENERIC0 because that's how the linker differentiates
94 * between built-in attributes and user-defined attributes.
96 shProg
->AttributeBindings
->put(index
+ VERT_ATTRIB_GENERIC0
, name
);
99 * Note that this attribute binding won't go into effect until
100 * glLinkProgram is called again.
105 is_active_attrib(const ir_variable
*var
)
110 switch (var
->data
.mode
) {
111 case ir_var_shader_in
:
112 return var
->data
.location
!= -1;
114 case ir_var_system_value
:
115 /* From GL 4.3 core spec, section 11.1.1 (Vertex Attributes):
116 * "For GetActiveAttrib, all active vertex shader input variables
117 * are enumerated, including the special built-in inputs gl_VertexID
118 * and gl_InstanceID."
120 return var
->data
.location
== SYSTEM_VALUE_VERTEX_ID
||
121 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
||
122 var
->data
.location
== SYSTEM_VALUE_INSTANCE_ID
;
130 _mesa_GetActiveAttrib(GLhandleARB program
, GLuint desired_index
,
131 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
132 GLenum
* type
, GLcharARB
* name
)
134 GET_CURRENT_CONTEXT(ctx
);
135 struct gl_shader_program
*shProg
;
138 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(maxLength < 0)");
142 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveAttrib");
146 if (!shProg
->LinkStatus
) {
147 _mesa_error(ctx
, GL_INVALID_VALUE
,
148 "glGetActiveAttrib(program not linked)");
152 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
153 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(no vertex shader)");
157 struct gl_program_resource
*res
=
158 _mesa_program_resource_find_index(shProg
, GL_PROGRAM_INPUT
,
161 /* User asked for index that does not exist. */
163 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(index)");
167 const ir_variable
*const var
= RESOURCE_VAR(res
);
169 if (!is_active_attrib(var
))
172 const char *var_name
= var
->name
;
174 /* Since gl_VertexID may be lowered to gl_VertexIDMESA, we need to
175 * consider gl_VertexIDMESA as gl_VertexID for purposes of checking
178 if (var
->data
.mode
== ir_var_system_value
&&
179 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
180 var_name
= "gl_VertexID";
183 _mesa_copy_string(name
, maxLength
, length
, var_name
);
186 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_ARRAY_SIZE
,
187 size
, "glGetActiveAttrib");
190 _mesa_program_resource_prop(shProg
, res
, desired_index
, GL_TYPE
,
191 (GLint
*) type
, "glGetActiveAttrib");
195 _mesa_GetAttribLocation(GLhandleARB program
, const GLcharARB
* name
)
197 GET_CURRENT_CONTEXT(ctx
);
198 struct gl_shader_program
*const shProg
=
199 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
205 if (!shProg
->LinkStatus
) {
206 _mesa_error(ctx
, GL_INVALID_OPERATION
,
207 "glGetAttribLocation(program not linked)");
214 /* Not having a vertex shader is not an error.
216 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)
219 unsigned array_index
= 0;
220 struct gl_program_resource
*res
=
221 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_INPUT
, name
,
227 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
229 /* The extra check against against 0 is made because of builtin-attribute
230 * locations that have offset applied. Function program_resource_location
231 * can return built-in attribute locations < 0 and glGetAttribLocation
232 * cannot be used on "conventional" attributes.
234 * From page 95 of the OpenGL 3.0 spec:
236 * "If name is not an active attribute, if name is a conventional
237 * attribute, or if an error occurs, -1 will be returned."
239 return (loc
>= 0) ? loc
: -1;
243 _mesa_count_active_attribs(struct gl_shader_program
*shProg
)
245 if (!shProg
->LinkStatus
246 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
250 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
252 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
253 if (res
->Type
== GL_PROGRAM_INPUT
&&
254 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
) &&
255 is_active_attrib(RESOURCE_VAR(res
)))
263 _mesa_longest_attribute_name_length(struct gl_shader_program
*shProg
)
265 if (!shProg
->LinkStatus
266 || shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
) {
270 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
272 for (unsigned j
= 0; j
< shProg
->NumProgramResourceList
; j
++, res
++) {
273 if (res
->Type
== GL_PROGRAM_INPUT
&&
274 res
->StageReferences
& (1 << MESA_SHADER_VERTEX
)) {
276 const size_t length
= strlen(RESOURCE_VAR(res
)->name
);
277 if (length
>= longest
)
278 longest
= length
+ 1;
286 _mesa_BindFragDataLocation(GLuint program
, GLuint colorNumber
,
289 _mesa_BindFragDataLocationIndexed(program
, colorNumber
, 0, name
);
293 _mesa_BindFragDataLocationIndexed(GLuint program
, GLuint colorNumber
,
294 GLuint index
, const GLchar
*name
)
296 GET_CURRENT_CONTEXT(ctx
);
298 struct gl_shader_program
*const shProg
=
299 _mesa_lookup_shader_program_err(ctx
, program
, "glBindFragDataLocationIndexed");
306 if (strncmp(name
, "gl_", 3) == 0) {
307 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindFragDataLocationIndexed(illegal name)");
312 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(index)");
316 if (index
== 0 && colorNumber
>= ctx
->Const
.MaxDrawBuffers
) {
317 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
321 if (index
== 1 && colorNumber
>= ctx
->Const
.MaxDualSourceDrawBuffers
) {
322 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindFragDataLocationIndexed(colorNumber)");
326 /* Replace the current value if it's already in the list. Add
327 * FRAG_RESULT_DATA0 because that's how the linker differentiates
328 * between built-in attributes and user-defined attributes.
330 shProg
->FragDataBindings
->put(colorNumber
+ FRAG_RESULT_DATA0
, name
);
331 shProg
->FragDataIndexBindings
->put(index
, name
);
333 * Note that this binding won't go into effect until
334 * glLinkProgram is called again.
340 _mesa_GetFragDataIndex(GLuint program
, const GLchar
*name
)
342 GET_CURRENT_CONTEXT(ctx
);
343 struct gl_shader_program
*const shProg
=
344 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataIndex");
350 if (!shProg
->LinkStatus
) {
351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
352 "glGetFragDataIndex(program not linked)");
359 if (strncmp(name
, "gl_", 3) == 0) {
360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
361 "glGetFragDataIndex(illegal name)");
365 /* Not having a fragment shader is not an error.
367 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
370 return _mesa_program_resource_location_index(shProg
, GL_PROGRAM_OUTPUT
,
375 _mesa_GetFragDataLocation(GLuint program
, const GLchar
*name
)
377 GET_CURRENT_CONTEXT(ctx
);
378 struct gl_shader_program
*const shProg
=
379 _mesa_lookup_shader_program_err(ctx
, program
, "glGetFragDataLocation");
385 if (!shProg
->LinkStatus
) {
386 _mesa_error(ctx
, GL_INVALID_OPERATION
,
387 "glGetFragDataLocation(program not linked)");
394 if (strncmp(name
, "gl_", 3) == 0) {
395 _mesa_error(ctx
, GL_INVALID_OPERATION
,
396 "glGetFragDataLocation(illegal name)");
400 /* Not having a fragment shader is not an error.
402 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)
405 unsigned array_index
= 0;
406 struct gl_program_resource
*res
=
407 _mesa_program_resource_find_name(shProg
, GL_PROGRAM_OUTPUT
, name
,
413 GLint loc
= program_resource_location(shProg
, res
, name
, array_index
);
415 /* The extra check against against 0 is made because of builtin-attribute
416 * locations that have offset applied. Function program_resource_location
417 * can return built-in attribute locations < 0 and glGetFragDataLocation
418 * cannot be used on "conventional" attributes.
420 * From page 95 of the OpenGL 3.0 spec:
422 * "If name is not an active attribute, if name is a conventional
423 * attribute, or if an error occurs, -1 will be returned."
425 return (loc
>= 0) ? loc
: -1;
429 _mesa_program_resource_name(struct gl_program_resource
*res
)
431 const ir_variable
*var
;
433 case GL_UNIFORM_BLOCK
:
434 case GL_SHADER_STORAGE_BLOCK
:
435 return RESOURCE_UBO(res
)->Name
;
436 case GL_TRANSFORM_FEEDBACK_VARYING
:
437 return RESOURCE_XFB(res
)->Name
;
438 case GL_PROGRAM_INPUT
:
439 var
= RESOURCE_VAR(res
);
440 /* Special case gl_VertexIDMESA -> gl_VertexID. */
441 if (var
->data
.mode
== ir_var_system_value
&&
442 var
->data
.location
== SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
) {
443 return "gl_VertexID";
446 case GL_PROGRAM_OUTPUT
:
447 return RESOURCE_VAR(res
)->name
;
449 case GL_BUFFER_VARIABLE
:
450 return RESOURCE_UNI(res
)->name
;
451 case GL_VERTEX_SUBROUTINE_UNIFORM
:
452 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
453 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
454 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
455 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
456 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
457 return RESOURCE_UNI(res
)->name
+ MESA_SUBROUTINE_PREFIX_LEN
;
458 case GL_VERTEX_SUBROUTINE
:
459 case GL_GEOMETRY_SUBROUTINE
:
460 case GL_FRAGMENT_SUBROUTINE
:
461 case GL_COMPUTE_SUBROUTINE
:
462 case GL_TESS_CONTROL_SUBROUTINE
:
463 case GL_TESS_EVALUATION_SUBROUTINE
:
464 return RESOURCE_SUB(res
)->name
;
466 assert(!"support for resource type not implemented");
473 _mesa_program_resource_array_size(struct gl_program_resource
*res
)
476 case GL_TRANSFORM_FEEDBACK_VARYING
:
477 return RESOURCE_XFB(res
)->Size
> 1 ?
478 RESOURCE_XFB(res
)->Size
: 0;
479 case GL_PROGRAM_INPUT
:
480 case GL_PROGRAM_OUTPUT
:
481 return RESOURCE_VAR(res
)->data
.max_array_access
;
483 case GL_VERTEX_SUBROUTINE_UNIFORM
:
484 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
485 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
486 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
487 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
488 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
489 case GL_BUFFER_VARIABLE
:
490 return RESOURCE_UNI(res
)->array_elements
;
491 case GL_VERTEX_SUBROUTINE
:
492 case GL_GEOMETRY_SUBROUTINE
:
493 case GL_FRAGMENT_SUBROUTINE
:
494 case GL_COMPUTE_SUBROUTINE
:
495 case GL_TESS_CONTROL_SUBROUTINE
:
496 case GL_TESS_EVALUATION_SUBROUTINE
:
497 case GL_ATOMIC_COUNTER_BUFFER
:
498 case GL_UNIFORM_BLOCK
:
499 case GL_SHADER_STORAGE_BLOCK
:
502 assert(!"support for resource type not implemented");
508 * Checks if array subscript is valid and if so sets array_index.
511 valid_array_index(const GLchar
*name
, unsigned *array_index
)
514 const GLchar
*out_base_name_end
;
516 idx
= parse_program_resource_name(name
, &out_base_name_end
);
526 /* Find a program resource with specific name in given interface.
528 struct gl_program_resource
*
529 _mesa_program_resource_find_name(struct gl_shader_program
*shProg
,
530 GLenum programInterface
, const char *name
,
531 unsigned *array_index
)
533 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
534 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
535 if (res
->Type
!= programInterface
)
538 /* Resource basename. */
539 const char *rname
= _mesa_program_resource_name(res
);
540 unsigned baselen
= strlen(rname
);
542 if (strncmp(rname
, name
, baselen
) == 0) {
543 switch (programInterface
) {
544 case GL_UNIFORM_BLOCK
:
545 case GL_SHADER_STORAGE_BLOCK
:
546 /* Basename match, check if array or struct. */
547 if (name
[baselen
] == '\0' ||
548 name
[baselen
] == '[' ||
549 name
[baselen
] == '.') {
553 case GL_TRANSFORM_FEEDBACK_VARYING
:
554 case GL_BUFFER_VARIABLE
:
556 case GL_VERTEX_SUBROUTINE_UNIFORM
:
557 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
558 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
559 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
560 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
561 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
562 case GL_VERTEX_SUBROUTINE
:
563 case GL_GEOMETRY_SUBROUTINE
:
564 case GL_FRAGMENT_SUBROUTINE
:
565 case GL_COMPUTE_SUBROUTINE
:
566 case GL_TESS_CONTROL_SUBROUTINE
:
567 case GL_TESS_EVALUATION_SUBROUTINE
:
568 if (name
[baselen
] == '.') {
572 case GL_PROGRAM_INPUT
:
573 case GL_PROGRAM_OUTPUT
:
574 if (name
[baselen
] == '\0') {
576 } else if (name
[baselen
] == '[' &&
577 valid_array_index(name
, array_index
)) {
582 assert(!"not implemented for given interface");
590 calc_resource_index(struct gl_shader_program
*shProg
,
591 struct gl_program_resource
*res
)
595 for (i
= 0; i
< shProg
->NumProgramResourceList
; i
++) {
596 if (&shProg
->ProgramResourceList
[i
] == res
)
598 if (shProg
->ProgramResourceList
[i
].Type
== res
->Type
)
601 return GL_INVALID_INDEX
;
605 * Calculate index for the given resource.
608 _mesa_program_resource_index(struct gl_shader_program
*shProg
,
609 struct gl_program_resource
*res
)
612 return GL_INVALID_INDEX
;
615 case GL_UNIFORM_BLOCK
:
616 case GL_SHADER_STORAGE_BLOCK
:
617 return RESOURCE_UBO(res
)- shProg
->UniformBlocks
;
618 case GL_ATOMIC_COUNTER_BUFFER
:
619 return RESOURCE_ATC(res
) - shProg
->AtomicBuffers
;
620 case GL_TRANSFORM_FEEDBACK_VARYING
:
622 return calc_resource_index(shProg
, res
);
626 /* Find a program resource with specific index in given interface.
628 struct gl_program_resource
*
629 _mesa_program_resource_find_index(struct gl_shader_program
*shProg
,
630 GLenum programInterface
, GLuint index
)
632 struct gl_program_resource
*res
= shProg
->ProgramResourceList
;
635 for (unsigned i
= 0; i
< shProg
->NumProgramResourceList
; i
++, res
++) {
636 if (res
->Type
!= programInterface
)
640 case GL_UNIFORM_BLOCK
:
641 case GL_ATOMIC_COUNTER_BUFFER
:
642 case GL_SHADER_STORAGE_BLOCK
:
643 if (_mesa_program_resource_index(shProg
, res
) == index
)
646 case GL_TRANSFORM_FEEDBACK_VARYING
:
647 case GL_PROGRAM_INPUT
:
648 case GL_PROGRAM_OUTPUT
:
650 case GL_VERTEX_SUBROUTINE_UNIFORM
:
651 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
652 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
653 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
654 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
655 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
656 case GL_VERTEX_SUBROUTINE
:
657 case GL_GEOMETRY_SUBROUTINE
:
658 case GL_FRAGMENT_SUBROUTINE
:
659 case GL_COMPUTE_SUBROUTINE
:
660 case GL_TESS_CONTROL_SUBROUTINE
:
661 case GL_TESS_EVALUATION_SUBROUTINE
:
662 case GL_BUFFER_VARIABLE
:
663 if (++idx
== (int) index
)
667 assert(!"not implemented for given interface");
673 /* Get full name of a program resource.
676 _mesa_get_program_resource_name(struct gl_shader_program
*shProg
,
677 GLenum programInterface
, GLuint index
,
678 GLsizei bufSize
, GLsizei
*length
,
679 GLchar
*name
, const char *caller
)
681 GET_CURRENT_CONTEXT(ctx
);
683 /* Find resource with given interface and index. */
684 struct gl_program_resource
*res
=
685 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
687 /* The error INVALID_VALUE is generated if <index> is greater than
688 * or equal to the number of entries in the active resource list for
689 * <programInterface>.
692 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index %u)", caller
, index
);
697 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize %d)", caller
, bufSize
);
704 length
= &localLength
;
706 _mesa_copy_string(name
, bufSize
, length
, _mesa_program_resource_name(res
));
708 /* Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
711 * "If the active uniform is an array, the uniform name returned in
712 * name will always be the name of the uniform array appended with
715 * The same text also appears in the OpenGL 4.2 spec. It does not,
716 * however, appear in any previous spec. Previous specifications are
717 * ambiguous in this regard. However, either name can later be passed
718 * to glGetUniformLocation (and related APIs), so there shouldn't be any
719 * harm in always appending "[0]" to uniform array names.
721 * Geometry shader stage has different naming convention where the 'normal'
722 * condition is an array, therefore for variables referenced in geometry
723 * stage we do not add '[0]'.
725 * Note, that TCS outputs and TES inputs should not have index appended
728 bool add_index
= !(((programInterface
== GL_PROGRAM_INPUT
) &&
729 res
->StageReferences
& (1 << MESA_SHADER_GEOMETRY
)));
731 /* Transform feedback varyings have array index already appended
734 if (programInterface
== GL_TRANSFORM_FEEDBACK_VARYING
)
737 if (add_index
&& _mesa_program_resource_array_size(res
)) {
740 /* The comparison is strange because *length does *NOT* include the
741 * terminating NUL, but maxLength does.
743 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < bufSize
; i
++)
744 name
[*length
+ i
] = "[0]"[i
];
746 name
[*length
+ i
] = '\0';
753 program_resource_location(struct gl_shader_program
*shProg
,
754 struct gl_program_resource
*res
, const char *name
,
755 unsigned array_index
)
757 /* Built-in locations should report GL_INVALID_INDEX. */
758 if (is_gl_identifier(name
))
759 return GL_INVALID_INDEX
;
761 /* VERT_ATTRIB_GENERIC0 and FRAG_RESULT_DATA0 are decremented as these
762 * offsets are used internally to differentiate between built-in attributes
763 * and user-defined attributes.
766 case GL_PROGRAM_INPUT
:
767 /* If the input is an array, fail if the index is out of bounds. */
769 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
772 return RESOURCE_VAR(res
)->data
.location
+ array_index
- VERT_ATTRIB_GENERIC0
;
773 case GL_PROGRAM_OUTPUT
:
774 /* If the output is an array, fail if the index is out of bounds. */
776 && array_index
>= RESOURCE_VAR(res
)->type
->length
) {
779 return RESOURCE_VAR(res
)->data
.location
+ array_index
- FRAG_RESULT_DATA0
;
781 /* If the uniform is built-in, fail. */
782 if (RESOURCE_UNI(res
)->builtin
)
785 /* From the GL_ARB_uniform_buffer_object spec:
787 * "The value -1 will be returned if <name> does not correspond to an
788 * active uniform variable name in <program>, if <name> is associated
789 * with a named uniform block, or if <name> starts with the reserved
792 if (RESOURCE_UNI(res
)->block_index
!= -1 ||
793 RESOURCE_UNI(res
)->atomic_buffer_index
!= -1)
797 case GL_VERTEX_SUBROUTINE_UNIFORM
:
798 case GL_GEOMETRY_SUBROUTINE_UNIFORM
:
799 case GL_FRAGMENT_SUBROUTINE_UNIFORM
:
800 case GL_COMPUTE_SUBROUTINE_UNIFORM
:
801 case GL_TESS_CONTROL_SUBROUTINE_UNIFORM
:
802 case GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
:
803 /* If the uniform is an array, fail if the index is out of bounds. */
805 && array_index
>= RESOURCE_UNI(res
)->array_elements
) {
809 /* location in remap table + array element offset */
810 return RESOURCE_UNI(res
)->remap_location
+ array_index
;
817 get_top_level_name(const char *name
)
819 const char *first_dot
= strchr(name
, '.');
820 const char *first_square_bracket
= strchr(name
, '[');
822 /* From ARB_program_interface_query spec:
824 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer identifying the
825 * number of active array elements of the top-level shader storage block
826 * member containing to the active variable is written to <params>. If the
827 * top-level block member is not declared as an array, the value one is
828 * written to <params>. If the top-level block member is an array with no
829 * declared size, the value zero is written to <params>.
832 /* The buffer variable is on top level.*/
833 if (!first_square_bracket
&& !first_dot
)
834 name_size
= strlen(name
);
835 else if ((!first_square_bracket
||
836 (first_dot
&& first_dot
< first_square_bracket
)))
837 name_size
= first_dot
- name
;
839 name_size
= first_square_bracket
- name
;
841 return strndup(name
, name_size
);
845 get_var_name(const char *name
)
847 const char *first_dot
= strchr(name
, '.');
852 return strndup(first_dot
+1, strlen(first_dot
) - 1);
856 program_resource_top_level_array_size(struct gl_shader_program
*shProg
,
857 struct gl_program_resource
*res
,
860 int block_index
= RESOURCE_UNI(res
)->block_index
;
862 char *var_name
= get_top_level_name(name
);
863 char *interface_name
=
864 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
866 if (strcmp(var_name
, interface_name
) == 0) {
867 /* Deal with instanced array of SSBOs */
868 char *temp_name
= get_var_name(name
);
870 var_name
= get_top_level_name(temp_name
);
874 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
875 if (shProg
->Shaders
[i
] == NULL
)
878 const gl_shader
*stage
= shProg
->Shaders
[i
];
879 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
880 ir_variable
*var
= node
->as_variable();
881 if (!var
|| !var
->get_interface_type() ||
882 var
->data
.mode
!= ir_var_shader_storage
)
885 const glsl_type
*interface
= var
->get_interface_type();
887 if (strcmp(interface_name
, interface
->name
) != 0)
890 for (unsigned i
= 0; i
< interface
->length
; i
++) {
891 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
892 if (strcmp(field
->name
, var_name
) != 0)
894 /* From GL_ARB_program_interface_query spec:
896 * "For the property TOP_LEVEL_ARRAY_SIZE, a single integer
897 * identifying the number of active array elements of the top-level
898 * shader storage block member containing to the active variable is
899 * written to <params>. If the top-level block member is not
900 * declared as an array, the value one is written to <params>. If
901 * the top-level block member is an array with no declared size,
902 * the value zero is written to <params>.
904 if (field
->type
->is_unsized_array())
906 else if (field
->type
->is_array())
907 array_size
= field
->type
->length
;
910 goto found_top_level_array_size
;
914 found_top_level_array_size
:
915 free(interface_name
);
921 program_resource_top_level_array_stride(struct gl_shader_program
*shProg
,
922 struct gl_program_resource
*res
,
925 int block_index
= RESOURCE_UNI(res
)->block_index
;
926 int array_stride
= -1;
927 char *var_name
= get_top_level_name(name
);
928 char *interface_name
=
929 get_top_level_name(shProg
->UniformBlocks
[block_index
].Name
);
931 if (strcmp(var_name
, interface_name
) == 0) {
932 /* Deal with instanced array of SSBOs */
933 char *temp_name
= get_var_name(name
);
935 var_name
= get_top_level_name(temp_name
);
939 for (unsigned i
= 0; i
< shProg
->NumShaders
; i
++) {
940 if (shProg
->Shaders
[i
] == NULL
)
943 const gl_shader
*stage
= shProg
->Shaders
[i
];
944 foreach_in_list(ir_instruction
, node
, stage
->ir
) {
945 ir_variable
*var
= node
->as_variable();
946 if (!var
|| !var
->get_interface_type() ||
947 var
->data
.mode
!= ir_var_shader_storage
)
950 const glsl_type
*interface
= var
->get_interface_type();
952 if (strcmp(interface_name
, interface
->name
) != 0) {
956 for (unsigned i
= 0; i
< interface
->length
; i
++) {
957 const glsl_struct_field
*field
= &interface
->fields
.structure
[i
];
958 if (strcmp(field
->name
, var_name
) != 0)
960 /* From GL_ARB_program_interface_query:
962 * "For the property TOP_LEVEL_ARRAY_STRIDE, a single integer
963 * identifying the stride between array elements of the top-level
964 * shader storage block member containing the active variable is
965 * written to <params>. For top-level block members declared as
966 * arrays, the value written is the difference, in basic machine
967 * units, between the offsets of the active variable for
968 * consecutive elements in the top-level array. For top-level
969 * block members not declared as an array, zero is written to
972 if (field
->type
->is_array()) {
973 const enum glsl_matrix_layout matrix_layout
=
974 glsl_matrix_layout(field
->matrix_layout
);
975 bool row_major
= matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
;
976 const glsl_type
*array_type
= field
->type
->fields
.array
;
978 if (interface
->interface_packing
!= GLSL_INTERFACE_PACKING_STD430
) {
979 if (array_type
->is_record()) {
980 array_stride
= array_type
->std140_size(row_major
);
981 array_stride
= glsl_align(array_stride
, 16);
983 unsigned element_base_align
= 0;
984 element_base_align
= array_type
->std140_base_alignment(row_major
);
985 array_stride
= MAX2(element_base_align
, 16);
988 array_stride
= array_type
->std430_array_stride(row_major
);
993 goto found_top_level_array_size
;
997 found_top_level_array_size
:
1003 * Function implements following location queries:
1004 * glGetUniformLocation
1007 _mesa_program_resource_location(struct gl_shader_program
*shProg
,
1008 GLenum programInterface
, const char *name
)
1010 unsigned array_index
= 0;
1011 struct gl_program_resource
*res
=
1012 _mesa_program_resource_find_name(shProg
, programInterface
, name
,
1015 /* Resource not found. */
1019 return program_resource_location(shProg
, res
, name
, array_index
);
1023 * Function implements following index queries:
1024 * glGetFragDataIndex
1027 _mesa_program_resource_location_index(struct gl_shader_program
*shProg
,
1028 GLenum programInterface
, const char *name
)
1030 struct gl_program_resource
*res
=
1031 _mesa_program_resource_find_name(shProg
, programInterface
, name
, NULL
);
1033 /* Non-existent variable or resource is not referenced by fragment stage. */
1034 if (!res
|| !(res
->StageReferences
& (1 << MESA_SHADER_FRAGMENT
)))
1037 return RESOURCE_VAR(res
)->data
.index
;
1041 stage_from_enum(GLenum ref
)
1044 case GL_REFERENCED_BY_VERTEX_SHADER
:
1045 return MESA_SHADER_VERTEX
;
1046 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1047 return MESA_SHADER_TESS_CTRL
;
1048 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1049 return MESA_SHADER_TESS_EVAL
;
1050 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1051 return MESA_SHADER_GEOMETRY
;
1052 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1053 return MESA_SHADER_FRAGMENT
;
1054 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1055 return MESA_SHADER_COMPUTE
;
1057 assert(!"shader stage not supported");
1058 return MESA_SHADER_STAGES
;
1063 * Check if resource is referenced by given 'referenced by' stage enum.
1064 * ATC and UBO resources hold stage references of their own.
1067 is_resource_referenced(struct gl_shader_program
*shProg
,
1068 struct gl_program_resource
*res
,
1069 GLuint index
, uint8_t stage
)
1071 /* First, check if we even have such a stage active. */
1072 if (!shProg
->_LinkedShaders
[stage
])
1075 if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
)
1076 return RESOURCE_ATC(res
)->StageReferences
[stage
];
1078 if (res
->Type
== GL_UNIFORM_BLOCK
|| res
->Type
== GL_SHADER_STORAGE_BLOCK
)
1079 return shProg
->UniformBlockStageIndex
[stage
][index
] != -1;
1081 return res
->StageReferences
& (1 << stage
);
1085 get_buffer_property(struct gl_shader_program
*shProg
,
1086 struct gl_program_resource
*res
, const GLenum prop
,
1087 GLint
*val
, const char *caller
)
1089 GET_CURRENT_CONTEXT(ctx
);
1090 if (res
->Type
!= GL_UNIFORM_BLOCK
&&
1091 res
->Type
!= GL_ATOMIC_COUNTER_BUFFER
&&
1092 res
->Type
!= GL_SHADER_STORAGE_BLOCK
)
1093 goto invalid_operation
;
1095 if (res
->Type
== GL_UNIFORM_BLOCK
) {
1097 case GL_BUFFER_BINDING
:
1098 *val
= RESOURCE_UBO(res
)->Binding
;
1100 case GL_BUFFER_DATA_SIZE
:
1101 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1103 case GL_NUM_ACTIVE_VARIABLES
:
1105 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1106 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1107 struct gl_program_resource
*uni
=
1108 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1115 case GL_ACTIVE_VARIABLES
:
1116 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1117 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1118 struct gl_program_resource
*uni
=
1119 _mesa_program_resource_find_name(shProg
, GL_UNIFORM
, iname
,
1124 _mesa_program_resource_index(shProg
, uni
);
1126 return RESOURCE_UBO(res
)->NumUniforms
;
1128 } else if (res
->Type
== GL_SHADER_STORAGE_BLOCK
) {
1130 case GL_BUFFER_BINDING
:
1131 *val
= RESOURCE_UBO(res
)->Binding
;
1133 case GL_BUFFER_DATA_SIZE
:
1134 *val
= RESOURCE_UBO(res
)->UniformBufferSize
;
1136 case GL_NUM_ACTIVE_VARIABLES
:
1138 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1139 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1140 struct gl_program_resource
*uni
=
1141 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1148 case GL_ACTIVE_VARIABLES
:
1149 for (unsigned i
= 0; i
< RESOURCE_UBO(res
)->NumUniforms
; i
++) {
1150 const char *iname
= RESOURCE_UBO(res
)->Uniforms
[i
].IndexName
;
1151 struct gl_program_resource
*uni
=
1152 _mesa_program_resource_find_name(shProg
, GL_BUFFER_VARIABLE
,
1157 _mesa_program_resource_index(shProg
, uni
);
1159 return RESOURCE_UBO(res
)->NumUniforms
;
1161 } else if (res
->Type
== GL_ATOMIC_COUNTER_BUFFER
) {
1163 case GL_BUFFER_BINDING
:
1164 *val
= RESOURCE_ATC(res
)->Binding
;
1166 case GL_BUFFER_DATA_SIZE
:
1167 *val
= RESOURCE_ATC(res
)->MinimumSize
;
1169 case GL_NUM_ACTIVE_VARIABLES
:
1170 *val
= RESOURCE_ATC(res
)->NumUniforms
;
1172 case GL_ACTIVE_VARIABLES
:
1173 for (unsigned i
= 0; i
< RESOURCE_ATC(res
)->NumUniforms
; i
++)
1174 *val
++ = RESOURCE_ATC(res
)->Uniforms
[i
];
1175 return RESOURCE_ATC(res
)->NumUniforms
;
1178 assert(!"support for property type not implemented");
1181 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1182 _mesa_enum_to_string(res
->Type
),
1183 _mesa_enum_to_string(prop
));
1189 _mesa_program_resource_prop(struct gl_shader_program
*shProg
,
1190 struct gl_program_resource
*res
, GLuint index
,
1191 const GLenum prop
, GLint
*val
, const char *caller
)
1193 GET_CURRENT_CONTEXT(ctx
);
1195 #define VALIDATE_TYPE(type)\
1196 if (res->Type != type)\
1197 goto invalid_operation;
1199 #define VALIDATE_TYPE_2(type1, type2)\
1200 if (res->Type != type1 && res->Type != type2)\
1201 goto invalid_operation;
1204 case GL_NAME_LENGTH
:
1205 switch (res
->Type
) {
1206 case GL_ATOMIC_COUNTER_BUFFER
:
1207 goto invalid_operation
;
1208 case GL_TRANSFORM_FEEDBACK_VARYING
:
1209 *val
= strlen(_mesa_program_resource_name(res
)) + 1;
1212 /* Base name +3 if array '[0]' + terminator. */
1213 *val
= strlen(_mesa_program_resource_name(res
)) +
1214 (_mesa_program_resource_array_size(res
) > 0 ? 3 : 0) + 1;
1218 switch (res
->Type
) {
1220 case GL_BUFFER_VARIABLE
:
1221 *val
= RESOURCE_UNI(res
)->type
->gl_type
;
1223 case GL_PROGRAM_INPUT
:
1224 case GL_PROGRAM_OUTPUT
:
1225 *val
= RESOURCE_VAR(res
)->type
->gl_type
;
1227 case GL_TRANSFORM_FEEDBACK_VARYING
:
1228 *val
= RESOURCE_XFB(res
)->Type
;
1231 goto invalid_operation
;
1234 switch (res
->Type
) {
1236 case GL_BUFFER_VARIABLE
:
1237 *val
= MAX2(RESOURCE_UNI(res
)->array_elements
, 1);
1239 case GL_PROGRAM_INPUT
:
1240 case GL_PROGRAM_OUTPUT
:
1241 *val
= MAX2(RESOURCE_VAR(res
)->type
->length
, 1);
1243 case GL_TRANSFORM_FEEDBACK_VARYING
:
1244 *val
= MAX2(RESOURCE_XFB(res
)->Size
, 1);
1247 goto invalid_operation
;
1250 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1251 *val
= RESOURCE_UNI(res
)->offset
;
1253 case GL_BLOCK_INDEX
:
1254 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1255 *val
= RESOURCE_UNI(res
)->block_index
;
1257 case GL_ARRAY_STRIDE
:
1258 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1259 *val
= RESOURCE_UNI(res
)->array_stride
;
1261 case GL_MATRIX_STRIDE
:
1262 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1263 *val
= RESOURCE_UNI(res
)->matrix_stride
;
1265 case GL_IS_ROW_MAJOR
:
1266 VALIDATE_TYPE_2(GL_UNIFORM
, GL_BUFFER_VARIABLE
);
1267 *val
= RESOURCE_UNI(res
)->row_major
;
1269 case GL_ATOMIC_COUNTER_BUFFER_INDEX
:
1270 VALIDATE_TYPE(GL_UNIFORM
);
1271 *val
= RESOURCE_UNI(res
)->atomic_buffer_index
;
1273 case GL_BUFFER_BINDING
:
1274 case GL_BUFFER_DATA_SIZE
:
1275 case GL_NUM_ACTIVE_VARIABLES
:
1276 case GL_ACTIVE_VARIABLES
:
1277 return get_buffer_property(shProg
, res
, prop
, val
, caller
);
1278 case GL_REFERENCED_BY_COMPUTE_SHADER
:
1279 if (!_mesa_has_compute_shaders(ctx
))
1282 case GL_REFERENCED_BY_VERTEX_SHADER
:
1283 case GL_REFERENCED_BY_TESS_CONTROL_SHADER
:
1284 case GL_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1285 case GL_REFERENCED_BY_GEOMETRY_SHADER
:
1286 case GL_REFERENCED_BY_FRAGMENT_SHADER
:
1287 switch (res
->Type
) {
1289 case GL_PROGRAM_INPUT
:
1290 case GL_PROGRAM_OUTPUT
:
1291 case GL_UNIFORM_BLOCK
:
1292 case GL_BUFFER_VARIABLE
:
1293 case GL_SHADER_STORAGE_BLOCK
:
1294 case GL_ATOMIC_COUNTER_BUFFER
:
1295 *val
= is_resource_referenced(shProg
, res
, index
,
1296 stage_from_enum(prop
));
1299 goto invalid_operation
;
1302 switch (res
->Type
) {
1304 case GL_PROGRAM_INPUT
:
1305 case GL_PROGRAM_OUTPUT
:
1306 *val
= program_resource_location(shProg
, res
,
1307 _mesa_program_resource_name(res
),
1311 goto invalid_operation
;
1313 case GL_LOCATION_INDEX
:
1314 if (res
->Type
!= GL_PROGRAM_OUTPUT
)
1315 goto invalid_operation
;
1316 *val
= RESOURCE_VAR(res
)->data
.index
;
1319 case GL_NUM_COMPATIBLE_SUBROUTINES
:
1320 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1321 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1322 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1323 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1324 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1325 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1326 goto invalid_operation
;
1327 *val
= RESOURCE_UNI(res
)->num_compatible_subroutines
;
1329 case GL_COMPATIBLE_SUBROUTINES
: {
1330 const struct gl_uniform_storage
*uni
;
1331 struct gl_shader
*sh
;
1335 if (res
->Type
!= GL_VERTEX_SUBROUTINE_UNIFORM
&&
1336 res
->Type
!= GL_FRAGMENT_SUBROUTINE_UNIFORM
&&
1337 res
->Type
!= GL_GEOMETRY_SUBROUTINE_UNIFORM
&&
1338 res
->Type
!= GL_COMPUTE_SUBROUTINE_UNIFORM
&&
1339 res
->Type
!= GL_TESS_CONTROL_SUBROUTINE_UNIFORM
&&
1340 res
->Type
!= GL_TESS_EVALUATION_SUBROUTINE_UNIFORM
)
1341 goto invalid_operation
;
1342 uni
= RESOURCE_UNI(res
);
1344 sh
= shProg
->_LinkedShaders
[_mesa_shader_stage_from_subroutine_uniform(res
->Type
)];
1346 for (i
= 0; i
< sh
->NumSubroutineFunctions
; i
++) {
1347 struct gl_subroutine_function
*fn
= &sh
->SubroutineFunctions
[i
];
1348 for (j
= 0; j
< fn
->num_compat_types
; j
++) {
1349 if (fn
->types
[j
] == uni
->type
) {
1358 case GL_TOP_LEVEL_ARRAY_SIZE
:
1359 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1360 *val
= program_resource_top_level_array_size(shProg
, res
,
1361 _mesa_program_resource_name(res
));
1364 case GL_TOP_LEVEL_ARRAY_STRIDE
:
1365 VALIDATE_TYPE(GL_BUFFER_VARIABLE
);
1366 *val
= program_resource_top_level_array_stride(shProg
, res
,
1367 _mesa_program_resource_name(res
));
1370 /* GL_ARB_tessellation_shader */
1371 case GL_IS_PER_PATCH
:
1372 switch (res
->Type
) {
1373 case GL_PROGRAM_INPUT
:
1374 case GL_PROGRAM_OUTPUT
:
1375 *val
= RESOURCE_VAR(res
)->data
.patch
;
1378 goto invalid_operation
;
1384 #undef VALIDATE_TYPE
1385 #undef VALIDATE_TYPE_2
1388 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(%s prop %s)", caller
,
1389 _mesa_enum_to_string(res
->Type
),
1390 _mesa_enum_to_string(prop
));
1394 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(%s prop %s)", caller
,
1395 _mesa_enum_to_string(res
->Type
),
1396 _mesa_enum_to_string(prop
));
1401 _mesa_get_program_resourceiv(struct gl_shader_program
*shProg
,
1402 GLenum programInterface
, GLuint index
, GLsizei propCount
,
1403 const GLenum
*props
, GLsizei bufSize
,
1404 GLsizei
*length
, GLint
*params
)
1406 GET_CURRENT_CONTEXT(ctx
);
1407 GLint
*val
= (GLint
*) params
;
1408 const GLenum
*prop
= props
;
1411 struct gl_program_resource
*res
=
1412 _mesa_program_resource_find_index(shProg
, programInterface
, index
);
1414 /* No such resource found or bufSize negative. */
1415 if (!res
|| bufSize
< 0) {
1416 _mesa_error(ctx
, GL_INVALID_VALUE
,
1417 "glGetProgramResourceiv(%s index %d bufSize %d)",
1418 _mesa_enum_to_string(programInterface
), index
, bufSize
);
1422 /* Write propCount values until error occurs or bufSize reached. */
1423 for (int i
= 0; i
< propCount
&& i
< bufSize
; i
++, val
++, prop
++) {
1425 _mesa_program_resource_prop(shProg
, res
, index
, *prop
, val
,
1426 "glGetProgramResourceiv");
1428 /* Error happened. */
1429 if (props_written
== 0)
1432 amount
+= props_written
;
1435 /* If <length> is not NULL, the actual number of integer values
1436 * written to <params> will be written to <length>.