未定义的标识符 - 缺少哪些 header 个文件? - DX12

Undefined identifiers - which header files are missing? - DX12

我正在尝试使用新的 DX12 API,我已经从 Microsoft 文档中找到并复制了一些有关它的代码,但是在复制代码之后,许多功能仍然无法识别。

我一直在详细搜索文档,但找不到合适的 headers。 Headers 我包含的内容如下:

#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"

未识别的函数和属性是: ThrowIfFailed、GetHardwareAdapter、Win32Application 命名空间和 GetAssetFullPath

这些函数 'helpers' 包含在各种入门模板和示例中,但不是 Windows SDK 中实际 Windows API 的一部分。特别是,您将在 Win32 桌面的官方 DirectX 12 示例 GitHub 的示例中看到它们。

  • ThrowIfFailed 是一个简单的“如果 COM returned 失败,则抛出 C++ 异常”助手。这是因为您应该始终检查任何 returns HRESULT 而不是 void 的 COM 函数的 return 值,但大多数时候在 'working' 程序中许多地方来自 Direct3D 的任何故障代码都是 'fast-fatal' 错误。 'official' DX12 桌面示例在 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 中对其进行了定义以获取更多详细信息。

  • GetHardwareAdapter是另一个帮手。当您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了解有关创建 DirectX 12 设备的更多详细信息时。

  • Win32Application 命名空间只是一个非常简单的 WndProc 和 window 助手。你可以在这里看到实现 cpp / h

  • GetAssetFullPath 是另一个帮手,但这个更具体到 'official' DirectX 12 样本。它基本上处理了这样一个事实,即在 Visual Studio 中进行开发时,'current working directory' 通常是项目文件夹,但是 Visual Studio 构建的各种着色器 blob(cso 文件)是在 DebugRelease 等中的 EXE 旁边找到。您可以在 here.[=34= 中找到它]

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.

另一个常见问题是各种 D3DX12* 辅助函数也 不是 Windows SDK 的一部分。相反,您将 D3DX12.H 作为 DirectX 项目模板的一部分或从 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.

有关一些一般提示,请参阅 this blog post and DirectX Tool Kit for DX12

If you are really new to DirectX, you should seriously consider working with DirectX 11 before tackling DirectX 12.