diff options
author | Marek Olšák <[email protected]> | 2015-04-10 19:41:39 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2015-04-30 14:38:38 +0200 |
commit | 7070b0dd66d315b3106803580623df4fb5223473 (patch) | |
tree | 31e1ba1375de9777fafe759625f5e116e478296a /src/gallium/state_trackers/dri/dri2.c | |
parent | a2557b30d843d4f3dada6a022f27e8343adabca8 (diff) |
st/dri: implement the fence interface
Diffstat (limited to 'src/gallium/state_trackers/dri/dri2.c')
-rw-r--r-- | src/gallium/state_trackers/dri/dri2.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index f8f4ecf36d7..9b5631326d4 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -1251,6 +1251,85 @@ static __DRIimageExtension dri2ImageExtension = { .getCapabilities = dri2_get_capabilities, }; + +struct dri2_fence { + struct pipe_fence_handle *pipe_fence; +}; + +static void * +dri2_create_fence(__DRIcontext *_ctx) +{ + struct pipe_context *ctx = dri_context(_ctx)->st->pipe; + struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence); + + if (!fence) + return NULL; + + ctx->flush(ctx, &fence->pipe_fence, 0); + + if (!fence->pipe_fence) { + FREE(fence); + return NULL; + } + + return fence; +} + +static void * +dri2_get_fence_from_cl_event(__DRIscreen *_screen, intptr_t cl_event) +{ + return NULL; +} + +static void +dri2_destroy_fence(__DRIscreen *_screen, void *_fence) +{ + struct dri_screen *driscreen = dri_screen(_screen); + struct pipe_screen *screen = driscreen->base.screen; + struct dri2_fence *fence = (struct dri2_fence*)_fence; + + if (fence->pipe_fence) + screen->fence_reference(screen, &fence->pipe_fence, NULL); + else + assert(0); + + FREE(fence); +} + +static GLboolean +dri2_client_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags, + uint64_t timeout) +{ + struct dri_screen *driscreen = dri_screen(_ctx->driScreenPriv); + struct pipe_screen *screen = driscreen->base.screen; + struct dri2_fence *fence = (struct dri2_fence*)_fence; + + /* 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); + else { + assert(0); + return false; + } +} + +static void +dri2_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags) +{ + /* AFAIK, no driver currently supports parallel context execution. */ +} + +static __DRI2fenceExtension dri2FenceExtension = { + .base = { __DRI2_FENCE, 1 }, + + .create_fence = dri2_create_fence, + .get_fence_from_cl_event = dri2_get_fence_from_cl_event, + .destroy_fence = dri2_destroy_fence, + .client_wait_sync = dri2_client_wait_sync, + .server_wait_sync = dri2_server_wait_sync +}; + /* * Backend function init_screen. */ @@ -1262,6 +1341,7 @@ static const __DRIextension *dri_screen_extensions[] = { &dri2RendererQueryExtension.base, &dri2ConfigQueryExtension.base, &dri2ThrottleExtension.base, + &dri2FenceExtension.base, NULL }; |