tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SystemInfo.h (5673B)


      1 //
      2 // Copyright 2013 The ANGLE Project Authors. All rights reserved.
      3 // Use of this source code is governed by a BSD-style license that can be
      4 // found in the LICENSE file.
      5 //
      6 
      7 // SystemInfo.h: gathers information available without starting a GPU driver.
      8 
      9 #ifndef GPU_INFO_UTIL_SYSTEM_INFO_H_
     10 #define GPU_INFO_UTIL_SYSTEM_INFO_H_
     11 
     12 #include <cstdint>
     13 #include <optional>
     14 #include <string>
     15 #include <vector>
     16 
     17 namespace angle
     18 {
     19 
     20 using VendorID       = uint32_t;
     21 using DeviceID       = uint32_t;
     22 using RevisionID     = uint32_t;
     23 using SystemDeviceID = uint64_t;
     24 using DriverID       = uint32_t;
     25 
     26 struct VersionInfo
     27 {
     28    uint32_t major    = 0;
     29    uint32_t minor    = 0;
     30    uint32_t subMinor = 0;
     31    uint32_t patch    = 0;
     32 };
     33 
     34 struct GPUDeviceInfo
     35 {
     36    GPUDeviceInfo();
     37    ~GPUDeviceInfo();
     38 
     39    GPUDeviceInfo(const GPUDeviceInfo &other);
     40 
     41    VendorID vendorId             = 0;
     42    DeviceID deviceId             = 0;
     43    RevisionID revisionId         = 0;
     44    SystemDeviceID systemDeviceId = 0;
     45 
     46    std::string driverVendor;
     47    std::string driverVersion;
     48    std::string driverDate;
     49 
     50    // Fields only available via GetSystemInfoVulkan:
     51    VersionInfo detailedDriverVersion;
     52    DriverID driverId         = 0;
     53    uint32_t driverApiVersion = 0;
     54 };
     55 
     56 struct SystemInfo
     57 {
     58    SystemInfo();
     59    ~SystemInfo();
     60 
     61    SystemInfo(const SystemInfo &other);
     62 
     63    bool hasNVIDIAGPU() const;
     64    bool hasIntelGPU() const;
     65    bool hasAMDGPU() const;
     66 
     67    // Returns the index to `gpus` if the entry matches the preferred device string.
     68    std::optional<size_t> getPreferredGPUIndex() const;
     69 
     70    std::vector<GPUDeviceInfo> gpus;
     71 
     72    // Index of the GPU expected to be used for 3D graphics. Based on a best-guess heuristic on
     73    // some platforms. On Windows, this is accurate. Note `gpus` must be checked for empty before
     74    // indexing.
     75    int activeGPUIndex = 0;
     76 
     77    bool isOptimus       = false;
     78    bool isAMDSwitchable = false;
     79    // Only true on dual-GPU Mac laptops.
     80    bool isMacSwitchable = false;
     81    // Only true on Apple Silicon Macs when running in macCatalyst.
     82    bool needsEAGLOnMac = false;
     83 
     84    // Only available on Android
     85    std::string machineManufacturer;
     86    int androidSdkLevel = 0;
     87 
     88    // Only available on macOS and Android
     89    std::string machineModelName;
     90 
     91    // Only available on macOS
     92    std::string machineModelVersion;
     93 };
     94 
     95 // Gathers information about the system without starting a GPU driver and returns them in `info`.
     96 // Returns true if all info was gathered, false otherwise. Even when false is returned, `info` will
     97 // be filled with partial information.
     98 bool GetSystemInfo(SystemInfo *info);
     99 
    100 // Vulkan-specific info collection.
    101 bool GetSystemInfoVulkan(SystemInfo *info);
    102 
    103 // Known PCI vendor IDs
    104 constexpr VendorID kVendorID_AMD       = 0x1002;
    105 constexpr VendorID kVendorID_ARM       = 0x13B5;
    106 constexpr VendorID kVendorID_Broadcom  = 0x14E4;
    107 constexpr VendorID kVendorID_GOOGLE    = 0x1AE0;
    108 constexpr VendorID kVendorID_ImgTec    = 0x1010;
    109 constexpr VendorID kVendorID_Intel     = 0x8086;
    110 constexpr VendorID kVendorID_NVIDIA    = 0x10DE;
    111 constexpr VendorID kVendorID_Qualcomm  = 0x5143;
    112 constexpr VendorID kVendorID_VMWare    = 0x15ad;
    113 constexpr VendorID kVendorID_Apple     = 0x106B;
    114 constexpr VendorID kVendorID_Microsoft = 0x1414;
    115 
    116 // Known non-PCI (i.e. Khronos-registered) vendor IDs
    117 constexpr VendorID kVendorID_Vivante     = 0x10001;
    118 constexpr VendorID kVendorID_VeriSilicon = 0x10002;
    119 constexpr VendorID kVendorID_Kazan       = 0x10003;
    120 constexpr VendorID kVendorID_CodePlay    = 0x10004;
    121 constexpr VendorID kVendorID_Mesa        = 0x10005;
    122 constexpr VendorID kVendorID_PoCL        = 0x10006;
    123 
    124 // Known device IDs
    125 constexpr DeviceID kDeviceID_Swiftshader  = 0xC0DE;
    126 constexpr DeviceID kDeviceID_Adreno540    = 0x5040001;
    127 constexpr DeviceID kDeviceID_UHD630Mobile = 0x3E9B;
    128 
    129 // Predicates on vendor IDs
    130 bool IsAMD(VendorID vendorId);
    131 bool IsARM(VendorID vendorId);
    132 bool IsBroadcom(VendorID vendorId);
    133 bool IsImgTec(VendorID vendorId);
    134 bool IsIntel(VendorID vendorId);
    135 bool IsKazan(VendorID vendorId);
    136 bool IsNVIDIA(VendorID vendorId);
    137 bool IsQualcomm(VendorID vendorId);
    138 bool IsGoogle(VendorID vendorId);
    139 bool IsSwiftshader(VendorID vendorId);
    140 bool IsVeriSilicon(VendorID vendorId);
    141 bool IsVMWare(VendorID vendorId);
    142 bool IsVivante(VendorID vendorId);
    143 bool IsApple(VendorID vendorId);
    144 bool IsMicrosoft(VendorID vendorId);
    145 
    146 // Returns a readable vendor name given the VendorID
    147 std::string VendorName(VendorID vendor);
    148 
    149 // Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex,
    150 // isOptimus, and isAMDSwitchable.
    151 // Always assumes the non-Intel GPU is active on dual-GPU machines.
    152 void GetDualGPUInfo(SystemInfo *info);
    153 
    154 // Dumps the system info to stdout.
    155 void PrintSystemInfo(const SystemInfo &info);
    156 
    157 VersionInfo ParseNvidiaDriverVersion(uint32_t version);
    158 
    159 #if defined(ANGLE_PLATFORM_MACOS) || defined(ANGLE_PLATFORM_MACCATALYST)
    160 // Helper to get the active GPU ID from a given Core Graphics display ID.
    161 uint64_t GetGpuIDFromDisplayID(uint32_t displayID);
    162 
    163 // Helper to get the active GPU ID from an OpenGL display mask.
    164 uint64_t GetGpuIDFromOpenGLDisplayMask(uint32_t displayMask);
    165 
    166 // Get VendorID from metal device's registry ID
    167 VendorID GetVendorIDFromMetalDeviceRegistryID(uint64_t registryID);
    168 #endif
    169 
    170 uint64_t GetSystemDeviceIdFromParts(uint32_t highPart, uint32_t lowPart);
    171 uint32_t GetSystemDeviceIdHighPart(uint64_t systemDeviceId);
    172 uint32_t GetSystemDeviceIdLowPart(uint64_t systemDeviceId);
    173 
    174 // Returns lower-case of ANGLE_PREFERRED_DEVICE environment variable contents.
    175 std::string GetPreferredDeviceString();
    176 
    177 }  // namespace angle
    178 
    179 #endif  // GPU_INFO_UTIL_SYSTEM_INFO_H_