Thoughts from a 20-year Linux user

Home | About


Posts tagged "Gaming":

16 Dec 2024

Gaming in Linux

Introduction

Games are complex desktop applications that require interactions like:

  • your disk, to save game state, load images and audio/video files
  • network card, to allow playing online
  • graphics/audio card, for best performance/user interaction

Hardware interactions are handled by your operating system by specialized software components called device drivers. They offer higher level abstractions, which allows creating higher level APIs for application developers via software libraries.

In many cases, standards have evolved and are usually publicly available. They offer a guarantee that the application will continue to work as the operating system/software libraries get updated.

In case of the gaming world, for graphics we have the following main standards

For Audio APIs, we have:

  • XAudio2 - Windows specific, part of DirectX
  • OpenAL - started out open source, but latest versions are closed

Here's a high level overview of the infrastructure built-in Linux to support gaming/multimedia.

2560px-Linux_API.svg.png
Figure 1: Gaming support overview for Linux

Separate from this, there are a bunch of (higher level) libraries that do not adhere to a specific standard, like SDL, SFML or Raylib.

As you can imagine, building a game requires a deep integration with all these layers, making things complicated.

It is no wonder that, in order not to reinvent the wheel, all these functionalities have been integrated as parts of what people call a game engine.

The main platform for PC gaming is Microsoft Windows. Obviously, this closely follows the OS market shares, and, as things stand right now, it is unlikely this will change in the near future.

So, many game developers prefer to stay focused and target the dominant OS and use the APIs that make their life the easiest even though they may be OS specific. The big elephant in the room is DirectX multimedia API, which is many times preferred over the newer cross-platform standards.

In time, the Linux community has built an impressive compatibility layer (Wine) that allows you to run, with varying success, day to day Windows applications, games included.

There are a few native games, but the big names usually require Wine to run on Linux.

The gaming support has gradually increased over time. A few years ago, Valve, one of the biggest game digital distribution companies, decided to add Linux support for Steam, its software distribution platform. It worked with CodeWeavers (a commercial company that focuses on Wine development) to create Proton, an improved compatibility layer, which is integrated into Steam to offer Linux support. Proton is a Wine fork which specializes on running games and has added improved 3D support. It has a permissive license and is open source, allowing for contributions to be reincorporated/adapted in Wine, as needed.

I've given a high level outlook and history, and I will detail on the day to day user experience:

  • Kernel Drivers for graphics cards
  • Native games
  • Popular games

Kernel drivers

Usually, all hardware drivers come with the Linux kernel, which is included in your distribution. A notable exception is Nvidia, for which the proprietary drivers are to be preferred.

As with Windows, major vendors also publish the newest versions on their websites, e.g. :

Obviously, the first step is to properly identify your hardware, and then follow up with installing the right drivers if need be.

Detect hardware

I'll outline two methods below, one based on CLI and the other GUI based. I'd say that the CLI based one is more reliable, so fall back to it if needed.

CLI approach

You'll need the lshw package installed

george@local:~$ sudo apt install lshw

You can then use the lshw utility

george@local:~$ sudo lshw -numeric -C display
  *-display                 
       description: 3D controller
       product: AD107M [GeForce RTX 4060 Max-Q / Mobile] [10DE:28A0]
       vendor: NVIDIA Corporation [10DE]
       physical id: 0
       bus info: pci@0000:01:00.0
       logical name: /dev/fb0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list rom fb
       configuration: depth=32 driver=nvidia latency=0 mode=3072x1920 visual=truecolor xres=3072 yres=1920
       resources: iomemory:400-3ff iomemory:420-41f irq:196 memory:88000000-88ffffff memory:4000000000-41ffffffff memory:4200000000-4201ffffff ioport:3000(size=128)
  *-display
       description: VGA compatible controller
       product: Meteor Lake-P [Intel Arc Graphics] [8086:7D55]
       vendor: Intel Corporation [8086]
       physical id: 2
       bus info: pci@0000:00:02.0
       logical name: /dev/fb0
       version: 08
       width: 64 bits
       clock: 33MHz
       capabilities: pciexpress msi pm vga_controller bus_master cap_list rom fb
       configuration: depth=32 driver=i915 latency=0 resolution=3072,1920
       resources: iomemory:420-41f iomemory:420-41f irq:195 memory:4202000000-4202ffffff memory:4210000000-421fffffff memory:c0000-dffff memory:4a20000000-4a26ffffff

GUI approach

You need the GNOME control center application, which is preinstalled on Ubuntu 24.04 (and called Settings)

From there you can follow up the menu entries About, followed by System Details.

I've cropped the relevant output

system_details.png

Drivers

There's usually good support from Ubuntu on proprietary drivers, Nvidia included. I simply had to select the driver version, and I went with the proprietary one for now. They seem to be moving towards a more open sourced approach, but for now I think the proprietary ones is better tested.

additional_drivers.png

As you can see above, I've also had version 535 installed, and I've run into the flickering bug https://forums.developer.nvidia.com/t/flickering-at-the-top-of-the-screen/256447. This got fixed in 550 for me.

At the time I tried it, I could not select version 550 from the UI. This happened because of a collateral from 550 (https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-550-server/+bug/2062380) which got fixed in between.

