Skip to content

Instantly share code, notes, and snippets.

@BeRo1985
Created May 30, 2018 04:04
Show Gist options
  • Save BeRo1985/939241b471f776ab844657d28d59368c to your computer and use it in GitHub Desktop.
Save BeRo1985/939241b471f776ab844657d28d59368c to your computer and use it in GitHub Desktop.
Force usage of dedicated GPU for OpenGL with Delphi and FreePascal/Lazarus on Multi-GPU systems such as Notebooks on Windows
// Force usage of dedicated GPU for OpenGL with Delphi and FreePascal/Lazarus on Multi-GPU systems such as Notebooks on Windows
// Insert that into your main source file, which is for example the .dpr (Delphi) or .lpr (Lazarus) file
{$define ForceDedicatedGPUUsage} // then you can uncomment and recomment this line, for compile-time-switching between
// integrated GPU and dedicated GPU
{$if defined(Windows) and defined(ForceDedicatedGPUUsage) and (defined(cpu386) or defined(cpux64) or defined(cpuamd64))}
{$ifdef fpc}
{$asmmode intel}
{$endif}
procedure NvOptimusEnablement; {$ifdef fpc}assembler; nostackframe;{$endif}
asm
{$ifdef cpu64}
{$ifndef fpc}
.NOFRAME
{$endif}
{$endif}
dd 1
end;
procedure AmdPowerXpressRequestHighPerformance; {$ifdef fpc}assembler; nostackframe;{$endif}
asm
{$ifdef cpu64}
{$ifndef fpc}
.NOFRAME
{$endif}
{$endif}
dd 1
end;
exports NvOptimusEnablement,
AmdPowerXpressRequestHighPerformance;
{$ifend}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment