Those functions are 'helpers' included in various starter templates and samples, but are not part of the actual Windows APIs in the Windows SDK. In particular, you will see them in the samples from the official DirectX 12 Samples GitHub for Win32 desktop.
ThrowIfFailed
is a simple "if COM returned a failure, throw a C++ exception" helper. This is because you should always check the return value of any COM function that returns HRESULT
instead of void
, but in 'working' programs most of the time any failure code from Direct3D in many places is a 'fast-fatal' error. The 'official' desktop samples for DX12 define it in DXSampleHelper.h, but many other templates put it into the pch.h
precompiled header to make sure it's defined globally. See this wiki page for more details.
GetHardwareAdapter
is another helper. When you create a DirectX 11 device on any modern versions of Windows, you can pretty safely assume there's some Direct3D adapter there depending on your minimum Direct3D Hardware Feature level. With DirectX 12, you really need to check as it's quite possible that you have both a DX11 and a DX12 capable device on your system. See this blog post for more details on creating a DirectX 12 device.
The Win32Application
namespace is just a really simple WndProc and window helper. You can see the implementation here cpp / h
GetAssetFullPath
is another helper, but this one is more specific to the 'official' DirectX 12 samples. It basically deals with the fact that when doing development in Visual Studio, the 'current working directory' is typically the project folder, but the various shader blobs (cso
files) built by Visual Studio are found next to the EXE
in Debug, Release, etc. You can find it here.
This is a 'quirk' of Win32 desktop development since there's no standard packaging/setup/deployment system. For UWP and Xbox One development, the packaging typically places the EXE
and CSO
files next to each other along with other assets, and the Current Working Directory is set to the root of the 'package' at runtime.
Personally, I deal with the same issue slightly differently in my ReadData helper.
Another common issue is that the various D3DX12*
helper functions are also not part of the Windows SDK. Instead you get D3DX12.H
as part of a DirectX project template or from GitHub. The documentation is on Microsoft Docs.
I have a set of DirectX basic templates for Visual C++ hosted on GitHub you might want to look at. They include the DeviceResources module for handling your basic DirectX device when you are just getting started, the StepTimer helper, as well as D3DX12.h
.
See this blog post and DirectX Tool Kit for DX12 for some general tips.
If you are really new to DirectX, you should seriously consider working with DirectX 11 before tackling DirectX 12.
collection.h
header is specific to Windows Runtime C++/CX extensions and UWP , so you shouldn't be using it in a Win32 desktop app generally speaking. Also: Die,tchar.h
! Die! See UTF-8 Everywhere.