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.
33 #include "main/dispatch.h"
37 * Allocate a new query object. This is a fallback routine called via
38 * ctx->Driver.NewQueryObject().
39 * \param ctx - rendering context
40 * \param id - the new object's ID
41 * \return pointer to new query_object object or NULL if out of memory.
43 static struct gl_query_object
*
44 _mesa_new_query_object(struct gl_context
*ctx
, GLuint id
)
46 struct gl_query_object
*q
= CALLOC_STRUCT(gl_query_object
);
53 /* This is to satisfy the language of the specification: "In the initial
54 * state of a query object, the result is available" (OpenGL 3.1 §
59 /* OpenGL 3.1 § 2.13 says about GenQueries, "These names are marked as
60 * used, but no object is associated with them until the first time they
61 * are used by BeginQuery." Since our implementation actually does
62 * allocate an object at this point, use a flag to indicate that this
63 * object has not yet been bound so should not be considered a query.
65 q
->EverBound
= GL_FALSE
;
72 * Begin a query. Software driver fallback.
73 * Called via ctx->Driver.BeginQuery().
76 _mesa_begin_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
78 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
83 * End a query. Software driver fallback.
84 * Called via ctx->Driver.EndQuery().
87 _mesa_end_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
89 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
95 * Wait for query to complete. Software driver fallback.
96 * Called via ctx->Driver.WaitQuery().
99 _mesa_wait_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
101 /* For software drivers, _mesa_end_query() should have completed the query.
102 * For real hardware, implement a proper WaitQuery() driver function,
103 * which may require issuing a flush.
110 * Check if a query results are ready. Software driver fallback.
111 * Called via ctx->Driver.CheckQuery().
114 _mesa_check_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
116 /* No-op for sw rendering.
117 * HW drivers may need to flush at this time.
123 * Delete a query object. Called via ctx->Driver.DeleteQuery().
124 * Not removed from hash table here.
127 _mesa_delete_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
135 _mesa_init_query_object_functions(struct dd_function_table
*driver
)
137 driver
->NewQueryObject
= _mesa_new_query_object
;
138 driver
->DeleteQuery
= _mesa_delete_query
;
139 driver
->BeginQuery
= _mesa_begin_query
;
140 driver
->EndQuery
= _mesa_end_query
;
141 driver
->WaitQuery
= _mesa_wait_query
;
142 driver
->CheckQuery
= _mesa_check_query
;
145 static struct gl_query_object
**
146 get_pipe_stats_binding_point(struct gl_context
*ctx
,
149 const int which
= target
- GL_VERTICES_SUBMITTED_ARB
;
150 assert(which
< MAX_PIPELINE_STATISTICS
);
152 if (!_mesa_is_desktop_gl(ctx
) ||
153 !ctx
->Extensions
.ARB_pipeline_statistics_query
)
156 return &ctx
->Query
.pipeline_stats
[which
];
160 * Return pointer to the query object binding point for the given target and
162 * \return NULL if invalid target, else the address of binding point
164 static struct gl_query_object
**
165 get_query_binding_point(struct gl_context
*ctx
, GLenum target
, GLuint index
)
168 case GL_SAMPLES_PASSED_ARB
:
169 if (ctx
->Extensions
.ARB_occlusion_query
)
170 return &ctx
->Query
.CurrentOcclusionObject
;
173 case GL_ANY_SAMPLES_PASSED
:
174 if (ctx
->Extensions
.ARB_occlusion_query2
)
175 return &ctx
->Query
.CurrentOcclusionObject
;
178 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
179 if (ctx
->Extensions
.ARB_ES3_compatibility
180 || (ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30))
181 return &ctx
->Query
.CurrentOcclusionObject
;
184 case GL_TIME_ELAPSED_EXT
:
185 if (ctx
->Extensions
.EXT_timer_query
)
186 return &ctx
->Query
.CurrentTimerObject
;
189 case GL_PRIMITIVES_GENERATED
:
190 if (ctx
->Extensions
.EXT_transform_feedback
)
191 return &ctx
->Query
.PrimitivesGenerated
[index
];
194 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
195 if (ctx
->Extensions
.EXT_transform_feedback
)
196 return &ctx
->Query
.PrimitivesWritten
[index
];
200 case GL_VERTICES_SUBMITTED_ARB
:
201 case GL_PRIMITIVES_SUBMITTED_ARB
:
202 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
203 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
204 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
205 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
206 return get_pipe_stats_binding_point(ctx
, target
);
208 case GL_GEOMETRY_SHADER_INVOCATIONS
:
209 /* GL_GEOMETRY_SHADER_INVOCATIONS is defined in a non-sequential order */
210 target
= GL_VERTICES_SUBMITTED_ARB
+ MAX_PIPELINE_STATISTICS
- 1;
212 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
213 if (_mesa_has_geometry_shaders(ctx
))
214 return get_pipe_stats_binding_point(ctx
, target
);
218 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
219 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
220 if (ctx
->Extensions
.ARB_tessellation_shader
)
221 return get_pipe_stats_binding_point(ctx
, target
);
225 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
226 if (_mesa_has_compute_shaders(ctx
))
227 return get_pipe_stats_binding_point(ctx
, target
);
237 * Create $n query objects and store them in *ids. Make them of type $target
238 * if dsa is set. Called from _mesa_GenQueries() and _mesa_CreateQueries().
241 create_queries(struct gl_context
*ctx
, GLenum target
, GLsizei n
, GLuint
*ids
,
244 const char *func
= dsa
? "glGenQueries" : "glCreateQueries";
247 if (MESA_VERBOSE
& VERBOSE_API
)
248 _mesa_debug(ctx
, "%s(%d)\n", func
, n
);
251 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
255 first
= _mesa_HashFindFreeKeyBlock(ctx
->Query
.QueryObjects
, n
);
258 for (i
= 0; i
< n
; i
++) {
259 struct gl_query_object
*q
260 = ctx
->Driver
.NewQueryObject(ctx
, first
+ i
);
262 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
265 /* Do the equivalent of binding the buffer with a target */
267 q
->EverBound
= GL_TRUE
;
270 _mesa_HashInsert(ctx
->Query
.QueryObjects
, first
+ i
, q
);
276 _mesa_GenQueries(GLsizei n
, GLuint
*ids
)
278 GET_CURRENT_CONTEXT(ctx
);
279 create_queries(ctx
, 0, n
, ids
, false);
283 _mesa_CreateQueries(GLenum target
, GLsizei n
, GLuint
*ids
)
285 GET_CURRENT_CONTEXT(ctx
);
288 case GL_SAMPLES_PASSED
:
289 case GL_ANY_SAMPLES_PASSED
:
290 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
291 case GL_TIME_ELAPSED
:
293 case GL_PRIMITIVES_GENERATED
:
294 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
297 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCreateQueries(invalid target = %s)",
298 _mesa_enum_to_string(target
));
302 create_queries(ctx
, target
, n
, ids
, true);
307 _mesa_DeleteQueries(GLsizei n
, const GLuint
*ids
)
310 GET_CURRENT_CONTEXT(ctx
);
311 FLUSH_VERTICES(ctx
, 0);
313 if (MESA_VERBOSE
& VERBOSE_API
)
314 _mesa_debug(ctx
, "glDeleteQueries(%d)\n", n
);
317 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteQueriesARB(n < 0)");
321 for (i
= 0; i
< n
; i
++) {
323 struct gl_query_object
*q
= _mesa_lookup_query_object(ctx
, ids
[i
]);
326 struct gl_query_object
**bindpt
;
327 bindpt
= get_query_binding_point(ctx
, q
->Target
, q
->Stream
);
328 assert(bindpt
); /* Should be non-null for active q. */
332 q
->Active
= GL_FALSE
;
333 ctx
->Driver
.EndQuery(ctx
, q
);
335 _mesa_HashRemove(ctx
->Query
.QueryObjects
, ids
[i
]);
336 ctx
->Driver
.DeleteQuery(ctx
, q
);
344 _mesa_IsQuery(GLuint id
)
346 struct gl_query_object
*q
;
348 GET_CURRENT_CONTEXT(ctx
);
349 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
351 if (MESA_VERBOSE
& VERBOSE_API
)
352 _mesa_debug(ctx
, "glIsQuery(%u)\n", id
);
357 q
= _mesa_lookup_query_object(ctx
, id
);
365 query_error_check_index(struct gl_context
*ctx
, GLenum target
, GLuint index
)
368 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
369 case GL_PRIMITIVES_GENERATED
:
370 if (index
>= ctx
->Const
.MaxVertexStreams
) {
371 _mesa_error(ctx
, GL_INVALID_VALUE
,
372 "glBeginQueryIndexed(index>=MaxVertexStreams)");
378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBeginQueryIndexed(index>0)");
386 _mesa_BeginQueryIndexed(GLenum target
, GLuint index
, GLuint id
)
388 struct gl_query_object
*q
, **bindpt
;
389 GET_CURRENT_CONTEXT(ctx
);
391 if (MESA_VERBOSE
& VERBOSE_API
)
392 _mesa_debug(ctx
, "glBeginQueryIndexed(%s, %u, %u)\n",
393 _mesa_enum_to_string(target
), index
, id
);
395 if (!query_error_check_index(ctx
, target
, index
))
398 FLUSH_VERTICES(ctx
, 0);
400 bindpt
= get_query_binding_point(ctx
, target
, index
);
402 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginQuery{Indexed}(target)");
406 /* From the GL_ARB_occlusion_query spec:
408 * "If BeginQueryARB is called while another query is already in
409 * progress with the same target, an INVALID_OPERATION error is
413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
414 "glBeginQuery{Indexed}(target=%s is active)",
415 _mesa_enum_to_string(target
));
420 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginQuery{Indexed}(id==0)");
424 q
= _mesa_lookup_query_object(ctx
, id
);
426 if (ctx
->API
!= API_OPENGL_COMPAT
) {
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glBeginQuery{Indexed}(non-gen name)");
431 /* create new object */
432 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
434 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBeginQuery{Indexed}");
437 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
441 /* pre-existing object */
443 _mesa_error(ctx
, GL_INVALID_OPERATION
,
444 "glBeginQuery{Indexed}(query already active)");
448 /* Section 2.14 Asynchronous Queries, page 84 of the OpenGL ES 3.0.4
451 * "BeginQuery generates an INVALID_OPERATION error if any of the
452 * following conditions hold: [...] id is the name of an
453 * existing query object whose type does not match target; [...]
455 * Similar wording exists in the OpenGL 4.5 spec, section 4.2. QUERY
456 * OBJECTS AND ASYNCHRONOUS QUERIES, page 43.
458 if (q
->EverBound
&& q
->Target
!= target
) {
459 _mesa_error(ctx
, GL_INVALID_OPERATION
,
460 "glBeginQuery{Indexed}(target mismatch)");
465 /* This possibly changes the target of a buffer allocated by
466 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
469 * "CreateQueries adds a <target>, so strictly speaking the <target>
470 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
471 * isn't a selector, so we decided not to change it."
473 * Updating the target of the query object should be acceptable, so let's
481 q
->EverBound
= GL_TRUE
;
484 /* XXX should probably refcount query objects */
487 ctx
->Driver
.BeginQuery(ctx
, q
);
492 _mesa_EndQueryIndexed(GLenum target
, GLuint index
)
494 struct gl_query_object
*q
, **bindpt
;
495 GET_CURRENT_CONTEXT(ctx
);
497 if (MESA_VERBOSE
& VERBOSE_API
)
498 _mesa_debug(ctx
, "glEndQueryIndexed(%s, %u)\n",
499 _mesa_enum_to_string(target
), index
);
501 if (!query_error_check_index(ctx
, target
, index
))
504 FLUSH_VERTICES(ctx
, 0);
506 bindpt
= get_query_binding_point(ctx
, target
, index
);
508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEndQuery{Indexed}(target)");
512 /* XXX should probably refcount query objects */
515 /* Check for GL_ANY_SAMPLES_PASSED vs GL_SAMPLES_PASSED. */
516 if (q
&& q
->Target
!= target
) {
517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
518 "glEndQuery(target=%s with active query of target %s)",
519 _mesa_enum_to_string(target
),
520 _mesa_enum_to_string(q
->Target
));
526 if (!q
|| !q
->Active
) {
527 _mesa_error(ctx
, GL_INVALID_OPERATION
,
528 "glEndQuery{Indexed}(no matching glBeginQuery{Indexed})");
532 q
->Active
= GL_FALSE
;
533 ctx
->Driver
.EndQuery(ctx
, q
);
537 _mesa_BeginQuery(GLenum target
, GLuint id
)
539 _mesa_BeginQueryIndexed(target
, 0, id
);
543 _mesa_EndQuery(GLenum target
)
545 _mesa_EndQueryIndexed(target
, 0);
549 _mesa_QueryCounter(GLuint id
, GLenum target
)
551 struct gl_query_object
*q
;
552 GET_CURRENT_CONTEXT(ctx
);
554 if (MESA_VERBOSE
& VERBOSE_API
)
555 _mesa_debug(ctx
, "glQueryCounter(%u, %s)\n", id
,
556 _mesa_enum_to_string(target
));
559 if (target
!= GL_TIMESTAMP
) {
560 _mesa_error(ctx
, GL_INVALID_ENUM
, "glQueryCounter(target)");
565 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id==0)");
569 q
= _mesa_lookup_query_object(ctx
, id
);
571 /* XXX the Core profile should throw INVALID_OPERATION here */
573 /* create new object */
574 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
576 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glQueryCounter");
579 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
582 if (q
->Target
&& q
->Target
!= GL_TIMESTAMP
) {
583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
584 "glQueryCounter(id has an invalid target)");
590 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id is active)");
594 /* This possibly changes the target of a buffer allocated by
595 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
598 * "CreateQueries adds a <target>, so strictly speaking the <target>
599 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
600 * isn't a selector, so we decided not to change it."
602 * Updating the target of the query object should be acceptable, so let's
609 q
->EverBound
= GL_TRUE
;
611 if (ctx
->Driver
.QueryCounter
) {
612 ctx
->Driver
.QueryCounter(ctx
, q
);
614 /* QueryCounter is implemented using EndQuery without BeginQuery
615 * in drivers. This is actually Direct3D and Gallium convention.
617 ctx
->Driver
.EndQuery(ctx
, q
);
623 _mesa_GetQueryIndexediv(GLenum target
, GLuint index
, GLenum pname
,
626 struct gl_query_object
*q
= NULL
, **bindpt
= NULL
;
627 GET_CURRENT_CONTEXT(ctx
);
629 if (MESA_VERBOSE
& VERBOSE_API
)
630 _mesa_debug(ctx
, "glGetQueryIndexediv(%s, %u, %s)\n",
631 _mesa_enum_to_string(target
),
633 _mesa_enum_to_string(pname
));
635 if (!query_error_check_index(ctx
, target
, index
))
638 if (target
== GL_TIMESTAMP
) {
639 if (!ctx
->Extensions
.ARB_timer_query
) {
640 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryARB(target)");
645 bindpt
= get_query_binding_point(ctx
, target
, index
);
647 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(target)");
655 case GL_QUERY_COUNTER_BITS_ARB
:
657 case GL_SAMPLES_PASSED
:
658 *params
= ctx
->Const
.QueryCounterBits
.SamplesPassed
;
660 case GL_ANY_SAMPLES_PASSED
:
661 /* The minimum value of this is 1 if it's nonzero, and the value
662 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
667 case GL_TIME_ELAPSED
:
668 *params
= ctx
->Const
.QueryCounterBits
.TimeElapsed
;
671 *params
= ctx
->Const
.QueryCounterBits
.Timestamp
;
673 case GL_PRIMITIVES_GENERATED
:
674 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
;
676 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
677 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesWritten
;
679 case GL_VERTICES_SUBMITTED_ARB
:
680 *params
= ctx
->Const
.QueryCounterBits
.VerticesSubmitted
;
682 case GL_PRIMITIVES_SUBMITTED_ARB
:
683 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
;
685 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
686 *params
= ctx
->Const
.QueryCounterBits
.VsInvocations
;
688 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
689 *params
= ctx
->Const
.QueryCounterBits
.TessPatches
;
691 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
692 *params
= ctx
->Const
.QueryCounterBits
.TessInvocations
;
694 case GL_GEOMETRY_SHADER_INVOCATIONS
:
695 *params
= ctx
->Const
.QueryCounterBits
.GsInvocations
;
697 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
698 *params
= ctx
->Const
.QueryCounterBits
.GsPrimitives
;
700 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
701 *params
= ctx
->Const
.QueryCounterBits
.FsInvocations
;
703 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
704 *params
= ctx
->Const
.QueryCounterBits
.ComputeInvocations
;
706 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
707 *params
= ctx
->Const
.QueryCounterBits
.ClInPrimitives
;
709 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
710 *params
= ctx
->Const
.QueryCounterBits
.ClOutPrimitives
;
714 "Unknown target in glGetQueryIndexediv(target = %s)",
715 _mesa_enum_to_string(target
));
720 case GL_CURRENT_QUERY_ARB
:
721 *params
= (q
&& q
->Target
== target
) ? q
->Id
: 0;
724 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(pname)");
730 _mesa_GetQueryiv(GLenum target
, GLenum pname
, GLint
*params
)
732 _mesa_GetQueryIndexediv(target
, 0, pname
, params
);
736 _mesa_GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
*params
)
738 struct gl_query_object
*q
= NULL
;
739 GET_CURRENT_CONTEXT(ctx
);
741 if (MESA_VERBOSE
& VERBOSE_API
)
742 _mesa_debug(ctx
, "glGetQueryObjectiv(%u, %s)\n", id
,
743 _mesa_enum_to_string(pname
));
746 q
= _mesa_lookup_query_object(ctx
, id
);
748 if (!q
|| q
->Active
|| !q
->EverBound
) {
749 _mesa_error(ctx
, GL_INVALID_OPERATION
,
750 "glGetQueryObjectivARB(id=%d is invalid or active)", id
);
755 case GL_QUERY_RESULT_ARB
:
757 ctx
->Driver
.WaitQuery(ctx
, q
);
758 /* if result is too large for returned type, clamp to max value */
759 if (q
->Target
== GL_ANY_SAMPLES_PASSED
760 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
766 if (q
->Result
> 0x7fffffff) {
767 *params
= 0x7fffffff;
770 *params
= (GLint
)q
->Result
;
774 case GL_QUERY_RESULT_AVAILABLE_ARB
:
776 ctx
->Driver
.CheckQuery( ctx
, q
);
779 case GL_QUERY_TARGET
:
783 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectivARB(pname)");
790 _mesa_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
792 struct gl_query_object
*q
= NULL
;
793 GET_CURRENT_CONTEXT(ctx
);
795 if (MESA_VERBOSE
& VERBOSE_API
)
796 _mesa_debug(ctx
, "glGetQueryObjectuiv(%u, %s)\n", id
,
797 _mesa_enum_to_string(pname
));
800 q
= _mesa_lookup_query_object(ctx
, id
);
802 if (!q
|| q
->Active
|| !q
->EverBound
) {
803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
804 "glGetQueryObjectuivARB(id=%d is invalid or active)", id
);
809 case GL_QUERY_RESULT_ARB
:
811 ctx
->Driver
.WaitQuery(ctx
, q
);
812 /* if result is too large for returned type, clamp to max value */
813 if (q
->Target
== GL_ANY_SAMPLES_PASSED
814 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
820 if (q
->Result
> 0xffffffff) {
821 *params
= 0xffffffff;
824 *params
= (GLuint
)q
->Result
;
828 case GL_QUERY_RESULT_AVAILABLE_ARB
:
830 ctx
->Driver
.CheckQuery( ctx
, q
);
833 case GL_QUERY_TARGET
:
837 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectuivARB(pname)");
844 * New with GL_EXT_timer_query
847 _mesa_GetQueryObjecti64v(GLuint id
, GLenum pname
, GLint64EXT
*params
)
849 struct gl_query_object
*q
= NULL
;
850 GET_CURRENT_CONTEXT(ctx
);
852 if (MESA_VERBOSE
& VERBOSE_API
)
853 _mesa_debug(ctx
, "glGetQueryObjecti64v(%u, %s)\n", id
,
854 _mesa_enum_to_string(pname
));
857 q
= _mesa_lookup_query_object(ctx
, id
);
859 if (!q
|| q
->Active
|| !q
->EverBound
) {
860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
861 "glGetQueryObjectui64vARB(id=%d is invalid or active)", id
);
866 case GL_QUERY_RESULT_ARB
:
868 ctx
->Driver
.WaitQuery(ctx
, q
);
871 case GL_QUERY_RESULT_AVAILABLE_ARB
:
873 ctx
->Driver
.CheckQuery( ctx
, q
);
876 case GL_QUERY_TARGET
:
880 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjecti64vARB(pname)");
887 * New with GL_EXT_timer_query
890 _mesa_GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64EXT
*params
)
892 struct gl_query_object
*q
= NULL
;
893 GET_CURRENT_CONTEXT(ctx
);
895 if (MESA_VERBOSE
& VERBOSE_API
)
896 _mesa_debug(ctx
, "glGetQueryObjectui64v(%u, %s)\n", id
,
897 _mesa_enum_to_string(pname
));
900 q
= _mesa_lookup_query_object(ctx
, id
);
902 if (!q
|| q
->Active
|| !q
->EverBound
) {
903 _mesa_error(ctx
, GL_INVALID_OPERATION
,
904 "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id
);
909 case GL_QUERY_RESULT_ARB
:
911 ctx
->Driver
.WaitQuery(ctx
, q
);
914 case GL_QUERY_RESULT_AVAILABLE_ARB
:
916 ctx
->Driver
.CheckQuery( ctx
, q
);
919 case GL_QUERY_TARGET
:
923 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectui64vARB(pname)");
929 * New with GL_ARB_query_buffer_object
932 _mesa_GetQueryBufferObjectiv(GLuint id
, GLuint buffer
, GLenum pname
,
935 GET_CURRENT_CONTEXT(ctx
);
936 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectiv");
941 _mesa_GetQueryBufferObjectuiv(GLuint id
, GLuint buffer
, GLenum pname
,
944 GET_CURRENT_CONTEXT(ctx
);
945 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectuiv");
950 _mesa_GetQueryBufferObjecti64v(GLuint id
, GLuint buffer
, GLenum pname
,
953 GET_CURRENT_CONTEXT(ctx
);
954 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjecti64v");
959 _mesa_GetQueryBufferObjectui64v(GLuint id
, GLuint buffer
, GLenum pname
,
962 GET_CURRENT_CONTEXT(ctx
);
963 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectui64v");
968 * Allocate/init the context state related to query objects.
971 _mesa_init_queryobj(struct gl_context
*ctx
)
973 ctx
->Query
.QueryObjects
= _mesa_NewHashTable();
974 ctx
->Query
.CurrentOcclusionObject
= NULL
;
976 ctx
->Const
.QueryCounterBits
.SamplesPassed
= 64;
977 ctx
->Const
.QueryCounterBits
.TimeElapsed
= 64;
978 ctx
->Const
.QueryCounterBits
.Timestamp
= 64;
979 ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
= 64;
980 ctx
->Const
.QueryCounterBits
.PrimitivesWritten
= 64;
982 ctx
->Const
.QueryCounterBits
.VerticesSubmitted
= 64;
983 ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
= 64;
984 ctx
->Const
.QueryCounterBits
.VsInvocations
= 64;
985 ctx
->Const
.QueryCounterBits
.TessPatches
= 64;
986 ctx
->Const
.QueryCounterBits
.TessInvocations
= 64;
987 ctx
->Const
.QueryCounterBits
.GsInvocations
= 64;
988 ctx
->Const
.QueryCounterBits
.GsPrimitives
= 64;
989 ctx
->Const
.QueryCounterBits
.FsInvocations
= 64;
990 ctx
->Const
.QueryCounterBits
.ComputeInvocations
= 64;
991 ctx
->Const
.QueryCounterBits
.ClInPrimitives
= 64;
992 ctx
->Const
.QueryCounterBits
.ClOutPrimitives
= 64;
997 * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
1000 delete_queryobj_cb(GLuint id
, void *data
, void *userData
)
1002 struct gl_query_object
*q
= (struct gl_query_object
*) data
;
1003 struct gl_context
*ctx
= (struct gl_context
*)userData
;
1004 ctx
->Driver
.DeleteQuery(ctx
, q
);
1009 * Free the context state related to query objects.
1012 _mesa_free_queryobj_data(struct gl_context
*ctx
)
1014 _mesa_HashDeleteAll(ctx
->Query
.QueryObjects
, delete_queryobj_cb
, ctx
);
1015 _mesa_DeleteHashTable(ctx
->Query
.QueryObjects
);