Skip to content

GPU: title memory page bitmaps live in video memory - #2175

Open
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/title-memory-bitmap-in-vram
Open

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/title-memory-bitmap-in-vram

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

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

🤖 Generated with Claude Code

Translated shaders that use title memory mark every page they write
(and every page they miss) with an atomic OR into their list's page
bitmap. That bitmap was a shared buffer in system memory, so each of
those atomics went over the bus, and the lanes of a pass writing one
output region all hit the same few dwords one after another. On an
NVIDIA host the title's acceleration-structure build passes (two
straight-line compute programs with two root UAVs, dispatched a few
thousand times in one list) then ran for seconds and the device was
removed with DEVICE_HUNG.

The bitmap is now a video-memory buffer: the list clears it (a copy from
a shared zero buffer) where it first uses title memory and copies it
into a read-back buffer when it is closed (HostList::read_back_at_close),
so every run of the list, also a repeated one, starts clear and the CPU
reads the marks after the run as before.

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

@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; source review of the diff.

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

@MamaLeVrai

MamaLeVrai commented Nov 25, 2026 •

Copy link
Copy Markdown

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 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/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

github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Two 256.5 KiB copies, the bitmap into read-back memory and zeros over
it, as the video-memory bitmaps of Marvisak#2175 and Marvisak#2465 record at a list's
end or after a submission: 12.2 µs on an RTX 5070 Ti (median of 20).
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…has GPU upload heaps

Translated shaders mark every page they write through views, every heap
slot they read, and (programs using title memory) every page they write at
computed addresses with an atomic OR into a bitmap, and the lanes of a pass
writing one region all OR the same few dwords. Those bitmaps were shared
buffers in CPU-cached system memory, so each atomic crossed the bus: on an
NVIDIA host 1M ORs of one dword take 18 ms there against 0.03 ms in video
memory, lists of the title's acceleration-structure builds ran for seconds
until the device was removed (Marvisak#2175), and one dispatch measured in
isolation took 20 ms against 0.24 ms with the bitmap in video memory
(issue Marvisak#2695).

Where the host reports GPU upload heaps (D3D12 options 16, which D3DMetal
does) the bitmaps are now DEFAULT-heap buffers; VICTORY_VRAM_MARKS=1|0
overrides, and hosts without upload heaps keep the system-memory bitmaps
as before (also where making the video-memory ones fails):

- the views' bitmaps (shadow.rs): a list recorded once and closed runs
  after every submission's lists, copies each bitmap into a mapped
  read-back buffer and clears it from zeros (Marvisak#2465's tail list). The CPU
  reads the marks from the read-back mapping as it read the bitmap. Read
  marks now last one submission on the GPU, so take_reads keeps their
  union for reads_since (the port latentdev described on Marvisak#2465);
- the page bitmaps of lists using title memory (memory.rs, pooled since
  Marvisak#1865): the list clears its bitmap where it binds it and copies it into
  a read-back buffer when it is closed (Marvisak#2175's read_back_at_close), so a
  closed list run again starts clear.

Ported by hand from wbkepler's Marvisak#2175 and Marvisak#2465 (written against an older
main, before the bitmaps were split and pooled and read marks came), with
their Host::uav_buffer, HostList::read_back_at_close and the tail list.

Tests: marks_in_video_memory_are_read_back_and_cleared_each_submission
(shader-free: GPU copies set the marks; both lists' marks read back, the
next submission sees only its own, read marks kept) and Marvisak#2175's
marked_pages_go_back_after_each_run (HLSL, so not under Wine's compiler).

Co-authored-by: wbkepler <211408787+wbkepler@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
- Night round: record the Windows CI run at 9b3715b, credit wbkepler on
  Marvisak#2175/Marvisak#2465 and note only the first 2 commits of Marvisak#3102 were taken,
  credit ff0e3be to the review of Marvisak#3047 (not Marvisak#3048), and say Marvisak#2065 was
  already merged in the evening round (the night round adds only the
  by-ordinal census).
- New late night round section: its 23 tracks with provenance, what to
  check on the Mac, and how it was tested.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants