Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
zink: flag batch usage on swapchain images
Browse files Browse the repository at this point in the history
while swapchains themselves are protected against early deletion
during presentation, there is nothing protecting them from
deletion while they are rendering if a swapchain updates
while rendering but before presentation

to address this, add batch usage to swapchains which can be
checked during pruning to ensure a rendering swapchain isn't
pruned

Fixes: dc8c9d2 ("zink: prune old swapchains on present")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22962>
(cherry picked from commit 47d9eaa)
  • Loading branch information
zmike authored and 1ace committed May 25, 2023
1 parent 2bfaca8 commit 4afab8f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pick_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,7 @@
"description": "zink: flag batch usage on swapchain images",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "dc8c9d20568360d6756dcd62610d818991f479d8"
},
Expand Down
2 changes: 2 additions & 0 deletions src/gallium/drivers/zink/zink_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ reset_obj(struct zink_screen *screen, struct zink_batch_state *bs, struct zink_r
obj->view_prune_count = 0;
obj->view_prune_timeline = 0;
simple_mtx_unlock(&obj->view_lock);
if (obj->dt)
zink_kopper_prune_batch_usage(obj->dt, &bs->usage);
} else if (util_dynarray_num_elements(&obj->views, VkBufferView) > MAX_VIEW_COUNT && !zink_bo_has_unflushed_usage(obj->bo)) {
/* avoid ballooning from too many views on always-used resources: */
simple_mtx_lock(&obj->view_lock);
Expand Down
30 changes: 29 additions & 1 deletion src/gallium/drivers/zink/zink_kopper.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ prune_old_swapchains(struct zink_screen *screen, struct kopper_displaytarget *cd
continue;
return;
}
struct zink_batch_usage *u = cswap->batch_uses;
if (!zink_screen_usage_check_completion(screen, u)) {
/* these can't ever be pruned */
if (!wait || zink_batch_usage_is_unflushed(u))
return;

zink_screen_timeline_wait(screen, u->usage, UINT64_MAX);
cswap->batch_uses = NULL;
}
cdt->old_swapchain = cswap->next;
destroy_swapchain(screen, cswap);
}
Expand Down Expand Up @@ -597,7 +606,9 @@ zink_kopper_acquire(struct zink_context *ctx, struct zink_resource *res, uint64_
} else if (is_swapchain_kill(ret)) {
kill_swapchain(ctx, res);
}
return !is_swapchain_kill(ret);
bool is_kill = is_swapchain_kill(ret);
zink_batch_usage_set(&cdt->swapchain->batch_uses, ctx->batch.state);
return !is_kill;
}

VkSemaphore
Expand Down Expand Up @@ -822,6 +833,7 @@ zink_kopper_acquire_readback(struct zink_context *ctx, struct zink_resource *res
res->base.b.width0 = ctx->swapchain_size.width;
res->base.b.height0 = ctx->swapchain_size.height;
}
zink_batch_usage_set(&cdt->swapchain->batch_uses, ctx->batch.state);
return true;
}

Expand Down Expand Up @@ -972,3 +984,19 @@ zink_kopper_query_buffer_age(struct pipe_context *pctx, struct pipe_resource *pr

return cdt->swapchain->images[res->obj->dt_idx].age;
}

static void
swapchain_prune_batch_usage(struct kopper_swapchain *cswap, const struct zink_batch_usage *u)
{
if (cswap->batch_uses == u)
cswap->batch_uses = NULL;
}

void
zink_kopper_prune_batch_usage(struct kopper_displaytarget *cdt, const struct zink_batch_usage *u)
{
struct kopper_swapchain *cswap = cdt->swapchain;
swapchain_prune_batch_usage(cswap, u);
for (cswap = cdt->old_swapchain; cswap; cswap = cswap->next)
swapchain_prune_batch_usage(cswap, u);
}
5 changes: 5 additions & 0 deletions src/gallium/drivers/zink/zink_kopper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
extern "C" {
#endif

struct zink_batch_usage;

struct kopper_swapchain_image {
bool init;
bool acquired;
Expand All @@ -56,6 +58,7 @@ struct kopper_swapchain {
unsigned num_acquires;
unsigned max_acquires;
unsigned async_presents;
struct zink_batch_usage *batch_uses;
struct kopper_swapchain_image *images;
};

Expand Down Expand Up @@ -146,6 +149,8 @@ void
zink_kopper_set_swap_interval(struct pipe_screen *pscreen, struct pipe_resource *pres, int interval);
int
zink_kopper_query_buffer_age(struct pipe_context *pctx, struct pipe_resource *pres);
void
zink_kopper_prune_batch_usage(struct kopper_displaytarget *cdt, const struct zink_batch_usage *u);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 4afab8f

Please sign in to comment.