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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c
index 9616c83..212c2b5 100644
--- a/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -140,32 +140,24 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
if (fb_info == NULL) {
return 0;
}
- if (_this->egl_data->egl_swapinterval == 0) {
- /* Swap buffers instantly, possible tearing */
- /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModeSetCrtc(%d, %u, %u, 0, 0, &%u, 1, &%ux%u@%u)",
- vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id, vdata->saved_conn_id,
- displaydata->cur_mode.hdisplay, displaydata->cur_mode.vdisplay, displaydata->cur_mode.vrefresh); */
- ret = KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
- 0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode);
- if(ret != 0) {
- SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not pageflip with drmModeSetCrtc: %d", ret);
- }
- } else {
- /* Queue page flip at vsync */
- /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
- or FlipPage won't work in some cases. */
- if (!wdata->crtc_ready) {
- if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
- SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips");
- return 0;
- }
+ /* Have we already setup the CRTC to one of the GBM buffers? Do so if we have not,
+ or FlipPage won't work in some cases. */
+ if (!wdata->crtc_ready) {
+ if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
+ SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing pageflips");
+ return 0;
}
+ }
+
+ /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
+ vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
+ ret = KMSDRM_drmModePageFlip(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
+ DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip);
+
+ if (_this->egl_data->egl_swapinterval == 1) {
+ /* Queue page flip at vsync */
- /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
- vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id); */
- ret = KMSDRM_drmModePageFlip(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
- DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip);
if (ret == 0) {
wdata->waiting_for_flip = SDL_TRUE;
} else {