Bug 198684 - [WebGPU] Performance: Cache staging MTLBuffers used by GPUBuffer.unmap
Summary: [WebGPU] Performance: Cache staging MTLBuffers used by GPUBuffer.unmap
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGPU (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-06-07 15:55 PDT by Justin Fan
Modified: 2019-06-07 16:00 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Fan 2019-06-07 15:55:28 PDT
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'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.
Comment 1 Radar WebKit Bug Importer 2019-06-07 15:58:48 PDT
<rdar://problem/51539224>
Comment 2 Radar WebKit Bug Importer 2019-06-07 15:58:48 PDT
<rdar://problem/51539225>
Comment 3 Justin Fan 2019-06-07 16:00:33 PDT
Small addition: Specify MTLResourceCPUCacheModeWriteCombined in the creation option for these staging buffers, as the CPU never reads from them.