Per Application PRIME Setting

Hi,
I’m here to ask for inspiration:
I’m writing a GUI to set per application if GPU offloading should be active or not. My best idea so far was to parse the system for .desktop files and overload them in ~/.local/share/applications/ with the according environment variables set (e.g. copying the the .desktop entry and changing the Exec= key to Exec=primerun with primerun being a small script setting __NV_PRIME_RENDER_OFFLOAD=1 and __GLX_VENDOR_LIBRARY_NAME=nvidia).

However this approach is prone to error because .desktop files are a moving target and there is other stuff creating .desktop files in ~/.local/share/applications/.

I would much prefer to set it on a per binary basis like the GUI in windows allows the user to do. However I didn’t find a way to set the environment variable or something equivalent based on a binary path being executed.

Does anyone know how the Windows driver/settings gui handles this? I checked C:\Windows\System32\DriverStore\FileRepository\nvtf.inf_amd64_<some_hex_number>\nv-vk64.json what I assume to be the Windows equivalent of /usr/share/vulkan/implicit_layer.d/nvidia_layers.json, but unlike on Linux it does not check an environment variable, so I assume the setting is not handles via environment variables on Windows.

Does someone have an idea where in the execution chain i could hook into to have something like if <binary_path>: set <environment>? I already found the code location that checks for __NV_PRIME_RENDER_OFFLOAD=1 and __GLX_VENDOR_LIBRARY_NAME=nvidia in the Vulkan (VulkanLoader) and OpenGL (libglvnd) sourcecode respectifly, however i didn’t find a hint of alternative decision mechnisms.

Sorry for the long novel above, I tried to summerise my research so far as short as possible.

Don’t know whether anyone ever tried using application profiles in nvidia settings for that.

I think the application profiles only come into effect once the application is already running on the nvidia card. Are the variables you set there even environment variables or nvidia driver internal variables?

Please correct me if I’m wrong.

Good point. So forget what I said.