🐛 Fail a buffer as internal where the platform refuses a host copy

What the guest observes changes. e00ce9ff74 failed a guest's command buffer
with MTLCommandBufferErrorOutOfMemory where the platform refused a copy the
host made for it: a fill or a copy into a wide home at its begin, rule 1's copy
into a plane's other shapes, or a copy between a cache and its wide home at an
encoder's end. Nothing ran short of memory there, and an app may answer
OutOfMemory by letting go of caches of its own, so that answer was wrong. Such a
buffer now fails with MTLCommandBufferErrorInternal; OutOfMemory stays on the
existing route, a cache's buffer whose memory the platform refused.

The platform's refusal of a command does not say why it refused, and copy()
answers a copy that made no view or staging piece the same way, so every
refused copy answers the internal error, and none is mapped to OutOfMemory.
Where one command buffer meets both kinds, the memory's wins.

The host's writers' fence update at a guest encoder's end, which those copies
wait for, now folds its answer too: refused, the copies could not wait for the
encoder's writes, so the buffer fails with the internal error, counted under a
code of its own, surface-fence-refused, since it is no copy. The compute
encoder answered nothing of its commands, so ComputeEncoder gains
update_fence, which answers Encoded as a blit or render encoder's command does,
and CommandBuffer gains fail_internal, which rt keeps as it keeps a skipped
dispatch's failure: the first failure set is the one the buffer ends with.

Two new tests pin the fence fold, for a blit and a compute encoder; the fill
and rule 1 tests now expect the internal error and no OutOfMemory, and the
refused-memory test no internal error. Red before (m3-max-78155: the four
failed, the memory test passed). Green after: the reims-vgpu fake set
(m3-max-78157, 1172 passed, 115 skipped), its surface, shape and command buffer
rt tests with rt's compute and command buffer tests on the 5080 (m3-max-78159,
48 passed), and reims-vgpu-vulkan's own (m3-max-78160, 789 passed, 1 skipped).
This commit is contained in:
Anees Iqbal committed 2026-12-02 06:10:00 -08:00
1 parent aaedba617b
commit ac5b41b2ed
11 files changed
+354 -154

No files matched your search

