DirectX:无法创建 directx11 设备,即使我的系统说它支持它

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

我打开 dxdiag 应用程序,select 用于检查支持的功能级别的显示选项卡是结果

今天我的 RAM 不足,因为我的一个芯片坏了,现在我在 2GB 内存上运行

看来我的设备非常支持 directx 功能级别 11

跳转到 visual studio 2019 我尝试创建一个 D3D11 设备

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);
  }

输出:

我查看了我的制造商网站和 windows 更新,但都说您已经安装了最新的驱动程序。任何帮助将不胜感激

正如评论中所建议的那样,删除支持的最低功能级别,即 9_1 就是答案。

来自文档,如果特征级别数组为空则默认数组

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                               
  };

与我传递的数组相同,设备会检查支持哪些功能级别,但 IN ORDERFIRST 返回数组中支持的功能级别[不是最适合您的设备]

所以只要颠倒数组并将特征级别 11 放在数组的第一位就是答案