Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set Graphics Performance for an app

There is an option in Windows control panel that allows to set a app to "high performance". Control Panel -> System -> Display -> Graphics Settings.

On adding my application there, I noticed that, when encoding with Media Foundation and H.265 it uses the NVIDIA gfx adapter for encoding. Before that, it used to use the embedded Intel graphics which would only do H.264 encoding, so H.265 encoding was slowly done in CPU.

How can I add my application there programmatically? It's crucial for my sequencer's performance.

Thanks a lot.

Graphics Settings

like image 500
Michael Chourdakis Avatar asked Jan 26 '23 10:01

Michael Chourdakis


1 Answers

To my best knowledge there is no API or documentation for this. The preference is, however, kept in registry under

HKEY_CURRENT_USER\Software\Microsoft\DirectX\UserGpuPreferences

String value with GpuPreference part and integer value corresponding DXGI_GPU_PREFERENCE enumeration.

If you set the value there programmatically, it is picked up with next app restart. The parent UserGpuPreferences and DirectX keys might not exist, so you need to make sure they are present too.

Also, to my best knowledge, this preference takes precedence over possibly existing similar preference setting in vendor (AMD, NVIDIA) specific settings.

See also:

  • Graphics performance preference on MSDN Forums

Example

If your application is C:\testapp.exe, you want to create the following registry entry:

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\DirectX\UserGpuPreferences]
"C:\\testapp.exe"="GpuPreference=1;"

Or another way is to add the override interactively using settings and then review the created registry value.

like image 154
Roman R. Avatar answered Jan 29 '23 11:01

Roman R.