How to Run a Vulkan or Direct3D 12 Demo on a Particular GPU



Both Vulkan and Direct3D 12, the new low level graphics APIs, offer a nice feature so far reserved to computing APIs (OpenCL or CUDA): the ability to run graphics tasks on a particular GPU.

If you have more than one GPU in your system (for example two or three single GPU graphics cards, or one dual-GPU card like a Radeon R9 295X or a GeForce GTX Titan Z), you can select a specific GPU and run a Vulkan or Direct3D 12 demo on this GPU.

With OpenGL, this is not possible on Windows. OpenGL has one renderer (usually the first GPU) and the only way to use the second GPU is to enable SLI or CrossFire. But even with SLI / CrossFire, OpenGL sees only one renderer which is a logical GPU. On a system with one physical GPU, OpenGL sees one logical GPU made up of one physical GPU and on a system with two GPUs (and with SLI or CrossFire enabled), OpenGL still sees one logical GPU made up of two physical GPUs.

As a programmer, you can not assign graphics / compute task to a particular GPU in OpenGL on Windows. This limitation has been removed by Vulkan and Direct3D 12.

On Linux and OS X, you run an OpenGL demo on a particular GPU. On Linux you have to create a context on the proper display, while virtual screens do the job on OS X.

You can easily test this feature with the latest GeeXLab. Just take any Vulkan demo of the code sample pack (in the vk/ folder), and change the value of the gpu_index attribute of the window XML node. The following code snippet show how to run the demo on the first GPU (index = 0):

  

 
To run the demo on the second GPU (index = 1):

  

 
GeeXLab allows to create several 3D windows in the same demo (each window running its own set of scripts: INIT, FRAME, etc.). I prepared a Vulkan demo that creates two 3D windows, each window being assigned to a particular GPU. On my dev system, I have two cards: GeForce GTX 960 + GeForce GTX 750. The first window will run on the GTX 960 and the second will run on the GTX 750:

  
          
  
  

 
The demo is available here: vk/02-triangle-of-death-multiple-windows.xml


Vulkan multi-GPU demo

 
Remark: at the time of writing, the multiple windows feature works only on Windows. There is a bug that prevent to run it on Linux. I hope to fix it for the next release…





Leave a Comment

Your email address will not be published. Required fields are marked *