遊戲

出自 Arch Linux 中文维基

本文或本節需要翻譯。要貢獻翻譯,請訪問簡體中文翻譯團隊

附註: 部分內容缺少翻譯為英文,需要跟進翻譯(在 Talk:遊戲# 中討論)

Linux 曾被認為是「非官方」的遊戲平台; 向其提供的支持和目標受眾並不是大多數遊戲組織的首要任務。 從 2021 年開始,這種情況的變化開始加速,這是因為像 ValveCodeWeavers 組和 community 這樣的大公司/組織的參與,他們給 Linux 的遊戲生態帶來了巨大的變化,讓 Linux 真正成為一個可行的遊戲平台。 此外,越來越多的獨立開發團隊努力使用跨平台渲染引擎,以使他們的遊戲能夠在 Linux 上編譯和運行。

當談到遊戲時,大多數用戶的想法往往指向流行的 AAA games,這些遊戲通常是專門為 Microsoft Windows 平台編寫的。 這是可以理解的,但這不是唯一的可能性。 請參閱頁面下方的 #遊戲環境#獲取遊戲,您可以在其中找到從其他平台運行遊戲的軟件。

然而,如果您執着於讓為 Microsoft Windows 編寫的遊戲在 Linux 上運行,那麼需要不同的思維方式、工具和方法; 了解內部結構並提供功能替代。 請閱讀下面的 #遊戲技術性

遊戲技術性[編輯 | 編輯原始碼]

試圖在 Linux 上玩 AAA games一般會出現三個難題。他們是:

  • 圖形軟件開發工具包(SDK)
    • 在 Linux 上無法運行使用 Linux 無法識別的應用程式編程接口(API)(例如DirectX)開發的遊戲。
  • 通用庫依賴
    • 在遊戲過程中進行通用操作所需的庫,例如保存遊戲、加載配置。(例如 Microsoft Visual C++、MFC、.NET)。
  • 不兼容的接口
    • 除了上面提到的框架之外,還有一個問題就是 Linux 系統無法直接識別以 Windows 系統為目標而生成的二進制格式和編譯的代碼。

圖形SDK將圖形調用轉發到底層圖形驅動程序,然後驅動程序繼續與GPU硬件交互。

上面的 API 將它們的圖形調用轉發給底層驅動程序,然後驅動程序再繼續與GPU硬件溝通。 幸運的是,AMD用戶擁有AMD自己發佈的開源驅動程序,這就已經解決了一個巨大的問題了。而Nvidia用戶必須依賴其他替代品,這些替代品通常打包為二進制大型對象(blobs)。 (作為 Nvidia 驅動程序逆向工程的結果,才能以這樣的方式使用微代碼和固件)

大量的遊戲使用了 DirectX 作為他們主要的驅動SDK. Linux僅能原生支持OpenGLVulkan。Linux自己本身無法支持DirectX或任何上述技術(Microsoft Visual C++、MFC、.NET)。

相反,有多個開源替代項目被開發出來提供相同的功能,最終從圖形的角度實現相同的結果。這些項目有它們自己的成型替代品,它們試圖從 黑盒子 的角度重新發明原始SDK調用可能實現的內容。受歡迎的包括:

  • Wine (Wine Is Not an Emulator) [提供「加載器虛擬機」、自寫依賴項、互操作性等]
  • Proton (Wine項目的分支,是Valve 針對 Steam 進行了優化的版本)
  • Mono (.NET框架的等效替代)
  • MF-Media (多媒體基礎依賴)

例如,在 DirectX 上加載、轉換和着色頂點的調用可能會在 Wine 擁有的新 .dll/.so 中從頭開始重寫,提供他們自己關於功能可能在下面做什麼的假設想法,並將其轉發給 OpenGL 替代方案,有效地嘗試實現類似的結果。 由於這些調用是直接等效的,並且可以看作好像正在運行DirectX,因此性能不會受到影響。 (與這些互操作的起始開銷除外)

這些工具往往同時被帶入系統的發行版中。 創建並配置了prefix(Wine 的術語,用於模擬 Windows 沙箱的目錄)。 依賴項被安裝在prefix內("沙盒"仍然需要遊戲的 可再發行程序庫),通常和 winetricks 一起出現,以這樣的方式去運行遊戲,"就好像"它是在Windows上運行一樣。

幸運的是,這套方案如今適用於大多數遊戲(帶有防作弊保護的遊戲除外,這需要一個 Wine/Proton 還沒有的內核驅動程序)。 如果遊戲無法運行,通常是由於包不兼容、缺少依賴項或 Wine/Proton 未實現的功能。

Lutris 是一款提供運行器和沙箱的軟件,使用Lutris可以幫您在安裝遊戲時處理相關依賴關係,以避免上述複雜和難以處理的枯燥過程。

常見的遊戲依賴[編輯 | 編輯原始碼]

如果您決定走 Wine/Proton 路線,為了更深入地了解您打算做什麼,有必要關注運行遊戲所需的常見依賴項。還需要考慮指令集架構,無論是x86還是x64,最好是兩者。

prefix需要填充以下內容才能運行"大多數"Windows 遊戲。

必不可少的(因為被廣泛使用)[編輯 | 編輯原始碼]

本文或本章節的語言、語法或風格需要改進。參考:Help:Style

原因:此處應使用指向包含包連結(例如 Fonts)的 wiki 文章的連結(在Talk:遊戲討論)
  • Microsoft Core Fonts
  • Microsoft Visual C++ 2015 (2017 版本使用率最高, 推薦安裝) [2005, 2008, 2010, 2012, 2013, 2015, 2017-2018, 2019]
  • DirectX 9.0 (11.0 版本使用率最高,推薦安裝) [June SDK update 2010] {舉幾個其中包括的例子:}
    • Direct3D
    • Direct2D
    • DirectShow
    • DirectInput
    • DirectPlay
    • DirectSound
    • DXGI
    • XAudio2
  • .NET Framework (3.5 版本使用率最高)
  • OpenGL
    • OpenAL
    • OpenAI
    • OpenCL
  • Vulkan

可選的(但仍然很常見)[編輯 | 編輯原始碼]

  • XNA
  • PhysX
  • Media Foundation
  • Quicktime
  • Adobe Reader 11
  • Java SRE (為運行 Minecraft)

少見的(不太常見)[編輯 | 編輯原始碼]

  • Gamespy
  • MIDI driver
  • ACDSee

對系統的要求[編輯 | 編輯原始碼]

僅僅用遊戲需要的依賴項填充prefix是不夠的。Linux內核本身必須具有它將提供運行遊戲所需的調用之替代。如前所述,驅動程序和相關替代庫必須要是有效的。

顯卡驅動程序[編輯 | 編輯原始碼]

對系統和替代品的依賴[編輯 | 編輯原始碼]

這主要是提供信息。 一旦你安裝了主要的包,其中一些包就會自行安裝。

遊戲環境[編輯 | 編輯原始碼]

Wine/Proton 並不是玩遊戲的唯一途徑。在Linux中玩遊戲存在不同的環境,並且與Windows上的遊戲一樣多(或更多):

  • 原生遊戲 —— 構建目標為 Linux 平台的遊戲,附帶 OpenGL 和/或 Vulkan 圖形 API 支持。
  • 遊戲模擬器 —— 運行為其他架構和系統設計的軟件所必需的。 一旦 ROM 被輸入模擬器,大多數遊戲都會開箱即用,而且很少遇到問題。 有關選項,請參閱 視頻遊戲平台模擬器
  • Java —— 一次編寫,隨處運行平台。 在 Linux 上運行的流行遊戲示例有 MinecraftRunescapeWurm OnlinePuzzle Pirates
  • 網絡 —— 在網絡瀏覽器中運行的遊戲。
    • HTML5 遊戲使用canvas畫布和WebGL技術,可在所有現代瀏覽器中運行。
    • Flash-based —— 您需要安裝插件才能播放。
  • Wine —— Windows 兼容層,允許在類Unix作業系統上運行Windows應用程式(和許多遊戲)。通過添加 Wine#DXVK,在運行時支持DirectX到 Vulkan的轉換,還能提高僅支持DirectX的遊戲的性能。
  • 虛擬機 —— 可用於安裝兼容的作業系統(如 Windows)。 VirtualBox 具有良好的 3D 支持。作為對此的擴展,如果您有兼容的硬件,您可以考慮將 VGA直通到Windows KVM客戶機,關鍵字是 「虛擬功能I/O」(VFIO),或通過OVMF進行PCI直通
  • Proton/DXVK —— 用於專有steam平台的Wine項目分支,比 Wine 更好地支持遊戲。有關詳細信息,請參考 Steam#Proton Steam-Play

遊戲兼容性[編輯 | 編輯原始碼]

增大 vm.max_map_count[編輯 | 編輯原始碼]

默認的65536 maps大小的vm.max_map_count對於有些遊戲來說太小了[1]。因此,建議通過創建sysctl配置文件來永久改變它的大小:

/etc/sysctl.d/80-gamecompatibility.conf
vm.max_map_count = 2147483642

運行以下命令以應用更改(無需重啟):

# sysctl --system
注意: 這可能導致與嘗試讀取核心轉儲文件的舊程序不兼容 [2].

獲取遊戲[編輯 | 編輯原始碼]

不能僅僅通過遊戲是否能在Linux上運行來判斷它們是否是原生遊戲;它們可能是用 WineDOSBox 預打包的。

官方倉庫AUR 中為 Arch 打包的遊戲列表請參見 遊戲列表

  • Athenaeum — Steam 的自由軟件替代品。
https://gitlab.com/librebob/athenaeum || athenaeum-gitAUR
  • Bottles — 開源的wine和proton prefix管理器。用於運行windows軟件和遊戲。
https://usebottles.com/ || bottlesAUR
  • Flathub — 中心化的Flatpak軟件倉庫, 有比較少但仍在不斷增長的遊戲份額。
https://flathub.org/apps/category/Game || flatpak, discover, gnome-software
  • GOG.com — 無DRM遊戲的遊戲商店。
https://www.gog.com || lgogdownloaderAUR, wyvernAUR, minigalaxyAUR
  • Heroic Games Launcher — GOG 和 Epic 的GUI,Epic Games Launcher 的開源替代品。
https://heroicgameslauncher.com/ || heroic-games-launcherAUR
https://itch.io || itch-setup-binAUR
  • Legendary — Epic Games Launcher 的免費開源替代品。
https://github.com/derrod/legendary || legendaryAUR
  • Lutris — Linux 的開放遊戲平台。從 GOG、Steam、Battle.net、Origin、Uplay 和許多其他來源獲取遊戲。Lutris 利用各種遊戲運行器啟動具有完全可自定義的配置選項的遊戲。
https://lutris.net || lutris
  • Play.it — 自動構建原生軟件包,還支持 WineDOSBox 和 ScummVM 遊戲。
https://www.dotslashplay.it/ || play.itAUR
  • Rare — 基於PyQt5的另一個Epic GUI
https://github.com/Dummerle/Rare || rareAUR
  • Steam — Valve開發的數字發行和社區平台。
https://store.steampowered.com || steam

對於第三方 Wine 程序,請參見 Wine#第三方程序

配置遊戲[編輯 | 編輯原始碼]

某些遊戲或遊戲類型可能需要特殊配置才能運行或按預期運行。在大多數情況下,由於編譯時優化,遊戲將在Arch Linux中開箱即用,性能可能優於其他發行版。但是,某些特殊設置可能需要一些配置或腳本才能使遊戲按預期順利運行。

多顯示器設置[編輯 | 編輯原始碼]

運行多屏設置可能會導致全屏遊戲出現問題。在這種情況下,運行另一個X顯示伺服器 是一種可能的解決方案。對於 NVIDIA 用戶,一個可能的解決方案可以在 NVIDIA#用_TwinView_玩遊戲中找到。

鍵盤抓取[編輯 | 編輯原始碼]

許多遊戲會佔用鍵盤,明顯會阻止您切換窗口(也稱為 alt-tabbing)。

一些 SDL 遊戲(例如 Guacamelee)允許您通過按 Ctrl-g 來禁用抓取。

注意: 眾所周知,SDL 有時無法抓取輸入系統。在這種情況下,等待幾秒鐘可能會恢復。

在單獨的X顯示伺服器中啟動遊戲[編輯 | 編輯原始碼]

在某些情況下,如上面提到的那些,可能需要或希望運行第二個X顯示伺服器。 運行第二個X顯示伺服器有很多優勢,例如更好的性能,使用 Ctrl+Alt+F7/Ctrl+Alt+F8 來「跳出」遊戲的能力,在遊戲與圖形驅動程序衝突的情況下也不會導致您的主X會話(可能有未完成的工作)崩潰。 新的X顯示伺服器將類似於ALSA的遠程訪問登錄,因此您的用戶需要成為 audio 組的一部分才能聽到聲音。

要啟動第二個 X 伺服器(以免費的第一人稱射擊遊戲 Xonotic 為例),您可以簡單地執行以下操作:

$ xinit /usr/bin/xonotic-glx -- :1 vt$XDG_VTNR

這可以通過使用單獨的X配置文件來做一些自定義設置:

$ xinit /usr/bin/xonotic-glx -- :1 -xf86config xorg-game.conf vt$XDG_VTNR

在這裏提供替代「xorg.conf」的一個很好的理由可能是您的主要配置使用了 NVIDIA 的 Twinview,它將在您的多屏幕設置中間呈現您的 3D 遊戲,如 Xonotic,跨越所有屏幕。這是不可取的,因此建議使用禁用第二個屏幕的替代配置啟動第二個 X。要注意的是X配置文件位置是相對於 /etc/X11 目錄的。

使用 Openbox 作為您的主目錄或 /usr/local/bin 的遊戲啟動腳本可能如下所示:

~/game.sh
if [ $# -ge 1 ]; then
        game="$(which $1)"
        openbox="$(which openbox)"
        tmpgame="/tmp/tmpgame.sh"
        DISPLAY=:1.0
        echo -e "${openbox} &\n${game}" > ${tmpgame}
        echo "starting ${game}"
        xinit ${tmpgame} -- :1 -xf86config xorg-game.conf || exit 1
else
        echo "not a valid argument"
fi

添加可執行權限 後,您可以執行以下操作:

$ ~/game.sh xonotic-glx
注意: 如果你想避免從/etc/X11/xorg.conf.d加載配置,你還應該使用-configdir選項,指定一個空目錄。

調整鼠標檢測[編輯 | 編輯原始碼]

對於需要大量鼠標技能的遊戲,調整 鼠標輪詢率 可以幫助提高準確性。

使用 OpenAL 的雙耳音頻[編輯 | 編輯原始碼]

對於使用了OpenAL的遊戲, 如果您使用耳機,您可能會使用 OpenAL 的 HRTF 過濾器獲得更好的定位音頻。 要啟用,請創建如下文件:

~/.alsoftrc
hrtf = true

或者,從AUR安裝openal-hrtfAUR,並編輯/etc/openal/alsoftrc.conf中的選項

對於 Source 遊戲,必須將遊戲內設置「dsp_slow_cpu」設置為「1」以啟用 HRTF,否則遊戲將啟用自己的處理。您還需要將 Steam 設置為使用原生運行時,或者將其 openal.so副本連結到您自己的本地副本。為了完整起見,還使用以下選項:

dsp_slow_cpu 1 # 禁用游戏内空间化
snd_spatialize_roundrobin 1 # 禁用空间化 1.0*100% 的声音
dsp_enhance_stereo 0 # 禁用 DSP 音效。 如果你发现它不会干扰您对音效的感知,也可以将其保持打开状态。
snd_pitchquality 1 # 使用高质量的声音

調整PulseAudio[編輯 | 編輯原始碼]

如果你使用PulseAudio, 您可能希望調整一些默認設置以確保它以最佳方式運行。

啟用實時優先級和負nice級別[編輯 | 編輯原始碼]

Pulseaudio被構建為以實時優先級運行,是一個音頻守護進程。但是,由於它鎖定系統的安全風險,默認情況下它被安排為常規線程。 要對此進行調整,首先確保您在 audio組中。然後,取消註釋並編輯 /etc/pulse/daemon.conf 中的以下行:

/etc/pulse/daemon.conf
high-priority = yes
nice-level = -11

realtime-scheduling = yes
realtime-priority = 5

再重新啟動 pulseaudio。

使用更高質量的混音以獲得更好的聲音[編輯 | 編輯原始碼]

Arch上的PulseAudio默認使用speex-float-1來重新混合頻道,這被認為是「中低」質量的混音。如果您的系統可以處理額外的負載,將其設置為以下之一可以提升聲音效果:

resample-method = speex-float-10

將硬件緩衝區與Pulse的緩衝相匹配[編輯 | 編輯原始碼]

匹配緩衝區可以減少卡頓並略微提高性能。 有關詳細信息,請參考這裏

遠程遊玩[編輯 | 編輯原始碼]

雲遊戲由於對客戶端硬件的要求低,在過去幾年中獲得了廣泛的歡迎。唯一重要的是穩定的互聯網連接(推薦使用以太網電纜或5GHz WiFi),最低速度為 5-10 Mbit/s(取決於視頻質量和幀率)。

參考 Gamepad#Gamepad over network 用於通過網絡使用遊戲手柄以及通常不支持此功能的服務。

注意: 大多數在瀏覽器中運行的服務通常意味着只與 google-chromeAUR 兼容。
Service Installer In browser client Use your own host Offers host renting Full desktop support Controller support Remarks
Dixper Windows-only ? ? ?
Reemo reemod-binAUR Chromium based only Windows-only You can also install the software with the official installation script in the download section via their website.
Xbox Cloud xbox-cloud-gamingAUR You need Game Pass Ultimate to be able to use XCloud.
GeForce Now You must have games on Steam, Epic Client or GOG to use this service. Not all games are available.
Moonlight moonlight-qtAUR This is only a client. Host machine must use either GeForce Experience (windows only) or Sunshine (multiplatform).
Parsec parsec-binAUR 是 (experimental) Windows-only Cloud hosting no longer available[失效連結 2023-05-06 ⓘ]
VDI Stream Client vdi-stream-clientAUR Windows-only VDI client with 3D GPU acceleration and built-in USB redirection
Playkey playkey-linuxAUR ? ? ? ? ?
PlayStation Now Runs under Wine or Steam's proton Play PS4, PS3 and PS2 games on PC. Alternatively, you can use emulators.
PlayStation Remote Play chiakiAUR Play games from your PS4 and/or PS5 on PC.
Rainway Coming in 2019 Q3 Windows-only ?
Shadow Stable: shadow-techAUR
Beta: shadow-betaAUR
Controller support is dependent on USB over IP, and currently AVC only as HEVC is not supported
Steam Remote Play Part of steam
Stadia Service is shutting down on 18/01/2023
Vortex[失效連結 2024-01-29 ⓘ] ?
VNC tigervnc or x11vnc General purpose remote desktop protocol, but the latency should be low enough to use it for gaming over a LAN. See Gamepad#Gamepad over network for gamepad support.
xrdp xrdpAUR Another general purpose remote desktop protocol, has both OpenGL and Vulkan support after configuring graphical accleration. Recommended for gaming over a LAN. See Gamepad#Gamepad over network for gamepad support.
X11 forwarding openssh X forwarding over SSH with VirtualGL supports OpenGL and works for some but not all games. See Gamepad#Gamepad over network for gamepad support.
Boosteroid boosteroidAUR You must have games on a digital distribution platform (Steam, EGS, Origin, etc.) to use this service. Not all games are available. You need to sign up (free) to see the full list of games. You need to purchase a subscription, to launch the games you own on the digital distribution platform.
Blacknut blacknut-appimageAUR or Blacknut AppImage You need a subscription to be able to use this service. Not all games are available.

性能優化[編輯 | 編輯原始碼]

參考主要文章:性能優化。 對於 Wine 程序,請參閱 Wine#性能。 要獲得良好的低延遲遊戲體驗,需要一致的響應時間(無抖動)和足夠的吞吐量(每秒幀數)。 如果您有多個信號源並帶有一點點抖動,它們有時可能會重疊並產生明顯的卡頓。 因此,大多數時候最好稍微降低吞吐量以獲得更多的響應時間一致性。

提高 clock_gettime 吞吐量[編輯 | 編輯原始碼]

用戶空間程序,尤其是遊戲會多次調用 clock_gettime(2) 來獲取計算遊戲物理、fps 等的當前時間。 運行下面的命令可以查看使用率

# perf top

並查看 read_hpet(或 acpi_pm_read)的開銷。

如果您不依賴於非常精確的計時器,您可以從 hpet(高精度事件計時器)或 acpi_pm(ACPI電源管理計時器)切換到更快的TSC(時間戳計數器)計時器。添加 內核參數

tsc=reliable clocksource=tsc

使TSC可用並啟用它。重啟後通過運行確認時鐘源

# cat /sys/devices/system/clocksource/clocksource*/current_clocksource

您可以通過運行下面命令查看所有當前可用的計時器

# cat /sys/devices/system/clocksource/clocksource*/available_clocksource

往current_clocksource寫入其中之一來進行更改。 在使用 [3] 的 Zen 3 系統基準測試中,與 hpetacpi_pm 相比,tsc 的吞吐量高約 50 倍。

調整內核參數以實現響應時間一致性[編輯 | 編輯原始碼]

您可以安裝實時內核以獲得一些默認情況下的優勢(參見實時內核),代價是損失 CPU 吞吐量且可能延遲中斷處理。此外,實時內核與 nvidia-open-dkms不兼容,並且不會更改 SCHED_NORMAL(也稱為 SCHED_OTHER)進程的調度程序,這是默認進程調度類型。以下內核參數更改進一步提高了實時內核以及其他內核(例如默認 linux 內核)的響應時間一致性:

透明巨面(THP)分配的主動壓縮會減少平均分配停滯,但不一定減少最大分配停滯。根據 內核文檔,禁用主動壓縮,因為它會引入抖動:

# echo 0 > /proc/sys/vm/compaction_proactiveness

在內存碎片化的情況下,降低水印加速因數以對一個單獨的頁面塊(64位x86上為2MB)進行碎片整理。這會更好地在內存碎片事件之後將應用程式數據保留在最後一級處理器緩存中。

# echo 1 > /proc/sys/vm/watermark_boost_factor

如果您有足夠的可用 RAM,請增加最小可用千字節數以避免內存分配卡頓:-os-jitter.html[4]。 不要將其設置為低於 1024 KB 或高於系統內存的 5%。 設置為預留1GB的命令如下:

# echo 1048576 > /proc/sys/vm/min_free_kbytes

如果您有足夠的可用 RAM,請增加水印比例因數以進一步降低分配停滯的可能性[5][6]。將水印距離設置為 RAM 的5%:

# echo 500 > /proc/sys/vm/watermark_scale_factor

除非系統沒有更多可用內存,否則避免交換(鎖定頁面會引入延遲並使用磁盤 IO):

# echo 10 > /proc/sys/vm/swappiness

啟用多代最近最少使用(MGLRU),同時以較小的性能成本降低鎖定爭用的可能性[7]

# echo 5 > /sys/kernel/mm/lru_gen/enabled

禁用區域回收(鎖定和移動引入延遲峰值的內存頁面):

# echo 0 > /proc/sys/vm/zone_reclaim_mode

當性能開銷很大時,禁用透明巨面 (THP)。 即使禁用碎片整理,THP 也可能會引入延遲峰值[8][9]。僅當應用程式使用 madvise 或 advise 特別請求時才啟用:

# echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
# echo advise > /sys/kernel/mm/transparent_hugepage/shmem_enabled
# echo never > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag

請注意,如果您的遊戲使用 TCMalloc(例如 Dota 2 和 CS:GO),則不建議禁用 THP,因為它會帶來很大的性能成本[10]

減少最大頁面鎖定獲取延遲,同時保持足夠的吞吐量 [11][12][13]

# echo 1 > /proc/sys/vm/page_lock_unfairness

調整調度程序設置。以下調度程序設置與 cfs-zen-tweaksAUR 衝突,因此對於每個設置只選擇一個提供程序。默認情況下,linux 內核調度程序針對吞吐量而非延遲進行了優化。以下手工設置改變了這一點,並在不同的遊戲中進行了測試,得到了顯着的改進。 它們可能不是您的用例的最佳選擇; 考慮根據需要來修改它們 [14][15][16]

# echo 0 > /proc/sys/kernel/sched_child_runs_first
# echo 1 > /proc/sys/kernel/sched_autogroup_enabled
# echo 3000 > /proc/sys/kernel/sched_cfs_bandwidth_slice_us
# echo 3000000 > /sys/kernel/debug/sched/latency_ns
# echo 500000 > /sys/kernel/debug/sched/migration_cost_ns
# echo 8 > /sys/kernel/debug/sched/nr_migrate

固化更改[編輯 | 編輯原始碼]

通常,永久設置內核參數的建議是創建並修改sysctl配置文件或更改引導加載程序選項。然而,由於我們的更改跨越 procfs(/proc,包含 sysctl)和 sysfs(/sys),最方便的方法是使用 systemd-tmpfiles

/etc/tmpfiles.d/consistent-response-time-for-gaming.conf
#    Path                  Mode UID  GID  Age Argument # default value as of linux 6.6
w /proc/sys/vm/compaction_proactiveness - - - - 0 # 20
w /proc/sys/vm/watermark_boost_factor - - - - 1 # 15000
w /proc/sys/vm/min_free_kbytes - - - - 1048576 # 67584
w /proc/sys/vm/watermark_scale_factor - - - - 500 # 10
w /proc/sys/vm/swappiness - - - - 10 # 60
w /sys/kernel/mm/lru_gen/enabled - - - - 5 # 7
w /proc/sys/vm/zone_reclaim_mode - - - - 0 # 0  
w /sys/kernel/mm/transparent_hugepage/enabled - - - - madvise # always
w /sys/kernel/mm/transparent_hugepage/shmem_enabled - - - - advise # never
w /sys/kernel/mm/transparent_hugepage/defrag - - - - never # madvise
w /proc/sys/vm/page_lock_unfairness - - - - 1 # 5
w /proc/sys/kernel/sched_child_runs_first - - - - 0 # 0
w /proc/sys/kernel/sched_autogroup_enabled - - - - 1 # 1
w /proc/sys/kernel/sched_cfs_bandwidth_slice_us - - - - 3000 # 5000
w /sys/kernel/debug/sched/base_slice_ns  - - - - 3000000 # 3000000
w /sys/kernel/debug/sched/migration_cost_ns - - - - 500000 # 500000
w /sys/kernel/debug/sched/nr_migrate - - - - 8 # 32

重啟後查看值是否生效。

立即加載共享對象以獲得更好的首次延遲[編輯 | 編輯原始碼]

給你要運行的遊戲設置環境變量

LD_BIND_NOW=1

避免需要在運行時加載程序代碼(參見 ld.so(8)),從而導致第一次調用函數時出現延遲。但是不要為 startplasma-x11 或連結到庫中的其他程序設置此項,這些庫實際上不再存在於系統中並且永遠不會被程序調用。如果是這種情況,程序將在啟動時嘗試連結一個不存在的共享對象而失敗,從而使這個問題很容易識別。啟用此設置後,大多數遊戲應該都能正常啟動。

工具[編輯 | 編輯原始碼]

Gamemode[編輯 | 編輯原始碼]

Gamemode 是 Linux 的守護進程和庫組合,它允許遊戲請求將一組優化臨時應用於host作業系統。 這可以提高遊戲性能。

Gamescope[編輯 | 編輯原始碼]

Gamescope是 Valve 開發的一個微合成器,用於 Steam Deck 。其目標是提供一種針對遊戲量身定製的獨立合成器,並且支持許多以遊戲為中心的功能。

ACO編譯器[編輯 | 編輯原始碼]

注意: 下面顯示的方法適用於運行AMDGPU 驅動程序的 AMD GPU。

參考 AMDGPU#ACO編譯器

減少DRI延遲[編輯 | 編輯原始碼]

直接渲染基礎結構 (DRI) 配置文件適用於所有DRI驅動程序,包括Mesa和Nouveau。您可以在 /etc/drirc 或每個用戶在 $HOME/.drirc 中更改系統範圍內的 DRI 配置。如果文件不存在,可以創建它們。兩個文件使用相同的語法; 這些選項的文檔可以在 [17] 找到。如果要禁用垂直同步來減少輸入延遲,添加以下內容:

<driconf>
   <device>
       <application name="Default">
           <option name="vblank_mode" value="0" />
       </application>
   </device>
</driconf>

使用調度策略提高幀速率和響應能力[編輯 | 編輯原始碼]

Most games can benefit if given the correct scheduling policies for the kernel to prioritize the task. These policies should ideally be set per-thread by the application itself.

For programs which do not implement scheduling policies on their own, application known as schedtool, and its associated daemon schedtooldAUR can handle many of these tasks automatically.

To edit what programs relieve what policies, simply edit /etc/schedtoold.conf and add the program followed by the schedtool arguments desired.

Policies[編輯 | 編輯原始碼]

SCHED_ISO (only implemented in BFS/MuQSSPDS schedulers found in -pf and -ck kernels) – will not only allow the process to use a maximum of 80 percent of the CPU, but will attempt to reduce latency and stuttering wherever possible. Most if not all games will benefit from this:

bit.trip.runner -I

SCHED_FIFO provides an alternative, that can even work better. You should test to see if your applications run more smoothly with SCHED_FIFO, in which case by all means use it instead. Be warned though, as SCHED_FIFO runs the risk of starving the system! Use this in cases where -I is used below:

bit.trip.runner -F -p 15

Nice levels[編輯 | 編輯原始碼]

Secondly, the nice level sets which tasks are processed first, in ascending order. A nice level of -4 is recommended for most multimedia tasks, including games:

bit.trip.runner -n -4

Core affinity[編輯 | 編輯原始碼]

There is some confusion in development as to whether the driver should be multithreading, or the program. Allowing both the driver and program to simultaneously multithread can result in significant performance reductions, such as framerate loss and increased risk of crashes. Examples of this include a number of modern games, and any Wine program which is running with GLSL enabled. To select a single core and allow only the driver to handle this process, simply use the -a 0x# flag, where # is the core number, e.g.:

bit.trip.runner -a 0x1

uses first core.

Some CPUs are hyperthreaded and have only 2 or 4 cores but show up as 4 or 8, and are best accounted for:

bit.trip.runner -a 0x5

which use virtual cores 0101, or 1 and 3.

General case[編輯 | 編輯原始碼]

For most games which require high framerates and low latency, usage of all of these flags seems to work best. Affinity should be checked per-program, however, as most native games can understand the correct usage. For a general case:

bit.trip.runner -I -n -4
Amnesia.bin64 -I -n -4
hl2.exe -I -n -4 -a 0x1 #Wine with GLSL enabled

etc.

Optimus, and other helping programs[編輯 | 編輯原始碼]

As a general rule, any other process which the game requires to operate should be reniced to a level above that of the game itself. Strangely, Wine has a problem known as reverse scheduling, it can often have benefits when the more important processes are set to a higher nice level. Wineserver also seems unconditionally to benefit from SCHED_FIFO, since it rarely consumes the whole CPU and needs higher prioritization when possible.

optirun -I -n -5
wineserver -F -p 20 -n 19
steam.exe -I -n -5

Peripherals[編輯 | 編輯原始碼]

Mouse[編輯 | 編輯原始碼]

You might want to set your mouse acceleration to control your mouse more accurately.

If your mouse has more than 3 buttons, you might want to see Mouse buttons.

If you are using a gaming mouse (especially Logitech and Steelseries) you may want to configure your mouse polling rate, DPI, LEDs etc. Using piper. See this page for a full list of supported devices by piper. Alternatively solaar for logitech devices only.

LEDs[編輯 | 編輯原始碼]

You can change and manipulate various RGBs with openrgb, for a list of currently supported devices see [18].

See also[編輯 | 編輯原始碼]

  • [19] - Forum on reddit.com with gaming on linux as its topic, subpages: gaming/wiki/index Wiki, FAQ.
  • Linux Gaming Guide - Compilation of different techniques for optimizing the Linux gaming experience.
  • are we anti cheat yet A comprehensive and crowd-sourced list of games using anti-cheats and their compatibility with GNU/Linux or Wine/Proton.
  • proton db crowdsourced Linux compatibility reports