#include "context.h"
#include "enums.h"
#include "hash.h"
-#include "imports.h"
+
#include "queryobj.h"
#include "mtypes.h"
-#include "main/dispatch.h"
+#include "util/u_memory.h"
/**
/**
- * Delete a query object. Called via ctx->Driver.DeleteQuery().
+ * Delete a query object. Called via ctx->Driver.DeleteQuery(), if not
+ * overwritten by driver. In the latter case, called from the driver
+ * after all driver-specific clean-up has been done.
* Not removed from hash table here.
+ *
+ * \param ctx GL context to wich query object belongs.
+ * \param q query object due to be deleted.
*/
-static void
+void
_mesa_delete_query(struct gl_context *ctx, struct gl_query_object *q)
{
free(q->Label);
get_pipe_stats_binding_point(struct gl_context *ctx,
GLenum target)
{
- const int which = target - GL_VERTICES_SUBMITTED_ARB;
+ const int which = target - GL_VERTICES_SUBMITTED;
assert(which < MAX_PIPELINE_STATISTICS);
- if (!_mesa_is_desktop_gl(ctx) ||
- !ctx->Extensions.ARB_pipeline_statistics_query)
+ if (!_mesa_has_ARB_pipeline_statistics_query(ctx))
return NULL;
return &ctx->Query.pipeline_stats[which];
get_query_binding_point(struct gl_context *ctx, GLenum target, GLuint index)
{
switch (target) {
- case GL_SAMPLES_PASSED_ARB:
- if (ctx->Extensions.ARB_occlusion_query)
+ case GL_SAMPLES_PASSED:
+ if (_mesa_has_ARB_occlusion_query(ctx) ||
+ _mesa_has_ARB_occlusion_query2(ctx))
return &ctx->Query.CurrentOcclusionObject;
else
return NULL;
case GL_ANY_SAMPLES_PASSED:
- if (ctx->Extensions.ARB_occlusion_query2)
+ if (_mesa_has_ARB_occlusion_query2(ctx) ||
+ _mesa_has_EXT_occlusion_query_boolean(ctx))
return &ctx->Query.CurrentOcclusionObject;
else
return NULL;
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
- if (ctx->Extensions.ARB_ES3_compatibility
- || (ctx->API == API_OPENGLES2 && ctx->Version >= 30))
+ if (_mesa_has_ARB_ES3_compatibility(ctx) ||
+ _mesa_has_EXT_occlusion_query_boolean(ctx))
return &ctx->Query.CurrentOcclusionObject;
else
return NULL;
- case GL_TIME_ELAPSED_EXT:
- if (ctx->Extensions.EXT_timer_query)
+ case GL_TIME_ELAPSED:
+ if (_mesa_has_EXT_timer_query(ctx) ||
+ _mesa_has_EXT_disjoint_timer_query(ctx))
return &ctx->Query.CurrentTimerObject;
else
return NULL;
case GL_PRIMITIVES_GENERATED:
- if (ctx->Extensions.EXT_transform_feedback)
+ if (_mesa_has_EXT_transform_feedback(ctx) ||
+ _mesa_has_EXT_tessellation_shader(ctx) ||
+ _mesa_has_OES_geometry_shader(ctx))
return &ctx->Query.PrimitivesGenerated[index];
else
return NULL;
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
- if (ctx->Extensions.EXT_transform_feedback)
+ if (_mesa_has_EXT_transform_feedback(ctx) || _mesa_is_gles3(ctx))
return &ctx->Query.PrimitivesWritten[index];
else
return NULL;
+ case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW:
+ if (_mesa_has_ARB_transform_feedback_overflow_query(ctx))
+ return &ctx->Query.TransformFeedbackOverflow[index];
+ else
+ return NULL;
+ case GL_TRANSFORM_FEEDBACK_OVERFLOW:
+ if (_mesa_has_ARB_transform_feedback_overflow_query(ctx))
+ return &ctx->Query.TransformFeedbackOverflowAny;
+ else
+ return NULL;
- case GL_VERTICES_SUBMITTED_ARB:
- case GL_PRIMITIVES_SUBMITTED_ARB:
- case GL_VERTEX_SHADER_INVOCATIONS_ARB:
- case GL_FRAGMENT_SHADER_INVOCATIONS_ARB:
- case GL_CLIPPING_INPUT_PRIMITIVES_ARB:
- case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB:
+ case GL_VERTICES_SUBMITTED:
+ case GL_PRIMITIVES_SUBMITTED:
+ case GL_VERTEX_SHADER_INVOCATIONS:
+ case GL_FRAGMENT_SHADER_INVOCATIONS:
+ case GL_CLIPPING_INPUT_PRIMITIVES:
+ case GL_CLIPPING_OUTPUT_PRIMITIVES:
return get_pipe_stats_binding_point(ctx, target);
case GL_GEOMETRY_SHADER_INVOCATIONS:
/* GL_GEOMETRY_SHADER_INVOCATIONS is defined in a non-sequential order */
- target = GL_VERTICES_SUBMITTED_ARB + MAX_PIPELINE_STATISTICS - 1;
+ target = GL_VERTICES_SUBMITTED + MAX_PIPELINE_STATISTICS - 1;
/* fallthrough */
- case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
+ case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED:
if (_mesa_has_geometry_shaders(ctx))
return get_pipe_stats_binding_point(ctx, target);
else
return NULL;
- case GL_TESS_CONTROL_SHADER_PATCHES_ARB:
- case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB:
+ case GL_TESS_CONTROL_SHADER_PATCHES:
+ case GL_TESS_EVALUATION_SHADER_INVOCATIONS:
if (_mesa_has_tessellation(ctx))
return get_pipe_stats_binding_point(ctx, target);
else
return NULL;
- case GL_COMPUTE_SHADER_INVOCATIONS_ARB:
+ case GL_COMPUTE_SHADER_INVOCATIONS:
if (_mesa_has_compute_shaders(ctx))
return get_pipe_stats_binding_point(ctx, target);
else
q->EverBound = GL_TRUE;
}
ids[i] = first + i;
- _mesa_HashInsert(ctx->Query.QueryObjects, first + i, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, first + i, q);
}
}
}
case GL_TIMESTAMP:
case GL_PRIMITIVES_GENERATED:
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
+ case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW:
+ case GL_TRANSFORM_FEEDBACK_OVERFLOW:
break;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glCreateQueries(invalid target = %s)",
q->Active = GL_FALSE;
ctx->Driver.EndQuery(ctx, q);
}
- _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]);
+ _mesa_HashRemoveLocked(ctx->Query.QueryObjects, ids[i]);
ctx->Driver.DeleteQuery(ctx, q);
}
}
switch (target) {
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
case GL_PRIMITIVES_GENERATED:
+ case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW:
if (index >= ctx->Const.MaxVertexStreams) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glBeginQueryIndexed(index>=MaxVertexStreams)");
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBeginQuery{Indexed}");
return;
}
- _mesa_HashInsert(ctx->Query.QueryObjects, id, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q);
}
}
else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glQueryCounter");
return;
}
- _mesa_HashInsert(ctx->Query.QueryObjects, id, q);
+ _mesa_HashInsertLocked(ctx->Query.QueryObjects, id, q);
}
else {
if (q->Target && q->Target != GL_TIMESTAMP) {
if (!query_error_check_index(ctx, target, index))
return;
+ /* From the GL_EXT_occlusion_query_boolean spec:
+ *
+ * "The error INVALID_ENUM is generated if GetQueryivEXT is called where
+ * <pname> is not CURRENT_QUERY_EXT."
+ *
+ * Same rule is present also in ES 3.2 spec.
+ *
+ * EXT_disjoint_timer_query extends this with GL_QUERY_COUNTER_BITS.
+ */
+ if (_mesa_is_gles(ctx)) {
+ switch (pname) {
+ case GL_CURRENT_QUERY:
+ break;
+ case GL_QUERY_COUNTER_BITS:
+ if (_mesa_has_EXT_disjoint_timer_query(ctx))
+ break;
+ /* fallthrough */
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryivEXT(%s)",
+ _mesa_enum_to_string(pname));
+ }
+ }
+
if (target == GL_TIMESTAMP) {
- if (!ctx->Extensions.ARB_timer_query) {
+ if (!_mesa_has_ARB_timer_query(ctx) &&
+ !_mesa_has_EXT_disjoint_timer_query(ctx)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glGetQueryARB(target)");
return;
}
}
switch (pname) {
- case GL_QUERY_COUNTER_BITS_ARB:
+ case GL_QUERY_COUNTER_BITS:
switch (target) {
case GL_SAMPLES_PASSED:
*params = ctx->Const.QueryCounterBits.SamplesPassed;
break;
case GL_ANY_SAMPLES_PASSED:
+ case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
/* The minimum value of this is 1 if it's nonzero, and the value
* is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
* bits.
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
*params = ctx->Const.QueryCounterBits.PrimitivesWritten;
break;
- case GL_VERTICES_SUBMITTED_ARB:
+ case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW:
+ case GL_TRANSFORM_FEEDBACK_OVERFLOW:
+ /* The minimum value of this is 1 if it's nonzero, and the value
+ * is only ever GL_TRUE or GL_FALSE, so no sense in reporting more
+ * bits.
+ */
+ *params = 1;
+ break;
+ case GL_VERTICES_SUBMITTED:
*params = ctx->Const.QueryCounterBits.VerticesSubmitted;
break;
- case GL_PRIMITIVES_SUBMITTED_ARB:
+ case GL_PRIMITIVES_SUBMITTED:
*params = ctx->Const.QueryCounterBits.PrimitivesSubmitted;
break;
- case GL_VERTEX_SHADER_INVOCATIONS_ARB:
+ case GL_VERTEX_SHADER_INVOCATIONS:
*params = ctx->Const.QueryCounterBits.VsInvocations;
break;
- case GL_TESS_CONTROL_SHADER_PATCHES_ARB:
+ case GL_TESS_CONTROL_SHADER_PATCHES:
*params = ctx->Const.QueryCounterBits.TessPatches;
break;
- case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB:
+ case GL_TESS_EVALUATION_SHADER_INVOCATIONS:
*params = ctx->Const.QueryCounterBits.TessInvocations;
break;
case GL_GEOMETRY_SHADER_INVOCATIONS:
*params = ctx->Const.QueryCounterBits.GsInvocations;
break;
- case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
+ case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED:
*params = ctx->Const.QueryCounterBits.GsPrimitives;
break;
- case GL_FRAGMENT_SHADER_INVOCATIONS_ARB:
+ case GL_FRAGMENT_SHADER_INVOCATIONS:
*params = ctx->Const.QueryCounterBits.FsInvocations;
break;
- case GL_COMPUTE_SHADER_INVOCATIONS_ARB:
+ case GL_COMPUTE_SHADER_INVOCATIONS:
*params = ctx->Const.QueryCounterBits.ComputeInvocations;
break;
- case GL_CLIPPING_INPUT_PRIMITIVES_ARB:
+ case GL_CLIPPING_INPUT_PRIMITIVES:
*params = ctx->Const.QueryCounterBits.ClInPrimitives;
break;
- case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB:
+ case GL_CLIPPING_OUTPUT_PRIMITIVES:
*params = ctx->Const.QueryCounterBits.ClOutPrimitives;
break;
default:
break;
}
break;
- case GL_CURRENT_QUERY_ARB:
+ case GL_CURRENT_QUERY:
*params = (q && q->Target == target) ? q->Id : 0;
break;
default:
return;
}
- if (buf && buf != ctx->Shared->NullBufferObj) {
+ /* From GL_EXT_occlusion_query_boolean spec:
+ *
+ * "Accepted by the <pname> parameter of GetQueryObjectivEXT and
+ * GetQueryObjectuivEXT:
+ *
+ * QUERY_RESULT_EXT 0x8866
+ * QUERY_RESULT_AVAILABLE_EXT 0x8867"
+ *
+ * Same rule is present also in ES 3.2 spec.
+ */
+ if (_mesa_is_gles(ctx) &&
+ (pname != GL_QUERY_RESULT && pname != GL_QUERY_RESULT_AVAILABLE)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(%s)", func,
+ _mesa_enum_to_string(pname));
+ return;
+ }
+
+ if (buf) {
bool is_64bit = ptype == GL_INT64_ARB ||
ptype == GL_UNSIGNED_INT64_ARB;
- if (!ctx->Extensions.ARB_query_buffer_object) {
+ if (!_mesa_has_ARB_query_buffer_object(ctx)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(not supported)", func);
return;
}
return;
}
+ if (offset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset is negative)", func);
+ return;
+ }
+
switch (pname) {
case GL_QUERY_RESULT:
case GL_QUERY_RESULT_NO_WAIT:
value = q->Result;
break;
case GL_QUERY_RESULT_NO_WAIT:
- if (!ctx->Extensions.ARB_query_buffer_object)
+ if (!_mesa_has_ARB_query_buffer_object(ctx))
goto invalid_enum;
ctx->Driver.CheckQuery(ctx, q);
if (!q->Ready)
return;
}
- /* TODO: Have the driver be required to handle this fixup. */
- if (q->Target == GL_ANY_SAMPLES_PASSED ||
- q->Target == GL_ANY_SAMPLES_PASSED_CONSERVATIVE)
- value = !!value;
-
switch (ptype) {
case GL_INT: {
GLint *param = (GLint *)offset;