ValveSoftware / csgo-osx-linux

Counter-Strike: Global Offensive
http://counter-strike.net
774 stars 69 forks source link

Mouse/peripheral input lag with comparison to windows and potential solutions | Discussion #3836

Open Bookaj opened 1 week ago

Bookaj commented 1 week ago
System information Computer Information: _ Motherboard Gigabyte GA-H61M-S2PV GPU Gigabyte GeForce GTX 960 4GB CPU i5-3570 CPU @ 3.40GHz/3.80 GHz RAM noname 16 GB DDR3 SSD Kingston A400 1TB Display BenQ T221W @ 75hz Mouse XPG Primer PMW 3360 Keyboard Logitech DeLuxe 250 Sensitivity Φ @ 800 DPI _ Manufacturer: Gigabyte Technology Co., Ltd. Model: H61M-S2PV Form Factor: Desktop No Touch Input Detected Processor Information: CPU Vendor: GenuineIntel CPU Brand: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz CPU Family: 0x6 CPU Model: 0x3a CPU Stepping: 0x9 CPU Type: 0x0 Speed: 3800 MHz 4 logical processors 4 physical processors Hyper-threading: Unsupported FCMOV: Supported SSE2: Supported SSE3: Supported SSSE3: Supported SSE4a: Unsupported SSE41: Supported SSE42: Supported AES: Supported AVX: Supported AVX2: Unsupported AVX512F: Unsupported AVX512PF: Unsupported AVX512ER: Unsupported AVX512CD: Unsupported AVX512VNNI: Unsupported SHA: Unsupported CMPXCHG16B: Supported LAHF/SAHF: Supported PrefetchW: Unsupported Operating System Version: "Garuda Linux Bird of Prey" (64 bit) Kernel Name: Linux Kernel Version: 6.10.9-zen1-2-zen X Server Vendor: The X.Org Foundation X Server Release: 12101013 X Window Manager: Xfwm4 Steam Runtime Version: steam-runtime_0.20240610.91380 Video Card: Driver: NVIDIA Corporation NVIDIA GeForce GTX 960/PCIe/SSE2 Driver Version: 4.6.0 NVIDIA 560.35.03 OpenGL Version: 4.6 Desktop Color Depth: 24 bits per pixel Monitor Refresh Rate: 74 Hz VendorID: 0x10de DeviceID: 0x1401 Revision Not Detected Number of Monitors: 1 Number of Logical Video Cards: 1 Primary Display Resolution: 1440 x 900 Desktop Resolution: 1440 x 900 Primary Display Size: 18.50" x 11.42" (21.73" diag), 47.0cm x 29.0cm (55.2cm diag) Primary Bus: PCI Express 16x Primary VRAM: 4096 MB Supported MSAA Modes: 2x 4x 8x 16x Sound card: Audio device: Realtek ALC887-VD Memory: RAM: 15957 Mb VR Hardware: VR Headset: None detected Miscellaneous: UI Language: English LANG: en_US.UTF-8 Total Hard Disk Space Available: 915711 MB Largest Free Hard Disk Block: 780818 MB Storage: Number of SSDs: 1 SSD sizes: 960G Number of HDDs: 0 Number of removable drives: 0

Please describe your issue in as much detail as possible:

Mouse input lag when the attached config is not used. Ingame settings do not change anything in regard to input lag.

Tips:

  1. Disable vsync in nvidia-settings (anywhere you can really).
  2. Verify polling rate with evhz or any other software while following available guidelines (in my case, 500 to 1000hz and 12Mb bus speed)
  3. Switch to linux-zen kernel (does decrease input lag). I have tested linux-rt kernel and the input lag is the same or worse than on lts.
  4. Use an appropriate for your likings xorg config.

Using linux-zen kernel, proper mouse acceleration and decceleration settings, and the gamescope --force-grab-cursor game launch option contribute the most to feeling of the game.

Reminder Synchronous and asynchronous execution is different than multitasking and multiprocessing I/O at the same time. Multiprocessing can occur both synchronously and asynchronously.

Potential contributing factors (up to verification, simplified English): The way Windows and Linux handle interrupt signals from peripheral devices such as mice and keyboard is quite different. Windows handles the mouse interrupt signals asynchronously (out of order) with MSI which enables devices to allocate up to 2048 interrupts. When Counter Strike 2 chokes up, the feature allows the allocated interrupts to be executed multiple times per ingame frame (system gets choked up, interrupts are sequenced for execution, when interrupts are enabled it's a burst execution). This is potentially the reason for why game client feels more responsive in terms of input lag, but the desynchronization between screen rendered image and captured client packets appears to be greater than with Linux. Linux uses signal handling and the signals are executed in a kernel specific order. Linux uses signals to notify processes about specific events - there is no direct Windows equivalent for that function. Signal handling allows application to capture signals in sync with each other. If an application cannot maintain "real time" execution, it is executed with a delay. ?? m_rawinput signal data grabbing is influenced by applications framerate to ensure synchronous in-game inputs for client server networking purposes. --force-grab-cursor launch command forces the application to grab asynchronously processed signal data from xserver which operates faster than the application, in turn reducing input lag xserver attempts to be efficient by operating at display's refresh rate. --force-grab-cursor provides the most up-to-date signal data available for xserver, whereas rawinput takes the most up-to-sync data available for the application. ??

Potential additional fixes: -Use higher tickrate kernels for the clients.

Additional Linux Optimizations High Priority Interrupts for USB Devices: Identify the USB devices (mouse and keyboard) with lsusb and determine their IRQ numbers with: cat /proc/interrupts | grep -i "usb" Assign higher priority to these IRQs by setting their CPU affinity: sudo sh -c 'echo 2 > /proc/irq/XX/smp_affinity' Replace XX with the IRQ number of your USB devices. Kernel Parameters for Low Latency: Add or modify the following parameters in /etc/sysctl.conf for reduced latency: conf Copy code vm.swappiness=1 vm.dirty_background_ratio=5 vm.dirty_ratio=10 net.core.netdev_max_backlog=250000 net.core.rmem_max=16777216 net.core.wmem_max=16777216 kernel.sched_migration_cost_ns=500000 kernel.sched_latency_ns=1000000 kernel.sched_min_granularity_ns=500000 kernel.sched_wakeup_granularity_ns=1500000 Apply these settings with: bash Copy code sudo sysctl -p Disable CPU C-States in GRUB: To reduce input latency caused by CPU power-saving states, disable CPU C-states by editing the GRUB configuration: sudo nano /etc/default/grub Add processor.max_cstate=1 to the GRUB_CMDLINE_LINUX_DEFAULT line: conf GRUB_CMDLINE_LINUX_DEFAULT="quiet splash processor.max_cstate=1" Update GRUB to apply the changes: Copy code sudo update-grub

Loose description:

CS2 on Linux delays the input execution to ensure client sided and client-server synchronization, which results in better hitreg and smoother animations. CS2 on Windows doesn't care about input synchronization, which results in more responsive client sided environment, but causes desync across the client and the client-server communication.

Launch options gamescope --force-grab-cursor -vblank_mode=0 -forcenovsync __GL_SHADER_DISK_CACHE=0
Xorg config GNU nano 8.2 /etc/X11/xorg.conf.d/50-mouse-acceleration.conf Section "InputClass" Identifier "My Mouse" Driver "libinput" MatchIsPointer "yes" Option "AccelProfile" "flat" Option "AccelSpeed" "0.0" Option "ConstantDeceleration" "0" Option "AdaptiveDeceleration" "0" EndSection

Steps for reproducing this issue:

  1. Launch the game on the same hardware.
  2. Open up any match

EXTRAS:

In order to play 4:3 stretched resolution (i.e. 800x600) without sensitivity issues, on a 16:10 or 16:9, temporarily change your desktop display resolution to the same settings as you want ingame.

Bookaj commented 1 week ago

Problem solved. It's actually the game - it's trash.

ilievi187 commented 3 days ago

Gamescope doesn't work well with CS2 for reasons I haven't been able to figure out. I've had the same issue for a while and never managed to solve it. It feels like something is affecting input—movement, firing, etc.—everything has noticeable delay. If you play on two screens, one with Windows and the other with Linux, you'll spot the difference immediately.

I think this might be due to some restrictions from the CS2 dev team, though I can't say for sure. In other Valve games like Dota 2, the Half-Life series, and even Deadlock, everything works perfectly. There's no noticeable difference between Windows and Linux performance in those titles. But with CS2, it feels like you're running it through an extra layer or something.

I'll give you a few things to try that might help reduce the input delay, though it probably won't fix CS2 entirely:

Use your native monitor resolution – For example, if your monitor is 1920x1080, stick to that. Max out your refresh rate – If your monitor supports 144Hz or higher, use the maximum available. Try the Flatpak version of Steam – The Flatpak version has hardware acceleration pre-enabled, which can help with compatibility issues. Some distros don’t handle this well by default, so using Flatpak Steam can be beneficial. Lower your polling rate to 500Hz – If you’re using Xorg, Linux can struggle with polling rates higher than 500Hz, especially on Xorg. Plug your USB devices directly into the motherboard chipset – Avoid using external USB ports on your case. Lastly, test your setup in other shooters. If they run fine without any delay, then it's probably specific to CS2