There has been much discussion around the upcoming API (Application Programming Interface) DirectX12 as it has been described as a game changer for the development of games of the future. So what exactly can DirectX12 offer us that DirectX11 cannot?
“The short answer is that newer APIs will make the CPU faster” Hable said to GamingBolt. “The improved APIs change how long it takes for you to tell the GPU what you want it to do”.
Hable explains the difference between DirectX 11 and DirectX 12 with an extremely simplistic example.
“Let’s say that you are drawing a cute little family of bunnies. These bunnies are made of triangles and each bunny has its own colour map, normal map, etc. With OpenGL or DirectX 11 you would have to describe each of these bunnies one at a time. The first bunny has a red colour map. The second bunny has a blue colour map. The third bunny has a green colour map. And every frame you have to tell the GPU the same thing over and over again.”
“DirectX12 and Vulkan are much more efficient. In the first frame, you can describe all the bunnies to the GPU. You tell the GPU that there is a red one, a blue one, and a green one. Then they can all be drawn together. With DirectX11 and OpenGL you have to describe all the bunnies every frame but with DirectX 12 and Vulkan you can just say “draw all the bunnies”. I’m oversimplifying but that is the idea.”
What this means in the long run is that there is a more efficient transfer of data between the application and the GPU. This does not mean that the units will render faster as the amount of time taken by the old and new API is the same but the time taken to give the command is reduced, resulting in slightly speedier results.
What this means for PC gamers is “if your game is bottlenecked by the CPU, going to DirectX 12 or Vulkan will greatly help your game.” He explains that “this situation happens a lot on PC games where you have a powerful card sitting idle because it can draw things faster than it can be told to draw them” and “many games are intentionally making “bad” decisions for the GPU to help out the driver on the CPU.”
“For example, let’s say that your bunnies have multiplied and now you have 5 red bunnies, 5 blue bunnies, and 5 green bunnies. For the GPU, the ideal way to render the bunnies is front to back to minimize overdraw. But the cost of telling the driver to do that would be too slow with DirectX 11 and OpenGL.”
“Telling the GPU to render red, blue, blue, green, red, blue, etc. would have too many state changes. So you have to render all the red bunnies together, followed by all the blue and green bunnies. With DirectX 12 and Vulkan, the overhead is low enough that we can render the bunnies in the optimal front to back order.”