To force switching to it, I've used the ubuntu-drivers command line utility. You basically need to list out possible versions, and then run with the install option using the version you need.

This is also an alternative to the UI approach, and I've outlined a few steps below

george@local:~$ sudo ubuntu-drivers list
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
udevadm hwdb is deprecated. Use systemd-hwdb instead.
nvidia-driver-535-server-open, (kernel modules provided by linux-modules-nvidia-535-server-open-generic-hwe-24.04)
nvidia-driver-550, (kernel modules provided by linux-modules-nvidia-550-generic-hwe-24.04)
nvidia-driver-535-open, (kernel modules provided by linux-modules-nvidia-535-open-generic-hwe-24.04)
nvidia-driver-535-server, (kernel modules provided by linux-modules-nvidia-535-server-generic-hwe-24.04)
nvidia-driver-535, (kernel modules provided by linux-modules-nvidia-535-generic-hwe-24.04)
nvidia-driver-550-open, (kernel modules provided by linux-modules-nvidia-550-open-generic-hwe-24.04)
george@local:~$ sudo ubuntu-drivers
Usage: ubuntu-drivers [OPTIONS] COMMAND [ARGS]...

Options:
  --gpgpu              gpgpu drivers
  --free-only          Only consider free packages
  --package-list PATH  Create file with list of installed packages (in install
                       mode)
  --no-oem             Do not include OEM enablement packages (these enable an
                       external archive)
  -h, --help           Show this message and exit.

Commands:
  autoinstall  Deprecated, please use "install" instead
  debug        Print all available information and debug data about drivers.
  devices      Show all devices which need drivers, and which packages...
  install      Install a driver [driver[:version][,driver[:version]]]
  list         Show all driver packages which apply to the current system.
  list-oem     Show all OEM enablement packages which apply to this system

Linux native games

There are some native Linux games, which are free and can be installed with your default distribution package manager. Here are some classic games examples below:

Chess
GNOME chess (has a default engine, but one can use others such as stockfish).
Backgammon
GNU backgammon
Solitaire
Aisleriot
Tetris
LTris
Tux Racer
Tux Racer
Minesweeper
GNOME mines

I will not go into details on how to install them. You can apt from CLI, or GNOME software for a UI based approach. More details are available here

Popular games

The bigger names mostly come via digital distribution platforms. Here are some that openly support Linux:

Valve offers Linux support for its software client (Steam), while the others do not.

There are good solutions readily available though, namely Lutris and Heroic Games Launcher. They seem roughly equivalent at this, I've decided to go with Lutris because it is available as a package in the distribution, and also like the idea that it is built on GTK, the UI library that GNOME is built on.

In the end though, it seems they've started working on common infrastructure, so it probably will not matter as much what you use in terms of games supported.

Steam

Installing the steam client is as simple as:

george@local:~$ sudo apt install steam

You may need the multiverse repository

george@local:~$ sudo add-apt-repository multiverse
george@local:~$ sudo apt update

Of course, you can use GNOME software as well:

steam_install.png

You can go with the snap or flatpak approach, but I think each one comes with some limitations.

I used the snap approach and I noticed a noticeable slowness on startup, but other than this, things worked out just fine.

For the flatpak one, I consider it more complicated to maintain, as flatpak needs to maintain its own copy of the kernel drivers

For the playable games from Steam, you can already check out https://www.protondb.com/ to get an idea if your favorite game is properly supported.

proton_db.png

You can also try it out unsupported games, some of them still work just fine in the majority of the case. You will need to enable the compatibility checkbox as outlined below.

steam_compatibility.png

I've been able to play Dota 2, OpenTTD and Sid Meier's Civilization V.

For Civ 5, I needed to apply the following fix https://steamcommunity.com/app/8930/discussions/0/2632849569464744216/, basically configure the launch options as outlined below.

civ5_launch.png

Also, I've only been to play it at maximum resolution only for some reason (this worked just fine when I've installed it via snap). I did not investigate more than this, as the solution was good enough for me.

Overall, I've been able to play the games I found on Steam, but needed to apply some workarounds

Lutris

You can easily install Lutris via GNOME software, as outlined below

lutris_install.png You can check out the supported game in their database, here's a snapshot below attempting to find Heroes and Might Magic III, a game for which I've not found a solution on Steam.

lutris_heroes.png

I've found the version I was interested in on gog.com, but unfortunately it doesn't offer support for Linux out of the box. So, I had to check out whether Lutris had a solution for it, and I've found one here. For me, only the "GOG + HD mod version" solution worked out, but it was more than enough for me.

Overall, I've had a good experience with the application, it has good integration with gog.com, as well as with as other vendors.

Conclusion

Overall, the Linux gaming infrastructure has gotten much better nowadays, with more and more games supporting Linux via Steam or other vendors. You will probably still run into various issues, but this time around I expect to find a lot more answers in various forums, as this was my overall experience.

There are some concerns caused by the fact that Linux has no anti cheat kernel based solution, resulting in some game developers not supporting Linux as a platform. The community maintains a website tracking these games and the plans for it at https://areweanticheatyet.com/

Things can always be better, but I consider things good enough so that you can get by. If gaming stopped you from switching to Linux, you should check out the Protondb/Lutris databases to see if you're favorite games are available.

Tags: Linux Gaming
Other posts
Copyright Linux Logs @2024