Accelerated canvas performance issues on Metal ANGLE
Categories
(Core :: Graphics: Canvas2D, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox155 | --- | fixed |
People
(Reporter: jnicol, Assigned: jnicol)
References
(Blocks 1 open bug)
Details
(Whiteboard: [fxpe])
Attachments
(2 external files)
Generally using Metal ANGLE performance looks decent. On Apple silicon, we get improvements in the speedometer 3 canvas subtests. But it's more of a mixed bag on motionmark: apple silicon, intel.
Here is a profile of MotionMark 1.3 taken on a 2019 Intel Macbook Pro: https://share.firefox.dev/4yrNbms
If we look first at the canvas paths subtest: https://share.firefox.dev/4yqRj67
There's a huge amount of time spent within glBufferSubData() called from DrawPathAccel(). This is a problem we've seen before in bug 1826134, which we fixed by using unsynchronized mappings instead of glBufferSubData. But in bug 1827047 we saw this regressed performance on D3D ANGLE, so avoided that path when IsANGLE() is true. At the time IsANGLE() implied D3D, but that's no longer the case. We do in fact want to use unsynchronized mappings over glBufferSubData on Metal ANGLE.
Now if we look at canvas lines: https://share.firefox.dev/3T1pcul
There are a few things to unpack here:
- Lots of time spent uploading textures - https://share.firefox.dev/4aZkiUR
- Metal allocates a staging buffer for each upload, and most of the cost here is allocating those buffers. We certainly don't want to disable the staging buffer flag, as that makes performance much worse. (Presumably stalling the pipeline until pending texture reads have finished before the upload). We should instead allocate our own larger fixed size PBOs instead of making the driver allocate many small/varying size ones.
- Perhaps some overhead from using
GL_TRIANGLE_FANinDrawRectAccel() -> DrawQuad()- https://share.firefox.dev/4wbnzJd- ANGLE appears to emulate this, see the
drawTriFanArraysWithBaseVertex()call, but I'm not sure how much overhead there really is to the emulation. Probably not much different to us using an index buffer ourself to achieve the same result withGL_TRIANGLES
- ANGLE appears to emulate this, see the
- Draw call overhead, and a huge number of draw calls
- Can see this in
rx::ContextMtl::setupDraw()in the above profile, and also manifests inCopyToSwapChain()underendEncoding()when switching the draw framebuffer frommFramebufferto the swapchain's FB - https://share.firefox.dev/4wFTNvY - I don't know exactly why this is so slow, but reducing the number of draw calls we use for canvas lines by batching together consecutive calls to
DrawRectAcceldrastically improved the performance. (Replacing some of the current uniform data with instance attributes)
- Can see this in
| Assignee | ||
Comment 1•4 months ago
|
||
Here's a profile with some vibe-coded fixes for the aforementioned issues: https://share.firefox.dev/4w9cckO
The canvas lines test at 2:30 is looking much better.
You may also notice that the canvas paths test at 2:00 now falls back to unaccelerated canvas whereas as previously it did not. I think this is because as the complexity scales up, without the glMapBufferRange(UNSYNCHRONIZED) fix in particular we become so slow that we don't actually complete enough failed frames. With the fix, we very quickly render lots of frames with path cache misses, and fallback to unaccelerated. For the arcs test we quickly fall back to unaccelerated both with and without ANGLE.
Updated•4 months ago
|
| Assignee | ||
Comment 2•4 months ago
|
||
Bug 1827047 prevented us using this fast path on ANGLE due to
performance regressions on D3D. At the time, IsANGLE() could only mean
D3D, but now it can also mean Metal where we do in fact want this fast
path.
Updated•4 months ago
|
| Assignee | ||
Comment 3•4 months ago
|
||
Metal ANGLE allocates a staging buffer for each glTexSubImage texture
upload. With accelerated canvas on MotionMark's canvas lines subtest
this results in a lot of overhead during upload.
This patch implements a simple shared PBO upload mechanism for
DrawTargetWebgl. A fixed-size 1MiB PBO is allocated, and each upload
appends its data to the end of the buffer before uploading. The buffer
is orhpaned once full. Individual allocations too large for the buffer
avoid the PBO path altogeher.
Comment 5•4 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/9ec93414071b
https://hg.mozilla.org/mozilla-central/rev/c9c78ae99215
Comment 6•4 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/9ec93414071b
https://hg.mozilla.org/mozilla-central/rev/c9c78ae99215
Comment 7•4 months ago
|
||
| bugherder | ||
Comment 8•4 months ago
|
||
| bugherder | ||
Updated•3 months ago
|
Updated•3 months ago
|
Updated•3 months ago
|
Description
•