diff --git a/src/mesa/state_tracker/st_cb_syncobj.c b/src/mesa/state_tracker/st_cb_syncobj.c index 123925a..265bf10 100644 --- a/src/mesa/state_tracker/st_cb_syncobj.c +++ b/src/mesa/state_tracker/st_cb_syncobj.c @@ -59,9 +59,13 @@ static void st_delete_sync_object(struct gl_context *ctx, struct pipe_screen *screen = st_context(ctx)->pipe->screen; struct st_sync_object *so = (struct st_sync_object*)obj; + mtx_lock(&ctx->Shared->Mutex); + screen->fence_reference(screen, &so->fence, NULL); free(so->b.Label); free(so); + + mtx_unlock(&ctx->Shared->Mutex); } static void st_fence_sync(struct gl_context *ctx, struct gl_sync_object *obj, @@ -71,9 +75,14 @@ static void st_fence_sync(struct gl_context *ctx, struct gl_sync_object *obj, struct st_sync_object *so = (struct st_sync_object*)obj; assert(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0); + + mtx_lock(&ctx->Shared->Mutex); + assert(so->fence == NULL); pipe->flush(pipe, &so->fence, PIPE_FLUSH_DEFERRED); + + mtx_unlock(&ctx->Shared->Mutex); } static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj) @@ -81,17 +90,32 @@ static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj) struct pipe_context *pipe = st_context(ctx)->pipe; struct pipe_screen *screen = pipe->screen; struct st_sync_object *so = (struct st_sync_object*)obj; + struct pipe_fence_handle *fence = NULL; + boolean success; + + mtx_lock(&ctx->Shared->Mutex); + + screen->fence_reference(screen, &fence, so->fence); /* If the fence doesn't exist, assume it's signalled. */ - if (!so->fence) { + if (!fence) { so->b.StatusFlag = GL_TRUE; - return; + goto unlock; } - if (screen->fence_finish(screen, pipe, so->fence, 0)) { + mtx_unlock(&ctx->Shared->Mutex); + success = screen->fence_finish(screen, pipe, fence, 0); + mtx_lock(&ctx->Shared->Mutex); + + if (success) { screen->fence_reference(screen, &so->fence, NULL); so->b.StatusFlag = GL_TRUE; } + + screen->fence_reference(screen, &fence, NULL); + +unlock: + mtx_unlock(&ctx->Shared->Mutex); } static void st_client_wait_sync(struct gl_context *ctx, @@ -101,11 +125,17 @@ static void st_client_wait_sync(struct gl_context *ctx, struct pipe_context *pipe = st_context(ctx)->pipe; struct pipe_screen *screen = pipe->screen; struct st_sync_object *so = (struct st_sync_object*)obj; + struct pipe_fence_handle *fence = NULL; + boolean success; + + mtx_lock(&ctx->Shared->Mutex); + + screen->fence_reference(screen, &fence, so->fence); /* If the fence doesn't exist, assume it's signalled. */ - if (!so->fence) { + if (!fence) { so->b.StatusFlag = GL_TRUE; - return; + goto unlock; } /* Section 4.1.2 of OpenGL 4.5 (Compatibility Profile) says: @@ -120,11 +150,19 @@ static void st_client_wait_sync(struct gl_context *ctx, * Assume GL_SYNC_FLUSH_COMMANDS_BIT is always set, because applications * forget to set it. */ - if (so->fence && - screen->fence_finish(screen, pipe, so->fence, timeout)) { + mtx_unlock(&ctx->Shared->Mutex); + success = screen->fence_finish(screen, pipe, fence, timeout); + mtx_lock(&ctx->Shared->Mutex); + + if (success) { screen->fence_reference(screen, &so->fence, NULL); so->b.StatusFlag = GL_TRUE; } + + screen->fence_reference(screen, &fence, NULL); + +unlock: + mtx_unlock(&ctx->Shared->Mutex); } static void st_server_wait_sync(struct gl_context *ctx,