@@ -478,6 +478,13 @@ pub trait CommandBuffer<P: Platform>: Handle {
/// ([`Buffer::make_memory`](super::resource::Buffer::make_memory)), and was dropped. Nothing
/// by default, for a platform that defers no buffer's memory.
fn fail_out_of_memory(&self) {}
/// The platform's own, no Metal call, before the commit: the command buffer ends with
/// Metal's `MTLCommandBufferErrorInternal` (1) in `MTLCommandBufferErrorDomain`, its status
/// an error, whatever its work does, unless it ends with an error of its own, or was failed
/// already ([`Self::fail_out_of_memory`]), the first kept: a command the caller added to it
/// for itself, which its work relies on, was refused by the platform (`reims-vgpu`'s surface
/// caches, "Refused copies"). Nothing by default.
fn fail_internal(&self) {}
/// The platform's own, no Metal call: before any encoder, the caller's word that no
/// compute encoder of the buffer, nor of the parts cut from it ([`Self::split`],
/// [`Self::part`]), is sent a command predication record (`encodeStartIf:...`,
@@ -14,7 +14,7 @@
use super::blit::ResourceRef;
use super::types::{MtlRegion, MtlSize, NsRange};
use super::{Handle, Platform};
use super::{Encoded, Handle, Platform};
use crate::core::raise::{OnFault, RaiseResult};
/// One `MTLComputeCommandEncoder` command.
@@ -281,6 +281,11 @@ pub trait ComputeEncoder<P: Platform>: Handle {
/// Sends one [`ComputeCmd`]. `on` says what a raise in a command reached both under a
/// handler and with none (`EndEncoding`) does; the other commands are reached one way only.
fn encode(&self, on: OnFault, cmd: ComputeCmd<'_, P>) -> RaiseResult<()>;
/// [`ComputeCmd::UpdateFence`] of `fence`, sent as [`Self::encode`] sends it, answering
/// whether the platform recorded it, as a render or a blit encoder's command answers
/// ([`Encoded`]): for a caller that adds the update for itself, whose work after relies on
/// it.
fn update_fence(&self, on: OnFault, fence: &P::Fence) -> RaiseResult<Encoded>;
/// sel: encodeEndDoWhile:offset:comparison:referenceValue: SPI
/// Declared on MTLComputeCommandEncoderSPI (protocol).
fn encode_end_do_while(
@@ -37,6 +37,9 @@ impl CommandQueue<FakePlatform> for Fk<kind::CommandQueue> {
/// names it.
pub const FAIL_OUT_OF_MEMORY: &str = "failOutOfMemory";
/// The name the fake logs [`CommandBuffer::fail_internal`] under: no selector of Metal's names it.
pub const FAIL_INTERNAL: &str = "failInternal";
/// `to`, a command buffer made from `from` (`split`, `part`), keeps the names of `from`'s work, as
/// the Vulkan platform's parts do ([`CommandBuffer::names_work`]).
fn names_on(from: &Fk<kind::CommandBuffer>, to: &Fk<kind::CommandBuffer>) {
@@ -244,6 +247,12 @@ impl CommandBuffer<FakePlatform> for Fk<kind::CommandBuffer> {
self.set_logged(FAIL_OUT_OF_MEMORY, vec![]);
}
/// Logged under [`FAIL_INTERNAL`], as no selector of Metal's names it; the test completes the
/// buffer as it scripts.
fn fail_internal(&self) {
self.set_logged(FAIL_INTERNAL, vec![]);
}
/// Not logged, as no selector of Metal's names it and it changes nothing the buffer does:
/// kept on the model, the first named alone, and handed on to the command buffers `split` and
/// `part` make from it, as the Vulkan platform keeps them
@@ -7,10 +7,10 @@ use super::super::calllog::Arg;
use super::super::objects::{Fk, Model, kind};
use super::super::platform::FakePlatform;
use super::res_ids;
use crate::core::platform::Platform;
use crate::core::platform::compute::*;
use crate::core::platform::stage::{FillEnd, held};
use crate::core::platform::types::NsErrorText;
use crate::core::platform::{Encoded, Platform};
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::testkit::script::{Policy, Step};
@@ -71,6 +71,24 @@ impl Fk<kind::ComputeEncoder> {
}
impl ComputeEncoder<FakePlatform> for Fk<kind::ComputeEncoder> {
/// Logged as [`Self::encode`] logs `updateFence:`, with the script's death or raise answered
/// as [`Fk::act`] answers them; refused, recording nothing, where the script answers nil for
/// it ([`Step::Nil`], the platform's refusal of the command), else recorded.
fn update_fence(
&self,
on: OnFault,
fence: &<FakePlatform as Platform>::Fence,
) -> RaiseResult<Encoded> {
let _ = on;
let step = self.call("updateFence:", vec![Arg::obj(fence)]);
step.throws(Policy::Caught, "updateFence:")?;
Ok(if step.is_nil() {
Encoded::REFUSED
} else {
Encoded::RECORDED
})
}
fn encode(&self, on: OnFault, cmd: ComputeCmd<'_, FakePlatform>) -> RaiseResult<()> {
let sel = cmd.selector();
match cmd {
@@ -64,8 +64,9 @@
//! (`CommandBuffer::fail_out_of_memory`, `super::buffer`'s "Deferred memory") ends with
//! `OutOfMemory` (8) where rt gave it no error of its own: its status, once rt's is completed,
//! is an error, and its error, then, that one. One a dispatch of which its stage's fill skipped
//! (`super::compute`, [`Kept::fail_internal`]) ends so with `Internal` (1). The first of the
//! two set is the one it ends with.
//! (`super::compute`, [`Kept::fail_internal`]), or that its caller failed for a command it added
//! for itself that rt refused (`CommandBuffer::fail_internal`), ends so with `Internal` (1). The
//! first set is the one it ends with.
//! - **Encoders**: blit encoders ([`super::blit`]), compute encoders ([`super::compute`]), of
//! the serial dispatch type or the descriptor's (another value is Metal's refusal, nil), and
//! render encoders ([`super::render`]) of the pass the descriptor keeps
@@ -924,8 +925,9 @@ pub struct Kept(
type KeptObjects = HashMap<ObjId, Box<dyn Send>, KeyBuild>;
/// The code of Metal's error a command buffer was failed with, 0 for none, the first set kept: by
/// its caller for a deferred buffer's memory rt refused (`CommandBuffer::fail_out_of_memory`), or
/// by a dispatch of it that its stage's fill skipped ([`Kept::fail_internal`]) (the module's docs,
/// its caller for a deferred buffer's memory rt refused (`CommandBuffer::fail_out_of_memory`) or
/// for a command it added for itself that rt refused (`CommandBuffer::fail_internal`), or by a
/// dispatch of it that its stage's fill skipped ([`Kept::fail_internal`]) (the module's docs,
/// "What a completed handler learns").
#[derive(Clone, Default)]
struct Failed(Arc<AtomicI64>);
@@ -1104,7 +1106,10 @@ fn error_of(made: &rt::CommandBuffer, failure: &Failure, failed: &Failed) -> Opt
ERROR_OUT_OF_MEMORY => {
"a buffer the command buffer used was refused its memory at that use"
}
_ => "a dispatch of the command buffer was skipped: its stage's fill failed or breached",
_ => {
"a dispatch of the command buffer was skipped, its stage's fill having failed or \
breached, or a command its caller added for itself was refused"
}
};
Some(NsErrorText {
domain: ERROR_DOMAIN.to_owned(),
@@ -1565,6 +1570,12 @@ impl CommandBuffer<RtPlatform> for RtObj<RtCommandBuffer> {
self.kept.3.fail(ERROR_OUT_OF_MEMORY);
}
/// Ends the command buffer with `Internal` (the module's docs, "What a completed handler
/// learns").
fn fail_internal(&self) {
self.kept.3.fail(ERROR_INTERNAL);
}
/// rt's wait, then the wait for its completed handlers handed on ([`hand_on`]); none,
/// counted, where rt refuses it (in a scheduled handler, or on rt's completion thread for a
/// command buffer not yet completed, which it would never see), and so on the queue of
@@ -82,7 +82,7 @@ use crate::core::platform::blit::ResourceRef;
use crate::core::platform::compute::{ComputeCmd, ComputeEncoder};
use crate::core::platform::stage::{Refused, StageFills, held};
use crate::core::platform::types::{MtlSize, NsRange};
use crate::core::platform::{Handle, ObjId, Platform};
use crate::core::platform::{Encoded, Handle, ObjId, Platform};
use crate::core::raise::{OnFault, RaiseResult};
use crate::core::sync::Mutex;
@@ -553,40 +553,70 @@ pub(super) fn note_declared(
}
}
impl RtObj<RtComputeEncoder> {
/// `cmd` on rt's encoder (the module's docs); `endEncoding` ends rt's encoder. Whether rt
/// recorded it: refused where it stopped, at Metal's refusal, an unbuilt piece or rt's own,
/// each counted ([`report`]).
fn send(&self, cmd: ComputeCmd<'_, RtPlatform>) -> Encoded {
let sel = cmd.selector();
let ending = matches!(cmd, ComputeCmd::EndEncoding);
let dispatch = dispatches(&cmd);
note_copies(self.kept.copies(), &cmd);
let mut open = self.open.lock();
if let Some(names) = open.naming.names() {
note_names(names, &cmd);
}
let stopped = self.command(&mut open, cmd).err();
let functions = match (&stopped, &open.kernel) {
(Some(Stop::Rt(_) | Stop::Unbuilt(_)), Some(kernel)) if dispatch => {
vec![("kernel", kernel.clone())]
}
_ => Vec::new(),
};
if ending && let Some(e) = open.rt.take() {
e.end_encoding();
self.mark.end();
open.naming.end();
}
drop(open);
let encoded = match stopped {
None => Encoded::RECORDED,
Some(_) => Encoded::REFUSED,
};
naming_functions(functions, || report(sel, stopped));
encoded
}
}
impl ComputeEncoder<RtPlatform> for RtObj<RtComputeEncoder> {
/// rt's command (the module's docs); `endEncoding` ends rt's encoder.
/// rt's command ([`Self::send`]), whose refusal it answers nothing of.
fn encode(&self, on: OnFault, cmd: ComputeCmd<'_, RtPlatform>) -> RaiseResult<()> {
let recorded_call = crate::recorder::rec_call!(@cmd self, cmd);
let recorded_answer = crate::recorder::run(|| -> RaiseResult<()> {
let _ = on;
let sel = cmd.selector();
let ending = matches!(cmd, ComputeCmd::EndEncoding);
let dispatch = dispatches(&cmd);
note_copies(self.kept.copies(), &cmd);
let mut open = self.open.lock();
if let Some(names) = open.naming.names() {
note_names(names, &cmd);
}
let stopped = self.command(&mut open, cmd).err();
let functions = match (&stopped, &open.kernel) {
(Some(Stop::Rt(_) | Stop::Unbuilt(_)), Some(kernel)) if dispatch => {
vec![("kernel", kernel.clone())]
}
_ => Vec::new(),
};
if ending && let Some(e) = open.rt.take() {
e.end_encoding();
self.mark.end();
open.naming.end();
}
drop(open);
naming_functions(functions, || report(sel, stopped));
self.send(cmd).go_on();
Ok(())
});
crate::recorder::rec_done!(recorded_call, recorded_answer);
recorded_answer
}
/// rt's `updateFence:` ([`Self::send`]), answering whether rt recorded it.
fn update_fence(
&self,
on: OnFault,
fence: &<RtPlatform as Platform>::Fence,
) -> RaiseResult<Encoded> {
let cmd = ComputeCmd::UpdateFence { fence };
let recorded_call = crate::recorder::rec_call!(@cmd self, cmd);
let recorded_answer = crate::recorder::run(|| -> RaiseResult<Encoded> {
let _ = on;
Ok(self.send(cmd))
});
crate::recorder::rec_done!(recorded_call, recorded_answer);
recorded_answer
}
/// Unbuilt: NO, as with nothing open ([`Unbuilt::Predication`]).
fn encode_end_do_while(
&self,
+45 -39
View File
@@ -171,7 +171,7 @@ use super::sequencer::Ticket;
use super::shares::FanOut;
use super::split::{Estimate, PACE_WAIT_MOST, Parts, Progress, QueueRate, SplitHold};
use super::surface_cache::shapes::ShapeRef;
use super::surface_cache::{Reach, Uses};
use super::surface_cache::{FENCE_REFUSED, Failure, Reach, Uses};
use super::surface_order::{AheadEntry, BEGIN_WAIT_LOGGED, Marks, Signalled};
use super::tables::{FOUND_A_HOLD, QueueCounts};
use super::{
@@ -779,9 +779,8 @@ struct Walked<P: Platform> {
/// The blocks whose caches' buffers the walk named an object over
/// ([`GraphicsDecoder::note_over_cache`]).
over: Vec<u64>,
/// Whether the platform refused a cache's buffer its memory at a use the walk made
/// ([`GraphicsDecoder::out_of_memory`]).
out_of_memory: bool,
/// How what the host did for the walk fails the command buffer ([`GraphicsDecoder::failed`]).
failure: Failure,
/// The first compute and render pipeline states its encoders set, 0 for none
/// ([`GraphicsDecoder::pipeline_set`]).
firsts: (u64, u64),
@@ -903,10 +902,9 @@ pub(crate) struct Begun<P: Platform> {
in_flight: InFlight,
/// Its count among the users of the device caches it uses, until its commit.
uses: Option<Uses<P>>,
/// A fill of a device cache its begin made found the platform refused the cache's buffer its
/// memory: it fails with Metal's `MTLCommandBufferErrorOutOfMemory`
/// ([`GraphicsDecoder::out_of_memory`]).
out_of_memory: bool,
/// How a fill or a copy of a device cache its begin made fails it
/// ([`super::surface_cache::Begin::failure`], [`GraphicsDecoder::failed`]).
failure: Failure,
/// It holds `SURFACE_ORDER`: it signals its queue's surface timeline as it ends.
order: bool,
/// Its queue's marks in the surface order.
@@ -2278,7 +2276,7 @@ impl<P: Platform> GraphicsDecoder<P> {
let super::surface_cache::Begin {
waits: fill_waits,
follows,
out_of_memory,
failure,
mut uses,
} = (self.surface_caches).before_answering(
device,
@@ -2337,7 +2335,7 @@ impl<P: Platform> GraphicsDecoder<P> {
cb,
in_flight,
uses,
out_of_memory,
failure,
order: take.order.is_some(),
marks: Arc::clone(&counts.order),
waits_for_order,
@@ -2392,7 +2390,7 @@ impl<P: Platform> GraphicsDecoder<P> {
cb,
in_flight,
uses,
out_of_memory,
failure,
order,
marks,
waits_for_order,
@@ -2573,10 +2571,10 @@ impl<P: Platform> GraphicsDecoder<P> {
};
// A cache's buffer the platform refused its memory at a use the walk made, or at a fill
// its begin made, fails the buffer, its last part's error its own, as Metal's fails with
// `MTLCommandBufferErrorOutOfMemory` ([`GraphicsDecoder::out_of_memory`]).
if self.out_of_memory.take() | out_of_memory {
cb.fail_out_of_memory();
}
// `MTLCommandBufferErrorOutOfMemory`; a command the host added for itself that the
// platform refused fails it with `MTLCommandBufferErrorInternal`
// ([`GraphicsDecoder::failed`]).
self.failed.take().max(failure).fail::<P>(&cb);
self.name_firsts();
let commit = || {
if let Some(submission) = submission {
@@ -3346,7 +3344,7 @@ impl<P: Platform> GraphicsDecoder<P> {
self.laid_written.borrow_mut().clear();
self.shapes_written.borrow_mut().clear();
self.over_caches.borrow_mut().clear();
self.out_of_memory.set(false);
self.failed.set(Failure::None);
self.encoder_shapes.borrow_mut().clear();
self.slot_shapes.borrow_mut().clear();
self.slot_pipeline.set(0);
@@ -3560,7 +3558,7 @@ impl<P: Platform> GraphicsDecoder<P> {
written: std::mem::take(&mut *self.laid_written.borrow_mut()),
shapes: std::mem::take(&mut *self.shapes_written.borrow_mut()),
over: std::mem::take(&mut *self.over_caches.borrow_mut()),
out_of_memory: self.out_of_memory.take(),
failure: self.failed.take(),
firsts: self.firsts.take(),
began: began.saturating_duration_since(deal.handed),
walk,
@@ -3613,7 +3611,7 @@ impl<P: Platform> GraphicsDecoder<P> {
written: std::mem::take(&mut *self.laid_written.borrow_mut()),
shapes: std::mem::take(&mut *self.shapes_written.borrow_mut()),
over: std::mem::take(&mut *self.over_caches.borrow_mut()),
out_of_memory: self.out_of_memory.take(),
failure: self.failed.take(),
firsts: self.firsts.take(),
began: began.saturating_duration_since(handed),
walk: clock.now_mono().saturating_duration_since(began),
@@ -3699,7 +3697,7 @@ impl<P: Platform> GraphicsDecoder<P> {
written,
shapes,
over,
out_of_memory,
failure,
firsts: (compute, render),
began,
walk,
@@ -3708,9 +3706,7 @@ impl<P: Platform> GraphicsDecoder<P> {
return Ok(Err(e));
}
deal.next = j + 1;
if out_of_memory {
self.out_of_memory.set(true);
}
self.fail(failure);
// Its firsts follow those of the chunks before it, before any of it is committed.
if let Some(names) = self.work_names.borrow().as_ref() {
names.note_firsts(compute, render);
@@ -3889,6 +3885,25 @@ impl<P: Platform> GraphicsDecoder<P> {
view.find_all(ids[..n].iter().copied());
}
/// The platform's answer to the writers' fence update the walk added at a guest encoder's end
/// ([`Self::laid_writes_fence`]): refused, the host's copies of the encoder's writes after it
/// cannot wait for them, so the command buffer fails with the internal error, counted
/// ([`FENCE_REFUSED`], the process's first logged; `surface_cache`'s module doc, "Refused
/// copies").
fn fence_updated(&self, updated: Encoded) {
if updated.recorded() {
return;
}
self.fail(Failure::Internal);
reims_vgpu_vulkan::answer::count_kind(FENCE_REFUSED);
// Once per boot; later ones at debug, counted (`core::logging`).
log::warn!(
target: "reims_vgpu::graphics", kind:% = FENCE_REFUSED;
"the platform refused the writers' fence update at a guest encoder's end, which the \
host's copies of its writes wait for: the command buffer fails ({FENCE_REFUSED})"
);
}
/// The writers' fence ([`super::surface_cache::Caches::writes_fence`]) where the encoder being
/// walked noted a use that may write a laid-out cache or its wide home ([`Self::note_laid`]),
/// or a shape whose plane has another ([`Self::note_shape`]), for it to update as it ends;
@@ -3911,7 +3926,7 @@ impl<P: Platform> GraphicsDecoder<P> {
/// ([`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. A copy the
/// platform refused a command of fails the command buffer, as a refused memory does
/// platform refused a command of fails the command buffer with the internal error
/// (`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());
@@ -3939,9 +3954,7 @@ impl<P: Platform> GraphicsDecoder<P> {
self.laid_written
.borrow_mut()
.extend(written.iter().map(|&(block, _)| block));
if self.surface_caches.reconcile(cb, &written)? {
self.out_of_memory.set(true);
}
self.fail(self.surface_caches.reconcile(cb, &written)?);
Ok(())
}
@@ -3956,9 +3969,7 @@ impl<P: Platform> GraphicsDecoder<P> {
if written.is_empty() {
return Ok(());
}
if self.surface_caches.reconcile_shapes(cb, &written)? {
self.out_of_memory.set(true);
}
self.fail(self.surface_caches.reconcile_shapes(cb, &written)?);
Ok(())
}
@@ -4274,26 +4285,21 @@ impl<P: Platform> GraphicsDecoder<P> {
match encoder.take() {
Some(OpenEncoder::Render(enc, _)) => {
if let Some(fence) = fence {
enc.encode(
ON,
RenderCmd::UpdateFence {
fence,
stages: RENDER_STAGE_FRAGMENT,
},
)?
.go_on();
let stages = RENDER_STAGE_FRAGMENT;
let update = RenderCmd::UpdateFence { fence, stages };
self.fence_updated(enc.encode(ON, update)?);
}
enc.encode(ON, RenderCmd::EndEncoding)?.go_on();
}
Some(OpenEncoder::Compute(enc, _)) => {
if let Some(fence) = fence {
enc.encode(ON, ComputeCmd::UpdateFence { fence })?;
self.fence_updated(enc.update_fence(ON, fence)?);
}
enc.encode(ON, ComputeCmd::EndEncoding)?;
}
Some(OpenEncoder::Blit(enc)) => {
if let Some(fence) = fence {
enc.encode(ON, BlitCmd::UpdateFence { fence })?.go_on();
self.fence_updated(enc.encode(ON, BlitCmd::UpdateFence { fence })?);
}
enc.encode(ON, BlitCmd::EndEncoding)?.go_on();
}
+20 -11
View File
@@ -269,11 +269,11 @@ use managed::{STORAGE_MODE_MANAGED, storage_mode};
pub(crate) use pipeline_key::PipelineKey;
use sequencer::Sequencer;
pub(crate) use sequencer::Ticket;
use surface_cache::Caches;
#[cfg(test)]
pub(crate) use surface_cache::LARGEST as surface_cache_largest;
pub(crate) use surface_cache::shapes::ShapesLive;
pub(crate) use surface_cache::{CacheLive, CachesLive, FillHook, FillWait};
use surface_cache::{Caches, Failure};
pub(crate) use tables::TableCounts;
use tables::{BytesKeep, Context, Entry, GuestBytes, LaidUse, QueueCounts, View};
@@ -1472,12 +1472,15 @@ pub struct GraphicsDecoder<P: Platform> {
/// The blocks whose device caches' buffers the command buffer's walk named an object over
/// itself so far, each once ([`Self::note_over_cache`]).
over_caches: RefCell<Vec<u64>>,
/// Whether the platform refused a device cache's buffer its memory at a use the command
/// buffer's walk made so far ([`Self::require_buffer`], [`Self::reconcile_shapes`]; the
/// cache's module doc, "Deferred memory"): the op that used it is dropped, and the buffer
/// fails at its commit with `MTLCommandBufferErrorOutOfMemory`, as Metal's fails where a
/// resource it uses could not be made resident.
out_of_memory: Cell<bool>,
/// How the command buffer fails at its commit for what the host did for it in the walk so
/// far ([`Failure`]): with `MTLCommandBufferErrorOutOfMemory` where the platform refused a
/// device cache's buffer its memory at a use the walk made ([`Self::require_buffer`],
/// [`Self::reconcile_shapes`]; the cache's module doc, "Deferred memory"), the op that used
/// it dropped, as Metal's fails where a resource it uses could not be made resident; with
/// `MTLCommandBufferErrorInternal` where it refused a command the host added for itself, a
/// copy between the caches or a writers' fence update (the cache's module doc, "Refused
/// copies").
failed: Cell<Failure>,
/// In the per-shape form, the shapes the encoder being walked may write, each by its block
/// and once, in the order the walk last noted them ([`Self::note_shape`]): at the encoder's
/// end each other shape of their planes takes their write ([`Self::reconcile_shapes`]).
@@ -1696,7 +1699,7 @@ impl<P: Platform> GraphicsDecoder<P> {
laid_written: RefCell::new(Vec::new()),
shapes_written: RefCell::new(Vec::new()),
over_caches: RefCell::new(Vec::new()),
out_of_memory: Cell::new(false),
failed: Cell::new(Failure::None),
encoder_shapes: RefCell::new(Vec::new()),
slot_shapes: RefCell::new(Vec::new()),
slot_pipeline: Cell::new(0),
@@ -7656,7 +7659,7 @@ impl<P: Platform> GraphicsDecoder<P> {
/// cache's buffer itself is noted ([`Self::note_over_cache`]), and has its memory made, which
/// the cache's buffer gets at its first use (the cache's module doc, "Deferred memory"):
/// where the platform refuses it, the raise is [`refused::out_of_memory`]'s, which drops the
/// op, and the command buffer fails ([`Self::out_of_memory`]).
/// op, and the command buffer fails ([`Self::failed`]).
pub(crate) fn require_buffer(&self, id: u64) -> RaiseResult<&P::Buffer> {
let (entry, buffer) = self.buffer_entry(id)?;
self.note_over_cache(entry);
@@ -7686,16 +7689,22 @@ impl<P: Platform> GraphicsDecoder<P> {
/// device cache's buffer itself ([`Entry::over_cache`]) whose memory is not made yet (the
/// cache's module doc, "Deferred memory"): where the platform refuses it, the raise is
/// [`refused::out_of_memory`]'s, which drops the op, and the command buffer fails
/// ([`Self::out_of_memory`]).
/// ([`Self::failed`]).
fn cache_memory(&self, id: u64, entry: &Entry<P>, buffer: &P::Buffer) -> RaiseResult<()> {
let block = entry.span.map(|(block, _)| block);
if !entry.over_cache || self.surface_caches.memory_of(block, buffer) {
return Ok(());
}
self.out_of_memory.set(true);
self.fail(Failure::OutOfMemory);
Err(refused::out_of_memory(id))
}
/// The command buffer being walked fails at its commit as `failure` says, or as it failed
/// already where that is the greater ([`Self::failed`]).
pub(crate) fn fail(&self, failure: Failure) {
self.failed.set(self.failed.get().max(failure));
}
/// The buffer `id` names, `None` for 0; an exec fault when a non-zero `id` names no buffer.
/// Noted as [`Self::require_buffer`] notes it.
pub(crate) fn get_buffer(&self, id: u64) -> RaiseResult<Option<&P::Buffer>> {
@@ -452,8 +452,14 @@
//! the pages' older bytes; a release's is logged. An early copy refused is not made, its
//! command buffer not committed. A fill, or a copy into a wide home, refused at a command
//! buffer's begin, and a write's copy into another shape or a copy between a cache and its
//! home refused at its encoder's end, fails the command buffer as a refused memory does
//! ("Deferred memory"). A cache's zeros refused leave it unmade, as where the platform makes
//! home refused at its encoder's end, fails the command buffer, as a refused memory does
//! ("Deferred memory"), but with Metal's `MTLCommandBufferErrorInternal`, not
//! `OutOfMemory`, which an app may answer by letting go of caches of its own, and nothing ran
//! short of memory ([`Failure`]). The platform's refusal of a command does not say why it
//! refused, nor does a copy that made no view or piece, so every refused copy answers the
//! internal error; `OutOfMemory` stays the memory's alone. So does a writers' fence update
//! at a guest encoder's end that the platform refused, which those copies wait for
//! ([`FENCE_REFUSED`]): unordered, they would read the encoder's writes too early. A cache's zeros refused leave it unmade, as where the platform makes
//! no encoder for them, and the host's video's zeros owed. The host tries none again of its
//! own: the next use, download or release that needs the copy makes it. The guest's own
//! commands are no such copies: one the platform refused is dropped, and its command buffer
@@ -1462,6 +1468,38 @@ pub(crate) fn fold(whole: &mut Encoded, encoded: Encoded) {
}
}
/// The degradation code of a writers' fence update at a guest encoder's end that the platform
/// refused (`super::cmdbuf`'s `ENCODER_END`): the host's copies of the encoder's writes after it
/// (rule 1's, and those between a cache and its wide home) could not wait for them, so its
/// command buffer fails (the module doc, "Refused copies"; docs/conventions.md). Counted at each
/// refusal.
pub(crate) const FENCE_REFUSED: &str = "surface-fence-refused";
/// How a guest's command buffer fails for what the host did for it, by the platform's refusal's
/// kind: not; with Metal's `MTLCommandBufferErrorInternal` where it refused a command the host
/// added for itself, a copy of the caches' or a writers' fence update (the module doc, "Refused
/// copies"); with `MTLCommandBufferErrorOutOfMemory` where it refused a cache's buffer its memory
/// ("Deferred memory"), which an app may answer by letting go of its own caches. Where both, the
/// memory's: the greater.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum Failure {
#[default]
None,
Internal,
OutOfMemory,
}
impl Failure {
/// Fails `cb` so, before its commit; nothing for [`Failure::None`].
pub(crate) fn fail<P: Platform>(self, cb: &P::CommandBuffer) {
match self {
Failure::None => {}
Failure::Internal => cb.fail_internal(),
Failure::OutOfMemory => cb.fail_out_of_memory(),
}
}
}
/// The name of the shapes' age rule's timer's thread ([`AgeTimer`]).
const SHAPE_AGE_THREAD: &str = "reims-vgpu.graphics-shape-age";
@@ -2657,11 +2695,11 @@ pub(crate) struct SurfaceCaches<P: Platform> {
/// The threads that move a staged download's bytes into its pages and land it
/// ([`INTO_PAGES_THREADS`]), a block's in the order their command buffers completed.
lands_out: Arc<Worker>,
/// A fill since it was last taken found the platform refused a cache's buffer its memory
/// ([`Self::fill`], [`Self::fill_shapes`]), or a command of the fill or of a copy into a
/// wide home ([`Self::home_in`], the module doc, "Refused copies"): a begin's fails its
/// command buffer ([`Begin::out_of_memory`]).
memory_refused: bool,
/// How a fill since it was last taken failed its command buffer: the platform refused a
/// cache's buffer its memory ([`Self::fill`], [`Self::fill_shapes`]), or a command of the
/// fill or of a copy into a wide home ([`Self::home_in`], the module doc, "Refused copies").
/// A begin's fails its command buffer so ([`Begin::failure`]).
failed: Failure,
/// The command buffers finished that used a cache and wait on the GPU for a buffer of another
/// queue that had not finished then, each as the cache's users name it: by its queue and the
/// value of its end event. Those finished since are let go of as another is kept
@@ -2987,7 +3025,7 @@ impl<P: Platform> SurfaceCaches<P> {
left_over: HashMap::default(),
let_go: Vec::new(),
lands_out: Arc::new(Worker::new(INTO_PAGES_THREADS)),
memory_refused: false,
failed: Failure::None,
held: Vec::new(),
asker: None,
}
@@ -4355,7 +4393,7 @@ impl<P: Platform> SurfaceCaches<P> {
if let Some(home) = cache.wide.as_mut() {
home.stale = true;
}
self.memory_refused = true;
self.failed = self.failed.max(Failure::Internal);
copy_refused(format_args!(
"the IOSurface block at {block:#x}: a copy of its cache into its wide home"
));
@@ -4369,20 +4407,20 @@ impl<P: Platform> SurfaceCaches<P> {
/// through the textures over its wide home (`from_home`) or over its cache: the side it
/// wrote is copied into the other in `cb`, its texel rows alone, so the encoders after it
/// read the write through either, as Metal's do (the module doc, "Wider than the plane").
/// Nothing where the block has no wide home. Whether the platform refused the copy, which
/// fails the command buffer (the module doc, "Refused copies"): a home it was to copy into
/// lacks the cache's texels still.
/// Nothing where the block has no wide home. How the command buffer fails: with the
/// internal error where the platform refused the copy (the module doc, "Refused copies"),
/// a home it was to copy into lacking the cache's texels still.
pub(crate) fn reconcile(
&mut self,
cb: &P::CommandBuffer,
block: u64,
from_home: bool,
) -> RaiseResult<bool> {
) -> RaiseResult<Failure> {
let Some(cache) = self.by_block.get_mut(&block) else {
return Ok(false);
return Ok(Failure::None);
};
let Some(home) = cache.wide.as_mut() else {
return Ok(false);
return Ok(Failure::None);
};
home.stale = false;
let way = if from_home { Way::In } else { Way::Out };
@@ -4395,11 +4433,11 @@ impl<P: Platform> SurfaceCaches<P> {
copy_refused(format_args!(
"the IOSurface block at {block:#x}: a copy between its cache and its wide home"
));
return Ok(true);
return Ok(Failure::Internal);
}
None => {}
}
Ok(false)
Ok(Failure::None)
}
/// The fence an encoder that may have written a laid-out cache or its wide home updates as it
@@ -4564,7 +4602,7 @@ impl<P: Platform> SurfaceCaches<P> {
cb: &P::CommandBuffer,
block: u64,
written: &[u64],
refused: &mut bool,
failed: &mut Failure,
) -> RaiseResult<Vec<P::Texture>> {
let since = self.dirty_since(block);
let Some(cache) = self.by_block.get_mut(&block) else {
@@ -4608,11 +4646,11 @@ impl<P: Platform> SurfaceCaches<P> {
.collect();
let into: Vec<u64> = (others.iter()).filter(|o| o.1).map(|o| o.0).collect();
// The source's overlap goes into the buffer on the way: within its extent. Where the
// platform refuses the buffer's memory, no copy is made, and `refused` fails the
// command buffer (the module doc, "Deferred memory"); so it does where the platform
// refuses a command of the copy ("Refused copies").
// platform refuses the buffer's memory, no copy is made, and `failed` fails the
// command buffer with OutOfMemory (the module doc, "Deferred memory"); where it
// refuses a command of the copy, with the internal error ("Refused copies").
if !into.is_empty() && !cache.copy_through(MemoryFor::Reconcile) {
*refused = true;
*failed = Failure::OutOfMemory;
} else {
if !into.is_empty() {
cache.changed.add(key.span());
@@ -4626,7 +4664,7 @@ impl<P: Platform> SurfaceCaches<P> {
&mut self.counts.shapes,
)?;
if !copied.recorded() {
*refused = true;
*failed = (*failed).max(Failure::Internal);
copy_refused(format_args!(
"the IOSurface block at {block:#x}: a write's copy into the other shapes \
of its plane"
@@ -5678,7 +5716,9 @@ impl<P: Platform> SurfaceCaches<P> {
return true;
}
let made = cache.copy_through(MemoryFor::Fill);
self.memory_refused |= !made;
if !made {
self.failed = Failure::OutOfMemory;
}
made
}) else {
return Ok(None);
@@ -5756,7 +5796,7 @@ impl<P: Platform> SurfaceCaches<P> {
}
}
if !whole.recorded() {
self.memory_refused = true;
self.failed = self.failed.max(Failure::Internal);
copy_refused(format_args!(
"the IOSurface block at {block:#x}: a fill of its cache from its pages"
));
@@ -5818,7 +5858,9 @@ impl<P: Platform> SurfaceCaches<P> {
return true;
}
let made = cache.copy_through(MemoryFor::FillShapes);
self.memory_refused |= !made;
if !made {
self.failed = Failure::OutOfMemory;
}
made
}) else {
return Ok(None);
@@ -5900,7 +5942,7 @@ impl<P: Platform> SurfaceCaches<P> {
cache.shapes.written_back(&back, &mut self.counts.shapes);
}
if !whole.recorded() {
self.memory_refused = true;
self.failed = self.failed.max(Failure::Internal);
copy_refused(format_args!(
"the IOSurface block at {block:#x}: a fill of its shapes"
));
@@ -7243,10 +7285,10 @@ pub(crate) struct Begin<P: Platform> {
pub(crate) waits: bool,
/// It follows a deferred copy of a cache ([`Uses`]'s `follows`).
pub(crate) follows: bool,
/// A fill the begin made found the platform refused a cache's buffer its memory (the module
/// doc, "Deferred memory"): the command buffer fails with Metal's
/// `MTLCommandBufferErrorOutOfMemory`.
pub(crate) out_of_memory: bool,
/// How a fill or a copy the begin made fails the command buffer ([`Failure`]): the platform
/// refused a cache's buffer its memory (the module doc, "Deferred memory"), or a command of
/// it ("Refused copies").
pub(crate) failure: Failure,
/// Its count among the users of the blocks it uses.
pub(crate) uses: Option<Uses<P>>,
}
@@ -7997,20 +8039,20 @@ impl<P: Platform> Caches<P> {
/// An encoder just ended in command buffer `cb` that may have written the surfaces of
/// `written`, each by its block and whether through a texture over its wide home: each side
/// written is copied into the other in `cb` ([`SurfaceCaches::reconcile`]). Whether the
/// platform refused a copy, which fails the command buffer (the module doc, "Refused
/// copies").
/// written is copied into the other in `cb` ([`SurfaceCaches::reconcile`]). How the command
/// buffer fails: with the internal error where the platform refused a copy (the module doc,
/// "Refused copies").
pub(crate) fn reconcile(
&self,
cb: &P::CommandBuffer,
written: &[(u64, bool)],
) -> RaiseResult<bool> {
) -> RaiseResult<Failure> {
let mut state = self.lock();
let mut refused = false;
let mut failure = Failure::None;
for &(block, from_home) in written {
refused |= state.reconcile(cb, block, from_home)?;
failure = failure.max(state.reconcile(cb, block, from_home)?);
}
Ok(refused)
Ok(failure)
}
/// Whether the encoder being walked, which may have written the shapes `written`, each by its
@@ -8025,14 +8067,15 @@ impl<P: Platform> Caches<P> {
/// each by its block, in the order its walk last noted them: each other shape of their planes
/// takes the write in `cb` ([`SurfaceCaches::reconcile_shapes`]). What goes is let go of with
/// no lock held, a refusal logged. A cache's buffer the copy goes through has its memory made
/// with the lock let go of first ([`Self::make_memory`]); whether the platform refused one
/// its memory, which fails the command buffer (the module doc, "Deferred memory"), or
/// refused a command of a copy ("Refused copies").
/// with the lock let go of first ([`Self::make_memory`]). How the command buffer fails
/// ([`Failure`]): with OutOfMemory where the platform refused one its memory (the module
/// doc, "Deferred memory"), with the internal error where it refused a command of a copy
/// ("Refused copies").
pub(crate) fn reconcile_shapes(
&self,
cb: &P::CommandBuffer,
written: &[(u64, shapes::ShapeRef)],
) -> RaiseResult<bool> {
) -> RaiseResult<Failure> {
let mut blocks: Vec<u64> = written.iter().map(|(block, _)| *block).collect();
blocks.sort_unstable();
blocks.dedup();
@@ -8046,7 +8089,7 @@ impl<P: Platform> Caches<P> {
})
.collect();
let mut gone = Vec::new();
let mut refused = false;
let mut failure = Failure::None;
{
let mut state = self.lock();
// A write another shape takes goes through the cache's buffer.
@@ -8064,7 +8107,7 @@ impl<P: Platform> Caches<P> {
state = self.lock();
}
for (block, ids) in &by_block {
gone.extend(state.reconcile_shapes(cb, *block, ids, &mut refused)?);
gone.extend(state.reconcile_shapes(cb, *block, ids, &mut failure)?);
}
}
if !gone.is_empty()
@@ -8076,7 +8119,7 @@ impl<P: Platform> Caches<P> {
release was refused: {refusal}"
);
}
Ok(refused)
Ok(failure)
}
/// The device's reset ([`SurfaceCaches::reset`]), which no command buffer is begun across:
@@ -8240,11 +8283,11 @@ impl<P: Platform> Caches<P> {
if let Some(answer) = answer {
answer();
}
let (waits, follows, out_of_memory) = (false, false, false);
let (waits, follows, failure) = (false, false, Failure::None);
return Ok(Begin {
waits,
follows,
out_of_memory,
failure,
uses: None,
});
}
@@ -8270,19 +8313,19 @@ impl<P: Platform> Caches<P> {
}
let before = self.before_locked(state, device, cb, uses, (reach, asker));
drop(answered);
let (waits, out_of_memory, uses) = before?;
let (waits, failure, uses) = before?;
let follows = uses.as_ref().is_some_and(|u| !u.follows.is_empty());
Ok(Begin {
waits,
follows,
out_of_memory,
failure,
uses,
})
}
/// [`Self::before_answering`] from its lock on, `state`, which it lets go of: whether `cb`
/// waits on the GPU for a copy of a cache, whether a fill it made found the platform refused a
/// cache's buffer its memory, and its uses.
/// waits on the GPU for a copy of a cache, how a fill or a copy it made fails `cb`
/// ([`Begin::failure`]), and its uses.
fn before_locked<'a>(
self: &'a Arc<Self>,
mut state: Locked<'a, P>,
@@ -8290,7 +8333,7 @@ impl<P: Platform> Caches<P> {
cb: &P::CommandBuffer,
uses: &[RgfxOpSurfaceUse],
(reach, asker): (&Reach, Option<&Asker>),
) -> RaiseResult<(bool, bool, Option<Uses<P>>)> {
) -> RaiseResult<(bool, Failure, Option<Uses<P>>)> {
// The pieces the first fills the buffer's work reaches, and a recovery's refills, would
// make for want of a spare are made with the lock let go of, and reserved for their
// blocks (the module doc, "Staged copies").
@@ -8302,15 +8345,15 @@ impl<P: Platform> Caches<P> {
};
reserve_ahead(&mut state, device, &reached);
state.after_recovery(device);
// What this begin's fills find refused of a cache's buffer's memory, alone.
state.memory_refused = false;
// What this begin's fills find refused, alone.
state.failed = Failure::None;
let reached = match reach.work {
true => state.fill_reached(device, cb, reach.context)?,
false => false,
};
let mut memory_refused = std::mem::take(&mut state.memory_refused);
let mut failure = std::mem::take(&mut state.failed);
if uses.is_empty() {
return Ok((reached, memory_refused, None));
return Ok((reached, failure, None));
}
let picked: Vec<RgfxOpSurfaceUse> = by_block(&state, uses).into_iter().copied().collect();
let decoded_of = |block: u64| {
@@ -8404,7 +8447,7 @@ impl<P: Platform> Caches<P> {
};
let mut waits = reached;
let mut raised = None;
state.memory_refused = false;
state.failed = Failure::None;
for u in &picked {
let decoded = decoded_of(u.block_offset);
let video = reach.video && !reach.work;
@@ -8428,7 +8471,7 @@ impl<P: Platform> Caches<P> {
}
}
}
memory_refused |= std::mem::take(&mut state.memory_refused);
failure = failure.max(std::mem::take(&mut state.failed));
drop(state);
if !spare.is_empty()
&& let Err(refusal) = refusals::refusing(move || drop(spare))
@@ -8442,11 +8485,7 @@ impl<P: Platform> Caches<P> {
if let Some(raise) = raised {
return Err(raise);
}
Ok((
waits,
memory_refused,
(!held.blocks.is_empty()).then_some(held),
))
Ok((waits, failure, (!held.blocks.is_empty()).then_some(held)))
}
/// Whether a command buffer whose `SURFACE_USE` ops are `uses` waits for no copy of a cache
@@ -1495,17 +1495,24 @@ mod tests {
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
/// A shape whose fill the platform refuses owes it still: the command buffer whose begin
/// asked the fill fails with Metal's internal error, not OutOfMemory, as nothing ran short
/// of memory; 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() {
use reims_vgpu_vulkan::core::testkit::impls::command::{FAIL_INTERNAL, FAIL_OUT_OF_MEMORY};
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");
let mark = r.p.call_log().mark();
use_surfaces(&mut r, 1, 0x100, &[(BLOCK, 2, false)]);
assert_eq!(counted("surface-copy-refused"), before + 1);
let calls = r.p.call_log().since(mark);
let failed = |sel: &str| calls.iter().filter(|c| c.sel == sel).count();
assert_eq!((failed(FAIL_INTERNAL), failed(FAIL_OUT_OF_MEMORY)), (1, 0));
r.p.world().complete_all(CompleteOn::Caller);
let mark = r.p.call_log().mark();
use_surfaces(&mut r, 1, 0x101, &[(BLOCK, 2, false)]);
@@ -1516,12 +1523,13 @@ mod tests {
}
/// 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
/// fails its command buffer, as one whose buffer the platform refused its memory does, but
/// with Metal's internal error, not OutOfMemory, as nothing ran short of memory; the other
/// shape takes nothing of the buffer's older bytes, and 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;
use reims_vgpu_vulkan::core::testkit::impls::command::{FAIL_INTERNAL, 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));
@@ -1536,11 +1544,58 @@ mod tests {
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);
let failed = |sel: &str| calls.iter().filter(|c| c.sel == sel).count();
assert_eq!((failed(FAIL_INTERNAL), failed(FAIL_OUT_OF_MEMORY)), (1, 0));
assert_eq!(counted("surface-copy-refused"), before + 1);
}
/// A blit encoder's write through one shape whose writers' fence update, at the encoder's
/// end, the platform refuses fails its command buffer with Metal's internal error, not
/// OutOfMemory: rule 1's copy after it could not wait for the write. Counted under its own
/// code
#[test]
fn a_blit_writes_refused_fence_update_fails_its_buffer_internal() {
use reims_vgpu_vulkan::core::testkit::impls::command::{FAIL_INTERNAL, FAIL_OUT_OF_MEMORY};
let mut r = shaped();
texture_image(&mut r, 21, 80, (32, 8));
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("updateFence:", Step::Nil);
let before = counted("surface-fence-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 == "updateFence:"), "asked");
let failed = |sel: &str| calls.iter().filter(|c| c.sel == sel).count();
assert_eq!((failed(FAIL_INTERNAL), failed(FAIL_OUT_OF_MEMORY)), (1, 0));
assert_eq!(counted("surface-fence-refused"), before + 1);
}
/// A compute encoder's write through one shape whose writers' fence update, at the encoder's
/// end, the platform refuses fails its command buffer with Metal's internal error, as a blit
/// encoder's does ([`a_blit_writes_refused_fence_update_fails_its_buffer_internal`])
#[test]
fn a_compute_writes_refused_fence_update_fails_its_buffer_internal() {
use reims_vgpu_vulkan::core::testkit::impls::command::{FAIL_INTERNAL, FAIL_OUT_OF_MEMORY};
let mut r = shaped();
compute_pipeline(&mut r, 31);
writable_image(&mut r, 25);
texture_image(&mut r, 22, 80, (16, 4));
r.p.world().complete_all(CompleteOn::Caller);
r.p.script().push("updateFence:", Step::Nil);
let before = counted("surface-fence-refused");
let mark = r.p.call_log().mark();
computes(&mut r, 0x100, &[bind_pipeline(31), bind_texture(25, 0)]);
r.p.world().complete_all(CompleteOn::Caller);
let calls = r.p.call_log().since(mark);
assert!(calls.iter().any(|c| c.sel == "updateFence:"), "asked");
let failed = |sel: &str| calls.iter().filter(|c| c.sel == sel).count();
assert_eq!((failed(FAIL_INTERNAL), failed(FAIL_OUT_OF_MEMORY)), (1, 0));
assert_eq!(counted("surface-fence-refused"), before + 1);
}
/// A buffer-to-buffer copy (`copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:`).
const BUFFER_COPY: &str = "copyFromBuffer:sourceOffset:toBuffer:destinationOffset:size:";
@@ -1695,7 +1750,9 @@ mod tests {
/// Where the platform refuses a shaped cache's buffer its memory, nothing is copied through
/// the buffer, and the command buffer whose begin's fill found it refused fails with Metal's
/// `MTLCommandBufferErrorOutOfMemory`, once: here a new shape's fill over a dirty shape, as
/// `MTLCommandBufferErrorOutOfMemory`, once, not with the internal error a refused copy
/// takes ([`a_shape_whose_fill_the_platform_refuses_owes_it_still`]): here a new shape's
/// fill over a dirty shape, as
/// the cache's first fill went straight into the shapes and asked for no memory. A command
/// that names the buffer is dropped so too
/// ([`a_refused_cache_buffer_drops_the_command_naming_it_and_copies_nothing`])
@@ -1721,6 +1778,11 @@ mod tests {
calls.iter().filter(|c| c.sel == FAIL_OUT_OF_MEMORY).count(),
1
);
let internal = reims_vgpu_vulkan::core::testkit::impls::command::FAIL_INTERNAL;
assert!(
!calls.iter().any(|c| c.sel == internal),
"the memory's kind alone"
);
let id = |a: &Arg| a.as_obj().map_or(0, |o| o.0);
let through = |c: &&Call| {
[BUFFER_COPY, FILL, TO_BUFFER].contains(&c.sel) && c.args.iter().any(|a| id(a) == cache)
+5 -1
View File
@@ -251,7 +251,11 @@ repeats the ones code cites.
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:
`MTLCommandBufferErrorInternal`, where a cache's refused memory fails it
with `MTLCommandBufferErrorOutOfMemory`; `surface-fence-refused`, a
writers' fence update at a guest encoder's end that the platform
refused, which the host's copies of the encoder's writes wait for, so
its command buffer fails with the internal error:
`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,