Closed Bug 2055839 Opened 4 months ago Closed

Accelerated canvas performance issues on Metal ANGLE

Categories

(Core :: Graphics: Canvas2D, defect)

Unspecified
macOS
defect

Tracking

()

RESOLVED FIXED
155 Branch
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_FAN in DrawRectAccel() -> 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 with GL_TRIANGLES
  • Draw call overhead, and a huge number of draw calls
    • Can see this in rx::ContextMtl::setupDraw() in the above profile, and also manifests in CopyToSwapChain() under endEncoding() when switching the draw framebuffer from mFramebuffer to 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 DrawRectAccel drastically improved the performance. (Replacing some of the current uniform data with instance attributes)

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.

Severity: -- → S3

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.

Assignee: nobody → jnicol
Status: NEW → ASSIGNED

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.

Pushed by jnicol@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/acca47549fb0 https://hg.mozilla.org/integration/autoland/rev/9ec93414071b Ensure accelerated canvas uses glMapBufferRange fast path on Metal ANGLE. r=gfx-reviewers,gw https://github.com/mozilla-firefox/firefox/commit/c547c203c14b https://hg.mozilla.org/integration/autoland/rev/c9c78ae99215 Use shared PBO for DrawTargetWebgl uploads. r=gfx-reviewers,lsalzman
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch
Whiteboard: [fxpe]
Regressions: 2059433
Regressions: 2059291
QA Whiteboard: [qa-triage-done-c156/b155]
Regressions: 2064463
Regressions: 2080436
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: