diff --git a/AGENTS.md b/AGENTS.md index a129a27cf6..575c2d6bd1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -110,3 +110,22 @@ Fork: MagiccConch/VIctory, upstream: Marvisak/VIctory. CI: windows-latest only ( - Run 6 (07:26, presumably aa133a1 — NO 0x887A0006 this time, so the intro fixes likely ran and held): crashed at the SAME title instruction as the heap-era null writes (image+0x2215c35, identical rcx=0x4189374bc6a7f0 across all four occurrences — a constant-derived pointer), amid the past-cap flood (count=934464, indices ~1,136,xxx). Two processes 41 s apart (XLaunchNewGame self-relaunch crashed again) → both died early-ish, ~2 min in, near/past the intro. VICTORY_LOG_FILE was NOT set for run 6 (stale PowerShell window) → no full log; stderr excerpt only. - Clamp wiring verified sound (2026-11-25): shader_cache::build() → host() first (cap probed, set_view_heap_limit) → key includes cap; every HostShader carries view_limit read at translation time; shaders clamp createHandleFromHeap indices to cap-1 (null last slot). So a past-cap slot reads a NULL descriptor on the GPU (safe). The null write is the TITLE CPU on wrong data: either (a) GPU-written heap bytes the title reads back that copy-back missed (suspect: writes through paths that don't mark pages — e.g. the twin bridge CopyTextureRegion, or unmarked UAV writes), or (b) the title needs real views at slots ≥ 934,464 → the two-heap REMAP (sketch: uniform root layout, heap0=title [0,1e6), heap1=title [1e6,1179648)+dynamic tail, SPLIT=1e6 in emit; touches emit/shader.rs, pipeline/make.rs, descriptor/host.rs, GPU_RANGES). Do NOT build the remap before the run-7 log confirms which mechanism. + +## Run 7 (07:03, aa133a1): removal mid pipeline-creation flood; upstream scan (2026-11-25) + +- Run 7 = the 0x887A0006 crash record (07:03:52): device removed after a submission of 7 lists, mid PSO-compilation flood, ~2 min in. Debug layer was OFF (zero `D3D12:` lines). The log tail shows `no room for the null buffer views` (warn, once) and `no breadcrumbs`; `method not implemented` (2, victory_gpu::object device slot 0x218/0x1c8) near the end is HLE-noise, unrelated. NO past-cap warnings before this removal (run 6 had 187,078) — the title reached further. +- crashes.log now holds 8 records: 4× null-write 0xc0000005 image+0x2215c35 (rcx=0x4189374bc6a7f0 constant in ALL — 02:17, 04:39, 07:26:14, 07:26:55; the 07:26 pair = run 6 self-relaunched 41 s apart), 2× 0x887A0001 (04:53 sampler era, 06:03 B4G4R4A4 era), 2× 0x887A0006 (07:03 run 5's hang-era, 07:03 run 7). The 07:26 crashes mean the intro fixes (aa133a1) held past the picker but the null-write path re-surfaced. +- **Run 7 root cause (fork gap, fixed in PR #13, branch capped-null-buffer-views, commit 2e388ec):** the title heap landed on the PORTABLE_VIEWS cap path (count+MIN_DYNAMIC=1,065,536 > 1M → make(1M), count=934,464, dynamic=131,071) — there `pairs_end` was `total-1` but `pairs.0` started at count+extra=1,065,535 > pairs_end: the pair range was EMPTY (starved; pairs recycled through dynamic slots), and the null raw SRV/UAV for computed buffer-view indices (NULL_BUFFER_VIEW=2,097,150/-1) sat PAST the 1M heap → never made → the "no room for the null buffer views" warn. PR #13 fixes: buffer_guard clamps computed indices below view_limit and reads null SRV/UAV at limit-2/-3 (upstream PRs #2177/#2185's direction, not yet merged upstream); capped heap reserves last 3 slots (null SRV, null UAV, clamp guard); exact-fit rungs trim 3 dynamic slots; deep-cap path reserves CAPPED_PAIRS (1<<15 slots = 16,384 copy-back pairs) with full MIN_DYNAMIC; pipeline-library tag hashes the cap (library-reuse bug fixed); past-cap warn throttled to 1/s (highest-so-far), new maxima at debug. AMD paths byte-identical (min(NULL_BUFFER_VIEW, total-2) == NULL_BUFFER_VIEW on 2M heaps). +- **Upstream scan verdict (git):** merge-base main upstream/main == 940d32f == upstream/main tip — the fork already contains ALL merged upstream work. Upstream main CI green (45527330187, 01:39). Fork main CI green through df2da99. 3 upstream PRs merged 2026-11-25 00:20–01:12 (#1911, #1925 GPU-less-adapter skips; #629 reject multisampled linear layouts) — all in our tree via 940d32f. Upstream NEVER merged PR #1133 (view-heap cap): still open, rebased on 940d32f (head 0d19c4c), split per triage (barrier → #2035), triage verdict "merge-candidate" (2026-11-25 07:23), tested RTX 5060/5070 + RX 7700 XT. Our port = PR #11 (c4b3947); diff vs 0d19c4c is only the struct-literal shape (Options) — semantically identical, no catch-up needed. +- Upstream open-PR traffic on OUR exact problems: #2177 (clamp+null buffer views in capped heaps, RTX 5060 Ti tested), #2185 (clamp to cap, "world uses title slots past 1,236,191" — same run shape as ours), #2189 (graceful degradation tiers 1M→500K→250K→MIN_DYNAMIC + cursor wraparound), #2180 (strip unsupported UAV/RT format flags — same idea as fork's 5ecd621), #2187 (deny-SRV share), #2186 (WARP u32→f32 rounding), #2190 (typeless view mapping). Watch #2177/#2185/#2189 for upstream merge — they touch descriptor/host.rs and emit/lower.rs, both files PR #13 touches; rebase PR #13 or re-port after upstream merges whichever wins. +- Upstream CI note: PRs from first-time/external forks come up `action_required` (approval-gated); do not read that as a failure. Merge-candidate verdicts appear in issue comments as `victory-triage v1 ... verdict=merge-candidate`. +- Toolchain note (container): no cargo preinstalled — `curl https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.98.1 --profile minimal`, `rustup target add x86_64-pc-windows-gnu`, `sudo apt-get update && sudo apt-get install -y mingw-w64` (test binaries need x86_64-w64-mingw32-dlltool; check/clippy do not). All three gates green locally. +- Run 8 plan: user re-pulls PR #13, rebuilds, deletes nothing (cap unchanged → shader cache keys stay; library tag changes → pre-build remakes the library), re-runs pre-build (tag changed → it will list 0 found and remake), then runs with `VICTORY_D3D12_DEBUG=1` + `VICTORY_LOG_FILE=victory-run8.log`. Expect: no "no room for the null" warn, `kept=705085` in the capped warn, ≤60 past-cap warns/minute, and the null-write question decided — if image+0x2215c35 recurs, trace the copy-back/twin-bridge write-marking path in victory-run8.log. + +## Upstream issue scan → run-8 fixes (2026-11-25, commits 3bf9424 on PR #13) + +- Ranked the open issues by impact on our capped-heap/NVIDIA era (user instruction: deference to NVIDIA/AMD GPU issues). Top-10 shortlist read in full: #747 (capped 2^16 dynamics starve world tables — MEASURED on RTX 4070 Ti: G-buffer 0.1% → 2^18 → 60-65%), #911 (rejected binds retain dynamic reservations), #1118 (the +0x2215c35 null-write family — title-allocator exhaustion on a worker thread, RTX 3070 Ti, same stack as ours), #698 (NVIDIA no-removal breakpoint 6.7 min), #850/#876 (cutscene picture missing; typeless view mapping PR #2190 "ready to merge" but UNMERGED — 494-line descriptor rework, deferred), #653/#71/#778 (DRED wave64 mesh TDRs), #1001/#886/#468 (Ampere wave64/untranslated/E_INVALIDARG families), #400 (frame-time forensics), #1633 (coordination hub). +- **#747 ported (commit 3bf9424):** the fork's `MIN_DYNAMIC` (2^16) was exactly the starved config upstream measured — run 7's heap (count 934,464) took the `count + MIN_DYNAMIC == cap` rung. Fix: the capped path now takes the fork's `DYNAMIC` (2^18) over title slots past it; `MIN_DYNAMIC` and its two duplicate rungs deleted; deep-cap title = PORTABLE_VIEWS - DYNAMIC - CAPPED_PAIRS - 3 = 705,085 (was 836,157 with 2^17... actually was 836,157 under PR #13's first cut with MIN-sized deep-cap; the 2^18 port makes title coverage 705,085 with 262,144 dynamics + 32,768 pairs + 3 null = exactly 1,000,000). Layout: title [0, 705,085), dynamic [705,085, 967,229), pairs [967,229, 999,997), null UAV/SRV [999,997, 999,999), guard 999,999. The exact-fit rung (cap == count + DYNAMIC) keeps ALL title slots with the -3 trim. +- **#911 ported (same commit):** `tables()` now rolls back the failing stage's just-allocated ranges on `table_failed` — release(first, n), fresh_tables entry removed, self.dynamic entry dropped, made cleared. Safe because those binds were never recorded (the draw drops before its root arguments are set); later draws re-make them. Previous behavior cached them until list reset, amplifying exhaustion exactly as #911 describes. +- NOT ported now: #876/#2190 (typeless views — 494-line unmerged rework; our cutscene/UI symptoms were addressed by the twin work), wave64/compute translation (#2176, large), #2189's tier ladder (our ladder already degrades gracefully with the 2^18 port). Re-check #2177/#2185/#2189/#2190 when upstream merges any — all touch descriptor/host.rs + emit/lower.rs, which PR #13 now modifies; expect rebase work then. +- Run 8 expectations UPDATED by 3bf9424: capped warn now logs `kept=705085`; `host view heap capped at 1000000` count=934464. The past-cap title range widens (title slots [705,085, 1,179,648) read null) — that is #747's accepted trade (its own tested config mirrored only 672,319 title slots). Watch for "no dynamic slots" drops GONE from the log (was thousands/frame in #747's measurements). diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index d3331ecd2b..c2655e74f4 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -20,7 +20,8 @@ pub(crate) struct HostHeap { /// Slots mirroring the title's; view heaps have `dynamic` more. count: u32, /// Dynamic slots past `count` (none in sampler heaps): [`DYNAMIC`] - /// where the host takes them, else [`MIN_DYNAMIC`]. + /// where the host takes them, else fewer title slots mirrored on a + /// capped heap ([`DYNAMIC`] still, over the title's slots past it). dynamic: u32, sampler: bool, /// The record (view index and generation) each slot was last made from. @@ -86,10 +87,16 @@ pub(crate) fn near_heaps(va: u64) -> String { /// tiers 1 and 2; tier 3 hardware may take more. const PORTABLE_VIEWS: u32 = 1_000_000; +/// View-pair slots a capped view heap reserves for copy-back view pairs +/// (`HostHeap::pair`, `crate::memory`): 16384 pairs, freed and reused as +/// their copy-backs run. 2026-11-25 (run 7): without their own range, pairs +/// starved and never freed, losing the pages their copy-backs carried. +const CAPPED_PAIRS: u32 = 1 << 15; + /// The size of a capped view heap if `device` takes no larger /// shader-visible view heap (NVIDIA), else `None`. Translated shaders keep /// their view indices below it (`set_view_heap_limit`), and a capped heap -/// keeps its last slot null for them. +/// keeps its last slots null for them. pub(crate) fn view_heap_cap(device: &ID3D12Device) -> Option { // SAFETY: plain heap creation, released at once. let larger = unsafe { @@ -107,13 +114,15 @@ pub(crate) fn view_heap_cap(device: &ID3D12Device) -> Option { /// afresh (constant buffers copied per draw). A list holds the slots it /// took until it is reset (its submissions have run) or released. /// 2^16 ran out seconds into the world (every world run on an RX 9070 XT, -/// each a device removal shortly after; #59). +/// each a device removal shortly after; #59), and on a capped heap +/// (NVIDIA, 1,000,000 slots) it starved the world's tables: indirect and +/// mesh draws dropped as "no dynamic slots", the G-buffer about 0.1% +/// covered; 2^18 with fewer title slots mirrored raised that to 60-65% +/// and dropped nothing for lack of slots (upstream issue #747, measured +/// on an RTX 4070 Ti). So a capped heap takes these too, over title slots +/// past it — a title that reaches them needs remapping either way. const DYNAMIC: u32 = 1 << 18; -/// The dynamic slots of a heap whose host would not take [`DYNAMIC`] more -/// (a capped heap, NVIDIA): the title's slots keep their room first. -const MIN_DYNAMIC: u32 = 1 << 16; - impl HostHeap { pub(crate) fn new(sampler: bool, count: u32) -> Option { let host = host()?; @@ -155,8 +164,10 @@ impl HostHeap { // The larger dynamic range only where the host takes it on top of // every title slot; else the smaller one, and the cap after that. // Translated shaders clamp below the host cap (or `HEAP_VIEWS`), - // samplers below `HEAP_SAMPLERS`: every such slot must exist. The - // cap's last slot stays null, including for dynamic and pair views. + // samplers below `HEAP_SAMPLERS`: every such slot must exist. A + // capped heap keeps its last three slots out of title, dynamic and + // pair views: the null SRV/UAV a computed buffer-view index reads + // (`emit::buffer_guard`), and the slot a shader's index clamps to. let cap = victory_shader::emit::view_heap_limit(); let views = cap .unwrap_or(victory_shader::emit::HEAP_VIEWS) @@ -172,31 +183,37 @@ impl HostHeap { } } else if let Ok(heap) = make((count + DYNAMIC).max(views)) { // A host that takes every slot on top of the larger dynamic - // one; a capped one whose cap fits them keeps its last slot - // out of the dynamic range instead. - (heap, count, DYNAMIC - u32::from(cap == Some(count + DYNAMIC))) + // one; a capped one whose cap fits them keeps the heap's last + // three slots out of the dynamic range instead (the null + // SRV/UAV a computed buffer-view index reads, then the slot a + // shader's index clamps to). + (heap, count, DYNAMIC - 3 * u32::from(cap == Some(count + DYNAMIC))) } else if let Ok(heap) = make(count + DYNAMIC) { // A host that allows the title's whole range beside the larger // dynamic one, though below `HEAP_VIEWS` (NVIDIA): every title // slot mirrored. (heap, count, DYNAMIC) - } else if let Ok(heap) = make((count + MIN_DYNAMIC).max(views)) { - // The same for the smaller dynamic range. - (heap, count, MIN_DYNAMIC - u32::from(cap == Some(count + MIN_DYNAMIC))) - } else if let Ok(heap) = make(count + MIN_DYNAMIC) { - (heap, count, MIN_DYNAMIC) } else { - match make(count + MIN_DYNAMIC) { - Ok(heap) => (heap, count, MIN_DYNAMIC), - Err(_e) if count + MIN_DYNAMIC > PORTABLE_VIEWS => { - // shortcut: descriptors past the host's limit are left - // out; a title that reaches them needs remapping. A - // shader's index past the heap reads its last slot, - // which no view takes (translated shaders clamp to it). + match make(count + DYNAMIC) { + Ok(heap) => (heap, count, DYNAMIC), + Err(_e) if count + DYNAMIC > PORTABLE_VIEWS => { + // shortcut: title slots past the host's cap are left out; + // a title that reaches them needs remapping (a shader's + // index past the heap reads the cap's last slot, which no + // view takes). The dynamic range, a `pairs` range for + // copy-back view pairs, and the null buffer views stay: + // a starved `pairs` range never frees its views, and the + // null SRV/UAV for computed buffer-view indices must sit + // inside the heap (2026-11-25, run 7's warn "no room for + // the null buffer views" and copy-back pairs lost at the + // cap). Title slots give way first: 2^16 dynamic slots + // starved the world's tables on the capped heap (upstream + // #747, 0.1% G-buffer coverage), 2^18 filled it. match make(PORTABLE_VIEWS) { Ok(heap) => { - tracing::warn!(count, "host view heap capped at {PORTABLE_VIEWS}"); - (heap, PORTABLE_VIEWS - MIN_DYNAMIC, MIN_DYNAMIC - 1) + let title = PORTABLE_VIEWS - DYNAMIC - CAPPED_PAIRS - 3; + tracing::warn!(count, kept = title, "host view heap capped at {PORTABLE_VIEWS}"); + (heap, count.min(title), DYNAMIC) } Err(e) => { tracing::warn!(error = %e, count, sampler, "no host descriptor heap"); @@ -239,10 +256,13 @@ impl HostHeap { kept: Mutex::new(vec![None; (count + extra) as usize]), next: Mutex::new((0, vec![false; extra as usize])), pairs: Mutex::new((count + extra, Vec::new())), - pairs_end: match victory_shader::emit::NULL_BUFFER_VIEW { - null if !sampler && null > count + extra && null < total => null - 1, - _ if !sampler && cap == Some(total) => total - 1, - _ => total, + // Where `pairs` may allocate: before the heap's null buffer + // views (a computed buffer-view index reads them when the + // view-stride table says no buffer view is there, + // `emit::buffer_guard`), else the heap's end. + pairs_end: { + let null_srv = victory_shader::emit::NULL_BUFFER_VIEW.min(total - 2); + if !sampler && null_srv > count + extra { null_srv - 1 } else { total } }, strides, marks, @@ -261,13 +281,17 @@ impl HostHeap { tracing::warn!(error = %e, "host descriptor heap not made null"); } tracing::debug!(ms = started.elapsed().as_millis(), "host descriptor heap made null"); - // What shaders read instead of a slot without a buffer view where - // they take one at a computed index (`victory_shader::emit`, "Buffer - // views at computed heap indices"): a null raw SRV, and UAV below it. - let null = victory_shader::emit::NULL_BUFFER_VIEW; - if !sampler && null > count + extra && null < total { - h.raw_view_at(null, None, 0, 0, false); - h.raw_view_at(null - 1, None, 0, 0, true); + // The heap slots a computed buffer-view index reads when the + // view-stride table says no buffer view is there (`victory_shader::emit`, + // "Buffer views at computed heap indices"): a null raw SRV, and the + // null UAV below it. At [`NULL_BUFFER_VIEW`] where the heap spans it, + // else at the heap's last two slots (a capped heap; run 7, 2026-11-25, + // "no room for the null buffer views": `NULL_BUFFER_VIEW` sat past a + // heap of [`PORTABLE_VIEWS`]). + let null_srv = victory_shader::emit::NULL_BUFFER_VIEW.min(total - 2); + if !sampler && null_srv > count + extra { + h.raw_view_at(null_srv, None, 0, 0, false); + h.raw_view_at(null_srv - 1, None, 0, 0, true); } else if !sampler { tracing::warn!(count, total, "no room for the null buffer views: computed indices of slots without a buffer view read what is there"); } @@ -716,14 +740,24 @@ impl HostHeap { pub(crate) fn mirror(&self, index: u32, handle: u64, for_draw: bool) -> Option { if index >= self.count { // Diagnostic (NVIDIA heap cap): the highest title slot past the - // host heap seen so far. + // host heap seen so far. Warn at most once a second with that + // highest (a mirror of the whole heap floods the log; 187078 + // lines in a run on 2026-11-25). static HIGHEST: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); - if HIGHEST.fetch_max(index, std::sync::atomic::Ordering::Relaxed) < index { + static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); + let highest = HIGHEST.fetch_max(index, std::sync::atomic::Ordering::Relaxed); + if highest < index { + tracing::debug!(index, count = self.count, for_draw, "title slot past the host heap"); + } + let now = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map_or(0, |d| d.as_millis() as u64); + let next = NEXT.load(std::sync::atomic::Ordering::Relaxed); + if now >= next && NEXT.swap(now + 1000, std::sync::atomic::Ordering::Relaxed) <= next { tracing::warn!( - index, + index = HIGHEST.load(std::sync::atomic::Ordering::Relaxed), count = self.count, - for_draw, - "title slot past the host heap" + "title slots past the host heap read null" ); } return None; @@ -1552,20 +1586,24 @@ mod tests { return; // the host takes larger heaps }; let heap = HostHeap::new(false, cap + 1).expect("a capped view heap"); - assert_eq!(heap.count + heap.dynamic, cap - 1); + // Title slots give way to the whole dynamic range, a pair range and + // the heap's three null slots (the null SRV/UAV, then the guard). + assert_eq!(heap.count + heap.dynamic, cap - CAPPED_PAIRS - 3); let last = heap.dynamic(heap.dynamic).unwrap() + heap.dynamic - 1; - assert!(last < cap - 1); - assert_eq!(heap.pairs_end, cap - 1); + assert!(last < cap - CAPPED_PAIRS - 3); + // Pairs end before the null buffer views at the cap's last slots. + assert_eq!(heap.pairs_end, cap - 3); // Small title heaps must cover the same shader-visible range too. let small = HostHeap::new(false, 4).expect("a small capped view heap"); // SAFETY: a plain query of a live heap. assert_eq!(unsafe { small.heap.GetDesc().NumDescriptors }, cap); - assert!(small.count + small.dynamic < cap); - assert_eq!(small.pairs_end, cap - 1); - // A dynamic range ending exactly at the cap also leaves a guard. + assert!(small.count + small.dynamic < cap - CAPPED_PAIRS - 3); + assert_eq!(small.pairs_end, cap - 3); + // A dynamic range ending exactly at the cap also leaves the heap's + // three null slots: the rung trims three dynamic slots for them. let exact = HostHeap::new(false, cap - DYNAMIC).expect("an exact capped view heap"); - assert_eq!(exact.count + exact.dynamic, cap - 1); - assert_eq!(exact.pairs_end, cap - 1); + assert_eq!(exact.count + exact.dynamic, cap - 3); + assert_eq!(exact.pairs_end, cap - 3); } /// Dynamic slots stay taken until given back, and runs do not wrap. diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index e0e99fc95f..afeba2dca6 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -1164,6 +1164,13 @@ impl State { } } let mut made = Vec::new(); + // Ranges this call allocated: a rejected bind (a fresh table + // without dynamic slots) keeps none of them — they were never + // recorded into the list (the draw is dropped before its root + // arguments are set), and a later draw re-makes them from scratch + // (upstream issue #911: retained reservations amplified heap + // exhaustion; here they are given back at once). + let mut just: Vec<(usize, u32, u32, (u64, u64))> = Vec::new(); for slot in fresh { let Some(&Root::Table(table)) = self.roots_ref(compute).get(usize::from(slot)) else { continue; @@ -1217,6 +1224,7 @@ impl State { self.fresh_tables.insert(key, first); self.dynamic .push((std::ptr::from_ref(heap) as usize, first, n)); + just.push((std::ptr::from_ref(heap) as usize, first, n, key)); // The whole range: a shader may index past the entries its // used-resource list names (descriptor arrays). for k in 0..n { @@ -1239,6 +1247,19 @@ impl State { } made.push((slot, first * 32)); } + if self.table_failed { + // Give back what this call reserved: the bind is rejected, and + // these ranges were never recorded into the list. + for (heap, first, n, key) in just { + self.fresh_tables.remove(&key); + self.dynamic.retain(|d| !(d.0 == heap && d.1 == first)); + // SAFETY: the heap lives while its device does, as in + // `self.dynamic`'s held entries. + let host = unsafe { &*(heap as *const crate::descriptor::host::HostHeap) }; + host.release(first, n); + } + made.clear(); + } made } diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs index 9946221283..952d039848 100644 --- a/crates/victory-gpu/src/pipeline/library.rs +++ b/crates/victory-gpu/src/pipeline/library.rs @@ -183,6 +183,10 @@ fn open(device: &ID3D12Device1, blob: Vec) -> Option { /// host descriptions). fn tag(blob: &[u8]) -> String { let limit = victory_shader::emit::loop_limit().to_le_bytes(); + // The view-heap cap is a translation setting (a shader's clamps move + // with it); the cap joins the shader cache's key, so the library's tag + // must too, or a library saved on the other host reuses wrong DXIL. + let cap = victory_shader::emit::view_heap_limit().unwrap_or(0).to_le_bytes(); let translator = victory_shader::SOURCE_HASH.as_bytes(); let mut h = blake3::Hasher::new(); for part in [ @@ -190,6 +194,7 @@ fn tag(blob: &[u8]) -> String { translator, include_bytes!("../shader_cache.rs"), &limit, + &cap, include_bytes!("host.rs"), include_bytes!("library.rs"), ] { diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 6af8550a11..7807ceece4 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -5053,7 +5053,13 @@ impl<'a> Lower<'a> { return index; } let c = self.cur; - let last = self.s.m.i32(super::HEAP_VIEWS - 1); + // The host heap shaders index: [`HEAP_VIEWS`], or the cap of a host + // whose shader-visible view heaps stop below it (NVIDIA). The clamp + // and the null pair must stay inside it (`victory-gpu`'s + // `descriptor::host` sizes the heap to it and keeps the last slots + // null for these reads). + let limit = self.s.view_limit.unwrap_or(super::HEAP_VIEWS).min(super::HEAP_VIEWS); + let last = self.s.m.i32(limit - 1); let over = self.s.m.cmp(c, pred::IUGT, index, last); let index = self.s.m.select(c, over, last, index); let four = self.s.m.i32(4); @@ -5065,8 +5071,9 @@ impl<'a> Lower<'a> { let stride = self.as_int(x); let zero = self.s.m.i32(0); let none = self.s.m.cmp(c, pred::EQ, stride, zero); - // The null unordered access view sits just below the null SRV. - let null = super::NULL_BUFFER_VIEW - u32::from(props.0 & 0x1000 != 0); + // The null unordered access view sits just below the null SRV; both + // at the heap's last slots, inside a capped heap too. + let null = limit - 2 - u32::from(props.0 & 0x1000 != 0); let null = self.s.m.i32(null); self.s.m.select(c, none, null, index) } diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index 3638bdddba..1ee100d8b4 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -137,8 +137,9 @@ pub(crate) struct Shader { lds: Option, main: V, pub entry: usize, - /// View heap indices stay below this ([`super::view_heap_limit`]). - view_limit: Option, + /// View heap indices stay below this ([`super::view_heap_limit`]); a + /// sibling module's clamp reads it too (`lower`'s `buffer_guard`). + pub(super) view_limit: Option, } impl Shader {