zink: set VK_QUERY_RESULT_WAIT_BIT when copying to qbo
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 19 Apr 2022 20:01:35 +0000 (16:01 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 21 Apr 2022 00:04:27 +0000 (00:04 +0000)
according to spec, this ensures that drivers will accurately
return results relative to when the query was ended

cc: mesa-stable

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16049>

src/gallium/drivers/zink/zink_query.c

index 1b0c350..0772706 100644 (file)
@@ -768,7 +768,17 @@ update_qbo(struct zink_context *ctx, struct zink_query *q)
       copy_pool_results_to_buffer(ctx, q, start->vkq[i]->pool->query_pool, start->vkq[i]->query_id,
                                   zink_resource(qbo->buffers[i]),
                                   offset,
-                                  1, VK_QUERY_RESULT_64_BIT);
+                                  1,
+                                  /*
+                                     there is an implicit execution dependency from
+                                     each such query command to all query commands previously submitted to the same queue. There
+                                     is one significant exception to this; if the flags parameter of vkCmdCopyQueryPoolResults does not
+                                     include VK_QUERY_RESULT_WAIT_BIT, execution of vkCmdCopyQueryPoolResults may happen-before
+                                     the results of vkCmdEndQuery are available.
+
+                                   * - Chapter 18. Queries
+                                   */
+                                  VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
    }
 
    if (!is_timestamp)
@@ -1227,6 +1237,16 @@ zink_get_query_result_resource(struct pipe_context *pctx,
       return;
    }
 
+   /*
+      there is an implicit execution dependency from
+      each such query command to all query commands previously submitted to the same queue. There
+      is one significant exception to this; if the flags parameter of vkCmdCopyQueryPoolResults does not
+      include VK_QUERY_RESULT_WAIT_BIT, execution of vkCmdCopyQueryPoolResults may happen-before
+      the results of vkCmdEndQuery are available.
+
+    * - Chapter 18. Queries
+    */
+   size_flags |= VK_QUERY_RESULT_WAIT_BIT;
    if (!is_time_query(query) && !is_bool_query(query)) {
       if (num_queries == 1 && query->type != PIPE_QUERY_PRIMITIVES_GENERATED &&
                               query->type != PIPE_QUERY_PRIMITIVES_EMITTED &&