GPU: title memory page bitmaps live in video memory #2173

Open
wbkepler wants to merge 1 commit from upstream-pr/2175 into main
wbkepler commented 2026-11-25 07:03:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by wbkepler on 2026-11-25T07:03:59Z.


What

Translated shaders that use title memory mark each page they write (and each page they miss) with an atomic OR into their list's page bitmap (crate::memory). The bitmap was a shared buffer in system memory, so every one of those atomics crossed the bus, and the lanes of a pass writing one output region all hit the same few bitmap dwords one after another.

The bitmap now lives in video memory:

  • memory::bind makes a DEFAULT-heap UAV buffer, records a clear in the list (a CopyBufferRegion from one shared zeroed upload buffer, then COPY_DEST -> UNORDERED_ACCESS), and asks for it to be read back.
  • HostList::read_back_at_close (new): at close(), the list copies the bitmap into a mapped read-back buffer (UNORDERED_ACCESS -> COPY_SOURCE, CopyBufferRegion).
  • defer_missed / defer_after read the marks from the read-back mapping as before. Because the clear and the copy are recorded in the list, a closed list that runs again starts with a clear bitmap too.
  • Host::uav_buffer / Host::readback_buffer are small helpers for the two buffers.

Per list that uses title memory, that adds two 256 KiB copies on the GPU. Nothing changes in the translator (shader cache entries stay valid).

Why

On an NVIDIA host the title's acceleration-structure build passes use title memory: two straight-line compute programs with two root UAVs, dispatched a few thousand times in one list. With the bitmap in system memory that list ran for seconds and the device was removed with DXGI_ERROR_DEVICE_HUNG. DRED stopped in those dispatches in every run, with no page fault reported. This matches the hangs reported in #294 for programs with two raw root UAVs. Their code has no loops that could spin: the only loops are bounded by a byte, a popcount or 4.

Verification (Windows 11, NVIDIA RTX 5090)

On an integration build (this branch + a few open PRs needed to reach the world on a 32-lane host), diag build, VICTORY_D3D12_DRED=1, with and without VICTORY_GPU_TIMING=1:

before after
the list holding the build passes device removed after 17.7 s (GPU_TIMING), and in every run 1.87 s, and every build dispatch of the two programs takes 0.2 ms or less
where the device is removed in those dispatches (both runs) they finish. The next removal is elsewhere: an indirect dispatch of another program (below)

