diff --git a/src/gpu_info_util/SystemInfo.cpp b/src/gpu_info_util/SystemInfo.cpp index dc6fc0a47..7bb917a46 100644 --- a/src/gpu_info_util/SystemInfo.cpp +++ b/src/gpu_info_util/SystemInfo.cpp @@ -29,6 +29,42 @@ SystemInfo::~SystemInfo() = 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) { return vendorId == kVendorID_AMD; @@ -54,9 +90,9 @@ bool IsIntel(VendorID vendorId) return vendorId == kVendorID_Intel; } -bool IsNvidia(VendorID vendorId) +bool IsNVIDIA(VendorID vendorId) { - return vendorId == kVendorID_Nvidia; + return vendorId == kVendorID_NVIDIA; } bool IsQualcomm(VendorID vendorId) @@ -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->isOptimus = hasIntel && IsNvidia(info->gpus[primary].vendorId); + info->isOptimus = hasIntel && IsNVIDIA(info->gpus[primary].vendorId); info->isAMDSwitchable = hasIntel && IsAMD(info->gpus[primary].vendorId); } diff --git a/src/gpu_info_util/SystemInfo.h b/src/gpu_info_util/SystemInfo.h index c08cc4cce..f71b1c165 100644 --- a/src/gpu_info_util/SystemInfo.h +++ b/src/gpu_info_util/SystemInfo.h @@ -52,6 +52,10 @@ struct SystemInfo SystemInfo(const SystemInfo &other); + bool hasNVIDIAGPU() const; + bool hasIntelGPU() const; + bool hasAMDGPU() const; + std::vector gpus; // Index of the primary GPU (the discrete one on dual GPU systems) in `gpus`. @@ -87,7 +91,7 @@ constexpr VendorID kVendorID_AMD = 0x1002; constexpr VendorID kVendorID_ARM = 0x13B5; constexpr VendorID kVendorID_ImgTec = 0x1010; constexpr VendorID kVendorID_Intel = 0x8086; -constexpr VendorID kVendorID_Nvidia = 0x10DE; +constexpr VendorID kVendorID_NVIDIA = 0x10DE; constexpr VendorID kVendorID_Qualcomm = 0x5143; // Known non-PCI (i.e. Khronos-registered) vendor IDs @@ -101,7 +105,7 @@ bool IsARM(VendorID vendorId); bool IsImgTec(VendorID vendorId); bool IsIntel(VendorID vendorId); bool IsKazan(VendorID vendorId); -bool IsNvidia(VendorID vendorId); +bool IsNVIDIA(VendorID vendorId); bool IsQualcomm(VendorID vendorId); bool IsVeriSilicon(VendorID vendorId); bool IsVivante(VendorID vendorId); diff --git a/src/gpu_info_util/SystemInfo_android.cpp b/src/gpu_info_util/SystemInfo_android.cpp index 5a0c54501..743da00a0 100644 --- a/src/gpu_info_util/SystemInfo_android.cpp +++ b/src/gpu_info_util/SystemInfo_android.cpp @@ -201,7 +201,7 @@ bool GetSystemInfo(SystemInfo *info) gpu.driverVersion = FormatString("0x%x", properties.driverVersion); gpu.detailedDriverVersion.major = properties.driverVersion; break; - case kVendorID_Nvidia: + case kVendorID_NVIDIA: gpu.driverVendor = "NVIDIA Corporation"; gpu.driverVersion = FormatString("%d.%d.%d.%d", properties.driverVersion >> 22, (properties.driverVersion >> 14) & 0XFF, diff --git a/src/gpu_info_util/SystemInfo_linux.cpp b/src/gpu_info_util/SystemInfo_linux.cpp index 98f000b06..b4d6aff4a 100644 --- a/src/gpu_info_util/SystemInfo_linux.cpp +++ b/src/gpu_info_util/SystemInfo_linux.cpp @@ -108,7 +108,7 @@ bool GetSystemInfo(SystemInfo *info) } } - if (IsNvidia(gpu->vendorId)) + if (IsNVIDIA(gpu->vendorId)) { std::string version; if (GetNvidiaDriverVersionWithXNVCtrl(&version)) @@ -127,7 +127,7 @@ bool GetSystemInfo(SystemInfo *info) if (GetNvidiaDriverVersionWithXNVCtrl(&version)) { GPUDeviceInfo nvidiaInfo; - nvidiaInfo.vendorId = kVendorID_Nvidia; + nvidiaInfo.vendorId = kVendorID_NVIDIA; nvidiaInfo.deviceId = 0; gpu->driverVendor = "Nvidia"; gpu->driverVersion = std::move(version); diff --git a/src/tests/test_utils/ANGLETest.cpp b/src/tests/test_utils/ANGLETest.cpp index b0b37119e..d532fa5ec 100644 --- a/src/tests/test_utils/ANGLETest.cpp +++ b/src/tests/test_utils/ANGLETest.cpp @@ -325,7 +325,7 @@ ANGLETestBase::ANGLETestBase(const angle::PlatformParameters ¶ms) // Workaround if any of the GPUs is Nvidia, since we can't detect current GPU. EGLint renderer = params.getRenderer(); bool needsWindowSwap = - hasNvidiaGPU() && mLastRendererType.valid() && + hasNVIDIAGPU() && mLastRendererType.valid() && ((renderer != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE) != (mLastRendererType.value() != EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)); @@ -928,16 +928,10 @@ void ANGLETestBase::checkD3D11SDKLayersMessages() #endif // defined(ANGLE_PLATFORM_WINDOWS) } -bool ANGLETestBase::hasNvidiaGPU() +bool ANGLETestBase::hasNVIDIAGPU() const { - for (const angle::GPUDeviceInfo &gpu : ANGLETestEnvironment::GetSystemInfo()->gpus) - { - if (angle::IsNvidia(gpu.vendorId)) - { - return true; - } - } - return false; + angle::SystemInfo *systemInfo = angle::GetTestSystemInfo(); + return systemInfo && systemInfo->hasNVIDIAGPU(); } bool ANGLETestBase::extensionEnabled(const std::string &extName) @@ -1291,7 +1285,6 @@ Optional ANGLETestBase::mLastRendererType; std::unique_ptr ANGLETestEnvironment::gEGLLibrary; std::unique_ptr ANGLETestEnvironment::gWGLLibrary; -std::unique_ptr ANGLETestEnvironment::gSystemInfo; void ANGLETestEnvironment::SetUp() { @@ -1328,19 +1321,6 @@ angle::Library *ANGLETestEnvironment::GetWGLLibrary() return gWGLLibrary.get(); } -angle::SystemInfo *ANGLETestEnvironment::GetSystemInfo() -{ - if (!gSystemInfo) - { - gSystemInfo = std::make_unique(); - if (!angle::GetSystemInfo(gSystemInfo.get())) - { - std::cerr << "Failed to get system info." << std::endl; - } - } - return gSystemInfo.get(); -} - void ANGLEProcessTestArgs(int *argc, char *argv[]) { testing::AddGlobalTestEnvironment(new ANGLETestEnvironment()); diff --git a/src/tests/test_utils/ANGLETest.h b/src/tests/test_utils/ANGLETest.h index 4515919e6..9b8e68f65 100644 --- a/src/tests/test_utils/ANGLETest.h +++ b/src/tests/test_utils/ANGLETest.h @@ -399,7 +399,7 @@ class ANGLETestBase private: void checkD3D11SDKLayersMessages(); - bool hasNvidiaGPU(); + bool hasNVIDIAGPU() const; void drawQuad(GLuint program, const std::string &positionAttribName, @@ -469,14 +469,10 @@ class ANGLETestEnvironment : public testing::Environment static angle::Library *GetEGLLibrary(); static angle::Library *GetWGLLibrary(); - static angle::SystemInfo *GetSystemInfo(); - private: // For loading entry points. static std::unique_ptr gEGLLibrary; static std::unique_ptr gWGLLibrary; - - static std::unique_ptr gSystemInfo; }; // This base fixture loads the EGL entry points. diff --git a/src/tests/test_utils/angle_test_instantiate.cpp b/src/tests/test_utils/angle_test_instantiate.cpp index c11212a31..028275c66 100644 --- a/src/tests/test_utils/angle_test_instantiate.cpp +++ b/src/tests/test_utils/angle_test_instantiate.cpp @@ -28,17 +28,6 @@ namespace angle { namespace { -SystemInfo *GetTestSystemInfo() -{ - static SystemInfo *sSystemInfo = nullptr; - if (sSystemInfo == nullptr) - { - sSystemInfo = new SystemInfo; - GetSystemInfo(sSystemInfo); - } - return sSystemInfo; -} - bool IsANGLEConfigSupported(const PlatformParameters ¶m, OSWindow *osWindow) { std::unique_ptr eglLibrary; @@ -77,6 +66,20 @@ bool IsNativeConfigSupported(const PlatformParameters ¶m, OSWindow *osWindow } } // 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() { #if defined(ANGLE_PLATFORM_ANDROID) @@ -202,13 +205,13 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters } // Win ES emulation is currently only supported on NVIDIA. - return vendorID == kVendorID_Nvidia; + return IsNVIDIA(vendorID); default: return false; } case GLESDriverType::SystemWGL: // AMD does not support the ES compatibility extensions. - return vendorID != kVendorID_AMD; + return IsAMD(vendorID); default: return false; } @@ -216,7 +219,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters 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) { return false; @@ -228,23 +231,25 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters return false; } + // Currently we only support the OpenGL back-end on OSX. return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE); } 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) { return false; } + // Currently we only support the Vulkan back-end on Fuchsia. return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE); } 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) return false; @@ -252,17 +257,19 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters if (param.majorVersion > 2) return false; + // Currently we only support the GLES back-end on Ozone. return (param.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE); } 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) { return false; } + // Currently we support the OpenGL and Vulkan back-ends on Linux. switch (param.getRenderer()) { case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE: @@ -276,7 +283,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters 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) { return false; @@ -289,6 +296,7 @@ bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters return false; } + // Currently we support the GLES and Vulkan back-ends on Android. switch (param.getRenderer()) { case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE: diff --git a/src/tests/test_utils/angle_test_instantiate.h b/src/tests/test_utils/angle_test_instantiate.h index c2f6c0aac..d294310ec 100644 --- a/src/tests/test_utils/angle_test_instantiate.h +++ b/src/tests/test_utils/angle_test_instantiate.h @@ -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. bool IsConfigSupported(const PlatformParameters ¶m); +// Returns shared test system information. Can be used globally in the tests. +SystemInfo *GetTestSystemInfo(); } // namespace angle #endif // ANGLE_TEST_INSTANTIATE_H_ diff --git a/src/tests/util_tests/PrintSystemInfoTest.cpp b/src/tests/util_tests/PrintSystemInfoTest.cpp index f3175516a..dfab04c65 100644 --- a/src/tests/util_tests/PrintSystemInfoTest.cpp +++ b/src/tests/util_tests/PrintSystemInfoTest.cpp @@ -34,7 +34,7 @@ std::string VendorName(VendorID vendor) return "AMD"; case kVendorID_Intel: return "Intel"; - case kVendorID_Nvidia: + case kVendorID_NVIDIA: return "Nvidia"; case kVendorID_Qualcomm: return "Qualcomm";