From bb77745681e179b53ea64da7bc1987b57643b7b0 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 25 Nov 2014 17:52:27 +0000 Subject: [PATCH] meta: Fix saving the results of the current occlusion query When restoring the current state in _mesa_meta_end it was previously trying to copy the on-going sample count of the current occlusion query into the new query after restarting it so that the driver will continue adding to the previous value. This wouldn't work for two reasons. Firstly, the query might not be ready yet so the Result member will usually be zero. Secondly the saved query is stored as a pointer to the query object, not a copy of the struct, so it is actually restarting the exact same object. Copying the result value is just copying between identical addresses with no effect. The call to _mesa_BeginQuery will have always reset it back to zero. This patch fixes it by making it actually wait for the query object to be ready before grabbing the previous result. The downside of doing this is that it could introduce a stall but I think this situation is unlikely so it might not matter too much. A better solution might be to introduce a real suspend/resume mechanism to the driver interface. This could be implemented in the i965 driver by saving the depth count multiple times like it does in the i945 driver. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88248 Reviewed-by: Carl Worth Cc: "10.5" --- src/mesa/drivers/common/meta.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c index bb0073074e7..3636ee83b9b 100644 --- a/src/mesa/drivers/common/meta.c +++ b/src/mesa/drivers/common/meta.c @@ -827,15 +827,18 @@ _mesa_meta_end(struct gl_context *ctx) const GLbitfield state = save->SavedState; int i; - /* After starting a new occlusion query, initialize the results to the - * values saved previously. The driver will then continue to increment - * these values. - */ + /* Grab the result of the old occlusion query before starting it again. The + * old result is added to the result of the new query so the driver will + * continue adding where it left off. */ if (state & MESA_META_OCCLUSION_QUERY) { if (save->CurrentOcclusionObject) { - _mesa_BeginQuery(save->CurrentOcclusionObject->Target, - save->CurrentOcclusionObject->Id); - ctx->Query.CurrentOcclusionObject->Result = save->CurrentOcclusionObject->Result; + struct gl_query_object *q = save->CurrentOcclusionObject; + GLuint64EXT result; + if (!q->Ready) + ctx->Driver.WaitQuery(ctx, q); + result = q->Result; + _mesa_BeginQuery(q->Target, q->Id); + ctx->Query.CurrentOcclusionObject->Result += result; } } -- 2.30.2