Not fixed here: 1.86 s of that remaining 1.87 s is a single 2-group dispatch of another build program (most likely a loop running to the 2^20 limit). A later list also stops at an ExecuteIndirect (with the stopping program skipped, the next one at the same position stops instead), and that one is still open.

  • cargo clippy -p victory-gpu --all-targets -- -D warnings, cargo clippy -p victory --features diagnostics --all-targets -- -D warnings: clean
  • cargo test -p victory-gpu: 77 passed. New memory::tests::marked_pages_go_back_after_each_run (a shader writes title memory through the page table and marks its page; the page goes back after the first run and again after a second run of the same closed list). Two tests fail identically on main on this host: memory::tests::lists_share_a_table_and_copies_keep_their_views and descriptor::host::tests::dynamic_slots_are_held_until_released (both assume a view heap of 2^21 slots, and NVIDIA caps them at 1,000,000).
  • cargo xtask policy: ok
  • #2167 attacks the same contention from the shader side (test-before-or on the marks, coalesced table loads). The two changes complement each other: that PR makes fewer atomics, and this one makes each atomic cheap.
  • #1865 pools the system-memory bitmaps in memory::bind. It conflicts with this PR textually; with the bitmap in video memory, the pool would hold DEFAULT + read-back pairs instead.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6599138053 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2175). Originally posted by [wbkepler](https://github.com/wbkepler) on 2026-11-25T07:03:59Z. --- ## What Translated shaders that use title memory mark each page they write (and each page they miss) with an atomic OR into their list's page bitmap (`crate::memory`). The bitmap was a shared buffer in **system memory**, so every one of those atomics crossed the bus, and the lanes of a pass writing one output region all hit the same few bitmap dwords one after another. The bitmap now lives in **video memory**: - `memory::bind` makes a `DEFAULT`-heap UAV buffer, records a clear in the list (a `CopyBufferRegion` from one shared zeroed upload buffer, then `COPY_DEST -> UNORDERED_ACCESS`), and asks for it to be read back. - `HostList::read_back_at_close` (new): at `close()`, the list copies the bitmap into a mapped read-back buffer (`UNORDERED_ACCESS -> COPY_SOURCE`, `CopyBufferRegion`). - `defer_missed` / `defer_after` read the marks from the read-back mapping as before. Because the clear and the copy are recorded in the list, a closed list that runs again starts with a clear bitmap too. - `Host::uav_buffer` / `Host::readback_buffer` are small helpers for the two buffers. Per list that uses title memory, that adds two 256 KiB copies on the GPU. Nothing changes in the translator (shader cache entries stay valid). ## Why On an NVIDIA host the title's acceleration-structure build passes use title memory: two straight-line compute programs with two root UAVs, dispatched a few thousand times in one list. With the bitmap in system memory that list ran for seconds and the device was removed with `DXGI_ERROR_DEVICE_HUNG`. DRED stopped in those dispatches in every run, with no page fault reported. This matches the hangs reported in #294 for programs with two raw root UAVs. Their code has no loops that could spin: the only loops are bounded by a byte, a popcount or 4. ## Verification (Windows 11, NVIDIA RTX 5090) On an integration build (this branch + a few open PRs needed to reach the world on a 32-lane host), diag build, `VICTORY_D3D12_DRED=1`, with and without `VICTORY_GPU_TIMING=1`: | | before | after | |---|---|---| | the list holding the build passes | device removed after 17.7 s (`GPU_TIMING`), and in every run | 1.87 s, and every build dispatch of the two programs takes 0.2 ms or less | | where the device is removed | in those dispatches (both runs) | they finish. The next removal is elsewhere: an indirect dispatch of another program (below) | Not fixed here: 1.86 s of that remaining 1.87 s is a single 2-group dispatch of another build program (most likely a loop running to the 2^20 limit). A later list also stops at an `ExecuteIndirect` (with the stopping program skipped, the next one at the same position stops instead), and that one is still open. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, `cargo clippy -p victory --features diagnostics --all-targets -- -D warnings`: clean - `cargo test -p victory-gpu`: 77 passed. New `memory::tests::marked_pages_go_back_after_each_run` (a shader writes title memory through the page table and marks its page; the page goes back after the first run and again after a second run of the same closed list). Two tests fail identically on `main` on this host: `memory::tests::lists_share_a_table_and_copies_keep_their_views` and `descriptor::host::tests::dynamic_slots_are_held_until_released` (both assume a view heap of 2^21 slots, and NVIDIA caps them at 1,000,000). - `cargo xtask policy`: ok ## Related - #2167 attacks the same contention from the shader side (test-before-or on the marks, coalesced table loads). The two changes complement each other: that PR makes fewer atomics, and this one makes each atomic cheap. - #1865 pools the system-memory bitmaps in `memory::bind`. It conflicts with this PR textually; with the bitmap in video memory, the pool would hold `DEFAULT` + read-back pairs instead. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 08:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T07:17:36Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Title memory page bitmaps in video memory — bitmap placement change; check readback paths still work.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053350856 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2175#pullrequestreview-6053350856). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T07:17:36Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Title memory page bitmaps in video memory — bitmap placement change; check readback paths still work.
MamaLeVrai commented 2026-11-25 09:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T08:52:18Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 82ae414a into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 702 passed, 0 failed, 10 ignored in the second run. In the first run one test failed, bindless::tests::heap_views_follow_writes_through_another_mapping (bindless.rs:612, "round 0, dword 0, left 0, right 1064"). That failure is not this PR's: the same assertion failed on main alone in another full run here (see #2252 for the numbers). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157576075 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2175#issuecomment-7157576075). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T08:52:18Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `82ae414a` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 702 passed, 0 failed, 10 ignored in the second run. In the first run one test failed, `bindless::tests::heap_views_follow_writes_through_another_mapping` (`bindless.rs:612`, "round 0, dword 0, left 0, right 1064"). That failure is not this PR's: the same assertion failed on `main` alone in another full run here (see #2252 for the numbers). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 13:02:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:41:00Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/memory.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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162710598 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2175#issuecomment-7162710598). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T12:41:00Z. --- <!-- victory-triage v1 head=82ae414af9342b0443593fa6b7eb5c942be75a99 verdict=needs-rebase at=2026-11-25T16:09:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/memory.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](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2175:upstream-pr/2175'
git switch 'upstream-pr/2175'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2175'
git switch 'upstream-pr/2175'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2175'
git switch 'upstream-pr/2175'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2175'
git switch 'main'
git merge --squash 'upstream-pr/2175'
git switch 'main'
git merge --ff-only 'upstream-pr/2175'
git switch 'main'
git merge 'upstream-pr/2175'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2173
No description provided.