cwinapidirectxdirect3d

Direct3D 11 - The specified device interface or feature level is not supported on this system


I am new to Direct3D and trying to execute this piece of code:

#include <iostream>

#include <windows.h>
#include <d3d11.h>
#include <d3dcompiler.h>

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dcompiler.lib")
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "comctl32.lib")

using namespace std;

int main()
{
    ID3D11Device* g_pDevice = NULL;
    IDXGISwapChain* g_pSwapChain = NULL;
    ID3D11DeviceContext* g_pContext = NULL;
    D3D_FEATURE_LEVEL g_featureLevel;
    D3D_DRIVER_TYPE g_driverType;

    HRESULT hr = S_OK;

    UINT createDeviceFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;

#ifdef _DEBUG
    createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
    printf(">Got rect\n");

    D3D_DRIVER_TYPE driverTypes[] =
    {
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
    };
    DXGI_SWAP_CHAIN_DESC sd;
    ZeroMemory(&sd, sizeof(sd));
    sd.BufferCount = 1;
    sd.BufferDesc.Width = 700;
    sd.BufferDesc.Height = 600;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 75;
    sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = NULL;
    sd.SampleDesc.Count = 1;
    sd.SampleDesc.Quality = 0;
    sd.Windowed = TRUE;
    printf(">Checking drivers\n");
    for (UINT i = 0; i < ARRAYSIZE(driverTypes); i++)
    {
        g_driverType = driverTypes[i];
        hr = D3D11CreateDeviceAndSwapChain(
            NULL,
            g_driverType,
            NULL,
            createDeviceFlags,
            featureLevels,
            ARRAYSIZE(featureLevels),
            D3D11_SDK_VERSION,
            &sd,
            &g_pSwapChain,
            &g_pDevice,
            &g_featureLevel,
            &g_pContext
        );
        printf(">>Driver type: %ld\n", g_driverType);
        if (SUCCEEDED(hr)) break;
    }
    LPSTR s = (LPSTR)calloc(512, 1);
    FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, hr, 0, s, 512, NULL);
    printf("%s\n", s);
    return 0;
}

...I get an error saying I have no suitable driver for this program

Interestingly, I could execute this code successfully when I was testing it without any vertex buffers and triangles*. But suddenly adding them caused a driver error... I tried to find an answer here but one guy had a problem with a specific driver type and I can't even run the program with any of them. I also watched a youtube tutorial which recommends to install program that can work with message coming from the application (it was about final products like games and I have a debug program). Thank you

*- it seems that it doesn't matter if I have geometry initialized or not

P.S. Changed code to match the "minimal, reproducible example" rule, so now you can try it yourself (if you have Windows SDK)


Solution

  • I've finally found out the problem here: I had this code in main.cpp file:

    Window* mw = new Window(800, 600, "Name"); // Window init
    Scene* sc = new Scene(mw->g_hWnd, 75); // DirectX init
    if (!mw->Show() || !sc->Check())
    {
        delete mw;
        delete sc;
        return -1;
    }
    

    And it appears that Window constructor doesn't initialize the window itself but the mw->Show() which has InitInstance() call in it. That's why I edited my code like:

    Window* mw = new Window(800, 600, "Name"); // Window init
    if (!mw->Show())
    {
        delete mw;
        return -1;
    }
    Scene* sc = new Scene(mw->g_hWnd, 75); // DirectX init
    if (!sc->Check())
    {
        delete mw;
        delete sc;
        return -1;
    }
    

    If you're still encountering this error, check this website. It seems someone has rewritten my question in more sophisticated English and answered it :)