【问题标题】:Find out DirectX Version找出 DirectX 版本
【发布时间】:2014-04-09 01:14:49
【问题描述】:

如何检测 Windows 7 机器上的 directx 版本是 11 还是 11.1?

最好通过 PInvoke 或 SharpDX 使用 .NET 语言?

【问题讨论】:

    标签: .net windows-7 directx sharpdx


    【解决方案1】:

    只需尝试创建具有特定功能级别(以及其他参数)的设备。

    • 在本机代码中(使用D3D11CreateDevice* 函数之一)。如果功能不成功 - 不支持功能级别。为方便起见,我们通常传递功能级别数组,然后,如果设备不是nullptr,我们可以检查哪一个是最高支持的:

      const D3D_FEATURE_LEVEL arrFeatLevels[] = 
      {
          D3D_FEATURE_LEVEL_11_1, 
          D3D_FEATURE_LEVEL_11_0,
          D3D_FEATURE_LEVEL_10_1, 
          D3D_FEATURE_LEVEL_10_0,
          D3D_FEATURE_LEVEL_9_3, 
          D3D_FEATURE_LEVEL_9_2,
          D3D_FEATURE_LEVEL_9_1, 
      };
      
      const unsigned int nFeatLevels = _countof(arrFeatLevels);
      
      D3D11CreateDeviceAndSwapChain(..., arrFeatLevels, nFeatLevels, ..., 
                                         &m_Device, &featureLevel, &m_Context);
      if (m_Device && m_Context)
      {
          featureLevel // you can access to highest supported feature level here
      
    • 在 SharpDX 中,您需要使用构造函数,它接受特定的功能级别:

      Device(DriverType, DeviceCreationFlags, FeatureLevel[])
      

      如果设备创建成功,则检查Device.FeatureLevel 属性。

    编码愉快!

    编辑

    我想我误解了你的问题。您询问了检测操作系统支持哪个版本,而不是操作系统+显卡+驱动程序一起检测。支持的最大版本预装了操作系统,因此您只需要知道您在哪个操作系统上:

    OS version                      Version of DX runtime
    
    Windows Vista                   DirectX 10
    Windows Vista SP1/SP2           DirectX 10.1
    Windows Vista SP2               DirectX 11.0
    Windows 7                       DirectX 11.0
    Windows 7 SP1                   DirectX 11.0
    Windows 7 SP1 with KB2670838    DirectX 11.1
    Windows 8 / Windows RT          DirectX 11.1
    Windows 8.1 / Windows RT        DirectX 11.2
    

    来源:

    您还可以查询d3d11.dll 的版本并与维基页面上的版本进行比较。 见:

    【讨论】:

    • 谢谢!有趣的是,它在我的 Windows 7 上报告 D3D_FEATURE_LEVEL_10_0。
    • 也就是说你的显卡只支持DirectX 10
    • @Drop "Maximum supported version are preinstalled with OS", "Windows 7 SP1 | DirectX 11.1" 不正确,对吧? Win7SP1 仍然只预装 DX11.0。 DX11.1 需要特殊的“平台更新”。来源:Same wiki page.
    • @Peter 确实,看起来 Windows SP1 需要安装更新 KB2670838 才能获得 DirectX 11.1 运行时。另见here。我将此信息添加到答案中
    • @Peter 是的,这是设计使然。 (我在上面“编辑”部分的第二个短语中暗示了这一点)。只要操作系统支持,您可以使用任何 API 版本编写程序,但功能级别(您可以实际运行的一组按定义的功能)由可用的 API 版本、硬件和驱动程序功能(可能还有其他供应商特定的因素)。见:MSDN: Direct3D feature levels
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    相关资源
    最近更新 更多