-
Notifications
You must be signed in to change notification settings - Fork 433
Implementation
Be sure to read the Implementation page for DirectX Tool Kit for DirectX 11 as those topics also apply to DirectX Tool Kit for DirectX 12:
- Naming conventions
- The pImpl idiom
- Calling-conventions
- Default constructors/assignment operators
- DirectXMath Parameter Conventions
The DirectX Toolkit library makes extensive use of SAL2 annotations (_In_
, _Outptr_opt_
, etc.) which greatly improves the accuracy of the Visual C++ static code analysis (also known as PREFAST). The standard Windows headers #define
them all to empty strings if not building with /analyze
, so they have no effect on code-generation.
The main thing to note about Direct3D 12 is that the types D3D12_GPU_DESCRIPTOR_HANDLE
and D3D12_CPU_DESCRIPTOR_HANDLE
are actually implemented as structs, so SAL pointer-style annotation doesn't apply to them (_In_
, _In_opt_
, etc.).
Rather than trying to share a single root signature across all shaders in the DirectX Tool Kit, the IEffect::Apply
will call both SetGraphicsRootSignature
and SetPipelineState
as well as other required parameters. The overhead of resetting the root signature is minimal for the greatly improved usability and maintainability of the library.
Another design decision here is to use distinct SetGraphicsRootDescriptorTable
entries for each texture and sampler descriptor. While the Direct3D 12 root signature allows you to create ranges for the tables, it means that all such descriptors must be continuous in the heap. Rather than impose this requirement on the application-level API, we use multiple tables.
All shaders have HLSL-described root signatures. While this isn't strictly for PCs since the driver already has to compile the IL into vendor-specific microcode so it can accommodate changes to the root signature, this is a significant performance hit on Xbox One XDK apps.
When creating root signatures you have the choice of using static samplers built into the signature, or you must provide a sampler descriptor and set the sampler heap at render time. For SpriteBatch
we support both a static-sampler mode and a sampler heap descriptor mode for ease of use, and the fact that this feature only added a couple of shader combinations. For Effects generally, we require sampler heap descriptors which must be set in addition to the texture heap descriptor to render.
Dual-use Coding Techniques for Games
C++ Core Guidelines
DirectX Developer Blog
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