Bug 220843

Summary: WebGL power preference and discrete/internal gpu selection implemented incorrectly with ANGLE
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebGLAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Normal CC: annulen, bfulgham, cdumez, changseok, dino, esprehn+autocc, ews-watchlist, graouts, gyuyoung.kim, kbr, kondapallykalyan, kpiddington, marcin.ignac, ryuan.choi, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Mac (Intel)   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=227408
Bug Depends on: 220845, 220852, 220989    
Bug Blocks: 220844, 220846, 228298    
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Kimmo Kinnunen 2021-01-21 23:59:38 PST
GraphicsContextGLOpenGLCocoa is changing the GPU behind ANGLE's back. This invalidates ANGLE assumptions.
The context gpu is changed based on which window the context is being used on. This cannot work with ANGLE, as all the contexts share one underlying implementation.
Comment 1 Kimmo Kinnunen 2021-01-22 00:20:10 PST
Created attachment 418112 [details]
Patch
Comment 2 Kimmo Kinnunen 2021-01-22 00:27:16 PST
Created attachment 418114 [details]
Patch
Comment 3 Kimmo Kinnunen 2021-01-22 02:33:13 PST
Created attachment 418123 [details]
Patch
Comment 4 Kimmo Kinnunen 2021-01-22 02:59:28 PST
Created attachment 418129 [details]
Patch
Comment 5 Kimmo Kinnunen 2021-01-22 03:05:59 PST
Created attachment 418130 [details]
Patch
Comment 6 Kimmo Kinnunen 2021-01-22 04:35:30 PST
Created attachment 418138 [details]
Patch
Comment 7 Kimmo Kinnunen 2021-01-22 08:12:53 PST
Created attachment 418149 [details]
Patch
Comment 8 Kenneth Russell 2021-01-22 11:28:55 PST
Comment on attachment 418149 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=418149&action=review

Looks like a good improvement overall. A couple of comments. Would like to see what else needs to change in order to pass the tests.

> Source/WebCore/platform/graphics/mac/GraphicsChecksMac.cpp:2
> + * Copyright (C) 2018 Apple Inc. All rights reserved.

2021? Here and throughout for the new files.

> Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h:44
> +        SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU();

Won't this crash if the singleton doesn't exist?

> Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h:49
> +            SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU();

Here too.

> Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h:61
> +        return { 0 };

This form of calling the 1-arg constructor threw me for a bit of a loop...
Comment 9 Kimmo Kinnunen 2021-01-22 12:33:21 PST
Created attachment 418170 [details]
Patch
Comment 10 Kimmo Kinnunen 2021-01-22 12:51:23 PST
(In reply to Kenneth Russell from comment #8)
> Comment on attachment 418149 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=418149&action=review
> 
> Looks like a good improvement overall. A couple of comments. Would like to
> see what else needs to change in order to pass the tests.
> 
> > Source/WebCore/platform/graphics/mac/GraphicsChecksMac.cpp:2
> > + * Copyright (C) 2018 Apple Inc. All rights reserved.
> 
> 2021? Here and throughout for the new files.

The code is from 2018 file, though.. I'll change.

> > Source/WebCore/platform/graphics/mac/ScopedHighPerformanceGPURequest.h:44
> > +        SwitchingGPUClient::singletonIfExists()->releaseHighPerformanceGPU();
> 
> Won't this crash if the singleton doesn't exist?

If it doesn't exist, nothing gets acquired..
Comment 11 Kimmo Kinnunen 2021-01-22 12:52:51 PST
Created attachment 418171 [details]
Patch
Comment 12 Kimmo Kinnunen 2021-01-26 00:02:38 PST
Created attachment 418375 [details]
Patch
Comment 13 Kimmo Kinnunen 2021-01-26 05:25:40 PST
I did my best to verify this based on the logging, for the time being until the underlying things are fixed.
Comment 14 EWS 2021-01-26 05:44:05 PST
Committed r271880: <https://trac.webkit.org/changeset/271880>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418375 [details].
Comment 15 Radar WebKit Bug Importer 2021-01-26 05:45:16 PST
<rdar://problem/73613562>
Comment 16 Brent Fulgham 2021-01-29 10:26:45 PST
This is actually:
<rdar://problem/70979077>.
Comment 17 Marcin Ignac 2021-07-24 15:51:05 PDT
Has this ever shipped? Both Safari Version 14.1.1 (16611.2.7.1.4) and Safari TP Release 128 (Safari 15.0, WebKit 16612.1.22.11.3) are unable to select high-performance gpu on Big Sur 11.4 (20F71).
Comment 18 Kenneth Russell 2021-07-26 13:47:27 PDT
How are you determining whether the discrete GPU was selected? With ANGLE's Metal backend - now the default in WebKit / Safari - I don't think there will be a system-wide GPU switch any more when the discrete GPU is used for WebGL. However, testing indicates differently - I'll file a bug dependent on this one.
Comment 19 Kenneth Russell 2021-07-26 13:54:52 PDT
Note, have filed Bug 228298 with a small test case - not sure whether things are working correctly in the Metal backend - let's follow up on that bug.
Comment 20 Kimmo Kinnunen 2021-08-02 01:02:42 PDT
It shipped and then broke again with Metal and then fixed in bug 227408 and currently shipped with previews.