-
Notifications
You must be signed in to change notification settings - Fork 411
Getting Started
This is the Getting Started tutorial for DirectX Tool Kit which introduces the reader to using the DirectX Tool Kit with DirectX 12 in C++. This takes the form of a series of tutorial lessons for introducing the various functional parts of the tool kit. If you are just looking for basic integration instructions, see Adding to a VS solution.
If you are new to DirectX, the place to start is the DirectX Tool Kit for DirectX 11 tutorials. DirectX 12 is an expert API which builds on knowing the ins & outs of DirectX 11. DirectX 12 is an extremely low-level API designed for graphic experts who have a solid understanding of the architecture of modern GPU hardware. Both DirectX 11 and DirectX 12 provide access to the same core hardware features on Windows 10 / Windows 11, but drive the hardware in different ways which can allow a well-optimized DirectX 12 engine to achieve much lower CPU overhead than in DirectX 11.
That said, if you already know the DirectX 11 version of DirectX Tool Kit, you'll find the DirectX 12 version familiar and will have an easier time with the transition.
DirectX 12 is also required to take advantage of Shader Model 6, DirectX Raytracing, Amplification & Mesh Shaders, or other DirectX 12 Ultimate hardware features.
This tutorial assumes the reader is familiar with the basics of C++ programming using Microsoft Visual C++, including writing code, building applications, and basic debugging. Coding conventions here will make use of C++11 language features such as nullptr
, auto
, ranged-based for
loops, simple lambdas (aka anonymous functions), the standard smart-pointer std::unique_ptr
/ std::make_unique<T>()
, and std::function<>
.There is also one class that requires basic use of std::future
. Familiarity with the Standard C++ Library std::wstring
and the std::vector
container are required as well.
- Welcome back to C++ - Modern C++
- C++ Language and Standard Libraries
- Tools for Visual C++ Development
- Smart Pointers
- ComPtr
If you are more comfortable with C#, then you should consider SharpDX and read this blog post.
The tutorial assumes the reader is already familiar with the DirectX 12 API, and is an expert in graphics programming. If you are already an expert in Direct3D 11 but are new to the DirectX 12 API, then you should start by reviewing the Direct3D 12 Programming Guide on Microsoft Docs.
- Getting Started with Direct3D 12
- Porting from Direct3D 11 to Direct3D 12
- DirectX 12: DirectX 11 to DirectX 12 porting guide (YouTube video)
Note that Direct3D 12 and DirectX Tool Kit are not Windows Runtime (aka "WinRT") components, so we do not make use of the C++/CX language extensions (a.k.a.
/ZW
switch) or C++/WinRT language projections, although it is compatible with both of those programming models. DirectX Tool Kit is a 'pure' C++ library, which is why it's not directly usable by Visual Basic, C# or HTML+JavaScript applications.
One thing that many C++ developers, particularly game developers, may not be all that familiar with is "C++ Exception Handling". This is distinct from "Structured Exception Handling" (SEH) which some developers have seen in the past, and can leave an unfavorable impression of C++ EH. On both ARM and x64 native platforms, C++ EH is very efficient, although the x86 32-bit implementation does have some quirks. In any case, DirectX Tool Kit uses C++ Exception Handling for most error conditions, just as the Standard Template Library (STL) does and the standard behavior of the operator new
.
For debugging exceptions thrown by the DirectX Tool Kit, you should enable the checkbox next to std::exception
in the Visual Studio Exception Settings dialog (Debug -> Windows -> Exception Settings). It's not on by default. Then select the "C++ Exceptions" line, right-click and select the + button, and type DirectX::com_exception
to add that one. If working with the Direct3D VS Game templates you should do this once more typing DX::com_exception
.
For some more detail on how the Visual Studio debugger deals with exceptions, read this blog post.
These tutorials are written with game development in mind as the target application since games are an excellent fit for the 'immersive DirectX app' model. DirectX 12 can also be used for non-game applications. The reader is assumed to be familiar with Direct3D programming and have a basic understanding of the DirectX 12 API.
The DirectX Tool Kit for DirectX 12 tutorials assume you are using Windows 10 or Windows 11. You also need a graphics card with DirectX 12 capable drivers. The DirectX Tool Kit only requires the D3D_FEATURE_LEVEL_11_0
Direct3D hardware feature level with Shader Model 6 support.
While a version of DirectX 12 is available for Windows 7 SP1 along with a down-level XAudio 2.9, this is not a good development environment for DirectX 12 applications. Tools like PIX, the debug layer, etc. are only available on Windows 10 / Windows 11, which you should use for development even if planning to utilize the Windows 7 support.
For more information on Windows 7 support, see GitHub. Note that there is no support for DirectX 12 on Windows 8.x.
For learning purposes, these instructions are going to focus on the following setup:
- Visual Studio 2019 (16.11) or Visual Studio 2022 Community, Professional, Premium, or Ultimate
- Windows 10 SDK (19041 is the minimum supported version)
- Windows 10 (May 2020 Update a.k.a. Version 2004 is recommended) or Windows 11
We will be using a Win32 desktop application project template, but all these techniques and APIs apply to Universal Windows Platform (UWP) apps and Xbox as well.
There is no need to install the legacy DirectX SDK to use DirectX Tool Kit. The DirectX SDK is deprecated, and has no DirectX 12 material. Since the DirectX Tool Kit for DirectX 12 projects are built with
_WIN32_WINNT
set to0x0A00
, DirectX Tool Kit for Audio will make use of XAudio 2.9 which is included with Windows 10 / Windows 11 and the Windows SDK. There is also no need to use theDXSDK_DIR
environment variable. This was only used by the legacy DirectX SDK and by an early DirectX 12 SDK Beta. The DirectX 12 headers & libraries are part of the standard Windows SDK.
When using the new lightweight installer be sure to select the appropriate workloads. Here are the recommended options to select:
- Workload: Game development with C++ or Desktop development with C++
For UWP apps, include:
- Workload: Universal Windows Platform development
- Optional component: C++ Universal Windows Platform tools
The D3DX12.H
utility header is not part of the Windows SDK, nor is it a part of the DirectX Tool Kit. It's commonly used in DirectX 12 C++ programming, and is included as part of a number of templates including the Direct3D Game Visual Studio templates used for this tutorial. It's not actually required for DirectX 12 development, but it does contain useful helper code. You can obtain the latest version of this utility header from GitHub. See the wiki for more details.
Note that for Xbox development,
D3DX12_X.H
andD3DX12_XS.H
are in the Xbox One XDK / Microsoft GDKX.
For a quick introduction to DirectX 12 programming, take a look at the Introductory Graphics samples on Xbox-ATG-Samples. For the Microsoft GDK, these samples are available on Xbox-GDK-Samples.
- Basic drawing: SimpleTriangle12
- Basic texturing: SimpleTexture12
- Basic lighting: SimpleLighting12
- DirectCompute: SimpleCompute12
- Tessellation: SimpleBezier12
- Instancing: SimpleInstancing12
- Multisample Antialiasing: SimpleMSAA12
The official samples for DirectX 12 are available on GitHub.
- Sprites and textures
- Drawing text
- Simple rendering
- Line drawing and anti-aliasing
- 3D shapes
- Rendering a model
- Animating using model bones
- Using skinned models
- Using advanced shaders
- Multistream rendering and instancing
- Writing custom shaders
- Authoring an Effect
- Using HDR rendering
- Physically-based rendering
For materials on using DirectX Tool Kit's Input, Math, and Audio support, see the DirectX Tool Kit for DirectX 11 tutorials as all those types and classes are identical.
Dual-use Coding Techniques for Games
C++ Core Guidelines
Luna, Introduction to 3D Game Programming with DirectX 12, Mercury Learning & Information (March 24, 2016)
Meyers, Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14, O'Reilly Media (November 2014)
Varcholik, Real-Time 3D Rendering with DirectX and HLSL: A Practical Guide to Graphics Programming, Addison-Wesley (May 31, 2014)
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Xbox One
- Xbox Series X|S
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20