简体   繁体   中英

DirectX : cannot create an directx11 device even though my system says it supports it

I open the dxdiag app, select the display tab to check supported feature levels here are the results

Dxdiag 屏幕截图

I have low RAM today as one my chips got blown and am now operating on 2GB ram

So It looks like my device supports directx feature level 11 great

Jump to visual studio 2019 i try creating an D3D11 Device

D3D_FEATURE_LEVEL levels[] = {                            //Supported Levels We Want 11 or above
                                D3D_FEATURE_LEVEL_9_1,
                                D3D_FEATURE_LEVEL_9_2,
                                D3D_FEATURE_LEVEL_9_3,
                                D3D_FEATURE_LEVEL_10_0,
                                D3D_FEATURE_LEVEL_10_1,
                                D3D_FEATURE_LEVEL_11_0,
                                D3D_FEATURE_LEVEL_11_1                               
  };
  D3D_FEATURE_LEVEL supported = {};
 
  HRESULT deviceCreate = D3D11CreateDevice(
                                            nullptr                                                         //Use Default Adapter
                                           ,D3D_DRIVER_TYPE_HARDWARE,0                                       //Use Hardware ,no software module provided
                                           ,D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_DEBUG     //Flags for device creation
                                           ,levels,ARRAYSIZE(levels),D3D11_SDK_VERSION                       //Feature array,size of array,sdk to use
                                           ,&device,&supported,&context                                      //Created Device,supported level,context
                                          );
  if (FAILED(deviceCreate))
  {
    MessageBox(NULL, L"Failed To Create D3D11 Device", L"Failed DirectX", MB_OK);
    error = 1;
    return;
  }

  switch (supported)
  {
    case D3D_FEATURE_LEVEL_9_1:MessageBox(NULL, L"9_1", L"9_1", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_9_2:MessageBox(NULL, L"9_2", L"9_2", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_9_3:MessageBox(NULL, L"9_3", L"9_3", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_10_0:MessageBox(NULL, L"10_0", L"10_0", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_10_1:MessageBox(NULL, L"10_1", L"10_1", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_11_0:MessageBox(NULL, L"11_0", L"11_0", MB_OK);
    break;
    case D3D_FEATURE_LEVEL_11_1:MessageBox(NULL, L"11_1", L"11_1", MB_OK);
  }

Output:

在此处输入图片说明

I looked on my manufactures website and on windows update but both say you already have the latest drivers installed. Any help would be greatly appreciated

As suggested in the comments removing the lowest supported feature level ie 9_1 was the answer.

From the docs if the feature level array is null then the default array

D3D_FEATURE_LEVEL levels[] = {                            
                                D3D_FEATURE_LEVEL_9_1,
                                D3D_FEATURE_LEVEL_9_2,
                                D3D_FEATURE_LEVEL_9_3,
                                D3D_FEATURE_LEVEL_10_0,
                                D3D_FEATURE_LEVEL_10_1,
                                D3D_FEATURE_LEVEL_11_0,
                                D3D_FEATURE_LEVEL_11_1                               
  };

which is same as the array i passed is used and the device checks which of the feature levels are supported but IN ORDER and the FIRST supported feature level in the array is returned[Not the Best for your device]

So just reversing the array and putting Feature level 11 first in the array was the answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM