<?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>235043</bug_id>
          
          <creation_ts>2022-01-10 12:37:40 -0800</creation_ts>
          <short_desc>texImage2D with ImageBitmap from a video element is slow</short_desc>
          <delta_ts>2022-03-07 02:00:05 -0800</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 Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>234920</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Kimmo Kinnunen">kkinnunen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>erik</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>simontaylor1</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1829593</commentid>
    <comment_count>0</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2022-01-10 12:37:40 -0800</bug_when>
    <thetext>texImage2D with ImageBitmap from a video element is slow

Has multiple copies of the data
WebGL in GPUP off causes extra copies due to IPC</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1831552</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-01-17 12:38:15 -0800</bug_when>
    <thetext>&lt;rdar://problem/87687340&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848519</commentid>
    <comment_count>2</comment_count>
    <who name="Erik Zivkovic">erik</who>
    <bug_when>2022-03-05 04:45:40 -0800</bug_when>
    <thetext>This is hurting our web app in a BIG way: we have thousands of users watching live streamed video 3D projected in Safari - Every day!

It takes around 72ms to upload _ONE_ video frame which blows our entire frame budget.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848593</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Taylor">simontaylor1</who>
    <bug_when>2022-03-06 07:05:27 -0800</bug_when>
    <thetext>Erik - I&apos;m not sure how you&apos;re getting your ImageBitmap, but if you can do the texImage2d directly from a video element you&apos;ll get much better performance.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848600</commentid>
    <comment_count>4</comment_count>
    <who name="Erik Zivkovic">erik</who>
    <bug_when>2022-03-06 09:42:56 -0800</bug_when>
    <thetext>That&apos;s exactly what I&apos;m doing

gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, this.videoElement);

The performance is very bad, 70+ ms / requestAnimationFrame</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848639</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Taylor">simontaylor1</who>
    <bug_when>2022-03-07 00:46:12 -0800</bug_when>
    <thetext>Using RGBA as format and internal format is recommended on Safari, RGB has a bit of a performace penalty.

Your timings do seem high though - what hardware / Safari version are you seeing this with? What&apos;s the src for the video element? What&apos;s the video resolution?

It&apos;s possible you&apos;re seeing bug 236699.

This bug is specifically about ImageBitmap from a video element being slow to upload:
createImageBitmap(this.videoElement).then(bitmap =&gt; {
   gl.texImage2d(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
});</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848645</commentid>
    <comment_count>6</comment_count>
    <who name="Erik Zivkovic">erik</who>
    <bug_when>2022-03-07 01:58:16 -0800</bug_when>
    <thetext>Using gl.RGBA made texImage2D drop from 64.6ms to 6.9ms in my latest test.

I am using a MacBook Pro (16-inch, 2019) 2,6 GHz 6-Core Intel Core i7, 32 GB 2667 MHz DDR4, AMD Radeon Pro 5300M 4 GB / Intel UHD Graphics 630 1536 MB

We are not using createImageBitmap anywhere in our code. The video source is a HLS video (about 4k resolution) and using HLS.js (MediaSource extension).

Using gl.RGBA mitigates the issue, so thanks for that!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1848647</commentid>
    <comment_count>7</comment_count>
    <who name="Erik Zivkovic">erik</who>
    <bug_when>2022-03-07 02:00:05 -0800</bug_when>
    <thetext>Sorry forgot the Safari version: Version 15.3 (17612.4.9.1.8)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>