Commit a683628b by Jamie Madill

Use common SystemInfo in tests.

We were using a static SystemInfo in two places. Consolidate the SystemInfo collection to a single location. Also renames Nvidia to NVIDIA to be consistent with the company naming. And adds a few helpers to SystemInfo for GPU detection. Will lead to test changes to reduce flakiness on Intel Windows. Bug: angleproject:3261 Change-Id: I4e0addf19d6fe26b4d31a1289efce72092a0a1dd Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1531533Reviewed-by: 's avatarJonah Ryan-Davis <jonahr@google.com> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent a11db2ac
...@@ -29,6 +29,42 @@ SystemInfo::~SystemInfo() = default; ...@@ -29,6 +29,42 @@ SystemInfo::~SystemInfo() = default;
SystemInfo::SystemInfo(const SystemInfo &other) = default; SystemInfo::SystemInfo(const SystemInfo &other) = default;
bool SystemInfo::hasNVIDIAGPU() const
{
for (const GPUDeviceInfo &gpu : gpus)
{
if (IsNVIDIA(gpu.vendorId))
{
return true;
}
}
return false;
}
bool SystemInfo::hasIntelGPU() const
{
for (const GPUDeviceInfo &gpu : gpus)
{
if (IsIntel(gpu.vendorId))
{
return true;
}
}
return false;
}
bool SystemInfo::hasAMDGPU() const
{
for (const GPUDeviceInfo &gpu : gpus)
{
if (IsAMD(gpu.vendorId))
{
return true;
}
}
return false;
}
bool IsAMD(VendorID vendorId) bool IsAMD(VendorID vendorId)
{ {
return vendorId == kVendorID_AMD; return vendorId == kVendorID_AMD;
...@@ -54,9 +90,9 @@ bool IsIntel(VendorID vendorId) ...@@ -54,9 +90,9 @@ bool IsIntel(VendorID vendorId)
return vendorId == kVendorID_Intel; return vendorId == kVendorID_Intel;
} }
bool IsNvidia(VendorID vendorId) bool IsNVIDIA(VendorID vendorId)
{ {
return vendorId == kVendorID_Nvidia; return vendorId == kVendorID_NVIDIA;
} }
bool IsQualcomm(VendorID vendorId) bool IsQualcomm(VendorID vendorId)
...@@ -187,9 +223,9 @@ void FindPrimaryGPU(SystemInfo *info) ...@@ -187,9 +223,9 @@ void FindPrimaryGPU(SystemInfo *info)
} }
} }
// Assume that a combination of AMD or Nvidia with Intel means Optimus or AMD Switchable // Assume that a combination of NVIDIA or AMD with Intel means Optimus or AMD Switchable
info->primaryGPUIndex = primary; info->primaryGPUIndex = primary;
info->isOptimus = hasIntel && IsNvidia(info->gpus[primary].vendorId); info->isOptimus = hasIntel && IsNVIDIA(info->gpus[primary].vendorId);
info->isAMDSwitchable = hasIntel && IsAMD(info->gpus[primary].vendorId); info->isAMDSwitchable = hasIntel && IsAMD(info->gpus[primary].vendorId);
} }
......
...@@ -52,6 +52,10 @@ struct SystemInfo ...@@ -52,6 +52,10 @@ struct SystemInfo
SystemInfo(const SystemInfo &other); SystemInfo(const SystemInfo &other);
bool hasNVIDIAGPU() const;
bool hasIntelGPU() const;
bool hasAMDGPU() const;
std::vector<GPUDeviceInfo> gpus; std::vector<GPUDeviceInfo> gpus;
// Index of the primary GPU (the discrete one on dual GPU systems) in `gpus`. // Index of the primary GPU (the discrete one on dual GPU systems) in `gpus`.
...@@ -87,7 +91,7 @@ constexpr VendorID kVendorID_AMD = 0x1002; ...@@ -87,7 +91,7 @@ constexpr VendorID kVendorID_AMD = 0x1002;
constexpr VendorID kVendorID_ARM = 0x13B5; constexpr VendorID kVendorID_ARM = 0x13B5;
constexpr VendorID kVendorID_ImgTec = 0x1010; constexpr VendorID kVendorID_ImgTec = 0x1010;
constexpr VendorID kVendorID_Intel = 0x8086; constexpr VendorID kVendorID_Intel = 0x8086;
constexpr VendorID kVendorID_Nvidia = 0x10DE; constexpr VendorID kVendorID_NVIDIA = 0x10DE;
constexpr VendorID kVendorID_Qualcomm = 0x5143; constexpr VendorID kVendorID_Qualcomm = 0x5143;
// Known non-PCI (i.e. Khronos-registered) vendor IDs // Known non-PCI (i.e. Khronos-registered) vendor IDs
...@@ -101,7 +105,7 @@ bool IsARM(VendorID vendorId); ...@@ -101,7 +105,7 @@ bool IsARM(VendorID vendorId);
bool IsImgTec(VendorID vendorId); bool IsImgTec(VendorID vendorId);
bool IsIntel(VendorID vendorId); bool IsIntel(VendorID vendorId);
bool IsKazan(VendorID vendorId); bool IsKazan(VendorID vendorId);
bool IsNvidia(VendorID vendorId); bool IsNVIDIA(VendorID vendorId);
bool IsQualcomm(VendorID vendorId); bool IsQualcomm(VendorID vendorId);
bool IsVeriSilicon(VendorID vendorId); bool IsVeriSilicon(VendorID vendorId);
bool IsVivante(VendorID vendorId); bool IsVivante(VendorID vendorId);
......
...@@ -201,7 +201,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -201,7 +201,7 @@ bool GetSystemInfo(SystemInfo *info)
gpu.driverVersion = FormatString("0x%x", properties.driverVersion); gpu.driverVersion = FormatString("0x%x", properties.driverVersion);
gpu.detailedDriverVersion.major = properties.driverVersion; gpu.detailedDriverVersion.major = properties.driverVersion;
break; break;
case kVendorID_Nvidia: case kVendorID_NVIDIA:
gpu.driverVendor = "NVIDIA Corporation"; gpu.driverVendor = "NVIDIA Corporation";
gpu.driverVersion = FormatString("%d.%d.%d.%d", properties.driverVersion >> 22, gpu.driverVersion = FormatString("%d.%d.%d.%d", properties.driverVersion >> 22,
(properties.driverVersion >> 14) & 0XFF, (properties.driverVersion >> 14) & 0XFF,
......
...@@ -108,7 +108,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -108,7 +108,7 @@ bool GetSystemInfo(SystemInfo *info)
} }
} }
if (IsNvidia(gpu->vendorId)) if (IsNVIDIA(gpu->vendorId))
{ {
std::string version; std::string version;
if (GetNvidiaDriverVersionWithXNVCtrl(&version)) if (GetNvidiaDriverVersionWithXNVCtrl(&version))
...@@ -127,7 +127,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -127,7 +127,7 @@ bool GetSystemInfo(SystemInfo *info)
if (GetNvidiaDriverVersionWithXNVCtrl(&version)) if (GetNvidiaDriverVersionWithXNVCtrl(&version))
{ {
GPUDeviceInfo nvidiaInfo; GPUDeviceInfo nvidiaInfo;
nvidiaInfo.vendorId = kVendorID_Nvidia; nvidiaInfo.vendorId = kVendorID_NVIDIA;
nvidiaInfo.deviceId = 0; nvidiaInfo.deviceId = 0;
gpu->driverVendor = "Nvidia"; gpu->driverVendor = "Nvidia";
gpu->driverVersion = std::move(version); gpu->driverVersion = std::move(version);
......
...@@ -325,7 +325,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters &params) ...@@ -325,7 +325,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters &params)
// Workaround if any of the GPUs is Nvidia, since we can't detect current GPU. // Workaround if any of the GPUs is Nvidia, since we can't detect current GPU.
EGLint renderer = params.getRenderer(); EGLint renderer = params.getRenderer();
bool needsWindowSwap = bool needsWindowSwap =
hasNvidiaGPU() && mLastRendererType.valid() && hasNVIDIAGPU() && mLastRendererType.valid() &&
((renderer != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) != ((renderer != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) !=
(mLastRendererType.value() != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)); (mLastRendererType.value() != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE));
...@@ -928,16 +928,10 @@ void ANGLETestBase::checkD3D11SDKLayersMessages() ...@@ -928,16 +928,10 @@ void ANGLETestBase::checkD3D11SDKLayersMessages()
#endif // defined(ANGLE_PLATFORM_WINDOWS) #endif // defined(ANGLE_PLATFORM_WINDOWS)
} }
bool ANGLETestBase::hasNvidiaGPU() bool ANGLETestBase::hasNVIDIAGPU() const
{ {
for (const angle::GPUDeviceInfo &gpu : ANGLETestEnvironment::GetSystemInfo()->gpus) angle::SystemInfo *systemInfo = angle::GetTestSystemInfo();
{ return systemInfo && systemInfo->hasNVIDIAGPU();
if (angle::IsNvidia(gpu.vendorId))
{
return true;
}
}
return false;
} }
bool ANGLETestBase::extensionEnabled(const std::string &extName) bool ANGLETestBase::extensionEnabled(const std::string &extName)
...@@ -1291,7 +1285,6 @@ Optional<EGLint> ANGLETestBase::mLastRendererType; ...@@ -1291,7 +1285,6 @@ Optional<EGLint> ANGLETestBase::mLastRendererType;
std::unique_ptr<angle::Library> ANGLETestEnvironment::gEGLLibrary; std::unique_ptr<angle::Library> ANGLETestEnvironment::gEGLLibrary;
std::unique_ptr<angle::Library> ANGLETestEnvironment::gWGLLibrary; std::unique_ptr<angle::Library> ANGLETestEnvironment::gWGLLibrary;
std::unique_ptr<angle::SystemInfo> ANGLETestEnvironment::gSystemInfo;
void ANGLETestEnvironment::SetUp() void ANGLETestEnvironment::SetUp()
{ {
...@@ -1328,19 +1321,6 @@ angle::Library *ANGLETestEnvironment::GetWGLLibrary() ...@@ -1328,19 +1321,6 @@ angle::Library *ANGLETestEnvironment::GetWGLLibrary()
return gWGLLibrary.get(); return gWGLLibrary.get();
} }
angle::SystemInfo *ANGLETestEnvironment::GetSystemInfo()
{
if (!gSystemInfo)
{
gSystemInfo = std::make_unique<angle::SystemInfo>();
if (!angle::GetSystemInfo(gSystemInfo.get()))
{
std::cerr << "Failed to get system info." << std::endl;
}
}
return gSystemInfo.get();
}
void ANGLEProcessTestArgs(int *argc, char *argv[]) void ANGLEProcessTestArgs(int *argc, char *argv[])
{ {
testing::AddGlobalTestEnvironment(new ANGLETestEnvironment()); testing::AddGlobalTestEnvironment(new ANGLETestEnvironment());
......
...@@ -399,7 +399,7 @@ class ANGLETestBase ...@@ -399,7 +399,7 @@ class ANGLETestBase
private: private:
void checkD3D11SDKLayersMessages(); void checkD3D11SDKLayersMessages();
bool hasNvidiaGPU(); bool hasNVIDIAGPU() const;
void drawQuad(GLuint program, void drawQuad(GLuint program,
const std::string &positionAttribName, const std::string &positionAttribName,
...@@ -469,14 +469,10 @@ class ANGLETestEnvironment : public testing::Environment ...@@ -469,14 +469,10 @@ class ANGLETestEnvironment : public testing::Environment
static angle::Library *GetEGLLibrary(); static angle::Library *GetEGLLibrary();
static angle::Library *GetWGLLibrary(); static angle::Library *GetWGLLibrary();
static angle::SystemInfo *GetSystemInfo();
private: private:
// For loading entry points. // For loading entry points.
static std::unique_ptr<angle::Library> gEGLLibrary; static std::unique_ptr<angle::Library> gEGLLibrary;
static std::unique_ptr<angle::Library> gWGLLibrary; static std::unique_ptr<angle::Library> gWGLLibrary;
static std::unique_ptr<angle::SystemInfo> gSystemInfo;
}; };
// This base fixture loads the EGL entry points. // This base fixture loads the EGL entry points.
......
...@@ -28,17 +28,6 @@ namespace angle ...@@ -28,17 +28,6 @@ namespace angle
{ {
namespace namespace
{ {
SystemInfo *GetTestSystemInfo()
{
static SystemInfo *sSystemInfo = nullptr;
if (sSystemInfo == nullptr)
{
sSystemInfo = new SystemInfo;
GetSystemInfo(sSystemInfo);
}
return sSystemInfo;
}
bool IsANGLEConfigSupported(const PlatformParameters &param, OSWindow *osWindow) bool IsANGLEConfigSupported(const PlatformParameters &param, OSWindow *osWindow)
{ {
std::unique_ptr<angle::Library> eglLibrary; std::unique_ptr<angle::Library> eglLibrary;
...@@ -77,6 +66,20 @@ bool IsNativeConfigSupported(const PlatformParameters &param, OSWindow *osWindow ...@@ -77,6 +66,20 @@ bool IsNativeConfigSupported(const PlatformParameters &param, OSWindow *osWindow
} }
} // namespace } // namespace
SystemInfo *GetTestSystemInfo()
{
static SystemInfo *sSystemInfo = nullptr;
if (sSystemInfo == nullptr)
{
sSystemInfo = new SystemInfo;
if (!GetSystemInfo(sSystemInfo))
{
std::cerr << "Warning: incomplete system info collection.\n";
}
}
return sSystemInfo;
}
bool IsAndroid() bool IsAndroid()
{ {
#if defined(ANGLE_PLATFORM_ANDROID) #if defined(ANGLE_PLATFORM_ANDROID)
...@@ -202,13 +205,13 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -202,13 +205,13 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
} }
// Win ES emulation is currently only supported on NVIDIA. // Win ES emulation is currently only supported on NVIDIA.
return vendorID == kVendorID_Nvidia; return IsNVIDIA(vendorID);
default: default:
return false; return false;
} }
case GLESDriverType::SystemWGL: case GLESDriverType::SystemWGL:
// AMD does not support the ES compatibility extensions. // AMD does not support the ES compatibility extensions.
return vendorID != kVendorID_AMD; return IsAMD(vendorID);
default: default:
return false; return false;
} }
...@@ -216,7 +219,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -216,7 +219,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
if (IsOSX()) if (IsOSX())
{ {
// Currently we only support the OpenGL back-end on OSX. // We do not support non-ANGLE bindings on OSX.
if (param.driver != GLESDriverType::AngleEGL) if (param.driver != GLESDriverType::AngleEGL)
{ {
return false; return false;
...@@ -228,23 +231,25 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -228,23 +231,25 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
return false; return false;
} }
// Currently we only support the OpenGL back-end on OSX.
return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE); return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE);
} }
if (IsFuchsia()) if (IsFuchsia())
{ {
// Currently we only support the Vulkan back-end on Fuchsia. // We do not support non-ANGLE bindings on Fuchsia.
if (param.driver != GLESDriverType::AngleEGL) if (param.driver != GLESDriverType::AngleEGL)
{ {
return false; return false;
} }
// Currently we only support the Vulkan back-end on Fuchsia.
return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE); return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE);
} }
if (IsOzone()) if (IsOzone())
{ {
// Currently we only support the GLES back-end on Ozone. // We do not support non-ANGLE bindings on Ozone.
if (param.driver != GLESDriverType::AngleEGL) if (param.driver != GLESDriverType::AngleEGL)
return false; return false;
...@@ -252,17 +257,19 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -252,17 +257,19 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
if (param.majorVersion > 2) if (param.majorVersion > 2)
return false; return false;
// Currently we only support the GLES back-end on Ozone.
return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE); return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE);
} }
if (IsLinux()) if (IsLinux())
{ {
// Currently we support the OpenGL and Vulkan back-ends on Linux. // We do not support non-ANGLE bindings on Linux.
if (param.driver != GLESDriverType::AngleEGL) if (param.driver != GLESDriverType::AngleEGL)
{ {
return false; return false;
} }
// Currently we support the OpenGL and Vulkan back-ends on Linux.
switch (param.getRenderer()) switch (param.getRenderer())
{ {
case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE: case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
...@@ -276,7 +283,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -276,7 +283,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
if (IsAndroid()) if (IsAndroid())
{ {
// Currently we support the GLES and Vulkan back-ends on Linux. // We do not support non-ANGLE bindings on Android.
if (param.driver != GLESDriverType::AngleEGL) if (param.driver != GLESDriverType::AngleEGL)
{ {
return false; return false;
...@@ -289,6 +296,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -289,6 +296,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
return false; return false;
} }
// Currently we support the GLES and Vulkan back-ends on Android.
switch (param.getRenderer()) switch (param.getRenderer())
{ {
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE: case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
......
...@@ -110,6 +110,8 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ...@@ -110,6 +110,8 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters
// Determines if a config is supported by trying to initialize it. Does not require SystemInfo. // Determines if a config is supported by trying to initialize it. Does not require SystemInfo.
bool IsConfigSupported(const PlatformParameters &param); bool IsConfigSupported(const PlatformParameters &param);
// Returns shared test system information. Can be used globally in the tests.
SystemInfo *GetTestSystemInfo();
} // namespace angle } // namespace angle
#endif // ANGLE_TEST_INSTANTIATE_H_ #endif // ANGLE_TEST_INSTANTIATE_H_
...@@ -34,7 +34,7 @@ std::string VendorName(VendorID vendor) ...@@ -34,7 +34,7 @@ std::string VendorName(VendorID vendor)
return "AMD"; return "AMD";
case kVendorID_Intel: case kVendorID_Intel:
return "Intel"; return "Intel";
case kVendorID_Nvidia: case kVendorID_NVIDIA:
return "Nvidia"; return "Nvidia";
case kVendorID_Qualcomm: case kVendorID_Qualcomm:
return "Qualcomm"; return "Qualcomm";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment