Gry

How to Show FPS Counter in Linux Games

How to Show FPS Counter in Linux Games
Linux gaming got a major push when Valve announced Linux support for Steam client and their games in 2012. Since then, many AAA and indie games have made their way to Linux and the number of users who game on Linux have increased considerably.

With the growth of Linux gaming, many users started to look for proper ways to display “frames per second” (FPS) counter as an overlay on running Linux games. An FPS counter helps in tweaking performance of running games as well as in benchmarking a PC's overall ability to play games at different resolutions.

Unfortunately there is no single unified way to display FPS counter in all Linux games that is independent of underlying technologies a game is running upon. Different renderers and APIs have different ways to display FPS counter. This guide will explain various methods that can be used to display an FPS counter in Linux games.

Method 1 (Steam)

Compatibility Notes:

Steam for Linux includes a built-in FPS counter that can be toggled from settings. This is probably one of the most compatible options that works with a majority of Linux games. However I had some issues with Unity engine games not displaying the built-in FPS counter. This option also requires you to have a Steam account and Steam client installed on your system.

Steam even allows you to add games not purchased from Steam to the game library and the built-in FPS counter works in these games as well. To add a non steam game, click on “Games” and then click on “Add a Non-Steam Game to My Library”, as shown in the screenshot below:

Browse to the location of your game files and then toggle “All Files” option at the bottom.

Select the game executable and then click on “ADD SELECTED PROGRAMS” as shown in the screenshot below:

If you want to run a Windows only game in Steam's Proton compatibility layer, you will have to enable an additional option in game properties.

I have added SuperTuxKart executable in steam Library, and FPS counter is working fine here as well. Note that any third party games added to Steam library should not have any spaces in their file location path.

Method 2 (LibGL)

Compatibility Notes:

LibGL is a Mesa library that exposes OpenGL APIs to apps and games and it is included in almost all Linux distributions by default. Using this library and another package that creates a HUD on visible display, we will show an FPS counter in Linux games. Run the following command to install the required package:

sudo apt install xosd-bin

To show FPS counter in native Linux games, use the command below after replacing /path/to/executable with your own game executable path. You can know more about all osd-cat options from here.

LIBGL_SHOW_FPS=1 /path/to/executable 2>&1 |
tee /dev/stderr | sed -u -n -e '/^libGL: FPS = /s/.* \([^ ]*\)= /\1/;p' |
osd_cat --lines=1 --color=yellow --outline=1 --pos=top --align=left

To show FPS counter in Windows games running on Linux through Wine, use the command below after replacing /path/to/executable with your own game executable path.

WINEDEBUG=fps wine /path/to/executable 2>&1 | tee /dev/stderr |
sed -u -n -e '/trace/ s/.*approx //p' | osd_cat --lines=1 --color=yellow
--outline=1 --pos=top --align=center

If you are using a Wine prefix, command would be (replace /path/to/wine/prefix and /path/to/executable):

WINEDEBUG=fps WINEPREFIX=/path/to/wine/prefix wine
/path/to/executable 2>&1 | tee /dev/stderr | sed -u -n -e '/trace/ s/
.*approx //p' | osd_cat --lines=1 --color=yellow --outline=1 --pos=top
--align=center

This method has a small limitation. While you can customize the osd-cat HUD, it stays at a fixed position on the display area without taking into consideration the geometry of the game window. In the screenshot above, FPS counter is shown above game window, not inside it. Games running in fullscreen are not affected by this.

Method 3 (Gallium3D)

  • Works with OpenGL games only.
  • Works with native games and Wine games.
  • Tested working with AMD graphics cards with open source drivers.
  • Gallium3D support for Intel is ongoing, so not working yet.
  • Untested with NVIDIA cards as I don't own an NVIDIA card. Since NVIDIA open source driver is Gallium3D enabled, this method should work.
  • Gallium3D is an API that makes it easier to develop drivers for graphics cards by providing a set of standard libraries and interfaces. AMD and NVIDIA open source drivers are built upon Gallium3D.

    To show FPS counter in native Linux games, use the command below after replacing /path/to/executable with your own game executable path:

    GALLIUM_HUD="simple,fps" /path/to/executable

    To show FPS counter in Windows games running on Linux through Wine, use the command below after replacing /path/to/executable with your own game executable path.

    GALLIUM_HUD="simple,fps" wine /path/to/executable

    If you are using a Wine prefix, command would be (replace /path/to/wine/prefix and /path/to/executable):

    GALLIUM_HUD="simple,fps" WINEPREFIX=/path/to/wine/prefix wine /path/to/executable

    In the screenshot above, I am using a customized GALLIUM_HUD variable that shows GPU and CPU temperatures as well. This custom command is different for different PC configurations. To read more about all customization options, run commands:

    sudo apt install mesa-utils
    GALLIUM_HUD=help glxgears

    Just for reference, here is the Custom command I used in the screenshots above:

    GALLIUM_HUD="simple,fps;sensors_temp_cu-amdgpu-pci-1c00.temp1;
    sensors_temp_cu-k10temp-pci-00c3.Tdie" /path/to/executable

    Method 4 (Mesa Vulkan Overlay)

    Compatibility Notes:

    Mesa Vulkan overlay is a new Vulkan layer added to recent builds of Mesa. It displays various information about the running application using an overlay.

    To show FPS counter in native Linux games, use the command below after replacing /path/to/executable with your own game executable path:

    VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=position=top-left /path/to/executable

    To show FPS counter in Windows games running on Linux through Wine and DXVK, use the command below after replacing /path/to/executable with your own game executable path:

    VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=position=top-left wine /path/to/executable

    If you are using a Wine prefix, command would be (replace /path/to/wine/prefix and /path/to/executable):

    VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay
    VK_LAYER_MESA_OVERLAY_CONFIG=position=top-left
    WINEPREFIX=/path/to/wine/prefix wine /path/to/executable

    Method 5 (DXVK HUD)

    Compatibility Notes:

    DXVK provides a Vulkan-based translation layer for D3D10 and D3D11 allowing users to play Direct3D 10/11 games on Linux. D9VK uses DXVK backend to provide an additional Direct3D9 implementation that can be used to play games built upon D3D9.

    To show FPS counter in DXVK games running on Linux through Wine, use the command below after replacing /path/to/executable with your own game executable path:

    DXVK_HUD=fps wine /path/to/executable

    If you are using a Wine prefix, command would be (replace /path/to/wine/prefix and /path/to/executable):

    DXVK_HUD=fps WINEPREFIX=/path/to/wine/prefix wine /path/to/executable

    This marks the end of this post. To conclude, I would mention one small detail omitted from above. All the non-steam methods explained above will work for Steam games as well. You have to replace “/path/to/executable” or “wine /path/to/executable” or “WINEPREFIX=/path/to/wine/prefix wine /path/to/executable” with “%command%” in the same commands used above. Just add the full command to launch options in game properties inside Steam app, as shown in the screenshot below:

    C Przykłady pętli programowania
    Pętla jest bardzo istotną częścią każdego języka programowania, aby rozwiązać każdy problem. W większości języków programowania istnieją trzy rodzaje ...
    Przykłady programowania w C w systemie Linux dla początkujących
    Język programowania C to jeden z dobrych wyborów do nauki programowania komputerowego dla początkujących. Podstawowej logiki programowania można się ł...
    Samouczek wywołania systemu Linux z C
    W naszym ostatnim artykule na temat Linux System Calls zdefiniowałem wywołanie systemowe, omówiłem powody, dla których można ich używać w programie or...