Closed Bug 1425451 Opened 8 years ago Closed 8 years ago

Make WR hit-testing robust to timing irregularities

Categories

(Core :: Graphics: WebRender, enhancement, P1)

Other Branch
enhancement

Tracking

()

RESOLVED FIXED

People

(Reporter: kats, Assigned: kats)

References

Details

(Whiteboard: [gfx-noted][triage])

Attachments

(1 file)

The current plan is that Nical's transaction work will address this. It might be possible to fix it in other, less-invasive, ways as well but for now I'm ok with waiting.
Depends on: 1425453
The transaction stuff is on inbound now, and I believe it should fix this. Picking up this bug to verify that I don't see the problems I was seeing before.
Assignee: nobody → bugmail
Turns out this isn't yet fixed with the current set of transaction patches from bug 1425453. The reason is that we still do the "SetDisplayList" and "GenerateFrame" operations in separate transactions, and a hit-test query can sneak in between. Either we need to expand the lifetime of a transaction or we need to force a GenerateFrame (or whatever relevant sub-parts of that we need) before doing the hit-test. Also for reference the way I'm testing this is by running (on Linux): MOZ_WEBRENDER=1 MOZ_ACCELERATED=1 xr ./mach mochitest --setpref gfx.webrender.hit-test=true --keep-open=false gfx/layers/apz/test/mochitest/test_group_hittest.html and checking for deterministic output. In theory this test should pass (and it does if I stick some code in render_backend to publish a document before doing the hit test) but currently it produces nondeterministic failures.
:nical, do you have any plans to expand the transaction lifetimes, so that we never do a SetDisplayList without a GenerateFrame? If not then maybe I'll just modify the HitTest impl in WR to do this instead.
^
Flags: needinfo?(nical.bugzilla)
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #4) > :nical, do you have any plans to expand the transaction lifetimes, so that > we never do a SetDisplayList without a GenerateFrame? If not then maybe I'll > just modify the HitTest impl in WR to do this instead. I don't have a specific plan related to this although I do have opinions (but you own the decision). What would make most sense to me is to sample animated properties and hit testing on the render backend thread just before generating the frame instead of doing it on the compositor (assuming these things are cheap enough to not eat a large part of the frame budget). That way we could send the display list and generate the frame in the same transaction, and hit testing would always operate on the latest built scene without having to worry about the number of scenes in flight and other raciness situations. That said I don't have a complete mental picture of everything that ties into APZ so I my suggestion might be off. The pipeline would go something like: > build transaction (C) -> receive transaction (RB) -> build scene (W) -> swap scene (RB) -> hit test/APZ/anim (RB) -> generate frame (RB) -> render (R) > (C): compositor thread > (RB): render backend thread > (W): worker thread (but currently it's still the render backend thread) > (R) renderer thread With a completely linear dependency chain instead of having two dependencies coming from the compositor (what we have now, which creates the races). Frames caused by animations or scrolling without a new scene would start directly at the hit test/APZ/anim stage on the current scene. If we delay sending the transaction containing the DL until the time we call GenerateFrame, it means that we lose some parallelism since we don't get a chance to start building the scene earlier. Also we'd then sample APZ and animations before building the scene instead of after so the timings would not be as accurate when the scene takes long to build. If we generate a frame as soon as we receive the display list, we don't get any throttling from the frame rate and receiving pieces of the display list from multiple sources (content and chrome) in the same 16ms span. So that's my least favorite solution.
Flags: needinfo?(nical.bugzilla)
My explanation might be a bit confusing. In the description of the pipeline, "generate frame (RB)" really means the moment where we generate the frame and not the GenerateFrame() call on TransactionBuilder. All API calls (SetDisplayList, GenerateFrame, etc.) would happen in "build transaction". If there is no display list (and thus no scene to re-build), then the "build scene" and "swap scene" steps are skipped.
Would this plan mean that hit testing will not block on blob image rasterization? (That's what seems to be happening at the moment, see bug 1429363.)
I'm not sure I fully understand. I'm going to take your pipeline and remove "hit testing" from it because IMO it does not make sense to lump it in with "APZ/anim". IIUC, the APZ/anim step happen per-vsync, when we are take the current async offsets and apply them to the thing that the user will see. However, hit-testing can happen at any time, when we get an input event from the user. So I want to deal with it separately. Here's the pipeline (without hit-testing), which seems reasonable to me: build transaction (C) -> receive transaction (RB) -> build scene (W) -> swap scene (RB) -> APZ/anim (RB) -> generate frame (RB) -> render (R) Now you said: > What would make most sense to me is to sample > animated properties and hit testing on the render backend thread just before > generating the frame instead of doing it on the compositor (assuming these > things are cheap enough to not eat a large part of the frame budget). Agreed, we should do the sampling as late as possible in order to have the visual rendering as up-to-date as possible. > If we delay sending the transaction containing the DL until the time we call > GenerateFrame, it means that we lose some parallelism since we don't get a > chance to start building the scene earlier. Also we'd then sample APZ and > animations before building the scene instead of after so the timings would > not be as accurate when the scene takes long to build. So correct me if I'm wrong, but this to me implies that we should send one transaction (which includes a SetDisplayList and UpdateResources and stuff, but does NOT include a GenerateFrame) from the C -> RB when we get an updated display list from content. And we should send another transaction (which does a APZ/anim updates and a GenerateFrame, but no SetDisplayList/UpdateResources) per vsync to kick off the frame rendering. This seems reasonable, but then we need to make sure that any hit-testing that happens between these two transactions uses the "old" display list and scene information (the one that was used in the rendering that is still visible to the user). It seems that currently that is not the case. > If we generate a frame as soon as we receive the display list, we don't get > any throttling from the frame rate and receiving pieces of the display list > from multiple sources (content and chrome) in the same 16ms span. So that's > my least favorite solution. Agreed, and this supports my above interpretation that you want two separate transactions for the display list and generate frame steps. To add hit-testing back into the model, I think we have a separate pipeline: input event (C) -> hit test (RB) -> hit result (C) which must always produce a correct result, regardless of how it's interleaved with your pipeline. So we actually have two pipelines: 1. build transaction (C) -> receive transaction (RB) -> build scene (W) -> swap scene (RB) -> APZ/anim (RB) -> generate frame (RB) -> render (R) 2. input event (C) -> hit test (RB) -> hit result (C) Right now I think the "build scene/swap scene" is kind of split in that part of it (updating the display list) happens as part of the "receive transaction" and part of it (updating the clip_scroll_tree) happens as part of "generate frame". So the interleaving where (2) happens at the "APZ/anim" step in (1) produces a garbage result. After thinking about this some more, I'm not sure if the problem I'm trying to fix is actually orthogonal to the transaction stuff or not. I'm going to try and wrap my head around it some more, but in the meantime any comments you have are welcome. [1] https://searchfox.org/mozilla-central/rev/137f1b2f434346a0c3756ebfcbdbee4069e15dc8/gfx/webrender/src/frame_builder.rs#1695
(In reply to Markus Stange [:mstange] from comment #9) > Would this plan mean that hit testing will not block on blob image > rasterization? (That's what seems to be happening at the moment, see bug > 1429363.) I haven't looked into this but it seemed to me that the hit-testing you're referring to is the main-thread hit-testing, so it's unrelated to this bug. This bug is about the compositor hit-testing which doesn't touch the main thread.
(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #11) > (In reply to Markus Stange [:mstange] from comment #9) > > Would this plan mean that hit testing will not block on blob image > > rasterization? (That's what seems to be happening at the moment, see bug > > 1429363.) > > I haven't looked into this but it seemed to me that the hit-testing you're > referring to is the main-thread hit-testing, so it's unrelated to this bug. > This bug is about the compositor hit-testing which doesn't touch the main > thread. I misunderstood. We discussed this on IRC and I left a comment at https://bugzilla.mozilla.org/show_bug.cgi?id=1429363#c2 about it.
So I spent some more time wrapping my head around the code that governs all this and I understand nical's comment a lot better now. I think what I said in comment 10 still mostly makes sense, although I didn't fully realize that nical meant the APZ/anim updates should be queried via a rust->C++ callback during the frame rendering step. But I don't see any real objections to that, as long as we have the timestamp of the upcoming vsync handy. Also I think in order to do all this transaction/pipeline stuff (in particular, moving the build_scene step to a worker thread), we need to first solve the problem I was actually trying to solve. That problem stems from the fact that the clip scroll tree is necessary for hit-testing, but gets clobbered by the build_scene step (which currently happens on the RB thread). In order to move that step to the worker thread it needs to operate on a second copy of the clip scroll tree, which would get swapped in as part of the swap_scene step. That implies the RB thread would keep the clip_scroll_tree from the previous render around until the swap_scene, and so hit-tests during that phase would work correctly. So while this transaction/pipeline stuff all makes sense, I still need to solve the hit-testing problem first. I'm continuing the discussion for that on servo/webrender#2099.
The PR has merged, so the next WR update will resolve this bug.
Depends on: 1431776
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
nical, do you know how far we are from moving the build-scene step into a worker thread? Doing that would help fix both bug 1433663 and the debug assertion failures that I'm seeing with WR hit-testing enabled, because we can then stop triggering a render from the WR side that gecko isn't really expecting.
Flags: needinfo?(nical.bugzilla)
I can make this my next priority after https://bugzilla.mozilla.org/show_bug.cgi?id=1432708 which shouldn't take much time. How easy building scenes off the backend thread will be I am not 100% sure yet, maybe a few days of work if I am lucky.
Flags: needinfo?(nical.bugzilla)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: