[Bug 42035] no way to turn off vsync

Michel Dänzer michel at daenzer.net
Mon Oct 24 04:30:26 PDT 2011


On Don, 2011-10-20 at 12:16 +0200, Michal Suchanek wrote:
> 
> On 20 October 2011 11:38,  <bugzilla-daemon at freedesktop.org> wrote:
> > https://bugs.freedesktop.org/show_bug.cgi?id=42035
> >
> > --- Comment #1 from Michel Dänzer <michel at daenzer.net> 2011-10-20 02:38:29 PDT ---
> >> This should be runtime configurable, preferably per-application like dri.
> >
> > That would require some xserver dri2 changes first, to allow the driver to tell
> > the different cases apart. There's been some discussion about this on the
> > xorg-devel list, started by Chris Wilson.
> 
> Anyone can point at the discussion or say what the problem is with this?

Actually, the radeon driver patch below might be good enough, at least
for now. It disables Option "SwapBuffersWait" by default when the real
sync-to-vblank functionality is working. There should be no need for the
vline waits for DRI2 in that case. 

Thoughts?


diff --git a/man/radeon.man b/man/radeon.man
index 55c5d02..dfe15e0 100644
--- a/man/radeon.man
+++ b/man/radeon.man
@@ -281,11 +281,11 @@ This option controls the behavior of glXSwapBuffers and glXCopySubBufferMESA
 calls by GL applications.  If enabled, the calls will avoid tearing by making
 sure the display scanline is outside of the area to be copied before the copy
 occurs.  If disabled, no scanline synchronization is performed, meaning tearing
-will likely occur.  Note that when enabled, this option can adversely affect
+may occur.  Note that when enabled, this option can adversely affect
 the framerate of applications that render frames at less than refresh rate.
 .IP
 The default value is
-.B on.
+.B off when real sync-to-vblank works, on otherwise.
 .TP
 .BI "Option \*qEnablePageFlip\*q \*q" boolean \*q
 Enable DRI2 page flipping.  The default is
diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index 88117a5..7e6c029 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -1292,6 +1292,44 @@ blit_fallback:
 

 Bool
+radeon_dri2_vblank_scheduling_works(ScrnInfoPtr pScrn)
+{
+#ifdef USE_DRI2_SCHEDULING
+    RADEONInfoPtr info = RADEONPTR(pScrn);
+    Bool ret = TRUE;
+
+    if (info->dri->pKernelDRMVersion->version_minor < 4) {
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need a newer kernel for "
+		   "sync extension\n");
+	ret = FALSE;
+    } else if (info->drmmode.mode_res->count_crtcs > 2) {
+#ifdef DRM_CAP_VBLANK_HIGH_CRTC
+	uint64_t cap_value;
+
+	if (drmGetCap(info->dri2.drm_fd, DRM_CAP_VBLANK_HIGH_CRTC, &cap_value)) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need a newer kernel "
+		       "for VBLANKs on CRTC > 1\n");
+	    ret = FALSE;
+	} else if (!cap_value) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Your kernel does not "
+		       "handle VBLANKs on CRTC > 1\n");
+	    ret = FALSE;
+	}
+#else
+	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need to rebuild against a "
+		   "newer libdrm to handle VBLANKs on CRTC > 1\n");
+	ret = FALSE;
+#endif
+    }
+
+    return ret;
+
+#else
+    return FALSE;
+#endif
+}
+
+Bool
 radeon_dri2_screen_init(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -1300,7 +1338,6 @@ radeon_dri2_screen_init(ScreenPtr pScreen)
 #ifdef USE_DRI2_SCHEDULING
     RADEONEntPtr pRADEONEnt   = RADEONEntPriv(pScrn);
     const char *driverNames[2];
-    Bool scheduling_works = TRUE;
 #endif
 
     if (!info->useEXA) {
@@ -1333,33 +1370,7 @@ radeon_dri2_screen_init(ScreenPtr pScreen)
     dri2_info.CopyRegion = radeon_dri2_copy_region;
 
 #ifdef USE_DRI2_SCHEDULING
-    if (info->dri->pKernelDRMVersion->version_minor < 4) {
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need a newer kernel for "
-		   "sync extension\n");
-	scheduling_works = FALSE;
-    }
-
-    if (scheduling_works && info->drmmode.mode_res->count_crtcs > 2) {
-#ifdef DRM_CAP_VBLANK_HIGH_CRTC
-	uint64_t cap_value;
-
-	if (drmGetCap(info->dri2.drm_fd, DRM_CAP_VBLANK_HIGH_CRTC, &cap_value)) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need a newer kernel "
-		       "for VBLANKs on CRTC > 1\n");
-	    scheduling_works = FALSE;
-	} else if (!cap_value) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Your kernel does not "
-		       "handle VBLANKs on CRTC > 1\n");
-	    scheduling_works = FALSE;
-	}
-#else
-	xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "You need to rebuild against a "
-		   "newer libdrm to handle VBLANKs on CRTC > 1\n");
-	scheduling_works = FALSE;
-#endif
-    }
-
-    if (scheduling_works) {
+    if (radeon_dri2_vblank_scheduling_works(pScrn)) {
         dri2_info.version = 4;
         dri2_info.ScheduleSwap = radeon_dri2_schedule_swap;
         dri2_info.GetMSC = radeon_dri2_get_msc;
diff --git a/src/radeon_dri2.h b/src/radeon_dri2.h
index 7995286..819348e 100644
--- a/src/radeon_dri2.h
+++ b/src/radeon_dri2.h
@@ -35,6 +35,7 @@ struct radeon_dri2 {
 
 #ifdef RADEON_DRI2
 #include "dri2.h"
+Bool radeon_dri2_vblank_scheduling_works(ScrnInfoPtr pScrn);
 Bool radeon_dri2_screen_init(ScreenPtr pScreen);
 void radeon_dri2_close_screen(ScreenPtr pScreen);
 #endif
diff --git a/src/radeon_kms.c b/src/radeon_kms.c
index 32065fb..dcb9938 100644
--- a/src/radeon_kms.c
+++ b/src/radeon_kms.c
@@ -717,16 +717,17 @@ Bool RADEONPreInit_KMS(ScrnInfoPtr pScrn, int flags)
 		   "KMS Pageflipping: %sabled\n", info->allowPageFlip ? "en" : "dis");
     }
 
-    info->swapBuffersWait = xf86ReturnOptValBool(info->Options,
-						 OPTION_SWAPBUFFERS_WAIT, TRUE);
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-	       "SwapBuffers wait for vsync: %sabled\n", info->swapBuffersWait ? "en" : "dis");
-
     if (drmmode_pre_init(pScrn, &info->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Kernel modesetting setup failed\n");
 	goto fail;
     }
 
+    info->swapBuffersWait = xf86ReturnOptValBool(info->Options,
+						 OPTION_SWAPBUFFERS_WAIT,
+						 !radeon_dri2_vblank_scheduling_works(pScrn));
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+	       "SwapBuffers wait for vblank: %sabled\n", info->swapBuffersWait ? "en" : "dis");
+
     if (info->drmmode.mode_res->count_crtcs == 1)
         pRADEONEnt->HasCRTC2 = FALSE;
     else


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


More information about the xorg-driver-ati mailing list