Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force system with nVidia Optimus to use the real GPU for my application?

I want my application to always run using the real gpu on nVidia Optimus laptops.

From "Enabling High Performance Graphics Rendering on Optimus Systems", (http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf):

Global Variable NvOptimusEnablement (new in Driver Release 302) Starting with the Release 302 drivers, application developers can direct the Optimus driver at runtime to use the High Performance Graphics to render any application–even those applications for which there is no existing application profile. They can do this by exporting a global variable named NvOptimusEnablement. The Optimus driver looks for the existence and value of the export. Only the LSB of the DWORD matters at this time. A value of 0x00000001 indicates that rendering should be performed using High Performance Graphics. A value of 0x00000000 indicates that this method should be ignored. Example Usage:

extern "C" {   _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; }

The problem is that I want to do this using Delphi. From what I've read Delphi does not support export of variables even though some hacks exists. I did try a few of them but couldn't make it work.

In the same nvidia document I read that forcing the proper GPU can be accomplished via linking statically to one of a handful listed dlls. But I don't want to link to dlls I'm not using. (Why the opengl.dll is not one of them is beyond me.) A simple exported variable seems much cleaner.

like image 443
DelphiDabber Avatar asked Mar 12 '13 21:03

DelphiDabber


People also ask

How do I force NVIDIA Optimus?

Manually Configure OptimusRight Click on your desktop. Click NVIDIA Control Panel. Click Manage 3D Settings on the left menu. Click on the Preferred graphics processor drop down menu under the Global Settings tab.

How can I make a program use GPU instead of CPU?

Switching to the dedicated Nvidia GPU - Navigate to 3D Settings > Manage 3D Settings. - Open the tab Program Settings and choose the game from the dropdown menu. - Next, select the preferred graphics processor for this program from the second dropdown. Your Nvidia GPU should show as High performance Nvidia processor.

What is GPU Optimus mode?

NVIDIA Optimus automatically, instantaneously, and seamlessly optimizes the notebook to offer the best performance or best battery life depending on the application. When the GPU can provide an increase in performance, functionality, or quality over the IGP for an application, the NVIDIA driver will enable the GPU.


1 Answers

From what I've read Delphi does not support export of variables.

That statement is incorrect. Here's the simplest example that shows how to export a global variable from a Delphi DLL:

library GlobalVarExport;

uses
  Windows;

var
  NvOptimusEnablement: DWORD;

exports
  NvOptimusEnablement;

begin
  NvOptimusEnablement := 1;
end.

I think your problem is that you wrote it like this:

library GlobalVarExport;

uses
  Windows;

var
  NvOptimusEnablement: DWORD=1;

exports
  NvOptimusEnablement;

begin
end.

And that fails to compile with this error:

E2276 Identifier 'NvOptimusEnablement' cannot be exported

I don't understand why the compiler doesn't like the second version. It's probably a bug. But the workaround in the first version is just fine.

like image 82
David Heffernan Avatar answered Oct 01 '22 02:10

David Heffernan