1

I am trying to play with the new DX12 API and I have found and copied some code from the Microsoft Documentations regarding it but after copying the code many functions are still being unidentified.

I have been searching the documentations in detail but I am unable to find the right headers for them. Headers that I have included are the following:

#include "targetver.h"
#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from 
#include "windows.h"
// C RunTime Header Files
#include "stdlib.h"
#include "malloc.h"
#include "memory.h"
#include "tchar.h"
//for wstrings
#include "locale"
//for Microsoft namespace
#include "collection.h"
//for SwapChain3
#include "dxgi1_4.h"
#include "D3DX12.h"
#include "D3d12.h"
#include "directxmath.h"
#include "D3DCompiler.h"

The unidentified functions and properties are: ThrowIfFailed, GetHardwareAdapter, Win32Application namespace and GetAssetFullPath

4

1 Answer 1

2

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.

1
  • Thank you very much for your help! I am new to DirectX 12, but I have been studying DIrectX 11 and I was asking for a hard project for my final year because I want my degree to actually have an impact. I know it's going to be a big task but I am up for it. Thank you once again, I really appreciate your time and shared knowledge!
    – RoWh0906
    Aug 25, 2019 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.