对可执行文件执行右键单击操作并选择 "Run with Graphics Processor" 等选项的命令

Command to perform right click operation on executable file and choose an option like "Run with Graphics Processor"

我想在 Windows 命令提示符中编写命令以复制以下内容:

  1. 右键单击可执行文件
  2. Select "Run with Graphics Processor"
  3. 选择"High-Performance NVIDIA Processor"

有办法吗?

根据 NVIDIA 的技术说明 Enabling High Performance Graphics Rendering on Optimus Systems,您可以通过导出一个名为 NvOptimusEnablement 的全局变量来确保您的应用程序使用高性能图形模式,该变量的值设置为 1.

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

(此示例代码使用 __declspec(export) to instruct the compiler to automatically export the symbol as data, which assumes Microsoft's compiler,尽管 GCC 现在支持它作为 MSVC 兼容性的扩展。)

或者,同一文档说您可以静态地 link 到其中一个 NVIDIA 驱动程序 DLL 以实现相同的效果:

For any application without an existing application profile, there is a set of libraries which, when statically linked to a given application executable, will direct the Optimus driver to render the application using High Performance Graphics. As of Release 302, the current list of libraries are vcamp110.dll, vcamp110d.dll, nvapi.dll, nvapi64.dll, opencl.dll, nvcuda.dll, and cudart*.*.

请注意,此解决方案将对 NVIDIA 驱动程序实施 依赖关系 ,而导出变量则不会。