zink: fix longstanding issue with active batch state recycling

the previous code could recycle a currently-submitting state by hitting
a race condition where zink_screen_check_last_finished(batch_id) returned
true because batch_id was 0

this can no longer recycle the current batch, but the race should still be
eliminated for consistency: check 'submitted' since this guarantees batch_id
is valid

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27729>
(cherry picked from commit 3283415bbd9d291a20a2e02e1a76f6b1b4984eda)
This commit is contained in:
Mike Blumenkrantz 2024-02-21 11:04:51 -05:00 committed by Eric Engestrom
parent 2728e5f2cc
commit ab000d7951
2 changed files with 6 additions and 3 deletions

View file

@ -314,7 +314,7 @@
"description": "zink: fix longstanding issue with active batch state recycling",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -460,8 +460,11 @@ get_batch_state(struct zink_context *ctx, struct zink_batch *batch)
}
/* states are stored sequentially, so if the first one doesn't work, none of them will */
if (!bs && ctx->batch_states && ctx->batch_states->next) {
if (zink_screen_check_last_finished(screen, ctx->batch_states->fence.batch_id) ||
find_unused_state(ctx->batch_states)) {
/* only a submitted state can be reused */
if (p_atomic_read(&ctx->batch_states->fence.submitted) &&
/* a submitted state must have completed before it can be reused */
(zink_screen_check_last_finished(screen, ctx->batch_states->fence.batch_id) ||
p_atomic_read(&ctx->batch_states->fence.completed))) {
bs = ctx->batch_states;
pop_batch_state(ctx);
}