如何判断系统DirectX是11还是11.1?

How to determine the system DirectX is 11 or 11.1?

我是运行ning Windows 7.我用DxDiag的时候显示版本是11.

当我使用 Visual Studio 2012 可以访问 Windows API 时,它可以 运行 具有 D3D_FEATURE_LEVEL_11_1

功能级别的代码

所以我很困惑,我的 DirectX 版本的确切版本是什么?

DirectX 功能级别

https://msdn.microsoft.com/en-us/library/windows/desktop/ff476876%28v=vs.85%29.aspx

A feature level is a well defined set of GPU functionality.

您的 DirectX 版本是 11,但根据您的硬件 (GPU),您可能会获得功能级别 11_1。如果您街边的朋友有 Windows 8.1 和支持的显卡,他们可能有 11.2 功能。

尽管听起来,您至少可以使用一些 11.1 功能。

https://walbourn.github.io/directx-11-1-and-windows-7-update/ (http://blogs.msdn.com/b/chuckw/archive/2013/02/26/directx-11-1-and-windows-7-update.aspx)

DXDIAG: Even after applying KB 2670838 to Windows 7 SP1, DXDIAG will still report it as "DirectX 11".

如有疑问,我建议依赖从 CreateDevice(等)返回的功能级别是正确的。

这里有许多混杂因素在起作用,所以让我们一次只考虑一个:

  1. DXDIAG 是 OS 和 DirectX 运行时的一部分,但也针对该字符串手动更新,因此它通常小于 detailed/accurate 报告“DirectX”版本。对于 Windows Vista SP1,它不会说“DirectX 10.1”,而是说“DirectX 10”。同样,Windows 8 和 Windows 7 SP 1 + KB2670838 installed it still says "DirectX 11" and not "DirectX 11.1". On Windows 8.1 it still says "DirectX 11" and not "DirectX 11.2". In short, DXDIAG is not your best option for technical details like this. You could try using the latest version of dxcapsviewer 在 Windows 8.1 SDK 中,它在检查事物的方式上更复杂一些,但仍然需要手动随着时间的推移不断更新,因此它目前没有提及 Windows 10 种功能,例如 DX 11.3 或 DX 12。
  2. 如果您将 pFeatureLevels 的 NULL 传递给 D3DCreateDevice,即使在 Windows 8.x 上,您仍然不会得到 D3D_FEATURE_LEVEL_11_1。这是出于向后兼容的原因,并确保在 NULL 使您达到 9.1 - 11.0 时行为不会改变。您必须手动列出数组中的 11.1 值才能获取它——假设系统+驱动程序组合实际上支持它。请注意,如果您确实在数组中包含 11.1,则在 Windows Vista SP2、Windows 7 RTM 或没有 KB2670838 的 Windows 7 SP1 上,调用将失败并显示 E_INVALIDARG
  3. Windows 7 SP1 + KB2670838 提供 DirectX 11.1 API,但不支持 D3D_FEATURE_LEVEL_11_1 或任何新的可选硬件功能,因为它不支持新的 WDDM 1.2 驱动程序模型。您必须使用 Windows 8 或更高版本才能通过 WDDM 1.2 驱动程序和适当的硬件获得 D3D_FEATURE_LEVEL_11_1。参见 Microsoft Docs

一般来说,Windows 桌面应用程序处理所有这些问题的正确方法是:

D3D_FEATURE_LEVEL lvl[] = {
   D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
   D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
   D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1
};

DWORD createDeviceFlags = 0;
#ifdef _DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif

ID3D11Device* pDevice = nullptr;
ID3D11DeviceContext* pContext = nullptr;
D3D_FEATURE_LEVEL fl;
HRESULT hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
    createDeviceFlags, lvl, _countof(lvl),
     D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
if ( hr == E_INVALIDARG )
{
    hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
         createDeviceFlags, &lvl[1], _countof(lvl)-1,
         D3D11_SDK_VERSION, &pDevice, &fl, &pContext );
}
if (FAILED(hr))
   ...

然后检测对Direct3D 11.1的支持,看能不能获取到Direct3D 11.1的接口:

ID3D11Device1* pDevice1 = nullptr;
ID3D11DeviceContext1* pContext1 = nullptr;
hr = pDevice->QueryInterface( __uuidof( ID3D11Device1 ),
    reinterpret_cast<void**>( &pDevice1 ) );
if ( SUCCEEDED(hr) )
{
    // DirectX 11.1 is present, otherwise only DirectX 11.0
    (void)pContext->QueryInterface( __uuidof( ID3D11DeviceContext1 ),
         reinterpret_cast<void**>( &pContext1 ) );
}

不要根据 Direct3D Feature Level 安装的 DirectX 版本做出假设,反之亦然。

  • Windows 8 个商店应用程序可以假定存在 DirectX 11.1,但不能假定任何特定的 Direct3D 功能级别(尽管 9.1 是您所见过的最低级别)。
  • Windows 8.1 商店应用程序可以假定 DirectX 11.2 存在,但同样不能假定任何关于 Direct3D 功能级别的信息。
  • Windows phone 8.0 应用程序可以假定存在 DirectX 11.0,并且设备仅支持 9.3。
  • Windows phone 8.1 应用程序可以假定存在 DirectX 11.1,并且设备仅支持 9.3。
  • Xbox One 应用程序可以假定存在 DirectX 11.1。独家应用程序可以假设 FL 11.1 存在。共享应用程序必须使用 FL 10.0。

有关设备创建和 DirectX 11.x 版本检测的各种细微差别的详细信息,请参阅 this post

有关 Windows 7 上 DirectX 11.1 的重要说明,请参阅 this post and this one

如前所述:运行 dxdiag -> 进入显示 -> 检查驱动程序型号。如果你有 WDDM 1.3 而不是 DirectX 11.2 安装在你的系统中,如果你有 WDDM 1.2 而不是你有 DirectX 11.1。