Skip to content

Instantly share code, notes, and snippets.

@statico
Last active November 8, 2024 14:50
Show Gist options
  • Save statico/6809850727c708f08458 to your computer and use it in GitHub Desktop.
Save statico/6809850727c708f08458 to your computer and use it in GitHub Desktop.
Trick to tell AMD and Nvidia drivers to use the most powerful GPU instead of a lower-performance (such as integrated) GPU
#ifdef _WIN32
// Use discrete GPU by default.
extern "C" {
// http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
// http://developer.amd.com/community/blog/2015/10/02/amd-enduro-system-for-developers/
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
#endif
@parkercoates
Copy link

Sadly, that AMD link has expired and I haven't found a better reference anywhere, other than this forum post: https://community.amd.com/thread/169965

@Moguri
Copy link

Moguri commented Jul 1, 2019

Copy link

ghost commented Jun 1, 2020

Dumb question: Are these relevant in Linux (or OSX for that matter)?

@peterix
Copy link

peterix commented Mar 25, 2021

No, this is not relevant for anything other than Windows.

@IGR2014
Copy link

IGR2014 commented Mar 29, 2022

More dumb question: There's nothing similar for Intel (integrated HD Graphics), right?

@tinuroth
Copy link

More dumb question: can I do this somehow from a managed C# application? It does Pinvoke for the purpose of calling native algos, but how would I extern "C" { __declspec(dllexport) ... } such properties to be picked up by the drivers? Can any of my native DLLs export this and it will be picked up?

@JustAndreww
Copy link

and is there analogue to force rendering on Intel discrete GPU?

@SubBastion
Copy link

right

Intel always uses the Power Plan. If there is a Intel ARC GPU and an Intel UHD Integrated and the power plan says to maximize performance it will use the Intel ARC

managed

Based on what I read and tried for AMD at least it uses a utility that scans for the string of AmdPowerXpressRequestHighPerformance before it's executed and thus A: you can't inject DLL code in memory B: you can't use a wrapper for it (TESTED) as the graphics selection isn't inherited between processes. C: People already tested putting the code in the DLL on both AMD and NVIDIA and it does nothing. It has to be the main EXE

@SubBastion
Copy link

SubBastion commented Jan 25, 2024

Anyone Figure out how to programmatically use one of AMD's EXE's and NVIDIA to add Graphics entries directly to the UI instead of dealing with this madness which doesn't support wrappers or DLLs. I checked the registry it doesn't appear to do anything on an AMD machine tested with 2019 AMD Software. 2020+ AMD Software ignores switchable graphics entries and only uses the powerplan fallowing intels footsteps. Before Windows Added Graphics Entry Options in windows 10 (2020?) AMD and NVIDIA Software was the only way of setting the preferred graphics processor per exe

@SubBastion
Copy link

SubBastion commented Jan 25, 2024

Dumb question: Are these relevant in Linux (or OSX for that matter)?

If they have the right AMD drivers it should in theory work for linux based on how it's detected of literally dumping strings and looking for the field.
MacOs doesn't use NVIDIA in any recent years nor AMD they create their own now I believe and also I believe on macos only supports onegpu. The GPU being either intel iris neither integrated nor dedicated, or their own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment