🐛 Answer a download failed where the platform refuses its copy
What the guest observes changes. Before, each copy the host makes for itself between a surface's device cache, its shapes, its wide home and its pages took the platform's answer to each command with go_on(), so a refused one changed nothing of the caches' state. A shape whose write-back was refused was marked written back, a refused fill marked its shape filled and the cache at the new generation, and a SURFACE_DOWNLOAD whose copy into the pages was refused was answered RGFX_STATUS_OK over the pages' older bytes, and never copied again. Now each such copy folds its commands' answers, by the ruling that keeps today's behaviour for the guest's own commands alone, and a refused one, or an encoder the platform made not, leaves what it was to move as not copied: - A shape whose write-back was refused stays dirty, and one whose fill was refused owes it still. A refused fill of the buffer leaves the cache at its older generation. - A download whose copy into the pages was refused, or that waits for a copy that landed short (a refused later round of one that circulates its pieces), is answered failed (RGFX_STATUS_REFUSED) through the driver's existing path, where it was answered OK on stale bytes before. The cache stays written, so the next download copies it again. A refused copy's pieces put none of their bytes into the pages. - A fill or a copy into a wide home refused at a command buffer's begin, and a write's copy into its plane's other shapes or a copy between a cache and its home refused at its encoder's end, fails that command buffer with MTLCommandBufferErrorOutOfMemory, as a cache's refused memory already does. - An early copy refused is not made, its command buffer not committed, and the refill it carried no longer marks the buffer as holding the pages; that also holds where the platform refuses a copy by runs, which left it so before. The host tries none of these again by itself: the next use, download or release that needs the copy makes it. Each refusal is counted under surface-copy-refused, the process's first logged at warn. The guest's own blits and draws still go on past a refused command. No rt-refused or rt-unbuilt code shows in the degradation counts of the 30 latest kept boot logs, so no boot has reached these paths so far. Five new fake-platform tests, red before (m3-max-78078, all five failed), pass with the fix: the reims-vgpu fake set (m3-max-78128, 1170 passed, 115 skipped) and its surface, shape and command buffer rt tests on the 5080 (m3-max-78131, 31 passed).
This commit is contained in:
1 parent
62ab502c71
commit
aaedba617b
5 files changed
+875
-268
No files matched your search
@@ -3910,7 +3910,9 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
/// side written is copied into the other in `cb` before the next encoder
|
||||
/// ([`super::surface_cache::Caches::reconcile`]), so it reads the write through either, as
|
||||
/// the Macs' next encoders read it (docs/graphics-kext/dgpu-oracle.md, Q37). An encoder that
|
||||
/// wrote both sides of a block keeps the home's writes in the texels both hold.
|
||||
/// wrote both sides of a block keeps the home's writes in the texels both hold. A copy the
|
||||
/// platform refused a command of fails the command buffer, as a refused memory does
|
||||
/// (`surface_cache`'s module doc, "Refused copies").
|
||||
fn reconcile_laid(&self, cb: &P::CommandBuffer) -> RaiseResult<()> {
|
||||
let uses = std::mem::take(&mut *self.laid_uses.borrow_mut());
|
||||
let mut written: Vec<(u64, bool)> = Vec::new();
|
||||
@@ -3937,7 +3939,10 @@ impl<P: Platform> GraphicsDecoder<P> {
|
||||
self.laid_written
|
||||
.borrow_mut()
|
||||
.extend(written.iter().map(|&(block, _)| block));
|
||||
self.surface_caches.reconcile(cb, &written)
|
||||
if self.surface_caches.reconcile(cb, &written)? {
|
||||
self.out_of_memory.set(true);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// In the per-shape form, the encoder just ended in `cb` may have written the shapes its uses
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -211,7 +211,6 @@ use std::collections::VecDeque;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use reims_vgpu_vulkan::core::platform::Platform;
|
||||
use reims_vgpu_vulkan::core::platform::blit::{BlitCmd, BlitEncoder as _};
|
||||
use reims_vgpu_vulkan::core::platform::command::CommandBuffer as _;
|
||||
use reims_vgpu_vulkan::core::platform::descriptor::RenderPassDescriptor as _;
|
||||
@@ -219,7 +218,10 @@ use reims_vgpu_vulkan::core::platform::render::{RenderCmd, RenderEncoder as _};
|
||||
use reims_vgpu_vulkan::core::platform::resource::Texture as _;
|
||||
use reims_vgpu_vulkan::core::platform::types::{ClearColor, MtlOrigin, MtlSize, PixelFormatInfo};
|
||||
use reims_vgpu_vulkan::core::platform::values::ColorAttachmentSet;
|
||||
use reims_vgpu_vulkan::core::platform::{Encoded, Platform};
|
||||
use reims_vgpu_vulkan::core::raise::{OnFault, RaiseResult};
|
||||
|
||||
use super::fold;
|
||||
use reims_vgpu_vulkan::gpu::no_texture::no_view;
|
||||
|
||||
/// How many unreferenced shapes an entry keeps, the most recently used (the planner's ruling of
|
||||
@@ -1062,24 +1064,28 @@ impl<T> ShapeTable<T> {
|
||||
/// Encodes in `cb`, in a blit encoder of its own, a copy of `buffer`, a cache's, into each shape of
|
||||
/// `table` that `pick` picks, each the buffer's bytes at its place ([`ShapeKey::span`]), which
|
||||
/// then owes no fill and holds no write the buffer lacks; counted in `counts`. Nothing where it
|
||||
/// picks none, or the platform made no encoder.
|
||||
/// picks none. Refused where the platform made no encoder or refused a command
|
||||
/// (`super`'s module doc, "Refused copies"): a shape whose copy it refused, or every shape where
|
||||
/// it refused the encoder or its end, owes its fill still.
|
||||
pub(crate) fn fill<P: Platform>(
|
||||
cb: &P::CommandBuffer,
|
||||
buffer: &P::Buffer,
|
||||
table: &mut ShapeTable<P::Texture>,
|
||||
pick: impl Fn(&Shape<P::Texture>) -> bool,
|
||||
counts: &mut ShapeCounts,
|
||||
) -> RaiseResult<()> {
|
||||
) -> RaiseResult<Encoded> {
|
||||
const ON: OnFault = OnFault::Return;
|
||||
if !table.iter().any(&pick) {
|
||||
return Ok(());
|
||||
return Ok(Encoded::RECORDED);
|
||||
}
|
||||
let Some(blit) = cb.blit_encoder(ON)? else {
|
||||
return Ok(());
|
||||
return Ok(Encoded::REFUSED);
|
||||
};
|
||||
for shape in table.iter_mut().filter(|s| pick(s)) {
|
||||
let mut whole = Encoded::RECORDED;
|
||||
let mut copied = Vec::new();
|
||||
for shape in table.iter().filter(|s| pick(s)) {
|
||||
let key = shape.key;
|
||||
blit.encode(
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyBufferToTexture {
|
||||
source_buffer: buffer,
|
||||
@@ -1092,12 +1098,20 @@ pub(crate) fn fill<P: Platform>(
|
||||
destination_level: 0,
|
||||
destination_origin: MtlOrigin::default(),
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
filled(shape, counts);
|
||||
)?;
|
||||
fold(&mut whole, encoded);
|
||||
if encoded.recorded() {
|
||||
copied.push(shape.id());
|
||||
}
|
||||
}
|
||||
blit.encode(ON, BlitCmd::EndEncoding)?.go_on();
|
||||
Ok(())
|
||||
let ended = blit.encode(ON, BlitCmd::EndEncoding)?;
|
||||
fold(&mut whole, ended);
|
||||
if ended.recorded() {
|
||||
for shape in table.iter_mut().filter(|s| copied.contains(&s.id())) {
|
||||
filled(shape, counts);
|
||||
}
|
||||
}
|
||||
Ok(whole)
|
||||
}
|
||||
|
||||
/// Metal's `MTLTextureUsageRenderTarget`, `MTLLoadActionClear` and `MTLStoreActionStore`: what
|
||||
@@ -1131,29 +1145,36 @@ pub(crate) fn clears_fit<P: Platform>(
|
||||
/// memory yet, reads (the module doc, "Zeros"), with no copy and no source. Each shape then owes
|
||||
/// no fill and holds no write the buffer lacks, as [`fill`] leaves it, counted in `counts` as a
|
||||
/// fill and as a clear. The caller made sure each takes a clear ([`clears_fit`]): one that does
|
||||
/// not, or that `pass_of` gives no pass, or whose pass the platform made no encoder for, is left
|
||||
/// owing its fill.
|
||||
/// not, or that `pass_of` gives no pass, is left owing its fill; so is one whose pass the platform
|
||||
/// made no encoder for or refused the end of, the fill then refused (`super`'s module doc,
|
||||
/// "Refused copies").
|
||||
pub(crate) fn fill_clears<P: Platform>(
|
||||
pass_of: impl Fn(&Shape<P::Texture>) -> RaiseResult<Option<P::RenderPassDescriptor>>,
|
||||
cb: &P::CommandBuffer,
|
||||
table: &mut ShapeTable<P::Texture>,
|
||||
pick: impl Fn(&Shape<P::Texture>) -> bool,
|
||||
counts: &mut ShapeCounts,
|
||||
) -> RaiseResult<()> {
|
||||
) -> RaiseResult<Encoded> {
|
||||
const ON: OnFault = OnFault::Return;
|
||||
let mut whole = Encoded::RECORDED;
|
||||
for shape in (table.iter_mut()).filter(|s| pick(s) && takes_clear::<P>(s)) {
|
||||
let Some(pass) = pass_of(shape)? else {
|
||||
continue;
|
||||
};
|
||||
let Some(encoder) = cb.render_encoder(ON, &pass)? else {
|
||||
whole = Encoded::REFUSED;
|
||||
continue;
|
||||
};
|
||||
encoder.encode(ON, RenderCmd::EndEncoding)?.go_on();
|
||||
let ended = encoder.encode(ON, RenderCmd::EndEncoding)?;
|
||||
fold(&mut whole, ended);
|
||||
if !ended.recorded() {
|
||||
continue;
|
||||
}
|
||||
counts.zero_cleared += 1;
|
||||
counts.zero_cleared_bytes += shape.bytes;
|
||||
filled(shape, counts);
|
||||
}
|
||||
Ok(())
|
||||
Ok(whole)
|
||||
}
|
||||
|
||||
/// A render pass of `platform`'s whose one colour attachment is `image`, loaded by a clear to
|
||||
@@ -1205,18 +1226,22 @@ pub(crate) type Source<'a, B> = (&'a B, std::ops::Range<u64>, u64);
|
||||
/// each its own texels, which the caller made sure the split lies between
|
||||
/// (`SurfaceCache::fills_straight`). The shape then owes no fill and holds no write the buffer
|
||||
/// lacks, as [`fill`] leaves it, counted in `counts` as a fill and as one made straight, with the
|
||||
/// copies encoded. A row no source holds ends its shape's copies there.
|
||||
/// copies encoded. A row no source holds ends its shape's copies there. Refused where the
|
||||
/// platform refused a copy (`super`'s module doc, "Refused copies"): that copy's shape owes its
|
||||
/// fill still.
|
||||
pub(crate) fn fill_from<P: Platform>(
|
||||
blit: &P::BlitEncoder,
|
||||
sources: &[Source<'_, P::Buffer>],
|
||||
table: &mut ShapeTable<P::Texture>,
|
||||
pick: &dyn Fn(&Shape<P::Texture>) -> bool,
|
||||
counts: &mut ShapeCounts,
|
||||
) -> RaiseResult<()> {
|
||||
) -> RaiseResult<Encoded> {
|
||||
const ON: OnFault = OnFault::Return;
|
||||
let source_of = |byte: u64| sources.iter().find(|(_, held, _)| held.contains(&byte));
|
||||
let mut whole = Encoded::RECORDED;
|
||||
for shape in table.iter_mut().filter(|s| pick(s)) {
|
||||
let key = shape.key;
|
||||
let mut took = Encoded::RECORDED;
|
||||
let row = key.width.saturating_mul(key.texel_bytes);
|
||||
let mut y = 0;
|
||||
'rows: while y < key.height {
|
||||
@@ -1230,7 +1255,7 @@ pub(crate) fn fill_from<P: Platform>(
|
||||
let rows = ((held.end - end).checked_div(key.bytes_per_row))
|
||||
.map_or(1, |more| more.saturating_add(1))
|
||||
.min(key.height - y);
|
||||
blit.encode(
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyBufferToTexture {
|
||||
source_buffer: buffer,
|
||||
@@ -1243,8 +1268,8 @@ pub(crate) fn fill_from<P: Platform>(
|
||||
destination_level: 0,
|
||||
destination_origin: MtlOrigin { x: 0, y, z: 0 },
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
)?;
|
||||
fold(&mut took, encoded);
|
||||
counts.straight_copies += 1;
|
||||
y += rows;
|
||||
continue;
|
||||
@@ -1256,7 +1281,7 @@ pub(crate) fn fill_from<P: Platform>(
|
||||
break 'rows;
|
||||
};
|
||||
let part = held.end.min(end) - from;
|
||||
blit.encode(
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyBufferToTexture {
|
||||
source_buffer: buffer,
|
||||
@@ -1273,43 +1298,50 @@ pub(crate) fn fill_from<P: Platform>(
|
||||
z: 0,
|
||||
},
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
)?;
|
||||
fold(&mut took, encoded);
|
||||
counts.straight_copies += 1;
|
||||
counts.straight_split_rows += u64::from(from == start);
|
||||
from += part;
|
||||
}
|
||||
y += 1;
|
||||
}
|
||||
fold(&mut whole, took);
|
||||
if !took.recorded() {
|
||||
continue;
|
||||
}
|
||||
counts.straight_fills += 1;
|
||||
counts.straight_bytes += shape.bytes;
|
||||
filled(shape, counts);
|
||||
}
|
||||
Ok(())
|
||||
Ok(whole)
|
||||
}
|
||||
|
||||
/// Encodes in `cb`, in a blit encoder of its own, a copy of each shape of `table` that `pick`
|
||||
/// picks into `buffer`, a cache's, its whole extent at its place ([`ShapeKey::span`]): the ids of
|
||||
/// the shapes copied, for [`ShapeTable::written_back`] once `cb` is committed. Shapes agree where
|
||||
/// they overlap (rule 1), so their order is free. None where it picks none, or the platform made
|
||||
/// no encoder.
|
||||
/// the shapes copied, for [`ShapeTable::written_back`] once `cb` is committed, and whether every
|
||||
/// copy was recorded. Shapes agree where they overlap (rule 1), so their order is free. None
|
||||
/// where it picks none. Refused where the platform made no encoder or refused a command
|
||||
/// (`super`'s module doc, "Refused copies"): a shape whose copy it refused, or every shape where
|
||||
/// it refused the encoder or its end, is not among the ids, and stays dirty.
|
||||
pub(crate) fn write_back<P: Platform>(
|
||||
cb: &P::CommandBuffer,
|
||||
buffer: &P::Buffer,
|
||||
table: &ShapeTable<P::Texture>,
|
||||
pick: impl Fn(&Shape<P::Texture>) -> bool,
|
||||
) -> RaiseResult<Vec<u64>> {
|
||||
) -> RaiseResult<(Vec<u64>, Encoded)> {
|
||||
const ON: OnFault = OnFault::Return;
|
||||
if !table.iter().any(&pick) {
|
||||
return Ok(Vec::new());
|
||||
return Ok((Vec::new(), Encoded::RECORDED));
|
||||
}
|
||||
let Some(blit) = cb.blit_encoder(ON)? else {
|
||||
return Ok(Vec::new());
|
||||
return Ok((Vec::new(), Encoded::REFUSED));
|
||||
};
|
||||
let mut ids = Vec::new();
|
||||
let mut whole = Encoded::RECORDED;
|
||||
for shape in table.iter().filter(|s| pick(s)) {
|
||||
let key = shape.key;
|
||||
blit.encode(
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyTextureToBuffer {
|
||||
source_texture: &shape.image,
|
||||
@@ -1322,12 +1354,18 @@ pub(crate) fn write_back<P: Platform>(
|
||||
destination_bytes_per_row: key.bytes_per_row,
|
||||
destination_bytes_per_image: key.bytes_per_row.saturating_mul(key.height),
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
ids.push(shape.id());
|
||||
)?;
|
||||
fold(&mut whole, encoded);
|
||||
if encoded.recorded() {
|
||||
ids.push(shape.id());
|
||||
}
|
||||
}
|
||||
blit.encode(ON, BlitCmd::EndEncoding)?.go_on();
|
||||
Ok(ids)
|
||||
let ended = blit.encode(ON, BlitCmd::EndEncoding)?;
|
||||
fold(&mut whole, ended);
|
||||
if !ended.recorded() {
|
||||
ids.clear();
|
||||
}
|
||||
Ok((ids, whole))
|
||||
}
|
||||
|
||||
/// Encodes in `cb` rule 1's copy of the shape `source` of `table`, which the encoder just ended
|
||||
@@ -1339,8 +1377,10 @@ pub(crate) fn write_back<P: Platform>(
|
||||
/// and the buffer only takes a write early that the source, dirty, copies into it again. A
|
||||
/// texel of another shape that the source's rows cover only in part (one wider than the
|
||||
/// source's, at the end of its rows) keeps its bytes, counted in `counts`
|
||||
/// ([`ShapeCounts::straddled`]). Nothing where `into` names no shape, the table holds no
|
||||
/// `source`, or the platform made no encoder.
|
||||
/// ([`ShapeCounts::straddled`]). Nothing where `into` names no shape or the table holds no
|
||||
/// `source`. Refused where the platform made no encoder or refused a command (`super`'s module
|
||||
/// doc, "Refused copies"); the other shapes take nothing where it refused the wait or the copy
|
||||
/// into the buffer.
|
||||
pub(crate) fn copy_overlaps<P: Platform>(
|
||||
cb: &P::CommandBuffer,
|
||||
buffer: &P::Buffer,
|
||||
@@ -1348,10 +1388,10 @@ pub(crate) fn copy_overlaps<P: Platform>(
|
||||
(source, into): (u64, &[u64]),
|
||||
fence: Option<&P::Fence>,
|
||||
counts: &mut ShapeCounts,
|
||||
) -> RaiseResult<()> {
|
||||
) -> RaiseResult<Encoded> {
|
||||
const ON: OnFault = OnFault::Return;
|
||||
let Some(from) = table.iter().find(|s| s.id() == source) else {
|
||||
return Ok(());
|
||||
return Ok(Encoded::RECORDED);
|
||||
};
|
||||
let targets: Vec<&Shape<P::Texture>> = (table.iter())
|
||||
.filter(|s| s.id() != source && into.contains(&s.id()))
|
||||
@@ -1359,33 +1399,43 @@ pub(crate) fn copy_overlaps<P: Platform>(
|
||||
let Some((bytes, rows)) = (targets.iter().map(|t| from.key.overlap(&t.key)))
|
||||
.reduce(|(b, r), (bytes, rows)| (b.max(bytes), r.max(rows)))
|
||||
else {
|
||||
return Ok(());
|
||||
return Ok(Encoded::RECORDED);
|
||||
};
|
||||
let key = from.key;
|
||||
let Some(blit) = cb.blit_encoder(ON)? else {
|
||||
return Ok(());
|
||||
return Ok(Encoded::REFUSED);
|
||||
};
|
||||
let mut whole = Encoded::RECORDED;
|
||||
if let Some(fence) = fence {
|
||||
blit.encode(ON, BlitCmd::WaitForFence { fence })?.go_on();
|
||||
fold(
|
||||
&mut whole,
|
||||
blit.encode(ON, BlitCmd::WaitForFence { fence })?,
|
||||
);
|
||||
}
|
||||
if whole.recorded() {
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyTextureToBuffer {
|
||||
source_texture: &from.image,
|
||||
source_slice: 0,
|
||||
source_level: 0,
|
||||
source_origin: MtlOrigin::default(),
|
||||
source_size: MtlSize::new(bytes.div_ceil(key.texel_bytes), rows, 1),
|
||||
destination_buffer: buffer,
|
||||
destination_offset: key.offset,
|
||||
destination_bytes_per_row: key.bytes_per_row,
|
||||
destination_bytes_per_image: key.bytes_per_row.saturating_mul(rows),
|
||||
},
|
||||
)?;
|
||||
fold(&mut whole, encoded);
|
||||
}
|
||||
fold(&mut whole, blit.encode(ON, BlitCmd::EndEncoding)?);
|
||||
// The others take nothing of a buffer the source's overlap did not reach.
|
||||
if !whole.recorded() {
|
||||
return Ok(whole);
|
||||
}
|
||||
blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyTextureToBuffer {
|
||||
source_texture: &from.image,
|
||||
source_slice: 0,
|
||||
source_level: 0,
|
||||
source_origin: MtlOrigin::default(),
|
||||
source_size: MtlSize::new(bytes.div_ceil(key.texel_bytes), rows, 1),
|
||||
destination_buffer: buffer,
|
||||
destination_offset: key.offset,
|
||||
destination_bytes_per_row: key.bytes_per_row,
|
||||
destination_bytes_per_image: key.bytes_per_row.saturating_mul(rows),
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
blit.encode(ON, BlitCmd::EndEncoding)?.go_on();
|
||||
let Some(blit) = cb.blit_encoder(ON)? else {
|
||||
return Ok(());
|
||||
return Ok(Encoded::REFUSED);
|
||||
};
|
||||
for target in targets {
|
||||
let (bytes, rows) = key.overlap(&target.key);
|
||||
@@ -1397,7 +1447,7 @@ pub(crate) fn copy_overlaps<P: Platform>(
|
||||
if width == 0 || rows == 0 {
|
||||
continue;
|
||||
}
|
||||
blit.encode(
|
||||
let encoded = blit.encode(
|
||||
ON,
|
||||
BlitCmd::CopyBufferToTexture {
|
||||
source_buffer: buffer,
|
||||
@@ -1410,8 +1460,8 @@ pub(crate) fn copy_overlaps<P: Platform>(
|
||||
destination_level: 0,
|
||||
destination_origin: MtlOrigin::default(),
|
||||
},
|
||||
)?
|
||||
.go_on();
|
||||
)?;
|
||||
fold(&mut whole, encoded);
|
||||
counts.overlap_copies += 1;
|
||||
counts.overlap_bytes += width * rows * texel;
|
||||
if target.key.storage != key.storage {
|
||||
@@ -1421,8 +1471,8 @@ pub(crate) fn copy_overlaps<P: Platform>(
|
||||
reims_vgpu_vulkan::answer::count_kind_by(ORDER_COPY_BYTES, width * rows * texel);
|
||||
}
|
||||
}
|
||||
blit.encode(ON, BlitCmd::EndEncoding)?.go_on();
|
||||
Ok(())
|
||||
fold(&mut whole, blit.encode(ON, BlitCmd::EndEncoding)?);
|
||||
Ok(whole)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -1931,7 +1981,11 @@ mod tests {
|
||||
let mark = platform.call_log().mark();
|
||||
let mut counts = ShapeCounts::default();
|
||||
let pass_of = |s: &Shape<_>| zeros_pass(&platform, &s.image).map(Some);
|
||||
fill_clears::<FakePlatform>(pass_of, &cb, &mut table, |s| s.owed, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill_clears::<FakePlatform>(pass_of, &cb, &mut table, |s| s.owed, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
let calls = platform.call_log().since(mark);
|
||||
let sels: Vec<&str> = calls.iter().map(|c| c.sel).collect();
|
||||
assert_eq!(
|
||||
@@ -2082,7 +2136,11 @@ mod tests {
|
||||
let mut counts = ShapeCounts::default();
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
let pass_of = |s: &Shape<_>| zeros_pass(&*platform, &s.image).map(Some);
|
||||
fill_clears::<V>(pass_of, &cb, &mut table, |s| s.owed, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill_clears::<V>(pass_of, &cb, &mut table, |s| s.owed, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
cb.commit(ON).unwrap();
|
||||
cb.wait_until_completed(ON).unwrap();
|
||||
assert_eq!(counts.zero_cleared, 4, "each cleared");
|
||||
@@ -2172,7 +2230,11 @@ mod tests {
|
||||
};
|
||||
let mut counts = ShapeCounts::default();
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.owed, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.owed, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
cb.commit(ON).unwrap();
|
||||
cb.wait_until_completed(ON).unwrap();
|
||||
assert_eq!(counts.fills, 3);
|
||||
@@ -2233,7 +2295,8 @@ mod tests {
|
||||
assert!(table.mark_dirty(id));
|
||||
}
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
let written = write_back::<V>(&cb, &back, &table, |s| s.dirty).unwrap();
|
||||
let (written, recorded) = write_back::<V>(&cb, &back, &table, |s| s.dirty).unwrap();
|
||||
assert!(recorded.recorded());
|
||||
cb.commit(ON).unwrap();
|
||||
cb.wait_until_completed(ON).unwrap();
|
||||
assert_eq!(written, inner);
|
||||
@@ -2258,7 +2321,11 @@ mod tests {
|
||||
);
|
||||
// Nothing owes a fill now: nothing is encoded, nothing counted.
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.owed, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.owed, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
cb.commit(ON).unwrap();
|
||||
cb.wait_until_completed(ON).unwrap();
|
||||
assert_eq!(counts.fills, 3);
|
||||
@@ -2397,11 +2464,19 @@ mod tests {
|
||||
let mut counts = ShapeCounts::default();
|
||||
store(&p);
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() == whole, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() == whole, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
commit(cb);
|
||||
store(&vec![0; LENGTH.to_usize()]);
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() != whole, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() != whole, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
commit(cb);
|
||||
assert_eq!(
|
||||
rows_of(&table, wide),
|
||||
@@ -2409,15 +2484,15 @@ mod tests {
|
||||
);
|
||||
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
copy_overlaps::<V>(
|
||||
let copied = copy_overlaps::<V>(
|
||||
&cb,
|
||||
&buffer,
|
||||
&table,
|
||||
(whole, &[wide, narrow]),
|
||||
None,
|
||||
&mut counts,
|
||||
)
|
||||
.unwrap();
|
||||
);
|
||||
assert!(copied.unwrap().recorded());
|
||||
commit(cb);
|
||||
assert_eq!(rows_of(&table, wide), corner(&p, 32, 8));
|
||||
assert_eq!(rows_of(&table, narrow), corner(&p, 18, 2));
|
||||
@@ -2446,10 +2521,18 @@ mod tests {
|
||||
// The narrow one takes `q`, then gives the whole its two rows.
|
||||
store(&q);
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() == narrow, &mut counts).unwrap();
|
||||
assert!(
|
||||
fill::<V>(&cb, &buffer, &mut table, |s| s.id() == narrow, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
commit(cb);
|
||||
let cb = queue.command_buffer(ON).unwrap().unwrap();
|
||||
copy_overlaps::<V>(&cb, &buffer, &table, (narrow, &[whole]), None, &mut counts).unwrap();
|
||||
assert!(
|
||||
copy_overlaps::<V>(&cb, &buffer, &table, (narrow, &[whole]), None, &mut counts)
|
||||
.unwrap()
|
||||
.recorded()
|
||||
);
|
||||
commit(cb);
|
||||
let mut want = corner(&p, ROW, 16);
|
||||
for (y, row) in want.iter_mut().enumerate().take(2) {
|
||||
|
||||
@@ -448,8 +448,9 @@ mod tests {
|
||||
|
||||
use super::super::surface_cache::tests::{
|
||||
NO_REACH, blit_with, blits_with, buffer_bytes, cache_id, cached, complete_round,
|
||||
complete_staged, copies, counted, download, encoder_with, pages_id, queues, ram_bytes,
|
||||
reading, release, surface_texture, surface_texture_as, surface_textures, use_surfaces,
|
||||
complete_staged, copies, counted, download, download_answered, encoder_with, pages_id,
|
||||
queues, ram_bytes, reading, release, surface_texture, surface_texture_as, surface_textures,
|
||||
use_surfaces,
|
||||
};
|
||||
use super::super::surface_pages::tests::{BLOCK, Rig, one_plane, rig};
|
||||
use super::*;
|
||||
@@ -1462,6 +1463,84 @@ mod tests {
|
||||
assert_eq!(r.dec.caches().counts().shapes.written_back, 1);
|
||||
}
|
||||
|
||||
/// A dirty shape whose write back into its cache's buffer the platform refuses stays dirty,
|
||||
/// and the download that asked it copies nothing into the pages, the buffer lacking the
|
||||
/// write: it is answered refused, counted under its own code, and the next download writes
|
||||
/// the shape back, copies the buffer into the pages and is answered done
|
||||
#[test]
|
||||
fn a_shape_whose_write_back_the_platform_refuses_stays_dirty() {
|
||||
let mut r = shaped();
|
||||
buffer_made(&r);
|
||||
let cache = cache_id(&r);
|
||||
let image = texture_image(&mut r, 21, 80, (32, 8));
|
||||
write(&mut r, 0x100, 21, (32, 8));
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
r.p.script().push(TO_BUFFER, Step::Nil);
|
||||
let before = counted("surface-copy-refused");
|
||||
let mark = r.p.call_log().mark();
|
||||
let (done, refused) = download_answered(&r, BLOCK);
|
||||
let calls = r.p.call_log().since(mark);
|
||||
assert!(copies(&calls).is_empty(), "nothing into the pages");
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
assert!(refused.load(Ordering::SeqCst), "refused");
|
||||
assert!(!done.load(Ordering::SeqCst), "never done");
|
||||
assert_eq!(counted("surface-copy-refused"), before + 1);
|
||||
assert_eq!(r.dec.caches().counts().shapes.written_back, 0);
|
||||
let mark = r.p.call_log().mark();
|
||||
let (done, refused) = download_answered(&r, BLOCK);
|
||||
let calls = r.p.call_log().since(mark);
|
||||
assert_eq!(written_back(&calls), [(image, cache, 0)]);
|
||||
assert_eq!(copies(&calls).len(), 1);
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
assert!(done.load(Ordering::SeqCst) && !refused.load(Ordering::SeqCst));
|
||||
}
|
||||
|
||||
/// A shape whose fill the platform refuses owes it still: the next use that names the block
|
||||
/// fills it, and the refusal is counted under its own code
|
||||
#[test]
|
||||
fn a_shape_whose_fill_the_platform_refuses_owes_it_still() {
|
||||
let mut r = shaped();
|
||||
let pages = pages_id(&r);
|
||||
texture(&mut r, 21, 80, (32, 8));
|
||||
r.p.script().push(FILL, Step::Nil);
|
||||
let before = counted("surface-copy-refused");
|
||||
use_surfaces(&mut r, 1, 0x100, &[(BLOCK, 2, false)]);
|
||||
assert_eq!(counted("surface-copy-refused"), before + 1);
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
let mark = r.p.call_log().mark();
|
||||
use_surfaces(&mut r, 1, 0x101, &[(BLOCK, 2, false)]);
|
||||
let filled = fills(&r.p.call_log().since(mark));
|
||||
assert_eq!(filled.len(), 1, "filled again");
|
||||
assert_eq!(filled[0].0, pages);
|
||||
assert_eq!(r.dec.caches().counts().shapes.fills, 1);
|
||||
}
|
||||
|
||||
/// A write through one shape whose copy into its plane's other shape the platform refuses
|
||||
/// fails its command buffer, as one whose buffer the platform refused its memory does, and
|
||||
/// the other shape takes nothing of the buffer's older bytes; the refusal is counted under its
|
||||
/// own code
|
||||
#[test]
|
||||
fn a_writes_copy_into_its_planes_other_shape_the_platform_refuses_fails_its_buffer() {
|
||||
use reims_vgpu_vulkan::core::testkit::impls::command::FAIL_OUT_OF_MEMORY;
|
||||
let (mut r, _) = placing_deferred();
|
||||
let a = texture_image(&mut r, 21, 80, (32, 8));
|
||||
let b = texture_image(&mut r, 22, 80, (16, 4));
|
||||
use_surfaces(&mut r, 1, 0x100, &[(BLOCK, 0, false)]);
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
r.p.script().push(TO_BUFFER, Step::Nil);
|
||||
let before = counted("surface-copy-refused");
|
||||
let mark = r.p.call_log().mark();
|
||||
write(&mut r, 0x101, 21, (32, 8));
|
||||
r.p.world().complete_all(CompleteOn::Caller);
|
||||
let calls = r.p.call_log().since(mark);
|
||||
assert!(calls.iter().any(|c| c.sel == TO_BUFFER), "asked");
|
||||
let (_, into) = overlaps(&calls, &[a, b]);
|
||||
assert!(into.is_empty(), "B takes nothing");
|
||||
let failed = calls.iter().filter(|c| c.sel == FAIL_OUT_OF_MEMORY).count();
|
||||
assert_eq!(failed, 1);
|
||||
assert_eq!(counted("surface-copy-refused"), before + 1);
|
||||
}
|
||||
|
||||
/// A buffer-to-buffer copy (`copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`).
|
||||
const BUFFER_COPY: &str = "copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:";
|
||||
|
||||
|
||||
+12
-2
@@ -242,8 +242,18 @@ repeats the ones code cites.
|
||||
read and drawable format, whose draws took the colour's pass: "The
|
||||
colour as a table"; `display-frame-refused`, a frame of the window the
|
||||
platform refused a pass or a command of, not presented, the window
|
||||
keeping its last complete frame: "A refused encode"), and the guest's slow
|
||||
answers'
|
||||
keeping its last complete frame: "A refused encode"), the surfaces' device
|
||||
caches' (`surface-copy-refused`, a copy of the host's own between a cache,
|
||||
its shapes, its wide home and its pages that the platform refused a
|
||||
command or the encoder of, counted at each refusal and made again only at
|
||||
the guest's next use, download or release: what it was to move is left as
|
||||
not copied, so a `SURFACE_DOWNLOAD` whose copy into the pages was refused
|
||||
is answered failed (`RGFX_STATUS_REFUSED`), where it was answered done
|
||||
over the pages' older bytes before, and a fill, or a copy into a shape
|
||||
or a wide home, refused for a command buffer fails it with Metal's
|
||||
`MTLCommandBufferErrorOutOfMemory`, as a cache's refused memory does:
|
||||
`graphics/decode/surface_cache.rs`, "Refused copies"), and the guest's
|
||||
slow answers'
|
||||
(`slow-answer-over-make`, a ring-0 answer that went on its ring a frame,
|
||||
16.7 ms, or more after the device read its command, during which a make
|
||||
of rt's pool ran, and `slow-answer-over-make-max-ns` the longest;
|
||||
|
||||
Reference in new issue
Block a user