Skip to content

GPU: reserve 2^18 dynamic slots on capped view heaps and trim fresh tables (#747) - #1349

Open
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/nvidia-dynamic-view-heap
Open

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/nvidia-dynamic-view-heap

Conversation

@wbkepler

Copy link
Copy Markdown

Summary

Implements #747:

  • Reserves the full DYNAMIC (2^18 = 262,144) dynamic view slots on capped 1M heaps via capped_split() (737,856 mirrored + 262,144 dynamic, safe for small limits) so NVIDIA world indirect/mesh tables do not starve.
  • Trims fresh dynamic descriptor tables in draw.rs to [first_used, last_used] (clamped to mirrored count so base = first - start never underflows) and includes (start, end) in the per-list cache key.
  • Adds unit and live-device tests covering capped dynamic reservation and first-used-entry fresh-table indexing.

Verification

  • cargo clippy -p victory-gpu --all-targets -- -D warnings — passed
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test -p victory-gpu — passed
  • cargo xtask policy — passed

…ables

Implements Marvisak#747:
- Reserve the full DYNAMIC (2^18 = 262,144) dynamic view slots on capped 1M
  heaps via capped_split() (737,856 mirrored + 262,144 dynamic, safe for
  small limits) so NVIDIA world indirect/mesh tables do not starve.
- Trim fresh dynamic descriptor tables in draw.rs to [first_used, last_used]
  (clamped to mirrored count so base = first - start never underflows) and
  include (start, end) in the per-list cache key.
- Add unit and live-device tests covering capped dynamic reservation and
  first-used-entry fresh-table indexing.
simnJS added a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
BTP 6's view heap has 1,245,184 slots; hosts that cap shader-visible view
heaps at 1,000,000 (the RTX 4080 SUPER, resource binding tier 3, takes
exactly that many, measured) got 65,536 dynamic slots, and the Series S
world ran short of them: session 20261124-181140 dropped draws for "no
dynamic slots" from 18:13:07 (256 by 18:13:31) and the device hung at
18:13:51 (watch item 109); session 5 of the series-s task dropped draws
the same way. Upstream, 2^18 took an RTX 5090's slot drops from 20 to 0
(VIctory #747, #1440).

A capped heap now keeps DYNAMIC (2^18) slots dynamic and mirrors 737,856
title slots (capped_split). Title tables reaching past the mirrored slots
are made afresh in dynamic slots (draw.rs, as before), not read past the
heap. In a Series S session with this change (20261124-182836, 30 s in
the world) the title wrote no slot past 737,856 ("title slot past the
host heap" never came) and the dynamic peak was 32,774 of 262,144.

Not taken from #1349: dropping the middle step (a heap the host takes
with 2^16 dynamic slots on top of every title slot keeps them all; #1349
cut title slots there, which #747 does not ask), and its draw.rs half
(fresh tables trimmed to the entries used), the drops task's file.
VIctory #1444 (heap ABA) is in draw.rs only: not in this change.

Tests: the split (and small limits), and a heap of the title's size.

Ported from Marvisak/VIctory#1349 (head eb5fea7) by wbkepler

Co-authored-by: wrothgaril <211408787+wrothgaril@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shortselow-byte

Copy link
Copy Markdown

For triage: this conflicts with #955 (git merge-tree against the current heads, in descriptor/host.rs), and the two make incompatible choices about the same slots.

  • Here, capped_split(PORTABLE_VIEWS) gives (1_000_000 - 262_144, 262_144) = (737_856, 262_144), the whole 1M heap, and the uncapped path keeps count + DYNAMIC with all DYNAMIC slots dynamic.
  • Shaders, GPU: clamp descriptor heap indices to bound host heap guard slot #955 (which fixes the AMD >1M heap black screen) reserves the last slot of every view heap as a permanently-null guard that shaders clamp to: dynamic = DYNAMIC - 1 (or MIN_DYNAMIC - 1 when capped) and guard = total - 1.

Merged as they are, there is no slot left for #955's guard on a capped heap. Whichever lands second needs one slot less in one of the two ranges (e.g. DYNAMIC - 1 dynamic slots) so the guard stays outside both.

This PR on its own, at eb5fea7 on main ffe310e, isolated target directory, Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT: workspace 345 passed, 0 failed, including its three new tests; both clippy runs clean.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review plus the PR's own Windows tests.

Capped view heaps (NVIDIA 1M descriptor limit) now reserve the full DYNAMIC=2^18 dynamic budget out of the cap instead of shrinking to MIN_DYNAMIC=2^16: capped_split(limit) gives (limit - min(DYNAMIC, limit-1), ...) so mirrored title slots keep at least one slot and small limits never underflow (0→(0,0), 1→(1,0), 1024→(1,1023)). Uncapped heaps still try count+DYNAMIC first. Rationale documented (#59, #747: world tables starving on capped heaps). Trade-off: mirrored prefix shrinks from ~960K to ~768K on a 1M cap — worth a sentence in the PR description, but the direction is right. Unit tests cover the split boundaries; the GPU test skips cleanly without a host.

@devgosling

Copy link
Copy Markdown

Tested on an RTX 5080: the PR fixes the dynamic-slot starvation, but the world still hangs (0x887A0006) about as soon as before.

Setup

  • NVIDIA GeForce RTX 5080, driver 32.0.16.1088, Ryzen 9 9950X3D (its Radeon iGPU is also present; the RTX drives the display and nvlddmkm logs the errors), Windows 11 Pro 26200
  • Title 7952987A
  • diag profile with --features diagnostics, VICTORY_D3D12_DRED=1, default loop limit, no TDR registry changes. The D3D12 debug layer isn't installed, so this is DRED-only.
  • Baseline: main at ffe310e. PR: eb5fea7, which sits directly on ffe310e. One run each, same settings.
  • cargo test -p victory-gpu passes on this GPU with the PR: 53 passed, including the three new tests.

Results

ffe310e eb5fea7 (this PR)
View heap capped at 1000000 count=1245184 capped at 1000000 count=1245184 mirrored=737856 dynamic=262144
no free dynamic descriptor slots / no dynamic slots for its tables yes, from the first world frame on (dropped=1024 before the hang) none
title slot past the host heap none none
Hang after the first world frame ~22 s ~27 s
Last submission ms=5648 lists=27 ms=4730 lists=31
DRED page fault none none
DRED stop command 3 of 70 (op 42), mesh 159 [mesh 4adfa13bea1c556a] command 1391 of 1612 (op 42), commands 1390..1392 between barriers, mesh 50 [mesh 29f7805ffefc2e63, pixel 19acd330dacc8f32]

A third baseline run with VICTORY_SHADER_LOOP_LIMIT=4096 (ffe310e) also starved the dynamic slots (dropped=16384) and then hung on a single list (ms=4683 lists=1).

So on this GPU the dynamic-slot exhaustion comes with the hang, but it isn't what causes it. With the starvation gone, the hang is still a DispatchMesh hang with no page fault, and the mesh shader changes from run to run. That looks like the same thing as #1216 and #1670. These are single runs, so the timing difference between them doesn't mean much.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

In-world evidence for keeping 2^18 on capped heaps, from a fork that runs main into the world on NVIDIA (RTX 4070, capped at 1,000,000 views): fxceless/victory-gta6, the comment on DYNAMIC in descriptor/host.rs.

  • main's capped fallback, 2^16 (MIN_DYNAMIC, from GPU: drop draws whose fresh tables cannot be made; 2^18 dynamic slots #336), ran out in the world: "no free dynamic descriptor slots".
  • 2^17 ran out in the opening cutscene. A frame asks for up to 16,000 tables while the frame before still holds its own. A draw whose table was refused read slots never made for it, and the card stopped within frames.
  • 2^18 on the capped heap (about 737,000 title slots left; the highest title slot seen is about 720,000) is what the fork keeps, as this PR does.

The fork also found a second cost, which may matter for @devgosling's hang above. With slots free but in pieces, each refused table searched the whole ring before giving up: 0.33 ms each with 131,072 slots, and 1.0 s of the recording threads in a frame that refused 3,143 tables, all under the lock every table takes. It keeps a free-slot count, plus the shortest table length that last found no run, and refuses longer tables without searching until slots are given back.

Reading only, nothing run. AI-assisted (Claude Code).

@adnanoos

Copy link
Copy Markdown

RTX 5060 Laptop GPU: this PR stops every "no dynamic slots" drop and the world reaches the G-buffer

Setup. NVIDIA GeForce RTX 5060 Laptop GPU (heap capped at 1,000,000; the title asks 1,245,184), driver 32.0.16.2124, Windows 11 Pro 26200, title 1.0.2.1, Series X mode. Release build with --features diagnostics. The base is #1520 (2190efe) + the resync_title_writes bound from #994's thread + #452 + #1010. Compute eeed82b877b44b5f is skipped (VICTORY_SKIP_PIPELINES) in both runs, because it hangs the GPU here otherwise. Targets were dumped with VICTORY_DUMP_TARGETS at world frames. 8-minute runs, one each.

base base + this PR (eb5fea7)
host view heap 934,464 mirrored + 2^16 dynamic mirrored=672320 dynamic=262144 (see the merge note)
a draw or dispatch dropped: no dynamic slots for its tables over 1,048,576 in ~5.5 min of world 0
draws/frame in the world 897 2,401
indirect draws dropped/frame 2,665 926
draws dropped without a host pipeline/frame 2,233 1,206
device removal none none

Render targets.

  • Before: the 2560x1440 G-buffer colour targets (formats 27, 28, 34) held two specks. Only a later depth and mask pass had a few large shapes.
  • With this PR: the same targets hold the scene: a picnic table and bench, a plastic chair, a trash can, a sign, overhead lines. One target holds what looks like normals or material data, another albedo.
  • Unchanged: the final 3840x2160 output is still flat (this frame was a letterboxed cutscene: flat grey).

So on this GPU the PR takes the world from "not drawn" to "drawn but not lit". The remaining black is the lighting stage, as in #1317 and #638.

Merge note. On #1520, HostHeap::new also reserves aliases slots. To merge this PR there, I used count + DYNAMIC + aliases for the wanted size and capped_split(PORTABLE_VIEWS - aliases) for the capped case. The mirrored=672320 above comes from that.

Frame rate in the world drops (1.19 → 0.37 fps) because far more is drawn. No device removal in either run.

@wbkepler

Copy link
Copy Markdown
Author

Superseded by #1779, which redoes this on current main (70564ae).

main changed around this since the branch was cut: heaps are now at least HEAP_VIEWS (2^21) slots and translated shaders clamp to that and read the null buffer views at 2^21 - 2, neither of which exists in a capped 1,000,000-slot heap. #1779 keeps what this PR did (the full 2^18 dynamic range on a capped heap, tables made afresh trimmed to their first used entry) and adds the part this one could not cover: the clamp bound and the null buffer views fitted to the heap the host actually makes.

Leaving this open for the maintainers to close; it conflicts with main and will not be rebased.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

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.

7 participants