diff --git a/crates/reims-vgpu/src/graphics/nvidia.rs b/crates/reims-vgpu/src/graphics/nvidia.rs index 0faba8e6d..dab17e277 100644 --- a/crates/reims-vgpu/src/graphics/nvidia.rs +++ b/crates/reims-vgpu/src/graphics/nvidia.rs @@ -630,7 +630,7 @@ impl HostDecoder

for NvdecDecoder

{ ) -> Result>>, BackendError> { let picture = match self.decoder.decode(au) { Ok(picture) => picture, - Err(error) if error.is_picture_error() => return Ok(picture_error(NAME, error)), + Err(error) if error.is_picture_error() => return Err(picture_error(error)), Err(error) => return Err(error.into()), }; Ok(picture.map(|picture| { diff --git a/crates/reims-vgpu/src/graphics/vaapi.rs b/crates/reims-vgpu/src/graphics/vaapi.rs index 75fc382f5..ffb768afa 100644 --- a/crates/reims-vgpu/src/graphics/vaapi.rs +++ b/crates/reims-vgpu/src/graphics/vaapi.rs @@ -1300,7 +1300,7 @@ impl HostDecoder

for VaDecoder

{ .and_then(|targets| targets.target_for(codec, output, &self.said, &self.roles)); let mut frames = match self.frames(au, target_for) { Ok(frames) => frames, - Err(error) if error.is_picture_error() => return Ok(picture_error(NAME, error)), + Err(error) if error.is_picture_error() => return Err(picture_error(error)), Err(error) => return Err(error.into()), }; let frame = match (frames.pop(), frames.len()) { diff --git a/crates/reims-vgpu/src/graphics/video_host.rs b/crates/reims-vgpu/src/graphics/video_host.rs index b0d64f19f..755223344 100644 --- a/crates/reims-vgpu/src/graphics/video_host.rs +++ b/crates/reims-vgpu/src/graphics/video_host.rs @@ -60,7 +60,8 @@ //! them waits, once its picture is decoded, for the oldest to land. The landing waits only //! for the hardware, so the wait ends. //! - **A picture of the stream that does not decode** is answered with no picture -//! ([`picture_error`]), its command buffer completing as any other: one whose bytes do not +//! ([`picture_error`], which the backend answers as its error, [`NotDecoded`], and the session +//! takes as no picture), its command buffer completing as any other: one whose bytes do not //! read as its standard reads them, one that predicts from a picture the decoder does not //! hold (as a stream's first pictures do where it starts at a P picture), and one after a //! picture that did not decode, before the decoding starts afresh at an I (H.264) or IRAP @@ -71,7 +72,10 @@ //! `kVTVideoDecoderReferenceMissingErr` and no image. The output's earlier bytes, which the //! guest's decoder hands on here, are the device's own, not Apple's concealment. What is no //! picture's (a stream the decoder does not take, an `avcC` or `hvcC` record's error) and -//! the hardware's or the host API's errors fault the command buffer. +//! the hardware's or the host API's errors fault the command buffer. A session's first such +//! picture is logged at `warn`, so a report at the default level shows that a guest was handed +//! an output the picture did not land in (a new output's zeros, which show green), and its end +//! counts them all. //! - **The event** is a shared event, as the host signals it: the runtime holds a command //! buffer's wait for it on the host until the value is reached. //! - **An end** ([`Drop`]) closes the landing thread's queue and waits up to [`TEARDOWN_WAIT`] @@ -79,7 +83,8 @@ //! alive what it lands from, so a decoder may go before its last pictures land. //! //! The session logs the first picture of each way it lands at `info` ("hardware video: ..."), -//! and its counts at its end: its pictures by the way each landed, the outputs they landed in +//! and its counts at its end: its pictures by the way each landed, the decodes that answered none +//! and how many of them were pictures of the stream that do not decode, the outputs they landed in //! ([`Outputs`]: how many surfaces' memory, and the most of it live at once), and the time the //! CPU's copies of them took. @@ -161,8 +166,8 @@ pub(crate) trait HostDecoder: Send + 'static { /// sets the session handed it, and answers its picture, which the session lands in the /// decode's output; `None` for a picture the stream's random access skips (a RASL picture /// after a CRA picture at the stream's start), and for one of the stream's pictures that does - /// not decode ([`picture_error`]), whose output gets nothing. An error faults the command - /// buffer. + /// not decode, which it answers as the error [`picture_error`] makes ([`NotDecoded`]), whose + /// output gets nothing. Any other error faults the command buffer. /// /// `au` lies in the guest's bitstream buffer, in place. Its bytes stay mapped and as they are /// until the picture answered has landed ([`HostPicture::land`] returned), or, where none is @@ -1069,20 +1074,25 @@ fn decode_fault(what: impl std::fmt::Display) -> Raise { } /// A backend's answer to a decode whose access unit is a picture of the stream that does not -/// decode, `error` (the module docs, "A picture of the stream that does not decode"): no picture. -/// The process's first of each kind of error is logged at `info` (`kind`), and the rest counted. -pub(crate) fn picture_error( - name: &str, - error: impl std::fmt::Display, -) -> Option>> { - log::info!( - kind:% = error; - "hardware video: {name}: a picture of the stream that does not decode lands nothing, its \ - output keeping its bytes: {error}" - ); - None +/// decode, `error` (the module docs, "A picture of the stream that does not decode"): the error +/// [`NotDecoded`], which the session answers as no picture, faulting nothing, and logs and counts +/// ([`HostVideoSession::not_decoded`]). +pub(crate) fn picture_error(error: impl std::fmt::Display) -> BackendError { + Box::new(NotDecoded(error.to_string())) } +/// A picture of the stream that does not decode, as its decoder said it ([`picture_error`]). +#[derive(Debug)] +pub(crate) struct NotDecoded(String); + +impl std::fmt::Display for NotDecoded { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(&self.0) + } +} + +impl std::error::Error for NotDecoded {} + /// One decode's work for the landing thread: its picture, its output and its bitstream's buffer, /// held until its value is signalled. struct Job { @@ -1151,6 +1161,8 @@ struct Counts { landed: [u64; 6], /// Decodes that answered no picture. skipped: u64, + /// Of them, pictures of the stream that do not decode ([`NotDecoded`]). + not_decoded: u64, /// Pictures that failed to land. failed: u64, /// Pictures the hardware answered failed that landed as it left them. @@ -1270,6 +1282,28 @@ impl HostVideoSession

{ landing: Some(landing), }) } + + /// Counts `not`, a decode's picture of the stream that does not decode, which lands nothing, + /// its output keeping its bytes; the session's first is logged at `warn` (the module docs, "A + /// picture of the stream that does not decode"), the rest counted at its end. Answers whether + /// it was the first, said. + fn not_decoded(&self, not: &NotDecoded) -> bool { + let first = { + let mut counts = self.counts.lock(); + counts.not_decoded += 1; + counts.not_decoded == 1 + }; + if first { + let name = self.name; + log::warn!( + kind:% = not; + "hardware video: {name}: a picture of the stream that does not decode lands \ + nothing, its output keeping its bytes (a new output's zeros): {not}; the \ + session's others are counted at its end" + ); + } + first + } } impl GraphicsVideoSession

for HostVideoSession

{ @@ -1289,7 +1323,16 @@ impl GraphicsVideoSession

for HostVideoSession

{ (state.decoder.parameter_sets(decode.parameter_sets)) .map_err(|error| decode_fault(format_args!("its parameter sets: {error}")))?; } - let picture = state.decoder.decode(au, &output).map_err(decode_fault)?; + let picture = match state.decoder.decode(au, &output) { + Ok(picture) => picture, + Err(error) => match error.downcast::() { + Ok(not) => { + self.not_decoded(¬); + None + } + Err(error) => return Err(decode_fault(error)), + }, + }; state.outputs.saw(&output); let skipped = picture.is_none(); let value = state.value + 1; @@ -1361,14 +1404,16 @@ impl Drop for HostVideoSession

{ String::new() }; log::info!( - "hardware video: {name}: a session ended after {last} decodes: landed {}; {} skipped, \ - {} failed, {} landed as the hardware failed them{outputs_said}{cpu_said}", + "hardware video: {name}: a session ended after {last} decodes: landed {}; {} skipped \ + ({} of them pictures of the stream that do not decode), {} failed, {} landed as the \ + hardware failed them{outputs_said}{cpu_said}", if landed.is_empty() { "none".to_owned() } else { landed.join(", ") }, counts.skipped, + counts.not_decoded, counts.failed, counts.landed_failed ); diff --git a/crates/reims-vgpu/src/graphics/video_host/tests.rs b/crates/reims-vgpu/src/graphics/video_host/tests.rs index 7203c269f..30aff3e38 100644 --- a/crates/reims-vgpu/src/graphics/video_host/tests.rs +++ b/crates/reims-vgpu/src/graphics/video_host/tests.rs @@ -240,11 +240,12 @@ impl HostPicture

for Picture { } } -/// A decoder that logs what it is handed and answers `answers` in turn: a picture of +/// A decoder that logs what it is handed and answers `answers` in turn (an error as it is, a +/// picture of the stream that does not decode's [`picture_error`] among them): a picture of /// `Fill(n)` for decode `n` once they run out. struct Decoder { log: Log, - answers: VecDeque, &'static str>>, + answers: VecDeque, BackendError>>, decoded: u8, most_unlanded: usize, } @@ -276,7 +277,7 @@ impl HostDecoder

for Decoder { /// A session over a decoder answering `answers`, and the log it keeps, that spares 8 pictures. fn session( p: &FakePlatform, - answers: Vec, &'static str>>, + answers: Vec, BackendError>>, log: &Log, ) -> HostVideoSession

{ session_sparing(p, answers, log, 8) @@ -285,7 +286,7 @@ fn session( /// [`session`]'s, its decoder sparing `most_unlanded` pictures. fn session_sparing( p: &FakePlatform, - answers: Vec, &'static str>>, + answers: Vec, BackendError>>, log: &Log, most_unlanded: usize, ) -> HostVideoSession

{ @@ -637,7 +638,7 @@ struct InCache { #[cfg(unix)] impl InCache { - fn new(p: &FakePlatform, answers: Vec, &'static str>>) -> Self { + fn new(p: &FakePlatform, answers: Vec, BackendError>>) -> Self { use reims_vgpu_vulkan::core::platform::values::TextureDesc; let s = session(p, answers, &Log::default()); let memory = Arc::new(Acquires { @@ -884,30 +885,63 @@ fn values_are_signalled_in_decode_order_once_landed() { /// A picture of the stream that does not decode ([`picture_error`]) lands nothing: its value is /// signalled in its turn, its command buffer completes as any, and its output keeps its bytes. +/// The session counts it among the decodes that answered no picture and apart, for its end's +/// line, and says only its first ([`HostVideoSession::not_decoded`]). #[test] fn a_picture_of_the_stream_that_does_not_decode_lands_nothing_and_completes() { - assert!(picture_error::

("test", "a reference frame is missing").is_none()); + assert!(picture_error("a reference frame is missing").is::()); let p = FakePlatform::new(); let log = Log::default(); - let s = session(&p, vec![Ok(None)], &log); + let answers = vec![ + Err(picture_error("a reference frame is missing")), + Ok(None), + Err(picture_error("a picture after one that did not decode")), + ]; + let s = session(&p, answers, &log); let bitstream = buffer(&p, 4096, STORAGE_SHARED); - let (first, second) = ( - buffer(&p, 16384, STORAGE_SHARED), - buffer(&p, 16384, STORAGE_SHARED), + let outputs: Vec<_> = (0..4).map(|_| buffer(&p, 16384, STORAGE_SHARED)).collect(); + let decoded: Vec<_> = (outputs.iter()) + .map(|out| (s.decode(&decode(&bitstream, &[], planes(out, out, 96)))).unwrap()) + .collect(); + assert_eq!( + decoded.iter().map(|d| d.value).collect::>(), + [1, 2, 3, 4] ); - let none = s - .decode(&decode(&bitstream, &[], planes(&first, &first, 96))) - .unwrap(); - assert_eq!(none.value, 1); - let next = s - .decode(&decode(&bitstream, &[], planes(&second, &second, 96))) - .unwrap(); - assert_eq!(next.value, 2); - assert!(event_of(&s).wait_until_signaled_value(2, 10_000)); - assert!(!none.landed.as_deref().is_some_and(Landed::failed)); - assert!(bytes(&first).iter().all(|&x| x == UNTOUCHED)); - assert!(holds(&bytes(&second), 0, 64, 96, 2)); - assert_eq!(s.counts.lock().skipped, 1); + assert_eq!( + decoded.iter().map(|d| d.skipped).collect::>(), + [true, true, true, false] + ); + assert!(event_of(&s).wait_until_signaled_value(4, 10_000)); + assert!( + !decoded + .iter() + .any(|d| d.landed.as_deref().is_some_and(Landed::failed)) + ); + for out in &outputs[..3] { + assert!(bytes(out).iter().all(|&x| x == UNTOUCHED)); + } + assert!(holds(&bytes(&outputs[3]), 0, 64, 96, 4)); + let counts = s.counts.lock(); + assert_eq!((counts.skipped, counts.not_decoded), (3, 2)); +} + +/// Of a session's pictures of the stream that do not decode, only its first is said +/// ([`HostVideoSession::not_decoded`] answers whether it said it), each session's own. +#[test] +fn a_session_says_its_first_picture_that_does_not_decode_alone() { + let p = FakePlatform::new(); + let not = NotDecoded("a reference frame is missing".to_owned()); + let (one, two) = ( + session(&p, Vec::new(), &Log::default()), + session(&p, Vec::new(), &Log::default()), + ); + assert_eq!( + [one.not_decoded(¬), one.not_decoded(¬)], + [true, false] + ); + assert!(two.not_decoded(¬)); + assert_eq!(one.counts.lock().not_decoded, 2); + assert_eq!(two.counts.lock().not_decoded, 1); } /// A decode that would have the session hold more pictures unlanded than its decoder spares @@ -942,7 +976,11 @@ fn a_decode_past_the_decoder_s_spare_pictures_waits_for_the_oldest_to_land() { fn a_failed_landing_is_signalled_and_a_refusal_spends_no_value() { let p = FakePlatform::new(); let log = Log::default(); - let s = session(&p, vec![Ok(Some(Picture::Fail)), Err("a bad slice")], &log); + let s = session( + &p, + vec![Ok(Some(Picture::Fail)), Err("a bad slice".into())], + &log, + ); let bitstream = buffer(&p, 4096, STORAGE_SHARED); let pages = buffer(&p, 16384, STORAGE_SHARED); let d = || decode(&bitstream, &[], planes(&pages, &pages, 96));