<?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>198684</bug_id>
          
          <creation_ts>2019-06-07 15:55:28 -0700</creation_ts>
          <short_desc>[WebGPU] Performance: Cache staging MTLBuffers used by GPUBuffer.unmap</short_desc>
          <delta_ts>2019-06-07 16:00:45 -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>WebGPU</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>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Justin Fan">justin_fan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1542988</commentid>
    <comment_count>0</comment_count>
    <who name="Justin Fan">justin_fan</who>
    <bug_when>2019-06-07 15:55:28 -0700</bug_when>
    <thetext>GPUBuffers created with GPUDevice.createBufferMapped are not CPU-accessible if they are not created with MAP_WRITE or MAP_READ usage. This necessitates a copy of written data to a CPU/GPU shared MTLBuffer, before copying this staging buffer to the intended destination on the GPU, during the call to GPUBuffer.unmap.

Since MTLBuffer creation is expensive, we can cache reasonably-sized (TBD size) staging buffers for re-use on the GPUDevice. A GPUBuffer can re-use the device&apos;s staging buffer for its unmap call, or create a new one if one does not exist or is too small.

If the staging buffer is not used within a certain time (TBD, i.e. ~10 frames), it is released.

Bonus points: implement a (sorted?) LRU-cache of different-sized staging buffers and use the smallest one that will suffice. This would release unusually large staging buffers earlier, but require more storage overall.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1542990</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-06-07 15:58:48 -0700</bug_when>
    <thetext>&lt;rdar://problem/51539224&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1542991</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-06-07 15:58:48 -0700</bug_when>
    <thetext>&lt;rdar://problem/51539225&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1542993</commentid>
    <comment_count>3</comment_count>
    <who name="Justin Fan">justin_fan</who>
    <bug_when>2019-06-07 16:00:33 -0700</bug_when>
    <thetext>Small addition: Specify MTLResourceCPUCacheModeWriteCombined in the creation option for these staging buffers, as the CPU never reads from them.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>