DirectXHelpers (original) (raw)

DirectXTK

Contains various C++ utilities that simplify Direct3D 12 programming.

Direct3D 12 "core" helpers

The d3dx12.h header provides a number of helper classes intended to simplify the usage of the API when working with C++. These are all in the global C++ namespace, and are documented on Microsoft Docs.

Note that d3dx12.h is not included in the Windows SDK, nor is it a part of the DirectX Tool Kit. It is included in the DirectX project templates built into Visual Studio and in the Direct3D Game VS Templates. You can find the latest version on GitHub.

For Xbox One development d3dx12_x.h is included in the Xbox One XDK / Microsoft GDKX; for Xbox Series X|S development you use d3dx12_xs.h.

D3DX12 State Object Creation Helpers

If you define D3DX12_NO_STATE_OBJECT_HELPERS before including d3dx12.h you prevent the definition of these types which require the use of Standard C++ Library.

Checking Feature Support in Direct3D 12

The latest version of d3dx12.h includes CD3DX12FeatureSupport. See this blog post for details.

If you define D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS before including d3dx12.h you prevent the definition of this class which require the use of Standard C++ Library.

Resource barrier helpers

The DirectXHelpers.h header includes the following helpers in the DirectX namespace:

For more information, see Resource Barriers.

View helpers

Misc helpers

Debug object naming

To help track down resource leaks, the Direct3D 12 debug layer allows you to provide debug names to Direct3D 12 objects. The SetDebugObjectName template simplifies this for static debug name strings.

DX::ThrowIfFailed( device->CreateComputePipelineState(&desc, IID_PPV_ARGS(m_pipelineState.GetAddressOf())) );

SetDebugObjectName(m_pipelineState.Get(), L"FancyEffectPSO");

PIX events

The Windows SDK header pix.h defines various standard PIX events for use with Visual Studio Graphics Diagnostics. This header has been deprecated for DirectX 12. For Direct3D 12 on Windows, you should use the latest version of PIX, #include <pix3.h> instead of pix.h, and add the WinPixEventRuntime NuGet package to your project.

The DirectXHelpers.h header provides a ScopedPixEvent class if either pix.h or pix3.h is included before DirectXHelpers.h.

#include <pix3.h>

#include "DirectXHelpers.h"

Xbox-specific

A number of DirectX APIs use the COM parameter pattern of (..., REFIID riid, LPVOID *ppv). In these cases, the IID_PPV_ARGS macro is often employed such as the following:

using Microsoft::WRL::ComPtr;

ComPtr pso;

DX::ThrowIfFailed( device->CreateComputePipelineState(&desc, IID_PPV_ARGS(&pso)) );

The IID_PPV_ARGS macro works on any type that's derived from IUnknown.

For Xbox One XDK / Microsoft GDKX development, however, the Direct3D 12.X Runtime variant does not make use of the standard IUnknown interface (this is referred to as the 'monolithic' runtime vs. the Windows-style 'stock' runtime). This provides significant software optimizations for the fixed-hardware nature of the console, and generally is client-code compatible. The one exception is that this breaks IID_PPV_ARGS. Therefore, the Direct3D 12.X headers include a IID_GRAPHICS_PPV_ARGS macro which works on the variant DirectX APIs in the same way.

In order to simplify coding that is portable to both 'stock' PC and 'monolithic' Xbox, all usage of IID_PPV_ARGS within the library is replaced with IID_GRAPHICS_PPV_ARGS for graphics APIs. The DirectXHelpers.h provides a simple macro that maps IID_GRAPHICS_PPV_ARGS to IID_PPV_ARGS for non-Xbox platforms. This helper is available for client code as well.

#include "DirectXHelpers.h"

using Microsoft::WRL::ComPtr;

ComPtr pso;

DX::ThrowIfFailed( device->CreateComputePipelineState(&desc, IID_GRAPHICS_PPV_ARGS(&pso)) );

Note that IID_PPV_ARGS is still used on Xbox for COM APIs like the Windows Imaging Component (WIC).