Difference between revisions of "Improving performance"

From Linux Gaming
Jump to navigation Jump to search
 
(223 intermediate revisions by 13 users not shown)
Line 1: Line 1:
Gaming performance on Linux varies from game to game, and is ''very'' hardware dependent. Some of your games might run better than on Windows, some may run worse. But even with the same game where you would get a performance gain with one GPU you might take a performance hit with another. So it's impossible to say how your performance will compare to Windows. 
BUT: Generally, you should be expecting about the same performance (±10%) as on Windows<ref>https://www.youtube.com/watch?v=Nc1mS1hxn8Q</ref>. If your experience is much worse, there is probably an issue. Most Linux distributions aren't properly configured for gaming ''at all''. Nobara is a notable exception, it already includes many of the tweaks that are mentioned here. 
The good thing is, that this is very easy to change. Your performance should be OK if you do all ''major tweaks''. 
You don't have to go further if that is good enough for you and you don't want to bother reading the rest of the article. Everything else isn't as important, only situational, or might come with drawbacks. But if you still have issues, or you just want ''more'' ''performance'', you should definitely read it. There is much that can be done to get an additional bit of performance, less input lag, less FPS drops, and significantly more performance on severely under-powered systems.
== Major tweaks ==
== Major tweaks ==
This will give a ''huge'' boost for all games. If your presets are bad, this might be in the magnitude of 300% more FPS:
These are the important tweaks, they will give a ''huge'' boost for all games. You should do all these tweaks, otherwise you will not have a good gaming experience:
*If you use X11, [[Compositor|disable composition]].
*[[Compositor|Disable composition]].
*Set GPU and CPU to maximum performance. This might not always be necessary, but will give you large improvements in some cases. Definitely try it if you notice stuttering or input lag.
**You don't need to do this if you use GNOME (the default on Nobara Official, Nobara GNOME, and Pop!_OS)
**CPU: You can use [[Gamemode|GameMode]] or [[CoreCtrl]] to do this.
**You only need to do this [[Misc#Test whether you use X11 or Wayland|if you use X11]], it's not necessary on Wayland.
**GPU: Read the AMD/Nvidia specific tweaks section to see how.
**You do have to do this on Nobara KDE!
*Look at your thermals and if they are too high, adapt the fan speed.
*Use [[Gamemode|GameMode]]
==Minor tweaks==
*If they are not already installed, [https://github.com/lutris/docs/blob/master/InstallingDrivers.md install the correct drivers]
This will not make a difference as big as the major tweaks. But depending on the game, it can still give you something in the scale of ~20% FPS. Maybe more, maybe less.  
**You don't have to do this on Nobara or Pop!_OS (if you chose the NVIDIA ISO for NVIDIA graphics cards).
**Do '''NOT''' download anything manually. Read the link above.
**If you have an old Nvidia card that is not supported by the current driver, look at the Nvidia specific section.
**If you don't have an Nvidia GPU, the correct drivers are probably already preinstalled. However, you won't do anything wrong if you use the guide above. On some distributions this will also give you a more recent version. Old drivers can be a problem if they are too old.
*[[Misc#Watching the temperature|Look at your thermals]], and if they are too high, adapt the fan speed.
**There are tools to do this inside Linux, but it's probably easier to do it in the BIOS.
*If you have two GPUs (for example an integrated and a dedicated one), use the one with more performance. ''TODO: How?''
*Make sure you are using the Performance CPU governor, this can be changed with <code>cpupower</code>, part of the linux-tools package on most distros, or <code>cpupower-gui</code>, which is its own package.
 
==AMD/Nvidia specific==
These tweaks are depending on what type of '''GPU''' you have. Your CPU type is not important.
 
===AMD ===
It's probably worth doing, but if everything is fine and you think this is too complicated, you can ignore this section. The default values should be fine for casual gaming. If you want the maximum performance, or minimal input lag, read further.
 
==== Overclocking and controlling the GPU ====
You can use [[CoreCtrl]] to add performance profiles for your games, set fan speeds, and overclock/undervolt. You can also set CPU performance here, it will overrule the GameMode settings.
 
The default (automatic) performance profile is probably fine for most games, but it might make a big difference for some games. For example, if a game has a capped frame rate, the GPU might not clock to the highest speed which will result in sub optimal performance. Setting your GPU to high performance can yield higher FPS, or lower input lag.
 
Alternatively, you can also use GameMode, however this is probably a bit more complicated.
 
==== Using the correct driver ====
'''DO NOT DOWNLOAD DRIVERS WITH YOUR BROWSER'''. This is the ''"official"'' way, offered by AMD, but it's also the worst possible thing you can do.


*Enable <code>Fsync</code>. You need to use a compatible Kernel (like <code>zen</code>, <code>tkg-pds</code>, or <code>Xanmod</code>; '''kernel above 5.16 is compatible with F-sync out of the box'''), and enable it in Lutris: Right click the game -> <code>Configure</code> -> <code>Runner options</code> -> Enable <code>Fsync</code>
There are two Vulkan drivers available for AMD GPUs: amdvlk and vulkan-radeon (RADV, MESA). The vulkan-radeon (RADV, MESA) one is the open-source version and is preferable due to better performance in most cases. It should be the one that is installed as default, so usually you would not have to do anything.
 
If you experience sub-par performance, you can check which driver you are using. On Arch and Ubuntu based distros (for example Manjaro, or Pop!_OS), you can check which Vulkan implementations are installed on the system with this [[Terminal|command]]: <code>ls /usr/share/vulkan/icd.d/</code>. It should say <code>radeon_icd.x86_64.json</code>. If you have the 32bit version installed, it will (also) say <code>radeon_icd.i686.json</code>. There might be others (intel for example), just be sure that there is not <code>amd_icd64.json</code>. The system will use amdvlk by default if both are installed.
 
If you want to use amdvlk, look for instructions for your distribution. Downloading something from the AMD website should only be the last resort, if there really is no better option. There probably is a better option.
 
===Nvidia===
Use X11. You lose around 16% FPS on Wayland<ref name=":4">https://www.phoronix.com/review/wayland-nv-amd-2023/5</ref>.
 
The [https://wiki.archlinux.org/title/NVIDIA/Tips_and_tricks#Overclocking_and_cooling Arch Wiki] is a great place to start for information, but, as always, it's best to follow documentation specific to your distro.
 
Identify your GPU model from [https://wiki.archlinux.org/title/NVIDIA the Archlinux Wiki's Nvidia page] as well as the [https://nouveau.freedesktop.org/CodeNames.html#NV160 GPU model/family cross-reference page] and install the correct GPU release, as GPUs older than Maxwell require legacy drivers.
*Use DKMS for the driver. DKMS will be necessary for using custom kernels like Zen, Xanmod or tkg with the Nvidia driver because there are no pre-packaged nvidia kernel modules for them. It also lets you update to newer kernel versions without waiting for an Nvidia driver update.<ref>https://wiki.archlinux.org/title/Dynamic_Kernel_Module_Support</ref> Every distro that has proprietary Nvidia driver support ''should'' offer a DKMS version.
*For Arch-based distributions, you may also use TKG's <code>nvidia-all</code> [https://github.com/frogging-family/nvidia-all repo], with <code>_dkms="true"</code> in <code>customization.cfg</code>.<ref>https://www.reddit.com/r/linux_gaming/comments/sc9dv7/need_help_writing_wiki_article_about_how_to_tweak/hu54e1g/?context=3</ref>
*You may also use the nvidia-vulkan-dkms to acquire the most recent vulkan beta release with the most recent extensions.
 
====== Overclocking and controlling the GPU ======
*Enable coolbits in the Xorg configuration [https://wiki.archlinux.org/title/NVIDIA/Tips_and_tricks#Enabling_overclocking as described in the Archlinux Wiki]. Specifically, setting the coolbits value to 28 on anything currently supported (post-Fermi) will enable full control over the GPU through the nvidia-settings panel (at least, as much control as you're allowed to be given).
*Use [https://gitlab.com/leinardi/gwe GreenWithEnvy] for overclocking, setting power limits (raise or lower) and fan curves. It's the closest alternative we have to MSI Afterburner.
**Alternatively, you can also use the CLI, as described [https://wiki.archlinux.org/title/NVIDIA/Tips_and_tricks#Custom_TDP_Limit here].
 
====== DLSS, RTX, Reflex features on support Nvidia GPUs (NVAPI) ======
The github repo for DXVK-NVAPI should be read [https://github.com/jp7677/dxvk-nvapi here] to fully understand what you may need to do, as the Proton version you use may necessitate certain additional steps.
*Make sure to use a Proton version of at least 6.3-6, Experimental, Proton-6.21-GE-2 (now known as GE-Proton) or Proton-tkg/wine-tkg-git of 6.17 or greater (or build your own) for DLSS, RTX, and/or Reflex on supported GPUs.
*Using the most recent Proton, Proton Experimental or GE-Proton (As of this writing on 2022-09-06) requires the following:
**Steam: use the launch options PROTON_ENABLE_NVAPI=1 DXVK_ENABLE_NVAPI=1 %command%. You may also need to add PROTON_HIDE_NVIDIA_GPU=0 for some games that do not use DXGI for detection (per the [https://github.com/jp7677/dxvk-nvapi#readme DXVK=NVAPI github README]).
**For non-Steam games, use the latest Lutris or wine-ge-custom build, '''with [[Lutris]]''', and make sure to toggle on DLSS support in the Configure -> Runner options menu.
 
== Minor tweaks ==
These will not make a difference as big as the major tweaks. It might give you some FPS, or lower your input lag, but you don't have to do these tweaks if you think this is too complicated.
 
*Don't use Flatpak to run your game. You lose up to 20% FPS if the game is CPU bound<ref>https://github.com/flatpak/flatpak/issues/4187</ref>.
*Enable <code>Fsync</code>. You need to use a compatible Kernel (one of the gaming optimized kernels, or just any kernel above 5.16), and enable it in Lutris: Right click the game -> <code>Configure</code> -> <code>Runner options</code> -> Enable <code>Fsync</code>
**If you can't or don't want to install a kernel that is Fsync compatible, you can also enable Esync. The performance boost is usually not as large, though.
**If you can't or don't want to install a kernel that is Fsync compatible, you can also enable Esync. The performance boost is usually not as large, though.
*Install an optimized kernel like <code>zen</code>, <code>tkg-pds</code>, or <code>Xanmod</code>. <code>tkg-pds</code> ([https://github.com/Frogging-Family/linux-tkg linux-tkg] with pds scheduler) seems to perform better than <code>zen</code><ref>https://www.youtube.com/watch?v=qNzd57b0h08</ref>, but you have to compile it yourself. Alternatively you could also get it from chaotic AUR.<!-- I think, it also gives better input lag. It just feels better. Maybe someone finds a source for this. -->
*Install an optimized kernel like <code>linux-zen</code>, <code>[https://github.com/Frogging-Family/linux-tkg linux-tkg-pds]</code>, <code>[https://xanmod.org/ Xanmod]</code>, or <code>[https://liquorix.net/ Liquorix]</code>. This will also prevent the system from becoming unresponsive when under heavy CPU load.
**<code>linux-zen</code> and <code>linux-tkg</code> kernels are for Arch-based distros, <code>Xanmod</code> and <code>Liquorix</code> for Ubuntu-based distros.
***They should also work with other distributions, but you should always make sure to have a functioning way to update them. If you don't, you end up with an insecure system!
**<code>linux-tkg-pds</code> ([https://github.com/Frogging-Family/linux-tkg linux-tkg] with PDS scheduler) seems to perform better than <code>zen</code><ref>https://www.youtube.com/watch?v=qNzd57b0h08</ref>, and has lower input lag (this is definitely noticeable in competitive shooters). Some people also recommend using <code>linux-tkg-bmq</code> (linux-tkg with BMQ scheduler). Currently there are no scientific tests, so you have to see yourself what works best for you. You can get both from [https://aur.chaotic.cx/ chaotic AUR] ([https://archlinux.pkgs.org/rolling/chaotic-aur-x86_64/ list of available packages]). To get all benefits you have to compile it yourself, though; on a six-core processor, this will take something in the magnitude of half an hour. However, you can use Modprobed-db to only compile kernel modules you need; this will significantly cut down the time needed to compile the kernel.
**You don't need to fear that you might destroy your system. Installing a new kernel does not remove the old one. You can select the kernel you want to boot in GRUB. If things get messed up, just select your old kernel and you're fine.
==Optional==
These tweaks come with some drawback. You might want to apply them, but maybe only for some games.
*If you don't get enough FPS, use [[FSR - FidelityFX Super Resolution|FSR]]. This might ''dramatically'' improve your framerate in GPU limited games but will definitely hurt the image quality.
*[[Environment variables]]:
**Note that for many games, the following is not needed with Nvidia driver 520 (or higher) and DXVK 2.0 (or higher) thanks to VK_EXT_graphics_pipeline_library, Intel and AMD driver support is coming soon. However, there are still games that can profit from it, and it might lead to slightly better frame times<ref>https://www.youtube.com/watch?v=18AYlKq05ew</ref>. <code>DXVK_ASYNC=1</code>: Display frames even if they are not completely rendered. This will reduce stuttering a lot, but it could theoretically trigger anti cheat, even though this never actually happened. Your DXVK version needs to be compatible or patched to use it. Proton-GE, ''until version 7-44'', is compatible. For Non-Steam games you can't use Proton, and need a [https://github.com/Sporif/dxvk-async/releases patched DXVK-Version]. For Lutris you need to copy it to <code>~/.local/share/lutris/runtime/dxvk/</code>, and manually select the version inside Lutris (if you named the folder <code>dxvk-async-1.3</code>, you also need to manually type <code>dxvk-async-1.3</code> in the field).


==Optional==
*Use [https://github.com/ishitatsuyuki/LatencyFleX LatencyFleX] (warning: may trigger anticheat): Similar to NVIDIA Reflex (but works with AMD and Nvidia). Lowers input lag. Manually frame capping your game (so that your GPU never exceeds 80%) should be equally good. (If you use MangoHud to do this, this might add additional input lag!)
*The following tweaks<ref>https://github.com/CryoByte33/steam-deck-utilities/blob/main/docs/tweak-explanation.md</ref> can improve gaming performance, but might not be optimal for other workloads/normal desktop usage. However, it is possible to set/reset these settings with [[gamemode]], as described in [https://www.reddit.com/r/linux_gaming/comments/11lslhs/tutorial_how_to_use_memory_tweaks_from/ this tutorial].
**Use Transparent Hugepages: <code>echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled</code>
***With shared memory: <code>echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled</code>
**Use Compaction Proactiveness: <code>echo 0 | sudo tee /proc/sys/vm/compaction_proactiveness</code>
**Disable Hugepage Defragmentation: <code>echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag</code>
**Lower Page Lock Unfairness: <code>echo 1 | sudo tee /proc/sys/vm/page_lock_unfairness</code>


*Use [[FSR - FidelityFX Super Resolution|FSR]]. This might dramatically improve your framerate in GPU limited games but will definitely hurt the image quality.
*You might want to have a look at the extensive [https://wiki.archlinux.org/title/Gaming#Improving_performance Arch Wiki page] and [https://github.com/AdelKS/LinuxGamingGuide this collection of tweaks].


==Input lag, Desktop Environments, and x11/Wayland ==
=== BIOS tweaks ===
{{Needs work|Problem=Might be outdated, and there is missing data for various desktop environments and window managers}}
*It appears that KDE Plasma (X11) with no composition (currently) is (one of) the best regarding performance, and input lag. Gnome is also ok.<ref>https://www.reddit.com/r/linux_gaming/comments/cii545/linux_input_lag_analysis_v26des_windows_10_1809/</ref>
**Generally you should be fine if you can disable composition. This is not possible in Gnome, but Gnome uses unredirection (the same thing, Windows does) instead, which is almost as good.
*You should only use Wayland, if you can enable FreeSync, because otherwise it will force vsync. If you are using KDE, and you have FreeSync enabled, the performance and input lag should be close to KDE X11 with composition disabled.<ref>https://zamundaaa.github.io/wayland/2021/12/14/about-gaming-on-wayland.html</ref> The input lag will increase by the "half frame" that is displayed with tearing. It's basically the question whether or not you want to wait for the frame to complete before displaying it. KDE Plasma is currently the best DE for Wayland.<ref>https://www.reddit.com/r/linux_gaming/comments/rghr60/about_gaming_and_latency_on_wayland/hpox61p/?context=3</ref>


It should be noted that we are talking about milliseconds here (the best value is 20ms, the worst is 90ms). If you are not susceptible to this, you might not even notice. But generally speaking, the game will feel more responsive if your input lag is low. You might also notice stuttering if you 99th percentile is bad.
* [https://wiki.archlinux.org/title/improving_performance#Enabling_PCI_resizable_BAR Above 4G Decoding (SAM / rBAR)] - A BIOS option that allows the CPU to access the GPU's entire VRAM at once.
*[https://linustechtips.com/topic/1197132-setting-ram-speed-xmp-docp-for-dummies/ (A-)XMP / DOCP profile] - Unlocks the RAM's advertised memory speed ''(resulting in a faster access of the data the CPU needs)''.


== AMD/Nvidia specific tweaks==
=== Only AMD ===


===AMD===
==== GPU ====
* To lower your input lag even more (after doing all major and minor tweaks), you can disable page flipping (this will result in more tearing).
** This only works on X11, but if you care ''that much'' about input lag, you shouldn't use Wayland anyways.
**Create the file <code>/etc/X11/xorg.conf.d/20-amdgpu.conf</code> with content: <syntaxhighlight lang="bash">
Section "Device"
        Identifier "AMD"
        Driver "amdgpu"
        Option "TearFree" "false"
        Option "EnablePageFlip" "false"
EndSection</syntaxhighlight>


*Use [[CoreCtrl]]
*[[Environment variables]]:
**Add a profile for every game:  
**<code>RADV_FORCE_VRS=2x2</code>: Variable rate shading. This will improve performance, but reduce quality of shadows. Alternative values: <code>2x1</code> or <code>1x2</code> to use VRS only in one (x or y) direction<ref>https://www.basnieuwenhuizen.nl/a-first-foray-into-rendering-less/</ref>. (TODO: which is which?)
*** For your GPU select ''Performance mode'': ''Fixed'' and use the ''High'' setting (you may also adapt GPU fan speed here)
**<code>RADV_PERFTEST=sam</code>: Force enable resizable bar/smart access memory. Might improve, but might as well reduce performance. In case it is reducing performance and you use VKD3D, try adding <code>VKD3D_CONFIG=no_upload_hvv</code><ref name=":3" />.
***For your CPU select ''Performance scaling'': ''Custom'' and use ''Frequency governor'': ''Performance''
**<code>RADV_DEBUG=novrsflatshading</code>: disable VRS for [https://graphics.fandom.com/wiki/Flat_shading flat shading] (only on GFX10.3+)
*Use Mesa drivers
**<code>RADV_PERFTEST=nggc</code>: enable NGGC. Can slightly improve performance on RX6000 series, but may reduce performance for other cards<ref>https://www.phoronix.com/scan.php?page=article&item=radeon-radv-nggc</ref>.
**You may find more here: https://docs.mesa3d.org/envvars.html
**<code>RADV_PERFTEST=gpl</code>: Should lead to a behavior similar to shader caching on Windows. Games that don't stutter on Windows, should also not stutter on Linux. Currently, it also disables shader caching, so load times will be high. Is still new, and might not work correctly. You need at least mesa 23 for it to work.


===Nvidia<ref>https://www.reddit.com/r/linux_gaming/comments/sc9dv7/need_help_writing_wiki_article_about_how_to_tweak/hu54e1g/?context=3</ref>===
==== CPU ====
{{Needs work|Problem=not complete, and just copied from a reddit post}}
*[https://web.archive.org/web/20240224060623/https://www.reddit.com/r/linux/comments/15p4bfs/amd_pstate_and_amd_pstate_epp_scaling_driver/ AMD P-State and AMD P-State EPP Scaling Driver Configuration Guide]<ref>https://www.reddit.com/r/linux/comments/15p4bfs/amd_pstate_and_amd_pstate_epp_scaling_driver/</ref> - AMD's CPPC ''(ACPI Collaborative Processor Performance Controls)'' based scaling driver for a more efficient CPU utilization.
*Use the proprietary Nvidia driver. In almost every case the proprietary Nvidia driver will offer much better performance than the open source driver, Nouveau.<ref>[https://www.phoronix.com/scan.php?page=article&item=nvidia-nouveau-2019&num=2 https://www.phoronix.com/scan.php?page=article&item=nvidia-nouveau-2019&num=3]</ref><ref>https://www.phoronix.com/scan.php?page=article&item=nvidia-nouveau-2019&num=2</ref> In addition, Nouveau does not support many features available on newer Nvidia cards.<ref>https://nouveau.freedesktop.org/FeatureMatrix.html</ref>
*''^ Ignore the triple backticks ``` on the page (it's a formatting issue)''
*Use DKMS. DKMS is a prerequisite for using custom kernels like Zen, Xanmod or tkg with the Nvidia driver. It also lets you update to newer kernel versions without waiting for an Nvidia driver update. <ref>https://wiki.archlinux.org/title/Dynamic_Kernel_Module_Support</ref>Every distro that has proprietary Nvidia driver support offers a DKMS version.
 
*The [https://wiki.archlinux.org/title/NVIDIA/Tips_and_tricks#Overclocking_and_cooling Arch Wiki] is the best place to start. Enable coolbits as the link explains. Good is, setting the coolbits value to 28 on anything currently supported (post-Fermi) to enable full control over the GPU (at least, as much control as you're allowed to be given).
*'''''Note''':''
*Use GreenWithEnvy for overclocking, setting power limits (raise or lower) and fan curves. It's the closest alternative we have to MSI Afterburner.
**''Your CPU must be >= <u>Zen 2</u> (not Zen 1, or Zen +) to support the AMD P-State scaling driver. You also have to have <u>CPPC</u> support enabled in your <u>BIOS</u>.''<ref>https://www.reddit.com/r/archlinux/comments/1381g2g/amd_pstate_epp_scaling_driver_available_with/</ref>
*Make sure to use a Proton version of 6.3, Experimental, Proton-6.21-GE-2 or later for Proton-GE and Proton-tkg/wine-tkg-git of 6.17 or greater (or build your own) for DLSS support. For Steam, you need to put <code>PROTON_HIDE_NVIDIA_GPU=0 PROTON_ENABLE_NVAPI=1 %command%</code> in your launch options (side note: there should only ever be one <code>%command%</code>).
**''If <u>CPPC</u> is <u>locked</u> in your BIOS, you might be able to <u>unlock</u> it with [https://github.com/DavidS95/Smokeless_UMAF Smokeless_UMAF].''
*For non-Steam games, use the latest lutris or wine-ge-custom build, '''with Lutris''', and make sure to toggle on DLSS support in the Configure -> Runner options menu (though this might be better-suited to a Lutris article, which should exist). For non-Steam games, you also need a dxvk.conf file with <code>dxgi.nvapiHack = False</code> in it. You can just create one (mine is <code>~/Documents/dxvk.conf</code>) and set <code>DXVK_CONFIG_FILE=/path/to/dxvk.conf</code> in your <code>/etc/environment</code>.
==Differences between Desktop Environments, and X11/Wayland==
*Use [https://github.com/lutris/docs/blob/master/InstallingDrivers.md this] to get minimal required drivers installed.
{{Needs work|Problem=Might be outdated, and there is missing data for various desktop environments and window managers. Source needed for how good unredirection works in Cinnamon}}
*For Arch-based distributions, use TKG's <code>nvidia-all</code> [https://github.com/frogging-family/nvidia-all repo],  with <code>_dkms=""</code> set to true in <code>customization.cfg</code>.
 
== Troubleshooting==  
Desktop Environments may affect your performance. Your overall performance may be bad, or you might have good FPS, but high input lag.
 
Regarding input lag: It should be noted that we are talking about milliseconds here (the best value is 20ms, the worst is 90ms). If you are not susceptible to this (for example because you only play slow games), you may not even notice. But generally speaking, the game will feel more responsive if your input lag is low. You might also notice stuttering when the frame times are fluctuating.
 
=== X11 ===
X11 is currently the best choice if you want minimal input lag.<ref name=":0" />
 
Disabling [[Compositor|composition]] can help to reduce latency and improve performance, either by disabling it manually (KDE Plasma) or by unredirection (GNOME and derivatives like Cinnamon etc.)  
 
The latter is the same thing Windows does for managing Fullscreen games. Disabling composition should lead to slightly less input lag.<ref name=":2" />  
 
KDE Plasma (X11) with no composition appears to be a good and popular choice. GNOME is also valid, but adds a small amount of input lag.<ref name=":2">https://www.reddit.com/r/linux_gaming/comments/cii545/linux_input_lag_analysis_v26des_windows_10_1809/</ref> Cinnamon also uses unredirection which can be manually enabled or disabled on the Settings app under the General section ''(Test needed to know how good it works!)''. Pantheon, the Elementary OS desktop environment, has no option to disable composition at all.
 
You might want to avoid GNOME X11 if you want to use side buttons on your mouse, as this can lead to stuttering. This can be fixed, and is not an issue on Wayland<ref>https://www.reddit.com/r/linux_gaming/comments/qaxz3m/comment/hqankhn/?context=3</ref>. The fix however, requires recompiling, and leads to some hotkeys on keyboard layouts other than QWERTY not working<ref>https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1858#note_818548</ref>.
 
=== Wayland ===
Wayland on Nvidia gives you a performance hit of about 16%<ref name=":4" />.
 
The best way to achieve low input latency on a Wayland compositor is to enable Freesync or enable tearing updates. Currently, Sway and KDE support Freesync for AMD GPU's only. Other wlroots compositors may also support Freesync. KDE plasma 5.27 or higher will be required for tearing updates on Wayland and your game will also need to be run in fullscreen mode for it to work. Wine doesn't yet support tearing on Wayland.  
 
If you cannot enable Freesync, then you will effectively always have Vsync on (unless tearing updates are enabled), regardless of your in game settings. Vsync has seen very wide use across PC's and consoles and a majority of games ship with it enabled by default. If you already play games with Vsync enabled then you shouldn't notice much or any additional latency gaming on Wayland. 
 
Enabling Vsync in game can cause significant additional latency if you are using a Wayland compositor without Freesync. The compositors Vsync implementation can interact with the games Vsync implementation in unpredictable ways. In general there should be no need for in game Vsync if you are using a Wayland compositor, as either Wayland or Freesync will control synchronization. Bear in mind that most games enable Vsync by default.
 
If you are using KDE and you have FreeSync enabled, the performance and input lag should be close to KDE X11 with composition disabled.<ref name=":0">https://zamundaaa.github.io/wayland/2021/12/14/about-gaming-on-wayland.html</ref> The input lag will increase by the "half frame" that is displayed with tearing. It's basically the question whether or not you want to wait for the frame to complete before displaying it.<ref name=":1" />
 
GNOME will introduce greater input lag (comparable to composition on KDE, but without the FPS problems).<ref name=":1">https://www.reddit.com/r/linux_gaming/comments/rghr60/about_gaming_and_latency_on_wayland/hpox61p/?context=3</ref>
 
==Troubleshooting==  
*Limiting FPS with MangoHud can introduce input lag. (I assume it adds one frame delay. It might as well be a bug, and only happen in specific scenarios. If you know more, why this happens, if, or how it can be avoided, please add information here.)
*Limiting FPS with MangoHud can introduce input lag. (I assume it adds one frame delay. It might as well be a bug, and only happen in specific scenarios. If you know more, why this happens, if, or how it can be avoided, please add information here.)
*Using MangoHud may introduce stuttering if your framerate is higher or lower than your monitor refresh rate.
*You might have a distribution that uses PulseAudio instead of Pipewire. Pulseaudio introduces heavy audio delay. You should [[Common tweaks#Use Pipewire instead of PulseAudio|switch to Pipewire]].
*Sometimes a game has both, a Linux native, and a Windows version. They don't always run equally well. If you have problems, it might be worth a shot to try the other one.
*If you use Arch or an Arch based distribution, and you own a very new AMD GPU, it might be worth it to install <code>linux-firmware-git</code>, and <code>mesa-git</code> from the AUR (for example by using an AUR helper like <code>paru</code>). You might also consider to install a release candidate of the Linux kernel, for example by using <code>linux-rc</code> from the AUR, or by compiling <code>linux-tkg</code> and selecting a release candidate (to be detected by the <code>rc</code>, as in <code>v6.2-'''rc'''4</code>).
*On Nvidia, you might need the [[Environment variables|environment variable]] <code>PROTON_ENABLE_NVAPI=1</code> for DLSS.
*You might need the [[Environment variables|environment variable]] <code>VKD3D_CONFIG=dxr</code> for ray tracing.
*If you're using VKD3D, and enabling Resizable BAR leads to lower performance, you might want to try <code>VKD3D_CONFIG=no_upload_hvv</code><ref name=":3">https://www.reddit.com/r/linux_gaming/comments/119hwmt/this_setting_may_help_vkd3d_games_that_have/</ref>.
*If you're using KDE Plasma, you might get performance problems because of Baloo file indexing. You can disable it as described [https://community.kde.org/Baloo/Configuration here].
*Try Wayland if you use X11, try X11 if you use Wayland. There are cases where this multiplies FPS<ref>https://www.phoronix.com/review/wayland-nv-amd-2023</ref>.
==References and notes ==
<references />
<references />

Latest revision as of 12:10, 11 May 2024

Gaming performance on Linux varies from game to game, and is very hardware dependent. Some of your games might run better than on Windows, some may run worse. But even with the same game where you would get a performance gain with one GPU you might take a performance hit with another. So it's impossible to say how your performance will compare to Windows.

BUT: Generally, you should be expecting about the same performance (±10%) as on Windows[1]. If your experience is much worse, there is probably an issue. Most Linux distributions aren't properly configured for gaming at all. Nobara is a notable exception, it already includes many of the tweaks that are mentioned here.

The good thing is, that this is very easy to change. Your performance should be OK if you do all major tweaks.

You don't have to go further if that is good enough for you and you don't want to bother reading the rest of the article. Everything else isn't as important, only situational, or might come with drawbacks. But if you still have issues, or you just want more performance, you should definitely read it. There is much that can be done to get an additional bit of performance, less input lag, less FPS drops, and significantly more performance on severely under-powered systems.

Major tweaks

These are the important tweaks, they will give a huge boost for all games. You should do all these tweaks, otherwise you will not have a good gaming experience:

  • Disable composition.
    • You don't need to do this if you use GNOME (the default on Nobara Official, Nobara GNOME, and Pop!_OS)
    • You only need to do this if you use X11, it's not necessary on Wayland.
    • You do have to do this on Nobara KDE!
  • Use GameMode
  • If they are not already installed, install the correct drivers
    • You don't have to do this on Nobara or Pop!_OS (if you chose the NVIDIA ISO for NVIDIA graphics cards).
    • Do NOT download anything manually. Read the link above.
    • If you have an old Nvidia card that is not supported by the current driver, look at the Nvidia specific section.
    • If you don't have an Nvidia GPU, the correct drivers are probably already preinstalled. However, you won't do anything wrong if you use the guide above. On some distributions this will also give you a more recent version. Old drivers can be a problem if they are too old.
  • Look at your thermals, and if they are too high, adapt the fan speed.
    • There are tools to do this inside Linux, but it's probably easier to do it in the BIOS.
  • If you have two GPUs (for example an integrated and a dedicated one), use the one with more performance. TODO: How?
  • Make sure you are using the Performance CPU governor, this can be changed with cpupower, part of the linux-tools package on most distros, or cpupower-gui, which is its own package.

AMD/Nvidia specific

These tweaks are depending on what type of GPU you have. Your CPU type is not important.

AMD

It's probably worth doing, but if everything is fine and you think this is too complicated, you can ignore this section. The default values should be fine for casual gaming. If you want the maximum performance, or minimal input lag, read further.

Overclocking and controlling the GPU

You can use CoreCtrl to add performance profiles for your games, set fan speeds, and overclock/undervolt. You can also set CPU performance here, it will overrule the GameMode settings.

The default (automatic) performance profile is probably fine for most games, but it might make a big difference for some games. For example, if a game has a capped frame rate, the GPU might not clock to the highest speed which will result in sub optimal performance. Setting your GPU to high performance can yield higher FPS, or lower input lag.

Alternatively, you can also use GameMode, however this is probably a bit more complicated.

Using the correct driver

DO NOT DOWNLOAD DRIVERS WITH YOUR BROWSER. This is the "official" way, offered by AMD, but it's also the worst possible thing you can do.

There are two Vulkan drivers available for AMD GPUs: amdvlk and vulkan-radeon (RADV, MESA). The vulkan-radeon (RADV, MESA) one is the open-source version and is preferable due to better performance in most cases. It should be the one that is installed as default, so usually you would not have to do anything.

If you experience sub-par performance, you can check which driver you are using. On Arch and Ubuntu based distros (for example Manjaro, or Pop!_OS), you can check which Vulkan implementations are installed on the system with this command: ls /usr/share/vulkan/icd.d/. It should say radeon_icd.x86_64.json. If you have the 32bit version installed, it will (also) say radeon_icd.i686.json. There might be others (intel for example), just be sure that there is not amd_icd64.json. The system will use amdvlk by default if both are installed.

If you want to use amdvlk, look for instructions for your distribution. Downloading something from the AMD website should only be the last resort, if there really is no better option. There probably is a better option.

Nvidia

Use X11. You lose around 16% FPS on Wayland[2].

The Arch Wiki is a great place to start for information, but, as always, it's best to follow documentation specific to your distro.

Identify your GPU model from the Archlinux Wiki's Nvidia page as well as the GPU model/family cross-reference page and install the correct GPU release, as GPUs older than Maxwell require legacy drivers.

  • Use DKMS for the driver. DKMS will be necessary for using custom kernels like Zen, Xanmod or tkg with the Nvidia driver because there are no pre-packaged nvidia kernel modules for them. It also lets you update to newer kernel versions without waiting for an Nvidia driver update.[3] Every distro that has proprietary Nvidia driver support should offer a DKMS version.
  • For Arch-based distributions, you may also use TKG's nvidia-all repo, with _dkms="true" in customization.cfg.[4]
  • You may also use the nvidia-vulkan-dkms to acquire the most recent vulkan beta release with the most recent extensions.
Overclocking and controlling the GPU
  • Enable coolbits in the Xorg configuration as described in the Archlinux Wiki. Specifically, setting the coolbits value to 28 on anything currently supported (post-Fermi) will enable full control over the GPU through the nvidia-settings panel (at least, as much control as you're allowed to be given).
  • Use GreenWithEnvy for overclocking, setting power limits (raise or lower) and fan curves. It's the closest alternative we have to MSI Afterburner.
    • Alternatively, you can also use the CLI, as described here.
DLSS, RTX, Reflex features on support Nvidia GPUs (NVAPI)

The github repo for DXVK-NVAPI should be read here to fully understand what you may need to do, as the Proton version you use may necessitate certain additional steps.

  • Make sure to use a Proton version of at least 6.3-6, Experimental, Proton-6.21-GE-2 (now known as GE-Proton) or Proton-tkg/wine-tkg-git of 6.17 or greater (or build your own) for DLSS, RTX, and/or Reflex on supported GPUs.
  • Using the most recent Proton, Proton Experimental or GE-Proton (As of this writing on 2022-09-06) requires the following:
    • Steam: use the launch options PROTON_ENABLE_NVAPI=1 DXVK_ENABLE_NVAPI=1 %command%. You may also need to add PROTON_HIDE_NVIDIA_GPU=0 for some games that do not use DXGI for detection (per the DXVK=NVAPI github README).
    • For non-Steam games, use the latest Lutris or wine-ge-custom build, with Lutris, and make sure to toggle on DLSS support in the Configure -> Runner options menu.

Minor tweaks

These will not make a difference as big as the major tweaks. It might give you some FPS, or lower your input lag, but you don't have to do these tweaks if you think this is too complicated.

  • Don't use Flatpak to run your game. You lose up to 20% FPS if the game is CPU bound[5].
  • Enable Fsync. You need to use a compatible Kernel (one of the gaming optimized kernels, or just any kernel above 5.16), and enable it in Lutris: Right click the game -> Configure -> Runner options -> Enable Fsync
    • If you can't or don't want to install a kernel that is Fsync compatible, you can also enable Esync. The performance boost is usually not as large, though.
  • Install an optimized kernel like linux-zen, linux-tkg-pds, Xanmod, or Liquorix. This will also prevent the system from becoming unresponsive when under heavy CPU load.
    • linux-zen and linux-tkg kernels are for Arch-based distros, Xanmod and Liquorix for Ubuntu-based distros.
      • They should also work with other distributions, but you should always make sure to have a functioning way to update them. If you don't, you end up with an insecure system!
    • linux-tkg-pds (linux-tkg with PDS scheduler) seems to perform better than zen[6], and has lower input lag (this is definitely noticeable in competitive shooters). Some people also recommend using linux-tkg-bmq (linux-tkg with BMQ scheduler). Currently there are no scientific tests, so you have to see yourself what works best for you. You can get both from chaotic AUR (list of available packages). To get all benefits you have to compile it yourself, though; on a six-core processor, this will take something in the magnitude of half an hour. However, you can use Modprobed-db to only compile kernel modules you need; this will significantly cut down the time needed to compile the kernel.
    • You don't need to fear that you might destroy your system. Installing a new kernel does not remove the old one. You can select the kernel you want to boot in GRUB. If things get messed up, just select your old kernel and you're fine.

Optional

These tweaks come with some drawback. You might want to apply them, but maybe only for some games.

  • If you don't get enough FPS, use FSR. This might dramatically improve your framerate in GPU limited games but will definitely hurt the image quality.
  • Environment variables:
    • Note that for many games, the following is not needed with Nvidia driver 520 (or higher) and DXVK 2.0 (or higher) thanks to VK_EXT_graphics_pipeline_library, Intel and AMD driver support is coming soon. However, there are still games that can profit from it, and it might lead to slightly better frame times[7]. DXVK_ASYNC=1: Display frames even if they are not completely rendered. This will reduce stuttering a lot, but it could theoretically trigger anti cheat, even though this never actually happened. Your DXVK version needs to be compatible or patched to use it. Proton-GE, until version 7-44, is compatible. For Non-Steam games you can't use Proton, and need a patched DXVK-Version. For Lutris you need to copy it to ~/.local/share/lutris/runtime/dxvk/, and manually select the version inside Lutris (if you named the folder dxvk-async-1.3, you also need to manually type dxvk-async-1.3 in the field).
  • Use LatencyFleX (warning: may trigger anticheat): Similar to NVIDIA Reflex (but works with AMD and Nvidia). Lowers input lag. Manually frame capping your game (so that your GPU never exceeds 80%) should be equally good. (If you use MangoHud to do this, this might add additional input lag!)
  • The following tweaks[8] can improve gaming performance, but might not be optimal for other workloads/normal desktop usage. However, it is possible to set/reset these settings with gamemode, as described in this tutorial.
    • Use Transparent Hugepages: echo always | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
      • With shared memory: echo advise | sudo tee /sys/kernel/mm/transparent_hugepage/shmem_enabled
    • Use Compaction Proactiveness: echo 0 | sudo tee /proc/sys/vm/compaction_proactiveness
    • Disable Hugepage Defragmentation: echo 0 | sudo tee /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
    • Lower Page Lock Unfairness: echo 1 | sudo tee /proc/sys/vm/page_lock_unfairness

BIOS tweaks

Only AMD

GPU

  • To lower your input lag even more (after doing all major and minor tweaks), you can disable page flipping (this will result in more tearing).
    • This only works on X11, but if you care that much about input lag, you shouldn't use Wayland anyways.
    • Create the file /etc/X11/xorg.conf.d/20-amdgpu.conf with content:
      Section "Device"
              Identifier "AMD"
              Driver "amdgpu"
              Option "TearFree" "false"
              Option "EnablePageFlip" "false"
      EndSection
      
  • Environment variables:
    • RADV_FORCE_VRS=2x2: Variable rate shading. This will improve performance, but reduce quality of shadows. Alternative values: 2x1 or 1x2 to use VRS only in one (x or y) direction[9]. (TODO: which is which?)
    • RADV_PERFTEST=sam: Force enable resizable bar/smart access memory. Might improve, but might as well reduce performance. In case it is reducing performance and you use VKD3D, try adding VKD3D_CONFIG=no_upload_hvv[10].
    • RADV_DEBUG=novrsflatshading: disable VRS for flat shading (only on GFX10.3+)
    • RADV_PERFTEST=nggc: enable NGGC. Can slightly improve performance on RX6000 series, but may reduce performance for other cards[11].
    • You may find more here: https://docs.mesa3d.org/envvars.html
    • RADV_PERFTEST=gpl: Should lead to a behavior similar to shader caching on Windows. Games that don't stutter on Windows, should also not stutter on Linux. Currently, it also disables shader caching, so load times will be high. Is still new, and might not work correctly. You need at least mesa 23 for it to work.

CPU

  • Note:
    • Your CPU must be >= Zen 2 (not Zen 1, or Zen +) to support the AMD P-State scaling driver. You also have to have CPPC support enabled in your BIOS.[13]
    • If CPPC is locked in your BIOS, you might be able to unlock it with Smokeless_UMAF.

Differences between Desktop Environments, and X11/Wayland

This page needs work, for the following reason(s): Might be outdated, and there is missing data for various desktop environments and window managers. Source needed for how good unredirection works in Cinnamon.


Desktop Environments may affect your performance. Your overall performance may be bad, or you might have good FPS, but high input lag.

Regarding input lag: It should be noted that we are talking about milliseconds here (the best value is 20ms, the worst is 90ms). If you are not susceptible to this (for example because you only play slow games), you may not even notice. But generally speaking, the game will feel more responsive if your input lag is low. You might also notice stuttering when the frame times are fluctuating.

X11

X11 is currently the best choice if you want minimal input lag.[14]

Disabling composition can help to reduce latency and improve performance, either by disabling it manually (KDE Plasma) or by unredirection (GNOME and derivatives like Cinnamon etc.)

The latter is the same thing Windows does for managing Fullscreen games. Disabling composition should lead to slightly less input lag.[15]

KDE Plasma (X11) with no composition appears to be a good and popular choice. GNOME is also valid, but adds a small amount of input lag.[15] Cinnamon also uses unredirection which can be manually enabled or disabled on the Settings app under the General section (Test needed to know how good it works!). Pantheon, the Elementary OS desktop environment, has no option to disable composition at all.

You might want to avoid GNOME X11 if you want to use side buttons on your mouse, as this can lead to stuttering. This can be fixed, and is not an issue on Wayland[16]. The fix however, requires recompiling, and leads to some hotkeys on keyboard layouts other than QWERTY not working[17].

Wayland

Wayland on Nvidia gives you a performance hit of about 16%[2].

The best way to achieve low input latency on a Wayland compositor is to enable Freesync or enable tearing updates. Currently, Sway and KDE support Freesync for AMD GPU's only. Other wlroots compositors may also support Freesync. KDE plasma 5.27 or higher will be required for tearing updates on Wayland and your game will also need to be run in fullscreen mode for it to work. Wine doesn't yet support tearing on Wayland.

If you cannot enable Freesync, then you will effectively always have Vsync on (unless tearing updates are enabled), regardless of your in game settings. Vsync has seen very wide use across PC's and consoles and a majority of games ship with it enabled by default. If you already play games with Vsync enabled then you shouldn't notice much or any additional latency gaming on Wayland.

Enabling Vsync in game can cause significant additional latency if you are using a Wayland compositor without Freesync. The compositors Vsync implementation can interact with the games Vsync implementation in unpredictable ways. In general there should be no need for in game Vsync if you are using a Wayland compositor, as either Wayland or Freesync will control synchronization. Bear in mind that most games enable Vsync by default.

If you are using KDE and you have FreeSync enabled, the performance and input lag should be close to KDE X11 with composition disabled.[14] The input lag will increase by the "half frame" that is displayed with tearing. It's basically the question whether or not you want to wait for the frame to complete before displaying it.[18]

GNOME will introduce greater input lag (comparable to composition on KDE, but without the FPS problems).[18]

Troubleshooting

  • Limiting FPS with MangoHud can introduce input lag. (I assume it adds one frame delay. It might as well be a bug, and only happen in specific scenarios. If you know more, why this happens, if, or how it can be avoided, please add information here.)
  • Using MangoHud may introduce stuttering if your framerate is higher or lower than your monitor refresh rate.
  • You might have a distribution that uses PulseAudio instead of Pipewire. Pulseaudio introduces heavy audio delay. You should switch to Pipewire.
  • Sometimes a game has both, a Linux native, and a Windows version. They don't always run equally well. If you have problems, it might be worth a shot to try the other one.
  • If you use Arch or an Arch based distribution, and you own a very new AMD GPU, it might be worth it to install linux-firmware-git, and mesa-git from the AUR (for example by using an AUR helper like paru). You might also consider to install a release candidate of the Linux kernel, for example by using linux-rc from the AUR, or by compiling linux-tkg and selecting a release candidate (to be detected by the rc, as in v6.2-rc4).
  • On Nvidia, you might need the environment variable PROTON_ENABLE_NVAPI=1 for DLSS.
  • You might need the environment variable VKD3D_CONFIG=dxr for ray tracing.
  • If you're using VKD3D, and enabling Resizable BAR leads to lower performance, you might want to try VKD3D_CONFIG=no_upload_hvv[10].
  • If you're using KDE Plasma, you might get performance problems because of Baloo file indexing. You can disable it as described here.
  • Try Wayland if you use X11, try X11 if you use Wayland. There are cases where this multiplies FPS[19].

References and notes

  1. https://www.youtube.com/watch?v=Nc1mS1hxn8Q
  2. 2.0 2.1 https://www.phoronix.com/review/wayland-nv-amd-2023/5
  3. https://wiki.archlinux.org/title/Dynamic_Kernel_Module_Support
  4. https://www.reddit.com/r/linux_gaming/comments/sc9dv7/need_help_writing_wiki_article_about_how_to_tweak/hu54e1g/?context=3
  5. https://github.com/flatpak/flatpak/issues/4187
  6. https://www.youtube.com/watch?v=qNzd57b0h08
  7. https://www.youtube.com/watch?v=18AYlKq05ew
  8. https://github.com/CryoByte33/steam-deck-utilities/blob/main/docs/tweak-explanation.md
  9. https://www.basnieuwenhuizen.nl/a-first-foray-into-rendering-less/
  10. 10.0 10.1 https://www.reddit.com/r/linux_gaming/comments/119hwmt/this_setting_may_help_vkd3d_games_that_have/
  11. https://www.phoronix.com/scan.php?page=article&item=radeon-radv-nggc
  12. https://www.reddit.com/r/linux/comments/15p4bfs/amd_pstate_and_amd_pstate_epp_scaling_driver/
  13. https://www.reddit.com/r/archlinux/comments/1381g2g/amd_pstate_epp_scaling_driver_available_with/
  14. 14.0 14.1 https://zamundaaa.github.io/wayland/2021/12/14/about-gaming-on-wayland.html
  15. 15.0 15.1 https://www.reddit.com/r/linux_gaming/comments/cii545/linux_input_lag_analysis_v26des_windows_10_1809/
  16. https://www.reddit.com/r/linux_gaming/comments/qaxz3m/comment/hqankhn/?context=3
  17. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1858#note_818548
  18. 18.0 18.1 https://www.reddit.com/r/linux_gaming/comments/rghr60/about_gaming_and_latency_on_wayland/hpox61p/?context=3
  19. https://www.phoronix.com/review/wayland-nv-amd-2023