libsdl1.2 always uses backingstore which causes tearing in modern X servers

Bug #1280665 reported by Joseph Yasi
148
This bug affects 37 people
Affects Status Importance Assigned to Milestone
libsdl
Won't Fix
Medium
libsdl1.2 (Ubuntu)
Fix Released
Medium
Unassigned
Trusty
Fix Released
Medium
Unassigned

Bug Description

[Impact]
Tearing in SDL applications regardless of vsync setting.

[Test Case]
Use eg. XBMC to play any video, or a particular video that more easily shows up the tearing of the images.

[Regression Potential]
This is a regression fix in itself, and restores old behavior.

---

Fedora 21 has a similar patch applied https://bugzilla.redhat.com/show_bug.cgi?id=1073057

libsdl1.2 always enables backingstore when it is present in the X server. For modern X servers, backingstore is implemented by redirecting through the composite extension. This causes tearing on SDL applications such as xbmc because the redirected rendering is not guaranteed to be synchronized.

A discussion of the problem by Nvidia is here: https://devtalk.nvidia.com/default/topic/679688/linux/tearing-in-sdl-1-2-apps-unless-composite-extension-is-completely-disabled-/post/4111287/#4111287

The upstream bug is here: https://bugzilla.libsdl.org/show_bug.cgi?id=2383

I have a patch that restores a check for the SDL_VIDEO_X11_BACKINGSTORE environment variable before trying to enable backingstore.

Related branches

Revision history for this message
In , Kokoko3k (kokoko3k) wrote :

SDL_VIDEO_X11_BACKINGSTORE has no effect anymore (since years) , and having BACKINGSTORE enabled everytime may lead to tearing effect with newer Xorg servers if composite extension is enabled.

This comment makes me think that there is no point in leaving it in that state:

#if 0 /* This is an experiment - are the graphics faster now? - nope. */
if ( SDL_getenv("SDL_VIDEO_X11_BACKINGSTORE") )
#endif

Revision history for this message
Joseph Yasi (joe-yasi) wrote :
Joseph Yasi (joe-yasi)
description: updated
tags: added: patch
Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "sdl-check-for-SDL_VIDEO_X11_BACKINGSTORE.patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

Revision history for this message
In , Lordmocha (lordmocha) wrote :

unset SDL_VIDEO_X11_BACKINGSTORE fixes tearing on intel igpu with xbmc for me

Robie Basak (racb)
Changed in libsdl1.2 (Ubuntu):
importance: Undecided → Medium
Revision history for this message
In , 7-ajax (7-ajax) wrote :

Since I'm the person most nearly responsible for the X side of this problem, I'll add some background here.

Way back in 2007 (a bit before xserver 1.4) I rewrote X's bs implementation in terms of some of the Composite extension's internal machinery; automatic redirection in the Composite sense is equivalent to core backing store's WhenMapped state, so it made sense to do the one in terms of the other. What I didn't do then, though I'd intended to, was automatically advertise that backing store support if the Composite extension was enabled; you needed to still explicitly enable it in xorg.conf for the server to advertise the support.

In 1.15 I finally fixed that up, so now the server claims to support backing store if the Composite extension is enabled (and it usually is). This was intended to be a convenience for legacy applications that - arguably brokenly - require backing store support to work correctly because they don't bother to implement an Expose handler.

The automatic redirection code, however, is basically just XCopyArea. It doesn't know what a vblank is, it can't synchronize updates with the retrace, hence the tearing. The old pre-1.4 BS code was not any better in that respect. The only reason you _might_ want BS is if you're not running a compositor (hence wouldn't have vsync anyway), and even then it's a tradeoff, implicit double-buffering on the server side versus marginally less tearing and possibly not needing a proper Expose handler. I can't speak to whether working Expose handlers are common for SDL apps, but naively I would expect they're not common, that SDL apps default to being "like fullscreen" and don't expect to repaint things due to window system events.

