Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
Post Reply
andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by andrfgs »

This is a known bug that has been around for some time on Linux and hasn't been solved ever, though I am not sure if its a Factorio bug, a SDL bug or a compositor bug. The game suffers from serious tearing when walking, running or moving the map around. This doesn't seem to manifest when the player is stationary, even if there's movement in the background from machines. The tearing is very aggressive and causes headaches when playing the game. I used to play on Windows, but now I've switched to Linux I began noticing the bug. Other games I played on Linux (both native or through wine/Proton) do not suffer the same problem.

I'm using the following system:
PC: MSI Leopard 8RF (Laptop)
OS: Arch Linux
Kernel: 5.12.10-arch1-1
DE: Plasma 5.22.0 (KWin w/ OpenGL 3.1)
GPU: Nvidia GTX 1070M (using the dedicated gpu)
GPU driver: nvidia 465.31-8
Display Server: X Server (Xorg)

The Linux nvidia driver allows the activation of "Sync to VBlank" for all OpenGL games, which I also tried, on top of Factorio's option to vsync. Things I tried:
- Nvidia's Sync to VBlank On & Factorio's VSync Off
- Nvidia's Sync to VBlank Off & Factorio's VSync On
- Nvidia's Sync to VBlank Off & Factorio's VSync Off
- Nvidia's Sync to VBlank On & Factorio's VSync On
None of them work. Factorio's VSync does not avoid any tearing at all. Also, this happens in both Fullscreen or Windowed mode.

I also attempted to "Force Full Composition Pipeline" to no avail. This is certainly a bug in rendering: when connecting my laptop to an external 4K monitor, which causes the fps to drop below 60fps, I still get tearing, which makes no sense. This might not even be vsync at all but another problem in the render pipeline/display server/compositor. This is really strange as it only happens when moving the player/moving around the map.
Last edited by andrfgs on Sun Jun 27, 2021 6:20 pm, edited 2 times in total.
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving

Post by jodokus31 »

I also encountered something like this more often the last weeks:
If I run around and changing directions randomly, the screen is sometimes "rumbling" briefly. It gets quite irritating.
Sometimes its worse and after I reboot my computer, it gets better, but always a bit.

OS: endavourOS based on Arch
Kernel: 5.12.13-zen1-1-zen
GPU: Nvidia RTX 3600
GPU driver: nvidia 465.31-11

I checked on windows and here i don't have this behaviour.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving

Post by andrfgs »

Hey @jodokus31, what DE and what display server are you using? X11 I assume?
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving

Post by jodokus31 »

Cinnamon with X11

@other Linuxusers: Does somebody else has this problem, too?

quyxkh
Smart Inserter
Smart Inserter
Posts: 1028
Joined: Sun May 08, 2016 9:01 am
Contact:

Re: Tearing on Linux When Moving

Post by quyxkh »

I've been running Arch on a 1060 3GB for many years, thousands of hours of Factorio, and I've never once seen this behavior.
factorio-current.log
A little light googling says it's a refresh-rate mismatch and you sometimes have to turn gsync/freesync on yourself, or force the monitor to 60Hz, or set game.speed to (refresh Hz/60), if you've got nvidia hardware.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving

Post by jodokus31 »

I researched a bit further and it seems, that this here is helping a bit:
https://wiki.archlinux.org/title/NVIDIA ... en_tearing

However, not 100%, but you have to be quite attentive to notice it.
I have the impression, that it also gets better, when I disable my 2. monitor.
quyxkh wrote:
Sun Jun 27, 2021 2:39 am
A little light googling says it's a refresh-rate mismatch and you sometimes have to turn gsync/freesync on yourself, or force the monitor to 60Hz, or set game.speed to (refresh Hz/60), if you've got nvidia hardware.
Thanks for your reply:
My monitor does not support GSync? The second monitor has a refreshrate of 59,88 Hz and also no GSync
Nvidia Control Panel
Last edited by jodokus31 on Sun Jun 27, 2021 6:22 pm, edited 1 time in total.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving

Post by andrfgs »

