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:

  • Works with OpenGL and Vulkan games.
  • Works with native games and Proton Proton is a compatibility layer included in Steam for running Windows games in Linux. It is based on Wine, DXVK and D9VK open source projects with additional patches and new features added by Valve/Wine developers.
  • Works with games purchased on Steam or third party games added to Steam by the user.
  • Tested working with integrated Intel and AMD graphics cards.
  • Untested with NVIDIA cards as I don’t own an NVIDIA card. But according to Steam community forums, built-in fps counter works fine on NVIDIA cards.

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:

  • Works with OpenGL games only.
  • Works with native games and Wine games.
  • Tested working with integrated Intel and AMD graphics cards with open source drivers.
  • Untested with NVIDIA cards as I don’t own an NVIDIA card. It should however work with NVIDIA GPUs with open source drivers.

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:

    • Works with Vulkan games only.
    • Works with Ubuntu 19.10+ only and other distributions having latest Mesa with vulkan overlay layer.
    • Works with native games and Steam Proton games running with DXVK/D9VK support.
    • Works with with Wine games running with DXVK/D9VK libs.
    • Working status unknown for Wine’s Vkd3d. Since this is a Vulkan layer, it should work with anything as long as Mesa is built with VK_LAYER_MESA_overlay support.
    • Tested working with AMD graphics cards and integrated Intel cards with open source drivers.
    • Untested with NVIDIA cards as I don’t own an NVIDIA card. Since this is a Vulkan layer, it should work with anything as long as Mesa is built with VK_LAYER_MESA_overlay support.

    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:

    • Works only with Vulkan games running in Wine and Proton with DXVK/D9VK libs.
    • Tested working with AMD and integrated Intel graphics cards with open source drivers.
    • Untested with NVIDIA cards as I don’t own an NVIDIA card. Source code has commits that mention NVIDIA support so this method should work.

    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:

    About the author

    Nitesh Kumar

    Nitesh Kumar

    I am a freelancer software developer and content writer who loves Linux, open source software and the free software community.