diff --git a/crates/reims-vgpu/src/graphics/video_host.rs b/crates/reims-vgpu/src/graphics/video_host.rs index 4437ad817..47447bde9 100644 --- a/crates/reims-vgpu/src/graphics/video_host.rs +++ b/crates/reims-vgpu/src/graphics/video_host.rs @@ -31,7 +31,10 @@ //! error leaves one. A picture the hardware answered failed that the backend lands all the //! same, as the hardware left it ([`Landing::hardware_failed`]), is logged and counted apart, //! and lands as any other: a Mac's hardware H.264 decoder hands such a picture on with no -//! error (`super::nvidia`). +//! error (`super::nvidia`). A copy into the caches that the platform makes no blit encoder +//! for is skipped, as the decoder skips whole a pass the platform makes no encoder of: the +//! picture lands with the caches as they were, and is not counted as a failure to land +//! (`Stage::copy_with_caches`). //! //! A picture holds the hardware's surface until it has landed, so the session holds no more //! pictures unlanded than the decoder spares ([`HostDecoder::most_unlanded`]): a decode past @@ -488,6 +491,15 @@ impl Stage

{ /// Copies each plane `staged` says is staged between the staging buffer and its device /// cache, into the cache where `into`, else out of it, on the session's queue, and waits for /// the copy. + /// + /// **A copy into the caches the platform makes no blit encoder for** (on the rt platform, an + /// encoder metal2vulkan-runtime refuses, which it counts under `rt-refused-`) is + /// skipped, as the decoder skips whole a pass the platform makes no encoder of + /// (`decode::cmdbuf`'s `unmade`): the caches keep their bytes, and the picture lands with + /// them, its value signalled and its command buffer completing as any landed picture's. The + /// process's first is logged. A copy out of the caches, an encode's source, answers the + /// refusal as an error, which fails the frame: skipped, it would hand the encoder the staging + /// buffer's earlier bytes, another frame's or what the buffer held when it was made. fn copy_with_caches( &mut self, luma: &OutputPlane

, @@ -513,9 +525,18 @@ impl Stage

{ let cb = (queue.command_buffer(OnFault::Return)) .map_err(|r| fault("its command buffer", r))? .ok_or_else(|| format!("the copy {way} a device cache: no command buffer"))?; - let blit = (cb.blit_encoder(OnFault::Return)) - .map_err(|r| fault("its blit encoder", r))? - .ok_or_else(|| format!("the copy {way} a device cache: no blit encoder"))?; + let Some(blit) = + (cb.blit_encoder(OnFault::Return)).map_err(|r| fault("its blit encoder", r))? + else { + if into { + log::warn!( + "hardware video: the platform made no blit encoder for a picture's copy into \ + its device caches: the copy is skipped, and the caches keep their bytes" + ); + return Ok(()); + } + return Err(format!("the copy {way} a device cache: no blit encoder").into()); + }; for (plane, at) in [(luma, staged.luma), (chroma, staged.chroma)] { let Some(at) = at else { continue }; // A plane that lands in its cache's surface is copied into its image, staged at the diff --git a/crates/reims-vgpu/src/graphics/video_host/encode/tests.rs b/crates/reims-vgpu/src/graphics/video_host/encode/tests.rs index 0079b4b0b..ee21f41dd 100644 --- a/crates/reims-vgpu/src/graphics/video_host/encode/tests.rs +++ b/crates/reims-vgpu/src/graphics/video_host/encode/tests.rs @@ -401,6 +401,44 @@ fn a_source_in_a_device_cache_is_copied_out_of_it_first() { drop(s); } +/// A source plane in a device cache whose copy out the platform makes no blit encoder for fails +/// its frame, signalled with a failed result, rather than handing the encoder the staging +/// buffer's earlier bytes (`Stage::copy_with_caches`); the next frame's copy runs as any. +#[test] +fn a_source_whose_copy_out_has_no_blit_encoder_fails_its_frame() { + use reims_vgpu_vulkan::core::testkit::Step; + let p = FakePlatform::new(); + p.world().set_auto_complete(Some(CompleteOn::Caller)); + let log = Log::default(); + let s = session(&p, vec![], &log); + let cache = buffer(&p, 16384, PRIVATE); + let pages = source(&p); + let (failed, next) = (buffer(&p, 4096, SHARED), buffer(&p, 4096, SHARED)); + let (luma, _) = planes(&cache, 64, 32); + let (_, chroma) = planes(&pages, 64, 32); + p.script().push("blitCommandEncoder", Step::Nil); + let mut e = encode(&pages, &failed, 0, Some(settings())); + (e.luma, e.chroma) = (luma, chroma); + assert_eq!(s.encode(&e).unwrap(), 1); + assert!(event_of(&s).wait_until_signaled_value(1, 10_000)); + assert!(p.call_log().calls_to(COPY).is_empty(), "no copy out of the cache"); + assert_eq!(result_in(&bytes(&failed)).status, RGFX_VIDEO_ENCODE_FAILED); + assert!( + !(log.lock().iter()).any(|seen| matches!(seen, Seen::Finished(..))), + "the encoder read no source" + ); + + let (luma, _) = planes(&cache, 64, 32); + let (_, chroma) = planes(&pages, 64, 32); + let mut e = encode(&pages, &next, 1, None); + (e.luma, e.chroma) = (luma, chroma); + assert_eq!(s.encode(&e).unwrap(), 2); + assert!(event_of(&s).wait_until_signaled_value(2, 10_000)); + assert_eq!(p.call_log().calls_to(COPY).len(), 32, "the next frame's copy, one a row"); + assert_eq!(result_in(&bytes(&next)).status, RGFX_VIDEO_ENCODE_OK); + drop(s); +} + /// The settings every backend takes: each H.264 and HEVC profile with its format, and H.264's /// entropy coders where the profile has them. #[test] diff --git a/crates/reims-vgpu/src/graphics/video_host/tests.rs b/crates/reims-vgpu/src/graphics/video_host/tests.rs index d6bac34e0..87186486d 100644 --- a/crates/reims-vgpu/src/graphics/video_host/tests.rs +++ b/crates/reims-vgpu/src/graphics/video_host/tests.rs @@ -423,6 +423,39 @@ fn a_plane_in_a_device_cache_lands_staged_then_copied() { ); } +/// A copy into the output's caches that the platform makes no blit encoder for is skipped, as +/// the decoder skips whole a pass the platform makes no encoder of: the caches keep their bytes, +/// and the picture lands with them, its value signalled and its command buffer completing as any +/// landed picture's, not counted as a failure to land; the next picture's copy runs as any. +#[test] +fn a_copy_into_caches_the_platform_makes_no_blit_encoder_for_is_skipped() { + use reims_vgpu_vulkan::core::testkit::Step; + let p = FakePlatform::new(); + p.world().set_auto_complete(Some(CompleteOn::Caller)); + let log = Log::default(); + let s = session(&p, vec![], &log); + let bitstream = buffer(&p, 4096, STORAGE_SHARED); + let cache = buffer(&p, 16384, PRIVATE); + p.script().push("blitCommandEncoder", Step::Nil); + let skipped = (s.decode(&decode(&bitstream, &[], planes(&cache, &cache, 128)))).unwrap(); + assert_eq!(skipped.value, 1); + assert!(event_of(&s).wait_until_signaled_value(1, 10_000)); + assert!(p.call_log().calls_to(COPY).is_empty(), "no copy into the caches"); + assert!( + skipped.landed.as_deref().is_some_and(|l| !l.failed()), + "its command buffer completes as any landed picture's" + ); + assert_eq!(s.counts.lock().failed, 0); + + let next = (s.decode(&decode(&bitstream, &[], planes(&cache, &cache, 128)))).unwrap(); + assert_eq!(next.value, 2); + assert!(event_of(&s).wait_until_signaled_value(2, 10_000)); + assert_eq!(p.call_log().calls_to(COPY).len(), 2, "the next picture's copy"); + assert!(next.landed.as_deref().is_some_and(|l| !l.failed())); + assert_eq!(s.counts.lock().failed, 0); + drop(s); +} + /// Values are signalled in decode order, each once its picture landed: a decode that answers no /// picture is signalled in its turn, behind a picture still landing. #[test] diff --git a/docs/accuracy-ledger.md b/docs/accuracy-ledger.md index 9826a0ceb..6faf62452 100644 --- a/docs/accuracy-ledger.md +++ b/docs/accuracy-ledger.md @@ -88,7 +88,11 @@ refuses, as a resolve it builds none of, counted as above) is skipped whole: the the pass's ops up to its end, and the command buffer runs the rest and completes as it would have, as a Metal app's sends to a nil encoder do nothing and fail no command buffer (`crates/reims-vgpu/src/graphics/decode/cmdbuf.rs`, `unmade`). The process's first such pass of -each kind has a line. +each kind has a line. The host's video landing does the same with a picture's copy into its +output's device caches that rt makes no blit encoder for: the copy is skipped, the caches keep +their bytes and the decode's command buffer completes as for any landed picture; an encode's copy +of its source out of the caches fails the frame instead +(`crates/reims-vgpu/src/graphics/video_host.rs`, `Stage::copy_with_caches`). Among the translator's refusals (`rt-refused-translation`), a fragment function that reads an interpolant at a sample or an offset (`interpolate_at_sample`, `interpolate_at_offset`) outside diff --git a/docs/graphics-kext/design.md b/docs/graphics-kext/design.md index 3c6067076..a3e03d382 100644 --- a/docs/graphics-kext/design.md +++ b/docs/graphics-kext/design.md @@ -696,8 +696,10 @@ Stages: committed apart and taken in the other order) reads the newer bytes; a download of a cache nothing wrote since its last copy copies nothing; a decoder's new output whose - picture fails to land, or lands short of its planes, reads zeros where - the picture did not write, where the pages would give their bytes + picture fails to land, lands short of its planes, or lands with its + copy into the caches skipped (the runtime made no blit encoder for it, + docs/video/devices.md), reads zeros where the picture did not write, + where the pages would give their bytes (Metal leaves a failed decode's output undefined, and a new surface's texels are the kernel's zero-filled pages unless its client wrote them under a lock, which moves the count and has the decode's use fill the diff --git a/docs/video/devices.md b/docs/video/devices.md index b16d4247e..ff2876a14 100644 --- a/docs/video/devices.md +++ b/docs/video/devices.md @@ -164,6 +164,13 @@ command buffer of the session's process (`graphics/decode/video.rs`): decode (above) fails the session's next decode in its stead, whose command buffer completes failed at its end: the guest is told of the failure one picture late, counted as a degradation (`video-landing-failure-carried`). +- **A picture whose copy into its output's caches the runtime makes no blit encoder for** + (metal2vulkan-runtime's refusal, which it counts under `rt-refused-`) lands with the + caches as they were: the copy is skipped, as the decoder skips whole a pass the platform makes + no encoder of, and the command buffer completes as for any landed picture. The process's first + is logged. An encode whose source's copy out of its caches the runtime makes no blit encoder + for fails its frame instead (`RGFX_VIDEO_ENCODE_FAILED`), since the encoder would read the + staging buffer's earlier bytes. - **A failed picture's output holds what the driver wrote** where the driver writes the output itself: a picture decoded into its output's cache, and one the driver's video processing copies there or into the pages, which on VA-API is issued right behind its decode and copies