Forcing NVIDIA GPU programmatically in Optimus laptops

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 15:46:45

问题


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).


回答1:


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.




回答2:


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;
}


来源:https://stackoverflow.com/questions/10535950/forcing-nvidia-gpu-programmatically-in-optimus-laptops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!