Implement reusing of WebGPU external textures
Categories
(Core :: Graphics: WebGPU, task, P1)
Tracking
()
| 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:
- Let previousResult be the GPUExternalTexture returned previously.
- Set previousResult.[[expired]] to false, renewing ownership of the underlying resource.
- Let result be previousResult.
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
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.
| Assignee | ||
Comment 2•1 year ago
|
||
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.
Comment 4•1 year ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/ff61246f69d0
https://hg.mozilla.org/mozilla-central/rev/3f7509a33b44
Updated•1 year ago
|
Description
•