6
votes

I have notebook with integrated Intel and NVIDIA graphic cards and I want to run my program (written in C# with .NET) debugging in Visual Studio 2013 Community Edition on NVIDIA card, as my program extensively works with OpenGL and Intel card not support latest OpenGL features. But by default settings program runs on Intel card.

I have tried changing default graphic card for my program in NVIDIA settings, but it looks like after program recompiling settings are reset.

So, are there any other simple ways to run program on NVIDIA graphics card? Maybe there are special command line parameters or something like that?

5

5 Answers

10
votes

The easiest way is to just add this piece of code somewhere in your program:

extern "C" {
    _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

For more info, take a look here : http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf

2
votes

I currently use Visual Studio 2017 Professional edition and I also need to use OpenGL. Like @Omich said, to change default graphic card for VS2017 in NVIDIA settings does not work. Finally I try to right click the "Visual Studio 2017" shortcut (or the devenv.exe, just the same result) and select the option "Run with graphics processor->high performance NVIDIA procesor" and it just works. This way is simple but it seems a little trivil since you have to right click your VS icon every time you start it.

1
votes

Easiest is probably to compile your program into a .NET DLL and call your Main function from an executable written in C++/CLI that exports the NvOptimusEnablement variable as Jerem has mentioned in the other answer.

1
votes

You can use the NVidia Control Panel app. I believe it is installed when installing the NVidia driver, but I'm not exactly sure about that. Start it up and:

Select Manage 3D Settings -> Program Settings tab

  1. Select program to customize: click Add button Locate your executable and click Add Selected Program
  2. Select preferred graphics processor... Select your NVidia processor

When you run your exe, even using Visual Studio Debugger, it will use the selected graphics processor.

0
votes

After a couple of hours of searching I found the solution at http://drivenbynostalgia.com/files/SOP.cs

I guess it's better than moving the entire project into dll and using C++/CLI launcher.