So at a bare minimum I would suggest checking whether there's a compositor running on the screen already, and defaulting BS to off if there is. The code to do that is approximately:

    char *s = asprintf("_NET_WM_CM_S%d", screen);
    Atom a = XInternAtom(dpy, s);
    Window w = XGetSelectionOwner(dpy, a);

    if (w) /* compositor running */ ;

If possible I would suggest deferring the decision about BS-or-not to the point where you know what kind of rendering you're going to do, if that's a thing you can know. It's almost never going to be useful for GL clients.

Revision history for this message
In , Sam Lantinga (slouken) wrote :

Thanks for the info, that's very useful! :)

Revision history for this message
In , Sam Lantinga (slouken) wrote :

We don't have a release of SDL 1.2 planned, and Ryan is actively working on a binary compatible 1.2 API built on top of SDL 2.0, which doesn't have this problem.

I'm assigning this bug to Ryan just so he sees it and can update it when the 1.2 API on top of SDL 2.0 is available.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in libsdl1.2 (Ubuntu):
status: New → Confirmed
Revision history for this message
Johan Ferner (johan-ferner) wrote :

This bug causes tearing in xbmc with the latest nvidia drivers. Please apply the patch.

Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

I've the same with xbmc on 14.04 on intel (haswell). The upstream bug report has more background on the issue.

I've verified the patch works and it alone fixes the tearing issue, so I proposed it for merging. The u-series is not open yet during this weekend it seems, but probably next week this'll need to be uploaded there first before fixing in trusty.

Meanwhile, I've built the fixed libsdl1.2 in my PPA: https://launchpad.net/~timo-jyrinki/+archive/ppa (feel free to test and give positive/negative feedback).

Revision history for this message
pcworld (pcworld) wrote :

I had tearing in Teeworlds with vsync enabled after upgrading from 13.10 to 14.04.
I confirm that the patch sdl-check-for-SDL_VIDEO_X11_BACKINGSTORE.patch fixes the issue.

Revision history for this message
Joseph Yasi (joe-yasi) wrote :

It should be noted that upstream is not planning on making another SDL 1.2 release. They are building a compatibility API for SDL 2.0 instead. We should apply this patch until that compatibility API is ready.

Revision history for this message
luke (lukeg007) wrote :

how do you apply this patch tried sudo patch -i "patch" didnt work. thanks in advance

Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

luke: easiest is if you just add the PPA where I applied it already:
sudo apt-add-repository ppa:timo-jyrinki/ppa
sudo apt-get update
sudo apt-get install libsdl1.2debian

You can later remove the PPA with:
sudo apt-get install ppa-purge
sudo ppa-purge ppa:timo-jyrinki/ppa

Revision history for this message
luke (lukeg007) wrote :

Hi Timo, thanks for that helping out a linux novice, much appreciated.

description: updated
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libsdl1.2 - 1.2.15-8ubuntu2

