Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 96 additions & 7 deletions crates/victory-gpu/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,75 @@ static DROPPED_TAKEN: AtomicU64 = AtomicU64::new(0);

static TABLE_SLOT_DROPS: AtomicU64 = AtomicU64::new(0);

/// Why draws and dispatches were dropped, since the last report: each silent
/// exit names its cause on this thread ([`why`]) and the drop counts it
/// ([`count_drop`]). Release builds kept only the total, and runs on an RTX 3070
/// (2026-11-29) dropped about 2,400 of 7,000-9,800 draws a frame for a minute at
/// a time with no way to tell which exit.
#[derive(Clone, Copy)]
#[repr(u8)]
enum Why {
Other,
Builder,
NoPipeline,
Kind,
TableSlots,
MemoryViews,
Root,
Bind,
Index,
Rects,
// (Only diagnostics builds skip pipelines.)
#[cfg_attr(not(feature = "diagnostics"), allow(dead_code))]
Skipped,
}

/// The names of [`Why`]'s causes, in its order, for the frame line.
pub(crate) const DROP_WHY_NAMES: [&str; 11] = [
"other",
"ray-tracing builder off",
"no host pipeline",
"another kind of pipeline",
"no table slots",
"no view heap for memory reads",
"root views",
"bind",
"index buffer without a host copy",
"rectangles",
"skipped",
];

static DROP_WHY: [AtomicU64; 11] = [const { AtomicU64::new(0) }; 11];

thread_local! {
static WHY: std::cell::Cell<u8> = const { std::cell::Cell::new(Why::Other as u8) };
}

/// Names the cause of a drop about to happen on this thread.
fn why(w: Why) {
WHY.set(w as u8);
}

/// [`why`], unless a cause was named already (deeper in the same call).
fn why_unset(w: Why) {
if WHY.get() == Why::Other as u8 {
WHY.set(w as u8);
}
}

/// Counts a drop, under the cause last named on this thread.
fn count_drop() {
DROPPED.fetch_add(1, Ordering::Relaxed);
let w = WHY.replace(Why::Other as u8);
DROP_WHY[usize::from(w).min(DROP_WHY.len() - 1)].fetch_add(1, Ordering::Relaxed);
}

/// The drops by cause since the last call ([`DROP_WHY_NAMES`] gives the names).
pub(crate) fn take_drop_why() -> [u64; 11] {
std::array::from_fn(|i| DROP_WHY[i].swap(0, Ordering::Relaxed))
}


