Skip to content

GPU: dynamic descriptor slots go back only to the heap that took them - #1324

Merged
fxceless merged 1 commit into
fxceless:mainfrom
CwWwWwW:fix/dynamic-slots-heap-identity
Nov 26, 2026
Merged

fxceless merged 1 commit into
fxceless:mainfrom
CwWwWwW:fix/dynamic-slots-heap-identity

Conversation

@CwWwWwW

@CwWwWwW CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Problem

State::dynamic (crates/victory-gpu/src/draw.rs) keeps the title descriptor heap of each range of dynamic slots by its address, and descriptor::release_dynamic frees the range in whatever host heap is registered at that address when the list is reset.

A command list may outlive the title heap it recorded slots from: D3D12 keeps an object alive while a list names it, so the title can release a shader-visible heap before the lists that use it are reset. If the allocator later places another Box<Heap> at the same address and that heap is registered in SHADER_HEAPS, the old list's reset finds it by address and frees its dynamic slots - slots another live list has taken. Two live lists then hold the same dynamic slots; one rewrites the other's descriptors (wrong bindings, and descriptors rewritten under a list already submitted).

Change

  • HostHeap gets an identity from a process-wide counter (NEXT_ID).
  • State::dynamic records it next to the heap address.
  • HostHeap::release / descriptor::release_dynamic take it and free only when it is the heap's.

A heap that is still there takes its own ranges back exactly as before; a stale release for a heap that is gone (or for a new heap at the old address) does nothing - the host heap it named no longer exists, so there is nothing of it to free.

Tests

  • New descriptor::host::tests::dynamic_slots_are_given_back_only_to_the_heap_that_took_them: two host heaps; a range of A's released with B's identity stays taken, with A's identity is given back.
  • On this machine (no hardware D3D12, WARP): VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics dynamic_slots_are_given_back passes with the change; without it the test fails (free slots 262,144 against 262,142, i.e. B's identity freed A's range).
  • cargo test -p victory-gpu --lib --locked: 218 passed, 0 failed, 6 ignored.
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean; likewise with --all-features.
  • No game files or live gameplay were used. Whether the title really releases a shader-visible heap while lists still hold its slots is not proven here (the game cannot be run in this environment); this is hardening of a lifetime the layer already relies on, not a confirmed live failure.

