Replay: a lost device's fault addresses are placed among the stream's buffers and heaps

What: the runtime player's `loss` line places each access address of the driver's fault report
among the stream's buffers and heaps, as the play made them. An access's range is the address
rounded down to its precision, `precision` bytes long. The line names each live buffer or heap
the range meets, by address, with the address's offset in it. Then it names each of the last
65,536 released ones it meets, newest first, with the frame and call of the release. It shows
at most 8 of each, then "N more". Where none meets the range, it says the address is outside
every buffer and heap of the stream. The released spans are kept in a bounded queue, filled at
each release. Live spans are read from the object table only when the device was lost. A
texture is placed only through the heap or block it lies in, and the play's own buffers are not
placed. docs/REPLAY-STREAM.md documents the line.

Why: the runtime reports the driver's addresses as given (DeviceLoss::fault) and places none,
since only its caller knows what each range was. The player is that caller for a stream: a
replay that loses the device on a 3090 then says which of the stream's objects the fault hit,
whether it was live or freed (and when), or that it hit none.

Test: new_runtime::tests::a_fault_s_access_is_placed_among_the_stream_s_buffers_and_heaps:
- a live buffer and the live heap it lies in, by address with offsets;
- a page that meets a buffer starting past the address (negative offset);
- two released buffers, newest first, with their release positions;
- an address outside everything;
- the queue filled past its 65,536 entries, so the oldest is gone.

Verified: cargo fmt --all. Build, clippy and the tests run in the job named in the lane's report.
This commit is contained in:
Anees Iqbal committed 2026-11-21 00:59:14 -08:00
1 parent 5ea6b63f01
commit 53d429143a
4 files changed
+193 -7

No files matched your search

