DirectX - CreateDeviceAndSwapChain returns E_INVALIDARG

DirectX - CreateDeviceAndSwapChain returns E_INVALIDARG

我正在尝试用 C++ 初始化 Direct3D11。在安装了 Visual Studio 的机器上(所有这些都在 Windows 10 上 运行ning),它 运行 没问题。 在其他计算机上(未安装 Visual studio,Windows 10 和 7)它 returns E_INVALIDARG。

标志 P_FeatureLevelsSupported 在这些计算机上表示 0。我的上面写着 D3D_FEATURE_LEVEL_11_1。 所以我想这与 DirectX 安装有关,或者可能是因为缺少 SDK(但这不会很奇怪吗?:D)

通过 运行ning dxdiag,我知道那些机器支持 DirectX11_0。

我需要安装什么吗? 该软件必须 运行 在我们客户的 PC 上。

导致错误的代码:

const 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,
}; 
D3D_FEATURE_LEVEL  P_FeatureLevelsSupported;


//see microsoft documentation, we use 11_1 or 11_0 if 11_1 is not supported by the client machine
//https://docs.microsoft.com/en-us/windows/desktop/direct3d11/overviews-direct3d-11-devices-initialize
result  = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, lvl, _countof(lvl), D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &P_FeatureLevelsSupported, &deviceContext);
if(result == E_INVALIDARG) //check with FEATURE_LEVEL_11_0
      D3D11CreateDeviceAndSwapChain(NULL, 
                              D3D_DRIVER_TYPE_HARDWARE, 
                              NULL,
                              D3D11_CREATE_DEVICE_DEBUG, 
                              &lvl[1],
                              _countof(lvl) - 1,
                              D3D11_SDK_VERSION,
                              &swapChainDesc, 
                              &swapChain, 
                              &device,
                              &P_FeatureLevelsSupported, 
                              &deviceContext);

提前致谢:)

您要求通过传入 D3D11_CREATE_DEVICE_DEBUG 创建 调试 设备。要成功,您必须安装 D3D11*SDKLayers.dll,您的开发机器上可能已经安装了它。有关详细信息,请参阅 here,其中包括:

Debug Layer The debug layer provides extensive additional parameter and consistency validation (such as validating shader linkage and resource binding, validating parameter consistency, and reporting error descriptions).

To create a device that supports the debug layer, you must install the DirectX SDK (to get D3D11SDKLayers.dll), and then specify the D3D11_CREATE_DEVICE_DEBUG flag when calling the D3D11CreateDevice function or the D3D11CreateDeviceAndSwapChain function. If you run your application with the debug layer enabled, the application will be substantially slower. But, to ensure that your application is clean of errors and warnings before you ship it, use the debug layer. For more info, see Using the debug layer to debug apps.

Note

For Windows 8, to create a device that supports the debug layer, install the Windows Software Development Kit (SDK) for Windows 8 to get D3D11_1SDKLayers.dll.

如果您在客户机器上不需要调试设备,只需删除该标志。