我可以将 IDXGIFactory2::CreateSwapChainForHwnd 用于 directx 11.0

Can I use IDXGIFactory2::CreateSwapChainForHwnd for directx 11.0

据我所知,IDXGIFactory2::CreateSwapChainForHwnd 已添加到 DXGI 1.2 API 中,因此如果方法 D3D11CreateDevice return pFeatureLevel 等于 D3D_FEATURE_LEVEL_11_0 我们只能使用 DXGI 1.1 API,因此我们应该调用 IDXGIFactory::CreateSwapChain 而不是 IDXGIFactory2::CreateSwapChainForHwnd。我说的对吗?

    HRESULT D3D11CreateDevice(
  [in, optional]  IDXGIAdapter            *pAdapter,
                  D3D_DRIVER_TYPE         DriverType,
                  HMODULE                 Software,
                  UINT                    Flags,
  [in, optional]  const D3D_FEATURE_LEVEL *pFeatureLevels,
                  UINT                    FeatureLevels,
                  UINT                    SDKVersion,
  [out, optional] ID3D11Device            **ppDevice,
  [out, optional] D3D_FEATURE_LEVEL       *pFeatureLevel,
  [out, optional] ID3D11DeviceContext     **ppImmediateContex

我的猜测是您的客户是 运行 Windows 7,并且缺少由 KB2670838 update.

安装的 DirectX 11.1 运行时

参见 Microsoft Docs, as well as this blog post and this follow-up post

最好只告诉客户您需要 KB 2670838,如果他们正在使用 Windows 7. 支持 DirectX 11.0 运行时当然是可能的,但是有很多问题,您必须使用 DXGI 1.1交换链的接口。参见 this blog post

如果客户有 Internet 访问问题,Microsoft Download 也可以从 Microsoft Download 获得 KB 2670838 作为 MSU 文件。

You should recheck the error handling of your application. You should have gotten an error HRESULT when you tried to QueryInterface the IDXGIFactory2 interface if the system only had DirectX 11.0 on it. Remember if a function returns HRESULT, it's not safe to ignore the return value: Use FAILED or SUCCEEDED or a fast-fail like ThrowIfFailed to make sure you hit the failure when it happens and not sometime later.

现在如果支持Windows 7,最好需要Windows 7 Service Pack 1。例如,最近几个版本的Visual C++ 只支持Windows 7 SP1。也就是说,KB2670838 包含在 Service Pack 1 程序包中。它作为推荐更新通过 Windows 更新推出,但如果您关闭了 WU 或者创建了 Windows 7 SP1 的全新安装,您可能会错过它。请注意,KB2670838 在任何情况下都不支持 Windows 7 RTM。

Don't use 'Direct3D Hardware Feature Level' to infer the supported DirectX APIs. It's best to just QueryInterface for the ID3D11Device1 if you want to check after creating the ID3D11Device to see if DirectX 11.1 is present, but a more direct test is to try to QUeryInterface the IDXGIFactory2 interface.