Path: blob/main_old/src/gpu_info_util/SystemInfo_win.cpp
1693 views
//1// Copyright 2013 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56// SystemInfo_win.cpp: implementation of the Windows-specific parts of SystemInfo.h78#include "gpu_info_util/SystemInfo_internal.h"910#include "common/debug.h"11#include "common/string_utils.h"1213// Windows.h needs to be included first14#include <windows.h>1516#include <dxgi.h>1718#include <array>19#include <sstream>2021namespace angle22{2324namespace25{2627bool GetDevicesFromDXGI(std::vector<GPUDeviceInfo> *devices)28{29#if defined(ANGLE_ENABLE_WINDOWS_UWP)30IDXGIFactory1 *factory;31if (!SUCCEEDED(32CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void **>(&factory))))33{34return false;35}36#else37IDXGIFactory *factory;38if (!SUCCEEDED(CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void **>(&factory))))39{40return false;41}42#endif4344UINT i = 0;45IDXGIAdapter *adapter = nullptr;46while (factory->EnumAdapters(i++, &adapter) != DXGI_ERROR_NOT_FOUND)47{48DXGI_ADAPTER_DESC desc;49adapter->GetDesc(&desc);5051LARGE_INTEGER umdVersion;52if (adapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &umdVersion) ==53DXGI_ERROR_UNSUPPORTED)54{55adapter->Release();56continue;57}5859// The UMD driver version here is the same as in the registry except for the last number.60uint64_t intVersion = umdVersion.QuadPart;61std::ostringstream o;6263constexpr uint64_t kMask16 = std::numeric_limits<uint16_t>::max();64o << ((intVersion >> 48) & kMask16) << ".";65o << ((intVersion >> 32) & kMask16) << ".";66o << ((intVersion >> 16) & kMask16) << ".";67o << (intVersion & kMask16);6869GPUDeviceInfo device;70device.vendorId = desc.VendorId;71device.deviceId = desc.DeviceId;72device.driverVersion = o.str();7374devices->push_back(device);7576adapter->Release();77}7879factory->Release();8081return (i > 0);82}8384} // anonymous namespace8586bool GetSystemInfo(SystemInfo *info)87{88if (!GetDevicesFromDXGI(&info->gpus))89{90return false;91}9293if (info->gpus.size() == 0)94{95return false;96}9798// Call GetDualGPUInfo to populate activeGPUIndex, isOptimus, and isAMDSwitchable.99GetDualGPUInfo(info);100101// Override activeGPUIndex. The first index returned by EnumAdapters is the active GPU. We102// can override the heuristic to find the active GPU103info->activeGPUIndex = 0;104105#if !defined(ANGLE_ENABLE_WINDOWS_UWP)106// Override isOptimus. nvd3d9wrap.dll is loaded into all processes when Optimus is enabled.107HMODULE nvd3d9wrap = GetModuleHandleW(L"nvd3d9wrap.dll");108info->isOptimus = nvd3d9wrap != nullptr;109#endif110111return true;112}113114} // namespace angle115116117