mesa: treat unsupported queries as dummies

It's legal in OpenGL to start a query even if the result will have zero
valid bits. It's not enough to just report zero bits, We need to also
prevent calling down into the driver with these invalid queries.

Because ARB_ES3_compatibility adds ANY_SAMPLES_PASSED and
ANY_SAMPLES_PASSED_CONSERVATIVE to the set of queries that support zero
bits, we also need to check for the corresponding indices.

Fixes: 0186e9e1c5 ("mesa: always support occlusion queries")
Reviewed-by: Soroush Kashani <soroush.kashani@imgtec.com>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19750>
This commit is contained in:
Erik Faye-Lund 2022-11-15 15:41:22 +01:00 committed by Marge Bot
parent c70eec86ef
commit 1b1e8873fe
3 changed files with 35 additions and 6 deletions

View File

@ -124,6 +124,21 @@ target_to_index(const struct gl_query_object *q)
return 0;
}
static bool
query_type_is_dummy(struct gl_context *ctx, unsigned type)
{
struct st_context *st = st_context(ctx);
switch (type) {
case PIPE_QUERY_OCCLUSION_COUNTER:
case PIPE_QUERY_OCCLUSION_PREDICATE:
case PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE:
return !st->has_occlusion_query;
default:
break;
}
return false;
}
static void
begin_query(struct gl_context *ctx, struct gl_query_object *q)
{
@ -198,7 +213,12 @@ begin_query(struct gl_context *ctx, struct gl_query_object *q)
if (q->pq_begin)
ret = pipe->end_query(pipe, q->pq_begin);
} else {
if (!q->pq) {
if (query_type_is_dummy(ctx, type)) {
/* starting a dummy-query; ignore */
assert(!q->pq);
q->type = type;
ret = true;
} else if (!q->pq) {
q->pq = pipe->create_query(pipe, type, target_to_index(q));
q->type = type;
}
@ -237,7 +257,10 @@ end_query(struct gl_context *ctx, struct gl_query_object *q)
q->type = PIPE_QUERY_TIMESTAMP;
}
if (q->pq)
if (query_type_is_dummy(ctx, q->type)) {
/* ending a dummy-query; ignore */
ret = true;
} else if (q->pq)
ret = pipe->end_query(pipe, q->pq);
if (!ret) {
@ -258,8 +281,10 @@ get_query_result(struct pipe_context *pipe,
union pipe_query_result data;
if (!q->pq) {
/* Only needed in case we failed to allocate the gallium query earlier.
* Return TRUE so we don't spin on this forever.
/* Needed in case we failed to allocate the gallium query earlier, or
* in the case of a dummy query.
*
* Return TRUE in either case so we don't spin on this forever.
*/
return TRUE;
}
@ -430,8 +455,9 @@ store_query_result(struct gl_context *ctx, struct gl_query_object *q,
index = 0;
}
pipe->get_query_result_resource(pipe, q->pq, flags, result_type, index,
buf->buffer, offset);
if (q->pq)
pipe->get_query_result_resource(pipe, q->pq, flags, result_type, index,
buf->buffer, offset);
}
static struct gl_query_object **

View File

@ -625,6 +625,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe,
screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT);
st->has_indirect_partial_stride =
screen->get_param(screen, PIPE_CAP_MULTI_DRAW_INDIRECT_PARTIAL_STRIDE);
st->has_occlusion_query =
screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY);
st->has_single_pipe_stat =
screen->get_param(screen, PIPE_CAP_QUERY_PIPELINE_STATISTICS_SINGLE);
st->has_indep_blend_func =

View File

@ -156,6 +156,7 @@ struct st_context
boolean has_half_float_packing;
boolean has_multi_draw_indirect;
boolean has_indirect_partial_stride;
boolean has_occlusion_query;
boolean has_single_pipe_stat;
boolean has_indep_blend_func;
boolean needs_rgb_dst_alpha_override;