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
);
287 if (!ctx
->Extensions
.ARB_direct_state_access
) {
288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
289 "glCreateQueries(GL_ARB_direct_state_access "
290 "is not supported)");
295 case GL_SAMPLES_PASSED
:
296 case GL_ANY_SAMPLES_PASSED
:
297 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
298 case GL_TIME_ELAPSED
:
300 case GL_PRIMITIVES_GENERATED
:
301 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
304 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCreateQueries(invalid target = %s)",
305 _mesa_lookup_enum_by_nr(target
));
309 create_queries(ctx
, target
, n
, ids
, true);
314 _mesa_DeleteQueries(GLsizei n
, const GLuint
*ids
)
317 GET_CURRENT_CONTEXT(ctx
);
318 FLUSH_VERTICES(ctx
, 0);
320 if (MESA_VERBOSE
& VERBOSE_API
)
321 _mesa_debug(ctx
, "glDeleteQueries(%d)\n", n
);
324 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteQueriesARB(n < 0)");
328 for (i
= 0; i
< n
; i
++) {
330 struct gl_query_object
*q
= _mesa_lookup_query_object(ctx
, ids
[i
]);
333 struct gl_query_object
**bindpt
;
334 bindpt
= get_query_binding_point(ctx
, q
->Target
, q
->Stream
);
335 assert(bindpt
); /* Should be non-null for active q. */
339 q
->Active
= GL_FALSE
;
340 ctx
->Driver
.EndQuery(ctx
, q
);
342 _mesa_HashRemove(ctx
->Query
.QueryObjects
, ids
[i
]);
343 ctx
->Driver
.DeleteQuery(ctx
, q
);
351 _mesa_IsQuery(GLuint id
)
353 struct gl_query_object
*q
;
355 GET_CURRENT_CONTEXT(ctx
);
356 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
358 if (MESA_VERBOSE
& VERBOSE_API
)
359 _mesa_debug(ctx
, "glIsQuery(%u)\n", id
);
364 q
= _mesa_lookup_query_object(ctx
, id
);
372 query_error_check_index(struct gl_context
*ctx
, GLenum target
, GLuint index
)
375 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
376 case GL_PRIMITIVES_GENERATED
:
377 if (index
>= ctx
->Const
.MaxVertexStreams
) {
378 _mesa_error(ctx
, GL_INVALID_VALUE
,
379 "glBeginQueryIndexed(index>=MaxVertexStreams)");
385 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBeginQueryIndexed(index>0)");
393 _mesa_BeginQueryIndexed(GLenum target
, GLuint index
, GLuint id
)
395 struct gl_query_object
*q
, **bindpt
;
396 GET_CURRENT_CONTEXT(ctx
);
398 if (MESA_VERBOSE
& VERBOSE_API
)
399 _mesa_debug(ctx
, "glBeginQueryIndexed(%s, %u, %u)\n",
400 _mesa_lookup_enum_by_nr(target
), index
, id
);
402 if (!query_error_check_index(ctx
, target
, index
))
405 FLUSH_VERTICES(ctx
, 0);
407 bindpt
= get_query_binding_point(ctx
, target
, index
);
409 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginQuery{Indexed}(target)");
413 /* From the GL_ARB_occlusion_query spec:
415 * "If BeginQueryARB is called while another query is already in
416 * progress with the same target, an INVALID_OPERATION error is
420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
421 "glBeginQuery{Indexed}(target=%s is active)",
422 _mesa_lookup_enum_by_nr(target
));
427 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginQuery{Indexed}(id==0)");
431 q
= _mesa_lookup_query_object(ctx
, id
);
433 if (ctx
->API
!= API_OPENGL_COMPAT
) {
434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
435 "glBeginQuery{Indexed}(non-gen name)");
438 /* create new object */
439 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBeginQuery{Indexed}");
444 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
448 /* pre-existing object */
450 _mesa_error(ctx
, GL_INVALID_OPERATION
,
451 "glBeginQuery{Indexed}(query already active)");
455 /* Section 2.14 Asynchronous Queries, page 84 of the OpenGL ES 3.0.4
458 * "BeginQuery generates an INVALID_OPERATION error if any of the
459 * following conditions hold: [...] id is the name of an
460 * existing query object whose type does not match target; [...]
462 * Similar wording exists in the OpenGL 4.5 spec, section 4.2. QUERY
463 * OBJECTS AND ASYNCHRONOUS QUERIES, page 43.
465 if (q
->EverBound
&& q
->Target
!= target
) {
466 _mesa_error(ctx
, GL_INVALID_OPERATION
,
467 "glBeginQuery{Indexed}(target mismatch)");
472 /* This possibly changes the target of a buffer allocated by
473 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
476 * "CreateQueries adds a <target>, so strictly speaking the <target>
477 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
478 * isn't a selector, so we decided not to change it."
480 * Updating the target of the query object should be acceptable, so let's
488 q
->EverBound
= GL_TRUE
;
491 /* XXX should probably refcount query objects */
494 ctx
->Driver
.BeginQuery(ctx
, q
);
499 _mesa_EndQueryIndexed(GLenum target
, GLuint index
)
501 struct gl_query_object
*q
, **bindpt
;
502 GET_CURRENT_CONTEXT(ctx
);
504 if (MESA_VERBOSE
& VERBOSE_API
)
505 _mesa_debug(ctx
, "glEndQueryIndexed(%s, %u)\n",
506 _mesa_lookup_enum_by_nr(target
), index
);
508 if (!query_error_check_index(ctx
, target
, index
))
511 FLUSH_VERTICES(ctx
, 0);
513 bindpt
= get_query_binding_point(ctx
, target
, index
);
515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEndQuery{Indexed}(target)");
519 /* XXX should probably refcount query objects */
522 /* Check for GL_ANY_SAMPLES_PASSED vs GL_SAMPLES_PASSED. */
523 if (q
&& q
->Target
!= target
) {
524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
525 "glEndQuery(target=%s with active query of target %s)",
526 _mesa_lookup_enum_by_nr(target
),
527 _mesa_lookup_enum_by_nr(q
->Target
));
533 if (!q
|| !q
->Active
) {
534 _mesa_error(ctx
, GL_INVALID_OPERATION
,
535 "glEndQuery{Indexed}(no matching glBeginQuery{Indexed})");
539 q
->Active
= GL_FALSE
;
540 ctx
->Driver
.EndQuery(ctx
, q
);
544 _mesa_BeginQuery(GLenum target
, GLuint id
)
546 _mesa_BeginQueryIndexed(target
, 0, id
);
550 _mesa_EndQuery(GLenum target
)
552 _mesa_EndQueryIndexed(target
, 0);
556 _mesa_QueryCounter(GLuint id
, GLenum target
)
558 struct gl_query_object
*q
;
559 GET_CURRENT_CONTEXT(ctx
);
561 if (MESA_VERBOSE
& VERBOSE_API
)
562 _mesa_debug(ctx
, "glQueryCounter(%u, %s)\n", id
,
563 _mesa_lookup_enum_by_nr(target
));
566 if (target
!= GL_TIMESTAMP
) {
567 _mesa_error(ctx
, GL_INVALID_ENUM
, "glQueryCounter(target)");
572 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id==0)");
576 q
= _mesa_lookup_query_object(ctx
, id
);
578 /* XXX the Core profile should throw INVALID_OPERATION here */
580 /* create new object */
581 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
583 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glQueryCounter");
586 _mesa_HashInsert(ctx
->Query
.QueryObjects
, id
, q
);
589 if (q
->Target
&& q
->Target
!= GL_TIMESTAMP
) {
590 _mesa_error(ctx
, GL_INVALID_OPERATION
,
591 "glQueryCounter(id has an invalid target)");
597 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id is active)");
601 /* This possibly changes the target of a buffer allocated by
602 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
605 * "CreateQueries adds a <target>, so strictly speaking the <target>
606 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
607 * isn't a selector, so we decided not to change it."
609 * Updating the target of the query object should be acceptable, so let's
616 q
->EverBound
= GL_TRUE
;
618 if (ctx
->Driver
.QueryCounter
) {
619 ctx
->Driver
.QueryCounter(ctx
, q
);
621 /* QueryCounter is implemented using EndQuery without BeginQuery
622 * in drivers. This is actually Direct3D and Gallium convention.
624 ctx
->Driver
.EndQuery(ctx
, q
);
630 _mesa_GetQueryIndexediv(GLenum target
, GLuint index
, GLenum pname
,
633 struct gl_query_object
*q
= NULL
, **bindpt
= NULL
;
634 GET_CURRENT_CONTEXT(ctx
);
636 if (MESA_VERBOSE
& VERBOSE_API
)
637 _mesa_debug(ctx
, "glGetQueryIndexediv(%s, %u, %s)\n",
638 _mesa_lookup_enum_by_nr(target
),
640 _mesa_lookup_enum_by_nr(pname
));
642 if (!query_error_check_index(ctx
, target
, index
))
645 if (target
== GL_TIMESTAMP
) {
646 if (!ctx
->Extensions
.ARB_timer_query
) {
647 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryARB(target)");
652 bindpt
= get_query_binding_point(ctx
, target
, index
);
654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(target)");
662 case GL_QUERY_COUNTER_BITS_ARB
:
664 case GL_SAMPLES_PASSED
:
665 *params
= ctx
->Const
.QueryCounterBits
.SamplesPassed
;
667 case GL_ANY_SAMPLES_PASSED
:
668 /* The minimum value of this is 1 if it's nonzero, and the value
669 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
674 case GL_TIME_ELAPSED
:
675 *params
= ctx
->Const
.QueryCounterBits
.TimeElapsed
;
678 *params
= ctx
->Const
.QueryCounterBits
.Timestamp
;
680 case GL_PRIMITIVES_GENERATED
:
681 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
;
683 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
684 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesWritten
;
686 case GL_VERTICES_SUBMITTED_ARB
:
687 *params
= ctx
->Const
.QueryCounterBits
.VerticesSubmitted
;
689 case GL_PRIMITIVES_SUBMITTED_ARB
:
690 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
;
692 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
693 *params
= ctx
->Const
.QueryCounterBits
.VsInvocations
;
695 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
696 *params
= ctx
->Const
.QueryCounterBits
.TessPatches
;
698 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
699 *params
= ctx
->Const
.QueryCounterBits
.TessInvocations
;
701 case GL_GEOMETRY_SHADER_INVOCATIONS
:
702 *params
= ctx
->Const
.QueryCounterBits
.GsInvocations
;
704 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
705 *params
= ctx
->Const
.QueryCounterBits
.GsPrimitives
;
707 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
708 *params
= ctx
->Const
.QueryCounterBits
.FsInvocations
;
710 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
711 *params
= ctx
->Const
.QueryCounterBits
.ComputeInvocations
;
713 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
714 *params
= ctx
->Const
.QueryCounterBits
.ClInPrimitives
;
716 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
717 *params
= ctx
->Const
.QueryCounterBits
.ClOutPrimitives
;
721 "Unknown target in glGetQueryIndexediv(target = %s)",
722 _mesa_lookup_enum_by_nr(target
));
727 case GL_CURRENT_QUERY_ARB
:
728 *params
= (q
&& q
->Target
== target
) ? q
->Id
: 0;
731 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(pname)");
737 _mesa_GetQueryiv(GLenum target
, GLenum pname
, GLint
*params
)
739 _mesa_GetQueryIndexediv(target
, 0, pname
, params
);
743 _mesa_GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
*params
)
745 struct gl_query_object
*q
= NULL
;
746 GET_CURRENT_CONTEXT(ctx
);
748 if (MESA_VERBOSE
& VERBOSE_API
)
749 _mesa_debug(ctx
, "glGetQueryObjectiv(%u, %s)\n", id
,
750 _mesa_lookup_enum_by_nr(pname
));
753 q
= _mesa_lookup_query_object(ctx
, id
);
755 if (!q
|| q
->Active
|| !q
->EverBound
) {
756 _mesa_error(ctx
, GL_INVALID_OPERATION
,
757 "glGetQueryObjectivARB(id=%d is invalid or active)", id
);
762 case GL_QUERY_RESULT_ARB
:
764 ctx
->Driver
.WaitQuery(ctx
, q
);
765 /* if result is too large for returned type, clamp to max value */
766 if (q
->Target
== GL_ANY_SAMPLES_PASSED
767 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
773 if (q
->Result
> 0x7fffffff) {
774 *params
= 0x7fffffff;
777 *params
= (GLint
)q
->Result
;
781 case GL_QUERY_RESULT_AVAILABLE_ARB
:
783 ctx
->Driver
.CheckQuery( ctx
, q
);
786 case GL_QUERY_TARGET
:
790 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectivARB(pname)");
797 _mesa_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
799 struct gl_query_object
*q
= NULL
;
800 GET_CURRENT_CONTEXT(ctx
);
802 if (MESA_VERBOSE
& VERBOSE_API
)
803 _mesa_debug(ctx
, "glGetQueryObjectuiv(%u, %s)\n", id
,
804 _mesa_lookup_enum_by_nr(pname
));
807 q
= _mesa_lookup_query_object(ctx
, id
);
809 if (!q
|| q
->Active
|| !q
->EverBound
) {
810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
811 "glGetQueryObjectuivARB(id=%d is invalid or active)", id
);
816 case GL_QUERY_RESULT_ARB
:
818 ctx
->Driver
.WaitQuery(ctx
, q
);
819 /* if result is too large for returned type, clamp to max value */
820 if (q
->Target
== GL_ANY_SAMPLES_PASSED
821 || q
->Target
== GL_ANY_SAMPLES_PASSED_CONSERVATIVE
) {
827 if (q
->Result
> 0xffffffff) {
828 *params
= 0xffffffff;
831 *params
= (GLuint
)q
->Result
;
835 case GL_QUERY_RESULT_AVAILABLE_ARB
:
837 ctx
->Driver
.CheckQuery( ctx
, q
);
840 case GL_QUERY_TARGET
:
844 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectuivARB(pname)");
851 * New with GL_EXT_timer_query
854 _mesa_GetQueryObjecti64v(GLuint id
, GLenum pname
, GLint64EXT
*params
)
856 struct gl_query_object
*q
= NULL
;
857 GET_CURRENT_CONTEXT(ctx
);
859 if (MESA_VERBOSE
& VERBOSE_API
)
860 _mesa_debug(ctx
, "glGetQueryObjecti64v(%u, %s)\n", id
,
861 _mesa_lookup_enum_by_nr(pname
));
864 q
= _mesa_lookup_query_object(ctx
, id
);
866 if (!q
|| q
->Active
|| !q
->EverBound
) {
867 _mesa_error(ctx
, GL_INVALID_OPERATION
,
868 "glGetQueryObjectui64vARB(id=%d is invalid or active)", id
);
873 case GL_QUERY_RESULT_ARB
:
875 ctx
->Driver
.WaitQuery(ctx
, q
);
878 case GL_QUERY_RESULT_AVAILABLE_ARB
:
880 ctx
->Driver
.CheckQuery( ctx
, q
);
883 case GL_QUERY_TARGET
:
887 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjecti64vARB(pname)");
894 * New with GL_EXT_timer_query
897 _mesa_GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64EXT
*params
)
899 struct gl_query_object
*q
= NULL
;
900 GET_CURRENT_CONTEXT(ctx
);
902 if (MESA_VERBOSE
& VERBOSE_API
)
903 _mesa_debug(ctx
, "glGetQueryObjectui64v(%u, %s)\n", id
,
904 _mesa_lookup_enum_by_nr(pname
));
907 q
= _mesa_lookup_query_object(ctx
, id
);
909 if (!q
|| q
->Active
|| !q
->EverBound
) {
910 _mesa_error(ctx
, GL_INVALID_OPERATION
,
911 "glGetQueryObjectuui64vARB(id=%d is invalid or active)", id
);
916 case GL_QUERY_RESULT_ARB
:
918 ctx
->Driver
.WaitQuery(ctx
, q
);
921 case GL_QUERY_RESULT_AVAILABLE_ARB
:
923 ctx
->Driver
.CheckQuery( ctx
, q
);
926 case GL_QUERY_TARGET
:
930 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryObjectui64vARB(pname)");
936 * New with GL_ARB_query_buffer_object
939 _mesa_GetQueryBufferObjectiv(GLuint id
, GLuint buffer
, GLenum pname
,
942 GET_CURRENT_CONTEXT(ctx
);
943 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectiv");
948 _mesa_GetQueryBufferObjectuiv(GLuint id
, GLuint buffer
, GLenum pname
,
951 GET_CURRENT_CONTEXT(ctx
);
952 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectuiv");
957 _mesa_GetQueryBufferObjecti64v(GLuint id
, GLuint buffer
, GLenum pname
,
960 GET_CURRENT_CONTEXT(ctx
);
961 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjecti64v");
966 _mesa_GetQueryBufferObjectui64v(GLuint id
, GLuint buffer
, GLenum pname
,
969 GET_CURRENT_CONTEXT(ctx
);
970 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetQueryBufferObjectui64v");
975 * Allocate/init the context state related to query objects.
978 _mesa_init_queryobj(struct gl_context
*ctx
)
980 ctx
->Query
.QueryObjects
= _mesa_NewHashTable();
981 ctx
->Query
.CurrentOcclusionObject
= NULL
;
983 ctx
->Const
.QueryCounterBits
.SamplesPassed
= 64;
984 ctx
->Const
.QueryCounterBits
.TimeElapsed
= 64;
985 ctx
->Const
.QueryCounterBits
.Timestamp
= 64;
986 ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
= 64;
987 ctx
->Const
.QueryCounterBits
.PrimitivesWritten
= 64;
989 ctx
->Const
.QueryCounterBits
.VerticesSubmitted
= 64;
990 ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
= 64;
991 ctx
->Const
.QueryCounterBits
.VsInvocations
= 64;
992 ctx
->Const
.QueryCounterBits
.TessPatches
= 64;
993 ctx
->Const
.QueryCounterBits
.TessInvocations
= 64;
994 ctx
->Const
.QueryCounterBits
.GsInvocations
= 64;
995 ctx
->Const
.QueryCounterBits
.GsPrimitives
= 64;
996 ctx
->Const
.QueryCounterBits
.FsInvocations
= 64;
997 ctx
->Const
.QueryCounterBits
.ComputeInvocations
= 64;
998 ctx
->Const
.QueryCounterBits
.ClInPrimitives
= 64;
999 ctx
->Const
.QueryCounterBits
.ClOutPrimitives
= 64;
1004 * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
1007 delete_queryobj_cb(GLuint id
, void *data
, void *userData
)
1009 struct gl_query_object
*q
= (struct gl_query_object
*) data
;
1010 struct gl_context
*ctx
= (struct gl_context
*)userData
;
1011 ctx
->Driver
.DeleteQuery(ctx
, q
);
1016 * Free the context state related to query objects.
1019 _mesa_free_queryobj_data(struct gl_context
*ctx
)
1021 _mesa_HashDeleteAll(ctx
->Query
.QueryObjects
, delete_queryobj_cb
, ctx
);
1022 _mesa_DeleteHashTable(ctx
->Query
.QueryObjects
);