Bug 198684

Summary: [WebGPU] Performance: Cache staging MTLBuffers used by GPUBuffer.unmap
Product: WebKit Reporter: Justin Fan <justin_fan>
Component: WebGPUAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Justin Fan
Reported 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.
Attachments
Radar WebKit Bug Importer
Comment 1 2019-06-07 15:58:48 PDT
Radar WebKit Bug Importer
Comment 2 2019-06-07 15:58:48 PDT
Justin Fan
Comment 3 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.
Note You need to log in before you can comment on or make changes to this bug.