2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "api_validate.h"
29 #include "bufferobj.h"
33 #include "pipelineobj.h"
36 #include "transformfeedback.h"
39 #include "program/prog_print.h"
43 check_blend_func_error(struct gl_context
*ctx
)
45 /* The ARB_blend_func_extended spec's ERRORS section says:
47 * "The error INVALID_OPERATION is generated by Begin or any procedure
48 * that implicitly calls Begin if any draw buffer has a blend function
49 * requiring the second color input (SRC1_COLOR, ONE_MINUS_SRC1_COLOR,
50 * SRC1_ALPHA or ONE_MINUS_SRC1_ALPHA), and a framebuffer is bound that
51 * has more than the value of MAX_DUAL_SOURCE_DRAW_BUFFERS-1 active
52 * color attachements."
54 for (unsigned i
= ctx
->Const
.MaxDualSourceDrawBuffers
;
55 i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
;
57 if (ctx
->Color
.Blend
[i
]._UsesDualSrc
) {
58 _mesa_error(ctx
, GL_INVALID_OPERATION
,
59 "dual source blend on illegal attachment");
64 if (ctx
->Color
.BlendEnabled
&& ctx
->Color
._AdvancedBlendMode
) {
65 /* The KHR_blend_equation_advanced spec says:
67 * "If any non-NONE draw buffer uses a blend equation found in table
68 * X.1 or X.2, the error INVALID_OPERATION is generated by Begin or
69 * any operation that implicitly calls Begin (such as DrawElements)
72 * * the draw buffer for color output zero selects multiple color
73 * buffers (e.g., FRONT_AND_BACK in the default framebuffer); or
75 * * the draw buffer for any other color output is not NONE."
77 if (ctx
->DrawBuffer
->ColorDrawBuffer
[0] == GL_FRONT_AND_BACK
) {
78 _mesa_error(ctx
, GL_INVALID_OPERATION
,
79 "advanced blending is active and draw buffer for color "
80 "output zero selects multiple color buffers");
84 for (unsigned i
= 1; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
85 if (ctx
->DrawBuffer
->ColorDrawBuffer
[i
] != GL_NONE
) {
86 _mesa_error(ctx
, GL_INVALID_OPERATION
,
87 "advanced blending is active with multiple color "
93 /* The KHR_blend_equation_advanced spec says:
95 * "Advanced blending equations require the use of a fragment shader
96 * with a matching "blend_support" layout qualifier. If the current
97 * blend equation is found in table X.1 or X.2, and the active
98 * fragment shader does not include the layout qualifier matching
99 * the blend equation or "blend_support_all_equations", the error
100 * INVALID_OPERATION is generated [...]"
102 const struct gl_program
*prog
= ctx
->_Shader
->_CurrentFragmentProgram
;
103 const GLbitfield blend_support
= !prog
? 0 : prog
->sh
.fs
.BlendSupport
;
105 if ((blend_support
& ctx
->Color
._AdvancedBlendMode
) == 0) {
106 _mesa_error(ctx
, GL_INVALID_OPERATION
,
107 "fragment shader does not allow advanced blending mode "
109 _mesa_enum_to_string(ctx
->Color
.Blend
[0].EquationRGB
));
118 * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
119 * is called to see if it's valid to render. This involves checking that
120 * the current shader is valid and the framebuffer is complete.
121 * It also check the current pipeline object is valid if any.
122 * If an error is detected it'll be recorded here.
123 * \return GL_TRUE if OK to render, GL_FALSE if not
126 _mesa_valid_to_render(struct gl_context
*ctx
, const char *where
)
128 /* This depends on having up to date derived state (shaders) */
130 _mesa_update_state(ctx
);
132 if (ctx
->API
== API_OPENGL_COMPAT
) {
133 /* Any shader stages that are not supplied by the GLSL shader and have
134 * assembly shaders enabled must now be validated.
136 if (!ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
]
137 && ctx
->VertexProgram
.Enabled
&& !ctx
->VertexProgram
._Enabled
) {
138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
139 "%s(vertex program not valid)", where
);
143 if (!ctx
->_Shader
->CurrentProgram
[MESA_SHADER_FRAGMENT
]) {
144 if (ctx
->FragmentProgram
.Enabled
&& !ctx
->FragmentProgram
._Enabled
) {
145 _mesa_error(ctx
, GL_INVALID_OPERATION
,
146 "%s(fragment program not valid)", where
);
150 /* If drawing to integer-valued color buffers, there must be an
151 * active fragment shader (GL_EXT_texture_integer).
153 if (ctx
->DrawBuffer
&& ctx
->DrawBuffer
->_IntegerBuffers
) {
154 _mesa_error(ctx
, GL_INVALID_OPERATION
,
155 "%s(integer format but no fragment shader)", where
);
161 /* A pipeline object is bound */
162 if (ctx
->_Shader
->Name
&& !ctx
->_Shader
->Validated
) {
163 if (!_mesa_validate_program_pipeline(ctx
, ctx
->_Shader
)) {
164 _mesa_error(ctx
, GL_INVALID_OPERATION
,
165 "glValidateProgramPipeline failed to validate the "
171 /* If a program is active and SSO not in use, check if validation of
172 * samplers succeeded for the active program. */
173 if (ctx
->_Shader
->ActiveProgram
&& ctx
->_Shader
!= ctx
->Pipeline
.Current
) {
175 if (!_mesa_sampler_uniforms_are_valid(ctx
->_Shader
->ActiveProgram
,
177 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s", errMsg
);
182 if (ctx
->DrawBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
183 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
184 "%s(incomplete framebuffer)", where
);
188 if (!check_blend_func_error(ctx
)) {
192 /* From the GL_NV_fill_rectangle spec:
194 * "An INVALID_OPERATION error is generated by Begin or any Draw command if
195 * only one of the front and back polygon mode is FILL_RECTANGLE_NV."
197 if ((ctx
->Polygon
.FrontMode
== GL_FILL_RECTANGLE_NV
) !=
198 (ctx
->Polygon
.BackMode
== GL_FILL_RECTANGLE_NV
)) {
199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
200 "GL_FILL_RECTANGLE_NV must be used as both front/back "
201 "polygon mode or neither");
206 if (ctx
->_Shader
->Flags
& GLSL_LOG
) {
207 struct gl_program
**prog
= ctx
->_Shader
->CurrentProgram
;
209 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
210 if (prog
[i
] == NULL
|| prog
[i
]->_Used
)
213 /* This is the first time this shader is being used.
214 * Append shader's constants/uniforms to log file.
216 * Only log data for the program target that matches the shader
217 * target. It's possible to have a program bound to the vertex
218 * shader target that also supplied a fragment shader. If that
219 * program isn't also bound to the fragment shader target we don't
220 * want to log its fragment data.
222 _mesa_append_uniforms_to_file(prog
[i
]);
225 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
227 prog
[i
]->_Used
= GL_TRUE
;
237 * Check if OK to draw arrays/elements.
240 check_valid_to_render(struct gl_context
*ctx
, const char *function
)
242 if (!_mesa_valid_to_render(ctx
, function
)) {
246 if (!_mesa_all_buffers_are_unmapped(ctx
->Array
.VAO
)) {
247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
248 "%s(vertex buffers are mapped)", function
);
252 /* Section 11.2 (Tessellation) of the ES 3.2 spec says:
254 * "An INVALID_OPERATION error is generated by any command that
255 * transfers vertices to the GL if the current program state has
256 * one but not both of a tessellation control shader and tessellation
257 * evaluation shader."
259 * The OpenGL spec argues that this is allowed because a tess ctrl shader
260 * without a tess eval shader can be used with transform feedback.
261 * However, glBeginTransformFeedback doesn't allow GL_PATCHES and
262 * therefore doesn't allow tessellation.
264 * Further investigation showed that this is indeed a spec bug and
265 * a tess ctrl shader without a tess eval shader shouldn't have been
266 * allowed, because there is no API in GL 4.0 that can make use this
267 * to produce something useful.
269 * Also, all vendors except one don't support a tess ctrl shader without
270 * a tess eval shader anyway.
272 if (ctx
->TessCtrlProgram
._Current
&& !ctx
->TessEvalProgram
._Current
) {
273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
274 "%s(tess eval shader is missing)", function
);
280 /* Section 11.2 (Tessellation) of the ES 3.2 spec says:
282 * "An INVALID_OPERATION error is generated by any command that
283 * transfers vertices to the GL if the current program state has
284 * one but not both of a tessellation control shader and tessellation
285 * evaluation shader."
287 if (_mesa_is_gles3(ctx
) &&
288 ctx
->TessEvalProgram
._Current
&& !ctx
->TessCtrlProgram
._Current
) {
289 _mesa_error(ctx
, GL_INVALID_OPERATION
,
290 "%s(tess ctrl shader is missing)", function
);
294 /* For ES2, we can draw if we have a vertex program/shader). */
295 return ctx
->VertexProgram
._Current
!= NULL
;
298 /* For OpenGL ES, only draw if we have vertex positions
300 if (!ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
)
304 case API_OPENGL_CORE
:
305 /* Section 10.4 (Drawing Commands Using Vertex Arrays) of the OpenGL 4.5
306 * Core Profile spec says:
308 * "An INVALID_OPERATION error is generated if no vertex array
309 * object is bound (see section 10.3.1)."
311 if (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
312 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(no VAO bound)", function
);
316 /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec
319 * "If there is no active program for the vertex or fragment shader
320 * stages, the results of vertex and/or fragment processing will be
321 * undefined. However, this is not an error."
323 * The fragment shader is not tested here because other state (e.g.,
324 * GL_RASTERIZER_DISCARD) affects whether or not we actually care.
326 return ctx
->VertexProgram
._Current
!= NULL
;
328 case API_OPENGL_COMPAT
:
329 if (ctx
->VertexProgram
._Current
!= NULL
) {
330 /* Draw regardless of whether or not we have any vertex arrays.
331 * (Ex: could draw a point using a constant vertex pos)
335 /* Draw if we have vertex positions (GL_VERTEX_ARRAY or generic
338 return (ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_POS
].Enabled
||
339 ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_GENERIC0
].Enabled
);
344 unreachable("Invalid API value in check_valid_to_render()");
352 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
353 * etc? The set of legal values depends on whether geometry shaders/programs
355 * Note: This may be called during display list compilation.
358 _mesa_is_valid_prim_mode(struct gl_context
*ctx
, GLenum mode
)
360 /* The overwhelmingly common case is (mode <= GL_TRIANGLE_FAN). Test that
361 * first and exit. You would think that a switch-statement would be the
362 * right approach, but at least GCC 4.7.2 generates some pretty dire code
363 * for the common case.
365 if (likely(mode
<= GL_TRIANGLE_FAN
))
368 if (mode
<= GL_POLYGON
)
369 return (ctx
->API
== API_OPENGL_COMPAT
);
371 if (mode
<= GL_TRIANGLE_STRIP_ADJACENCY
)
372 return _mesa_has_geometry_shaders(ctx
);
374 if (mode
== GL_PATCHES
)
375 return _mesa_has_tessellation(ctx
);
382 * Is 'mode' a valid value for glBegin(), glDrawArrays(), glDrawElements(),
383 * etc? Also, do additional checking related to transformation feedback.
384 * Note: this function cannot be called during glNewList(GL_COMPILE) because
385 * this code depends on current transform feedback state.
386 * Also, do additional checking related to tessellation shaders.
389 _mesa_valid_prim_mode(struct gl_context
*ctx
, GLenum mode
, const char *name
)
391 bool valid_enum
= _mesa_is_valid_prim_mode(ctx
, mode
);
394 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(mode=%x)", name
, mode
);
398 /* From the OpenGL 4.5 specification, section 11.3.1:
400 * The error INVALID_OPERATION is generated if Begin, or any command that
401 * implicitly calls Begin, is called when a geometry shader is active and:
403 * * the input primitive type of the current geometry shader is
404 * POINTS and <mode> is not POINTS,
406 * * the input primitive type of the current geometry shader is
407 * LINES and <mode> is not LINES, LINE_STRIP, or LINE_LOOP,
409 * * the input primitive type of the current geometry shader is
410 * TRIANGLES and <mode> is not TRIANGLES, TRIANGLE_STRIP or
413 * * the input primitive type of the current geometry shader is
414 * LINES_ADJACENCY_ARB and <mode> is not LINES_ADJACENCY_ARB or
415 * LINE_STRIP_ADJACENCY_ARB, or
417 * * the input primitive type of the current geometry shader is
418 * TRIANGLES_ADJACENCY_ARB and <mode> is not
419 * TRIANGLES_ADJACENCY_ARB or TRIANGLE_STRIP_ADJACENCY_ARB.
421 * The GL spec doesn't mention any interaction with tessellation, which
422 * is clearly a spec bug. The same rule should apply, but instead of
423 * the draw primitive mode, the tessellation evaluation shader primitive
424 * mode should be used for the checking.
426 if (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]) {
427 const GLenum geom_mode
=
428 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->
429 info
.gs
.input_primitive
;
430 struct gl_program
*tes
=
431 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
];
432 GLenum mode_before_gs
= mode
;
435 if (tes
->info
.tess
.point_mode
)
436 mode_before_gs
= GL_POINTS
;
437 else if (tes
->info
.tess
.primitive_mode
== GL_ISOLINES
)
438 mode_before_gs
= GL_LINES
;
440 /* the GL_QUADS mode generates triangles too */
441 mode_before_gs
= GL_TRIANGLES
;
444 switch (mode_before_gs
) {
446 valid_enum
= (geom_mode
== GL_POINTS
);
451 valid_enum
= (geom_mode
== GL_LINES
);
454 case GL_TRIANGLE_STRIP
:
455 case GL_TRIANGLE_FAN
:
456 valid_enum
= (geom_mode
== GL_TRIANGLES
);
463 case GL_LINES_ADJACENCY
:
464 case GL_LINE_STRIP_ADJACENCY
:
465 valid_enum
= (geom_mode
== GL_LINES_ADJACENCY
);
467 case GL_TRIANGLES_ADJACENCY
:
468 case GL_TRIANGLE_STRIP_ADJACENCY
:
469 valid_enum
= (geom_mode
== GL_TRIANGLES_ADJACENCY
);
476 _mesa_error(ctx
, GL_INVALID_OPERATION
,
477 "%s(mode=%s vs geometry shader input %s)",
479 _mesa_lookup_prim_by_nr(mode_before_gs
),
480 _mesa_lookup_prim_by_nr(geom_mode
));
485 /* From the OpenGL 4.0 (Core Profile) spec (section 2.12):
487 * "Tessellation operates only on patch primitives. If tessellation is
488 * active, any command that transfers vertices to the GL will
489 * generate an INVALID_OPERATION error if the primitive mode is not
491 * Patch primitives are not supported by pipeline stages below the
492 * tessellation evaluation shader. If there is no active program
493 * object or the active program object does not contain a tessellation
494 * evaluation shader, the error INVALID_OPERATION is generated by any
495 * command that transfers vertices to the GL if the primitive mode is
499 if (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
] ||
500 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_CTRL
]) {
501 if (mode
!= GL_PATCHES
) {
502 _mesa_error(ctx
, GL_INVALID_OPERATION
,
503 "only GL_PATCHES valid with tessellation");
508 if (mode
== GL_PATCHES
) {
509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
510 "GL_PATCHES only valid with tessellation");
515 /* From the GL_EXT_transform_feedback spec:
517 * "The error INVALID_OPERATION is generated if Begin, or any command
518 * that performs an explicit Begin, is called when:
520 * * a geometry shader is not active and <mode> does not match the
521 * allowed begin modes for the current transform feedback state as
522 * given by table X.1.
524 * * a geometry shader is active and the output primitive type of the
525 * geometry shader does not match the allowed begin modes for the
526 * current transform feedback state as given by table X.1.
529 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
530 GLboolean pass
= GL_TRUE
;
532 if(ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]) {
533 switch (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_GEOMETRY
]->
534 info
.gs
.output_primitive
) {
536 pass
= ctx
->TransformFeedback
.Mode
== GL_POINTS
;
539 pass
= ctx
->TransformFeedback
.Mode
== GL_LINES
;
541 case GL_TRIANGLE_STRIP
:
542 pass
= ctx
->TransformFeedback
.Mode
== GL_TRIANGLES
;
548 else if (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
]) {
549 struct gl_program
*tes
=
550 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_TESS_EVAL
];
551 if (tes
->info
.tess
.point_mode
)
552 pass
= ctx
->TransformFeedback
.Mode
== GL_POINTS
;
553 else if (tes
->info
.tess
.primitive_mode
== GL_ISOLINES
)
554 pass
= ctx
->TransformFeedback
.Mode
== GL_LINES
;
556 pass
= ctx
->TransformFeedback
.Mode
== GL_TRIANGLES
;
561 pass
= ctx
->TransformFeedback
.Mode
== GL_POINTS
;
566 pass
= ctx
->TransformFeedback
.Mode
== GL_LINES
;
569 pass
= ctx
->TransformFeedback
.Mode
== GL_TRIANGLES
;
574 _mesa_error(ctx
, GL_INVALID_OPERATION
,
575 "%s(mode=%s vs transform feedback %s)",
577 _mesa_lookup_prim_by_nr(mode
),
578 _mesa_lookup_prim_by_nr(ctx
->TransformFeedback
.Mode
));
583 /* From GL_INTEL_conservative_rasterization spec:
585 * The conservative rasterization option applies only to polygons with
586 * PolygonMode state set to FILL. Draw requests for polygons with different
587 * PolygonMode setting or for other primitive types (points/lines) generate
588 * INVALID_OPERATION error.
590 if (ctx
->IntelConservativeRasterization
) {
591 GLboolean pass
= GL_TRUE
;
598 case GL_LINES_ADJACENCY
:
599 case GL_LINE_STRIP_ADJACENCY
:
603 case GL_TRIANGLE_STRIP
:
604 case GL_TRIANGLE_FAN
:
608 case GL_TRIANGLES_ADJACENCY
:
609 case GL_TRIANGLE_STRIP_ADJACENCY
:
610 if (ctx
->Polygon
.FrontMode
!= GL_FILL
||
611 ctx
->Polygon
.BackMode
!= GL_FILL
)
618 _mesa_error(ctx
, GL_INVALID_OPERATION
,
619 "mode=%s invalid with GL_INTEL_conservative_rasterization",
620 _mesa_lookup_prim_by_nr(mode
));
629 * Verify that the element type is valid.
631 * Generates \c GL_INVALID_ENUM and returns \c false if it is not.
634 valid_elements_type(struct gl_context
*ctx
, GLenum type
, const char *name
)
637 case GL_UNSIGNED_BYTE
:
638 case GL_UNSIGNED_SHORT
:
639 case GL_UNSIGNED_INT
:
643 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(type = %s)", name
,
644 _mesa_enum_to_string(type
));
650 validate_DrawElements_common(struct gl_context
*ctx
,
651 GLenum mode
, GLsizei count
, GLenum type
,
652 const GLvoid
*indices
,
655 /* Section 2.14.2 (Transform Feedback Primitive Capture) of the OpenGL ES
658 * The error INVALID_OPERATION is also generated by DrawElements,
659 * DrawElementsInstanced, and DrawRangeElements while transform feedback
660 * is active and not paused, regardless of mode.
662 * The OES_geometry_shader_spec says:
668 * (13) Does this extension change how transform feedback operates
669 * compared to unextended OpenGL ES 3.0 or 3.1?
671 * RESOLVED: Yes... Since we no longer require being able to predict how
672 * much geometry will be generated, we also lift the restriction that
673 * only DrawArray* commands are supported and also support the
674 * DrawElements* commands for transform feedback.
676 * This should also be reflected in the body of the spec, but that appears
677 * to have been overlooked. The body of the spec only explicitly allows
678 * the indirect versions.
680 if (_mesa_is_gles3(ctx
) &&
681 !_mesa_has_OES_geometry_shader(ctx
) &&
682 _mesa_is_xfb_active_and_unpaused(ctx
)) {
683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
684 "%s(transform feedback active)", caller
);
689 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(count)", caller
);
693 if (!_mesa_valid_prim_mode(ctx
, mode
, caller
)) {
697 if (!valid_elements_type(ctx
, type
, caller
))
700 if (!check_valid_to_render(ctx
, caller
))
703 /* Not using a VBO for indices, so avoid NULL pointer derefs later.
705 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
) && indices
== NULL
)
715 * Error checking for glDrawElements(). Includes parameter checking
716 * and VBO bounds checking.
717 * \return GL_TRUE if OK to render, GL_FALSE if error found
720 _mesa_validate_DrawElements(struct gl_context
*ctx
,
721 GLenum mode
, GLsizei count
, GLenum type
,
722 const GLvoid
*indices
)
724 FLUSH_CURRENT(ctx
, 0);
726 return validate_DrawElements_common(ctx
, mode
, count
, type
, indices
,
732 * Error checking for glMultiDrawElements(). Includes parameter checking
733 * and VBO bounds checking.
734 * \return GL_TRUE if OK to render, GL_FALSE if error found
737 _mesa_validate_MultiDrawElements(struct gl_context
*ctx
,
738 GLenum mode
, const GLsizei
*count
,
739 GLenum type
, const GLvoid
* const *indices
,
744 FLUSH_CURRENT(ctx
, 0);
747 * Section 2.3.1 (Errors) of the OpenGL 4.5 (Core Profile) spec says:
749 * "If a negative number is provided where an argument of type sizei or
750 * sizeiptr is specified, an INVALID_VALUE error is generated."
752 * and in the same section:
754 * "In other cases, there are no side effects unless otherwise noted;
755 * the command which generates the error is ignored so that it has no
756 * effect on GL state or framebuffer contents."
758 * Hence, check both primcount and all the count[i].
761 _mesa_error(ctx
, GL_INVALID_VALUE
,
762 "glMultiDrawElements(primcount=%d)", primcount
);
766 for (i
= 0; i
< primcount
; i
++) {
768 _mesa_error(ctx
, GL_INVALID_VALUE
,
769 "glMultiDrawElements(count)" );
774 if (!_mesa_valid_prim_mode(ctx
, mode
, "glMultiDrawElements")) {
778 if (!valid_elements_type(ctx
, type
, "glMultiDrawElements"))
781 if (!check_valid_to_render(ctx
, "glMultiDrawElements"))
784 /* Not using a VBO for indices, so avoid NULL pointer derefs later.
786 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
787 for (i
= 0; i
< primcount
; i
++) {
798 * Error checking for glDrawRangeElements(). Includes parameter checking
799 * and VBO bounds checking.
800 * \return GL_TRUE if OK to render, GL_FALSE if error found
803 _mesa_validate_DrawRangeElements(struct gl_context
*ctx
, GLenum mode
,
804 GLuint start
, GLuint end
,
805 GLsizei count
, GLenum type
,
806 const GLvoid
*indices
)
808 FLUSH_CURRENT(ctx
, 0);
811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawRangeElements(end<start)");
815 return validate_DrawElements_common(ctx
, mode
, count
, type
, indices
,
816 "glDrawRangeElements");
820 validate_draw_arrays(struct gl_context
*ctx
, const char *func
,
821 GLenum mode
, GLsizei count
, GLsizei numInstances
)
823 struct gl_transform_feedback_object
*xfb_obj
824 = ctx
->TransformFeedback
.CurrentObject
;
825 FLUSH_CURRENT(ctx
, 0);
828 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(count)", func
);
832 if (!_mesa_valid_prim_mode(ctx
, mode
, func
))
835 if (!check_valid_to_render(ctx
, func
))
838 /* From the GLES3 specification, section 2.14.2 (Transform Feedback
839 * Primitive Capture):
841 * The error INVALID_OPERATION is generated by DrawArrays and
842 * DrawArraysInstanced if recording the vertices of a primitive to the
843 * buffer objects being used for transform feedback purposes would result
844 * in either exceeding the limits of any buffer object’s size, or in
845 * exceeding the end position offset + size − 1, as set by
848 * This is in contrast to the behaviour of desktop GL, where the extra
849 * primitives are silently dropped from the transform feedback buffer.
851 * This text is removed in ES 3.2, presumably because it's not really
852 * implementable with geometry and tessellation shaders. In fact,
853 * the OES_geometry_shader spec says:
855 * "(13) Does this extension change how transform feedback operates
856 * compared to unextended OpenGL ES 3.0 or 3.1?
858 * RESOLVED: Yes. Because dynamic geometry amplification in a geometry
859 * shader can make it difficult if not impossible to predict the amount
860 * of geometry that may be generated in advance of executing the shader,
861 * the draw-time error for transform feedback buffer overflow conditions
862 * is removed and replaced with the GL behavior (primitives are not
863 * written and the corresponding counter is not updated)..."
865 if (_mesa_is_gles3(ctx
) && _mesa_is_xfb_active_and_unpaused(ctx
) &&
866 !_mesa_has_OES_geometry_shader(ctx
) &&
867 !_mesa_has_OES_tessellation_shader(ctx
)) {
868 size_t prim_count
= vbo_count_tessellated_primitives(mode
, count
, 1);
869 if (xfb_obj
->GlesRemainingPrims
< prim_count
) {
870 _mesa_error(ctx
, GL_INVALID_OPERATION
,
871 "%s(exceeds transform feedback size)", func
);
874 xfb_obj
->GlesRemainingPrims
-= prim_count
;
884 * Called from the tnl module to error check the function parameters and
885 * verify that we really can draw something.
886 * \return GL_TRUE if OK to render, GL_FALSE if error found
889 _mesa_validate_DrawArrays(struct gl_context
*ctx
, GLenum mode
, GLsizei count
)
891 return validate_draw_arrays(ctx
, "glDrawArrays", mode
, count
, 1);
896 _mesa_validate_DrawArraysInstanced(struct gl_context
*ctx
, GLenum mode
, GLint first
,
897 GLsizei count
, GLsizei numInstances
)
900 _mesa_error(ctx
, GL_INVALID_VALUE
,
901 "glDrawArraysInstanced(start=%d)", first
);
905 if (numInstances
<= 0) {
906 if (numInstances
< 0)
907 _mesa_error(ctx
, GL_INVALID_VALUE
,
908 "glDrawArraysInstanced(numInstances=%d)", numInstances
);
912 return validate_draw_arrays(ctx
, "glDrawArraysInstanced", mode
, count
, 1);
917 _mesa_validate_DrawElementsInstanced(struct gl_context
*ctx
,
918 GLenum mode
, GLsizei count
, GLenum type
,
919 const GLvoid
*indices
, GLsizei numInstances
)
921 FLUSH_CURRENT(ctx
, 0);
923 if (numInstances
< 0) {
924 _mesa_error(ctx
, GL_INVALID_VALUE
,
925 "glDrawElementsInstanced(numInstances=%d)", numInstances
);
929 return validate_DrawElements_common(ctx
, mode
, count
, type
, indices
,
930 "glDrawElementsInstanced")
931 && (numInstances
> 0);
936 _mesa_validate_DrawTransformFeedback(struct gl_context
*ctx
,
938 struct gl_transform_feedback_object
*obj
,
940 GLsizei numInstances
)
942 FLUSH_CURRENT(ctx
, 0);
944 if (!_mesa_valid_prim_mode(ctx
, mode
, "glDrawTransformFeedback*(mode)")) {
949 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawTransformFeedback*(name)");
953 /* From the GL 4.5 specification, page 429:
954 * "An INVALID_VALUE error is generated if id is not the name of a
955 * transform feedback object."
957 if (!obj
->EverBound
) {
958 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDrawTransformFeedback*(name)");
962 if (stream
>= ctx
->Const
.MaxVertexStreams
) {
963 _mesa_error(ctx
, GL_INVALID_VALUE
,
964 "glDrawTransformFeedbackStream*(index>=MaxVertexStream)");
968 if (!obj
->EndedAnytime
) {
969 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glDrawTransformFeedback*");
973 if (numInstances
<= 0) {
974 if (numInstances
< 0)
975 _mesa_error(ctx
, GL_INVALID_VALUE
,
976 "glDrawTransformFeedback*Instanced(numInstances=%d)",
981 if (!check_valid_to_render(ctx
, "glDrawTransformFeedback*")) {
989 valid_draw_indirect(struct gl_context
*ctx
,
990 GLenum mode
, const GLvoid
*indirect
,
991 GLsizei size
, const char *name
)
993 const uint64_t end
= (uint64_t) (uintptr_t) indirect
+ size
;
995 /* OpenGL ES 3.1 spec. section 10.5:
997 * "DrawArraysIndirect requires that all data sourced for the
998 * command, including the DrawArraysIndirectCommand
999 * structure, be in buffer objects, and may not be called when
1000 * the default vertex array object is bound."
1002 if (ctx
->Array
.VAO
== ctx
->Array
.DefaultVAO
) {
1003 _mesa_error(ctx
, GL_INVALID_OPERATION
, "(no VAO bound)");
1007 /* From OpenGL ES 3.1 spec. section 10.5:
1008 * "An INVALID_OPERATION error is generated if zero is bound to
1009 * VERTEX_ARRAY_BINDING, DRAW_INDIRECT_BUFFER or to any enabled
1012 * Here we check that for each enabled vertex array we have a vertex
1015 if (_mesa_is_gles31(ctx
) &&
1016 ctx
->Array
.VAO
->_Enabled
& ~ctx
->Array
.VAO
->VertexAttribBufferMask
) {
1017 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(No VBO bound)", name
);
1021 if (!_mesa_valid_prim_mode(ctx
, mode
, name
))
1024 /* OpenGL ES 3.1 specification, section 10.5:
1026 * "An INVALID_OPERATION error is generated if
1027 * transform feedback is active and not paused."
1029 * The OES_geometry_shader spec says:
1031 * On p. 250 in the errors section for the DrawArraysIndirect command,
1032 * and on p. 254 in the errors section for the DrawElementsIndirect
1033 * command, delete the errors which state:
1035 * "An INVALID_OPERATION error is generated if transform feedback is
1036 * active and not paused."
1038 * (thus allowing transform feedback to work with indirect draw commands).
1040 if (_mesa_is_gles31(ctx
) && !ctx
->Extensions
.OES_geometry_shader
&&
1041 _mesa_is_xfb_active_and_unpaused(ctx
)) {
1042 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1043 "%s(TransformFeedback is active and not paused)", name
);
1046 /* From OpenGL version 4.4. section 10.5
1047 * and OpenGL ES 3.1, section 10.6:
1049 * "An INVALID_VALUE error is generated if indirect is not a
1050 * multiple of the size, in basic machine units, of uint."
1052 if ((GLsizeiptr
)indirect
& (sizeof(GLuint
) - 1)) {
1053 _mesa_error(ctx
, GL_INVALID_VALUE
,
1054 "%s(indirect is not aligned)", name
);
1058 if (!_mesa_is_bufferobj(ctx
->DrawIndirectBuffer
)) {
1059 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1060 "%s: no buffer bound to DRAW_INDIRECT_BUFFER", name
);
1064 if (_mesa_check_disallowed_mapping(ctx
->DrawIndirectBuffer
)) {
1065 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1066 "%s(DRAW_INDIRECT_BUFFER is mapped)", name
);
1070 /* From the ARB_draw_indirect specification:
1071 * "An INVALID_OPERATION error is generated if the commands source data
1072 * beyond the end of the buffer object [...]"
1074 if (ctx
->DrawIndirectBuffer
->Size
< end
) {
1075 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1076 "%s(DRAW_INDIRECT_BUFFER too small)", name
);
1080 if (!check_valid_to_render(ctx
, name
))
1086 static inline GLboolean
1087 valid_draw_indirect_elements(struct gl_context
*ctx
,
1088 GLenum mode
, GLenum type
, const GLvoid
*indirect
,
1089 GLsizeiptr size
, const char *name
)
1091 if (!valid_elements_type(ctx
, type
, name
))
1095 * Unlike regular DrawElementsInstancedBaseVertex commands, the indices
1096 * may not come from a client array and must come from an index buffer.
1097 * If no element array buffer is bound, an INVALID_OPERATION error is
1100 if (!_mesa_is_bufferobj(ctx
->Array
.VAO
->IndexBufferObj
)) {
1101 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1102 "%s(no buffer bound to GL_ELEMENT_ARRAY_BUFFER)", name
);
1106 return valid_draw_indirect(ctx
, mode
, indirect
, size
, name
);
1109 static inline GLboolean
1110 valid_draw_indirect_multi(struct gl_context
*ctx
,
1111 GLsizei primcount
, GLsizei stride
,
1115 /* From the ARB_multi_draw_indirect specification:
1116 * "INVALID_VALUE is generated by MultiDrawArraysIndirect or
1117 * MultiDrawElementsIndirect if <primcount> is negative."
1119 * "<primcount> must be positive, otherwise an INVALID_VALUE error will
1122 if (primcount
< 0) {
1123 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(primcount < 0)", name
);
1128 /* From the ARB_multi_draw_indirect specification:
1129 * "<stride> must be a multiple of four, otherwise an INVALID_VALUE
1130 * error is generated."
1133 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(stride %% 4)", name
);
1141 _mesa_validate_DrawArraysIndirect(struct gl_context
*ctx
,
1143 const GLvoid
*indirect
)
1145 const unsigned drawArraysNumParams
= 4;
1147 FLUSH_CURRENT(ctx
, 0);
1149 return valid_draw_indirect(ctx
, mode
,
1150 indirect
, drawArraysNumParams
* sizeof(GLuint
),
1151 "glDrawArraysIndirect");
1155 _mesa_validate_DrawElementsIndirect(struct gl_context
*ctx
,
1156 GLenum mode
, GLenum type
,
1157 const GLvoid
*indirect
)
1159 const unsigned drawElementsNumParams
= 5;
1161 FLUSH_CURRENT(ctx
, 0);
1163 return valid_draw_indirect_elements(ctx
, mode
, type
,
1164 indirect
, drawElementsNumParams
* sizeof(GLuint
),
1165 "glDrawElementsIndirect");
1169 _mesa_validate_MultiDrawArraysIndirect(struct gl_context
*ctx
,
1171 const GLvoid
*indirect
,
1172 GLsizei primcount
, GLsizei stride
)
1174 GLsizeiptr size
= 0;
1175 const unsigned drawArraysNumParams
= 4;
1177 FLUSH_CURRENT(ctx
, 0);
1179 /* caller has converted stride==0 to drawArraysNumParams * sizeof(GLuint) */
1180 assert(stride
!= 0);
1182 if (!valid_draw_indirect_multi(ctx
, primcount
, stride
,
1183 "glMultiDrawArraysIndirect"))
1186 /* number of bytes of the indirect buffer which will be read */
1188 ? (primcount
- 1) * stride
+ drawArraysNumParams
* sizeof(GLuint
)
1191 if (!valid_draw_indirect(ctx
, mode
, indirect
, size
,
1192 "glMultiDrawArraysIndirect"))
1199 _mesa_validate_MultiDrawElementsIndirect(struct gl_context
*ctx
,
1200 GLenum mode
, GLenum type
,
1201 const GLvoid
*indirect
,
1202 GLsizei primcount
, GLsizei stride
)
1204 GLsizeiptr size
= 0;
1205 const unsigned drawElementsNumParams
= 5;
1207 FLUSH_CURRENT(ctx
, 0);
1209 /* caller has converted stride==0 to drawElementsNumParams * sizeof(GLuint) */
1210 assert(stride
!= 0);
1212 if (!valid_draw_indirect_multi(ctx
, primcount
, stride
,
1213 "glMultiDrawElementsIndirect"))
1216 /* number of bytes of the indirect buffer which will be read */
1218 ? (primcount
- 1) * stride
+ drawElementsNumParams
* sizeof(GLuint
)
1221 if (!valid_draw_indirect_elements(ctx
, mode
, type
,
1223 "glMultiDrawElementsIndirect"))
1230 valid_draw_indirect_parameters(struct gl_context
*ctx
,
1234 /* From the ARB_indirect_parameters specification:
1235 * "INVALID_VALUE is generated by MultiDrawArraysIndirectCountARB or
1236 * MultiDrawElementsIndirectCountARB if <drawcount> is not a multiple of
1239 if (drawcount
& 3) {
1240 _mesa_error(ctx
, GL_INVALID_VALUE
,
1241 "%s(drawcount is not a multiple of 4)", name
);
1245 /* From the ARB_indirect_parameters specification:
1246 * "INVALID_OPERATION is generated by MultiDrawArraysIndirectCountARB or
1247 * MultiDrawElementsIndirectCountARB if no buffer is bound to the
1248 * PARAMETER_BUFFER_ARB binding point."
1250 if (!_mesa_is_bufferobj(ctx
->ParameterBuffer
)) {
1251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1252 "%s: no buffer bound to PARAMETER_BUFFER", name
);
1256 if (_mesa_check_disallowed_mapping(ctx
->ParameterBuffer
)) {
1257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1258 "%s(PARAMETER_BUFFER is mapped)", name
);
1262 /* From the ARB_indirect_parameters specification:
1263 * "INVALID_OPERATION is generated by MultiDrawArraysIndirectCountARB or
1264 * MultiDrawElementsIndirectCountARB if reading a <sizei> typed value
1265 * from the buffer bound to the PARAMETER_BUFFER_ARB target at the offset
1266 * specified by <drawcount> would result in an out-of-bounds access."
1268 if (ctx
->ParameterBuffer
->Size
< drawcount
+ sizeof(GLsizei
)) {
1269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1270 "%s(PARAMETER_BUFFER too small)", name
);
1278 _mesa_validate_MultiDrawArraysIndirectCount(struct gl_context
*ctx
,
1282 GLsizei maxdrawcount
,
1285 GLsizeiptr size
= 0;
1286 const unsigned drawArraysNumParams
= 4;
1288 FLUSH_CURRENT(ctx
, 0);
1290 /* caller has converted stride==0 to drawArraysNumParams * sizeof(GLuint) */
1291 assert(stride
!= 0);
1293 if (!valid_draw_indirect_multi(ctx
, maxdrawcount
, stride
,
1294 "glMultiDrawArraysIndirectCountARB"))
1297 /* number of bytes of the indirect buffer which will be read */
1299 ? (maxdrawcount
- 1) * stride
+ drawArraysNumParams
* sizeof(GLuint
)
1302 if (!valid_draw_indirect(ctx
, mode
, (void *)indirect
, size
,
1303 "glMultiDrawArraysIndirectCountARB"))
1306 return valid_draw_indirect_parameters(
1307 ctx
, "glMultiDrawArraysIndirectCountARB", drawcount
);
1311 _mesa_validate_MultiDrawElementsIndirectCount(struct gl_context
*ctx
,
1312 GLenum mode
, GLenum type
,
1315 GLsizei maxdrawcount
,
1318 GLsizeiptr size
= 0;
1319 const unsigned drawElementsNumParams
= 5;
1321 FLUSH_CURRENT(ctx
, 0);
1323 /* caller has converted stride==0 to drawElementsNumParams * sizeof(GLuint) */
1324 assert(stride
!= 0);
1326 if (!valid_draw_indirect_multi(ctx
, maxdrawcount
, stride
,
1327 "glMultiDrawElementsIndirectCountARB"))
1330 /* number of bytes of the indirect buffer which will be read */
1332 ? (maxdrawcount
- 1) * stride
+ drawElementsNumParams
* sizeof(GLuint
)
1335 if (!valid_draw_indirect_elements(ctx
, mode
, type
,
1336 (void *)indirect
, size
,
1337 "glMultiDrawElementsIndirectCountARB"))
1340 return valid_draw_indirect_parameters(
1341 ctx
, "glMultiDrawElementsIndirectCountARB", drawcount
);
1345 check_valid_to_compute(struct gl_context
*ctx
, const char *function
)
1347 if (!_mesa_has_compute_shaders(ctx
)) {
1348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1349 "unsupported function (%s) called",
1354 /* From the OpenGL 4.3 Core Specification, Chapter 19, Compute Shaders:
1356 * "An INVALID_OPERATION error is generated if there is no active program
1357 * for the compute shader stage."
1359 if (ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
] == NULL
) {
1360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1361 "%s(no active compute shader)",
1370 _mesa_validate_DispatchCompute(struct gl_context
*ctx
,
1371 const GLuint
*num_groups
)
1374 FLUSH_CURRENT(ctx
, 0);
1376 if (!check_valid_to_compute(ctx
, "glDispatchCompute"))
1379 for (i
= 0; i
< 3; i
++) {
1380 /* From the OpenGL 4.3 Core Specification, Chapter 19, Compute Shaders:
1382 * "An INVALID_VALUE error is generated if any of num_groups_x,
1383 * num_groups_y and num_groups_z are greater than or equal to the
1384 * maximum work group count for the corresponding dimension."
1386 * However, the "or equal to" portions appears to be a specification
1387 * bug. In all other areas, the specification appears to indicate that
1388 * the number of workgroups can match the MAX_COMPUTE_WORK_GROUP_COUNT
1389 * value. For example, under DispatchComputeIndirect:
1391 * "If any of num_groups_x, num_groups_y or num_groups_z is greater than
1392 * the value of MAX_COMPUTE_WORK_GROUP_COUNT for the corresponding
1393 * dimension then the results are undefined."
1395 * Additionally, the OpenGLES 3.1 specification does not contain "or
1396 * equal to" as an error condition.
1398 if (num_groups
[i
] > ctx
->Const
.MaxComputeWorkGroupCount
[i
]) {
1399 _mesa_error(ctx
, GL_INVALID_VALUE
,
1400 "glDispatchCompute(num_groups_%c)", 'x' + i
);
1405 /* The ARB_compute_variable_group_size spec says:
1407 * "An INVALID_OPERATION error is generated by DispatchCompute if the active
1408 * program for the compute shader stage has a variable work group size."
1410 struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
1411 if (prog
->info
.cs
.local_size_variable
) {
1412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1413 "glDispatchCompute(variable work group size forbidden)");
1421 _mesa_validate_DispatchComputeGroupSizeARB(struct gl_context
*ctx
,
1422 const GLuint
*num_groups
,
1423 const GLuint
*group_size
)
1425 GLuint total_invocations
= 1;
1428 FLUSH_CURRENT(ctx
, 0);
1430 if (!check_valid_to_compute(ctx
, "glDispatchComputeGroupSizeARB"))
1433 /* The ARB_compute_variable_group_size spec says:
1435 * "An INVALID_OPERATION error is generated by
1436 * DispatchComputeGroupSizeARB if the active program for the compute
1437 * shader stage has a fixed work group size."
1439 struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
1440 if (!prog
->info
.cs
.local_size_variable
) {
1441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1442 "glDispatchComputeGroupSizeARB(fixed work group size "
1447 for (i
= 0; i
< 3; i
++) {
1448 /* The ARB_compute_variable_group_size spec says:
1450 * "An INVALID_VALUE error is generated if any of num_groups_x,
1451 * num_groups_y and num_groups_z are greater than or equal to the
1452 * maximum work group count for the corresponding dimension."
1454 if (num_groups
[i
] > ctx
->Const
.MaxComputeWorkGroupCount
[i
]) {
1455 _mesa_error(ctx
, GL_INVALID_VALUE
,
1456 "glDispatchComputeGroupSizeARB(num_groups_%c)", 'x' + i
);
1460 /* The ARB_compute_variable_group_size spec says:
1462 * "An INVALID_VALUE error is generated by DispatchComputeGroupSizeARB if
1463 * any of <group_size_x>, <group_size_y>, or <group_size_z> is less than
1464 * or equal to zero or greater than the maximum local work group size
1465 * for compute shaders with variable group size
1466 * (MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB) in the corresponding
1469 * However, the "less than" is a spec bug because they are declared as
1470 * unsigned integers.
1472 if (group_size
[i
] == 0 ||
1473 group_size
[i
] > ctx
->Const
.MaxComputeVariableGroupSize
[i
]) {
1474 _mesa_error(ctx
, GL_INVALID_VALUE
,
1475 "glDispatchComputeGroupSizeARB(group_size_%c)", 'x' + i
);
1479 total_invocations
*= group_size
[i
];
1482 /* The ARB_compute_variable_group_size spec says:
1484 * "An INVALID_VALUE error is generated by DispatchComputeGroupSizeARB if
1485 * the product of <group_size_x>, <group_size_y>, and <group_size_z> exceeds
1486 * the implementation-dependent maximum local work group invocation count
1487 * for compute shaders with variable group size
1488 * (MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB)."
1490 if (total_invocations
> ctx
->Const
.MaxComputeVariableGroupInvocations
) {
1491 _mesa_error(ctx
, GL_INVALID_VALUE
,
1492 "glDispatchComputeGroupSizeARB(product of local_sizes "
1493 "exceeds MAX_COMPUTE_VARIABLE_GROUP_INVOCATIONS_ARB "
1494 "(%d > %d))", total_invocations
,
1495 ctx
->Const
.MaxComputeVariableGroupInvocations
);
1503 valid_dispatch_indirect(struct gl_context
*ctx
,
1505 GLsizei size
, const char *name
)
1507 const uint64_t end
= (uint64_t) indirect
+ size
;
1509 if (!check_valid_to_compute(ctx
, name
))
1512 /* From the OpenGL 4.3 Core Specification, Chapter 19, Compute Shaders:
1514 * "An INVALID_VALUE error is generated if indirect is negative or is not a
1515 * multiple of four."
1517 if (indirect
& (sizeof(GLuint
) - 1)) {
1518 _mesa_error(ctx
, GL_INVALID_VALUE
,
1519 "%s(indirect is not aligned)", name
);
1524 _mesa_error(ctx
, GL_INVALID_VALUE
,
1525 "%s(indirect is less than zero)", name
);
1529 /* From the OpenGL 4.3 Core Specification, Chapter 19, Compute Shaders:
1531 * "An INVALID_OPERATION error is generated if no buffer is bound to the
1532 * DRAW_INDIRECT_BUFFER binding, or if the command would source data
1533 * beyond the end of the buffer object."
1535 if (!_mesa_is_bufferobj(ctx
->DispatchIndirectBuffer
)) {
1536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1537 "%s: no buffer bound to DISPATCH_INDIRECT_BUFFER", name
);
1541 if (_mesa_check_disallowed_mapping(ctx
->DispatchIndirectBuffer
)) {
1542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1543 "%s(DISPATCH_INDIRECT_BUFFER is mapped)", name
);
1547 if (ctx
->DispatchIndirectBuffer
->Size
< end
) {
1548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1549 "%s(DISPATCH_INDIRECT_BUFFER too small)", name
);
1553 /* The ARB_compute_variable_group_size spec says:
1555 * "An INVALID_OPERATION error is generated if the active program for the
1556 * compute shader stage has a variable work group size."
1558 struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[MESA_SHADER_COMPUTE
];
1559 if (prog
->info
.cs
.local_size_variable
) {
1560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1561 "%s(variable work group size forbidden)", name
);
1569 _mesa_validate_DispatchComputeIndirect(struct gl_context
*ctx
,
1572 FLUSH_CURRENT(ctx
, 0);
1574 return valid_dispatch_indirect(ctx
, indirect
, 3 * sizeof(GLuint
),
1575 "glDispatchComputeIndirect");