From 1b1e8873fe90e878f014140b3b6bd1e5dbfb5a4c Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Tue, 15 Nov 2022 15:41:22 +0100 Subject: [PATCH] mesa: treat unsupported queries as dummies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 0186e9e1c51 ("mesa: always support occlusion queries") Reviewed-by: Soroush Kashani Reviewed-by: Christian Gmeiner Reviewed-by: Marek Olšák Part-of: --- src/mesa/main/queryobj.c | 38 ++++++++++++++++++++++++----- src/mesa/state_tracker/st_context.c | 2 ++ src/mesa/state_tracker/st_context.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/queryobj.c b/src/mesa/main/queryobj.c index 2ec09855843..b7c1fb77cc4 100644 --- a/src/mesa/main/queryobj.c +++ b/src/mesa/main/queryobj.c @@ -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 ** diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 71fffcc4bff..9573b5f8679 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -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 = diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 7ff3baa0e6d..11937cbc532 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -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;