[RFC xserver 10/12] modesetting: Add implementation for in-fences

Michel Dänzer michel at daenzer.net
Wed Aug 30 07:24:29 UTC 2017


On 30/08/17 02:16 PM, Louis-Francis Ratté-Boulianne wrote:
> Allow the modesetting present implementation to wait on
> in-fences using ANDROID_native_fence_sync if the fence
> was created with DRI3 FenceFromDMAFenceFD.
> 
> Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>

[...]

> +void
> +glamor_add_fence(ScreenPtr screen, SyncFence *fence)
> +{
> +    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
> +
> +    if (glamor_priv->flags & GLAMOR_USE_EGL_SCREEN)
> +        glamor_egl_add_fence(screen, fence);
> +}

[...]

> +Bool
> +glamor_egl_add_fence(ScreenPtr pScreen,
> +                     SyncFence *fence)
> +{
> +    struct glamor_egl_screen_private *glamor_egl;
> +    EGLSyncKHR sync;
> +    EGLint attribs[3];
> +    int i = 0;
> +
> +    glamor_egl = glamor_egl_get_screen_private(xf86ScreenToScrn(pScreen));
> +    if (!glamor_egl->dmafence_capable || fence == NULL)
> +        return FALSE;
> +
> +    attribs[i++] = EGL_SYNC_NATIVE_FENCE_FD_ANDROID;
> +    attribs[i++] = miSyncTakeDMAFenceFDFromFence(pScreen, fence);
> +    attribs[i++] = EGL_NONE;
> +
> +    if (!eglMakeCurrent(glamor_egl->display,
> +                        EGL_NO_SURFACE, EGL_NO_SURFACE, glamor_egl->context))
> +        return FALSE;
> +
> +    sync = eglCreateSyncKHR(glamor_egl->display, EGL_SYNC_NATIVE_FENCE_ANDROID,
> +                            attribs);
> +    if (sync == EGL_NO_SYNC_KHR)
> +        return FALSE;
> +
> +    eglWaitSyncKHR(glamor_egl->display, sync, 0);
> +    eglDestroySyncKHR(glamor_egl->display, sync);
> +
> +    return TRUE;
> +}

[...]

> +/* Add a fence in the command stream
> + */
> +static void
> +ms_present_wait(RRCrtcPtr crtc,
> +                SyncFence *fence)
> +{
> +    ScreenPtr screen = crtc->pScreen;
> +
> +    glamor_add_fence(screen, fence);
> +}
> +

Instead of waiting for the fence as part of the GPU command stream,
would it be possible to get asynchronous notification when the fence
signals, and call present_event_notify or another callback to trigger
execution of the presentation? That could avoid stalling the GPU
pipeline while waiting for the fence to signal.


> @@ -388,7 +458,10 @@ static present_screen_info_rec ms_present_screen_info = {
>  #ifdef GLAMOR_HAS_GBM
>      .check_flip = ms_present_check_flip,
>      .flip = ms_present_flip,
> +    .flip_with_fence = ms_present_flip_with_fence,
>      .unflip = ms_present_unflip,
> +    .can_wait = ms_present_can_wait,
> +    .wait = ms_present_wait,

BTW, just "wait" might be a bit generic for the hook name, how about
"wait_fence"?


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the xorg-devel mailing list