i-rinat / libvdpau-va-gl

VDPAU driver with OpenGL/VAAPI backend
MIT License
161 stars 26 forks source link

Video tearing with any version above 0.2.1 #44

Closed trinaldi closed 9 years ago

trinaldi commented 9 years ago

Hi, Rinat.

I've been scratching my head on this one: Any version above 0.2.1 creates video tearing on both mplayer and Flash. I don't know which commit/change makes this happen.

I don't know what kind of info you need, I'm gonna post what I think it's relevant: Ubuntu 15.04;

vdpauinfo header:

display: :0   screen: 0
[VS] Software VDPAU backend library initialized
libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_37
libva info: va_openDriver() returns 0
API version: 1
Information string: OpenGL/VAAPI/libswscale backend for VDPAU

vainfo header:

libva info: VA-API version 0.37.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_37
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.37 (libva 1.5.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Ivybridge Mobile - 1.5.0

mesa-vdpau-drivers 10.5.2-0ubuntu1 vdpau-va-driver 0.7.4-3 libvdpau1 0.9-1

If you need some other info, please tell me!

Thanks for your work.

i-rinat commented 9 years ago

Tearing is an inherent issue of X11. X11 draws instantly and synchronously, so one doesn't have a way to determine when drawing will occur regarding to vertical synchronization. Sometimes upgrading client applications, X server, or drivers introduce delays or eliminates them. And drawing that happened in the middle of screen refresh moves to the pause time. That's how tearing disappears. If for similar reason, drawing moves from pause period to the time of active screen refresh, you start to see tearing.

There is only way to help mitigate tearing possible for X11 apps: draw to back buffer and then present it instantly with something like XCopyArea. One can also actively wait for vsync, but that additional care is not applicable for middleware such as libvdpau-va-gl. Assume you are running it with Flash movies, and there are 60 of them on the page simultaneously. As they all run in one thread, waiting for vsync will add 1/60 s delay for each of them, combining to 1 second for each frame. That one thread is browser main thread, so browser will become extremely laggy too.

I suggest to use composition managers like compton instead. Composition manager will be the only who waits for vsync, and that's acceptable. As always, there is no working-for-all solution, and even with compton you'll have to experiment to find settings which are good for you. Start with $ compton --backend xrender --vsync opengl

trinaldi commented 9 years ago

Thanks for your explanation, it makes perfect sense. I've tried tweaking some vsync settings before, none of them was successful, unfortunately. I'll think about compton, with 0.2.1 I have no problems with tearing so I fear that changing things that are working might ruin them, eventually. So, I'll might try it.

The only reason I opened the 'issue' was the fact that the newer versions are somewhat related to the tearing. I figured i might be some new feature or changes that would cause it.

Thanks again, Rinat.

trinaldi commented 9 years ago

I have some updates.

I'm using GNOME as my DE, so Mutter is the acting composition manager. Before trying compton, I've been googling around for Tearing issue and found a workaround - it seems. It is working flawlessly with FF + YouTube's HTML5 Player, I haven't experienced any tearing so far.

The workaround is getting into Looking Glass (GNOME's integrated debugger and inspector tool/interactive JavaScript prompt):

  1. Alt+F2
  2. Run the command 'lg'
  3. At the "Evaluator" tab, run 'Meta.disable_unredirect_for_screen(global.screen);'
  4. Press ESC to leave Looking Glass

That removed the tearing issues I had with Youtube and Firefox.

You can create a shortcut for Looking Glass:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval 'Main.lookingGlass.toggle();'

I believe you can create a direct shortcut with the command:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval 'Meta.disable_unredirect_for_screen(global.screen);'

As I said, it seems to be working. To be fair, I don't think this is related to libvdpau-va-gl at all, I just thought I should give you a heads up for helping me understand the way X11 work its way around drawing the screen :)

It might help people having tearing issues with Flash (I'm using freshplayerplugin and the same issue is gone).

i-rinat commented 9 years ago

Thanks for the updates. That looks interesting.