DXGI 集成适配器

DXGI Integred adapter

使用 DXGI,我得到了所有显卡的列表。

IDXGIFactory* factory;
vector<IDXGIAdapter*> all_adapters;

HRESULT result(S_FALSE);
result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
if (FAILED(result))
    return false;

for (int i(0);; i++)
{
    IDXGIAdapter* adpt(nullptr);
    result = factory->EnumAdapters(i, &adpt);
    if (FAILED(result))
        break;
    DXGI_ADAPTER_DESC adesc;
    ZeroMemory(&adesc, sizeof(adesc));
    adpt->GetDesc(&adesc);
    if ((adesc.VendorId == 0x1414) && (adesc.DeviceId == 0x8c)) // no add WARP
    {
        adpt->Release();
        continue;
    }
    all_adapters.push_back(adpt);
}

如何定义集成显卡?

我想鉴定一下独立显卡和集成显卡

除了供应商 ID 之外,没有简单的方法来识别它们,即使那样,由于 NVidia Optimus 或 AMD PowerXpress 等混合图形解决方案,您也无法确定您真正使用的是什么。

通常您只需使用默认设备,并可能将以下内容添加到您的代码中以提示任何混合解决方案:

extern "C"
{
    __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

已更新:在 Windows 2018 年 4 月 10 日更新中,现在有一个支持新 EnumAdapterByGpuPreference 方法的新 IDXGIFactory6 界面它允许您通过 'max performance' 或 'minimum power'

枚举适配器
ComPtr<IDXGIAdapter1> adapter;
ComPtr<IDXGIFactory6> factory6;
HRESULT hr = m_dxgiFactory.As(&factory6);
if (SUCCEEDED(hr))
{
    for (UINT adapterIndex = 0;
        DXGI_ERROR_NOT_FOUND != factory6->EnumAdapterByGpuPreference(
            adapterIndex,
            DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE,
            IID_PPV_ARGS(adapter.ReleaseAndGetAddressOf()));
        adapterIndex++)
    {
        DXGI_ADAPTER_DESC1 desc;
        adapter->GetDesc1(&desc);

        if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
        {
            // Don't select the Basic Render Driver adapter.
            continue;
        }
        break;
    }
}
else
{
    for (UINT adapterIndex = 0;
        DXGI_ERROR_NOT_FOUND != m_dxgiFactory->EnumAdapters1(
            adapterIndex,
            adapter.ReleaseAndGetAddressOf());
            adapterIndex++)
    {
        DXGI_ADAPTER_DESC1 desc;
        adapter->GetDesc1(&desc);
        if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
        {
            // Don't select the Basic Render Driver adapter.
            continue;
        }
        break;
    }        
}