@@ -0,0 +1,88 @@
//! A lost device's fault addresses placed among the stream's buffers and heaps, for the report's
//! `loss` line (`docs/REPLAY-STREAM.md` section 10). An access's range is its address rounded
//! down to its precision, `precision` bytes long. Each live buffer or heap whose memory meets it
//! is named with the address's offset in it, then each of the last [`FREED_KEPT`] released ones
//! that met it, newest first, with the frame and call of its release; where none meets it, the
//! line says so. A texture is placed only through the heap or block it lies in, and the play's
//! own buffers are not placed.
use metal2vulkan_runtime as rt;
use std::collections::VecDeque;
/// The released buffers and heaps kept for placing, oldest dropped first.
pub(super) const FREED_KEPT: usize = 1 << 16;
/// The places named for one address, of the live ones and of the released ones each.
const SHOWN: usize = 8;
/// A buffer's or heap's memory: its object, whether it is a heap (or a block of the stream),
/// and its GPU address range in the play.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct Span {
pub(super) object: u64,
pub(super) heap: bool,
pub(super) start: u64,
pub(super) len: u64,
}
impl Span {
fn meets(&self, low: u64, high: u64) -> bool {
self.start < high && low < self.start.saturating_add(self.len)
}
/// `#OBJECT buffer +OFFSET`, the address's offset from the start (`-` where it lies below).
fn name(&self, address: u64) -> String {
let kind = if self.heap { "heap" } else { "buffer" };
match address.checked_sub(self.start) {
Some(offset) => format!("#{} {kind} +{offset:#x}", self.object),
None => format!("#{} {kind} -{:#x}", self.object, self.start - address),
}
}
}
/// The released buffers and heaps, oldest first, each with the frame and call of its release.
#[derive(Default)]
pub(super) struct Freed(VecDeque<(Span, (u64, u64))>);
impl Freed {
/// `span` was released at `at` (frame, call).
pub(super) fn released(&mut self, span: Span, at: (u64, u64)) {
if self.0.len() == FREED_KEPT {
self.0.pop_front();
}
self.0.push_back((span, at));
}
}
/// Where `address` lies: ` in PLACE live, ...` and ` in PLACE released at frame F call C, ...`,
/// at most [`SHOWN`] of each with the count of the rest, or ` outside every buffer and heap of
/// the stream`.
pub(super) fn place(address: &rt::FaultAddress, live: &[Span], freed: &Freed) -> String {
let low = address.address & !address.precision.saturating_sub(1);
let high = low.saturating_add(address.precision.max(1));
let mut places = Vec::new();
// Live ones by address, then object: the table is a map.
let mut live: Vec<&Span> = live.iter().filter(|span| span.meets(low, high)).collect();
live.sort_unstable_by_key(|span| (span.start, span.object));
let freed = (freed.0.iter().rev()).filter(|(span, _)| span.meets(low, high));
let live: Vec<String> = (live.iter())
.map(|span| format!("{} live", span.name(address.address)))
.collect();
let freed: Vec<String> = freed
.map(|(span, (frame, call))| {
let name = span.name(address.address);
format!("{name} released at frame {frame} call {call}")
})
.collect();
for named in [live, freed] {
let rest = named.len().saturating_sub(SHOWN);
places.extend(named.into_iter().take(SHOWN));
if rest > 0 {
places.push(format!("{rest} more"));
}
}
match places.is_empty() {
true => " outside every buffer and heap of the stream".to_owned(),
false => format!(" in {}", places.join(", ")),
}
}
@@ -11,6 +11,7 @@
mod aside;
mod encoders;
mod faulted;
mod guest_ram;
mod imports;
pub(super) mod indices;
@@ -433,12 +434,16 @@ fn stages_line(at: &str, stages: &Stages) -> String {
/// A `loss CALL RESULT` line of the report for the device's first loss (`Device::loss`), with the
/// driver's fault report as given where the runtime read one: its description, then each access,
/// instruction pointer and vendor record.
fn loss_line(loss: &rt::DeviceLoss) -> String {
/// placed among the stream's buffers and heaps, `live` and `freed` (`faulted`), each instruction
/// pointer and each vendor record.
fn loss_line(loss: &rt::DeviceLoss, live: &[faulted::Span], freed: &faulted::Freed) -> String {
let mut line = format!("loss {} {:?}", loss.call, loss.result);
if let Some(fault) = &loss.fault {
line.push_str(&format!("; fault {:?}", fault.description));
line.extend(fault.accesses.iter().map(|a| format!("; access {a:?}")));
line.extend((fault.accesses.iter()).map(|a| {
let placed = faulted::place(a, live, freed);
format!("; access {a:?}{placed}")
}));
line.extend((fault.instructions.iter()).map(|a| format!("; instruction {a:?}")));
line.extend((fault.vendor.iter()).map(|(description, code, data)| {
format!("; vendor {description:?} code {code:#x} data {data:#x}")
@@ -447,6 +452,27 @@ fn loss_line(loss: &rt::DeviceLoss) -> String {
line
}
/// Buffer `object`'s memory in the play, for placing a fault's addresses.
fn span(object: u64, buffer: &rt::Buffer) -> faulted::Span {
let (start, len) = (buffer.gpu_address(), buffer.length());
faulted::Span {
object,
heap: false,
start,
len,
}
}
/// Block or heap `object`'s memory in the play, for placing a fault's addresses.
fn block_span(object: u64, range: &rt::HeapRange, block: &rt::Block) -> faulted::Span {
faulted::Span {
object,
heap: true,
start: block.gpu_address + range.offset,
len: range.len,
}
}
/// A compute pipeline state's making: its wall time, and whether its kernel was new to the play
/// (no state of another specialization of it made before).
struct Creation {
@@ -537,6 +563,8 @@ pub struct NewRuntime {
skips: Skips,
/// The frame and the stream position of the call being played (`Backend::locate`).
at: (u64, u64),
/// The stream's buffers and heaps released, for placing a fault's addresses (`faulted`).
freed: faulted::Freed,
substitutes: Substitutes,
unrecorded_tessellation: render::UnrecordedTessellation,
/// Each open encoder's command buffer.
@@ -975,6 +1003,7 @@ impl NewRuntime {
completed: 0,
skips: Skips::default(),
at: (0, 0),
freed: faulted::Freed::default(),
substitutes: Substitutes::default(),
unrecorded_tessellation: render::UnrecordedTessellation::default(),
owners: HashMap::new(),
@@ -2488,7 +2517,8 @@ impl Backend for NewRuntime {
match self.objects.remove(&call.receiver) {
// Its place and its device copy's, where it has them: a no-copy buffer's memory
// is an import, and one in a block or heap the stream's.
Some(Object::Buffer(_, place)) => {
Some(Object::Buffer(buffer, place)) => {
self.freed.released(span(call.receiver, &buffer), self.at);
let copy = self.device_copies.remove(&call.receiver);
let held: Vec<Place> = copy.into_iter().chain(place).collect();
if !held.is_empty() {
@@ -2501,6 +2531,8 @@ impl Backend for NewRuntime {
// The runtime keeps the block while a buffer of it lives or work uses it, as a
// heap's resources keep the heap.
Some(Object::Block(range, class, block)) => {
let heap = block_span(call.receiver, &range, &block);
self.freed.released(heap, self.at);
self.no_copies.block_released(call.receiver);
self.device.release_block(block).map_err(failed(call))?;
self.block_bytes[class_index(class)] -= range.len;
@@ -3186,7 +3218,16 @@ impl Backend for NewRuntime {
let metrics = self.device.counters().metrics();
let longest = metrics.commit_lock_wait_max_nanos;
lines.push(format!("commit lock wait longest {longest} ns"));
lines.extend(self.device.loss().as_ref().map(loss_line));
if let Some(loss) = self.device.loss() {
let live: Vec<faulted::Span> = (self.objects.iter())
.filter_map(|(&object, held)| match held {
Object::Buffer(buffer, _) => Some(span(object, buffer)),
Object::Block(range, _, block) => Some(block_span(object, range, block)),
_ => None,
})
.collect();
lines.push(loss_line(&loss, &live, &self.freed));
}
let ended = self.frame_stages.iter().enumerate();
lines.extend(ended.map(|(frame, stages)| stages_line(&frame.to_string(), stages)));
lines.push(stages_line("end", &stages(&metrics)));
@@ -187,3 +187,54 @@ fn a_record_without_the_tessellation_key_is_unrecorded() {
program's tessellation state is unknown, and the player drew them with Metal's defaults"
);
}
/// A fault's access is placed among the stream's buffers and heaps: in a live buffer and the live
/// heap it lies in, by address, with its offset in each; in a released buffer, with the frame and
/// call of its release, newest first; outside all of them where none meets its range, which is
/// the address rounded down to its precision. The released ones kept are the last `FREED_KEPT`.
#[test]
fn a_fault_s_access_is_placed_among_the_stream_s_buffers_and_heaps() {
use super::faulted::{place, Freed, Span, FREED_KEPT};
let at = |address, precision| rt::FaultAddress {
kind: ash::vk::DeviceFaultAddressTypeEXT::READ_INVALID,
address,
precision,
};
let span = |object, heap, start, len| Span {
object,
heap,
start,
len,
};
let live = [
span(7, false, 0x1_2000, 0x1000),
span(3, true, 0x1_0000, 0x1_0000),
span(9, false, 0x3_0080, 0x100),
];
let mut freed = Freed::default();
freed.released(span(11, false, 0x5_0000, 0x2000), (4, 120));
freed.released(span(12, false, 0x5_1000, 0x40), (6, 33));
assert_eq!(
place(&at(0x1_2345, 0x10), &live, &freed),
" in #3 heap +0x2345 live, #7 buffer +0x345 live"
);
// A page's precision meets a buffer that starts inside the page, past the address.
assert_eq!(
place(&at(0x3_0010, 0x1000), &live, &freed),
" in #9 buffer -0x70 live"
);
assert_eq!(
place(&at(0x5_1008, 0x4), &live, &freed),
" in #12 buffer +0x8 released at frame 6 call 33, #11 buffer +0x1008 released at frame 4 call 120"
);
assert_eq!(
place(&at(0x9_0000, 0x1000), &live, &freed),
" outside every buffer and heap of the stream"
);
// Filled past what it keeps, the oldest released buffer goes.
for object in 0..FREED_KEPT as u64 {
freed.released(span(100 + object, false, 0x100_0000, 0x10), (7, object));
}
let placed = place(&at(0x5_0000, 0x4), &[], &freed);
assert_eq!(placed, " outside every buffer and heap of the stream");
}
+8 -2
View File
@@ -983,8 +983,14 @@ function by name, was made before), its `commit lock wait longest N ns` (the run
the executed counter `commit_lock_wait_nanos` gives the waits by frame, summed), its
`loss CALL RESULT` where the device was lost (`Device::loss`: the first loss's call and result,
then, where the runtime read the driver's fault report, `; fault "DESCRIPTION"` and an
`; access KIND ADDRESS precision P`, `; instruction KIND ADDRESS precision P` or
`; vendor "DESCRIPTION" code C data D` for each of its records, as the driver gave them), its
`; access KIND ADDRESS precision P PLACES`, `; instruction KIND ADDRESS precision P` or
`; vendor "DESCRIPTION" code C data D` for each of its records, as the driver gave them; an
access's `PLACES` are where the play placed it among the stream's buffers and heaps, its range
being the address rounded down to `P`, `P` bytes long: ` in #OBJECT buffer +OFFSET live` or
`heap` for each live one its range meets, by address, then `... released at frame F call C` for
each of the last 65,536 released ones it meets, newest first, at most 8 of each with `N more`
after, or ` outside every buffer and heap of the stream`; an offset is `-` where the address lies
below the start, and a texture is placed only through the heap or block it lies in), its
`stages F commit_to_scheduled=C0,...,C22 scheduled_to_gpu_start=... gpu_run=...
gpu_end_to_handler=...` for each frame `F` a later call followed and `stages end ...` at the play's
end (the runtime's four histograms of its command buffers' stages, `Metrics::commit_to_scheduled`