New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 822837 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner: ----
Closed: Apr 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 3
Type: Bug



Sign in to add a comment

macOS: Discrete GPU switching issue on startup

Project Member Reported by marshall@chromium.org, Mar 16 2018

Issue description

Chrome Version: 65.0.3325.162
OS: macOS 10.12.5 and 10.13.3

What steps will reproduce the problem?
(1) Launch content_shell on a MacBook Pro with dual GPUs (for example, "Intel Iris Pro 1536 MB" / "AMD Radeon R9 M370X 2 GB" GPUs).

What is the expected result?
Discrete GPU should not be activated on startup (Activity Monitor should not show "Requires High Perf GPU").

What happens instead?
Discrete GPU is activated. In Chrome something is triggering an immediate switch back to the integrated GPU. In content_shell the discrete GPU remains active. Keeping the discrete GPU active significantly reduces battery life.

Please use labels and text to provide additional information.

Related discussion on graphics-dev: https://groups.google.com/a/chromium.org/d/msg/graphics-dev/lYmc1Fcs5xQ/BgrpgF7sBAAJ

InitializeOnOffForSandbox [1] is calling CGLChoosePixelFormat with an empty CGLPixelFormatAttribute array due to  GLContext::SwitchableGPUsSupported returning false (SetSwitchableGPUsSupported [2] is called later in the startup process). This activates the discrete GPU.

Chrome printf logging:

CGDisplayRegisterReconfigurationCallback
InitializeOneOffForSandbox
InitializeOneOffForSandbox CGLChoosePixelFormat  << empty CGLPixelFormatAttribute array
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=8476d
DisplayReconfigCallback gpu_changed=1  << switch to discrete GPU
GpuDataManagerImplPrivate::HandleGpuSwitch
GpuSwitchingManager::NotifyGpuSwitched
DisplayReconfigCallback flags=8736d
DisplayReconfigCallback gpu_changed=0
InitializeOneOffForSandbox CGLChoosePixelFormat success
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=8476d
DisplayReconfigCallback gpu_changed=1  << switch to integrated GPU (not sure what causes this)
GpuDataManagerImplPrivate::HandleGpuSwitch
GpuSwitchingManager::NotifyGpuSwitched
DisplayReconfigCallback flags=8736d
DisplayReconfigCallback gpu_changed=0
InitializeSwitchableGPUs  << call SetSwitchableGPUsSupported

content_shell printf logging:

CGDisplayRegisterReconfigurationCallback
InitializeOneOffForSandbox
InitializeOneOffForSandbox CGLChoosePixelFormat  << empty CGLPixelFormatAttribute array
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=1d
DisplayReconfigCallback flags=8476d
DisplayReconfigCallback gpu_changed=1  << switch to discrete GPU
GpuDataManagerImplPrivate::HandleGpuSwitch
GpuSwitchingManager::NotifyGpuSwitched
DisplayReconfigCallback flags=8736d
DisplayReconfigCallback gpu_changed=0
InitializeOneOffForSandbox CGLChoosePixelFormat success
InitializeSwitchableGPUs  << call SetSwitchableGPUsSupported

From https://developer.apple.com/library/content/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_pixelformats/opengl_pixelformats.html :

"Adding the attribute NSOpenGLPFAAllowOfflineRenderers allows OpenGL to include offline renderers in the list of virtual screens returned in the pixel format object. Apple recommends you include this attribute, because it allows your application to work better in environments where renderers come and go, such as when a new display is plugged into a Mac."

So it sounds like always setting kCGLPFAAllowOfflineRenderers might be safe. I'm running a trial of this currently in a Chromium-based application [4]

There also appears to be an unrelated bug in IOSurfaceContext::Get [3] where it adds the "end of array" 0 value twice.

[1] https://cs.chromium.org/chromium/src/ui/gl/init/gl_initializer_mac.cc?type=cs&q=InitializeOneOffForSandbox&l=40

[2] https://cs.chromium.org/chromium/src/gpu/config/gpu_switching.cc?type=cs&q=SetSwitchableGPUsSupported&l=82

[3] https://cs.chromium.org/chromium/src/ui/accelerated_widget_mac/io_surface_context.mm?type=cs&q=CGLChoosePixelFormat&l=51 

[4] https://bitbucket.org/chromiumembedded/cef/issues/2398


 

Comment 1 by kbr@chromium.org, Mar 17 2018

Cc: -jbau...@chromium.org ccameron@chromium.org
Components: -Internals>GPU Internals>GPU>Internals

Comment 2 by piman@chromium.org, Mar 20 2018

Owner: ccameron@chromium.org
Status: Assigned (was: Untriaged)
It sounds like it is an issue even for Chrome because we switch back-and-forth, which probably hurts startup a bit. Should we figure out the configuration and call SetSwitchableGPUsSupported earlier in InitializeOneOffForSandbox?

Comment 3 by zmo@chromium.org, Mar 20 2018

re: #2: Yes that's exactly what we did. Still need to figure out why Chrome switch to discrete GPU in the first place at launch.
@comment#3: The initial switch to discrete GPU is because InitializeOnOffForSandbox is calling CGLChoosePixelFormat with an empty CGLPixelFormatAttribute array due to  GLContext::SwitchableGPUsSupported returning false. SetSwitchableGPUsSupported is called from InitializeSwitchableGPUs later in the startup process. You can see the call stacks at 65.0.3325.162 here: https://bitbucket.org/chromiumembedded/cef/issues/2398#comment-43943652

Comment 5 by zmo@chromium.org, Mar 20 2018

Owner: zmo@chromium.org
Ah I got confused. I remember we did collect GPUInfo and make GPU switching decisions in sandbox_init_mac.cc, but we didn't actually force the decision early enough.

Let me fix it.

Comment 6 by zmo@chromium.org, Mar 23 2018

Owner: ----
Status: Untriaged (was: Assigned)
https://chromium-review.googlesource.com/c/chromium/src/+/976818 just landed, which should fix the issue of Chrome briefly switch to discrete GPU on startup.

Unassign myself for now.
Labels: Needs-Feedback
zmo: Are more steps required to fix this issue?
Project Member

Comment 8 by bugdroid1@chromium.org, Mar 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/ee6d9fdd6aa00ecc73a23d6da91425c3e776e498

commit ee6d9fdd6aa00ecc73a23d6da91425c3e776e498
Author: Zhenyao Mo <zmo@chromium.org>
Date: Fri Mar 23 14:25:24 2018

Enforce GPU earlier on Mac to avoid GPU switching during startup.

BUG= 822837 
TEST=manual on Mac with dual GPUs
R=ccameron@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ia8a0d741ffaa83fec68d21e67cd54a3eb9eb0136
Reviewed-on: https://chromium-review.googlesource.com/976818
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: ccameron <ccameron@chromium.org>
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545434}
[modify] https://crrev.com/ee6d9fdd6aa00ecc73a23d6da91425c3e776e498/content/common/sandbox_init_mac.cc
[modify] https://crrev.com/ee6d9fdd6aa00ecc73a23d6da91425c3e776e498/gpu/ipc/service/gpu_init.cc

Comment 9 by zmo@chromium.org, Mar 23 2018

I fixed the Chrome issue. The original bug is about content_shell. I won't be able to look into content_shell behavior dual GPU at the moment.
Cc: sandeepkumars@chromium.org
Unable to verify the issue as we don't have a Mac machine with dual GPUs. 

Requesting reporter to verify the fix and confirm.

Thanks!!
Status: Fixed (was: Untriaged)
Mac triage: marking this Fixed per #8.

Sign in to add a comment