---------------
libsdl1.2 (1.2.15-8ubuntu2) utopic; urgency=medium

  * debian/patches/sdl-check-for-SDL_VIDEO_X11_BACKINGSTORE.patch:
    - Restore old backingstore behavior to prevent tearing
      (LP: #1280665)
 -- Timo Jyrinki <email address hidden> Sat, 19 Apr 2014 23:22:43 +0300

Changed in libsdl1.2 (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Fuujuhi (fuujuhi) wrote :

For info, this patch works for me on ubuntu trusty 14.04 + nvidia 331.38 + xbmc 13 gotham.
Thanks!

Revision history for this message
Maarten Fonville (maarten-fonville) wrote :

When will this be backported to trusty? It is a quite relevant and important fix for those using the new radeon vdpau acceleration for XBMC. I don't think many people would expect the source of their tearing to be in libsdl1.2 and find this fix on their own.

Revision history for this message
David Gnedt (lxp13) wrote :

+1 for trusty backport

Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

Yes I agree this should be backported, but we need someone to sponsor my branch lp:~timo-jyrinki/ubuntu/trusty/libsdl1.2/fix_backingstore_tearing I prepared for trusty. So currently waiting for that, after which SRU team will evaluate it, and this bug will be updated if/when it lands to trusty-proposed since at that point people are asked to test it once more.

Revision history for this message
Andrejs Hanins (ahanins) wrote :

Just informing about testing results: I also have Intel Haswell graphics and Timo's fix helped me. Using XBMC for a week with Timo's fix and no problems. Tearing is gone. No side effects observed.

P.S. Thanks a lot Timo!

Changed in libsdl1.2 (Ubuntu Trusty):
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Brian Murray (brian-murray) wrote : Please test proposed package

Hello Joseph, or anyone else affected,

Accepted libsdl1.2 into trusty-proposed. The package will build now and be available at http://launchpad.net/ubuntu/+source/libsdl1.2/1.2.15-8ubuntu1.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, and change the tag from verification-needed to verification-done. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed. In either case, details of your testing will help us make a better decision.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance!

Changed in libsdl1.2 (Ubuntu Trusty):
status: Triaged → Fix Committed
tags: added: verification-needed
Revision history for this message
pcworld (pcworld) wrote :

libsdl1.2debian 1.2.15-8ubuntu1.1 fixes the bug.

tags: added: verification-done
removed: verification-needed
Revision history for this message
smlx (sml) wrote :

I can confirm that libsdl1.2debian 1.2.15-8ubuntu1.1 from trusty-proposed fixes this bug for me in XBMC.

Revision history for this message
Joseph Yasi (joe-yasi) wrote :

I can verify that the bug still occurs with libsdl1.2debian 1.2.15-8ubuntu1 and is fixed by libsdl1.2debian 1.2.15-8ubuntu1.1.

Revision history for this message
Andrejs Hanins (ahanins) wrote :

I also confirm that 1.2.15-8ubuntu1.1 from trusty-proposed fixes tearing bug in XBMC for me (Intel Haswell CPU). Original trusty version 1.2.15-8ubuntu1 definitely has this bug for me.

Revision history for this message
Ivo Anjo (knuckles) wrote :

+1 had the same issue with XBMC, package in trusty-proposed fixed the issue.

Revision history for this message
JaSauders (jasauders) wrote :

I was having screen tearing on Ubuntu 14.04 with XBMC 12.3 & 13.0. Never had tearing on VLC or smplayer though but no matter what I did it continued on XBMC. Once I added the ppa, exited XBMC and reopened it, tearing is gone. Thank you for the immediate fix!

Devs - *please* merge this into 14.04.

Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

Hey. Enough verifications, thank you :) The bug is already marked 'verification-done', but as per https://wiki.ubuntu.com/StableReleaseUpdates process it will take at minimum 3 more days before the stable release team copies the updated package to -updates for everyone to get.

Revision history for this message
JaSauders (jasauders) wrote :

Sorry Timo, just had to share the good news with my own little +1. :)

Thanks for the information regarding the process too as I was not aware of that. I'm sure I speak for everone when I say we thank you for the PPA to circumvent this issue until it arrives in the main repo. Your time is appreciated!

smuggly (smuggly-1)
Changed in libsdl1.2 (Ubuntu Trusty):
status: Fix Committed → Fix Released
Colin Watson (cjwatson)
Changed in libsdl1.2 (Ubuntu Trusty):
status: Fix Released → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libsdl1.2 - 1.2.15-8ubuntu1.1

---------------
libsdl1.2 (1.2.15-8ubuntu1.1) trusty; urgency=medium

  * debian/patches/sdl-check-for-SDL_VIDEO_X11_BACKINGSTORE.patch:
    - Restore old backingstore behavior to prevent tearing
      (LP: #1280665)
 -- Timo Jyrinki <email address hidden> Sat, 19 Apr 2014 23:22:43 +0300

Changed in libsdl1.2 (Ubuntu Trusty):
status: Fix Committed → Fix Released
Revision history for this message
Colin Watson (cjwatson) wrote : Update Released

The verification of the Stable Release Update for libsdl1.2 has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regresssions.

Revision history for this message
In , illume (illume) wrote :
Changed in libsdl:
importance: Unknown → Medium
status: Unknown → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.