🐛 Keep a staging buffer whose cache copy failed out of use
A host video session stages a picture's planes, or an encode's source, in one staging buffer and copies them into or out of the output's device caches on the GPU. A copy that failed once committed failed its picture or frame, but the buffer stayed the session's, so the next picture or frame staged its bytes in it. Where the copy's wait failed (on the rt platform, a lost device), the GPU may run the copy still, reading the buffer into the old output's caches or writing it out of them, while the CPU writes or reads the next one's bytes there. Stage now keeps a staging buffer whose copy failed once committed out of use while the session lives, and the next copy stages in a new one. What the guest sees: nothing on a live device, where the wait returns once the copy is done. After a lost device, a later picture or frame no longer shares a buffer with a copy that may still run. Test: a_copy_into_caches_whose_wait_fails_keeps_its_staging_buffer_out_of_use, on the stand-in device with a scripted failed wait.
This commit is contained in:
1 parent
b13fe6059b
commit
9a849a50a7
3 files changed
+73
-4
No files matched your search
@@ -790,6 +790,9 @@ struct Stage<P: Platform> {
|
||||
device: P::Device,
|
||||
queue: Option<P::CommandQueue>,
|
||||
buffer: Option<P::Buffer>,
|
||||
/// 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<P::Buffer>,
|
||||
/// 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<P: Platform> Stage<P> {
|
||||
/// refuses, counted under `rt-refused-<kind>`, 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<P>,
|
||||
@@ -1081,10 +1091,17 @@ impl<P: Platform> Stage<P> {
|
||||
.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<P: Platform> HostVideoSession<P> {
|
||||
device: device.clone_ref(),
|
||||
queue: None,
|
||||
buffer: None,
|
||||
failed: Vec::new(),
|
||||
unmade: false,
|
||||
};
|
||||
let landing = {
|
||||
|
||||
@@ -445,6 +445,7 @@ impl<P: Platform> HostEncodeSession<P> {
|
||||
device: device.clone_ref(),
|
||||
queue: None,
|
||||
buffer: None,
|
||||
failed: Vec::new(),
|
||||
unmade: false,
|
||||
};
|
||||
let thread = {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user