kk: Reset queries through compute dispatch instead of queue writes

Signed-off-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40849>
This commit is contained in:
Aitor Camacho 2026-04-08 15:54:57 +09:00 committed by Marge Bot
parent 4e00e1c3d0
commit d8b9ee99fa
2 changed files with 54 additions and 27 deletions

View file

@ -1,7 +1,7 @@
/*
* Copyright © 2022 Collabora Ltd. and Red Hat Inc.
* Copyright © 2024 Alyssa Rosenzweig
* Copyright © 2024 Valve Corporation
* Copyright 2022 Collabora Ltd. and Red Hat Inc.
* Copyright 2024 Alyssa Rosenzweig
* Copyright 2024 Valve Corporation
* Copyright 2025 LunarG, Inc.
* Copyright 2025 Google LLC
* SPDX-License-Identifier: MIT
@ -10,6 +10,45 @@
#include "kk_query.h"
static inline global uint64_t *
query_report(global uint64_t *results, global uint16_t *oq_index,
uint reports_per_query, uint query)
{
/* For occlusion queries, results[] points to the device global heap. We
* need to remap indices according to the query pool's allocation.
*/
uint result_index = oq_index ? oq_index[query] : query;
return results + (result_index * reports_per_query);
}
/**
* Goes through a series of consecutive query indices in the given pool,
* setting all element values to 0 and emitting them as available.
*/
KERNEL(1)
libkk_reset_query(global uint64_t *availability, global uint64_t *results,
global uint16_t *oq_index, uint32_t first_query,
uint16_t reports_per_query, int set_available)
{
uint32_t query = first_query + cl_global_id.x;
uint64_t value = 0;
if (availability) {
availability[query] = set_available;
} else {
value = set_available ? 0 : UINT64_MAX;
}
global uint64_t *report =
query_report(results, oq_index, reports_per_query, query);
/* XXX: is this supposed to happen on the begin? */
for (unsigned j = 0; j < reports_per_query; ++j) {
report[j] = value;
}
}
KERNEL(1)
libkk_write_u64(global struct libkk_imm_write *write_array)
{

View file

@ -216,35 +216,24 @@ kk_ResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
}
}
/**
* Goes through a series of consecutive query indices in the given pool,
* setting all element values to 0 and emitting them as available.
*/
static void
emit_zero_queries(struct kk_cmd_buffer *cmd, struct kk_query_pool *pool,
uint32_t first_index, uint32_t num_queries,
bool set_available)
{
struct kk_device *dev = kk_cmd_buffer_device(cmd);
mtl_buffer *buffer = pool->bo->map;
struct libkk_reset_query_args info = {
.availability = kk_has_available(pool) ? pool->bo->gpu : 0,
.results = pool->oq_queries ? dev->occlusion_queries.bo->gpu
: pool->bo->gpu + pool->query_start,
.oq_index = pool->oq_queries ? pool->bo->gpu + pool->query_start : 0,
for (uint32_t i = 0; i < num_queries; i++) {
uint64_t report = kk_query_report_addr(dev, pool, first_index + i);
uint64_t value = 0;
if (kk_has_available(pool)) {
uint64_t available = kk_query_available_addr(pool, first_index + i);
kk_cmd_write(cmd, buffer, available, set_available);
} else {
value = set_available ? 0u : UINT64_MAX;
}
/* XXX: is this supposed to happen on the begin? */
for (unsigned j = 0; j < kk_reports_per_query(pool); ++j) {
kk_cmd_write(cmd, buffer,
report + (j * sizeof(struct kk_query_report)), value);
}
}
.first_query = first_index,
.reports_per_query = kk_reports_per_query(pool),
.set_available = set_available,
};
struct mtl_size grid = {.x = num_queries, .y = 1u, .z = 1u};
libkk_reset_query_struct(cmd, grid, false, info);
}
VKAPI_ATTR void VKAPI_CALL
@ -255,11 +244,10 @@ kk_CmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
VK_FROM_HANDLE(kk_query_pool, pool, queryPool);
/* Need to flush other availabilities just in case there is a reset after it
* was made available but the writes have not propagated yet. Need to avoid
* data rances in the writes. This is save to do sice vkCmdResetQueryPool
* data races in the writes. This is save to do sice vkCmdResetQueryPool
* cannot be called when a render pass is active. */
upload_queue_writes(cmd);
emit_zero_queries(cmd, pool, firstQuery, queryCount, false);
upload_queue_writes(cmd);
}
VKAPI_ATTR void VKAPI_CALL