zink: track tc fences better

tc fence lifetimes can exceed the lifetimes of their parent contexts,
which means they can be destroyed after mfence->fence has been destroyed

to avoid invalid memory access on a destroyed fence, store all the assigned
tc fences into an array on the real fence and then use that to unset fence
pointers on any outstanding tc fences

fixes flakiness in dEQP-EGL.functional.sharing.gles2.multithread.random_egl_sync.images.texsubimage2d.12

in caselist:
dEQP-EGL.functional.query_context.get_current_surface.rgba4444_pbuffer
dEQP-EGL.functional.create_surface.platform_window.rgba5551_depth_no_stencil
dEQP-EGL.functional.query_surface.simple.pbuffer.rgb888_depth_no_stencil
dEQP-EGL.functional.color_clears.multi_context.gles2.rgb888_pixmap
dEQP-EGL.functional.color_clears.multi_context.gles1_gles2.rgba8888_window
dEQP-EGL.functional.color_clears.multi_context.gles1_gles2_gles3.rgb888_window
dEQP-EGL.functional.render.multi_thread.gles2_gles3.rgba5551_pbuffer
dEQP-EGL.functional.sharing.gles2.multithread.random_egl_sync.buffers.buffersubdata.3
dEQP-EGL.functional.sharing.gles2.multithread.random_egl_sync.programs.link.6
dEQP-EGL.functional.sharing.gles2.multithread.random_egl_sync.images.texsubimage2d.12

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21843>
This commit is contained in:
Mike Blumenkrantz
2023-03-10 12:48:30 -05:00
committed by Marge Bot
parent 7edae456e2
commit 9df68c633e
4 changed files with 14 additions and 1 deletions

View File

@@ -270,6 +270,12 @@ zink_batch_state_destroy(struct zink_screen *screen, struct zink_batch_state *bs
util_dynarray_fini(&bs->bindless_releases[1]);
util_dynarray_fini(&bs->acquires);
util_dynarray_fini(&bs->acquire_flags);
unsigned num_mfences = util_dynarray_num_elements(&bs->fence.mfences, void *);
struct zink_tc_fence **mfence = bs->fence.mfences.data;
for (unsigned i = 0; i < num_mfences; i++) {
mfence[i]->fence = NULL;
}
util_dynarray_fini(&bs->fence.mfences);
zink_batch_descriptor_deinit(screen, bs);
ralloc_free(bs);
}
@@ -326,6 +332,7 @@ create_batch_state(struct zink_context *ctx)
util_dynarray_init(&bs->bindless_releases[0], NULL);
util_dynarray_init(&bs->bindless_releases[1], NULL);
util_dynarray_init(&bs->swapchain_obj, NULL);
util_dynarray_init(&bs->fence.mfences, NULL);
cnd_init(&bs->usage.flush);
mtx_init(&bs->usage.mtx, mtx_plain);

View File

@@ -4146,10 +4146,13 @@ zink_flush(struct pipe_context *pctx,
*pfence = (struct pipe_fence_handle *)mfence;
}
assert(!mfence->fence);
mfence->fence = fence;
mfence->sem = export_sem;
if (fence)
if (fence) {
mfence->submit_count = submit_count;
util_dynarray_append(&fence->mfences, struct zink_tc_fence *, mfence);
}
if (deferred_fence) {
assert(fence);

View File

@@ -40,6 +40,8 @@
static void
destroy_fence(struct zink_screen *screen, struct zink_tc_fence *mfence)
{
if (mfence->fence)
util_dynarray_delete_unordered(&mfence->fence->mfences, struct zink_tc_fence *, mfence);
mfence->fence = NULL;
tc_unflushed_batch_token_reference(&mfence->tc_token, NULL);
if (mfence->sem)

View File

@@ -246,6 +246,7 @@ struct zink_fence {
uint64_t batch_id;
bool submitted;
bool completed;
struct util_dynarray mfences;
};