From cc0d0afe3b06e628fdd5576da07c50a15f859e98 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 27 Nov 2019 11:22:11 +0100 Subject: [PATCH] st/mesa: add a notify_before_flush callback param to flush MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The new callback is called right before the flush is done to allow users of st->flush to do some work after all the previous work has been flushed. This will be used by dri_flush in the next commit. Reviewed-by: Marek Olšák --- src/gallium/include/state_tracker/st_api.h | 4 +++- src/gallium/state_trackers/dri/dri2.c | 4 ++-- src/gallium/state_trackers/dri/dri_context.c | 2 +- src/gallium/state_trackers/dri/dri_drawable.c | 4 ++-- src/gallium/state_trackers/dri/dri_helpers.c | 4 ++-- src/gallium/state_trackers/dri/drisw.c | 4 ++-- src/gallium/state_trackers/glx/xlib/xm_api.c | 6 +++--- src/gallium/state_trackers/wgl/stw_context.c | 5 +++-- src/gallium/state_trackers/wgl/stw_framebuffer.c | 2 +- src/gallium/targets/haiku-softpipe/GalliumContext.cpp | 6 +++--- src/mesa/state_tracker/st_manager.c | 7 ++++++- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h index 9fd36447c7b..258da8fdeaf 100644 --- a/src/gallium/include/state_tracker/st_api.h +++ b/src/gallium/include/state_tracker/st_api.h @@ -389,7 +389,9 @@ struct st_context_iface * Flush all drawing from context to the pipe also flushes the pipe. */ void (*flush)(struct st_context_iface *stctxi, unsigned flags, - struct pipe_fence_handle **fence); + struct pipe_fence_handle **fence, + void (*notify_before_flush_cb) (void*), + void* notify_before_flush_cb_args); /** * Replace the texture image of a texture object at the specified level. diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 1f72c9d11c5..50b91cdaf2b 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -1517,11 +1517,11 @@ dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src, if (flush_flag == __BLIT_FLAG_FLUSH) { pipe->flush_resource(pipe, dst->texture); - ctx->st->flush(ctx->st, 0, NULL); + ctx->st->flush(ctx->st, 0, NULL, NULL, NULL); } else if (flush_flag == __BLIT_FLAG_FINISH) { screen = dri_screen(ctx->sPriv)->base.screen; pipe->flush_resource(pipe, dst->texture); - ctx->st->flush(ctx->st, 0, &fence); + ctx->st->flush(ctx->st, 0, &fence, NULL, NULL); (void) screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE); screen->fence_reference(screen, &fence, NULL); } diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index af9e3325f98..6efca4f8f80 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -241,7 +241,7 @@ dri_destroy_context(__DRIcontext * cPriv) * to avoid having to add code elsewhere to cope with flushing a * partially destroyed context. */ - ctx->st->flush(ctx->st, 0, NULL); + ctx->st->flush(ctx->st, 0, NULL, NULL, NULL); ctx->st->destroy(ctx->st); free(ctx); } diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 88eb6c01c1b..64eed15b2db 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -499,7 +499,7 @@ dri_flush(__DRIcontext *cPriv, struct pipe_screen *screen = drawable->screen->base.screen; struct pipe_fence_handle *new_fence = NULL; - st->flush(st, flush_flags, &new_fence); + st->flush(st, flush_flags, &new_fence, args.ctx ? notify_before_flush_cb : NULL, &args); /* throttle on the previous fence */ if (drawable->throttle_fence) { @@ -509,7 +509,7 @@ dri_flush(__DRIcontext *cPriv, drawable->throttle_fence = new_fence; } else if (flags & (__DRI2_FLUSH_DRAWABLE | __DRI2_FLUSH_CONTEXT)) { - st->flush(st, flush_flags, NULL); + st->flush(st, flush_flags, NULL, NULL, NULL); } if (drawable) { diff --git a/src/gallium/state_trackers/dri/dri_helpers.c b/src/gallium/state_trackers/dri/dri_helpers.c index 6753635ba6c..d4de8cdc59f 100644 --- a/src/gallium/state_trackers/dri/dri_helpers.c +++ b/src/gallium/state_trackers/dri/dri_helpers.c @@ -97,7 +97,7 @@ dri2_create_fence(__DRIcontext *_ctx) if (!fence) return NULL; - stapi->flush(stapi, 0, &fence->pipe_fence); + stapi->flush(stapi, 0, &fence->pipe_fence, NULL, NULL); if (!fence->pipe_fence) { FREE(fence); @@ -117,7 +117,7 @@ dri2_create_fence_fd(__DRIcontext *_ctx, int fd) if (fd == -1) { /* exporting driver created fence, flush: */ - stapi->flush(stapi, ST_FLUSH_FENCE_FD, &fence->pipe_fence); + stapi->flush(stapi, ST_FLUSH_FENCE_FD, &fence->pipe_fence, NULL, NULL); } else { /* importing a foreign fence fd: */ ctx->create_fence_fd(ctx, &fence->pipe_fence, fd, PIPE_FD_TYPE_NATIVE_SYNC); diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c index bf7ee6f9471..e3fb3f1b925 100644 --- a/src/gallium/state_trackers/dri/drisw.c +++ b/src/gallium/state_trackers/dri/drisw.c @@ -249,7 +249,7 @@ drisw_swap_buffers(__DRIdrawable *dPriv) if (ctx->hud) hud_run(ctx->hud, ctx->st->cso_context, ptex); - ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL); + ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL); drisw_copy_to_front(dPriv, ptex); } @@ -272,7 +272,7 @@ drisw_copy_sub_buffer(__DRIdrawable *dPriv, int x, int y, if (ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]) pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]); - ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL); + ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL); u_box_2d(x, dPriv->h - y - h, w, h, &box); drisw_present_texture(dPriv, ptex, &box); diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 64eee53f2b8..3e9d313138b 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -1358,7 +1358,7 @@ void XMesaSwapBuffers( XMesaBuffer b ) } if (xmctx && xmctx->xm_buffer == b) { - xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL); + xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL); } xmesa_swap_st_framebuffer(b->stfb); @@ -1373,7 +1373,7 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) { XMesaContext xmctx = XMesaGetCurrentContext(); - xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL); + xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL); xmesa_copy_st_framebuffer(b->stfb, ST_ATTACHMENT_BACK_LEFT, ST_ATTACHMENT_FRONT_LEFT, @@ -1388,7 +1388,7 @@ void XMesaFlush( XMesaContext c ) XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display); struct pipe_fence_handle *fence = NULL; - c->st->flush(c->st, ST_FLUSH_FRONT, &fence); + c->st->flush(c->st, ST_FLUSH_FRONT, &fence, NULL, NULL); if (fence) { xmdpy->screen->fence_finish(xmdpy->screen, NULL, fence, PIPE_TIMEOUT_INFINITE); diff --git a/src/gallium/state_trackers/wgl/stw_context.c b/src/gallium/state_trackers/wgl/stw_context.c index a9e4024c236..9003f43530a 100644 --- a/src/gallium/state_trackers/wgl/stw_context.c +++ b/src/gallium/state_trackers/wgl/stw_context.c @@ -448,10 +448,11 @@ stw_make_current(HDC hDrawDC, HDC hReadDC, DHGLRC dhglrc) if (old_ctx->shared) { struct pipe_fence_handle *fence = NULL; old_ctx->st->flush(old_ctx->st, - ST_FLUSH_FRONT | ST_FLUSH_WAIT, &fence); + ST_FLUSH_FRONT | ST_FLUSH_WAIT, &fence, + NULL, NULL); } else { - old_ctx->st->flush(old_ctx->st, ST_FLUSH_FRONT, NULL); + old_ctx->st->flush(old_ctx->st, ST_FLUSH_FRONT, NULL, NULL, NULL); } } } diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 232ab1d2305..3af69ab554e 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -647,7 +647,7 @@ DrvSwapBuffers(HDC hdc) if (ctx->current_framebuffer == fb) { /* flush current context */ - ctx->st->flush(ctx->st, ST_FLUSH_END_OF_FRAME, NULL); + ctx->st->flush(ctx->st, ST_FLUSH_END_OF_FRAME, NULL, NULL, NULL); } } diff --git a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp index d9be7904630..13378d1a375 100644 --- a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp +++ b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp @@ -243,7 +243,7 @@ GalliumContext::DestroyContext(context_id contextID) return; if (fContext[contextID]->st) { - fContext[contextID]->st->flush(fContext[contextID]->st, 0, NULL); + fContext[contextID]->st->flush(fContext[contextID]->st, 0, NULL, NULL, NULL); fContext[contextID]->st->destroy(fContext[contextID]->st); } @@ -297,7 +297,7 @@ GalliumContext::SetCurrentContext(Bitmap *bitmap, context_id contextID) if (oldContextID > 0 && oldContextID != contextID) { fContext[oldContextID]->st->flush(fContext[oldContextID]->st, - ST_FLUSH_FRONT, NULL); + ST_FLUSH_FRONT, NULL, NULL, NULL); } // We need to lock and unlock framebuffers before accessing them @@ -333,7 +333,7 @@ GalliumContext::SwapBuffers(context_id contextID) ERROR("%s: context not found\n", __func__); return B_ERROR; } - context->st->flush(context->st, ST_FLUSH_FRONT, NULL); + context->st->flush(context->st, ST_FLUSH_FRONT, NULL, NULL, NULL); struct hgl_buffer* buffer = hgl_st_framebuffer(context->draw->stfbi); pipe_surface* surface = buffer->surface; diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c index a194f529a29..d1c5a0b52ad 100644 --- a/src/mesa/state_tracker/st_manager.c +++ b/src/mesa/state_tracker/st_manager.c @@ -649,7 +649,9 @@ st_framebuffers_purge(struct st_context *st) static void st_context_flush(struct st_context_iface *stctxi, unsigned flags, - struct pipe_fence_handle **fence) + struct pipe_fence_handle **fence, + void (*before_flush_cb) (void*), + void* args) { struct st_context *st = (struct st_context *) stctxi; unsigned pipe_flags = 0; @@ -661,6 +663,9 @@ st_context_flush(struct st_context_iface *stctxi, unsigned flags, FLUSH_VERTICES(st->ctx, 0); FLUSH_CURRENT(st->ctx, 0); + /* Notify the caller that we're ready to flush */ + if (before_flush_cb) + before_flush_cb(args); st_flush(st, fence, pipe_flags); if ((flags & ST_FLUSH_WAIT) && fence && *fence) { -- 2.30.2