zink: add a param to check_batch_completion for toggling lock-taking

need this to avoid deadlocks

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11965>
This commit is contained in:
Mike Blumenkrantz
2021-06-09 14:12:13 -04:00
committed by Marge Bot
parent e7f958d841
commit 0dc77c8aa5
3 changed files with 9 additions and 6 deletions

View File

@@ -691,7 +691,7 @@ zink_batch_usage_check_completion(struct zink_context *ctx, const struct zink_ba
return true; return true;
if (zink_batch_usage_is_unflushed(u)) if (zink_batch_usage_is_unflushed(u))
return false; return false;
return zink_check_batch_completion(ctx, u->usage); return zink_check_batch_completion(ctx, u->usage, false);
} }
void void

View File

@@ -2631,7 +2631,7 @@ zink_wait_on_batch(struct zink_context *ctx, uint32_t batch_id)
} }
bool bool
zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id) zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id, bool have_lock)
{ {
assert(ctx->batch.state); assert(ctx->batch.state);
if (!batch_id) if (!batch_id)
@@ -2649,7 +2649,8 @@ zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id)
} }
struct zink_fence *fence; struct zink_fence *fence;
simple_mtx_lock(&ctx->batch_mtx); if (!have_lock)
simple_mtx_lock(&ctx->batch_mtx);
if (ctx->last_fence && batch_id == zink_batch_state(ctx->last_fence)->fence.batch_id) if (ctx->last_fence && batch_id == zink_batch_state(ctx->last_fence)->fence.batch_id)
fence = ctx->last_fence; fence = ctx->last_fence;
@@ -2657,13 +2658,15 @@ zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id)
struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&ctx->batch_states, batch_id, (void*)(uintptr_t)batch_id); struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&ctx->batch_states, batch_id, (void*)(uintptr_t)batch_id);
/* if we can't find it, it either must have finished already or is on a different context */ /* if we can't find it, it either must have finished already or is on a different context */
if (!he) { if (!he) {
simple_mtx_unlock(&ctx->batch_mtx); if (!have_lock)
simple_mtx_unlock(&ctx->batch_mtx);
/* return compare against last_finished, since this has info from all contexts */ /* return compare against last_finished, since this has info from all contexts */
return zink_screen_check_last_finished(zink_screen(ctx->base.screen), batch_id); return zink_screen_check_last_finished(zink_screen(ctx->base.screen), batch_id);
} }
fence = he->data; fence = he->data;
} }
simple_mtx_unlock(&ctx->batch_mtx); if (!have_lock)
simple_mtx_unlock(&ctx->batch_mtx);
assert(fence); assert(fence);
if (zink_screen(ctx->base.screen)->threaded && if (zink_screen(ctx->base.screen)->threaded &&
!util_queue_fence_is_signalled(&zink_batch_state(fence)->flush_completed)) !util_queue_fence_is_signalled(&zink_batch_state(fence)->flush_completed))

View File

@@ -328,7 +328,7 @@ void
zink_wait_on_batch(struct zink_context *ctx, uint32_t batch_id); zink_wait_on_batch(struct zink_context *ctx, uint32_t batch_id);
bool bool
zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id); zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id, bool have_lock);
void void
zink_flush_queue(struct zink_context *ctx); zink_flush_queue(struct zink_context *ctx);