2

I read about OpenGL multi-GPU support. I am currently using OpenGL 4.5 supported NVIDIA card. My iGPU is Intel HD 610 and I don't know about it's openGL version. Now I am try to use both together. I know DirectX 12 can support different GPUs. Does OpenGL support Intel iGPU and NVIDIA GPU together? Can I use iGPU port for my display and utilize NVIDIA card for Cycle Rendering in blender? (The last point is important because my monitor only supports VGA.)

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Bapi
  • 309
  • 1
  • 16
  • [As of EGL v1.5 there's a `EXT_platform_device`](https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_platform_device.txt) that allows one to choose a GPU to render on. – Hi-Angel Jan 21 '23 at 14:34

2 Answers2

6

OpenGL has been designed very long time ago, making adoption of this API to handle multiple GPU devices problematic. Unlike OpenCL or Vulkan, which have some basic meaning of selecting devices/drivers available in system from the very beginning, OpenGL (or specifically - WGL, GLX, EGL interfaces binding OpenGL to windowing system) do not have any - OS is fully responsible for driver selection using unclear logic.

What OpenGL actually provides:

  • GPU affinity/selection within the same OpenGL driver (WGL_AMD_gpu_association and WGL_NV_gpu_affinity). This allows managing GPU tandems of the same vendor GeForce+GeForce or Radeon+Radeon (including iGPUs in the latter case), but not GPUs of different vendors. MESA driver on Linux supports also GLX_MESA_query_renderer extension, but so far it allows only listing all available renderers in the system, not selecting specific one.
  • Preferred GPU in iGPU+Discrete tandem. Specific Intel+GeForce tandems provide driver settings (usually in NVIDIA control panel) allowing to use either iGPU or GeForce by specific application. Application might also use tricks (like exporting a symbol in DLL) asking driver to prefer discrete GPU over iGPU. There is no way using both GPUs at once in the same application. Note also, that this is applicable only to notebooks with special Intel+NVIDIA drivers, not to normal desktop configurations.
  • Active GPU in other multi-GPU (desktop) configs. OS is fully responsible for driver selection using unclear logic. Within interactive session, Windows decides which OpenGL driver to load based on to which GPU main display is physically connected (previously, it was stated somewhere, that window position altered this logic, but it seems no more the case for modern Windows systems). Within RDP session, the logic is unclear and non-configurable - it is somehow determined from the GPUs order in PCI-E slots; the only way to choose some GPU is disabling all other GPUs in Device manager.

In any case, using multiple GPUs even within APIs supporting this, is quite complicated stuff requiring a lot of efforts from application developer: managing multiple devices, duplicated memory management, splitting rendering viewports, balancing and synchronization. And even in the best case, the benefit will be much less then 2x for 2 equal GPUs, because portions of rendering pipeline have to be processed on both GPUs (like Shadows rendering in this video about VR renderer - so that 2 GPUs give only 30-35% performance increase).

At the same time, using non-equal GPUs in multi-GPU config is even larger headache - due to additional balancing issues, as well as inconsistent GPU (driver) capabilities. In Intel iGPU + Discrete GPU tandem, the first one will be not only slower, but have lower capabilities in terms of OpenGL core version or extensions. Although, AMD has shown some multi-GPU iGPU+Discrete GPU setups with some performance boost.

Hi-Angel
  • 4,933
  • 8
  • 63
  • 86
gkv311
  • 2,612
  • 1
  • 10
  • 11
  • Since you mention cases where utilities external to an application choose the GPU, I think also worth noting [the `DRI_PRIME` env. variable](https://docs.mesa3d.org/envvars.html#envvar-DRI_PRIME), which is supported by all Mesa-based drivers, starting with official ones like Intel, AMD, VMware SVGA, and ending with community supported like Nouveau, Asahi *(though probably not all GPU combinations exist in the wild)*… – Hi-Angel Jan 21 '23 at 12:31
3

If you have GPUs from different vendors on the machine, it is easy to select which one to use with OpenGL. In order to do so, call the following function before you create your OpenGL context:

// pass one of these to choose_ogl_vendor()
#define VENDOR_AMD "PCI\\VEN_1002&"
#define VENDOR_NVIDIA "PCI\\VEN_10DE&"
#define VENDOR_INTEL "PCI\\VEN_8086&"
void choose_ogl_vendor(const char *vendor_id)
{
    int idx;
    DISPLAY_DEVICEA dd;
    HDC dc;
    PIXELFORMATDESCRIPTOR pfd;

    dd.cb = sizeof(dd);
    idx = 0;
    while (1) {
        if (!EnumDisplayDevicesA(NULL, idx, &dd, 0))
            return; // not found!
        if (strstr(dd.DeviceID, vendor_id))
            break; // there we go
        idx += 1;
    }

    dc = CreateDCA(dd.DeviceName, NULL, NULL, NULL);
    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    // those flags are not important, they just need to be valid (and nondemanding, just in case).
    // later you will use whatever flags you wish when you are creating your actual gl context
    pfd.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER|PFD_DEPTH_DONTCARE;
    ChoosePixelFormat(dc, &pfd);
    DeleteDC(dc);
}

This function will force opengl32.dll to load the ogl driver of your choice. After that, proceed with the usual OpenGL context creation and initialization stuff.

Note, however, that once the GPU vendor's driver has been loaded, it can not be changed for the life time of your process.

l_belev
  • 109
  • 1
  • 2
  • Sorry, but that is very misleading. None of the API used has anything to do with OpenGL, and will not work on many existing systems, e.g. Mac OS, Ubuntu, Fedora, Archlinux… May work on Windows ones though. – Hi-Angel Jan 21 '23 at 12:51
  • @Hi-Angel It's misleading that using a Windows API won't work on platforms other than Windows? I think that part is rather obvious. – rdb Jan 21 '23 at 15:18
  • 1
    @rdb it isn't because the API functions used doesn't have a prefix like `Win` and answer is formulated in a very generic way, so to figure out you need to google up some of the functions mentioned. Do you know what API `EnumDisplayDevicesA` or `ChoosePixelFormat` belongs to? I don't. Anyway, I left a comment just in the hope that the author would clarify their answer, like adding at the top: `On Windows you can do this …`. – Hi-Angel Jan 21 '23 at 18:09