diff --git a/crates/reims-vgpu/src/graphics/video_host.rs b/crates/reims-vgpu/src/graphics/video_host.rs index e4f329d2f..65189d945 100644 --- a/crates/reims-vgpu/src/graphics/video_host.rs +++ b/crates/reims-vgpu/src/graphics/video_host.rs @@ -790,6 +790,9 @@ struct Stage { device: P::Device, queue: Option, buffer: Option, + /// Staging buffers whose copy failed once committed, which the GPU may read or write still: + /// kept out of use while the session lives ([`Self::copy_with_caches`]). + failed: Vec, /// A copy of a picture into its output's caches was not made since the landing last took it /// ([`Self::take_unmade`]): the platform made no blit encoder for it, or refused a staging /// copy ([`Self::copy_with_caches`]). @@ -930,6 +933,13 @@ impl Stage

{ /// refuses, counted under `rt-refused-`, which records nothing) answers the same way: /// the command buffer is not committed, and the picture fails to land, or the frame fails. /// The process's first refused copy into the caches is logged at warn, as a staging copy's. + /// + /// **A copy that fails once committed**, whose wait failed or which ended in an error, answers + /// an error too, and its staging buffer is kept out of use while the session lives, the next + /// copy staging in a new one: where the wait failed (on the rt platform, a lost device), the + /// GPU may run the copy still, reading the staging buffer into the caches or writing it out + /// of them, so no later picture or frame stages its bytes there. On a live device the wait + /// returns once the copy is done, and a guest sees none of this. fn copy_with_caches( &mut self, luma: &OutputPlane

, @@ -1081,10 +1091,17 @@ impl Stage

{ .go_on(); cb.commit(OnFault::Return) .map_err(|r| fault("its commit", r))?; - (cb.wait_until_completed(OnFault::Return)).map_err(|r| fault("its wait", r))?; - if cb.status() != CommandBufferStatus::COMPLETED { - let error = cb.error().map(|e| format!("{e:?}")).unwrap_or_default(); - return Err(format!("the copy {way} a device cache failed {error}").into()); + let failed = match cb.wait_until_completed(OnFault::Return) { + Err(raise) => Some(fault("its wait", raise)), + Ok(()) if cb.status() != CommandBufferStatus::COMPLETED => { + let error = cb.error().map(|e| format!("{e:?}")).unwrap_or_default(); + Some(format!("the copy {way} a device cache failed {error}")) + } + Ok(()) => None, + }; + if let Some(failed) = failed { + self.failed.extend(self.buffer.take()); + return Err(failed.into()); } Ok(()) } @@ -1496,6 +1513,7 @@ impl HostVideoSession

{ device: device.clone_ref(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let landing = { diff --git a/crates/reims-vgpu/src/graphics/video_host/encode.rs b/crates/reims-vgpu/src/graphics/video_host/encode.rs index 43c65ff6c..bd444ed4e 100644 --- a/crates/reims-vgpu/src/graphics/video_host/encode.rs +++ b/crates/reims-vgpu/src/graphics/video_host/encode.rs @@ -445,6 +445,7 @@ impl HostEncodeSession

{ device: device.clone_ref(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let thread = { diff --git a/crates/reims-vgpu/src/graphics/video_host/tests.rs b/crates/reims-vgpu/src/graphics/video_host/tests.rs index a4ba31056..2e4ec0aa1 100644 --- a/crates/reims-vgpu/src/graphics/video_host/tests.rs +++ b/crates/reims-vgpu/src/graphics/video_host/tests.rs @@ -918,6 +918,52 @@ fn a_staging_copy_into_caches_the_platform_refuses_fails_the_landing() { drop(s); } +/// A copy into the output's caches whose wait fails once it was committed (on the rt platform, +/// a lost device), which the GPU may run still, reading the staging buffer, fails the picture's +/// landing, its command buffer failing, and the staging buffer is kept out of use: the next +/// picture stages in a new one, and lands as any. +#[test] +fn a_copy_into_caches_whose_wait_fails_keeps_its_staging_buffer_out_of_use() { + 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( + "waitUntilCompleted", + Step::Raise { + name: "NSInternalInconsistencyException".to_owned(), + reason: "the device is lost".to_owned(), + }, + ); + let failed = (s.decode(&decode(&bitstream, &[], planes(&cache, &cache, 128)))).unwrap(); + assert_eq!(failed.value, 1); + assert!(event_of(&s).wait_until_signaled_value(1, 10_000)); + assert!( + failed.landed.as_deref().is_some_and(Landed::failed), + "its command buffer completes as a picture's that did not land" + ); + assert_eq!(s.counts.lock().failed, 1); + let first = p.call_log().calls_to(COPY); + assert_eq!(first.len(), 2, "the picture's copies, committed"); + + 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!(next.landed.as_deref().is_some_and(|l| !l.failed())); + assert_eq!(s.counts.lock().failed, 1, "the first picture's alone"); + let copies = p.call_log().calls_to(COPY); + assert_eq!(copies.len(), 4, "the next picture's copies"); + assert_ne!( + copies[2].args[0], first[0].args[0], + "the next picture staged in a new buffer" + ); + assert_eq!(copies[3].args[0], copies[2].args[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] @@ -1492,6 +1538,7 @@ fn a_pictures_coded_rows_below_its_crop_are_staged_for_its_caches() { device: p.device(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let bitstream = buffer(&p, 4096, STORAGE_SHARED); @@ -1612,6 +1659,7 @@ fn a_short_picture_staged_for_a_cache_lands_over_zeros() { device: p.device(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let bitstream = buffer(&p, 4096, STORAGE_SHARED); @@ -1693,6 +1741,7 @@ fn a_short_picture_the_hardware_writes_in_a_cache_has_the_plane_cleared_first() device: p.device(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let bitstream = buffer(&p, 4096, STORAGE_SHARED); @@ -1780,6 +1829,7 @@ fn a_short_picture_in_a_cache_s_surface_has_its_images_cleared_first() { device: p.device(), queue: None, buffer: None, + failed: Vec::new(), unmade: false, }; let bitstream = buffer(&p, 4096, STORAGE_SHARED);