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
);
238 _mesa_GenQueries(GLsizei n
, GLuint
*ids
)
241 GET_CURRENT_CONTEXT(ctx
);
243 if (MESA_VERBOSE
& VERBOSE_API
)
244 _mesa_debug(ctx
, "glGenQueries(%d)\n", n
);
247 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenQueriesARB(n < 0)");
251 first
= _mesa_HashFindFreeKeyBlock(ctx
->Query
.QueryObjects
, n
);
254 for (i
= 0; i
< n
; i
++) {
255 struct gl_query_object
*q
256 = ctx
->Driver
.NewQueryObject(ctx
, first
+ i
);
258 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenQueriesARB");
262 _mesa_HashInsert(ctx
->Query
.QueryObjects
, first
+ i
, q
);
269 _mesa_DeleteQueries(GLsizei n
, const GLuint
*ids
)
272 GET_CURRENT_CONTEXT(ctx
);
273 FLUSH_VERTICES(ctx
, 0);
275 if (MESA_VERBOSE
& VERBOSE_API
)
276 _mesa_debug(ctx
, "glDeleteQueries(%d)\n", n
);
279 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteQueriesARB(n < 0)");
283 for (i
= 0; i
< n
; i
++) {
285 struct gl_query_object
*q
= _mesa_lookup_query_object(ctx
, ids
[i
]);
288 struct gl_query_object
**bindpt
;
289 bindpt
= get_query_binding_point(ctx
, q
->Target
, q
->Stream
);
290 assert(bindpt
); /* Should be non-null for active q. */
294 q
->Active
= GL_FALSE
;
295 ctx
->Driver
.EndQuery(ctx
, q
);
297 _mesa_HashRemove(ctx
->Query
.QueryObjects
, ids
[i
]);
298 ctx
->Driver
.DeleteQuery(ctx
, q
);
306 _mesa_IsQuery(GLuint id
)
308 struct gl_query_object
*q
;
310 GET_CURRENT_CONTEXT(ctx
);
311 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
313 if (MESA_VERBOSE
& VERBOSE_API
)
314 _mesa_debug(ctx
, "glIsQuery(%u)\n", id
);
319 q
= _mesa_lookup_query_object(ctx
, id
);
327 query_error_check_index(struct gl_context
*ctx
, GLenum target
, GLuint index
)
330 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
331 case GL_PRIMITIVES_GENERATED
:
332 if (index
>= ctx
->Const
.MaxVertexStreams
) {
333 _mesa_error(ctx
, GL_INVALID_VALUE
,
334 "glBeginQueryIndexed(index>=MaxVertexStreams)");
340 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBeginQueryIndexed(index>0)");
348 _mesa_BeginQueryIndexed(GLenum target
, GLuint index
, GLuint id
)
350 struct gl_query_object
*q
, **bindpt
;
351 GET_CURRENT_CONTEXT(ctx
);
353 if (MESA_VERBOSE
& VERBOSE_API
)
354 _mesa_debug(ctx
, "glBeginQueryIndexed(%s, %u, %u)\n",
355 _mesa_lookup_enum_by_nr(target
), index
, id
);
357 if (!query_error_check_index(ctx
, target
, index
))
360 FLUSH_VERTICES(ctx
, 0);
362 bindpt
= get_query_binding_point(ctx
, target
, index
);
364 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginQuery{Indexed}(target)");
368 /* From the GL_ARB_occlusion_query spec:
370 * "If BeginQueryARB is called while another query is already in
371 * progress with the same target, an INVALID_OPERATION error is
375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
376 "glBeginQuery{Indexed}(target=%s is active)",
377 _mesa_lookup_enum_by_nr(target
));
382 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginQuery{Indexed}(id==0)");
386 q
= _mesa_lookup_query_object(ctx
, id
);
388 if (ctx
->API
!= API_OPENGL_COMPAT
) {
389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
390 "glBeginQuery{Indexed}(non-gen name)");
393 /* create new object */
394 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBeginQuery{Indexed}");
399 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
403 /* pre-existing object */
405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
406 "glBeginQuery{Indexed}(query already active)");
410 /* Section 2.14 Asynchronous Queries, page 84 of the OpenGL ES 3.0.4
413 * "BeginQuery generates an INVALID_OPERATION error if any of the
414 * following conditions hold: [...] id is the name of an
415 * existing query object whose type does not match target; [...]
417 * Similar wording exists in the OpenGL 4.5 spec, section 4.2. QUERY
418 * OBJECTS AND ASYNCHRONOUS QUERIES, page 43.
420 if (q
->EverBound
&& q
->Target
!= target
) {
421 _mesa_error(ctx
, GL_INVALID_OPERATION
,
422 "glBeginQuery{Indexed}(target mismatch)");
431 q
->EverBound
= GL_TRUE
;
434 /* XXX should probably refcount query objects */
437 ctx
->Driver
.BeginQuery(ctx
, q
);
442 _mesa_EndQueryIndexed(GLenum target
, GLuint index
)
444 struct gl_query_object
*q
, **bindpt
;
445 GET_CURRENT_CONTEXT(ctx
);
447 if (MESA_VERBOSE
& VERBOSE_API
)
448 _mesa_debug(ctx
, "glEndQueryIndexed(%s, %u)\n",
449 _mesa_lookup_enum_by_nr(target
), index
);
451 if (!query_error_check_index(ctx
, target
, index
))
454 FLUSH_VERTICES(ctx
, 0);
456 bindpt
= get_query_binding_point(ctx
, target
, index
);
458 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEndQuery{Indexed}(target)");
462 /* XXX should probably refcount query objects */
465 /* Check for GL_ANY_SAMPLES_PASSED vs GL_SAMPLES_PASSED. */
466 if (q
&& q
->Target
!= target
) {
467 _mesa_error(ctx
, GL_INVALID_OPERATION
,
468 "glEndQuery(target=%s with active query of target %s)",
469 _mesa_lookup_enum_by_nr(target
),
470 _mesa_lookup_enum_by_nr(q
->Target
));
476 if (!q
|| !q
->Active
) {
477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
478 "glEndQuery{Indexed}(no matching glBeginQuery{Indexed})");
482 q
->Active
= GL_FALSE
;
483 ctx
->Driver
.EndQuery(ctx
, q
);
487 _mesa_BeginQuery(GLenum target
, GLuint id
)
489 _mesa_BeginQueryIndexed(target
, 0, id
);
493 _mesa_EndQuery(GLenum target
)
495 _mesa_EndQueryIndexed(target
, 0);
499 _mesa_QueryCounter(GLuint id
, GLenum target
)
501 struct gl_query_object
*q
;
502 GET_CURRENT_CONTEXT(ctx
);
504 if (MESA_VERBOSE
& VERBOSE_API
)
505 _mesa_debug(ctx
, "glQueryCounter(%u, %s)\n", id
,
506 _mesa_lookup_enum_by_nr(target
));
509 if (target
!= GL_TIMESTAMP
) {
510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glQueryCounter(target)");
515 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id==0)");
519 q
= _mesa_lookup_query_object(ctx
, id
);
521 /* XXX the Core profile should throw INVALID_OPERATION here */
523 /* create new object */
524 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
526 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glQueryCounter");
529 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
532 if (q
->Target
&& q
->Target
!= GL_TIMESTAMP
) {
533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
534 "glQueryCounter(id has an invalid target)");
540 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id is active)");
547 q
->EverBound
= GL_TRUE
;
549 if (ctx
->Driver
.QueryCounter
) {
550 ctx
->Driver
.QueryCounter(ctx
, q
);
552 /* QueryCounter is implemented using EndQuery without BeginQuery
553 * in drivers. This is actually Direct3D and Gallium convention.
555 ctx
->Driver
.EndQuery(ctx
, q
);
561 _mesa_GetQueryIndexediv(GLenum target
, GLuint index
, GLenum pname
,
564 struct gl_query_object
*q
= NULL
, **bindpt
= NULL
;
565 GET_CURRENT_CONTEXT(ctx
);
567 if (MESA_VERBOSE
& VERBOSE_API
)
568 _mesa_debug(ctx
, "glGetQueryIndexediv(%s, %u, %s)\n",
569 _mesa_lookup_enum_by_nr(target
),
571 _mesa_lookup_enum_by_nr(pname
));
573 if (!query_error_check_index(ctx
, target
, index
))
576 if (target
== GL_TIMESTAMP
) {
577 if (!ctx
->Extensions
.ARB_timer_query
) {
578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryARB(target)");
583 bindpt
= get_query_binding_point(ctx
, target
, index
);
585 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(target)");
593 case GL_QUERY_COUNTER_BITS_ARB
:
595 case GL_SAMPLES_PASSED
:
596 *params
= ctx
->Const
.QueryCounterBits
.SamplesPassed
;
598 case GL_ANY_SAMPLES_PASSED
:
599 /* The minimum value of this is 1 if it's nonzero, and the value
600 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
605 case GL_TIME_ELAPSED
:
606 *params
= ctx
->Const
.QueryCounterBits
.TimeElapsed
;
609 *params
= ctx
->Const
.QueryCounterBits
.Timestamp
;
611 case GL_PRIMITIVES_GENERATED
:
612 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
;
614 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
615 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesWritten
;
617 case GL_VERTICES_SUBMITTED_ARB
:
618 *params
= ctx
->Const
.QueryCounterBits
.VerticesSubmitted
;
620 case GL_PRIMITIVES_SUBMITTED_ARB
:
621 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
;
623 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
624 *params
= ctx
->Const
.QueryCounterBits
.VsInvocations
;
626 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
627 *params
= ctx
->Const
.QueryCounterBits
.TessPatches
;
629 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
630 *params
= ctx
->Const
.QueryCounterBits
.TessInvocations
;
632 case GL_GEOMETRY_SHADER_INVOCATIONS
:
633 *params
= ctx
->Const
.QueryCounterBits
.GsInvocations
;
635 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
636 *params
= ctx
->Const
.QueryCounterBits
.GsPrimitives
;
638 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
639 *params
= ctx
->Const
.QueryCounterBits
.FsInvocations
;
641 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
642 *params
= ctx
->Const
.QueryCounterBits
.ComputeInvocations
;
644 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
645 *params
= ctx
->Const
.QueryCounterBits
.ClInPrimitives
;
647 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
648 *params
= ctx
->Const
.QueryCounterBits
.ClOutPrimitives
;
652 "Unknown target in glGetQueryIndexediv(target = %s)",
653 _mesa_lookup_enum_by_nr(target
));
658 case GL_CURRENT_QUERY_ARB
:
659 *params
= (q
&& q
->Target
== target
) ? q
->Id
: 0;
662 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(pname)");
668 _mesa_GetQueryiv(GLenum target
, GLenum pname
, GLint
*params
)
670 _mesa_GetQueryIndexediv(target
, 0, pname
, params
);
674 _mesa_GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
*params
)
676 struct gl_query_object
*q
= NULL
;
677 GET_CURRENT_CONTEXT(ctx
);
679 if (MESA_VERBOSE
& VERBOSE_API
)
680 _mesa_debug(ctx
, "glGetQueryObjectiv(%u, %s)\n", id
,
681 _mesa_lookup_enum_by_nr(pname
));
684 q
= _mesa_lookup_query_object(ctx
, id
);
686 if (!q
|| q
->Active
|| !q
->EverBound
) {
687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
688 "glGetQueryObjectivARB(id=%d is invalid or active)", id
);
693 case GL_QUERY_RESULT_ARB
:
695 ctx
->Driver
.WaitQuery(ctx
, q
);
696 /* if result is too large for returned type, clamp to max value */
697 if (q
->Target
== GL_ANY_SAMPLES_PASSED
698 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
704 if (q
->Result
> 0x7fffffff) {
705 *params
= 0x7fffffff;
708 *params
= (GLint
)q
->Result
;
712 case GL_QUERY_RESULT_AVAILABLE_ARB
:
714 ctx
->Driver
.CheckQuery( ctx
, q
);
718 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectivARB(pname)");
725 _mesa_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
727 struct gl_query_object
*q
= NULL
;
728 GET_CURRENT_CONTEXT(ctx
);
730 if (MESA_VERBOSE
& VERBOSE_API
)
731 _mesa_debug(ctx
, "glGetQueryObjectuiv(%u, %s)\n", id
,
732 _mesa_lookup_enum_by_nr(pname
));
735 q
= _mesa_lookup_query_object(ctx
, id
);
737 if (!q
|| q
->Active
|| !q
->EverBound
) {
738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
739 "glGetQueryObjectuivARB(id=%d is invalid or active)", id
);
744 case GL_QUERY_RESULT_ARB
:
746 ctx
->Driver
.WaitQuery(ctx
, q
);
747 /* if result is too large for returned type, clamp to max value */
748 if (q
->Target
== GL_ANY_SAMPLES_PASSED
749 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
755 if (q
->Result
> 0xffffffff) {
756 *params
= 0xffffffff;
759 *params
= (GLuint
)q
->Result
;
763 case GL_QUERY_RESULT_AVAILABLE_ARB
:
765 ctx
->Driver
.CheckQuery( ctx
, q
);
769 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectuivARB(pname)");
776 * New with GL_EXT_timer_query
779 _mesa_GetQueryObjecti64v(GLuint id
, GLenum pname
, GLint64EXT
*params
)
781 struct gl_query_object
*q
= NULL
;
782 GET_CURRENT_CONTEXT(ctx
);
784 if (MESA_VERBOSE
& VERBOSE_API
)
785 _mesa_debug(ctx
, "glGetQueryObjecti64v(%u, %s)\n", id
,
786 _mesa_lookup_enum_by_nr(pname
));
789 q
= _mesa_lookup_query_object(ctx
, id
);
791 if (!q
|| q
->Active
|| !q
->EverBound
) {
792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
793 "glGetQueryObjectui64vARB(id=%d is invalid or active)", id
);
798 case GL_QUERY_RESULT_ARB
:
800 ctx
->Driver
.WaitQuery(ctx
, q
);
803 case GL_QUERY_RESULT_AVAILABLE_ARB
:
805 ctx
->Driver
.CheckQuery( ctx
, q
);
809 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjecti64vARB(pname)");
816 * New with GL_EXT_timer_query
819 _mesa_GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64EXT
*params
)
821 struct gl_query_object
*q
= NULL
;
822 GET_CURRENT_CONTEXT(ctx
);
824 if (MESA_VERBOSE
& VERBOSE_API
)
825 _mesa_debug(ctx
, "glGetQueryObjectui64v(%u, %s)\n", id
,
826 _mesa_lookup_enum_by_nr(pname
));
829 q
= _mesa_lookup_query_object(ctx
, id
);
831 if (!q
|| q
->Active
|| !q
->EverBound
) {
832 _mesa_error(ctx
, GL_INVALID_OPERATION
,
833 "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id
);
838 case GL_QUERY_RESULT_ARB
:
840 ctx
->Driver
.WaitQuery(ctx
, q
);
843 case GL_QUERY_RESULT_AVAILABLE_ARB
:
845 ctx
->Driver
.CheckQuery( ctx
, q
);
849 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectui64vARB(pname)");
855 * Allocate/init the context state related to query objects.
858 _mesa_init_queryobj(struct gl_context
*ctx
)
860 ctx
->Query
.QueryObjects
= _mesa_NewHashTable();
861 ctx
->Query
.CurrentOcclusionObject
= NULL
;
863 ctx
->Const
.QueryCounterBits
.SamplesPassed
= 64;
864 ctx
->Const
.QueryCounterBits
.TimeElapsed
= 64;
865 ctx
->Const
.QueryCounterBits
.Timestamp
= 64;
866 ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
= 64;
867 ctx
->Const
.QueryCounterBits
.PrimitivesWritten
= 64;
869 ctx
->Const
.QueryCounterBits
.VerticesSubmitted
= 64;
870 ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
= 64;
871 ctx
->Const
.QueryCounterBits
.VsInvocations
= 64;
872 ctx
->Const
.QueryCounterBits
.TessPatches
= 64;
873 ctx
->Const
.QueryCounterBits
.TessInvocations
= 64;
874 ctx
->Const
.QueryCounterBits
.GsInvocations
= 64;
875 ctx
->Const
.QueryCounterBits
.GsPrimitives
= 64;
876 ctx
->Const
.QueryCounterBits
.FsInvocations
= 64;
877 ctx
->Const
.QueryCounterBits
.ComputeInvocations
= 64;
878 ctx
->Const
.QueryCounterBits
.ClInPrimitives
= 64;
879 ctx
->Const
.QueryCounterBits
.ClOutPrimitives
= 64;
884 * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
887 delete_queryobj_cb(GLuint id
, void *data
, void *userData
)
889 struct gl_query_object
*q
= (struct gl_query_object
*) data
;
890 struct gl_context
*ctx
= (struct gl_context
*)userData
;
891 ctx
->Driver
.DeleteQuery(ctx
, q
);
896 * Free the context state related to query objects.
899 _mesa_free_queryobj_data(struct gl_context
*ctx
)
901 _mesa_HashDeleteAll(ctx
->Query
.QueryObjects
, delete_queryobj_cb
, ctx
);
902 _mesa_DeleteHashTable(ctx
->Query
.QueryObjects
);