D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT可以和D3D_FEATURE_LEVEL_11_0一起传吗?

Can D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT be passed with D3D_FEATURE_LEVEL_11_0?

MSDN on D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT 说:

Direct3D 11: This value is not supported until Direct3D 11.1.

这是指运行时版本还是功能级别?

我可以将标志传递给 D3D11CreateDevice 但只传递功能级别 11_0 吗?

功能级别是无关紧要的,它只取决于安装的运行时版本吗?如果我将标志传递给 DX 运行时 11.0,会发生什么情况?会不会被默默无视?或者我是否首先必须以某种方式检测 DX 运行时版本,然后仅当 DX 运行时版本至少为 11.1 时才传递标志?

这是关于运行时版本,因此您至少需要 Windows 8 才能启用此功能。

您可以在拥有此标志的情况下请求功能级别 11 的唯一设备,刚刚尝试过并且效果很好。

否则会有问题,因为 NVidia 卡从 900x 代开始才支持 11.1。

指运行时版本

您可能会检测到 OS 版本,但通过检查已安装的 DirectX 运行时 .dll 版本可能会更容易,方法是尝试 LoadLibrary on:

{ 
    "d3d11.dll",
    "d3d11_1.dll",
    "d3d11.dll",
    "d3d11_1sdklayers.dll",
    "d3d11_2sdklayers.dll",
    "d3d11_3sdklayers.dll",
    "d3d12.dll"
}

依次执行直到失败 (returns NULL)。或者反过来,直到成功。这与创建具有最高功能级别的设备相同。

确定您是否拥有 Direct3D 11.1 运行时的 'correct' 方法如下:

#include <d3d11_1.h>
#include <wrl/client.h>

#pragma comment(lib,"d3d11.lib")

bool IsDirect3D11_1OrGreater()
{
    Microsoft::WRL::ComPtr<ID3D11Device> device;

    HRESULT hr = D3D11CreateDevice(
        nullptr,
        D3D_DRIVER_TYPE_NULL,
        nullptr,
        0,
        nullptr,
        0,
        D3D11_SDK_VERSION,
        device.GetAddressOf(),
        nullptr,
        nullptr
        );

    if (FAILED(hr))
        return false;

    Microsoft::WRL::ComPtr<ID3D11Device1> device1;
    return SUCCEEDED(device.As(&device1));
}

然后您调用 IsDirect3D11_1OrGreater。如果它是真的,那么您可以安全地使用像 D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT 这样需要 Direct3D 11.1 Runtime

的标志

Keep in mind that you shouldn't be using D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT as a matter of course. It really only should be used for DirectCompute-heavy programs that are free to tie up the GPU a lot and potentially cause the system to become unresponsive to UI. Use it with caution.

That also implies your application will require a Direct3D Feature Level 11.0 or greater card to use DirectCompute 5.0 -or- it will require Direct3D Feature Level 10.0 and need to do a CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, ...) call and verify D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x is true for DirectCompute 4.0.

如果IsDirect3D11_1OrGreater returns为假,那么你应该告诉用户:

This application requires the DirectX 11.1 Runtime. It is supported on
Windows 7 Service Pack 1 with KB2670838 or later Windows operating systems.

另见 DirectX 11.1 and Windows 7 and DirectX 11.1 and Windows 7 Update