forge
Explore
Log in

Don't you dare go Hollow

A forward reposition replaces the skip, never adds to it

Browse files at this commit

1077f5fa1b0de48b6469a35f299fc881d754ad51Ahmet Kaan GümüşParent: dd77ab0
  • fix
    • a forward reposition replaces the skip, never adds to it
Show full message
🐛 fix(engine-hw): a forward reposition replaces the skip, never adds to it

pump's one law is 'the picture delivered is position + skip': position
advances for every handle popped, dropped ones included, so a forward
reseek to a target ahead of the decoder must leave skip = ahead --
exactly the distance still to walk. The landed code added to whatever
skip was still standing, so a second forward reseek before the first
drained (rapid small seeks on the kept worker, or a flush whose RAP
skip was undrained when a forward span was asked) delivered ahead
frames past its target -- silently, because the pictures kept coming.

forward_skip() is the seam the law lives in, with a pinning test for
the stacked-forward and flush-then-forward shapes (red on the add,
green on the replace).
crates/engine-hw/src/lib.rsmodified+61 -2
@@ -188,6 +188,18 @@ fn reposition(position: i64, target: i64, frame_count: u32, limit: u32) -> Repos
188 }188 }
189 }189 }
190 190
191+/// The skip a forward reposition leaves standing: `ahead` itself, replacing
192+/// whatever skip was undrained -- `_standing` is read by no one, on purpose.
193+/// [`Session::pump`] advances `position` for every handle it pops, dropped
194+/// and delivered alike, so the next picture delivered is always
195+/// `position + skip`: only a replacement keeps that on the target. An
196+/// accumulate would land `ahead` frames past it -- and silently, because the
197+/// pictures keep arriving (a stacked reseek before the first drains, or a
198+/// flush whose RAP skip is still standing when a forward span is asked).
199+fn forward_skip(_standing: u32, ahead: u32) -> u32 {
200+ ahead
201+}
202+
191 struct Session {203 struct Session {
192 decoder: Decoder,204 decoder: Decoder,
193 /// NV12 (or, for a 10-bit stream, P010) descriptor for `vaGetImage`,205 /// NV12 (or, for a 10-bit stream, P010) descriptor for `vaGetImage`,
@@ -442,8 +454,12 @@ impl Session {
442 // not the access unit half-fed to it, not the pictures already454 // not the access unit half-fed to it, not the pictures already
443 // waiting in `ready` -- the skip walks past all of them exactly455 // waiting in `ready` -- the skip walks past all of them exactly
444 // as it walks past the ones still to decode, one `position` step456 // as it walks past the ones still to decode, one `position` step
445- // per handle either way.457+ // per handle either way. It *replaces* whatever skip was
446- self.skip = self.skip.saturating_add(ahead);458+ // standing, never adds to it: `position` already counts every
459+ // handle popped, dropped ones included, so the picture delivered
460+ // is always `position + skip` ([`forward_skip`]) -- an accumulate
461+ // would land `ahead` frames past the target, silently.
462+ self.skip = forward_skip(self.skip, ahead);
447 return Ok(());463 return Ok(());
448 }464 }
449 self.decoder.get().flush().map_err(|e| e.to_string())?;465 self.decoder.get().flush().map_err(|e| e.to_string())?;
@@ -2104,4 +2120,47 @@ mod tests {
2104 assert_eq!(forward_limit(f64::NAN), 0);2120 assert_eq!(forward_limit(f64::NAN), 0);
2105 assert_eq!(forward_limit(-30.0), 0);2121 assert_eq!(forward_limit(-30.0), 0);
2106 }2122 }
2123+
2124+ /// The drain machine's one law, held across *stacked* repositions: the
2125+ /// picture delivered is `position + skip`, `position` advancing one per
2126+ /// handle popped ([`Session::pump`]). A second forward reseek before the
2127+ /// first's skip has drained must land on its own target -- the skip is
2128+ /// replaced ([`forward_skip`]), never added to, or every reseek inside
2129+ /// another's window walks its predecessor's frames past the target and
2130+ /// the pictures keep arriving, only wrong.
2131+ #[test]
2132+ fn stacked_forward_reseeks_land_exactly_on_their_target() {
2133+ use Reposition::Forward;
2134+ let (count, limit) = (10_000u32, forward_limit(30.0));
2135+ let land = |position: i64, skip: u32| position + i64::from(skip);
2136+ let (mut position, mut skip) = (100i64, 0u32);
2137+ let Forward(ahead) = reposition(position, 110, count, limit) else {
2138+ panic!("110 is within the reach of 100")
2139+ };
2140+ skip = forward_skip(skip, ahead);
2141+ let Forward(ahead) = reposition(position, 114, count, limit) else {
2142+ panic!("114 is within the reach of 100")
2143+ };
2144+ skip = forward_skip(skip, ahead);
2145+ assert_eq!(land(position, skip), 114, "the second target, exactly");
2146+
2147+ // A flush whose RAP skip is still undrained when a forward span is
2148+ // asked: the flush stood at its RAP with `skip` toward its own
2149+ // target, and the forward reseek through that window replaces it.
2150+ position = 200;
2151+ skip = 12;
2152+ let Forward(ahead) = reposition(position, 208, count, limit) else {
2153+ panic!("208 is within the reach of 200")
2154+ };
2155+ skip = forward_skip(skip, ahead);
2156+ assert_eq!(land(position, skip), 208, "a flush's undrained skip does not compound");
2157+
2158+ // ...and a reseek to exactly where the decoder stands cancels
2159+ // whatever was standing: the next handle is shown, not skipped past.
2160+ let Forward(ahead) = reposition(position, position, count, limit) else {
2161+ panic!("a session's own position is within its reach")
2162+ };
2163+ skip = forward_skip(skip, ahead);
2164+ assert_eq!((ahead, land(position, skip)), (0, position));
2165+ }
2107 }2166 }