Closed Bug 1777426 Opened 2 years ago Closed 2 years ago

Support fast readbacks in CopyToSwapChain with async present

Categories

(Core :: Graphics: Canvas2D, defect)

defect

Tracking

()

RESOLVED FIXED
104 Branch
Tracking Status
firefox104 --- fixed

People

(Reporter: lsalzman, Assigned: lsalzman)

References

(Blocks 2 open bugs)

Details

Attachments

(5 files)

Currently CopyToSwapChain creates spurious copies of the back buffer when SharedSurfaces aren't exportable (= ToSurfaceDescriptor returns Nothing from SharedSurface_Basic). These then later get read back into a CPU memory buffer when PresentFrontBufferToCompositor is used to send the buffer to RemoteTextureMap.

Conceptually, we want Present/CopyToSwapChain to just do the right thing and automatically push buffers to RemoteTextureMap, rather than secondarily needing a hidden call to PresentFrontBufferToCompositor. Then we can get rid of the need to create front buffers whose only purpose is to shuttle data to PresentFrontBufferToCompositor which then shuttles it RemoteTextureMap.

Currently CopyToSwapChain creates spurious copies of the back buffer when SharedSurfaces aren't exportable (= ToSurfaceDescriptor returns Nothing from SharedSurface_Basic). These then later get read back into a CPU memory buffer when PresentFrontBufferToCompositor is used to send the buffer to RemoteTextureMap. This has associated performance and memory costs.

Conceptually, we want Present/CopyToSwapChain to just do the right thing and automatically push buffers to RemoteTextureMap, rather than secondarily needing a hidden call to PresentFrontBufferToCompositor. Then we can get rid of the need to create front buffers whose only purpose is to shuttle data to PresentFrontBufferToCompositor which then shuttles it RemoteTextureMap.

This patch achieves this by refactoring the guts of PresentFrontBufferToCompositor into Present/CopyToSwapChain. The remote texture ids are sent along inside SwapChainOptions if async present is enabled. Those remote texture ids are cached in ClientWebGLContext so that GetFrontBuffer can return them without any subsequent need for an IPDL call.

On the parent side, CopyToSwapChain will now notice if async present is to be used and if a SurfaceFactory does not generate SharedSurfaces that can be exported. In that case it cuts out the middle man and reads from the WebGLFramebuffer's back buffer directly into a CPU buffer to send to RemoteTextureMap.

With async present we can now rely on being able to do readbacks from WebGL
in the GPU process, rather than needing CopySnapshotTo to accelerate this in
the content process. Just remove CopySnapshotTo since it doesn't help anymore.

Depends on D150720

Depends on: 1776885
Blocks: 1771139
Blocks: 1777872
Pushed by lsalzman@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b9f43d8a6c2d
Support fast readbacks in CopyToSwapChain with async present. r=sotaro,jgilbert
https://hg.mozilla.org/integration/autoland/rev/d14ac16006c6
Add pref to force async present to sync anyway so we can use remote textures. r=sotaro
https://hg.mozilla.org/integration/autoland/rev/7bd6e0c436e7
Add gfx.canvas.accelerated.async-present for toggling async present with Canvas2D independent of WebGL. r=aosmond
https://hg.mozilla.org/integration/autoland/rev/2fdaa8eca97c
Remove CopySnapshotTo in favor of async present. r=aosmond
https://hg.mozilla.org/integration/autoland/rev/509b05b741a2
Ensure MemoryTextureData frees memory when owned by RemoteTextureMap. r=aosmond,gfx-reviewers
Regressions: 1781064
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: