Bug 28771 - [RADEON:KMS::R300C:R300G] waiting for vline forced always on
Summary: [RADEON:KMS::R300C:R300G] waiting for vline forced always on
Status: RESOLVED WONTFIX
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/DRI/r300 (show other bugs)
Version: git
Hardware: Other All
: medium normal
Assignee: Default DRI bug account
QA Contact:
URL:
Whiteboard:
Keywords:
: 26599 (view as bug list)
Depends on: 42035
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-26 12:14 UTC by Sven Arvidsson
Modified: 2014-07-07 16:43 UTC (History)
9 users (show)

See Also:
i915 platform:
i915 features:


Attachments
dri2 vblank for gallium (447 bytes, patch)
2010-07-15 12:28 UTC, Sven Arvidsson
Details | Splinter Review
turn off wait for vline for r600+ ddx patch (457 bytes, patch)
2010-08-16 02:50 UTC, Andy Furniss
Details | Splinter Review

Description Sven Arvidsson 2010-06-26 12:14:35 UTC
With kernel 2.6.35, there doesn't seem to be a way to turn off vsync/vblank. 

E.g. "vblank_mode=0 glxgears" has no effect.

This seems to be the same for both r300c and r300g.

System environment:
-- system architecture: 32-bit
-- Linux distribution: Debian unstable
-- GPU: RV570
-- Model: Asus EAX1950Pro 256MB
-- Display connector: DVI

-- xf86-video-ati: 801e83227a59a29eea425ea612083bbf2b536c30
-- xserver: 1.8.1.901
-- mesa: a5c44986a3f19936df448fe4ae47ca77ece9b0ce
-- drm: 6ea2bda5f5ec8f27359760ce580fdad3df0464df
-- kernel: 2.6.35-rc3
Comment 1 Jesse Barnes 2010-06-28 09:31:56 UTC
You need both:

commit 234286c0f8b7d30ed49223c648d4c73c1a517ab3
Author: Jesse Barnes <jbarnes@virtuousgeek.org>
Date:   Thu Apr 22 12:47:41 2010 -0700

    DRI2: add config query extension

and

commit 45e2b51c853471b79004a954ce3092a253b20b77
Author: Jesse Barnes <jbarnes@virtuousgeek.org>
Date:   Thu Apr 22 12:49:03 2010 -0700

    DRI2/GLX: check for vblank_mode in DRI2 GLX code

for vblank_mode to work.  Does your Mesa build have those?
Comment 2 Sven Arvidsson 2010-06-28 13:18:51 UTC
Yes, I'm using git master, so they're both there.
Comment 3 Jesse Barnes 2010-06-28 15:41:03 UTC
Oh, for the DRI2 radeon driver you'll probably need to add an explicit option somewhere; maybe the code path that used to check the vblank_mode flags is no longer called.

See intel_screen.c:
...
DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_ALWAYS_SYNC)
...

there's probably a similar section in the radeon driver somewhere.  You'll also need to add support for the new DRI2 config extension to the driver, again see intel_screen.c's intelScreenExtensions array:
...
    &dri2ConfigQueryExtension.base,
...

Hope that helps.
Comment 4 Alex Deucher 2010-07-15 11:55:31 UTC
Should be fixed in:
0a7803cbaca13033d9ed31ef33f59efa913fbfce
Comment 5 Sven Arvidsson 2010-07-15 12:28:10 UTC
Created attachment 37084 [details] [review]
dri2 vblank for gallium

