gpt4 book ai didi

c++ - DirectX - CreateDeviceAndSwapChain 返回 E_INVALIDARG

转载 作者:行者123 更新时间:2023-11-28 01:27:13 24 4
gpt4 key购买 nike

我正在尝试用 C++ 初始化 Direct3D11。在安装了 Visual Studio 的机器上(所有这些都在 Windows 10 上运行),它运行良好。在其他计算机(未安装 Visual Studio、Windows 10 和 7)上,它返回 E_INVALIDARG。

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

通过运行 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://learn.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.

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

关于c++ - DirectX - CreateDeviceAndSwapChain 返回 E_INVALIDARG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53208725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com