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.
26 #include "bufferobj.h"
34 #include "main/dispatch.h"
38 * Allocate a new query object. This is a fallback routine called via
39 * ctx->Driver.NewQueryObject().
40 * \param ctx - rendering context
41 * \param id - the new object's ID
42 * \return pointer to new query_object object or NULL if out of memory.
44 static struct gl_query_object
*
45 _mesa_new_query_object(struct gl_context
*ctx
, GLuint id
)
47 struct gl_query_object
*q
= CALLOC_STRUCT(gl_query_object
);
54 /* This is to satisfy the language of the specification: "In the initial
55 * state of a query object, the result is available" (OpenGL 3.1 §
60 /* OpenGL 3.1 § 2.13 says about GenQueries, "These names are marked as
61 * used, but no object is associated with them until the first time they
62 * are used by BeginQuery." Since our implementation actually does
63 * allocate an object at this point, use a flag to indicate that this
64 * object has not yet been bound so should not be considered a query.
66 q
->EverBound
= GL_FALSE
;
73 * Begin a query. Software driver fallback.
74 * Called via ctx->Driver.BeginQuery().
77 _mesa_begin_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
79 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
84 * End a query. Software driver fallback.
85 * Called via ctx->Driver.EndQuery().
88 _mesa_end_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
90 ctx
->NewState
|= _NEW_DEPTH
; /* for swrast */
96 * Wait for query to complete. Software driver fallback.
97 * Called via ctx->Driver.WaitQuery().
100 _mesa_wait_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
102 /* For software drivers, _mesa_end_query() should have completed the query.
103 * For real hardware, implement a proper WaitQuery() driver function,
104 * which may require issuing a flush.
111 * Check if a query results are ready. Software driver fallback.
112 * Called via ctx->Driver.CheckQuery().
115 _mesa_check_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
117 /* No-op for sw rendering.
118 * HW drivers may need to flush at this time.
124 * Delete a query object. Called via ctx->Driver.DeleteQuery().
125 * Not removed from hash table here.
128 _mesa_delete_query(struct gl_context
*ctx
, struct gl_query_object
*q
)
136 _mesa_init_query_object_functions(struct dd_function_table
*driver
)
138 driver
->NewQueryObject
= _mesa_new_query_object
;
139 driver
->DeleteQuery
= _mesa_delete_query
;
140 driver
->BeginQuery
= _mesa_begin_query
;
141 driver
->EndQuery
= _mesa_end_query
;
142 driver
->WaitQuery
= _mesa_wait_query
;
143 driver
->CheckQuery
= _mesa_check_query
;
146 static struct gl_query_object
**
147 get_pipe_stats_binding_point(struct gl_context
*ctx
,
150 const int which
= target
- GL_VERTICES_SUBMITTED_ARB
;
151 assert(which
< MAX_PIPELINE_STATISTICS
);
153 if (!_mesa_is_desktop_gl(ctx
) ||
154 !ctx
->Extensions
.ARB_pipeline_statistics_query
)
157 return &ctx
->Query
.pipeline_stats
[which
];
161 * Return pointer to the query object binding point for the given target and
163 * \return NULL if invalid target, else the address of binding point
165 static struct gl_query_object
**
166 get_query_binding_point(struct gl_context
*ctx
, GLenum target
, GLuint index
)
169 case GL_SAMPLES_PASSED_ARB
:
170 if (ctx
->Extensions
.ARB_occlusion_query
)
171 return &ctx
->Query
.CurrentOcclusionObject
;
174 case GL_ANY_SAMPLES_PASSED
:
175 if (ctx
->Extensions
.ARB_occlusion_query2
)
176 return &ctx
->Query
.CurrentOcclusionObject
;
179 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
180 if (ctx
->Extensions
.ARB_ES3_compatibility
181 || (ctx
->API
== API_OPENGLES2
&& ctx
->Version
>= 30))
182 return &ctx
->Query
.CurrentOcclusionObject
;
185 case GL_TIME_ELAPSED_EXT
:
186 if (ctx
->Extensions
.EXT_timer_query
)
187 return &ctx
->Query
.CurrentTimerObject
;
190 case GL_PRIMITIVES_GENERATED
:
191 if (ctx
->Extensions
.EXT_transform_feedback
)
192 return &ctx
->Query
.PrimitivesGenerated
[index
];
195 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
196 if (ctx
->Extensions
.EXT_transform_feedback
)
197 return &ctx
->Query
.PrimitivesWritten
[index
];
200 case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
:
201 if (ctx
->Extensions
.ARB_transform_feedback_overflow_query
)
202 return &ctx
->Query
.TransformFeedbackOverflow
[index
];
205 case GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
:
206 if (ctx
->Extensions
.ARB_transform_feedback_overflow_query
)
207 return &ctx
->Query
.TransformFeedbackOverflowAny
;
211 case GL_VERTICES_SUBMITTED_ARB
:
212 case GL_PRIMITIVES_SUBMITTED_ARB
:
213 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
214 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
215 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
216 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
217 return get_pipe_stats_binding_point(ctx
, target
);
219 case GL_GEOMETRY_SHADER_INVOCATIONS
:
220 /* GL_GEOMETRY_SHADER_INVOCATIONS is defined in a non-sequential order */
221 target
= GL_VERTICES_SUBMITTED_ARB
+ MAX_PIPELINE_STATISTICS
- 1;
223 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
224 if (_mesa_has_geometry_shaders(ctx
))
225 return get_pipe_stats_binding_point(ctx
, target
);
229 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
230 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
231 if (_mesa_has_tessellation(ctx
))
232 return get_pipe_stats_binding_point(ctx
, target
);
236 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
237 if (_mesa_has_compute_shaders(ctx
))
238 return get_pipe_stats_binding_point(ctx
, target
);
248 * Create $n query objects and store them in *ids. Make them of type $target
249 * if dsa is set. Called from _mesa_GenQueries() and _mesa_CreateQueries().
252 create_queries(struct gl_context
*ctx
, GLenum target
, GLsizei n
, GLuint
*ids
,
255 const char *func
= dsa
? "glGenQueries" : "glCreateQueries";
258 if (MESA_VERBOSE
& VERBOSE_API
)
259 _mesa_debug(ctx
, "%s(%d)\n", func
, n
);
262 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", func
);
266 first
= _mesa_HashFindFreeKeyBlock(ctx
->Query
.QueryObjects
, n
);
269 for (i
= 0; i
< n
; i
++) {
270 struct gl_query_object
*q
271 = ctx
->Driver
.NewQueryObject(ctx
, first
+ i
);
273 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s", func
);
276 /* Do the equivalent of binding the buffer with a target */
278 q
->EverBound
= GL_TRUE
;
281 _mesa_HashInsertLocked(ctx
->Query
.QueryObjects
, first
+ i
, q
);
287 _mesa_GenQueries(GLsizei n
, GLuint
*ids
)
289 GET_CURRENT_CONTEXT(ctx
);
290 create_queries(ctx
, 0, n
, ids
, false);
294 _mesa_CreateQueries(GLenum target
, GLsizei n
, GLuint
*ids
)
296 GET_CURRENT_CONTEXT(ctx
);
299 case GL_SAMPLES_PASSED
:
300 case GL_ANY_SAMPLES_PASSED
:
301 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE
:
302 case GL_TIME_ELAPSED
:
304 case GL_PRIMITIVES_GENERATED
:
305 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
306 case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
:
307 case GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
:
310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCreateQueries(invalid target = %s)",
311 _mesa_enum_to_string(target
));
315 create_queries(ctx
, target
, n
, ids
, true);
320 _mesa_DeleteQueries(GLsizei n
, const GLuint
*ids
)
323 GET_CURRENT_CONTEXT(ctx
);
324 FLUSH_VERTICES(ctx
, 0);
326 if (MESA_VERBOSE
& VERBOSE_API
)
327 _mesa_debug(ctx
, "glDeleteQueries(%d)\n", n
);
330 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteQueriesARB(n < 0)");
334 for (i
= 0; i
< n
; i
++) {
336 struct gl_query_object
*q
= _mesa_lookup_query_object(ctx
, ids
[i
]);
339 struct gl_query_object
**bindpt
;
340 bindpt
= get_query_binding_point(ctx
, q
->Target
, q
->Stream
);
341 assert(bindpt
); /* Should be non-null for active q. */
345 q
->Active
= GL_FALSE
;
346 ctx
->Driver
.EndQuery(ctx
, q
);
348 _mesa_HashRemoveLocked(ctx
->Query
.QueryObjects
, ids
[i
]);
349 ctx
->Driver
.DeleteQuery(ctx
, q
);
357 _mesa_IsQuery(GLuint id
)
359 struct gl_query_object
*q
;
361 GET_CURRENT_CONTEXT(ctx
);
362 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
364 if (MESA_VERBOSE
& VERBOSE_API
)
365 _mesa_debug(ctx
, "glIsQuery(%u)\n", id
);
370 q
= _mesa_lookup_query_object(ctx
, id
);
378 query_error_check_index(struct gl_context
*ctx
, GLenum target
, GLuint index
)
381 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
382 case GL_PRIMITIVES_GENERATED
:
383 case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
:
384 if (index
>= ctx
->Const
.MaxVertexStreams
) {
385 _mesa_error(ctx
, GL_INVALID_VALUE
,
386 "glBeginQueryIndexed(index>=MaxVertexStreams)");
392 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBeginQueryIndexed(index>0)");
400 _mesa_BeginQueryIndexed(GLenum target
, GLuint index
, GLuint id
)
402 struct gl_query_object
*q
, **bindpt
;
403 GET_CURRENT_CONTEXT(ctx
);
405 if (MESA_VERBOSE
& VERBOSE_API
)
406 _mesa_debug(ctx
, "glBeginQueryIndexed(%s, %u, %u)\n",
407 _mesa_enum_to_string(target
), index
, id
);
409 if (!query_error_check_index(ctx
, target
, index
))
412 FLUSH_VERTICES(ctx
, 0);
414 bindpt
= get_query_binding_point(ctx
, target
, index
);
416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBeginQuery{Indexed}(target)");
420 /* From the GL_ARB_occlusion_query spec:
422 * "If BeginQueryARB is called while another query is already in
423 * progress with the same target, an INVALID_OPERATION error is
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glBeginQuery{Indexed}(target=%s is active)",
429 _mesa_enum_to_string(target
));
434 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBeginQuery{Indexed}(id==0)");
438 q
= _mesa_lookup_query_object(ctx
, id
);
440 if (ctx
->API
!= API_OPENGL_COMPAT
) {
441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
442 "glBeginQuery{Indexed}(non-gen name)");
445 /* create new object */
446 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
448 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBeginQuery{Indexed}");
451 _mesa_HashInsertLocked(ctx
->Query
.QueryObjects
, id
, q
);
455 /* pre-existing object */
457 _mesa_error(ctx
, GL_INVALID_OPERATION
,
458 "glBeginQuery{Indexed}(query already active)");
462 /* Section 2.14 Asynchronous Queries, page 84 of the OpenGL ES 3.0.4
465 * "BeginQuery generates an INVALID_OPERATION error if any of the
466 * following conditions hold: [...] id is the name of an
467 * existing query object whose type does not match target; [...]
469 * Similar wording exists in the OpenGL 4.5 spec, section 4.2. QUERY
470 * OBJECTS AND ASYNCHRONOUS QUERIES, page 43.
472 if (q
->EverBound
&& q
->Target
!= target
) {
473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
474 "glBeginQuery{Indexed}(target mismatch)");
479 /* This possibly changes the target of a buffer allocated by
480 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
483 * "CreateQueries adds a <target>, so strictly speaking the <target>
484 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
485 * isn't a selector, so we decided not to change it."
487 * Updating the target of the query object should be acceptable, so let's
495 q
->EverBound
= GL_TRUE
;
498 /* XXX should probably refcount query objects */
501 ctx
->Driver
.BeginQuery(ctx
, q
);
506 _mesa_EndQueryIndexed(GLenum target
, GLuint index
)
508 struct gl_query_object
*q
, **bindpt
;
509 GET_CURRENT_CONTEXT(ctx
);
511 if (MESA_VERBOSE
& VERBOSE_API
)
512 _mesa_debug(ctx
, "glEndQueryIndexed(%s, %u)\n",
513 _mesa_enum_to_string(target
), index
);
515 if (!query_error_check_index(ctx
, target
, index
))
518 FLUSH_VERTICES(ctx
, 0);
520 bindpt
= get_query_binding_point(ctx
, target
, index
);
522 _mesa_error(ctx
, GL_INVALID_ENUM
, "glEndQuery{Indexed}(target)");
526 /* XXX should probably refcount query objects */
529 /* Check for GL_ANY_SAMPLES_PASSED vs GL_SAMPLES_PASSED. */
530 if (q
&& q
->Target
!= target
) {
531 _mesa_error(ctx
, GL_INVALID_OPERATION
,
532 "glEndQuery(target=%s with active query of target %s)",
533 _mesa_enum_to_string(target
),
534 _mesa_enum_to_string(q
->Target
));
540 if (!q
|| !q
->Active
) {
541 _mesa_error(ctx
, GL_INVALID_OPERATION
,
542 "glEndQuery{Indexed}(no matching glBeginQuery{Indexed})");
546 q
->Active
= GL_FALSE
;
547 ctx
->Driver
.EndQuery(ctx
, q
);
551 _mesa_BeginQuery(GLenum target
, GLuint id
)
553 _mesa_BeginQueryIndexed(target
, 0, id
);
557 _mesa_EndQuery(GLenum target
)
559 _mesa_EndQueryIndexed(target
, 0);
563 _mesa_QueryCounter(GLuint id
, GLenum target
)
565 struct gl_query_object
*q
;
566 GET_CURRENT_CONTEXT(ctx
);
568 if (MESA_VERBOSE
& VERBOSE_API
)
569 _mesa_debug(ctx
, "glQueryCounter(%u, %s)\n", id
,
570 _mesa_enum_to_string(target
));
573 if (target
!= GL_TIMESTAMP
) {
574 _mesa_error(ctx
, GL_INVALID_ENUM
, "glQueryCounter(target)");
579 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id==0)");
583 q
= _mesa_lookup_query_object(ctx
, id
);
585 /* XXX the Core profile should throw INVALID_OPERATION here */
587 /* create new object */
588 q
= ctx
->Driver
.NewQueryObject(ctx
, id
);
590 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glQueryCounter");
593 _mesa_HashInsertLocked(ctx
->Query
.QueryObjects
, id
, q
);
596 if (q
->Target
&& q
->Target
!= GL_TIMESTAMP
) {
597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
598 "glQueryCounter(id has an invalid target)");
604 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glQueryCounter(id is active)");
608 /* This possibly changes the target of a buffer allocated by
609 * CreateQueries. Issue 39) in the ARB_direct_state_access extension states
612 * "CreateQueries adds a <target>, so strictly speaking the <target>
613 * command isn't needed for BeginQuery/EndQuery, but in the end, this also
614 * isn't a selector, so we decided not to change it."
616 * Updating the target of the query object should be acceptable, so let's
623 q
->EverBound
= GL_TRUE
;
625 if (ctx
->Driver
.QueryCounter
) {
626 ctx
->Driver
.QueryCounter(ctx
, q
);
628 /* QueryCounter is implemented using EndQuery without BeginQuery
629 * in drivers. This is actually Direct3D and Gallium convention.
631 ctx
->Driver
.EndQuery(ctx
, q
);
637 _mesa_GetQueryIndexediv(GLenum target
, GLuint index
, GLenum pname
,
640 struct gl_query_object
*q
= NULL
, **bindpt
= NULL
;
641 GET_CURRENT_CONTEXT(ctx
);
643 if (MESA_VERBOSE
& VERBOSE_API
)
644 _mesa_debug(ctx
, "glGetQueryIndexediv(%s, %u, %s)\n",
645 _mesa_enum_to_string(target
),
647 _mesa_enum_to_string(pname
));
649 if (!query_error_check_index(ctx
, target
, index
))
652 if (target
== GL_TIMESTAMP
) {
653 if (!ctx
->Extensions
.ARB_timer_query
) {
654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQueryARB(target)");
659 bindpt
= get_query_binding_point(ctx
, target
, index
);
661 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(target)");
669 case GL_QUERY_COUNTER_BITS_ARB
:
671 case GL_SAMPLES_PASSED
:
672 *params
= ctx
->Const
.QueryCounterBits
.SamplesPassed
;
674 case GL_ANY_SAMPLES_PASSED
:
675 /* The minimum value of this is 1 if it's nonzero, and the value
676 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
681 case GL_TIME_ELAPSED
:
682 *params
= ctx
->Const
.QueryCounterBits
.TimeElapsed
;
685 *params
= ctx
->Const
.QueryCounterBits
.Timestamp
;
687 case GL_PRIMITIVES_GENERATED
:
688 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
;
690 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
:
691 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesWritten
;
693 case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
:
694 case GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
:
695 /* The minimum value of this is 1 if it's nonzero, and the value
696 * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
701 case GL_VERTICES_SUBMITTED_ARB
:
702 *params
= ctx
->Const
.QueryCounterBits
.VerticesSubmitted
;
704 case GL_PRIMITIVES_SUBMITTED_ARB
:
705 *params
= ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
;
707 case GL_VERTEX_SHADER_INVOCATIONS_ARB
:
708 *params
= ctx
->Const
.QueryCounterBits
.VsInvocations
;
710 case GL_TESS_CONTROL_SHADER_PATCHES_ARB
:
711 *params
= ctx
->Const
.QueryCounterBits
.TessPatches
;
713 case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB
:
714 *params
= ctx
->Const
.QueryCounterBits
.TessInvocations
;
716 case GL_GEOMETRY_SHADER_INVOCATIONS
:
717 *params
= ctx
->Const
.QueryCounterBits
.GsInvocations
;
719 case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB
:
720 *params
= ctx
->Const
.QueryCounterBits
.GsPrimitives
;
722 case GL_FRAGMENT_SHADER_INVOCATIONS_ARB
:
723 *params
= ctx
->Const
.QueryCounterBits
.FsInvocations
;
725 case GL_COMPUTE_SHADER_INVOCATIONS_ARB
:
726 *params
= ctx
->Const
.QueryCounterBits
.ComputeInvocations
;
728 case GL_CLIPPING_INPUT_PRIMITIVES_ARB
:
729 *params
= ctx
->Const
.QueryCounterBits
.ClInPrimitives
;
731 case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB
:
732 *params
= ctx
->Const
.QueryCounterBits
.ClOutPrimitives
;
736 "Unknown target in glGetQueryIndexediv(target = %s)",
737 _mesa_enum_to_string(target
));
742 case GL_CURRENT_QUERY_ARB
:
743 *params
= (q
&& q
->Target
== target
) ? q
->Id
: 0;
746 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetQuery{Indexed}iv(pname)");
752 _mesa_GetQueryiv(GLenum target
, GLenum pname
, GLint
*params
)
754 _mesa_GetQueryIndexediv(target
, 0, pname
, params
);
758 get_query_object(struct gl_context
*ctx
, const char *func
,
759 GLuint id
, GLenum pname
, GLenum ptype
,
760 struct gl_buffer_object
*buf
, intptr_t offset
)
762 struct gl_query_object
*q
= NULL
;
765 if (MESA_VERBOSE
& VERBOSE_API
)
766 _mesa_debug(ctx
, "%s(%u, %s)\n", func
, id
,
767 _mesa_enum_to_string(pname
));
770 q
= _mesa_lookup_query_object(ctx
, id
);
772 if (!q
|| q
->Active
|| !q
->EverBound
) {
773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
774 "%s(id=%d is invalid or active)", func
, id
);
778 if (buf
&& buf
!= ctx
->Shared
->NullBufferObj
) {
779 bool is_64bit
= ptype
== GL_INT64_ARB
||
780 ptype
== GL_UNSIGNED_INT64_ARB
;
781 if (!ctx
->Extensions
.ARB_query_buffer_object
) {
782 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(not supported)", func
);
785 if (buf
->Size
< offset
+ 4 * (is_64bit
? 2 : 1)) {
786 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(out of bounds)", func
);
791 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset is negative)", func
);
796 case GL_QUERY_RESULT
:
797 case GL_QUERY_RESULT_NO_WAIT
:
798 case GL_QUERY_RESULT_AVAILABLE
:
799 case GL_QUERY_TARGET
:
800 ctx
->Driver
.StoreQueryResult(ctx
, q
, buf
, offset
, pname
, ptype
);
804 /* fall through to get error below */
808 case GL_QUERY_RESULT
:
810 ctx
->Driver
.WaitQuery(ctx
, q
);
813 case GL_QUERY_RESULT_NO_WAIT
:
814 if (!ctx
->Extensions
.ARB_query_buffer_object
)
816 ctx
->Driver
.CheckQuery(ctx
, q
);
821 case GL_QUERY_RESULT_AVAILABLE
:
823 ctx
->Driver
.CheckQuery(ctx
, q
);
826 case GL_QUERY_TARGET
:
831 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)",
832 func
, _mesa_enum_to_string(pname
));
838 GLint
*param
= (GLint
*)offset
;
839 if (value
> 0x7fffffff)
845 case GL_UNSIGNED_INT
: {
846 GLuint
*param
= (GLuint
*)offset
;
847 if (value
> 0xffffffff)
854 case GL_UNSIGNED_INT64_ARB
: {
855 GLuint64EXT
*param
= (GLuint64EXT
*)offset
;
860 unreachable("unexpected ptype");
865 _mesa_GetQueryObjectiv(GLuint id
, GLenum pname
, GLint
*params
)
867 GET_CURRENT_CONTEXT(ctx
);
869 get_query_object(ctx
, "glGetQueryObjectiv",
870 id
, pname
, GL_INT
, ctx
->QueryBuffer
, (intptr_t)params
);
875 _mesa_GetQueryObjectuiv(GLuint id
, GLenum pname
, GLuint
*params
)
877 GET_CURRENT_CONTEXT(ctx
);
879 get_query_object(ctx
, "glGetQueryObjectuiv",
880 id
, pname
, GL_UNSIGNED_INT
,
881 ctx
->QueryBuffer
, (intptr_t)params
);
886 * New with GL_EXT_timer_query
889 _mesa_GetQueryObjecti64v(GLuint id
, GLenum pname
, GLint64EXT
*params
)
891 GET_CURRENT_CONTEXT(ctx
);
893 get_query_object(ctx
, "glGetQueryObjecti64v",
894 id
, pname
, GL_INT64_ARB
,
895 ctx
->QueryBuffer
, (intptr_t)params
);
900 * New with GL_EXT_timer_query
903 _mesa_GetQueryObjectui64v(GLuint id
, GLenum pname
, GLuint64EXT
*params
)
905 GET_CURRENT_CONTEXT(ctx
);
907 get_query_object(ctx
, "glGetQueryObjectui64v",
908 id
, pname
, GL_UNSIGNED_INT64_ARB
,
909 ctx
->QueryBuffer
, (intptr_t)params
);
913 * New with GL_ARB_query_buffer_object
916 _mesa_GetQueryBufferObjectiv(GLuint id
, GLuint buffer
, GLenum pname
,
919 struct gl_buffer_object
*buf
;
920 GET_CURRENT_CONTEXT(ctx
);
922 buf
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glGetQueryBufferObjectiv");
926 get_query_object(ctx
, "glGetQueryBufferObjectiv",
927 id
, pname
, GL_INT
, buf
, offset
);
932 _mesa_GetQueryBufferObjectuiv(GLuint id
, GLuint buffer
, GLenum pname
,
935 struct gl_buffer_object
*buf
;
936 GET_CURRENT_CONTEXT(ctx
);
938 buf
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glGetQueryBufferObjectuiv");
942 get_query_object(ctx
, "glGetQueryBufferObjectuiv",
943 id
, pname
, GL_UNSIGNED_INT
, buf
, offset
);
948 _mesa_GetQueryBufferObjecti64v(GLuint id
, GLuint buffer
, GLenum pname
,
951 struct gl_buffer_object
*buf
;
952 GET_CURRENT_CONTEXT(ctx
);
954 buf
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glGetQueryBufferObjecti64v");
958 get_query_object(ctx
, "glGetQueryBufferObjecti64v",
959 id
, pname
, GL_INT64_ARB
, buf
, offset
);
964 _mesa_GetQueryBufferObjectui64v(GLuint id
, GLuint buffer
, GLenum pname
,
967 struct gl_buffer_object
*buf
;
968 GET_CURRENT_CONTEXT(ctx
);
970 buf
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glGetQueryBufferObjectui64v");
974 get_query_object(ctx
, "glGetQueryBufferObjectui64v",
975 id
, pname
, GL_UNSIGNED_INT64_ARB
, buf
, offset
);
980 * Allocate/init the context state related to query objects.
983 _mesa_init_queryobj(struct gl_context
*ctx
)
985 ctx
->Query
.QueryObjects
= _mesa_NewHashTable();
986 ctx
->Query
.CurrentOcclusionObject
= NULL
;
988 ctx
->Const
.QueryCounterBits
.SamplesPassed
= 64;
989 ctx
->Const
.QueryCounterBits
.TimeElapsed
= 64;
990 ctx
->Const
.QueryCounterBits
.Timestamp
= 64;
991 ctx
->Const
.QueryCounterBits
.PrimitivesGenerated
= 64;
992 ctx
->Const
.QueryCounterBits
.PrimitivesWritten
= 64;
994 ctx
->Const
.QueryCounterBits
.VerticesSubmitted
= 64;
995 ctx
->Const
.QueryCounterBits
.PrimitivesSubmitted
= 64;
996 ctx
->Const
.QueryCounterBits
.VsInvocations
= 64;
997 ctx
->Const
.QueryCounterBits
.TessPatches
= 64;
998 ctx
->Const
.QueryCounterBits
.TessInvocations
= 64;
999 ctx
->Const
.QueryCounterBits
.GsInvocations
= 64;
1000 ctx
->Const
.QueryCounterBits
.GsPrimitives
= 64;
1001 ctx
->Const
.QueryCounterBits
.FsInvocations
= 64;
1002 ctx
->Const
.QueryCounterBits
.ComputeInvocations
= 64;
1003 ctx
->Const
.QueryCounterBits
.ClInPrimitives
= 64;
1004 ctx
->Const
.QueryCounterBits
.ClOutPrimitives
= 64;
1009 * Callback for deleting a query object. Called by _mesa_HashDeleteAll().
1012 delete_queryobj_cb(GLuint id
, void *data
, void *userData
)
1014 struct gl_query_object
*q
= (struct gl_query_object
*) data
;
1015 struct gl_context
*ctx
= (struct gl_context
*)userData
;
1016 ctx
->Driver
.DeleteQuery(ctx
, q
);
1021 * Free the context state related to query objects.
1024 _mesa_free_queryobj_data(struct gl_context
*ctx
)
1026 _mesa_HashDeleteAll(ctx
->Query
.QueryObjects
, delete_queryobj_cb
, ctx
);
1027 _mesa_DeleteHashTable(ctx
->Query
.QueryObjects
);