From: Mike Blumenkrantz Date: Wed, 9 Sep 2020 17:31:49 +0000 (-0400) Subject: zink: break out query result buffer copying into util function X-Git-Tag: upstream/21.2.3~7496 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da051b06a7c1ff086518ed253fb666cd3f0e4438;p=platform%2Fupstream%2Fmesa.git zink: break out query result buffer copying into util function we can reuse this a bit Reviewed-by: Dave Airlie Part-of: --- diff --git a/src/gallium/drivers/zink/zink_query.c b/src/gallium/drivers/zink/zink_query.c index 4b613c4..ae76439 100644 --- a/src/gallium/drivers/zink/zink_query.c +++ b/src/gallium/drivers/zink/zink_query.c @@ -456,6 +456,26 @@ force_cpu_read(struct zink_context *ctx, struct pipe_query *pquery, bool wait, e } static void +copy_results_to_buffer(struct zink_context *ctx, struct zink_query *query, struct zink_resource *res, unsigned offset, int num_results, VkQueryResultFlags flags) +{ + unsigned query_id = query->last_start; + struct zink_batch *batch = get_batch_for_query(ctx, query, true); + unsigned base_result_size = (flags & VK_QUERY_RESULT_64_BIT) ? sizeof(uint64_t) : sizeof(uint32_t); + unsigned result_size = base_result_size * num_results; + if (flags & VK_QUERY_RESULT_WITH_AVAILABILITY_BIT) + result_size += base_result_size; + /* if it's a single query that doesn't need special handling, we can copy it and be done */ + zink_batch_reference_resource_rw(batch, res, true); + zink_resource_buffer_barrier(batch, res, VK_ACCESS_TRANSFER_WRITE_BIT, 0); + util_range_add(&res->base, &res->valid_buffer_range, offset, offset + result_size); + vkCmdCopyQueryPoolResults(batch->cmdbuf, query->query_pool, query_id, num_results, res->buffer, + offset, 0, flags); + /* this is required for compute batch sync and will be removed later */ + if (batch->batch_id != ZINK_COMPUTE_BATCH_ID) + ctx->base.flush(&ctx->base, NULL, PIPE_FLUSH_HINT_FINISH); +} + +static void reset_pool(struct zink_context *ctx, struct zink_batch *batch, struct zink_query *q) { /* This command must only be called outside of a render pass instance @@ -712,9 +732,8 @@ zink_render_condition(struct pipe_context *pctx, int num_results = query->curr_query - query->last_start; if (query->type != PIPE_QUERY_PRIMITIVES_GENERATED && !is_so_overflow_query(query)) { - vkCmdCopyQueryPoolResults(batch->cmdbuf, query->query_pool, query->last_start, num_results, - res->buffer, 0, 0, flags); - zink_batch_reference_resource_rw(batch, res, true); + copy_results_to_buffer(ctx, query, res, 0, num_results, flags); + batch = zink_curr_batch(ctx); } else { /* these need special handling */ force_cpu_read(ctx, pquery, true, PIPE_QUERY_TYPE_U32, pres, 0); @@ -785,7 +804,6 @@ zink_get_query_result_resource(struct pipe_context *pctx, pipe_buffer_unmap(pctx, transfer); return; } - util_range_add(&res->base, &res->valid_buffer_range, offset, result_size); unsigned fences = p_atomic_read(&query->fences); if (!is_time_query(query) && (!fences || wait)) { @@ -796,15 +814,7 @@ zink_get_query_result_resource(struct pipe_context *pctx, query->type != PIPE_QUERY_OCCLUSION_PREDICATE && query->type != PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE && !is_so_overflow_query(query)) { - struct zink_batch *batch = get_batch_for_query(ctx, query, true); - /* if it's a single query that doesn't need special handling, we can copy it and be done */ - zink_batch_reference_resource_rw(batch, res, true); - zink_resource_buffer_barrier(batch, res, VK_ACCESS_TRANSFER_WRITE_BIT, 0); - vkCmdCopyQueryPoolResults(batch->cmdbuf, query->query_pool, query_id, 1, res->buffer, - offset, 0, size_flags); - /* this is required for compute batch sync and will be removed later */ - if (batch->batch_id != ZINK_COMPUTE_BATCH_ID) - pctx->flush(pctx, NULL, PIPE_FLUSH_HINT_FINISH); + copy_results_to_buffer(ctx, query, res, offset, 1, size_flags); return; } }