Commit 7cf862c9 by Daksh Idnani Committed by Zhenyao Mo

Reland "Make Mac SystemInfo reflect the currently active GPU on dual GPU machines"

This reverts commit 58940f67. Reason for revert: pixel test failures have been triaged in Gold. Relanding. Original change's description: > Revert "Make Mac SystemInfo reflect the currently active GPU on dual GPU machines" > > This reverts commit 720a8bab. > > Reason for revert: pixel test failures per http://crbug.com/984780#c13 > > Original change's description: > > Make Mac SystemInfo reflect the currently active GPU on dual GPU machines > > > > Currently, the GetSystemInfo() function (in gpu_info_util/SystemInfo_mac.mm) > > on dual GPU Macs always updates the active GPU field of the SystemInfo > > instance to the first non-Intel GPU it finds. This change overrides the > > activeGPUIndex field of the SystemInfo instance to reflect the current GPU > > instead of the non-intel GPU. > > > > Bug: 985486, 984780, angleproject:3701 > > Change-Id: Ia93f38f4a2f7728c05e99c83a940722bd3808766 > > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1752334 > > Commit-Queue: Kenneth Russell <kbr@chromium.org> > > Reviewed-by: Zhenyao Mo <zmo@chromium.org> > > Reviewed-by: Kenneth Russell <kbr@chromium.org> > > TBR=zmo@chromium.org,geofflang@chromium.org,kbr@chromium.org,dakshidnani@google.com > > Change-Id: Iacf4b8433ac1aa4d30c51f08ddfc6489af440cc4 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: 985486, 984780, angleproject:3701 > Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1757373 > Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Bug: 985486, 984780, angleproject:3701 Change-Id: I8f2f26f68329a2826a92742c46471b8c092b36ed Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1765963Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Commit-Queue: Kenneth Russell <kbr@chromium.org> (cherry picked from commit 5ec04880) Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1775272Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 08b97da8
...@@ -356,6 +356,7 @@ angle_static_library("angle_gpu_info_util") { ...@@ -356,6 +356,7 @@ angle_static_library("angle_gpu_info_util") {
"IOKit.framework", "IOKit.framework",
"CoreFoundation.framework", "CoreFoundation.framework",
"CoreGraphics.framework", "CoreGraphics.framework",
"OpenGL.framework",
] ]
} }
} }
......
...@@ -238,7 +238,7 @@ bool CMDeviceIDToDeviceAndVendorID(const std::string &id, uint32_t *vendorId, ui ...@@ -238,7 +238,7 @@ bool CMDeviceIDToDeviceAndVendorID(const std::string &id, uint32_t *vendorId, ui
return success; return success;
} }
void FindActiveGPU(SystemInfo *info) void GetDualGPUInfo(SystemInfo *info)
{ {
ASSERT(!info->gpus.empty()); ASSERT(!info->gpus.empty());
......
...@@ -108,6 +108,11 @@ bool IsVeriSilicon(VendorID vendorId); ...@@ -108,6 +108,11 @@ bool IsVeriSilicon(VendorID vendorId);
bool IsVMWare(VendorID vendorId); bool IsVMWare(VendorID vendorId);
bool IsVivante(VendorID vendorId); bool IsVivante(VendorID vendorId);
// Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex,
// isOptimus, and isAMDSwitchable.
// Always assumes the non-Intel GPU is active on dual-GPU machines.
void GetDualGPUInfo(SystemInfo *info);
// Dumps the system info to stdout. // Dumps the system info to stdout.
void PrintSystemInfo(const SystemInfo &info); void PrintSystemInfo(const SystemInfo &info);
} // namespace angle } // namespace angle
......
...@@ -29,10 +29,6 @@ bool ParseMacMachineModel(const std::string &identifier, ...@@ -29,10 +29,6 @@ bool ParseMacMachineModel(const std::string &identifier,
int32_t *minor); int32_t *minor);
bool CMDeviceIDToDeviceAndVendorID(const std::string &id, uint32_t *vendorId, uint32_t *deviceId); bool CMDeviceIDToDeviceAndVendorID(const std::string &id, uint32_t *vendorId, uint32_t *deviceId);
// Use a heuristic to attempt to find the GPU used for 3D graphics. Sets activeGPUIndex,
// isOptimus, and isAMDSwitchable. Deprecated: also sets primaryGPUIndex.
void FindActiveGPU(SystemInfo *info);
} // namespace angle } // namespace angle
#endif // GPU_INFO_UTIL_SYSTEM_INFO_INTERNAL_H_ #endif // GPU_INFO_UTIL_SYSTEM_INFO_INTERNAL_H_
...@@ -81,7 +81,7 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -81,7 +81,7 @@ bool GetSystemInfo(SystemInfo *info)
return false; return false;
} }
FindActiveGPU(info); GetDualGPUInfo(info);
for (size_t i = 0; i < info->gpus.size(); ++i) for (size_t i = 0; i < info->gpus.size(); ++i)
{ {
......
...@@ -17,6 +17,52 @@ namespace angle ...@@ -17,6 +17,52 @@ namespace angle
namespace namespace
{ {
using PlatformDisplayID = uint32_t;
constexpr CGLRendererProperty kCGLRPRegistryIDLow = static_cast<CGLRendererProperty>(140);
constexpr CGLRendererProperty kCGLRPRegistryIDHigh = static_cast<CGLRendererProperty>(141);
// Code from WebKit to get the active GPU's ID given a display ID.
uint64_t GetGpuIDFromDisplayID(PlatformDisplayID displayID)
{
GLuint displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);
GLint numRenderers = 0;
CGLRendererInfoObj rendererInfo = nullptr;
CGLError error = CGLQueryRendererInfo(displayMask, &rendererInfo, &numRenderers);
if (!numRenderers || !rendererInfo || error != kCGLNoError)
return 0;
// The 0th renderer should not be the software renderer.
GLint isAccelerated;
error = CGLDescribeRenderer(rendererInfo, 0, kCGLRPAccelerated, &isAccelerated);
if (!isAccelerated || error != kCGLNoError)
{
CGLDestroyRendererInfo(rendererInfo);
return 0;
}
GLint gpuIDLow = 0;
GLint gpuIDHigh = 0;
error = CGLDescribeRenderer(rendererInfo, 0, kCGLRPRegistryIDLow, &gpuIDLow);
if (error != kCGLNoError || gpuIDLow < 0)
{
CGLDestroyRendererInfo(rendererInfo);
return 0;
}
error = CGLDescribeRenderer(rendererInfo, 0, kCGLRPRegistryIDHigh, &gpuIDHigh);
if (error != kCGLNoError || gpuIDHigh < 0)
{
CGLDestroyRendererInfo(rendererInfo);
return 0;
}
CGLDestroyRendererInfo(rendererInfo);
return static_cast<uint64_t>(gpuIDHigh) << 32 | gpuIDLow;
}
std::string GetMachineModel() std::string GetMachineModel()
{ {
io_service_t platformExpert = IOServiceGetMatchingService( io_service_t platformExpert = IOServiceGetMatchingService(
...@@ -106,6 +152,44 @@ bool GetPCIDevices(std::vector<GPUDeviceInfo> *devices) ...@@ -106,6 +152,44 @@ bool GetPCIDevices(std::vector<GPUDeviceInfo> *devices)
return true; return true;
} }
void SetActiveGPUIndex(SystemInfo *info)
{
VendorID activeVendor;
DeviceID activeDevice;
uint64_t gpuID = GetGpuIDFromDisplayID(kCGDirectMainDisplay);
if (gpuID == 0)
return;
CFMutableDictionaryRef matchDictionary = IORegistryEntryIDMatching(gpuID);
io_service_t gpuEntry = IOServiceGetMatchingService(kIOMasterPortDefault, matchDictionary);
if (gpuEntry == IO_OBJECT_NULL)
{
IOObjectRelease(gpuEntry);
return;
}
if (!(GetEntryProperty(gpuEntry, CFSTR("vendor-id"), &activeVendor) &&
GetEntryProperty(gpuEntry, CFSTR("device-id"), &activeDevice)))
{
IOObjectRelease(gpuEntry);
return;
}
IOObjectRelease(gpuEntry);
for (size_t i = 0; i < info->gpus.size(); ++i)
{
if (info->gpus[i].vendorId == activeVendor && info->gpus[i].deviceId == activeDevice)
{
info->activeGPUIndex = static_cast<int>(i);
break;
}
}
}
} // anonymous namespace } // anonymous namespace
bool GetSystemInfo(SystemInfo *info) bool GetSystemInfo(SystemInfo *info)
...@@ -127,7 +211,16 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -127,7 +211,16 @@ bool GetSystemInfo(SystemInfo *info)
return false; return false;
} }
FindActiveGPU(info); // Call the generic GetDualGPUInfo function to initialize info fields
// such as isOptimus, isAMDSwitchable, and the activeGPUIndex
GetDualGPUInfo(info);
// Then override the activeGPUIndex field of info to reflect the current
// GPU instead of the non-intel GPU
if (@available(macOS 10.13, *))
{
SetActiveGPUIndex(info);
}
// Figure out whether this is a dual-GPU system. // Figure out whether this is a dual-GPU system.
// //
......
...@@ -88,8 +88,8 @@ bool GetSystemInfo(SystemInfo *info) ...@@ -88,8 +88,8 @@ bool GetSystemInfo(SystemInfo *info)
return false; return false;
} }
// Call FindActiveGPU to populate activeGPUIndex, isOptimus, and isAMDSwitchable. // Call GetDualGPUInfo to populate activeGPUIndex, isOptimus, and isAMDSwitchable.
FindActiveGPU(info); GetDualGPUInfo(info);
// Override activeGPUIndex. The first index returned by EnumAdapters is the active GPU. We // Override activeGPUIndex. The first index returned by EnumAdapters is the active GPU. We
// can override the heuristic to find the active GPU // can override the heuristic to find the active GPU
......
...@@ -112,6 +112,15 @@ SystemInfo *GetTestSystemInfo() ...@@ -112,6 +112,15 @@ SystemInfo *GetTestSystemInfo()
std::cerr << "Warning: incomplete system info collection.\n"; std::cerr << "Warning: incomplete system info collection.\n";
} }
// On dual-GPU Macs we want the active GPU to always appear to be the
// high-performance GPU for tests.
// We can call the generic GPU info collector which selects the
// non-Intel GPU as the active one on dual-GPU machines.
if (IsOSX())
{
GetDualGPUInfo(sSystemInfo);
}
// Print complete system info when available. // Print complete system info when available.
// Seems to trip up Android test expectation parsing. // Seems to trip up Android test expectation parsing.
// Also don't print info when a config is selected to prevent test spam. // Also don't print info when a config is selected to prevent test spam.
......
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