zink: break out unflushed batch waiting into separate function/mechanism

this is useful on its own

no functional changes

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36954>
(cherry picked from commit c9746103f5)
This commit is contained in:
Mike Blumenkrantz 2025-08-23 07:30:12 -04:00 committed by Eric Engestrom
parent a93b1275cc
commit af83e46d28
5 changed files with 39 additions and 8 deletions

View file

@ -4694,7 +4694,7 @@
"description": "zink: break out unflushed batch waiting into separate function/mechanism",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -1157,18 +1157,19 @@ zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_ba
return zink_check_batch_completion(ctx, u->usage);
}
static void
batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned submit_count, bool trywait)
ALWAYS_INLINE bool
zink_batch_usage_unflushed_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned submit_count, bool trywait)
{
if (!zink_batch_usage_exists(u))
return;
return true;
/* this batch state was already completed and reset */
if (u->submit_count - submit_count > 1)
return;
return true;
if (zink_batch_usage_is_unflushed(u)) {
if (likely(u == &ctx->bs->usage))
if (likely(u == &ctx->bs->usage)) {
ctx->base.flush(&ctx->base, NULL, PIPE_FLUSH_HINT_FINISH);
else { //multi-context
return true;
} else { //multi-context
mtx_lock(&u->mtx);
if (trywait) {
struct timespec ts = {0, 10000};
@ -1178,7 +1179,19 @@ batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned
mtx_unlock(&u->mtx);
}
}
zink_wait_on_batch(ctx, u->usage);
return !u->unflushed;
}
static void
batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned submit_count, bool trywait)
{
if (!zink_batch_usage_exists(u))
return;
/* this batch state was already completed and reset */
if (u->submit_count - submit_count > 1)
return;
if (zink_batch_usage_unflushed_wait(ctx, u, submit_count, trywait))
zink_wait_on_batch(ctx, u->usage);
}
void

View file

@ -121,6 +121,9 @@ zink_screen_usage_check_completion_fast(struct zink_screen *screen, const struct
bool
zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_batch_usage *u);
bool
zink_batch_usage_unflushed_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned submit_count, bool trywait);
void
zink_batch_usage_wait(struct zink_context *ctx, struct zink_batch_usage *u, unsigned submit_count);

View file

@ -187,6 +187,15 @@ zink_bo_usage_check_completion_fast(struct zink_screen *screen, struct zink_bo *
return true;
}
static ALWAYS_INLINE void
zink_bo_usage_unflushed_wait(struct zink_context *ctx, struct zink_bo *bo, enum zink_resource_access access)
{
if (access & ZINK_RESOURCE_ACCESS_READ)
zink_batch_usage_unflushed_wait(ctx, bo->reads.u, bo->reads.submit_count, false);
if (access & ZINK_RESOURCE_ACCESS_WRITE)
zink_batch_usage_unflushed_wait(ctx, bo->writes.u, bo->writes.submit_count, false);
}
static ALWAYS_INLINE void
zink_bo_usage_wait(struct zink_context *ctx, struct zink_bo *bo, enum zink_resource_access access)
{

View file

@ -150,6 +150,12 @@ zink_resource_usage_check_completion_fast(struct zink_screen *screen, struct zin
return zink_bo_usage_check_completion_fast(screen, res->obj->bo, access);
}
static inline void
zink_resource_usage_unflushed_wait(struct zink_context *ctx, struct zink_resource *res, enum zink_resource_access access)
{
zink_bo_usage_unflushed_wait(ctx, res->obj->bo, access);
}
static inline void
zink_resource_usage_try_wait(struct zink_context *ctx, struct zink_resource *res, enum zink_resource_access access)
{