/// Direct and indirect bind calls dropped because a fresh descriptor table
/// could not obtain its contiguous dynamic slots, since the last report.
pub(crate) fn take_table_slot_drops() -> u64 {
Expand Down Expand Up @@ -2503,6 +2572,7 @@ impl State {

/// As [`State::prepare`], for draws (`mesh` false) or mesh dispatches.
fn prepare_for(&mut self, list: &HostList, indexed: bool, mesh: bool) -> bool {
why(Why::Other);
#[cfg(feature = "diagnostics")]
if crate::pipeline::is_skipped(self.pipeline as This) {
return false;
Expand All @@ -2515,10 +2585,12 @@ impl State {
.filter(|_| sample_mask_on())
.and_then(|_| crate::pipeline::host_pipeline_masked(self.pipeline as This));
let Some(p) = masked.or_else(|| crate::pipeline::host_pipeline(self.pipeline as This)) else {
why(Why::NoPipeline);
return false;
};
if p.compute || p.mesh != mesh {
once!(mesh, "a draw or mesh dispatch with another kind of pipeline");
why(Why::Kind);
return false;
}
if p.rects && self.topology != RECTANGLES {
Expand All @@ -2540,6 +2612,7 @@ impl State {
}
}
if !self.bind(list, p, false) {
why_unset(Why::Bind);
return false;
}
let l = &list.list;
Expand Down Expand Up @@ -2573,6 +2646,7 @@ impl State {
if indexed {
let v = self.index;
let Some(shadow) = crate::shadow::find_any(v.address, u64::from(v.size)) else {
why(Why::Index);
return false;
};
shadow.refresh(list, v.address, u64::from(v.size));
Expand Down Expand Up @@ -2749,6 +2823,7 @@ impl State {
if made.iter().any(|m| m.1 == u32::MAX) {
TABLE_SLOT_DROPS.fetch_add(1, Ordering::Relaxed);
once!("a draw whose descriptor table found no free slots is dropped");
why(Why::TableSlots);
return false;
}
if stage.shader.ambient.is_some() {
Expand All @@ -2773,6 +2848,7 @@ impl State {
};
let Some(ready) = self.memory_ready(list, t, compute, use_) else {
once!("a shader that reads title memory by address without a view heap to hold its views: the draw is dropped");
why(Why::MemoryViews);
return false;
};
Some(ready)
Expand Down Expand Up @@ -3040,6 +3116,7 @@ impl State {
if !crate::pipeline::host::bounded_root_srvs() {
let Some((a, s)) = address.and_then(|a| Some((a, find(a)?))) else {
once!("a root UAV with nothing to bind: the draw is dropped");
why(Why::Root);
return false;
};
ready(a, &s);
Expand All @@ -3063,6 +3140,7 @@ impl State {
};
let Some((heap, host)) = heap.and_then(|h| Some((h, h.host()?))) else {
once!("a root UAV without a bound view heap: the draw is dropped");
why(Why::Root);
return false;
};
let key = (std::ptr::from_ref(heap) as usize, address.unwrap_or(0));
Expand All @@ -3077,6 +3155,7 @@ impl State {
crate::host::settle_for_fence();
host.dynamic(1)
}) else {
why(Why::Root);
return false;
};
self.dynamic.push((key.0, host.id(), index, 1));
Expand Down Expand Up @@ -3131,6 +3210,7 @@ impl State {
};
let Some((heap, host)) = heap.and_then(|h| Some((h, h.host()?))) else {
once!("a root SRV without a bound view heap: the draw is dropped");
why(Why::Root);
return false;
};
// A view that begins early is another view than one that does not
Expand All @@ -3153,6 +3233,7 @@ impl State {
crate::host::settle_for_fence();
host.dynamic(1)
}) else {
why(Why::Root);
return false;
};
self.dynamic.push((key.0, host.id(), index, 1));
Expand Down Expand Up @@ -4686,17 +4767,20 @@ impl State {

/// Runs a dispatch on the host.
pub(crate) fn dispatch(&mut self, list: &HostList, x: u32, y: u32, z: u32, flags: u32) {
why(Why::Other);
// It may write the arguments a window holds clamped.
self.window = None;
#[cfg(feature = "diagnostics")]
if crate::pipeline::is_skipped(self.pipeline as This) {
DROPPED.fetch_add(1, Ordering::Relaxed);
why(Why::Skipped);
count_drop();
crate::pipeline::note_drop(self.pipeline as This);
return;
}
// The ray-tracing structure builder's stages run all or none.
if crate::pipeline::is_builder(self.pipeline as This) && !crate::pipeline::builder_runs() {
DROPPED.fetch_add(1, Ordering::Relaxed);
why(Why::Builder);
count_drop();
#[cfg(feature = "diagnostics")]
{
crate::pipeline::note_why("a stage of the ray-tracing structure builder, which is off".to_owned());
Expand All @@ -4709,7 +4793,8 @@ impl State {
pipeline = format_args!("{:#x}", self.pipeline),
"a dispatch without a host pipeline dropped"
);
DROPPED.fetch_add(1, Ordering::Relaxed);
why(Why::NoPipeline);
count_drop();
#[cfg(feature = "diagnostics")]
{
crate::pipeline::note_drop(self.pipeline as This);
Expand All @@ -4725,7 +4810,8 @@ impl State {
return;
}
if !self.bind(list, p, true) {
DROPPED.fetch_add(1, Ordering::Relaxed);
why_unset(Why::Bind);
count_drop();
// A stage of the structure builder that cannot be bound is a
// dropped stage: the others stop too.
if crate::pipeline::is_builder(self.pipeline as This) {
Expand Down Expand Up @@ -5456,7 +5542,7 @@ impl State {
false
};
if !ran {
DROPPED.fetch_add(1, Ordering::Relaxed);
count_drop();
#[cfg(feature = "diagnostics")]
dropped(self.pipeline);
}
Expand Down Expand Up @@ -6127,7 +6213,7 @@ impl State {
DRAWN.fetch_add(1, Ordering::Relaxed);
}
if !ran {
DROPPED.fetch_add(1, Ordering::Relaxed);
count_drop();
#[cfg(feature = "diagnostics")]
dropped(self.pipeline);
}
Expand Down Expand Up @@ -6218,6 +6304,7 @@ impl State {
/// + count` as triangles, made when the list is submitted.
fn rectangles(&self, list: &HostList, count: u32, first: u32) -> bool {
let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else {
why(Why::NoPipeline);
return false;
};
let rects = u64::from(count / 3);
Expand All @@ -6240,9 +6327,11 @@ impl State {
|| crate::shadow::find(from, rects * 3 * stride).is_none()
{
once!(slot, "rectangle vertices outside their buffer");
why(Why::Rects);
return false;
}
let Some((gpu, to)) = list.scratch(rects * 6 * stride) else {
why(Why::Rects);
return false;
};
let (from, to, stride) = (from as usize, to as usize, stride as usize);
Expand Down Expand Up @@ -6311,7 +6400,7 @@ impl State {
DRAWN.fetch_add(1, Ordering::Relaxed);
}
if !ran {
DROPPED.fetch_add(1, Ordering::Relaxed);
count_drop();
#[cfg(feature = "diagnostics")]
dropped(self.pipeline);
}
Expand Down
Loading
Loading