forked from 1b-agent/opencadstudio-upstream
fix: never cache a buffer the device rejected
After an out-of-memory the viewport stopped updating for the rest of the session — both Model and Layout frozen, the UI still responsive. The log shows why: `block-wire-geometry` prints *after* the errors it provoked. The failed uploads were cached. A rejected allocation still yields a `Buffer`. It is invalid, every later use reports again, and it is indistinguishable from a good one at the cache key. So the entry keeps hitting, nothing ever rebuilds, and the frame stays empty even once memory frees up. Sharing `block_geometry` across slots in the previous commit made that worse, not better: one poisoned entry now serves every viewport. The device's uncaptured-error counter was already there, private to the handler that throttles the log. It is now readable, and the three caches that can retain a bad upload — block definition geometry, the shared wire buffer cache, and the arena's content id — snapshot it across their build and decline to record what it condemns. The degraded frame still draws; the next frame tries again. Best effort by construction: wgpu surfaces some errors asynchronously, so a moved counter means something failed, while an unmoved one is not proof that nothing did. That asymmetry is the right way round here — believing a bad buffer costs a frozen viewport, rebuilding a good one costs a frame. `block-wire-geometry` gains `poisoned=` so a run says whether this happened rather than leaving it to be inferred. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6599b82776
commit
d9c998fa17
3 files changed
+62
-11
No files matched your search
@@ -778,6 +778,8 @@ impl BlockWireGpu {
|
||||
// path's saving is visible rather than assumed.
|
||||
let mut uploaded_bytes = 0usize;
|
||||
let mut uploaded_segments = 0usize;
|
||||
// Definitions whose upload the device rejected, so they were not cached.
|
||||
let mut poisoned = 0usize;
|
||||
for (mesh_edge, group) in groups {
|
||||
let Some(&source) = group.first() else {
|
||||
continue;
|
||||
@@ -803,6 +805,12 @@ impl BlockWireGpu {
|
||||
push_block_batches(&mut out, device, queue, &chunks, &instances, mesh_edge);
|
||||
continue;
|
||||
}
|
||||
// A failed allocation still produces a `Buffer`; it is simply
|
||||
// invalid, and every later use of it reports again. Cached, it
|
||||
// freezes the viewport for the rest of the session because the key
|
||||
// keeps hitting and nothing ever rebuilds. Watch the device's error
|
||||
// count across the build and refuse to cache what it condemns.
|
||||
let errors_before = super::gpu_errors_seen();
|
||||
let (segments, mut constant) = emit_wire_native(source, 0, color, 0.0);
|
||||
if segments.is_empty() {
|
||||
continue;
|
||||
@@ -906,8 +914,17 @@ impl BlockWireGpu {
|
||||
* std::mem::size_of::<BlockWireVertex>()
|
||||
* if mode.uses_storage() { 1 } else { 6 };
|
||||
let chunks = std::sync::Arc::new(chunks);
|
||||
if let Some(cache) = cache.as_deref_mut() {
|
||||
cache.insert(cache_key, std::sync::Arc::clone(&chunks));
|
||||
let built_clean = super::gpu_errors_seen() == errors_before;
|
||||
if built_clean {
|
||||
if let Some(cache) = cache.as_deref_mut() {
|
||||
cache.insert(cache_key, std::sync::Arc::clone(&chunks));
|
||||
}
|
||||
} else {
|
||||
// Draw this frame with what we have — a degraded frame beats a
|
||||
// blank one — but leave the cache clean so the next frame tries
|
||||
// again. `live_keys` still holds the key, so the retain below
|
||||
// does not evict a good entry from an earlier frame.
|
||||
poisoned += 1;
|
||||
}
|
||||
let instances = block_instances(&group, base, mesh_edge, depth_map);
|
||||
push_block_batches(&mut out, device, queue, &chunks, &instances, mesh_edge);
|
||||
@@ -919,12 +936,13 @@ impl BlockWireGpu {
|
||||
if crate::perf::enabled() && uploaded_segments > 0 {
|
||||
crate::perf_record!(
|
||||
"[perf] block-wire-geometry mode={} definitions={} segments={} bytes={} \
|
||||
bytes_if_packed={}",
|
||||
bytes_if_packed={} poisoned={}",
|
||||
if mode.uses_storage() { "storage" } else { "packed" },
|
||||
live_keys.len(),
|
||||
uploaded_segments,
|
||||
uploaded_bytes,
|
||||
uploaded_segments * std::mem::size_of::<BlockWireVertex>() * 6,
|
||||
poisoned,
|
||||
);
|
||||
}
|
||||
out
|
||||
|
||||
Reference in new issue
Block a user