st/mesa: add a notify_before_flush callback param to flush
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Wed, 27 Nov 2019 10:22:11 +0000 (11:22 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tue, 10 Dec 2019 08:25:28 +0000 (09:25 +0100)
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 <marek.olsak@amd.com>
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/dri2.c
src/gallium/state_trackers/dri/dri_context.c
src/gallium/state_trackers/dri/dri_drawable.c
src/gallium/state_trackers/dri/dri_helpers.c
src/gallium/state_trackers/dri/drisw.c
src/gallium/state_trackers/glx/xlib/xm_api.c
src/gallium/state_trackers/wgl/stw_context.c
src/gallium/state_trackers/wgl/stw_framebuffer.c
src/gallium/targets/haiku-softpipe/GalliumContext.cpp
src/mesa/state_tracker/st_manager.c

index 9fd36447c7b33b28098438edb6c1ae50b0e595eb..258da8fdeaffd4b07a7793f81d715b3e28bb122f 100644 (file)
@@ -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.
index 1f72c9d11c56e7c647838454c8bc385ebf2cfac8..50b91cdaf2bffe480d5fd6efa4124290e6675f73 100644 (file)
@@ -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);
    }
index af9e3325f98ec7a6ce711382bda4c80bc33e7d38..6efca4f8f809af05aa58debad84b0674d9287c0e 100644 (file)
@@ -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);
 }
index 88eb6c01c1bc78492efe75ee6bfae21d9e2f2483..64eed15b2db58f2edf35987f75b63f5b779c1893 100644 (file)
@@ -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) {
index 6753635ba6c18b0fb82dbff1a143c33bd9bd83a6..d4de8cdc59facc68ad0c4b7d65a7d1d1f7ffa410 100644 (file)
@@ -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);
index bf7ee6f9471354c0fd6e4299299ffb31ecb1d6e5..e3fb3f1b9254fa89fec0c14e5b815cdb16e3b2d8 100644 (file)
@@ -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);
index 64eee53f2b88bca38516415f68b5fa0a6d72e526..3e9d313138b812488cc766e5f8bcd04c0927a358 100644 (file)
@@ -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);
index a9e4024c236d01232fc2e656083fce1ff0f67e55..9003f43530a64712311c0694714e15a53dc8a39a 100644 (file)
@@ -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);
          }
       }
    }
index 232ab1d230599d3a7c947f6f796b96b4f1ab6990..3af69ab554eb8a61278b314c6e0f73887214865b 100644 (file)
@@ -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);
       }
    }
 
index d9be790463090f0d463c9a462cde2cbbd3a6f70c..13378d1a375b1e8d595358a576774eca41662a67 100644 (file)
@@ -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;
index a194f529a2997405a8382e9f08fda36ded541da0..d1c5a0b52ad0c09744749f9a32eb579b975ab81c 100644 (file)
@@ -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) {