Path: blob/main_old/src/tests/test_expectations/GPUTestConfig.cpp
1693 views
1// Copyright 2019 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#include "GPUTestConfig.h"78#include <stdint.h>9#include <iostream>1011#include "common/angleutils.h"12#include "common/debug.h"13#include "common/platform.h"14#include "common/string_utils.h"15#include "gpu_info_util/SystemInfo.h"1617#if defined(ANGLE_PLATFORM_APPLE)18# include "GPUTestConfig_mac.h"19#endif2021namespace angle22{2324namespace25{2627// Generic function call to get the OS version information from any platform28// defined below. This function will also cache the OS version info in static29// variables.30inline bool OperatingSystemVersionNumbers(int32_t *majorVersion, int32_t *minorVersion)31{32static int32_t sSavedMajorVersion = -1;33static int32_t sSavedMinorVersion = -1;34bool ret = false;35if (sSavedMajorVersion == -1 || sSavedMinorVersion == -1)36{37#if defined(ANGLE_PLATFORM_WINDOWS)38OSVERSIONINFOEX version_info = {};39version_info.dwOSVersionInfoSize = sizeof(version_info);40::GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&version_info));41sSavedMajorVersion = version_info.dwMajorVersion;42*majorVersion = sSavedMajorVersion;43sSavedMinorVersion = version_info.dwMinorVersion;44*minorVersion = sSavedMinorVersion;45ret = true;4647#elif defined(ANGLE_PLATFORM_APPLE)48GetOperatingSystemVersionNumbers(&sSavedMajorVersion, &sSavedMinorVersion);49*majorVersion = sSavedMajorVersion;50*minorVersion = sSavedMinorVersion;51ret = true;5253#else54ret = false;55#endif56}57else58{59ret = true;60}61*majorVersion = sSavedMajorVersion;62*minorVersion = sSavedMinorVersion;63return ret;64}6566// Check if the OS is any version of Windows67inline bool IsWin()68{69#if defined(ANGLE_PLATFORM_WINDOWS)70return true;71#else72return false;73#endif74}7576// Check if the OS is a specific major version of windows.77inline bool IsWinVersion(const int32_t majorVersion)78{79if (IsWin())80{81int32_t currentMajorVersion = 0;82int32_t currentMinorVersion = 0;83if (OperatingSystemVersionNumbers(¤tMajorVersion, ¤tMinorVersion))84{85if (currentMajorVersion == majorVersion)86{87return true;88}89}90}91return false;92}9394// Check if the OS is a specific major and minor version of windows.95inline bool IsWinVersion(const int32_t majorVersion, const int32_t minorVersion)96{97if (IsWin())98{99int32_t currentMajorVersion = 0;100int32_t currentMinorVersion = 0;101if (OperatingSystemVersionNumbers(¤tMajorVersion, ¤tMinorVersion))102{103if (currentMajorVersion == majorVersion && currentMinorVersion == minorVersion)104{105return true;106}107}108}109return false;110}111112// Check if the OS is Windows XP113inline bool IsWinXP()114{115if (IsWinVersion(5))116{117return true;118}119return false;120}121122// Check if the OS is Windows Vista123inline bool IsWinVista()124{125if (IsWinVersion(6, 0))126{127return true;128}129return false;130}131132// Check if the OS is Windows 7133inline bool IsWin7()134{135if (IsWinVersion(6, 1))136{137return true;138}139return false;140}141142// Check if the OS is Windows 8143inline bool IsWin8()144{145if (IsWinVersion(6, 2) || IsWinVersion(6, 3))146{147return true;148}149return false;150}151152// Check if the OS is Windows 10153inline bool IsWin10()154{155if (IsWinVersion(10))156{157return true;158}159return false;160}161162// Check if the OS is any version of iOS163inline bool IsIOS()164{165#if defined(ANGLE_PLATFORM_IOS)166return true;167#else168return false;169#endif170}171172// Check if the OS is any version of OSX173inline bool IsMac()174{175#if defined(ANGLE_PLATFORM_MACOS)176return true;177#else178return false;179#endif180}181182// Check if the OS is a specific major and minor version of OSX183inline bool IsMacVersion(const int32_t majorVersion, const int32_t minorVersion)184{185if (IsMac())186{187int32_t currentMajorVersion = 0;188int32_t currentMinorVersion = 0;189if (OperatingSystemVersionNumbers(¤tMajorVersion, ¤tMinorVersion))190{191if (currentMajorVersion == majorVersion && currentMinorVersion == minorVersion)192{193return true;194}195}196}197return false;198}199200// Check if the OS is OSX Leopard201inline bool IsMacLeopard()202{203if (IsMacVersion(10, 5))204{205return true;206}207return false;208}209210// Check if the OS is OSX Snow Leopard211inline bool IsMacSnowLeopard()212{213if (IsMacVersion(10, 6))214{215return true;216}217return false;218}219220// Check if the OS is OSX Lion221inline bool IsMacLion()222{223if (IsMacVersion(10, 7))224{225return true;226}227return false;228}229230// Check if the OS is OSX Mountain Lion231inline bool IsMacMountainLion()232{233if (IsMacVersion(10, 8))234{235return true;236}237return false;238}239240// Check if the OS is OSX Mavericks241inline bool IsMacMavericks()242{243if (IsMacVersion(10, 9))244{245return true;246}247return false;248}249250// Check if the OS is OSX Yosemite251inline bool IsMacYosemite()252{253if (IsMacVersion(10, 10))254{255return true;256}257return false;258}259260// Check if the OS is OSX El Capitan261inline bool IsMacElCapitan()262{263if (IsMacVersion(10, 11))264{265return true;266}267return false;268}269270// Check if the OS is OSX Sierra271inline bool IsMacSierra()272{273if (IsMacVersion(10, 12))274{275return true;276}277return false;278}279280// Check if the OS is OSX High Sierra281inline bool IsMacHighSierra()282{283if (IsMacVersion(10, 13))284{285return true;286}287return false;288}289290// Check if the OS is OSX Mojave291inline bool IsMacMojave()292{293if (IsMacVersion(10, 14))294{295return true;296}297return false;298}299300// Check if the OS is any version of Linux301inline bool IsLinux()302{303#if defined(ANGLE_PLATFORM_LINUX)304return true;305#else306return false;307#endif308}309310// Check if the OS is any version of Android311inline bool IsAndroid()312{313#if defined(ANGLE_PLATFORM_ANDROID)314return true;315#else316return false;317#endif318}319320// Generic function call to populate the SystemInfo struct. This function will321// also cache the SystemInfo struct for future calls. Returns false if the322// struct was not fully populated. Guaranteed to set sysInfo to a valid pointer323inline bool GetGPUTestSystemInfo(SystemInfo **sysInfo)324{325static SystemInfo *sSystemInfo = nullptr;326static bool sPopulated = false;327if (sSystemInfo == nullptr)328{329sSystemInfo = new SystemInfo;330if (!GetSystemInfo(sSystemInfo))331{332std::cout << "Error populating SystemInfo." << std::endl;333}334else335{336// On dual-GPU Macs we want the active GPU to always appear to be the337// high-performance GPU for tests.338// We can call the generic GPU info collector which selects the339// non-Intel GPU as the active one on dual-GPU machines.340// See https://anglebug.com/3701.341if (IsMac())342{343GetDualGPUInfo(sSystemInfo);344}345sPopulated = true;346}347}348*sysInfo = sSystemInfo;349ASSERT(*sysInfo != nullptr);350return sPopulated;351}352353// Get the active GPUDeviceInfo from the SystemInfo struct.354// Returns false if devInfo is not guaranteed to be set to the active device.355inline bool GetActiveGPU(GPUDeviceInfo **devInfo)356{357SystemInfo *systemInfo = nullptr;358GetGPUTestSystemInfo(&systemInfo);359if (systemInfo->gpus.size() <= 0)360{361return false;362}363uint32_t index = systemInfo->activeGPUIndex;364ASSERT(index < systemInfo->gpus.size());365*devInfo = &(systemInfo->gpus[index]);366return true;367}368369// Get the vendor ID of the active GPU from the SystemInfo struct.370// Returns 0 if there is an error.371inline VendorID GetActiveGPUVendorID()372{373GPUDeviceInfo *activeGPU = nullptr;374if (GetActiveGPU(&activeGPU))375{376return activeGPU->vendorId;377}378else379{380return static_cast<VendorID>(0);381}382}383384// Get the device ID of the active GPU from the SystemInfo struct.385// Returns 0 if there is an error.386inline DeviceID GetActiveGPUDeviceID()387{388GPUDeviceInfo *activeGPU = nullptr;389if (GetActiveGPU(&activeGPU))390{391return activeGPU->deviceId;392}393else394{395return static_cast<DeviceID>(0);396}397}398399// Check whether the active GPU is NVIDIA.400inline bool IsNVIDIA()401{402return angle::IsNVIDIA(GetActiveGPUVendorID());403}404405// Check whether the active GPU is AMD.406inline bool IsAMD()407{408return angle::IsAMD(GetActiveGPUVendorID());409}410411// Check whether the active GPU is Intel.412inline bool IsIntel()413{414return angle::IsIntel(GetActiveGPUVendorID());415}416417// Check whether the active GPU is VMWare.418inline bool IsVMWare()419{420return angle::IsVMWare(GetActiveGPUVendorID());421}422423// Check whether this is a debug build.424inline bool IsDebug()425{426#if !defined(NDEBUG)427return true;428#else429return false;430#endif431}432433// Check whether this is a release build.434inline bool IsRelease()435{436return !IsDebug();437}438439// Check whether the system is a specific Android device based on the name.440inline bool IsAndroidDevice(const std::string &deviceName)441{442if (!IsAndroid())443{444return false;445}446SystemInfo *systemInfo = nullptr;447GetGPUTestSystemInfo(&systemInfo);448if (systemInfo->machineModelName == deviceName)449{450return true;451}452return false;453}454455// Check whether the system is a Nexus 5X device.456inline bool IsNexus5X()457{458return IsAndroidDevice("Nexus 5X");459}460461// Check whether the system is a Pixel 2 device.462inline bool IsPixel2()463{464return IsAndroidDevice("Pixel 2");465}466467// Check whether the system is a Pixel 2XL device.468inline bool IsPixel2XL()469{470return IsAndroidDevice("Pixel 2 XL");471}472473inline bool IsPixel4()474{475return IsAndroidDevice("Pixel 4");476}477478inline bool IsPixel4XL()479{480return IsAndroidDevice("Pixel 4 XL");481}482483// Check whether the active GPU is a specific device based on the string device ID.484inline bool IsDeviceIdGPU(const std::string &gpuDeviceId)485{486uint32_t deviceId = 0;487if (!HexStringToUInt(gpuDeviceId, &deviceId) || deviceId == 0)488{489// PushErrorMessage(kErrorMessage[kErrorEntryWithGpuDeviceIdConflicts], line_number);490return false;491}492return (deviceId == GetActiveGPUDeviceID());493}494495// Check whether the active GPU is a NVIDIA Quadro P400496inline bool IsNVIDIAQuadroP400()497{498if (!IsNVIDIA())499{500return false;501}502return IsDeviceIdGPU("0x1CB3");503}504505// Check whether the backend API has been set to D3D9 in the constructor506inline bool IsD3D9(const GPUTestConfig::API &api)507{508return (api == GPUTestConfig::kAPID3D9);509}510511// Check whether the backend API has been set to D3D11 in the constructor512inline bool IsD3D11(const GPUTestConfig::API &api)513{514return (api == GPUTestConfig::kAPID3D11);515}516517// Check whether the backend API has been set to OpenGL in the constructor518inline bool IsGLDesktop(const GPUTestConfig::API &api)519{520return (api == GPUTestConfig::kAPIGLDesktop);521}522523// Check whether the backend API has been set to OpenGLES in the constructor524inline bool IsGLES(const GPUTestConfig::API &api)525{526return (api == GPUTestConfig::kAPIGLES);527}528529// Check whether the backend API has been set to Vulkan in the constructor530inline bool IsVulkan(const GPUTestConfig::API &api)531{532return (api == GPUTestConfig::kAPIVulkan) || (api == GPUTestConfig::kAPISwiftShader);533}534535inline bool IsSwiftShader(const GPUTestConfig::API &api)536{537return (api == GPUTestConfig::kAPISwiftShader);538}539540// Check whether the backend API has been set to Metal in the constructor541inline bool IsMetal(const GPUTestConfig::API &api)542{543return (api == GPUTestConfig::kAPIMetal);544}545546} // anonymous namespace547548// Load all conditions in the constructor since this data will not change during a test set.549GPUTestConfig::GPUTestConfig() : GPUTestConfig(false) {}550551GPUTestConfig::GPUTestConfig(bool isSwiftShader)552{553mConditions[kConditionNone] = false;554mConditions[kConditionWinXP] = IsWinXP();555mConditions[kConditionWinVista] = IsWinVista();556mConditions[kConditionWin7] = IsWin7();557mConditions[kConditionWin8] = IsWin8();558mConditions[kConditionWin10] = IsWin10();559mConditions[kConditionWin] = IsWin();560mConditions[kConditionMacLeopard] = IsMacLeopard();561mConditions[kConditionMacSnowLeopard] = IsMacSnowLeopard();562mConditions[kConditionMacLion] = IsMacLion();563mConditions[kConditionMacMountainLion] = IsMacMountainLion();564mConditions[kConditionMacMavericks] = IsMacMavericks();565mConditions[kConditionMacYosemite] = IsMacYosemite();566mConditions[kConditionMacElCapitan] = IsMacElCapitan();567mConditions[kConditionMacSierra] = IsMacSierra();568mConditions[kConditionMacHighSierra] = IsMacHighSierra();569mConditions[kConditionMacMojave] = IsMacMojave();570mConditions[kConditionMac] = IsMac();571mConditions[kConditionIOS] = IsIOS();572mConditions[kConditionLinux] = IsLinux();573mConditions[kConditionAndroid] = IsAndroid();574// HW vendors are irrelevant if we are running on SW575mConditions[kConditionNVIDIA] = !isSwiftShader && IsNVIDIA();576mConditions[kConditionAMD] = !isSwiftShader && IsAMD();577mConditions[kConditionIntel] = !isSwiftShader && IsIntel();578mConditions[kConditionVMWare] = !isSwiftShader && IsVMWare();579mConditions[kConditionSwiftShader] = isSwiftShader;580581mConditions[kConditionRelease] = IsRelease();582mConditions[kConditionDebug] = IsDebug();583// If no API provided, pass these conditions by default584mConditions[kConditionD3D9] = true;585mConditions[kConditionD3D11] = true;586mConditions[kConditionGLDesktop] = true;587mConditions[kConditionGLES] = true;588mConditions[kConditionVulkan] = true;589mConditions[kConditionMetal] = true;590591// Devices are irrelevent if we are running on SW592mConditions[kConditionNexus5X] = !isSwiftShader && IsNexus5X();593mConditions[kConditionPixel2OrXL] = !isSwiftShader && (IsPixel2() || IsPixel2XL());594mConditions[kConditionPixel4OrXL] = !isSwiftShader && (IsPixel4() || IsPixel4XL());595mConditions[kConditionNVIDIAQuadroP400] = !isSwiftShader && IsNVIDIAQuadroP400();596597mConditions[kConditionPreRotation] = false;598mConditions[kConditionPreRotation90] = false;599mConditions[kConditionPreRotation180] = false;600mConditions[kConditionPreRotation270] = false;601602mConditions[kConditionSPIRVGen] = false;603}604605// If the constructor is passed an API, load those conditions as well606GPUTestConfig::GPUTestConfig(const API &api, uint32_t preRotation, bool enableDirectSPIRVGen)607: GPUTestConfig(IsSwiftShader(api))608{609mConditions[kConditionD3D9] = IsD3D9(api);610mConditions[kConditionD3D11] = IsD3D11(api);611mConditions[kConditionGLDesktop] = IsGLDesktop(api);612mConditions[kConditionGLES] = IsGLES(api);613mConditions[kConditionVulkan] = IsVulkan(api);614mConditions[kConditionMetal] = IsMetal(api);615616switch (preRotation)617{618case 90:619mConditions[kConditionPreRotation] = true;620mConditions[kConditionPreRotation90] = true;621break;622case 180:623mConditions[kConditionPreRotation] = true;624mConditions[kConditionPreRotation180] = true;625break;626case 270:627mConditions[kConditionPreRotation] = true;628mConditions[kConditionPreRotation270] = true;629break;630default:631break;632}633634if (enableDirectSPIRVGen)635{636mConditions[kConditionSPIRVGen] = true;637}638}639640// Return a const reference to the list of all pre-calculated conditions.641const GPUTestConfig::ConditionArray &GPUTestConfig::getConditions() const642{643return mConditions;644}645646} // namespace angle647648649