Skip to content

GPU/memory+descriptor: evict dropped HostHeaps from MEMORY.heaps on Heap::drop - #589

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-memory-evict-dropped-host-heaps
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-memory-evict-dropped-host-heaps

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

Problem

In crates/victory-gpu/src/memory.rs, MEMORY.heaps caches (base, made) descriptor-run state keyed by raw HostHeap pointer (std::ptr::from_ref(heap) as usize), where HostHeap is stored inline inside Heap::host: OnceLock<Option<HostHeap>>.

When a title releases a shader-visible view Heap, Heap::drop() (crates/victory-gpu/src/descriptor.rs) removed it from SHADER_HEAPS but never removed its HostHeap address from MEMORY.heaps. If a newly created Heap reused the freed address:

  • MEMORY.heaps.get(&key) hit the stale (base, made) entry, skipping heap.dynamic(COPIES + 1) and leaving the null UAV and copies 0..made unwritten on the new heap.
  • If the new heap had a different count, base could land inside the title's own descriptor slots or past the end of the host descriptor heap.

Fix

  • Add memory::forget_heap(heap: &HostHeap) in crates/victory-gpu/src/memory.rs and call it from Heap::drop() in crates/victory-gpu/src/descriptor.rs after dropping the SHADER_HEAPS lock.
  • Add synthetic D3D12 unit test dropping_a_view_heap_evicts_its_memory_heaps_entry.

Verification

  • cargo test -p victory-gpu --locked memory::tests -- --test-threads=1: 1 passed, 0 failed
  • cargo test -p victory-gpu --locked descriptor -- --test-threads=1: 15 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: clean (default-features build on c96b4f2 has only the pre-existing dead_code warning on placed_filler_twins, tracked in GPU: keep clippy green without the diagnostics feature #491)

(AI-assisted; synthetic unit tests only, no game data.)

…eap::drop

- Add `memory::forget_heap(&HostHeap)` and invoke it from `Heap::drop()` in
  `descriptor.rs` (after releasing `SHADER_HEAPS`) whenever the dropped title
  view heap materialized a `HostHeap`.
- Prevents a newly allocated `Heap` reusing the freed `Box<Heap>` address from
  hitting a stale `(base, made)` entry in `MEMORY.heaps`, which skipped
  reserving dynamic slots and could corrupt title descriptors or write OOB
  when the new heap's size differed.
- Add synthetic D3D12 unit test `dropping_a_view_heap_evicts_its_memory_heaps_entry`.
triippywhale added a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
- memory.rs (fxceless#589's test): ready() here takes the builder flag too.
- draw.rs (310c6eb): sort_unstable_by_key with Reverse, as clippy asks.
- indirect.rs (310c6eb's bare_command_cost bench): the stored
  depth_written handle is never read; allowed with a reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBA8CxPD68KngjiMeJb
PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…celess#24/fxceless#104), null CBVs (fxceless#304), tables at list cuts (fxceless#742), heap entries (fxceless#589), barriers (fxceless#787), depth-stencil UAV barriers (fxceless#214), windows ending at recorded writes (fxceless#663), sRGB views (fxceless#644), wide accesses across pages (fxceless#846), view-guard costs (fxceless#812/fxceless#853), the fill latch (fxceless#860), pipeline waits (fxceless#709), robustness; opt-in fxceless#868/fxceless#845
fxceless added a commit that referenced this pull request Nov 26, 2026
…e), 4 KiB dirty tracking, gather segments, the black-face texture fixes, shadow and translator fixes from pull requests

Measured in in-run on/off splits on an RTX 4070 (diagnostics builds, the
same switches for every run):
- VICTORY_CARD_HASH_WIDE=1|alt: the card's hashes of copies' pieces by a group
  of 64 threads a piece, alternating per submission: card -10 ms a frame
  (86.5 vs 96.5), world frames -5 ms.
- VICTORY_GATHER_SEGMENTS=1|alt (after flipflop877 c69bff1): one clamp pass
  per segment once a list stops gathering: ~30 records a pass, neutral to
  slightly faster at equal draws.
- VICTORY_DIRTY_4K=1|alt: refreshes copy only the written 4 KiB pages of a
  stale write-watched page: -45 % of those bytes; faster in loading, no world
  gain.
Fixes:
- Textures under a DirectStorage write or a landed plain read are made due
  again (VICTORY_PAGE_WRITES default 1|2|8): textures uploaded before their
  data landed kept zeros (black faces); VICTORY_HEAP_RECHECK_EVERY=<frames>
  keeps looking at uploaded textures after the schedule (after RyanCase94).
- Pull requests #646 (builder dispatches count threads), #1002 (alpha-tested
  geometry casts cascade shadows), #1314, #1324, #589, #702, #1112 (mesh
  triangle corners masked 9 bits, cube-map levels, two-sampler branches,
  split 64-lane masks); upstream #3198 (textures without card room retried).
- VICTORY_WAVE_WIDE_ONLY=<hashes>: listed refused programs may take the
  wave-wide form (after #823's a416e39; the water's colour, with dark patches
  still under investigation).
- VICTORY_MERGE_RUNS_ALT, VICTORY_CLAMP_LEAN, VICTORY_CLAMP_WINDOW,
  VICTORY_OCCLUSION: measured, no gain; off.
The shader translator changed: delete both shader caches before the first run.
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
… part 2)

