Bug 228298 - powerPreference may not be working correctly in WebGL's Metal backend
Summary: powerPreference may not be working correctly in WebGL's Metal backend
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 220843 227408
Blocks: 228576
  Show dependency treegraph
 
Reported: 2021-07-26 13:52 PDT by Kenneth Russell
Modified: 2021-10-19 05:32 PDT (History)
5 users (show)

See Also:


Attachments
Test case (912 bytes, text/html)
2021-07-26 13:54 PDT, Kenneth Russell
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Russell 2021-07-26 13:52:45 PDT
Marcin Ignac indicates on Bug 220843 that in the current Safari Technology Preview (Release 128 (Safari 15.0, WebKit 16612.1.22.11.3)), on a dual-GPU system running macOS 11.5, the powerPreference implementation may not be working correctly.

Attached is a test case. Switch which powerPreference line is picked in order to see the difference.

The system does still perform a graphics mux (legacy behavior, from OpenGL) when "powerPreference: 'high-performance'" is chosen. The mux shouldn't be necessary with ANGLE's Metal backend. However, WebKit's unmasked renderer string doesn't itself provide enough information to know whether the discrete GPU is actually used on a dual-GPU system.
Comment 1 Kenneth Russell 2021-07-26 13:54:00 PDT
Created attachment 434233 [details]
Test case

Simple test case allowing selection of low-power/high-performance GPUs
Comment 2 Kyle Piddington 2021-07-26 17:36:55 PDT
Checked this by hand on a MBP, I'm seeing the correct GPU get selected based off of the LowPowerMode / highPowerMode flag. Should we respond to the unmasked renderer / GPU strings at all?
Comment 3 Marcin Ignac 2021-07-27 02:55:14 PDT
I did manage to make it use high end gpu on my old laptop but can't make it work on MBP16. After upgrading macOS and Safari on my old laptop performance degraded.

How to replicate: 
1. Open http://projects.variable.io/webgl/shader-performance/ (noise based particle animation)
2. Open Activity Monitor and then GPU History

MacBook Pro (16-inch, 2019), macOS BigSur 11.5
- Safari 14.1.2 -> Intel UHD Graphics 630, 10fps unresponsive UI
- Chrome 92 -> AMD Radeon Pro 5600M, 60fps
- Firefox 90 -> AMD Radeon Pro 5600M, 60fps

Things like being plugged in and Automatic Graphic Switching on/off don't seem to make a difference. Also when i have Chrome using Radeon PRo 5600M and open Safari with the link above then Intel UHD kicks in anyway

MacBook Pro (15-inch 2017), macOS BigSur 11.0.1
- Safari 14.0.1 → AMD Radeon Pro 560, 60fps
- Chrome 92 -> AMD Radeon Pro 560, 60fps

After upgrading to macOS BigSur 11.5.1
MacBook Pro (15-inch 2017), macOS BigSur 11.5
- Safari 14.1.2 → Intel HD GRaphics 630, 20fps, unresponsive UI 
- Chrome 92 -> AMD Radeon Pro 560, 60fps
Comment 4 Kenneth Russell 2021-07-27 15:06:01 PDT
Let me reopen this because there's at least one bug where "powerPreference: high-performance" is still causing an OpenGL-based mux to the high-performance GPU which is unnecessary in the Metal backend.

Marcin, can you please test with Safari Technology Preview (Safari 15.0) and tell us your results?

There might be bugs in Safari 14 and selection of the high-performance GPU via WebGL, but they should be fixed in Safari 15 and Safari Technology Preview.
Comment 5 Marcin Ignac 2021-07-27 15:30:02 PDT
Safari TP behaves the same:


MacBook Pro (16-inch, 2019), macOS BigSur 11.5
Safari TP 128 (Safari 15.0, WebKit 16612.1.22.11.3) -> Intel UHD Graphics 630, 20-30fps, feels like 5fps, unresponsive UI
Comment 6 Kenneth Russell 2021-07-27 16:31:35 PDT
I don't think I can reproduce this on my 2017 15" MacBook Pro. Could this issue be hardware dependent?

macOS 11.5

Chrome 94.0.4588.0 (Official Build) canary (x86_64) -> 60 FPS
STP Release 128 (Safari 15.0, WebKit 16612.1.22.11.3) -> 60 FPS

Kyle, do you have a 16" MBP to test on? Can you reproduce this if so?
Comment 7 Marcin Ignac 2021-07-28 03:24:40 PDT
Sorry guys.

I can confirm that Safari TP Release 128 (Safari 15.0, WebKit 16612.1.22.11.3) fixes the issue on both MBP15 with AMD Radeon Pro 560, and MBP16 with AMD Radeon Pro 5600M.

The reason why it was running at 10fps on MBP16 was that i had "GPU Process: WebGL" enabled. Resetting all the flags gives me now big gpu and 60fps on both computers when using Safari TP.
Comment 8 Dean Jackson 2021-07-28 17:05:22 PDT
Yep! This was broken and then fixed recently. 

https://bugs.webkit.org/show_bug.cgi?id=227408
Comment 9 Kenneth Russell 2021-07-28 17:09:08 PDT
Thanks Marcin for confirming. Have filed Bug 228576 about removing the unnecessary OpenGL-based GPU mux when using the Metal backend.
Comment 10 Kimmo Kinnunen 2021-08-02 01:05:01 PDT
(In reply to Marcin Ignac from comment #7)
> The reason why it was running at 10fps on MBP16 was that i had "GPU Process:
> WebGL" enabled. Resetting all the flags gives me now big gpu and 60fps on
> both computers when using Safari TP.

Marcin, if you have a test case for this, feel free to link to it. I can file a bug about that. Thanks.
Comment 11 Marcin Ignac 2021-08-02 03:40:53 PDT
(In reply to Kimmo Kinnunen from comment #10)
> Marcin, if you have a test case for this, feel free to link to it. I can
> file a bug about that. Thanks.

It's the same as above http://projects.variable.io/webgl/shader-performance/

What does "GPU Process: WebGL" do under the hood that might have such a big impact on performance?
Comment 12 Kimmo Kinnunen 2021-08-02 04:35:21 PDT
(In reply to Marcin Ignac from comment #11)
> (In reply to Kimmo Kinnunen from comment #10)
> > Marcin, if you have a test case for this, feel free to link to it. I can
> > file a bug about that. Thanks.
> 
> It's the same as above http://projects.variable.io/webgl/shader-performance/

Thanks, missed it.

> What does "GPU Process: WebGL" do under the hood that might have such a big
> impact on performance?

It transfers the calls from web content process to GPU process, executes those in GPU process and then transfers the results back to web content process.