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

Bug #1280665 reported by Joseph Yasi on 2014-02-15
148
This bug affects 37 people
Affects Status Importance Assigned to Milestone
libsdl
Won't Fix
Medium
libsdl1.2 (Ubuntu)
Medium
Unassigned
Trusty
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

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

Joseph Yasi (joe-yasi) wrote :
Joseph Yasi (joe-yasi) on 2014-02-16
description: updated
tags: added: patch

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.]

unset SDL_VIDEO_X11_BACKINGSTORE fixes tearing on intel igpu with xbmc for me

Robie Basak (racb) on 2014-02-21
Changed in libsdl1.2 (Ubuntu):
importance: Undecided → Medium

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.

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

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.

Launchpad Janitor (janitor) wrote :

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

Changed in libsdl1.2 (Ubuntu):
status: New → Confirmed
Johan Ferner (johan-ferner) wrote :

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

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).

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.

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.

luke (lukeg007) wrote :

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

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

luke (lukeg007) wrote :

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

description: updated
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
Fuujuhi (fuujuhi) wrote :

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

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.

David Gnedt (lxp13) wrote :

+1 for trusty backport

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.

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

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
pcworld (pcworld) wrote :

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

tags: added: verification-done
removed: verification-needed
smlx (sml) wrote :

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

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.

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.

Ivo Anjo (knuckles) wrote :

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

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.

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.

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) on 2014-05-17
Changed in libsdl1.2 (Ubuntu Trusty):
status: Fix Committed → Fix Released
Colin Watson (cjwatson) on 2014-05-19
Changed in libsdl1.2 (Ubuntu Trusty):
status: Fix Released → Fix Committed
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

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.

Changed in libsdl:
importance: Unknown → Medium
status: Unknown → Won't Fix
To post a comment you must log in.
This report contains Public information  Edit
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.