Repository navigation
fix(host): stop the wire capture-grid drifting ahead at non-native refresh - #77
Conversation
…fresh
The host does not put the real capture stamp on the wire. It puts a steady-grid
point, wire_grid_ns, advanced by one requested `interval` per submission. The
grid was re-seeded only when it fell more than 2 * interval BEHIND submit_ns;
there was no correction when it ran AHEAD.
Frame-driven pacing iterates at the SOURCE arrival rate, not the requested rate
("arrivals are the clock"), so a client asking for 60 Hz against a 144 Hz
compositor advanced the grid ~2.4x faster than wall clock and walked it into the
future without bound, where the behind-only guard can never observe it
(saturating_sub yields 0).
Measured on the live nixos host, 1080p requested 60 on a 144 Hz desktop:
H1 first 60 Hz attempt: 0 frames, no 0xCF timing datagrams at all
H2 second 60 Hz attempt: 771 frames but only 8 timing samples, latency
p95 = p99 = max = 454 ms
H3 back to 144 Hz: 1606 frames, 1605 timing samples, p50 8.5 ms
Consecutive 144 Hz sessions were unaffected (1559/1598/1694 frames).
Fix: extract the grid policy into a pure WireGrid with a symmetric ahead-reseed
and a min(grid, submit_ns) emit clamp. The 144-on-144 path is byte-identical;
that is asserted by a test rather than argued.
Tests: three unit tests added (native identity, 60-on-144 drift, reverse
mismatch). The crate cannot link on this Windows desk because the vendored
libopus CMake build fails, so the in-crate tests did not execute here; they were
executed out of tree with rustc, 4/4 pass, and the pre-fix grid was measured
drifting ~1.94 s ahead over 200 frames.
tx-agent: jcode
tx-validated: none in-crate (audiopus_sys CMake failure on Windows); out-of-tree
rustc harness 4/4 pass; rustfmt clean
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
vindeckyy
left a comment
There was a problem hiding this comment.
Three nits from my review. The code is solid, these are all cosmetic. Since this is already merged they need applying by hand, not one click.
| if let Some(g) = self.next_ns { | ||
| if g.saturating_sub(submit_ns) > interval_ns.saturating_mul(2) { | ||
| self.next_ns = Some(if plausible { | ||
| frame_pts_ns.min(submit_ns) |
There was a problem hiding this comment.
| frame_pts_ns.min(submit_ns) | |
| frame_pts_ns |
| /// This is the 60 Hz-requested-on-a-144 Hz-compositor case: the loop follows the *source* arrival | ||
| /// rate (frame-driven pacing) but advances the grid by the *requested* interval, so a slower | ||
| /// request on a faster source outruns wall clock by (requested/actual)x and would otherwise drift | ||
| /// into the future without bound - which the behind-only guard can never see. |
There was a problem hiding this comment.
| /// into the future without bound - which the behind-only guard can never see. | |
| /// into the future without bound - which the behind-only guard can never see. |
| repeat: bool, | ||
| interval_ns: u64, | ||
| ) -> u64 { | ||
| let fresh = !repeat && plausible; |
There was a problem hiding this comment.
| let fresh = !repeat && plausible; | |
| debug_assert!(interval_ns > 0, "a zero interval would trip both stall guards every submission"); | |
| let fresh = !repeat && plausible; |
What
Stop the host's wire capture timestamp from drifting into the future when a client asks for a refresh rate that differs from the compositor's actual rate.
Why
The host does not put the real capture stamp on the wire. It puts a steady-grid point,
wire_grid_ns, advanced by one requestedintervalper submission, and re-seeds it only when it falls more than2 * intervalbehindsubmit_ns. There is no correction when it runs ahead.Frame-driven pacing iterates at the source arrival rate ("arrivals are the clock"), so a client asking for 60 Hz against a 144 Hz compositor advances the grid ~2.4x faster than wall clock and walks it into the future without bound. The behind-only guard can never observe a future grid, because
submit_ns.saturating_sub(g)saturates to 0.Measured on the live nixos host, 1080p requested 60 on a 144 Hz desktop:
0xCFtiming datagrams at allThree consecutive 144 Hz sessions were unaffected (1559 / 1598 / 1694 frames), which is why this never showed up in normal use.
This also explains a long-standing reporting oddity: the probe's
xferstage is a residual (host_us - (queue + encode + pace)), andhost_usis measured against the grid whilequeue_usis measured against the realframe.pts_ns. The two agree only while the grid has not drifted, so a flat ~5.3 ms "xfer" at 144 Hz is an accounting gap, and at 60 Hz the same expression saturates to 0.How
WireGridstate machine.min(grid, submit_ns)clamp on emit.Tests
Three new unit tests: native-rate identity, 60-on-144 drift, and the reverse mismatch.
cargo test -p slipstream-host --bins(the package has no lib target): 377 tests, 371 passed, 6 failed. All three new grid tests pass. The 6 failures are pre-existing platform-mismatch tests that assert Linux behaviour while running on Windows -library::art(x2),mgmt::compositors_lists_all_backends_with_flags,ops::store::sources::published_index_signature_verifies,session::gamelease::a_launch_always_gets_a_reference_instant_to_adopt_against,protocol::slipstream1::c_abi_connection_roundtrip- none in the touched code.cargo check -p slipstream-hostexits 0.Notes
Until this lands, the practical mitigation is to pin sessions to the desktop's real mode. Do not request 60 Hz against a 144 Hz desktop.