@quyxkh
Except my monitor doesnt support GSync, only Freesync and my Nvidia card wouldn't work with it either because Optimus laptops dont support it well or have bugs when both are active. And besides, I have no option to activate it either. The monitor is at 60Hz or at least the nvidia driver and KDE reports so. Also, if it's a refresh mismatch, then why is Factorio the only game affected by it? I tried OpenTTD, with and without VSync and it does not suffer from the same problem (the nvidia driver forces vsync even if the game doesn't). OpenTTD also uses SDL2 as the video backend. Not sure what is so specific in Factorio's rendering that causes this.

I've seen tons of blogs about people having tearing problems in Factorio in the past. But I could not understand if it was a Linux problem or not, hence why I posted this bug: they might be caused by different things.

By the way, are you using a laptop or desktop? I'm inclined to think this might be yet again another Optimus problem. I have Optimus manager installed and have Nvidia card only enabled.


@jodokus31
That fix doesn't do anything for me. I double checked and I put my external monitor address there: the monitor went black for a while and then it came back on, which means the command ran sucessfully. Yet, the bug still persisted when I opened Factorio after. It might be because I'm playing in 4K but for me this bug is incredibly noticeable, it causes headaches looking at it.
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving

Post by andrfgs »

Just a discovery I made now: I played Factorio in Window mode maximized and the bug is still there, on my 4K display. When reducing the window size however, such that the game can run at 60FPS, the tearing disappears (or maybe it becomes unoticeable). Should the game hiccup even a bit below 60FPS, the game tears again.

But this is only fixed if I have the Nvidia driver set to VSync. Factorio's VSync is completely ignored. With Nvidia's VSync off and Factorio's VSync on, the game tears regardless of framerate. So this makes me believe there's something wrong with how Factorio renders the frames on Linux. Now with lower fps, not even Nvidia's VSync works.

This is very very strange, because a lower FPS should not cause tearing with VSync, unless Factorio doesn't wait for the full frame to be drawn. Is Factorio's VSync simply an FPS capper? Are frames drawn immediately as they come? Because usually, VSync should wait for the entire frame to be drawn. I'm not even sure this was possible in OpenGL, this behaviour seems like the one Vulkan does in VK_PRESENT_MODE_IMMEDIATE_KHR.
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by andrfgs »

Bumping this post since this bug is really annoying and has been around for a while. I know the Linux demographic is usually small, so Linux support is usually a non priority but I would be really grateful if the devs could look into this Linux bug more in detail when possible.

And for Linux users, if you found a way to fix this bug please can you share the fixes here?
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by jodokus31 »

I have tried several things now:
- Disable the compositing system in Cinnamon
- Use compton as compositing system
- Try XFCE 4 (with and without compositing)
- Use exactly same refresh rate on 2.monitor (59,95 Hz).
- Use Triple Buffering
- Vsync on/off
- ForceCompositionPipeline on/off
- Try beta driver from Nvidia 470.xx
- Connect 2. monitor via HDMI instead of DisplayPort
- Use different 2. monitor (might work better)
- Reduce window resolution
- Experimenting with "The rest"-settings in factorio via Ctrl+Alt + Click on Settings in main menu

The thing, that seems to work best is to disconnect 2. monitor completely. And activate Vsync in game and opengl settings, ForceCompositionPipeline=on and reduce resolution to like 1800x1400
Quite disappointing.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by jodokus31 »

One thing, that's seems quite laggy is the "Show all smoke" - option

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by andrfgs »

Turns out this is a bug that is made manifest by another bug. Apparently, my game suffers from a huge fps drop on the Steam version but not on the non steam version. As said, the game only tears for me if the FPS is lower than the refresh rate. In the non steam version, which runs at 60fps in 4K on an external monitor, with the exact same mods and on the exact same game, I do not see this issue.

I reported the Steam bug on Steam. But regardless, this is another separate bug, which I found due to the Steam bug. Here's a link for my post in Steam: https://steamcommunity.com/app/427520/d ... 883910697/

My laptop monitor is turned off, only the external monitor is turned on.
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

User avatar
jodokus31
Smart Inserter
Smart Inserter
Posts: 1603
Joined: Sun Feb 26, 2017 4:13 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by jodokus31 »

jodokus31 wrote:
Thu Jul 01, 2021 11:15 am
I have tried several things now:
- Disable the compositing system in Cinnamon
- Use compton as compositing system
- Try XFCE 4 (with and without compositing)
Turns out, that compositing can't be disabled in cinnamon, which is somehow based on OpenGL
I experimented a bit with XFCE4, where I can deactivate compositing.
ForceCompositionPipeline needs to stay off, then it works kind ok now.

I also open factorio with:
export __GL_SYNC_TO_VBLANK=0
export __GL_FSAA_MODE=11
export __GL_LOG_MAX_ANISO=4

If have to see, if its stays better...
andrfgs wrote:
Fri Jul 02, 2021 10:19 pm
Turns out this is a bug that is made manifest by another bug. Apparently, my game suffers from a huge fps drop on the Steam version but not on the non steam version. As said, the game only tears for me if the FPS is lower than the refresh rate. In the non steam version, which runs at 60fps in 4K on an external monitor, with the exact same mods and on the exact same game, I do not see this issue.

I reported the Steam bug on Steam. But regardless, this is another separate bug, which I found due to the Steam bug. Here's a link for my post in Steam: https://steamcommunity.com/app/427520/d ... 883910697/

My laptop monitor is turned off, only the external monitor is turned on.
Maybe, steam messes around with opengl under linux? I never used the steam version.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by andrfgs »

Maybe it does. I would wish so much for a Vulkan version of this game. But I do understand the work of targeting the rendering engine for Vulkan is abysmal... Even when using SDL...
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.

andrfgs
Inserter
Inserter
Posts: 21
Joined: Fri Sep 04, 2020 10:12 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by andrfgs »

Apparently, this is a bug in all OpenGL games on Linux which use the Nvidia drivers on the X Server. It is a driver problem that hasn't been solved yet. All we Linux users can expect is that NVidia developers learn how to program a proper VSync given they suck at it.

It also seems SDL doesnt even implement VSync at all since checking those options on SDL games does nothing.
Definition of Evil: put train lines at (0, 0) with a constant stream of trains passing by.


User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Tearing on Linux When Moving (EDIT: When FPS is lower than refresh rate)

Post by ptx0 »

andrfgs wrote:
Tue Jul 06, 2021 11:52 pm
Apparently, this is a bug in all OpenGL games on Linux which use the Nvidia drivers on the X Server. It is a driver problem that hasn't been solved yet. All we Linux users can expect is that NVidia developers learn how to program a proper VSync given they suck at it.

It also seems SDL doesnt even implement VSync at all since checking those options on SDL games does nothing.
does nouveau work? fwiw i have to add an override to xorg config.d for amdgpu to paint the screen using vsync

Post Reply

Return to “Technical Help”