问题
We're developing software which uses DirectX for 3D rendering on Windows 7 and later machines, 64-bit C#/.NET code.
We've observed that a number of newer Dell laptops we're testing on have dual video cards. They have the Intel HD 4600 integrated graphics and they also have a faster NVIDIA Quadro card (for example).
By default, out of the box, the Intel graphics are used by the DirectX application. This is done, presumably to preserve battery life. But the performance is noticeably worse than the NVIDIA card.
Using the NVIDIA control panel, the user can control which one is used by default. As soon as the user switches it to use the NVIDIA card, the performance sees a big jump for the better.
So, my question is.... Is there any way to, in code, detect this setting and/or modify it for our application (on install and/or on launch)? Can we detect that for our app the Intel card is being used and if its one of these dual card scenarios, prompt the user and perhaps (if they request it) change the setting for them?
As it is currently we have to walk the users through manually making the change in the NVIDIA control panel.
Anyone else have any experience dealing with this and have any advice on how to proceed?
回答1:
You could use C# DLL Interop to access functions of the NVML (NVidia Management Libraries) that are part of the GPU Deployment Kit (GDK). NVML includes functions such as the following for enumerating and selecting GPU devices:
nvmlInit()
nvmlDeviceGetPciInfo()
nvmlDeviceGetCount()
nvmlDeviceGetHandleByIndex()
nvmlDeviceGetHandleByPciBusId()
and
nvmlDeviceSetPersistenceMode()
.
However, many NVML functions require Admin access and a reboot to change settings. So these are only viable if your users are ok with this (perhaps during initial installation).
A better option would be to enumerate the Direct3D devices and select the most appropriate one: Enumerating with DirectX11, and Enumerating with DirectX9.
回答2:
The answer is you can't, at least with some exceptions. Laptops that has dual video cards usually comes with a software that switches your currently used card, either manually or automatically. There are others that can automatically detect the need of a software application for larger resources, thus automatically switching to nvidia card.
However, there are a few workarounds for this, please see this thread. In addition, I suggest that you manually set the default graphics card to nvidia for all your laptops in order to eliminate this issue.
来源:https://stackoverflow.com/questions/29504891/laptop-dual-video-cards-how-to-programatically-detect-and-or-choose-which-one