9613092 alone does not build (its second deep-skips form call lacks the
label 93db653 adds), so the fifth merge goes on to e4245f3, the commit
it was meant to bring; nothing after it (fxceless#1320, fxceless#1321, fxceless#1353, fxceless#1336,
fxceless#1324 of 13:05 are left for later).

- 93db653: build fix for 9613092 (VICTORY_WAVE_WHY form label).
- e4245f3: VICTORY_CARD_HASH_WIDE=alt (1 was already there; default
  still a thread a piece), VICTORY_GATHER_SEGMENTS and
  VICTORY_GATHER_DISPATCHES (off), VICTORY_DIRTY_4K (off),
  VICTORY_MERGE_RUNS_ALT (unset), VICTORY_HEAP_RECHECK_EVERY (0),
  VICTORY_WAVE_WIDE_ONLY (empty); VICTORY_PAGE_WRITES default now
  guards+slots+plain reads' textures (1|2|8; "guards" is the old one);
  host callbacks check due textures first; textures without card room
  asked again (upstream VIctory #3198); a released view heap forgets its
  title-memory run (fxceless#589); shader fixes: mesh corners masked 9 bits,
  two immediate samplers behind a uniform branch, sampleLevel log2 and
  _cl clamp, split wave64 mask moves (fxceless#1112, fxceless#702).

Conflicts, our structure kept: HostList hunks moved to host/host_list.rs;
image hunks to emit/image_buffer.rs; copy_stale takes both COLD_SKIP
marks and DIRTY_4K pieces; Journal keeps cold_skip::Written plus the 4K
map; translate_listed wraps translate_counted; MERGE_RUNS_ALT before our
card_steps split. Duplicates kept once (ours): fxceless#1324 (HEAP_IDENTITY),
fxceless#1002 (SHADER_CASCADE_EXACT), and fxceless#646: upstream's DispatchX thread
counts (USER_DISPATCH_THREADS, same code 0x106) dropped for our port of
fxceless#1292 (USER_THREAD_LIMIT, which also covers the paired 64-lane form).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
…ure fixes), cascade shadows, render-target snapshots, and switches for rays, memory and input

Twenty-two commits, tested as fe2ede8 (cargo check of the workspace with
diagnostics clean; victory-gpu --lib 356 passed, 0 failed) and built by
Codex as fe2ede8-diagnostics.

On by default, each with a way back:
- the original's fifth merge up to e4245f3 with 93db653: VICTORY_PAGE_WRITES
  now also sends back to pending the textures written by slots and by
  plain reads (1|2|8; =guards is the default of before), textures without
  room on the card are asked for again (VIctory #3198), a released view
  heap forgets its run of title memory (fxceless#589), shader fixes (fxceless#1112, fxceless#702,
  mesh corners, samplers behind a uniform branch, sampleLevel);
- fxceless#1002: exact cascade shadows on cards of 32 lanes
  (VICTORY_SHADER_CASCADE_EXACT=0 goes back);
- fxceless#1371: render targets replayed from a copy taken at SetRenderTargets
  (VICTORY_RT_SNAPSHOT=0 goes back).

Off by default: VICTORY_RT_SKIN_SKIP, VICTORY_RT_RESOLVE_SKIP,
VICTORY_ACTIVATE_RAYS_SKIP, VICTORY_HAIR_VB_SKIP (with a census of such
programs), VICTORY_ALT_FLIP (fxceless#1341), VICTORY_RAM_TRIM, VICTORY_WINDOW_REUSE
(fxceless#1362), VICTORY_COLD_SKIP (fxceless#1358), the worker chain of fxceless#1290,
VICTORY_KEYS_FILE, VICTORY_NULL_SAMPLES, and the merge's CARD_HASH_WIDE=alt,
GATHER_SEGMENTS, GATHER_DISPATCHES, DIRTY_4K, MERGE_RUNS_ALT,
HEAP_RECHECK_EVERY and WAVE_WIDE_ONLY. The profiler test walks only modules
that never unload.

Left out: diagnostics/translate-water-5dc3-6f22-2026-11-26.txt, a
translation diagnostic of the original's run that lists offsets and
instructions of two of the title's shaders.

Measured by Codex on fe2ede8, the ten switches of Status, screenshots
every second, one pair of sessions of 480 s, the same binary: in the
opening's cafeteria two faces were drawn with their features with the new
default, and one of them came out without features and the background
washed out with VICTORY_PAGE_WRITES=guards, at different moments and
poses; in the reverse pair a face came out almost all black with the new
default (the guards session was stopped by the memory guard at 391 s), so
these fixes are not the whole answer to black faces. Not measured for
frame rate yet. Neither session crashed; frames of a second
or more between 150 and 450 s: 49 (longest 5.7 s) with guards, 52 (6.8 s)
with the default. A first session with a cold shader cache was ended at
388 s by the title itself after a frame of 21.5 s spent waiting for the
runtime's remapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hkmodd added a commit to hkmodd/victory-fork that referenced this pull request Nov 27, 2026
 per-axis thread counts, fxceless#1002, fxceless#589, #3198, HEAP_RECHECK_EVERY

Upstream kept: watch PAGE_WRITES default 1|2|8 with five counters; fxceless#646
per-axis dispatch thread counts beside our width form on code 0x106
(our counted form now needs a group wider than 2); fxceless#589 heap ids and
forget_heap; #3198 textures without card room asked again after 1 s;
VICTORY_HEAP_RECHECK_EVERY (off); VICTORY_WAVE_WIDE_ONLY; lower.rs
fxceless#646 prologue, two-sampler images, 9-bit mesh corners, cube-map levels.
Ours kept: submit and card-copy paths (host.rs card_pass, shadow, list,
indirect), ir.rs parked pairs (our 4fd34fd already adapts fxceless#1002).
Left out: CARD_HASH_WIDE, MERGE_RUNS_ALT, GATHER_SEGMENTS, DIRTY_4K and
the gather path the fusion had dropped. TRANSLATOR_VERSION 3.
Tests: victory-shader 328 ok, victory-gpu 447 ok; diag build ok.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant