OpenGL Geforce Driver Primary GPU Selection

Choose Files

We have a process that uses OpenGL and GLUT, and is run on Windows. Each time it runs, it always runs on the GPU that is associated with the primary display on the machine. And if no display is connected, apparently the GeForce drivers has some fixed deterministic way to determine the primary GPU at that point. However, we have machines with multiple GPUs and would like to run multiple of those processes on each machine with multiple GPUs.

So I have code which basically changes the primary display (using ChangeDisplaySettingsEx) and then Initialize OpenGL after that, which works great, but requires a slew of things, like no service, no sleep, no lock screen, etc

So I tried to hook into win32 api calls to return to Nvidia drivers the display I want as “primary”, but I can’t figure out how Nvidia figures out what the primary display is on windows. I know this is not supported and frowned upon, but was wondering if you guys can share how you determine your primary gpu is so I can run my process on the gpu I want. Or do you have a better way to do this? I know D3D has easy way to choose a device, but we have limitations preventing D3D usage. I am also using GeForce cards so NV_GPU_Affinity for Quadros is not an option either.