Thursday, 13 April 2017

Steam Streaming on Linux and Tearing/VSync Issues

So I gave in. It's true. I have given up on the idea that Lenovo will, in any foreseeable future, make a T4N0p laptop that has an awesome graphics card. I have since put some money in to building a small Mini-ITX rig that has a GTX 1070 inside it and planned on using steam streaming.

Now! I was really hyped up to play Fallout 4 by Steam-In-Home-Streaming it from my ITX rig. I did the download and I streamed it and... tearing. I tried VSync on the host-side, I tried hardware/software encoding on both sides ... nothing. Still tearing while streaming Fallout 4.

Here's where the eureka moment was, for me. I was actually browsing some Steam forums, trying to see if people have experienced the same issues, but I happened to notice that, while scrolling down the page, there was ever-so-slight, visible tearing in my Chrome session that I never noticed before.

I connected a monitor to the ITX rig directly and it confirmed my belief. There is no tearing on the server-side of the streaming, it must be my T440p.

XFCE's compositor has the following option in the "Window Manager Tweaks" settings:


This option does ABSOLUTELY NOTHING. It's either broken or has never worked. It doesn't VSync at all. After ticking the "Synchronise drawing to the vertical blank", tearing was still visible in Steam-streaming and in my Chrome session.

I later found this in by Xorg.0.log file:

[     3.612] (--) intel(0): Output DP2-2 using initial mode 1920x1200 on pipe 1
[     3.612] (==) intel(0): TearFree disabled
[     3.612] (==) intel(0): DPI set to (96, 96)

Now, TearFree is Intel's code-word for VSync. We need to enable this to fix the tearing.

There's a lot of discussion in the community about VSync and whether or not it's a good thing. It limits your framerates, so for those who want a GPU to pump out 300FPS on a monitor that only refreshes at 60Hz, you won't want to enable TearFree. For the rest of us who are interested not so much in raw frame counts but more in picture quality and not having tearing when playing games, you'll want to enable it.

Here's how you do it. If you don't already have an xorg.conf.d directory, you'll want to create it:

$ mkdir /etc/X11/xorg.conf.d

After that, use your favourite editor to edit /etc/X11/xorg.conf.d/20-intel.conf and put the following inside it:

$ cat /etc/X11/xorg.conf.d/20-intel.conf 
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod" "sna"
   Option      "TearFree" "true"
EndSection

After this, you reboot. Checking your /var/log/Xorg.0.log again, you should see this:

[     3.459] (**) intel(0): Option "AccelMethod" "sna"
[     3.459] (**) intel(0): Option "TearFree" "true"
[     3.461] (II) intel(0): Output eDP1 has no monitor section

Now your Steam-streaming games should be tear-free. Enjoy.