Programmatically set Graphics Performance for an app
Asked Answered
B

1

8

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

Bentwood answered 14/1, 2020 at 10:43 Comment(2)
I can't confirm right now, but I think Windows also honors those NVIDIA and AMD tricks: gist.github.com/statico/6809850727c708f08458 as dxgi.dll, d3d9.dll and opengl32.dll contain those magic strings.Mychael
@SimonMourier: sadly, these tricks are one way only, these can only enforce discrete GPU preference.Eshelman
E
13

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:

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.

Eshelman answered 14/1, 2020 at 10:58 Comment(9)
NOTE: It looks like this key may or may not already be there on any given machine. That threw me at first, but the usual Direct3D stuff is under HKLM (not HKCU). So, you may need to create the key under HKCU in addition to adding a value under it.Metcalf
I have tried this solution... and it doesn't work correctly.Clemons
for example in my application I have added a code; which on startup is supposed to add both the executable and another executable of the thread to the hig performance profileClemons
i have restarte the appClemons
The problem is that it does not recognize it as such. I have looked at the windows 11 task manager that shows what graph it is using... and it always marks #0...Clemons
Out of curiosity, enter the application preference manager in the graphic section and I have managed to verify that they do appear.Clemons
then try to open the application for the third time and then it came to use dedicated GPU #1 according to the task manager ...Clemons
any idea why this peculiarity?Clemons
I'd expect this method to be in good standing for Windows 11, even though it's not really clear what exactly does not work for you. I have a small tool here alax.info/blog/1987 which adds itself into registry the way suggested in this asnwer. Maybe you can try it out and see if it works (and than the method is assumed to be applicable to your system).Eshelman

© 2022 - 2024 — McMap. All rights reserved.