gallium: add a pipe_context parameter to fence_finish

required by glClientWaitSync (GL 4.5 Core spec) that can optionally flush
the context

Reviewed-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
This commit is contained in:
Marek Olšák
2016-08-06 16:41:42 +02:00
parent c6043e7d54
commit 54272e18a6
39 changed files with 73 additions and 46 deletions

View File

@@ -467,12 +467,10 @@ Flushing
PIPE_FLUSH_END_OF_FRAME: Whether the flush marks the end of frame.
PIPE_FLUSH_DEFERRED: It is not required to flush right away, but it is required
to return a valid fence. The behavior of fence_finish or any other call isn't
changed. The only side effect can be that fence_finish will wait a little
longer. No guidance is given as to how drivers should implement fence_finish
with deferred flushes. If some drivers can't do deferred flushes safely, they
should just ignore the flag.
to return a valid fence. If fence_finish is called with the returned fence
and the context is still unflushed, and the ctx parameter of fence_finish is
equal to the context where the fence was created, fence_finish will flush
the context.
``flush_resource``

View File

@@ -548,7 +548,7 @@ dd_flush_and_check_hang(struct dd_context *dctx,
if (!fence)
return false;
idle = screen->fence_finish(screen, fence, timeout_ms * 1000000);
idle = screen->fence_finish(screen, NULL, fence, timeout_ms * 1000000);
screen->fence_reference(screen, &fence, NULL);
if (!idle)
fprintf(stderr, "dd: GPU hang detected!\n");

View File

@@ -263,12 +263,14 @@ dd_screen_fence_reference(struct pipe_screen *_screen,
static boolean
dd_screen_fence_finish(struct pipe_screen *_screen,
struct pipe_context *_ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{
struct pipe_screen *screen = dd_screen(_screen)->screen;
struct pipe_context *ctx = _ctx ? dd_context(_ctx)->pipe : NULL;
return screen->fence_finish(screen, fence, timeout);
return screen->fence_finish(screen, ctx, fence, timeout);
}

View File

@@ -51,6 +51,7 @@ fd_screen_fence_ref(struct pipe_screen *pscreen,
}
boolean fd_screen_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -35,6 +35,7 @@ void fd_screen_fence_ref(struct pipe_screen *pscreen,
struct pipe_fence_handle **ptr,
struct pipe_fence_handle *pfence);
boolean fd_screen_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *pfence,
uint64_t timeout);
struct pipe_fence_handle * fd_fence_create(struct pipe_context *pctx,

View File

@@ -500,6 +500,7 @@ i915_fence_reference(struct pipe_screen *screen,
static boolean
i915_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -696,6 +696,7 @@ ilo_screen_fence_reference(struct pipe_screen *screen,
static boolean
ilo_screen_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -82,7 +82,8 @@ llvmpipe_finish( struct pipe_context *pipe,
struct pipe_fence_handle *fence = NULL;
llvmpipe_flush(pipe, &fence, reason);
if (fence) {
pipe->screen->fence_finish(pipe->screen, fence, PIPE_TIMEOUT_INFINITE);
pipe->screen->fence_finish(pipe->screen, NULL, fence,
PIPE_TIMEOUT_INFINITE);
pipe->screen->fence_reference(pipe->screen, &fence, NULL);
}
}

View File

@@ -572,6 +572,7 @@ llvmpipe_fence_reference(struct pipe_screen *screen,
*/
static boolean
llvmpipe_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence_handle,
uint64_t timeout)
{

View File

@@ -70,6 +70,7 @@ nouveau_screen_fence_ref(struct pipe_screen *pscreen,
static boolean
nouveau_screen_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *pfence,
uint64_t timeout)
{

View File

@@ -698,6 +698,7 @@ static void r300_fence_reference(struct pipe_screen *screen,
}
static boolean r300_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -954,6 +954,7 @@ static void r600_fence_reference(struct pipe_screen *screen,
}
static boolean r600_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -215,7 +215,7 @@ static bool r600_query_sw_get_result(struct r600_common_context *rctx,
return true;
case PIPE_QUERY_GPU_FINISHED: {
struct pipe_screen *screen = rctx->b.screen;
result->b = screen->fence_finish(screen, query->fence,
result->b = screen->fence_finish(screen, NULL, query->fence,
wait ? PIPE_TIMEOUT_INFINITE : 0);
return result->b;
}

View File

@@ -229,15 +229,15 @@ rbug_screen_fence_reference(struct pipe_screen *_screen,
static boolean
rbug_screen_fence_finish(struct pipe_screen *_screen,
struct pipe_context *_ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{
struct rbug_screen *rb_screen = rbug_screen(_screen);
struct pipe_screen *screen = rb_screen->screen;
struct pipe_context *ctx = _ctx ? rbug_context(_ctx)->pipe : NULL;
return screen->fence_finish(screen,
fence,
timeout);
return screen->fence_finish(screen, ctx, fence, timeout);
}
boolean

View File

@@ -42,6 +42,7 @@ softpipe_fence_reference(struct pipe_screen *screen,
static boolean
softpipe_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -153,7 +153,7 @@ softpipe_flush_resource(struct pipe_context *pipe,
* This is for illustrative purposes only, as softpipe does not
* have fences.
*/
pipe->screen->fence_finish(pipe->screen, fence,
pipe->screen->fence_finish(pipe->screen, NULL, fence,
PIPE_TIMEOUT_INFINITE);
pipe->screen->fence_reference(pipe->screen, &fence, NULL);
}

View File

@@ -348,7 +348,7 @@ void svga_context_flush( struct svga_context *svga,
if (SVGA_DEBUG & DEBUG_SYNC) {
if (fence)
svga->pipe.screen->fence_finish( svga->pipe.screen, fence,
svga->pipe.screen->fence_finish( svga->pipe.screen, NULL, fence,
PIPE_TIMEOUT_INFINITE);
}
@@ -369,7 +369,7 @@ svga_context_finish(struct svga_context *svga)
struct pipe_fence_handle *fence = NULL;
svga_context_flush(svga, &fence);
screen->fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
screen->fence_reference(screen, &fence, NULL);
}

View File

@@ -804,6 +804,7 @@ svga_fence_reference(struct pipe_screen *screen,
static boolean
svga_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -128,7 +128,7 @@ swr_transfer_map(struct pipe_context *pipe,
if (!swr_is_fence_pending(screen->flush_fence))
swr_fence_submit(swr_context(pipe), screen->flush_fence);
swr_fence_finish(pipe->screen, screen->flush_fence, 0);
swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0);
swr_resource_unused(resource);
}
}
@@ -205,7 +205,7 @@ swr_resource_copy(struct pipe_context *pipe,
swr_store_dirty_resource(pipe, src, SWR_TILE_RESOLVED);
swr_store_dirty_resource(pipe, dst, SWR_TILE_RESOLVED);
swr_fence_finish(pipe->screen, screen->flush_fence, 0);
swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0);
swr_resource_unused(src);
swr_resource_unused(dst);

View File

@@ -239,7 +239,7 @@ swr_finish(struct pipe_context *pipe)
struct pipe_fence_handle *fence = nullptr;
swr_flush(pipe, &fence, 0);
swr_fence_finish(pipe->screen, fence, 0);
swr_fence_finish(pipe->screen, NULL, fence, 0);
swr_fence_reference(pipe->screen, &fence, NULL);
}

View File

@@ -111,6 +111,7 @@ swr_fence_reference(struct pipe_screen *screen,
*/
boolean
swr_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence_handle,
uint64_t timeout)
{

View File

@@ -69,6 +69,7 @@ void swr_fence_reference(struct pipe_screen *screen,
struct pipe_fence_handle *f);
boolean swr_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence_handle,
uint64_t timeout);

View File

@@ -63,7 +63,7 @@ swr_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
if (pq->fence) {
if (swr_is_fence_pending(pq->fence))
swr_fence_finish(pipe->screen, pq->fence, 0);
swr_fence_finish(pipe->screen, NULL, pq->fence, 0);
swr_fence_reference(pipe->screen, &pq->fence, NULL);
}
@@ -128,7 +128,7 @@ swr_get_query_result(struct pipe_context *pipe,
if (!wait && !swr_is_fence_done(pq->fence))
return FALSE;
swr_fence_finish(pipe->screen, pq->fence, 0);
swr_fence_finish(pipe->screen, NULL, pq->fence, 0);
swr_fence_reference(pipe->screen, &pq->fence, NULL);
}

View File

@@ -657,7 +657,7 @@ swr_resource_destroy(struct pipe_screen *p_screen, struct pipe_resource *pt)
if (!swr_is_fence_pending(screen->flush_fence))
swr_fence_submit(swr_context(pipe), screen->flush_fence);
swr_fence_finish(p_screen, screen->flush_fence, 0);
swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
swr_resource_unused(pt);
}
@@ -692,7 +692,7 @@ swr_flush_frontbuffer(struct pipe_screen *p_screen,
struct pipe_context *pipe = screen->pipe;
if (pipe) {
swr_fence_finish(p_screen, screen->flush_fence, 0);
swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
swr_resource_unused(resource);
SwrEndFrame(swr_context(pipe)->swrContext);
}
@@ -712,7 +712,7 @@ swr_destroy_screen(struct pipe_screen *p_screen)
fprintf(stderr, "SWR destroy screen!\n");
swr_fence_finish(p_screen, screen->flush_fence, 0);
swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
swr_fence_reference(p_screen, &screen->flush_fence, NULL);
JitDestroyContext(screen->hJitMgr);

View File

@@ -1390,7 +1390,7 @@ swr_update_derived(struct pipe_context *pipe,
/* Ensure that any in-progress attachment change StoreTiles finish */
if (swr_is_fence_pending(screen->flush_fence))
swr_fence_finish(pipe->screen, screen->flush_fence, 0);
swr_fence_finish(pipe->screen, NULL, screen->flush_fence, 0);
/* Finally, update the in-use status of all resources involved in draw */
swr_update_resource_status(pipe, p_draw_info);

View File

@@ -402,20 +402,23 @@ trace_screen_fence_reference(struct pipe_screen *_screen,
static boolean
trace_screen_fence_finish(struct pipe_screen *_screen,
struct pipe_context *_ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{
struct trace_screen *tr_scr = trace_screen(_screen);
struct pipe_screen *screen = tr_scr->screen;
struct pipe_context *ctx = _ctx ? trace_context(_ctx)->pipe : NULL;
int result;
trace_dump_call_begin("pipe_screen", "fence_finish");
trace_dump_arg(ptr, screen);
trace_dump_arg(ptr, ctx);
trace_dump_arg(ptr, fence);
trace_dump_arg(uint, timeout);
result = screen->fence_finish(screen, fence, timeout);
result = screen->fence_finish(screen, ctx, fence, timeout);
trace_dump_ret(bool, result);

View File

@@ -61,6 +61,7 @@ vc4_fence_reference(struct pipe_screen *pscreen,
static boolean
vc4_fence_finish(struct pipe_screen *pscreen,
struct pipe_context *ctx,
struct pipe_fence_handle *pf,
uint64_t timeout_ns)
{

View File

@@ -524,6 +524,7 @@ static void virgl_fence_reference(struct pipe_screen *screen,
}
static boolean virgl_fence_finish(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout)
{

View File

@@ -242,11 +242,20 @@ struct pipe_screen {
/**
* Wait for the fence to finish.
*
* If the fence was created with PIPE_FLUSH_DEFERRED, and the context is
* still unflushed, and the ctx parameter of fence_finish is equal to
* the context where the fence was created, fence_finish will flush
* the context prior to waiting for the fence.
*
* In all other cases, the ctx parameter has no effect.
*
* \param timeout in nanoseconds (may be PIPE_TIMEOUT_INFINITE).
*/
boolean (*fence_finish)( struct pipe_screen *screen,
struct pipe_fence_handle *fence,
uint64_t timeout );
boolean (*fence_finish)(struct pipe_screen *screen,
struct pipe_context *ctx,
struct pipe_fence_handle *fence,
uint64_t timeout);
/**
* Returns a driver-specific query.

View File

@@ -141,7 +141,7 @@ hard_event::status() const {
else if (!_fence)
return CL_QUEUED;
else if (!screen->fence_finish(screen, _fence, 0))
else if (!screen->fence_finish(screen, NULL, _fence, 0))
return CL_SUBMITTED;
else
@@ -168,7 +168,7 @@ hard_event::wait() const {
queue()->flush();
if (!_fence ||
!screen->fence_finish(screen, _fence, PIPE_TIMEOUT_INFINITE))
!screen->fence_finish(screen, NULL, _fence, PIPE_TIMEOUT_INFINITE))
throw error(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
}

View File

@@ -1252,7 +1252,7 @@ dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
screen = dri_screen(ctx->sPriv)->base.screen;
pipe->flush_resource(pipe, dst->texture);
ctx->st->flush(ctx->st, 0, &fence);
(void) screen->fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
(void) screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
screen->fence_reference(screen, &fence, NULL);
}
}
@@ -1451,13 +1451,13 @@ dri2_client_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags,
/* No need to flush. The context was flushed when the fence was created. */
if (fence->pipe_fence)
return screen->fence_finish(screen, fence->pipe_fence, timeout);
return screen->fence_finish(screen, NULL, fence->pipe_fence, timeout);
else if (fence->cl_event) {
struct pipe_fence_handle *pipe_fence =
driscreen->opencl_dri_event_get_fence(fence->cl_event);
if (pipe_fence)
return screen->fence_finish(screen, pipe_fence, timeout);
return screen->fence_finish(screen, NULL, pipe_fence, timeout);
else
return driscreen->opencl_dri_event_wait(fence->cl_event, timeout);
}

View File

@@ -525,7 +525,7 @@ dri_flush(__DRIcontext *cPriv,
fence = swap_fences_pop_front(drawable);
if (fence) {
(void) screen->fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
(void) screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
screen->fence_reference(screen, &fence, NULL);
}

View File

@@ -1376,7 +1376,7 @@ void XMesaFlush( XMesaContext c )
c->st->flush(c->st, ST_FLUSH_FRONT, &fence);
if (fence) {
xmdpy->screen->fence_finish(xmdpy->screen, fence,
xmdpy->screen->fence_finish(xmdpy->screen, NULL, fence,
PIPE_TIMEOUT_INFINITE);
xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL);
}

View File

@@ -621,7 +621,7 @@ static void work_present(void *data)
{
struct end_present_struct *work = data;
if (work->fence_to_wait) {
(void) work->screen->fence_finish(work->screen, work->fence_to_wait, PIPE_TIMEOUT_INFINITE);
(void) work->screen->fence_finish(work->screen, NULL, work->fence_to_wait, PIPE_TIMEOUT_INFINITE);
work->screen->fence_reference(work->screen, &(work->fence_to_wait), NULL);
}
ID3DPresent_PresentBuffer(work->present, work->present_handle, work->hDestWindowOverride, NULL, NULL, NULL, 0);
@@ -743,7 +743,7 @@ bypass_rendering:
BOOL still_draw = FALSE;
fence = swap_fences_see_front(This);
if (fence) {
still_draw = !This->screen->fence_finish(This->screen, fence, 0);
still_draw = !This->screen->fence_finish(This->screen, NULL, fence, 0);
This->screen->fence_reference(This->screen, &fence, NULL);
}
if (still_draw)
@@ -754,7 +754,7 @@ bypass_rendering:
This->tasks[0]=NULL;
fence = swap_fences_pop_front(This);
if (fence) {
(void) This->screen->fence_finish(This->screen, fence, PIPE_TIMEOUT_INFINITE);
(void) This->screen->fence_finish(This->screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
This->screen->fence_reference(This->screen, &fence, NULL);
}

View File

@@ -327,7 +327,7 @@ vlVdpPresentationQueueBlockUntilSurfaceIdle(VdpPresentationQueue presentation_qu
pipe_mutex_lock(pq->device->mutex);
if (surf->fence) {
screen = pq->device->vscreen->pscreen;
screen->fence_finish(screen, surf->fence, PIPE_TIMEOUT_INFINITE);
screen->fence_finish(screen, NULL, surf->fence, PIPE_TIMEOUT_INFINITE);
screen->fence_reference(screen, &surf->fence, NULL);
}
pipe_mutex_unlock(pq->device->mutex);
@@ -369,7 +369,7 @@ vlVdpPresentationQueueQuerySurfaceStatus(VdpPresentationQueue presentation_queue
} else {
pipe_mutex_lock(pq->device->mutex);
screen = pq->device->vscreen->pscreen;
if (screen->fence_finish(screen, surf->fence, 0)) {
if (screen->fence_finish(screen, NULL, surf->fence, 0)) {
screen->fence_reference(screen, &surf->fence, NULL);
*status = VDP_PRESENTATION_QUEUE_STATUS_VISIBLE;
pipe_mutex_unlock(pq->device->mutex);

View File

@@ -383,7 +383,7 @@ xa_fence_wait(struct xa_fence *fence, uint64_t timeout)
struct pipe_screen *screen = fence->xa->screen;
boolean timed_out;
timed_out = !screen->fence_finish(screen, fence->pipe_fence, timeout);
timed_out = !screen->fence_finish(screen, NULL, fence->pipe_fence, timeout);
if (timed_out)
return -XA_ERR_BUSY;

View File

@@ -488,7 +488,7 @@ Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status)
*status = 0;
if (surface_priv->fence)
if (!pipe->screen->fence_finish(pipe->screen, surface_priv->fence, 0))
if (!pipe->screen->fence_finish(pipe->screen, NULL, surface_priv->fence, 0))
*status |= XVMC_RENDERING;
return Success;

View File

@@ -98,7 +98,7 @@ void st_finish( struct st_context *st )
st_flush(st, &fence, 0);
if(fence) {
st->pipe->screen->fence_finish(st->pipe->screen, fence,
st->pipe->screen->fence_finish(st->pipe->screen, NULL, fence,
PIPE_TIMEOUT_INFINITE);
st->pipe->screen->fence_reference(st->pipe->screen, &fence, NULL);
}

View File

@@ -87,7 +87,7 @@ static void st_check_sync(struct gl_context *ctx, struct gl_sync_object *obj)
return;
}
if (screen->fence_finish(screen, so->fence, 0)) {
if (screen->fence_finish(screen, NULL, so->fence, 0)) {
screen->fence_reference(screen, &so->fence, NULL);
so->b.StatusFlag = GL_TRUE;
}
@@ -110,7 +110,7 @@ static void st_client_wait_sync(struct gl_context *ctx,
* already called when creating a fence. */
if (so->fence &&
screen->fence_finish(screen, so->fence, timeout)) {
screen->fence_finish(screen, NULL, so->fence, timeout)) {
screen->fence_reference(screen, &so->fence, NULL);
so->b.StatusFlag = GL_TRUE;
}