(CI note: as with #1320/#1321, the check job on main is currently red on the asset-policy violation; #1322 fixes that, after which this branch can be rebased.)

`State::dynamic` keeps the title heap of each range of dynamic descriptor
slots by its address, and `descriptor::release_dynamic` frees the range in
whatever host heap is registered at that address when the list is reset. A
list may outlive the title heap it recorded slots from: D3D12 keeps an
object alive while a command list names it, so the title can release a
shader-visible heap before the lists that use it are reset. If a later heap
is made at the same address (a `Box<Heap>` of the same size), the old
list's reset then frees slots of the new heap that other lists hold - two
live lists get the same dynamic slots, and one rewrites the other's
descriptors.

Give each host heap an identity (`NEXT_ID`) and record it with the range;
`release` frees only when the identity is the heap's. A stale release now
does nothing (the host heap it named is gone, so its slots are too); a heap
still there takes its own ranges back as before.

Test: `dynamic_slots_are_given_back_only_to_the_heap_that_took_them` (two
host heaps; A's range released with B's identity frees nothing, with A's
frees it). It needs a host device: with `VICTORY_D3D12_WARP=1` and
`--features diagnostics` locally it passes with the change and fails
without it (free slots 262,144 against 262,142); CI runs the gpu tests on
WARP. `cargo test -p victory-gpu --lib`: 218 passed, 0 failed, 6 ignored;
`cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean, and the
same with `--all-features`.

Reachability in the title is not proven - the game cannot be run here - so
this hardens a D3D12 lifetime the layer already relies on.
@CwWwWwW

CwWwWwW commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Overlap note for the maintainer: #589 (AscilCH) is an independent, exact fix for the other half of this change's area - it makes a released view heap drop its page table and edits Heap::drop in descriptor.rs next to the identity used by this PR. Both are needed; if #589 lands first, rebase this branch on it (and vice versa). I checked that #589 is not superseded by this PR.

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.
@fxceless
fxceless merged commit 52ac4ec into fxceless:main Nov 26, 2026
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
… measuring

Staged the same evening, compiled and passing the tests, none measured:
the original's fxceless#1002 (exact cascade shadows on 32 lanes), fxceless#1324 and
fxceless#1333 (descriptor heaps), three more ray-only skips with a count of such
programs, fxceless#1341 (VICTORY_ALT_FLIP) and VICTORY_RAM_TRIM.

Why nothing of it has a figure: the process holds about 16.5 GB private
in the first room (the layer's own account of one session), the lab's
runner waits for 20 GiB free, and six readings between 18:47 and 19:11
local time gave 16.1 to 18.0 GiB free. The switches that make the layer
hold less (VICTORY_WINDOW_KB, VICTORY_WINDOW_TAILS, VICTORY_INPLACE,
all in main and off) go first.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
KomanderDG88 added a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
…f (VICTORY_HEAP_IDENTITY=0) for an A/B

On by default, as the fix it is. With VICTORY_HEAP_IDENTITY=0 a range is
given back to whatever heap is registered at the recorded address, as
before fxceless#1324, so one build can compare the faces that turn black and back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KomanderDG88 pushed a commit to KomanderDG88/VIniVIdiVIci that referenced this pull request Nov 26, 2026
Ported from Kamiloj9/victory-dlss commit 2023d5c (Kamil Ojdana), which
adapts PastiiJay/klbf-lab commit 74315e7: the ranges of title memory the
runtime mapped, unmapped or wrote lived in one unbounded Vec that the
first texture pass std::mem::take()d. A second view heap then saw none of
the notifications (its placed textures stayed stale until its slots were
written again), and a long run grew the Vec without bound since nothing
takes it unless a shader that picks textures by index is bound.

The ranges now live in a RemapQueue: sequential numbers, coalescing of
consecutive pages, and REMAP_LIMIT (1 << 15) entries with the oldest
evicted. Each heap has a cursor: it takes what was recorded after its last
pass, and a heap that finds its cursor behind the evicted range rescans
all its placed slots once instead of silently missing the range. Both
heaps still catch up on their own turns, and a slot a draw read through a
table still waits for its draw.

The metric text says "evicted from history" instead of "dropped".

Tests: a unit test of snapshots, coalescing and eviction detection, plus
the WARP test extended to two view heaps, per-heap cursors and an evicted
history that forces the rescan. cargo test -p victory-gpu --lib: 218
passed, 0 failed, 6 ignored; cargo clippy -p victory-gpu --all-targets --
-D warnings: clean.

Not in the fork, upstream/main, the fxceless#653 batch or any open PR (checked by
the fork comparison); this pull request touches descriptor/host.rs, which
fxceless#1324 also changes in an independent area - rebase whichever lands second.

Port: our pile already kept a single Vec plus an overflow flag (from
klbf-lab 74315e7) that made the next pass rescan every placed slot after
the Vec was cleared. The per-heap cursor's eviction check replaces that
flag, so REMAPPED is now only the RemapQueue; HostHeap keeps our `id`
field next to `remap_cursor`, and the rescan still logs "remapped ranges
overflowed" (now when the snapshot is None). Our overflow regression test
resets REMAPPED to an empty RemapQueue and the heap's cursor to 0; the
new test's note_buffer calls take our extra record_change argument.

(cherry picked from commit f513c17)

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
…mended, heap identity, and the switches brought from other projects

Forty-one commits, compiled and tested as 9ef09c2 (victory-shader 267,
victory-gpu 325, victory-loader 51, victory-hle 128, no warnings; build
9ef09c2-diagnostics).

On by default:
- the original's two commits up to 58de9bf: fxceless#927
  (half-precision values through 16-bit buffer views keep their bits) and
  the sign extension of the original project's #3124; the translator
  changes, so shaders are translated anew once;
- the leak of placed-view shapes mended (TaynanGT/Vice-Tay PR fxceless#27);
- fxceless#1324 (VICTORY_HEAP_IDENTITY, =0 goes back),
  fxceless#1333 (VICTORY_REMAP_PER_HEAP, =0 goes back) and fxceless#1336.

Off by default: VICTORY_NAN_SCRUB, VICTORY_SHADER_LOOP_LIMIT_CS,
VICTORY_SHADER_EARLY_DEPTH, VICTORY_UNMAKE_QUIET, VICTORY_PATCH_WAITS,
VICTORY_PATCH_CLZERO, VICTORY_PATCH_CLWB, VICTORY_BVH_NAMED_WRITES,
VICTORY_BVH_BOUNDS, VICTORY_BVH_FENCES, VICTORY_PIPELINE_COMPUTE_WAIT,
VICTORY_CARD_AWAKE, VICTORY_GUARD_OUTSIDE, VICTORY_HEAP_RESCAN_SPREAD,
VICTORY_LAND_ASIDE, VICTORY_GUARD_RUNS, VICTORY_RT_SKIN_SKIP,
VICTORY_WINDOW_SKIP_SAME, VICTORY_MERGE_SUBMISSIONS, VICTORY_MESH_LAUNCH
and the capture switches; =alt for four of them.

Measured by Codex on build 9ef09c2, the ten switches of Status, the
scripted manoeuvre, a quiet machine, one session: 1,819 frames in 274.0 s,
6.64 fps, median frame 144 ms (95th percentile 197), against 6.69 fps and
141 ms on the code of main before it (-0.7 %, one session each). Private
memory in the room 16.8 GiB against 16.1 to 16.7 in six sessions of main
that day; the layer's windows 3,252 MB against 2,844 to 3,336.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
BaggyALPHA pushed a commit to BaggyALPHA/victory-fork that referenced this pull request Nov 26, 2026
Rebased onto upstream 52ac4ec (clean). Two of its five new commits land in
this tree's own harvest area: fxceless#1320 fixes a dynamic-slot leak in
`submit_split` that this tree's enlarged ring may have been masking, and
fxceless#1324 stops dynamic slots being released into a heap that merely sits at the
same address -- which let two live lists hold the same slots and rewrite each
other's descriptors. That is the class of fault that removes a device with no
page-fault address, which is the signature seen here twice, and this tree
exercises that path harder than upstream because it triples the slot count.
First concrete suspect for the loss. fxceless#1321 also helps directly: a staging
file left by a killed process no longer loses its translation, and both
sessions here ended with the process killed.

flamingo `a6163f2` puts a caveat on the ambient result: it dumped every
skinning input over runs 229-235 and found dark faces are late textures
arriving at camera cuts, not lighting. The face turning skin-toned here was
read as the level change landing; it may have been the texture. The walls
gaining colour is the better evidence, and the outdoor near-field black is
not explained by late textures at all, so the depth-occlusion hypothesis
stands.

Also records trustno1's mouse device (worth taking -- the keyboard stand-in
pad is the weakest part of playing this here) and its automatic BAR window
cap under 24 GB, which relieves the same pressure that was present when the
card sat at 94 % of budget.

245 victory-gpu tests pass with diagnostics (225 plain, up from 224 as
upstream added tests), 234 victory-shader; build and clippy clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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>
grosterr added a commit to grosterr/victory-fork that referenced this pull request Nov 26, 2026
…ty check on dynamic slot release)

Cherry-picked commit 2609085 from refs/pr/1324 to avoid pulling 58de9bf shader translator changes before Wave L3.
Resolve conflicts in descriptor.rs and descriptor/host.rs:
- descriptor.rs: omit fxceless#927 half_view test not yet present before 58de9bf (keep release_dynamic id parameter and existing test updates)
- descriptor/host.rs: keep fxceless#1293 FLAG_* constants and fxceless#770 tiled_shown fields alongside NEXT_ID / id: u64

Co-Authored-By: Antigravity <noreply@anthropic.com>
pr0vId3nce added a commit to pr0vId3nce/VIctory-NVIDIA that referenced this pull request Nov 27, 2026
…fxceless/victory-fork#1324)

A list keeps the title heap of each range of dynamic descriptor slots by its
address, and `descriptor::release_dynamic` freed the range in whatever host
heap is registered at that address when the list is reset or has run. A
list may outlive the title heap it recorded slots from (the title can
release a shader-visible heap before the lists that use it are reset); if
a later heap is made at the same address, the old list then frees slots of
the new heap that other lists hold, and two live lists share slots.

Each host heap now has an identity (`NEXT_ID`), recorded with the range;
`HostHeap::release_from` frees only when the identity is the heap's.

Original author: cccw, fxceless/victory-fork#1324 (in victory-fork main
inside e4245f3c1; 52ac4ec0f there is empty). Ported by hand: this tree
reserves slots in `State::reserve_dynamic`. The test is the PR's.

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.

2 participants