2

My game runs with DirectX 11. I need to check if my PC supports DirectX 11 and if it is compatible with older DirectX versions.

Will my game that uses DirectX 11 work if my PC only has an older DirectX version?

I wrote this code, and it seems to work, but I'm not entirely sure about it:

bool CheckDirectXSupport(HRESULT &hr) {
    // Device descriptor
    D3D_FEATURE_LEVEL featureLevel;

    // Attempt to create the device Direct3D 11
    ID3D11Device* device = nullptr;
    ID3D11DeviceContext* context = nullptr;

    hr = D3D11CreateDevice(
        nullptr,                  
        D3D_DRIVER_TYPE_HARDWARE, 
        nullptr,                  
        0,                        
        nullptr,                  
        0,                        
        D3D11_SDK_VERSION,        
        &device,                  
        &featureLevel,            
        &context                  
    );

    // Test:
    // bool isSupported = SUCCEEDED(hr);

    bool isFailed = FAILED(hr);

    if (isFailed) {
        std::cout << "Failed to create DirectX 11 device. Error code: " << hr << std::endl;
        return false;
    }

    // Release recources
    if (device) device->Release();
    if (context) context->Release();

    return true;
} 

What if DirectX installed, but it doesn't work because driver failure or etc? Or what if my PC will have DirectX10? Will my game run and will CheckDirectX11Support() return true? Does my function cover all cases of incompatibility?

5
  • 4
    The last update to DX11 was in 2015. I think you're safe. Commented Nov 4, 2024 at 11:45
  • 2
    if a machine is running an OS that isnt able to run DX11 or later, its got bigger issues than running your game Commented Nov 4, 2024 at 11:52
  • 3
    If Windows version is 7 or higher, DirectX11 is installed (not necessarily all versions/features of DirectX11) Commented Nov 4, 2024 at 12:01
  • 1
    Thank you guys! I had doubts about my code. Now I'm sure it should check DirectX support :) Commented Nov 4, 2024 at 12:32
  • 1
    I personally fail to see the point if you’re already using Unity. Commented Nov 4, 2024 at 14:47

1 Answer 1

3

There are many reasons why D3D11CreateDevice could fail, but for the most part on modern versions of Windows you shouldn't do much more than 'fatal error' and exit.

Let's walk through them:

  • DirectX Runtime: On Windows 7 or later, you can guarantee that the ID3D11Device interfaces are supported. For Windows 8 or later, ID3D11Device1 or later. For Windows 8.1, ID3D11Device2 or later. For Windows 10, ID3D11Device3 or later.

There is no way to "install" DirectX. That is a holdover idea from Windows 95/98/ME. There are things that have been piggy-backed on the "DirectX End-User Runtime" package that older games need, but it isn't changing Direct3D at all. See this blog post for the full story.

IOW: You are not going to get E_NOINTERFACE with your code on any version of Windows you care about.

  • Direct3D device. There is always a Direct3D 11 compatible device on modern Windows. Even if there's no GPU in the system, you will end up with the Microsoft Basic Renderer which will successfully support create a Direct3D 11 device. That said, it's not likely you actually will have a working game in that case, but you can at least create a device and output some UI.

For more on MBR, see this blog post.

If you were providing a specific feature level requirement (you are passing nullptr so you currently accept any feature level), then on some really old systems you could end up with D3D_FEATURE_LEVEL_9_3 (or D3D_FEATURE_LEVEL_9_1 on an original Microsoft Surface). The reality is you probably want to specify some more reasonable minimum based on what your game uses. D3D_FEATURE_LEVEL_11_0 or if you want to support Windows Vista era system, D3D_FEATURE_LEVEL_10_0.

For more on Direct3D feature levels and what they mean, see this blog post.

  • You passed invalid arguments: If you are getting E_INVALIDARG that's a code bug and shouldn't happen in real programs.

If you were trying to support Windows 7 RTM or SP1 without KB2670838, then you can get a E_INVALIDARG if you ask for D3D_FEATURE_LEVEL_11_1, but in that case you'd just fallback to trying to call it again without that value. Again, see this blog post, but as long as you stick with D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, or D3D_FEATURE_LEVEL_10_0 which you really should, this is another non-issue edge-case.

  • The system configuration could be corrupt or the hardware is faulty. In this case, all you can do is display the value of the HRESULT to the user and let them figure it out.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.