Open Bug 1968102 Opened 1 year ago Updated 1 year ago

GPUQueue.writeBuffer is slow

Categories

(Core :: Graphics: WebGPU, defect, P1)

defect

Tracking

()

People

(Reporter: jimb, Unassigned)

References

(Blocks 2 open bugs)

Details

(Keywords: leave-open)

Attachments

(1 external file)

We believe that the performance of many of our WebGPU MVP apps is affected by GPUQueue.writeBuffer performance being very poor.

This profile of the Marching Cubes WebGPU sample shows that, of a 283ms requestAnimationFrame call, 41.7ms are spent in GPUQueue.writeBuffer calls. Obviously this profile has other problems as well, but we have observed that GPUQueue.writeBuffer shows up in many applications' profiles.

It seems like most of the time is in mozilla::ipc::shared_memory::Create, mozilla::ipc::shared_memory::Handle::Map, and mozilla::ipc::shared_memory::MappingBase::~MappingBase. Is it possible that we're creating a fresh shmem for every call?

Blocks: webgpu-perf
Type: enhancement → defect

Is it possible that we're creating a fresh shmem for every call?

Yep!

2 unity demos and project prismatic stutter/have low FPS and looking at profiles it seems that GPUQueue.writeBuffer is the main bottleneck:

Blocks: 1963161, 1954080

I added a profiler marker for GPUQueue.writeBuffer and here are the results (keep in mind these are per frame):

Looking at the parts that make up GPUQueue.writeBuffer:

Name mozilla::ipc::IProtocol::ChannelSend total shmem create shmem map shmem unmap shmem
Skinning Demo 58% 28.1% 12% 6.1% 10%
Boat Demo 50% 36.6% 17% 7.6% 12%
Project Prismatic 54% 34.2% 16% 6.2% 12%
Marching Cubes 34% 44.3% 15.3% 12% 17%

Talking with Nical and JimB in our matrix channel, we think we can speed up GPUQueue.writeBuffer in two ways:

  • Reuse shmem by introducing a pool (full logic TBD)
  • Reduce overhead of IPDL: Bug 1968122
See Also: → 1968122
No longer blocks: 1937100

Removed 1937100 as a blocker, since this bug has nothing to do with GC.

Assignee: nobody → ttanasoaia
Status: NEW → ASSIGNED

D253549 slightly improves performance but the main overhead is IPDL calls (Bug 1968122).
I should be able to put up the patch stack for Bug 1968122 today, it improves performance even more (the content timeline is now nearly empty) but apps making heavy use of GPUQueue.writeBuffer are still stuttering since we create and destroy a staging buffer for each writeBuffer call in wgpu.

The obvious solution would be to reuse staging buffers and we might end up doing that but I wonder if those writeBuffer calls only write to a few destination buffers, if they do, we could coalesce the calls since we are already buffering them.

Pushed by ttanasoaia@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/8b2c72e3e646 https://hg.mozilla.org/integration/autoland/rev/56f124668fe9 add `QueueWriteBufferInline` to avoid shmem overhead on small buffers r=webgpu-reviewers,nical
No longer blocks: 1963161
See Also: → 1963161

A possible optimization for CPU-backed buffers would be to map them and copy the data directly without an additional staging buffer.

See Also: → 1994733
Assignee: ttanasoaia → nobody
Status: ASSIGNED → NEW
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: