Closed Bug 1979110 Opened 1 year ago Closed 1 year ago

Implement reusing of WebGPU external textures

Categories

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

task

Tracking

()

RESOLVED FIXED
143 Branch
Tracking Status
firefox143 --- fixed

People

(Reporter: jnicol, Assigned: jnicol)

References

(Blocks 1 open bug)

Details

Attachments

(2 external files)

See step 2 here:

If the current image contents of source are the same as the most recent importExternalTexture() call with the same descriptor (ignoring label), and the user agent chooses to reuse it:

  1. Let previousResult be the GPUExternalTexture returned previously.
  2. Set previousResult.[[expired]] to false, renewing ownership of the underlying resource.
  3. Let result be previousResult.
Assignee: nobody → jnicol
Priority: -- → P1

And then eagerly destroy external textures and external texture sources
when possible.

We must retain a reference to the layers::Image from which an external
texture source was imported as long as any work involving external
textures created from that source is outstanding. This prevents the
decoder from attempting to recycle the underlying resource too early,
e.g. decoding a future video frame into the texture while wgpu is still
to render the previous frame.

On the other hand, we don't want to hold on to resources longer than
required in order to prevent excess memory usage.

For each external texture, keep track of submission index at which work
involving the external texture was last submitted, and the index of the
last such submission whose work has since completed. When all submitted
work for an external texture has completed, and the external texture
has been expired, eagerly destroy the external texture.

Additionally, when the external texture is destroyed also release its
reference to the external texture source. This means the source will
itself be destroyed as soon as there are no more live external textures
that were created from it. When the source is destroyed the last
reference to the layes::Image will be dropped, indicating to the
decoder that it can reuse the underlying resources.

The WebGPU spec allows us to return a previously imported external
texture from importExternalTexture() when provided with the same
descriptor (ignoring the label), as long as the current image contents
of the source is the same. For applications that import a large number
of external textures from the same source, this can be a significant
performance improvement.

This implementation maintains a cache of imported external texture
sources, keyed by the "serial" of the layers::Image they were imported
from. Additionally, each source maintains a cache of external textures
that have been created from it. This is keyed by the contents of their
descriptor, ignoring the label (as per the spec) and the "source" (as
the cache is owned by the source) leaving just the color space.

Using these two separate levels of cache means that we not only create
a single single external texture for multiple imports with the same
descriptor, but when importing from the same source with an otherwise
different descriptor we are still able to share the underlying plane
textures.

Pushed by jnicol@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/361fefaf487d https://hg.mozilla.org/integration/autoland/rev/ff61246f69d0 Hold reference to layers::Image until all external texture work using it is done. r=webgpu-reviewers,teoxoy https://github.com/mozilla-firefox/firefox/commit/95a29549cc25 https://hg.mozilla.org/integration/autoland/rev/3f7509a33b44 Allow reusing previously imported external textures. r=webgpu-reviewers,teoxoy
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
QA Whiteboard: [qa-triage-done-c144/b143]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: