View Single Post
Old 01-31-07, 04:31 AM   #2
Registered User
Join Date: Jan 2007
Posts: 8
Cool Re: VSYNC <-> tearing: summary of the situation !!!

Hello again,

After much playing around overnight, here are some clues for those who experience "tearing".

OpenGL perspective
The __GL_SYNC_TO_VBLANK environment variable affects "opengl" drivers/extensions only. Every OpenGL application launched AFTER it has been set (export __GL_SYNC_TO_VBLANK=1) will VSYNC to the chosen "screen". In other words, FPS (Frames per second) will equal the screen's refresh rate.

Use 'glxgears'. This tiny executable displays OpenGL-achieved rotating gears in a window, while showing the achieved FPS in the terminal window. On my machine, 'glxgears' achieves FPS between 1500 and 7000 (depending of the display window size) if VSYNC is disabled... and 60 FPS (equal to my LCD's 60Hz refresh rate) when VSYNC is enabled (I'll explain the 60Hz refresh rate later)

XVideo perspective
The 'nvidia-settings' allows to configure the nVidia driver and affects all applications/extensions launched AFTER the changes are made.
Launching 'nvidia-settings' with no arguments allows to configure the driver using a nice GUI (including nice helping tooltips). In the XVideo section, we are interested in the two 'Sync to Vblank' checkboxes. You changes will be saved/committed to the driver when exiting the application. Note that you will need include some 'nvidia-settings --load-config-only' command somewhere in your personal start-up script in order to customize the nVidia driver according to YOUR needs (changes are discarded/re-initalized every time you log-out/-in).

Use 'mplayer -benchmark -nosound -frames 1234 -vo xv <some_MRL>'. The '-benchmark' and '-nosound' option tells 'mplayer' to play the video as fast as possible, with no respect with sound synchronization. Calculating the achieved FPS here is a little tricky; the method given below only approximates the FPS (but should allow to find out if VSYNC is enabled or not).

Once the above command executed (on a NON-VSYNC-able machine; old ATI card):
- look at the benchmark results (in the line: BENCHMARKs: VC: 1.529s VO: 1.534s A: 0.000s Sys: 0.279s = 3.341s -> BENCH_TIME = 3.341
- the quantity of played frame is 1234 (you can change this ;-) ) -> COUNT_FRAMES = 1234
The achieved "rendered" FPS is (very approximately):
- FPS = COUNT_FRAMES / BENCH_TIME ( = 369 FPS in our example case)

Now, on my nVidia (VSYNC-able) machine; several scenarios:
1. NO "Composite" X extension
'mplayer -benchmark -nosound -frames 1234 -vo xv <some_MRL>' -> 72 FPS (mplayer's benchmark makes a poor job of trying to VSync... but at least it shows it tries)
2. "Composite" X extension ENABLED (but NOT used)
'mplayer -benchmark -nosound -frames 1234 -vo xv <some_MRL>' -> 72 FPS
3. "Composite" X extension ENABLED (and USED, with KDE Translucency "compositor")
'mplayer -benchmark -nosound -frames 1234 -vo xv <some_MRL>' -> 769 FPS ('mplayer' cannot VSync because of the "compositor")
4. In all cases, compared with OpenGL driver/extension:
'mplayer -benchmark -nosound -frames 1234 -vo gl2 <some_MRL>' -> 60 FPS ( )
NOTE: whatever your 'nvidia-settings', 'mplayer' ( ALWAYS enable XV_SYNC_TO_VBLANK (see 'xvinfo' output before and after starting 'mplayer')

LCD/CRT/whatever-screen perspective
Now comes the part that made me tear my hair off...
In my first Xorg settings, I let Xorg take the maximum refresh rate compatible with my LCD projector's specifications -> 85Hz.
Now, though achieved ("rendered") FPS (both OpenGL and XVideo) were perfectly in sync with the Xorg/GPU's refresh rate (85Hz <-> 85 FPS), I still experienced the "tearing" effect (even from a "bare" X windows + mplayer - no KDE/Gnome/whatever - perspective)... Grrrr!!!
Then came to my mind the fact that my old (1999) LCD projector (like many current LCD panels by the way) was designed to work at a 60Hz frequency... and I was feeding him 85Hz... thus having the same "tearing"-causing discrepancy between FPS and refresh rate... but from my LCD's internal video circuits perspective.
I then forced Xorg to feed 60Hz to my LCD (see 'xorg.conf' below)... and guess what... all tearing disappeared !!!
Conlusion: if you are using somehow-fixed-refresh-rate video equipment (and I *would* think this is very often the case, except when using plain old CRTs), make sure to use the proper refresh rate! Now, recent material maybe implements VSync internally (while my old stuff didn't seem to)... but better have the entire video chain be synchronized if you want "perfect" quality

I've been able to watch "Space Cowboys" yesterday evening with total satisfaction
Please correct me wherever I'm wrong or unclear !

Cheers to all

My 'xorg.conf'
Section "Monitor"
    Identifier     "Monitor0"
    ModelName      "LCD Panel 1024x768"
    HorizSync       23.0 - 80.0
    VertRefresh     50.0 - 101.0
    Option         "dpms"

Section "Device"
    Identifier     "Videocard0"
    Driver         "nvidia"
    Option         "NoLogo" "true"
    Option         "IgnoreDisplayDevices" "DFP, TV"
    Option         "ConnectedMonitor" "CRT"
    Option         "UseEDID" "false"
    Option         "DPI" "75 x 75"
    Option         "DynamicTwinView" "false"
    Option         "RandRRotation" "false"
#    Option         "XvmcUsesTextures" "true"
    Option         "TripleBuffer" "true"

Section "Screen"
    Identifier     "Screen0"
    Device         "Videocard0"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Viewport    0 0
        Depth       24
        Modes      "1024x768_60" "800x600_60" "640x480_60"

Section "Extensions"
    Option         "Composite" "Enable" # If enabled (and used), use OpenGL to VSync
My '/etc/bashrc'
if [ "${DISPLAY:0:1}" == ":" ]; then
  export __GL_SYNC_TO_VBLANK=1
  if [ -x /usr/bin/nvidia-settings ]; then
    if [ -r ~/.nvidia-settings-rc ]; then
      /usr/bin/nvidia-settings --load-config-only --config=~/.nvidia-settings-rc 2> /dev/null
    elif [ -r /etc/X11/nvidia-settings-rc ]; then
      /usr/bin/nvidia-settings --load-config-only --config=/etc/X11/nvidia-settings-rc 2> /dev/null

Last edited by cdufour; 02-01-07 at 02:02 AM.
cdufour is offline   Reply With Quote