KMSDRM_GLES_SwapWindow: fix non-vsync case
authorConn O'Griofa <connogriofa@gmail.com>
Fri, 06 Sep 2019 08:44:46 -0700
changeset 1306333bcd45f0447
parent 13062 211e1b06ec47
child 13064 9aa7aea27dec
KMSDRM_GLES_SwapWindow: fix non-vsync case
If KMSDRM_drmModeSetCrtc is called when the swap interval is
set to 0, the driver behaves as though vertical sync is engaged by
limiting framerate to the refresh rate, but performance is much worse
than with vertical sync enabled.

Resolve this issue by ensuring that the Crtc is only set up once,
and KMSDRM_drmModePageFlip is called, albeit without any followup
queueing or waiting for flips.
src/video/kmsdrm/SDL_kmsdrmopengles.c
     1.1 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Sep 06 08:42:54 2019 -0700
     1.2 +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c	Fri Sep 06 08:44:46 2019 -0700
     1.3 @@ -140,32 +140,24 @@
     1.4      if (fb_info == NULL) {
     1.5          return 0;
     1.6      }
     1.7 -    if (_this->egl_data->egl_swapinterval == 0) {
     1.8 -        /* Swap buffers instantly, possible tearing */
     1.9 -        /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModeSetCrtc(%d, %u, %u, 0, 0, &%u, 1, &%ux%u@%u)",
    1.10 -            vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id, vdata->saved_conn_id,
    1.11 -            displaydata->cur_mode.hdisplay, displaydata->cur_mode.vdisplay, displaydata->cur_mode.vrefresh); */
    1.12 -        ret = KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
    1.13 -                                    0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode);
    1.14 -        if(ret != 0) {
    1.15 -            SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not pageflip with drmModeSetCrtc: %d", ret);
    1.16 +
    1.17 +    /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
    1.18 +       or FlipPage won't work in some cases. */
    1.19 +    if (!wdata->crtc_ready) {
    1.20 +        if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
    1.21 +            SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing pageflips");
    1.22 +            return 0;
    1.23          }
    1.24 -    } else {
    1.25 +    }
    1.26 +
    1.27 +    /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
    1.28 +        vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
    1.29 +    ret = KMSDRM_drmModePageFlip(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
    1.30 +                                 DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip);
    1.31 +
    1.32 +    if (_this->egl_data->egl_swapinterval == 1) {
    1.33          /* Queue page flip at vsync */
    1.34  
    1.35 -        /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
    1.36 -           or FlipPage won't work in some cases. */
    1.37 -        if (!wdata->crtc_ready) {
    1.38 -            if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
    1.39 -                SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips");
    1.40 -                return 0;
    1.41 -            }
    1.42 -        }
    1.43 -
    1.44 -        /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
    1.45 -            vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
    1.46 -        ret = KMSDRM_drmModePageFlip(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
    1.47 -                                     DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip);
    1.48          if (ret == 0) {
    1.49              wdata->waiting_for_flip = SDL_TRUE;
    1.50          } else {