(In reply to comment #4)
> Should be fixed in:
> 0a7803cbaca13033d9ed31ef33f59efa913fbfce

Thanks, it works with the classic r300 driver now. 

For the Gallium one I had to make the same change in the dri state tracker. Not sure if it's the correct fix, but it works here.
Comment 6 Sven Arvidsson 2010-07-15 13:18:07 UTC
Hmm, I still can't toggle vsync on/off inside games, it has no effect, but maybe that's a separate bug?
Comment 7 Andy Furniss 2010-07-16 05:03:29 UTC
(In reply to comment #4)
> Should be fixed in:
> 0a7803cbaca13033d9ed31ef33f59efa913fbfce

For me using rv670 it doesn't work from .drirc eg.

<driconf>
    <device screen="0" driver="r600">
        <application name="all">
            <option name="force_s3tc_enable" value="false" />
            <option name="disable_s3tc" value="true" />
            <option name="vblank_mode" value="0"/>
        </application>
    </device>
</driconf>

It does work as an env so vblank_mode=0 ./gears works - but I still get wait for vline sync which means that fullscreen games or gears maximised gets capped to refresh.
Comment 8 Sven Arvidsson 2010-07-16 06:30:13 UTC
I can confirm that setting vblank_mode=0 in drirc doesn't work here either.

Can't reproduce the other problem though, window or fullscreen doesn't make a difference.
Comment 9 Andy Furniss 2010-07-16 06:37:58 UTC
(In reply to comment #8)
> I can confirm that setting vblank_mode=0 in drirc doesn't work here either.
> 
> Can't reproduce the other problem though, window or fullscreen doesn't make a
> difference.

Maybe the wait for vline type vsync I get is r600 specific.
Comment 10 Toni Spets 2010-07-17 22:36:22 UTC
(In reply to comment #9)
> (In reply to comment #8)
> > I can confirm that setting vblank_mode=0 in drirc doesn't work here either.
> > 
> > Can't reproduce the other problem though, window or fullscreen doesn't make a
> > difference.
> 
> Maybe the wait for vline type vsync I get is r600 specific.

I can also confirm .drirc gets ignored but env vblank_mode works.

To disable vsync completely you currently (and before) need a DDX hack along with vblank_mode=0.

With this patch interestingly glxgears goes from ~1400 fps to ~2100 fps and Quake 2 can run uncapped.

What is the real solution and why is this patch needed in DDX?

From 311d4c299ed8de4f28d3fd637a7bde8176db245b Mon Sep 17 00:00:00 2001
From: Toni Spets <toni.spets@iki.fi>
Date: Wed, 17 Feb 2010 17:37:49 +0200
Subject: [PATCH] Disable vsync

---
 src/radeon_dri2.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index a0ed085..b74a18b 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -315,7 +315,7 @@ radeon_dri2_copy_region(DrawablePtr drawable,
     }   
 
     vsync = info->accel_state->vsync;
-    info->accel_state->vsync = TRUE;
+    info->accel_state->vsync = FALSE;
 
     (*gc->ops->CopyArea)(src_drawable, dst_drawable, gc, 
                          0, 0, drawable->width, drawable->height, 0, 0); 
-- 
1.7.1
Comment 11 Alex Deucher 2010-07-18 01:10:40 UTC
(In reply to comment #10)
> 
> What is the real solution and why is this patch needed in DDX?

The real solution to what?  The various GLX vsync/vblank extensions basically just expose frame counters and vertical retrace events to applications so they can use them for synchronization.  They have nothing to do with tearing prevention directly.  The code in the ddx you are asking about has nothing to do with the GLX vsync/vblank extensions; it is there to prevent tearing on GL buffer swaps.  The variable should probably have been called vline_wait rather than vsync.  What the code does is forces the GPU to wait until the current scanline is past the area that will be updated by the swap before doing the swap blit.  It's the same method used by Xv to prevent tearing when rendering to the front buffer.
Comment 12 Andy Furniss 2010-07-18 03:35:09 UTC
(In reply to comment #10)

> With this patch interestingly glxgears goes from ~1400 fps to ~2100 fps and
> Quake 2 can run uncapped.

Thanks for the patch. The gears difference is expected as the wait for vline vsync still stalls GPU for the lines that the gears window covers. Changing res would also give different fps as more/less of the screen was outside the window.
Comment 13 Andy Furniss 2010-07-18 03:50:27 UTC
(In reply to comment #11)
> (In reply to comment #10)
> > 
> > What is the real solution and why is this patch needed in DDX?
> 
> The real solution to what?  The various GLX vsync/vblank extensions basically
> just expose frame counters and vertical retrace events to applications so they
> can use them for synchronization.

I guess what people want is a way to turn it off without patching, games don't seem to be able to.

Personally I am not that bothered about tearing in FPS type games and my old PC is often not able to render at refresh rate anyway - which means without triple buffering vsync hurts my already low framerate.

> It's the same method used by Xv to prevent tearing when rendering
> to the front buffer.

Can GL have a switch like XV has - or should games in theory be able to turn off, but are prevented by a bug?

Digression - I notice that XV with vsync on can't live with frame rate = refresh rate, which I sometimes use for "proper" deinterlaced TV. GL vsync is fine and GL wait vline is much better that XV. Is this a driver issue or is it just that mplayers gl driver makes mplayer behave differently to it's xv driver?
Comment 14 Toni Spets 2010-07-18 05:09:18 UTC
(In reply to comment #13)
> (In reply to comment #11)
> > (In reply to comment #10)
> > > 
> > > What is the real solution and why is this patch needed in DDX?
> > 
> > The real solution to what?  The various GLX vsync/vblank extensions basically
> > just expose frame counters and vertical retrace events to applications so they
> > can use them for synchronization.
> 
> I guess what people want is a way to turn it off without patching, games don't
> seem to be able to.
> 
> Personally I am not that bothered about tearing in FPS type games and my old PC
> is often not able to render at refresh rate anyway - which means without triple
> buffering vsync hurts my already low framerate.
> 

Yes, this is exactly what I'm talking about.

Quake-style games have options like gl_swapinterval and gl_ext_swapinterval but they do not seem to do anything. Honestly I don't even know what they should do, but on other platforms they used to disable vsync on some cards.

> > The code in the ddx you are asking about has nothing to
> > do with the GLX vsync/vblank extensions; it is there to prevent tearing on 
> > GL buffer swaps.

And it hurts performance not being able to turn it off without a patch. I like tearing! ;-)

Btw. are we still on-topic on this bug when the actual fix for vblank_mode was already committed?
Comment 15 Sven Arvidsson 2010-07-18 06:14:06 UTC
(In reply to comment #14)
> 
> Btw. are we still on-topic on this bug when the actual fix for vblank_mode was
> already committed?

There's still three issues here:

1, The Gallium driver, not sure if the change I did is in the correct place?
2, drirc being ignored, perhaps this isn't specific to radeon?
3, Toggling vsync on/off from an application. Again, perhaps a separate issue?
Comment 16 Sven Arvidsson 2010-07-18 06:22:26 UTC
(In reply to comment #15)
> There's still three issues here:
> 
> 1, The Gallium driver, not sure if the change I did is in the correct place?

Nevermind about this one, I should have remembered to do a git pull before commenting here :)
Comment 17 Alex Deucher 2010-07-19 10:29:31 UTC
(In reply to comment #13)
> Can GL have a switch like XV has - or should games in theory be able to turn
> off, but are prevented by a bug?

I'm not sure how you'd expose it.  You could make it a driver option, but then you'd have to restart X to change it.  There's no GLX extension to cover tearing as far as I know.

> 
> Digression - I notice that XV with vsync on can't live with frame rate =
> refresh rate, which I sometimes use for "proper" deinterlaced TV. GL vsync is
> fine and GL wait vline is much better that XV. Is this a driver issue or is it
> just that mplayers gl driver makes mplayer behave differently to it's xv
> driver?

Xv in general does not provide any mechanism for application synchronization.  I.e., here's no vblank events provided by Xv for app synchronization.  That's what the GLX vsync extensions do.

The driver uses the vline wait for avoid tearing for both Xv and GL buffer swaps, they have nothing to do with the GLX vsync extensions.  Those extensions only provide events that the application can use for synchronization.  If you remove the vline wait code, you can still synchronize your application to the refresh rate, but you might still get tearing depending when the GL buffer swap happens.
Comment 18 roberth 2010-07-27 23:00:11 UTC
(In reply to comment #7)
> (In reply to comment #4)
> > Should be fixed in:
> > 0a7803cbaca13033d9ed31ef33f59efa913fbfce
> 
> For me using rv670 it doesn't work from .drirc eg.
> 
> <driconf>
>     <device screen="0" driver="r600">
>         <application name="all">
>             <option name="force_s3tc_enable" value="false" />
>             <option name="disable_s3tc" value="true" />
>             <option name="vblank_mode" value="0"/>
>         </application>
>     </device>
> </driconf>
> 
> It does work as an env so vblank_mode=0 ./gears works - but I still get wait
> for vline sync which means that fullscreen games or gears maximised gets capped
> to refresh.

To use vblank_mode for dri2 in .drirc you need a seperate dri2 driver with vblank_mode specified, driconf doesn't handle it right.

Using your example it'd be:

<driconf>
    <device screen="0" driver="dri2">
        <application name="Default">
            <option name="vblank_mode" value="0" />
        </application>
    </device>
   <device screen="0" driver="r600">
       <application name="all">
           <option name="force_s3tc_enable" value="false" />
           <option name="disable_s3tc" value="true" />
       </application>
   </device>
</driconf>
Comment 19 Andy Furniss 2010-07-28 04:41:00 UTC
(In reply to comment #18)

> To use vblank_mode for dri2 in .drirc you need a seperate dri2 driver with
> vblank_mode specified, driconf doesn't handle it right.
> 
> Using your example it'd be:
> 
> <driconf>
>     <device screen="0" driver="dri2">
>         <application name="Default">
>             <option name="vblank_mode" value="0" />
>         </application>
>     </device>
>    <device screen="0" driver="r600">
>        <application name="all">
>            <option name="force_s3tc_enable" value="false" />
>            <option name="disable_s3tc" value="true" />
>        </application>
>    </device>
> </driconf>

Thank you, that does the trick.
Comment 20 Sven Arvidsson 2010-07-28 06:44:34 UTC
(In reply to comment #18)
> To use vblank_mode for dri2 in .drirc you need a seperate dri2 driver with
> vblank_mode specified, driconf doesn't handle it right.
> 

Great! Is there a bug open for driconf so this can be configured correctly?
Comment 21 Hans Nieser 2010-08-15 09:12:43 UTC
(In reply to comment #20)
> (In reply to comment #18)
> > To use vblank_mode for dri2 in .drirc you need a seperate dri2 driver with
> > vblank_mode specified, driconf doesn't handle it right.
> > 
> 
> Great! Is there a bug open for driconf so this can be configured correctly?

I believe I've run into the same problem with my RV770 (running mesa/libdrm/xf86-video-ati, tried both classic and gallium) from git master, where initially in every OpenGL app my framerate seemed to be capped to my screen's refresh (by default - even without a .drirc).

After making this change in my .drirc, the framerate is not capped anymore but it will still be swapping buffers during a retrace, and so I still get multiples of 60Hz (my screens refresh rate). This means in glxgears I get a ridicilous framerate like 2400, but in actual games like ioquake3, I get a framerate that jumps wildly from 30 to 60 to 120Hz, which I find really awkward :/

Is there any way currently to just make it swap buffers without regard for my screens vertical retrace? I realise that means I get a lot of tearing but I'd rather have that than a frame rate jumping around like that.
Comment 22 Andy Furniss 2010-08-16 02:45:45 UTC
(In reply to comment #21)

> Is there any way currently to just make it swap buffers without regard for my
> screens vertical retrace? I realise that means I get a lot of tearing but I'd
> rather have that than a frame rate jumping around like that.

For your chip you have to patch xf86-video-ati + disable as above. I'll attach the patch which someone posted in another bug when I find it.

I think this is going to come up again and again, so I hope in the absence of any way to change it on the fly, that it does get made into an xorg.conf option as suggested in comment 17.
Comment 23 Andy Furniss 2010-08-16 02:50:07 UTC
Created attachment 37895 [details] [review]
turn off wait for vline for r600+ ddx patch
Comment 24 Sven Arvidsson 2010-08-18 13:22:16 UTC
I compared how Intel (i965) compares when it comes to DRI2 and vsync, and as far as I can tell they have the same problems (needs a special driver="dri2" stansa in drirc, toggling vsync inside a game doesn't work). 

This bug can proabably be closed as resolved for radeon, and bugs for the shortcomings mentioned above filed against DRI2.
Comment 25 Alex Deucher 2010-08-22 21:37:56 UTC
*** Bug 26599 has been marked as a duplicate of this bug. ***
Comment 26 Tomasz Czapiewski 2010-09-26 14:19:53 UTC
Does anyone work on this to make it work without patching code to disable completely vsync?
Comment 27 Nikolay Rysev 2010-09-27 02:55:29 UTC
Excuse me, it's just interesting for me.

Why vsync is enabled for all OSS drivers by default?
Comment 28 Tomasz Czapiewski 2010-10-19 05:50:18 UTC
I want to know if are there any developers which would consider it as a bug to get fixed.
It is a real problem for games, mostly for older hardware.
Just try to play any first person shooter game where the framerate jumps from 60 to 30 so quickly.
Comment 29 Artem S. Tashkinov 2010-10-22 06:17:41 UTC
Is there a similar bug filed for Intel driver?

At least in RedHat's bugzilla there's a relevant patch: https://bugzilla.redhat.com/show_bug.cgi?id=634200
Comment 30 Ian Romanick 2011-02-21 13:44:15 UTC
(In reply to comment #29)
> Is there a similar bug filed for Intel driver?
> 
> At least in RedHat's bugzilla there's a relevant patch:
> https://bugzilla.redhat.com/show_bug.cgi?id=634200

I don't see any patches there.  Is it perhaps hiding in the .srpm?
Comment 31 Alex Deucher 2011-02-21 13:51:51 UTC
vline waits for non-pageflipped swap buffers can be disabled in both radeon and intel with:
Option "SwapbuffersWait" "False"
in the device section of your xorg.conf
Comment 32 Sven Arvidsson 2011-02-21 16:03:49 UTC
The need to manually configure drirc to use driver=dri2 is filed as bug 34401.

I'm still not sure if toggling vsync on/off inside an application is supposed to work (it doesn't seem to with r300g in Sauerbraten or M.A.R.S. for example). What component should a bug be filed against in this case?

At least M.A.R.S. seems to be using glXSwapIntervalSGI for vsync.
Comment 33 Sven Arvidsson 2011-02-21 16:22:38 UTC
(In reply to comment #32)
> I'm still not sure if toggling vsync on/off inside an application is supposed
> to work (it doesn't seem to with r300g in Sauerbraten or M.A.R.S. for example).
> What component should a bug be filed against in this case?
> 
> At least M.A.R.S. seems to be using glXSwapIntervalSGI for vsync.

Actually, forget about this part. It works, at least in MARS. Not sure about Sauerbraten, but it could be a bug in the game.
Comment 34 Andreas Boll 2014-07-07 16:43:38 UTC
The classic r300 driver has been abandoned long ago.
It was replaced by the Gallium driver r300g.

If you have issues with r300g please file a new bug report with component Drivers/Gallium/r300

Thanks.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.