Directx/C++ 3D Engine Programming: Learn Now, or Wait for Directx 12

DirectX/C++ 3D Engine programming: Learn now, or wait for DirectX 12?

Think of DX12 as "DirectX without training wheels, without brakes, and at the moment maybe without tires".

It will be more than a 'few months' for DirectX 12 to have a rich set of tutorials, support libraries, best practices, rock-solid drivers, and widely deployed support in the operating system on end-users machines. It's "bleed edge" right now, and best consumed by GPU graphics programming experts actively working on titles and engines today who want to make sure it all works.

For everyone else, learn DirectX 11 at least for the next year or so, and possibly longer depending on the needs of your app, your personal skill level, and the focus of what you are trying to learn in the meantime.

What I can say is that learning to program DirectX 11 using the legacy DirectX SDK stuff like D3DX is a dead-end for DX12. Focus instead on DirectX 11 using 'modern' helpers like DirectX Tool Kit and DirectXMath for C++.

  • Anatomy of Direct3D 11 Create Device
  • The Care and Feeding of Modern Swap Chains
  • Direct3D Win32 Game Visual Studio template
  • DirectX SDK Samples Catalog
  • DirectX SDK Tools Catalog
  • Living without D3DX
  • DirectX SDKs of a certain age

UPDATE: DirectX Tool Kit for DirectX 12 is now available along with some tutorials. That said, it is best to learn Direct3D 11 first as Direct3D 12 is an API designed for graphics experts and is quite unforgiving for newbies. Knowing how to use DirectX Tool Kit for DX11 will naturally map to the DirectX 12 version if you want to go that route.

New to Direct3D programming: 11 vs 12

I've answered this question before so you should take a look at that post.

In short, Direct3D 12 should be thought of as "DirectX Extreme Pro". It assumes you are already an expert in how the Direct3D 11 runtime works to the point that you can basically write it yourself. It is designed to allow middleware engines and low-level graphics developers to have maximum control over the behavior of the GPU. Direct3D 11 is also a "low-level" graphics API, but DirectX 12 has such a thin abstraction that many complexities of modern GPUs are exposed directly to the application programmer; complexities that Direct3D 11 hides from you.

Direct3D 12 is very powerful, but to achieve a very low CPU overhead, the API and runtime do very little to help you out. This exposes the memory model of the driver and makes the GPU/CPU synchronization a manual process that's a bit akin to 'lock-free programming' on the CPU.

If you are entirely new to Direct3D, I strongly suggest you start with DirectX Tool Kit and its tutorials using Direct3D 11. Once you've mastered that, you should be in a good place to move to Direct3D 12 when it makes sense for your applications.

There's a ton of tutorials, samples, books, and other educational material on Direct3D 11. The Direct3D 12 material is a bit thin, mainly consisting of the content on the DirectX-Graphics-Samples GitHub repo. I'm currently working on adding DirectX 12 support to DirectX Tool Kit, but even when it is available you'll find that starting with Direct3D 11 is a lot easier than trying to jump feet-first into DirectX 12.

The other thing to keep in mind w.r.t. to DirectX 12: It is supported only on Windows 10 systems with DirectX 12 enabled video drivers. This includes most Direct3D Feature Level 11.0+ hardware including NVIDIA Fermi, Kepler, Maxwell; AMD GCN; and Intel's Haswell, Broadwell, and Skylake. This, however, does not include any older video cards. See DirectX 12: A Major Stride for Gaming, AMD DirectX 12 Technology, and DirectX Developer Blog

UPDATE: DirectX Tool Kit for DirectX 12 is now available including basic tutorials. You should focus on learning Direct3D 11 before tackling Direct3D 12. DirectX 12 is an API designed for graphics experts and is quite unforgiving to newbies. DirectX Tool Kit helps soften the edges a little, but not much. Generally speaking, unless you are hitting the CPU performance limits of Direct3D 11 there's no need to use Direct3D 12. That said, for graphics experts it's worth learning to have a better understanding of how the underlying GPU hardware works, or those wanting to push the hardware to the limits of performance.

UPDATE 2: I should mention that based on some recent experience, if you mainly use the functionality provided in the DirectX Tool Kit (sprites, spritefont, basic primitives and models, etc.), switching from the DirectX 11 to DirectX 12 version is fairly straight-forward. Also, if you want to use DirectX Raytracing, DirectML, or Shader Model 6, you need to use DirectX 12 instead of DirectX 11. Of course, most game developers actually use existing 3rd party engines like Unity or Unreal Engine which abstract the API so it's more an issue of your target platform instead of usability for those cases.

How do you draw text in DirectX 12?

The general answer to questions like this is "if you have to ask, then you probably should be using DirectX 11." DirectX 12 is a graphics expert API that provide immense control, and is not particularly concerned with ease-of-use for novices. See this thread for more thoughts in this vein.

With that out of the way, one option is to use device interop and Direct2D/DirectWrite. See Working with Direct3D 11, Direct3D 10 and Direct2D.

UPDATE: DirectX Tool Kit for DirectX 12 is now available. It includes a SpriteFont / SpriteBatch implementation that will draw text on Direct3D 12 render targets. See this tutorial.

DirectX 11 on Windows 10

All the various books on Direct3D 11 are still applicable in their coverage of the core API, the concepts, and functionality of how to use DirectX 11. The problems come in due to their use of the now legacy DirectX SDK. Notably D3DX, D3DXMath or XNAMath, and use of the legacy Effects system. That said, you still end up learning how to do Direct3D graphics programming. I've got a blog post that goes into some detail on the various books with some notes of things to watch out for. See Book Recommendations. Note to self: I should take a look at the Sherrod & Jones book and update the post.

See Where is the DirectX SDK (2015 Edition)? and in particular MSDN on the proper method for 'mixing' the Windows 8.1/10 SDK with the legacy DirectX SDK if you still want to use the older stuff for learning.

A complete guide to how to replace all the legacy DirectX SDK stuff when using the Windows 8.1 SDK or Windows 10 SDK is Living Without D3DX. You'll note for the shader compilation API, it links to HLSL, FXC, and D3DCompile. As someone noted in the comments, CompileD3DShader is just some helper function provided by the book author. These days you can just call D3DCompileFromFile. I'm also using Microsoft::WRL::ComPtr which is a good smart-pointer to make use of with modern Direct3D C++ programming.

#include <d3d11.h>
#include <d3dcompiler.h>
#include <wrl/client.h>

using Microsoft::WRL::ComPtr;

...

ComPtr<ID3DBlob> shaderBlob;
ComPtr<ID3DBlob> errorBlob;
HRESULT hr = D3DCompileFromFile( L"SolidGreenColor.fx",
nullptr,
D3D_COMPILE_STANDARD_FILE_INCLUDE,
"VS_Main", "vs_4_0",
0 /* You probably want to use D3DCOMPILE_DEBUG in debug builds */,
0,
shaderBlob.GetAddressOf(),
errorMsg.GetAddressOf()));

#ifdef _DEBUG
if (errorBlob)
{
OutputDebugStringA( reinterpret_cast<const char*>( errorBlob->GetBufferPointer() ) );
}
#endif

if (FAILED(hr))
// Error condition

Other useful starting resources for learning Direct3D 11:

DirectX Tool Kit tutorials

Getting Started with Direct3D 11

Anatomy of Direct3D 11 Create Device



Related Topics



Leave a reply



Submit