Skip to content

GPU: take back the dynamic descriptor slots of lists that ran when a heap runs short - #688

Open
iurysf wants to merge 3 commits into
Marvisak:mainfrom
iurysf:dynamic-slot-reclaim
Open

iurysf wants to merge 3 commits into
Marvisak:mainfrom
iurysf:dynamic-slot-reclaim

Conversation

@iurysf

@iurysf iurysf commented Nov 24, 2026 •

Copy link
Copy Markdown

Rebased onto main 58fed37, which now includes #336, so this is a single commit on main. Tests after the rebase: cargo test -p victory-gpu -- --test-threads=1 gives 54 passed, 1 ignored. Clippy -D warnings is clean, with and without diagnostics, and cargo xtask policy is ok.

A list holds the dynamic descriptor slots its draws took until the title resets it. Submissions are waited for (Host::execute waits on its fence with INFINITE), so once a list has run, the GPU no longer reads those slots. On a capped view heap, though, the dynamic pool fills within seconds of entering the world and every further table is refused, so the draw or dispatch is dropped. On NVIDIA that cap is 1,000,000 slots, 65,536 of them dynamic (with #336). On an RTX 4070 we see dropped=65536 and no free dynamic descriptor slots.

Existing PRs enlarge the pool (#135, #336, now merged), fix the search (#251), share identical tables (#562) or drop the draw (#336). None gives back slots that are no longer read.

Change

  • When HostHeap::dynamic has no room, State::take_dynamic takes back the slots of the oldest list that already ran (descriptor::lease), one list at a time, and retries. Nothing changes while the heap has room.
  • The list taken back is marked lost. If it is submitted again without a reset, it is not run: its draws are dropped, just as a draw whose table could not be made is dropped today. It works again once the title resets it.
  • A list is never taken back while it runs, because Lease::start and reclaim share one lock.

On the GPU (RTX 4070, driver 32.0.16.2101, base main d2a4bae + #493 + #483, default loop limit, 300 s, two runs):

  • There was no device removal in either run.
  • Logged dynamic-slot drops (the log prints at doublings) peaked at 16,384 and 4,096. Without this change they reached 32,768 and 65,536 in the same configuration.
  • The "submitted again ... not run" warning, i.e. a reclaimed list being reused without a reset, never appeared. Only "taken back" appeared.
  • "dropped without a host pipeline" and refused pipelines are unchanged, as expected. World frames were still black, so no visual difference is shown. ms/frame is not comparable because the host CPU was busy with other jobs.

Risks

Tests: 5 new unit tests (without reclaim 2 fail; with start disabled 3 fail). cargo test -p victory-gpu -- --test-threads=1: 47 passed, 1 ignored (plus the load-flaky frame test, see the separate PR). Clippy -D warnings is clean; cargo xtask policy is ok.

No game data used. AI-assisted.

@LAKSHYA-cmd-tech LAKSHYA-cmd-tech left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 48 tests in �ictory-gpu passed cleanly, including all 5 new unit tests in descriptor::lease::tests and draw::tests. Reclaiming dynamic descriptor slots from the oldest completed command lists cleanly prevents GPU view heap exhaustion (65536 drop threshold) during world loading.

@iurysf
iurysf force-pushed the dynamic-slot-reclaim branch from 0a146af to bf4e37e Compare November 24, 2026 08:46
@iurysf iurysf changed the title GPU: take back the dynamic descriptor slots of lists that ran when a heap runs short (stacked on #336) GPU: take back the dynamic descriptor slots of lists that ran when a heap runs short Nov 24, 2026
@MartinIndra02

Copy link
Copy Markdown

Independent Windows + NVIDIA Ampere verification for bf4e37e:

  • Setup: Windows 11 Pro 26200, NVIDIA GeForce RTX 3080 (10 GB, driver 621.24), Ryzen 7 5800X3D, Rust 1.98.1 (x86_64-pc-windows-msvc).
  • cargo test -p victory-gpu --lib -- --test-threads=1: 54 passed, 0 failed, 1 ignored (all 5 new descriptor::lease::tests and draw::tests pass).

No game data used. AI-assisted; tests run on my machine.

@justr4mzi

Copy link
Copy Markdown

Tested PR #688 (bf4e37ed) on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2) and Rust 1.98.1 (x86_64-pc-windows-msvc), compared against main (02f404e) as baseline.

Test results (victory-gpu)

  • main (02f404e, baseline): cargo test -p victory-gpu -- --test-threads=1 -> 49 passed, 0 failed, 1 ignored (with --features diagnostics: 52 passed, 0 failed, 1 ignored).
  • PR GPU: take back the dynamic descriptor slots of lists that ran when a heap runs short #688 (bf4e37ed):
    • cargo test -p victory-gpu -- --test-threads=1: 54 passed, 0 failed, 1 ignored (all 5 new tests in descriptor::lease::tests and draw::tests pass).
    • cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 57 passed, 0 failed, 1 ignored.
    • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
    • cargo xtask policy: 153 files ok.
  • Note: bf4e37ed fast-forwards from 02f404e with #696 and #706 in its branch history; the 5 new GPU lease/draw tests are specific to #688.
  • Not run: runtime gameplay test (the title itself was not launched; no game data included).

AI-assisted test execution (reviewed locally).

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Independent Windows + AMD RDNA4 verification of bf4e37ed9 merged with main (8e79c80, clean merge): PASS.

  • Setup: Windows 11 Pro (26100), AMD Radeon RX 9060 XT (driver 32.0.32029.2010), Rust 1.98.1 (x86_64-pc-windows-msvc).
  • cargo xtask policy → asset policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings → pass (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings → pass (0 warnings)
  • cargo test --workspace --locked → 316 passed, 0 failed, 6 ignored (all 5 new descriptor::lease::tests::* and draw::tests::* pass under default parallel test execution)
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked → 55 passed, 0 failed, 1 ignored on RX 9060 XT (0.20s), zero debug-layer messages
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --locked → 55 passed, 0 failed, 1 ignored on WARP (0.20s), zero debug-layer messages
  • Diff review: lock ordering between FINISHED and Lease::ranges is consistent (FINISHED → ranges in reclaim and finish's prune path; finish's early emptiness check drops ranges before locking FINISHED), and take() ensures reset/dropped leases are never double-released.

AI-assisted; synthetic tests only, no game files.

@rpmaster2

rpmaster2 commented Nov 24, 2026 •

Copy link
Copy Markdown

Cross-check on Radeon RX 9070 XT 16 GB (RDNA4), Adrenalin 26.11.2 (32.0.32029.2010), Windows 11 26300, Ryzen 5 5600, 32 GB RAM, diag build, VICTORY_D3D12_DRED=1.

Base main @58fed37 (already carries #336's 2^18 dynamic slots and the drop), this branch merged on top, 480 s per run, alternating:

run binary result max frame
1 main device removed (~4m40s after start) 1249
2 main + this PR device removed 1282
3 main device removed 1142
4 main + this PR device removed 1167
5 main device removed 1126

So on this host the change neither regresses nor prevents the removal; 5/5 runs die at frame 1100-1300. Earlier 200-240 s runs of both binaries survived only because they were shorter than the crash window - that was my mistake, not evidence of a fix.

The removal is also no longer about slots: no free dynamic descriptor slots appears 0 times in every run above, with or without this PR. DRED names a different cause:

host GPU device removed after a submission of 24 lists; page fault at 0x...; inside freed ["texture 1024x1024 f98 flags 0x0 (type 34)"]

Across the five runs the fault lands inside a freed host texture: 1024x1024 f98/f99, 2048x2048 f98, 512x512 f29 (flags 0x1), 256x256 f99, always type 34. In two runs the stopped list is 7d85c9cab3c80721, whose tables come from shader f0c7efd2aceb2aaa and name placed SRVs. The log also reports a title texture was released while a list not yet reset names its host copy before the removal.

That points at a stale descriptor / use-after-free on a released texture, which #609 targets; I am testing #609 on the same host and will report there. Nothing here needs a change from you - this is only to keep the slot-exhaustion theory from being credited with a fix it does not provide on RDNA4.

Separately, the world stays black for a different reason: 426 shaders refuse translation (354 compute, 38 pixel, 30 mesh, 4 vertex), so their draws are dropped.

No game data in this report: counts, formats, shader hashes and error strings only.

AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested bf4e37e on Windows 11, RTX 5070, MSVC: cargo test -p victory-gpu -- --test-threads=1 54 passed. cargo clippy -p victory-gpu --all-targets is clean. Not exercised against a title here.

  • Locking: Lease::start and reclaim share the FINISHED lock, so a list is never taken back between being chosen and starting to run. Every Host::execute waits on its fence, so once a list is in FINISHED the GPU really has stopped reading its slots. Correct as long as submission stays synchronous.
  • Semantics, as you already note: D3D12 allows a closed list to be executed again without Reset. Under heap pressure, a reclaimed list that is submitted again now drops all of its draws, where today only the draws whose tables can't be made are dropped. That isn't worse than the current exhaustion behaviour, but the "submitted again … not run" warning is the only signal. It's worth keeping that warning at warn, outside diagnostics, so a title that relies on re-execution shows up in a normal log.
  • If #595 (async submit) lands first, finish must move to fence completion, not execute return. A debug_assert! or a comment at the finished(this) call site would stop that from being missed.

AI-assisted (Claude Code).

giritsu pushed a commit to giritsu/VIctory that referenced this pull request Nov 24, 2026
…arvisak#493)

A root SRV is an unbounded GPU address: mesh shader vertex fetch
read past a buffer copy's end into freed GPU memory, causing a page
fault. Bind each root SRV as a one-descriptor raw table sized to the
host copy (`raw_at`), wired through `State::take_dynamic` so slots
participate in lease reclamation (Marvisak#688).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/list.rs, crates/victory-gpu/src/queue.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

openbotgit Bot and others added 3 commits November 24, 2026 21:56
…heap runs short

A list keeps the dynamic slots its draws took until the title resets it.
Every submission is waited for, so once a list has run the GPU no longer
reads them, but a capped view heap (NVIDIA: 1,000,000 slots, 65,536 of them
dynamic) is full within seconds of the world and every later table is
refused: the draw or dispatch is dropped (Marvisak#336 drops it instead of reading
the title's slots).

When `HostHeap::dynamic` has no room, `State::take_dynamic` now takes back
the slots of the oldest list that already ran (`descriptor::lease`), one
list at a time, and retries. That list is marked lost; submitting it again
without a reset is refused (its draws are dropped, as a table that could not
be made already drops one) and it works again once the title resets it. A
list is not taken back while it runs: `start` and `reclaim` share one lock.
Nothing changes while the heap has room.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…n for the slot list compiles

A list's dynamic slots were a `Vec` field named `dynamic` that callers
pushed `(heap, first, n)` onto. The lease replaced it; keep the old name
and let `Lease::push` take the same tuple, so a change that still does
`self.dynamic.push((heap, first, 1))` (the root SRV one-view tables of

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
…issions

Capturing a list's current Arc<Lease> before host.execute means queue execution never dereferences a command list or re-reads State::lease after bottom-of-pipe writes have allowed another thread to reset or release the list. Tracking an in-flight submission count on Lease under FINISHED (and checking in_flight == 0 in reclaim) also keeps dynamic descriptor slots pinned until every overlapping or duplicate submission of the list finishes.

Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
@iurysf
iurysf force-pushed the dynamic-slot-reclaim branch from 2e42e8b to 39e68e2 Compare November 25, 2026 02:41
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
…r-high-half-111a

Shaders: keep d16 format-load high halves and saturate integer channels (Marvisak#440)
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…n a heap runs short)

Conflicts in list.rs and queue.rs: main now queues a submission's host
lists (segments) behind held work (crate::hold, decision 0007) and runs
them later from pump, instead of executing them in ExecuteCommandLists.
Marvisak#688's lease is carried onto that:
- list::start takes the list's segments (not one host list) and starts
  its lease; a lost list is skipped with Marvisak#688's one-time warning;
- queue::Segment pairs a held host list with the lease, on the list's
  last segment, and pump's run finishes it after host.execute, before the
  host list is recycled.
So a list's slots cannot be taken back while its host lists are held or
running. Lease, list, hold and queue tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…nd views held whole)

descriptor.rs is fork/main's but for Marvisak#688's lease module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

We ran a reclaim of our own on a capped NVIDIA view heap (1,000,000 views, 65,535 dynamic slots), built the way this PR describes. It hit the case the triage flagged, so here is what we found and the rule we settled on, in case it helps this PR along.

Lists submitted again before a reset

The title does submit lists again without resetting them. On our play build, the slot line counts "lists submitted again before a reset" every few seconds. In each 10-minute run it added up to 2,063-3,016 such submissions, about one a frame. In our first run with the reclaim (DP1), none of those lists had been taken back at the time, so nothing was lost: 0 lists not run across all 102 slot lines. That was luck. It held only because the take-backs happened to hit lists the title was done with.

Our rule: a list that the title has submitted again since it last ran, without a reset, is never taken back.

  • How we tell. A list's lease gets a ran flag, set when one of its submissions finishes. When the list is submitted again and ran is already set, the lease is marked again. A reset clears both, because the lease is emptied and starts over.
  • A lease marked again stays out of the queue of finished lists, and reclaim skips it. Its slots stay with it until the title resets it, as on main.
  • So a list is never lost, and no draws are dropped for a lost list. The lost path (refusing to run a list whose slots were taken back) is still there as a guard.

In this PR's descriptor/lease.rs, that would mean the following (a sketch, not tested on this head):

  • an again: AtomicBool and a ran: AtomicBool on Lease;
  • in start: if ran, set again;
  • in finish: set ran, and if again, don't push the lease onto FINISHED;
  • in reclaim: skip leases marked again;
  • in take: clear both flags.

All of this happens under the FINISHED lock that start and reclaim already share.

In-game counts (RTX 5070, our play build, 10 minutes a run)

Local title data was used for these runs; only counts and timings from the logs are given here.

The play build carries other unmerged changes. These counts are about the reclaim only.

run build slot lines lists submitted again before a reset (whole run) of them not run (slots taken back) dropped draws, last 61+ slot lines
DP1 reclaim, before the rule 102 2,812 0 0
N2U with the rule 101 2,910 0 0
N2P with the rule 106 2,401 0 0
N3A with the rule 106 2,689 0 0
N3B with the rule 106 2,781 0 0
N3C with the rule 101 2,063 0 0
OV0 with the rule 100 2,537 0 0
OV1 with the rule 108 3,016 0 0
  • Draws were still dropped for want of dynamic slots in each run, but only early on: in slot lines 11-41, depending on the run. From the 42nd line to the end (61-75 lines), every run logged 0. In DP1, those early drops came in bursts where one frame's lists held more than the whole pool, nearly all of it in fresh tables for title slots past the host's 934,464. Taking slots back can't help there, and we're looking at it separately.
  • Over those runs the reclaim took back 0-6,395 slots (0-12 lists) in the 8 frames of the last slot line.

The release path

This PR's HostHeap::release only clears the slots' flags (a fill over n). It doesn't walk the free run beside them, so the cost we bounded on our side doesn't apply here. Our walk came from our own bound on the longest free run (taken to skip searches that can't succeed), which this PR doesn't have.

Related

Our commits

They don't apply to this branch. Ours is a separate implementation: the lease lives in draw.rs on a later main. A merge-tree preview of each commit onto 39e68e2 conflicts in descriptor.rs, descriptor/host.rs, draw.rs, host.rs and queue.rs. So the rule above is the useful part, and we're glad to test a rebased head of this PR with it.

AI-assisted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants