Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing NVIDIA GPU programmatically in Optimus laptops

I'm programming a DirectX game, and when I run it on an Optimus laptop the Intel GPU is used, resulting in horrible performance. If I force the NVIDIA GPU using the context menu or by renaming my executable to bf3.exe or some other famous game executable name, performance is as expected.
Obviously neither is an acceptable solution for when I have to redistribute my game, so is there a way to programmatically force the laptop to use the NVIDIA GPU?

I've already tried using DirectX to enumerate adapters (IDirect3D9::GetAdapterCount, IDirect3D9::GetAdapterIdentifier) and it doesn't work: only 1 GPU is being reported (the one in use).

like image 621
Smohn Jith Avatar asked May 10 '12 14:05

Smohn Jith


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 do I bypass NVIDIA Optimus on my laptop?

You can find the 'Hybrid Mode' option on the right side of the screen. This mode allows Optimus to be enabled. This means, when you want to disable Optimus in your Gaming Laptop, you have to switch off the Hybrid Mode. The process is finally completed when you restart your computer.

Does my laptop support NVIDIA Optimus?

How do you know if your laptop is using NVidia Optimus? There are several ways to find out what video card your computer uses. An easy method is to go to Device Manager > Display Adapters and see an NVidia option is listed.


2 Answers

According to http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf starting from 302 drivers it is enough to link statically with one of the following libraries: vcamp110.dll, vcamp110d.dll, nvapi.dll, nvapi64.dll, opencl.dll, nvcuda.dll, cudart*.*, or to export a NvOptimusEnablement variable in your program:

extern "C" {     _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; } 
like image 128
DikobrAz Avatar answered Oct 19 '22 13:10

DikobrAz


The Optimus whitepaper at http://www.nvidia.com/object/LO_optimus_whitepapers.html is unclear on exactly what it takes before a switch to GPU is made. The whitepaper says that DX, DXVA, and CUDA calls are detected and will cause the GPU to be turned on. But in addition the decision is based on profiles maintained by NVIDIA and, of course, one does not yet exist for your game.

One thing to try would be make a CUDA call, for instance to cuInit(0);. As opposed to DX and DXVA, there is not way for the Intel integrated graphics to handle that, so it should force a switch to the GPU.

like image 34
Roger Dahl Avatar answered Oct 19 '22 15:10

Roger Dahl