<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>228298</bug_id>
          
          <creation_ts>2021-07-26 13:52:45 -0700</creation_ts>
          <short_desc>powerPreference may not be working correctly in WebGL&apos;s Metal backend</short_desc>
          <delta_ts>2021-10-19 05:32:52 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=228698</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=231012</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>220843</dependson>
    
    <dependson>227408</dependson>
          <blocked>228576</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Kenneth Russell">kbr</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>kpiddington</cc>
    
    <cc>marcin.ignac</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1779550</commentid>
    <comment_count>0</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-07-26 13:52:45 -0700</bug_when>
    <thetext>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 &quot;powerPreference: &apos;high-performance&apos;&quot; is chosen. The mux shouldn&apos;t be necessary with ANGLE&apos;s Metal backend. However, WebKit&apos;s unmasked renderer string doesn&apos;t itself provide enough information to know whether the discrete GPU is actually used on a dual-GPU system.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779552</commentid>
    <comment_count>1</comment_count>
      <attachid>434233</attachid>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-07-26 13:54:00 -0700</bug_when>
    <thetext>Created attachment 434233
Test case

Simple test case allowing selection of low-power/high-performance GPUs</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779652</commentid>
    <comment_count>2</comment_count>
    <who name="Kyle Piddington">kpiddington</who>
    <bug_when>2021-07-26 17:36:55 -0700</bug_when>
    <thetext>Checked this by hand on a MBP, I&apos;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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779714</commentid>
    <comment_count>3</comment_count>
    <who name="Marcin Ignac">marcin.ignac</who>
    <bug_when>2021-07-27 02:55:14 -0700</bug_when>
    <thetext>I did manage to make it use high end gpu on my old laptop but can&apos;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 -&gt; Intel UHD Graphics 630, 10fps unresponsive UI
- Chrome 92 -&gt; AMD Radeon Pro 5600M, 60fps
- Firefox 90 -&gt; AMD Radeon Pro 5600M, 60fps

Things like being plugged in and Automatic Graphic Switching on/off don&apos;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 -&gt; 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 -&gt; AMD Radeon Pro 560, 60fps</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779849</commentid>
    <comment_count>4</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-07-27 15:06:01 -0700</bug_when>
    <thetext>Let me reopen this because there&apos;s at least one bug where &quot;powerPreference: high-performance&quot; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779858</commentid>
    <comment_count>5</comment_count>
    <who name="Marcin Ignac">marcin.ignac</who>
    <bug_when>2021-07-27 15:30:02 -0700</bug_when>
    <thetext>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) -&gt; Intel UHD Graphics 630, 20-30fps, feels like 5fps, unresponsive UI</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1779884</commentid>
    <comment_count>6</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-07-27 16:31:35 -0700</bug_when>
    <thetext>I don&apos;t think I can reproduce this on my 2017 15&quot; MacBook Pro. Could this issue be hardware dependent?

macOS 11.5

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

Kyle, do you have a 16&quot; MBP to test on? Can you reproduce this if so?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1780009</commentid>
    <comment_count>7</comment_count>
    <who name="Marcin Ignac">marcin.ignac</who>
    <bug_when>2021-07-28 03:24:40 -0700</bug_when>
    <thetext>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 &quot;GPU Process: WebGL&quot; enabled. Resetting all the flags gives me now big gpu and 60fps on both computers when using Safari TP.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1780266</commentid>
    <comment_count>8</comment_count>
    <who name="Dean Jackson">dino</who>
    <bug_when>2021-07-28 17:05:22 -0700</bug_when>
    <thetext>Yep! This was broken and then fixed recently. 

https://bugs.webkit.org/show_bug.cgi?id=227408</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1780269</commentid>
    <comment_count>9</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2021-07-28 17:09:08 -0700</bug_when>
    <thetext>Thanks Marcin for confirming. Have filed Bug 228576 about removing the unnecessary OpenGL-based GPU mux when using the Metal backend.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781205</commentid>
    <comment_count>10</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-08-02 01:05:01 -0700</bug_when>
    <thetext>(In reply to Marcin Ignac from comment #7)
&gt; The reason why it was running at 10fps on MBP16 was that i had &quot;GPU Process:
&gt; WebGL&quot; enabled. Resetting all the flags gives me now big gpu and 60fps on
&gt; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781218</commentid>
    <comment_count>11</comment_count>
    <who name="Marcin Ignac">marcin.ignac</who>
    <bug_when>2021-08-02 03:40:53 -0700</bug_when>
    <thetext>(In reply to Kimmo Kinnunen from comment #10)
&gt; Marcin, if you have a test case for this, feel free to link to it. I can
&gt; file a bug about that. Thanks.

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

What does &quot;GPU Process: WebGL&quot; do under the hood that might have such a big impact on performance?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781223</commentid>
    <comment_count>12</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-08-02 04:35:21 -0700</bug_when>
    <thetext>(In reply to Marcin Ignac from comment #11)
&gt; (In reply to Kimmo Kinnunen from comment #10)
&gt; &gt; Marcin, if you have a test case for this, feel free to link to it. I can
&gt; &gt; file a bug about that. Thanks.
&gt; 
&gt; It&apos;s the same as above http://projects.variable.io/webgl/shader-performance/

Thanks, missed it.

&gt; What does &quot;GPU Process: WebGL&quot; do under the hood that might have such a big
&gt; 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.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>434233</attachid>
            <date>2021-07-26 13:54:00 -0700</date>
            <delta_ts>2021-07-26 13:54:00 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>which-gpu.html</filename>
            <type>text/html</type>
            <size>912</size>
            <attacher name="Kenneth Russell">kbr</attacher>
            
              <data encoding="base64">PGJvZHkgb25sb2FkPSJydW4oKSIKPGRpdiBpZD0ib3V0cHV0Ij4KPC9kaXY+CjxjYW52YXMgaWQ9
ImMiIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4Ij4KPC9jYW52YXM+CjxzY3JpcHQ+CmZ1bmN0aW9u
IG91dHB1dChzdHIpIHsKICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJvdXRwdXQiKS5pbm5l
ckhUTUwgKz0gIjxicj4iICsgc3RyOwogICAgY29uc29sZS5sb2coc3RyKTsKfQoKZnVuY3Rpb24g
cnVuKCkgewogICAgZ2wgPSBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiYyIp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