How to run an executable and tell it to use the discrete NVIDIA GPU instead of the onboard one

executablegamesgnomenvidiapop-os

I have a laptop with both a discrete and an onboard graphics card. I want to run a Game executable file using the discrete GPU but instead it runs on the obnboard one. How can I run it with the discrete GPU?

The game is not installed. It is a folder where I run the executable FILE.

  • OS: Pop! OS (Gnome)
  • CPU: amd ryzen 5 4000series
  • GPU: NVIDIA GTX 1650
  • game: cities:skyline
  • RAM: 16 gigs
  • File explorer – Nautilus

Discrete graphic option

I get this option for installed apps but how can I get it for executable files?

Tried to make the Desktop application

File:
location – /usr/share/applications/Cities.desktop – and double clicking it opens up the file explorer

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec="/home/{username}/Games/linux games/Cities - Skylines Collection/Cities.x64"
Name=Cities:Skyline
Icon="/home/{username}/Games/linux games/Cities - Skylines Collection/LauncherAssets/game-logo.png"

__GLX_VENDOR_LIBRARY_NAME=nvidia
__NV_PRIME_RENDER_OFFLOAD=1
__VK_LAYER_NV_optimus=NVIDIA_only

Best Answer

For AMD or Intel GPUs, setting the environment variable DRI_PRIME=1 should do the job.

For nVidia GPUs, you additionally need __GLX_VENDOR_LIBRARY_NAME=nvidia, __NV_PRIME_RENDER_OFFLOAD=1, and __VK_LAYER_NV_optimus=NVIDIA_only.

(The "Launch using Discrete graphics card" menu option internally uses the switcheroo-control service and I got these from its source code; I'm not 100% sure whether all of them are still needed today.)

I think there's a prime-run tool for nVidia but I don't actually know if it does anything beyond the above.

To include these in your .desktop file, you need something like (note the two sets of quotes, double on the outside and single around the path):

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=sh -c "__GLX_VENDOR_LIBRARY_NAME=nvidia __NV_PRIME_RENDER_OFFLOAD=1 __VK_LAYER_NV_optimus=NVIDIA_only '/home/{username}/Games/linux games/Cities - Skylines Collection/Cities.x64'"
Name=Cities:Skyline
Icon="/home/{username}/Games/linux games/Cities - Skylines Collection/LauncherAssets/game-logo.png"
Related Question