windowscommand-promptnvidia

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


I want to write a command in Windows Command Prompt to replicate the following:

  1. Right-click on an executable file
  2. Select "Run with Graphics Processor"
  3. Choose "High-Performance NVIDIA Processor"

Is there a way to do so?


Solution

  • According to NVIDIA's technical note, Enabling High Performance Graphics Rendering on Optimus Systems, you can ensure that your application uses the High Performance Graphics mode by by exporting a global variable named NvOptimusEnablement whose value is set to 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;
    }
    

    (This example code uses __declspec(export) to instruct the compiler to automatically export the symbol as data, which assumes Microsoft's compiler, although GCC now supports it as an extension for MSVC-compatibility.)

    Alternatively, the same document says that you can statically link to one of the NVIDIA driver DLLs to achieve the same effect:

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

    Note that this solution will enforce a dependency on the NVIDIA drivers, whereas exporting a variable will not.