Closed Bug 2083416 Opened 29 days ago Closed 26 days ago

Hardware video decoders can use wrong SyncObjectClient causing tearing/wrong frames to be displayed

Categories

(Core :: Graphics, defect)

Desktop
Windows
defect

Tracking

()

RESOLVED FIXED
160 Branch
Tracking Status
firefox160 --- fixed

People

(Reporter: aosmond, Assigned: aosmond)

References

Details

(Keywords: perf-alert)

Attachments

(4 external files)

In order to synchronize hardware video decoding with the compositor, it will prefer to use D3D11 fences and/or decoding on the compositor device. When those are unavailable, we can use a shared sync object via SyncObjectD3D11Client and SyncObjectD3D11Host.

On SWGL + D3D11, we get one sync object for our single ID3D11Device using for compositing. That means all windows will share the same the same sync object:
https://searchfox.org/firefox-main/rev/d0e0fc69c10b345e8e1a83bae3d2da774970704d/gfx/webrender_bindings/RenderCompositorD3D11SWGL.cpp#72

On full HW-WR, we get one sync object per RenderCompositorANGLE, which maps to each window:
https://searchfox.org/firefox-main/rev/d0e0fc69c10b345e8e1a83bae3d2da774970704d/gfx/webrender_bindings/RenderCompositorANGLE.cpp#168

Now normally the latter isn't a problem, but today we get the sync handle we want via TextureFactoryIdentifier when the video decoder is created. Since a tab can move between windows, that means we can end up using the wrong sync object. This can cause tearing and frame skips (but is otherwise safe). This won't happen with SWGL + D3D11 since it is always the same sync object.

Because it can be very complicated to synchronize which sync object the video decoder should be using, I think we should just follow the same model from SWGL + D3D11 with HW-WR. Most users are not impacted by this since they have D3D11 fence support, or they use the same ID3D11Device for compositing and decoding:
https://searchfox.org/firefox-main/rev/d0e0fc69c10b345e8e1a83bae3d2da774970704d/gfx/thebes/DeviceManagerDx.cpp#1178

Doing so will not only fix flickering issues for these users, it will also make refactors such as bug 2082607 safer.

Summary: Hardware-decoded video can be composited before decoding finishes after its tab moves to another window on some Windows configurations → Hardware video decoders can use wrong SyncObjectClient causing tearing/wrong frames to be displayed

The reuse decoder device feature was only recorded when the pref was on, and it
showed as enabled even when reuse could not happen: on AMD it was forced on
outside of gfxConfig, and it did not account for software WebRender or a
compositor device without video support. Fence support was not reported at all.
Together these decide whether video uses the D3D11 sync object.

The parent now decides decoder device reuse, including the AMD requirement, in
InitPlatformHardwareVideoConfig, using the adapter from gfxInfo like the
blocklist does. The GPU process reports whether the compositor device supports
video and fences in D3D11DeviceStatus, which is used to report whether the
compositor device is actually reused.

gfx.direct3d11.reuse-decoder-device.force-disabled disables reuse even where it
is required, and gfx.direct3d11.fences-enabled can turn fences off. Together
they force video onto the sync object on hardware that would otherwise use
fences or a shared device.

Each RenderCompositorANGLE created its own sync object, so a video decoder only
synchronized with the window whose sync handle it was given. That window may
not be the one compositing the video, for example after its tab moved to
another window, or it may be gone. SWGL with D3D11 already shared one sync
object per device through DeviceAttachmentsD3D11.

DeviceManagerDx now creates the sync object together with the compositor
device and drops it with the device. It is handed out together with the device,
so a compositor always gets the sync object of the device it renders with:
DeviceAttachmentsD3D11 receives it when created, and RenderThread keeps it with
the singleton GL context that ANGLE renders with. It is also created for WARP
devices, which ANGLE already did; the WARP exception dated from Windows 7.

SyncObjectHost becomes atomically refcounted because it is now shared across
threads. A sync object timeout on any window still triggers a device reset, as
before, but every window now waits on the same keyed mutex.

CompositorD3D11 acquired the sync object at the start of every frame, while
RenderCompositorANGLE only does so while a registered texture needs it
(RenderThread::SyncObjectNeeded). Both now share the same sync object, so give
SWGL with D3D11 the same behaviour, including handling a timeout as a device
reset instead of skipping the frame or crashing.

These textures always have a write fence, which LockInternal waits on, and the
producer never registers them with the sync object. Requesting the sync object
only made the compositors acquire its keyed mutex for nothing.

Attachment #9664164 - Attachment description: Bug 2083416 - Part 3. Only synchronize with the sync object when needed in RenderCompositorD3D11SWGL. → Bug 2083416 - Part 3. Synchronize with the sync object once per frame, after the frame update, and only when needed.
See Also: 2082607 →
See Also: → 2083548
Pushed by aosmond@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/a0818a07cfc7 https://hg.mozilla.org/integration/autoland/rev/e9f895b479bd Part 1. Report decoder device reuse and D3D11 fence support accurately, and add prefs to disable them. r=gfx-reviewers,sotaro https://github.com/mozilla-firefox/firefox/commit/481e9ef6a556 https://hg.mozilla.org/integration/autoland/rev/55ccc25015e7 Part 2. Share one sync object per compositor device between all compositors. r=gfx-reviewers,sotaro https://github.com/mozilla-firefox/firefox/commit/3da213b28200 https://hg.mozilla.org/integration/autoland/rev/fb885e00b773 Part 3. Synchronize with the sync object once per frame, after the frame update, and only when needed. r=gfx-reviewers,lsalzman https://github.com/mozilla-firefox/firefox/commit/399eeddde62b https://hg.mozilla.org/integration/autoland/rev/f420c8f42bb4 Part 4. RenderDXGIYCbCrTextureHost does not need the sync object. r=gfx-reviewers,lsalzman
See Also: → 2084927
See Also: 2084927 →
Blocks: 2085189

Perfherder has detected a talos performance change from push f420c8f42bb4e8ee67b1f19cc7608779e477bf3d.

No action is required from the author; this comment is provided for informational purposes only.

Improvement Test Platform Options Absolute values [old vs new]
2% tart (doc) windows11-64-24h2-shippable e10s fission stylo webrender-sw 1.83 -> 1.79

Need Help or Information?

If you have any questions, please reach out to acseh@mozilla.com. Alternatively, you can find help on Slack by joining #perf-help, and on Matrix you can find help by joining #perftest.

Details of the alert can be found in the alert summary, including links to graphs and comparisons for each of the affected tests.

Keywords: perf-alert

What fun, the unnecessary sync was causing us 2% on SWGL + D3D11 compositing! Easy win.

QA Whiteboard: [qa-triage-done-c161/b160]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: