GPU: the views' written-pages bitmap lives in video memory #2465
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2465
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2465"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wbkepler on GitHub · 2026-11-25 14:04 UTC · original
wbkepler:gpu/view-marks-in-vram→main· +438 −48 · 4 files · 2 commits · draftWhat
Translated shaders mark each 64 KiB page they write through views ("Write marks",
crate::shadow::copy_back_marks) with an atomic OR into one bitmap. That bitmap was a shared buffer in CPU-cached system memory. On an NVIDIA host, atomics there cost about 600 times what they cost in video memory: 1MInterlockedOrto one dword take 18 ms there and 0.03 ms in video memory. The lanes of a pass writing one region all OR the same few dwords.The bitmap now lives in video memory:
shadow::bitmap()makes aDEFAULT-heap UAV buffer (Host::uav_buffer), a mapped read-back buffer (Host::readback_buffer) and an upload buffer of zeros. It also records one list, once, and closes it: a UAV barrier, a copy of the bitmap into the read-back buffer,COPY_SOURCE -> COPY_DEST, and a copy of the zeros over the bitmap.HostList::marks_views, fromdraw.rs).Host::executethen runs that closed list after the submission's lists, andcopy_back_marksreads the marks from the read-back mapping. The CPU no longer clears them.Nothing changes in the translator, so shader cache entries stay valid.
Based on #2175 (
gpu/title-memory-bitmap-in-vram, which did the same for the title memory page bitmaps inmemory.rs). This branch includes its commit, forHost::uav_buffer/Host::readback_bufferand thememory::testsshader helper (nowpub(crate)). Review the second commit only; it rebases trivially once #2175 lands.Verification (Windows 11, NVIDIA RTX 5090)
Live runs on an integration build (this change on top of several open PRs needed to reach the world on a 32-lane host). Diag build, same settings and same 300 s script, averaged over 150–285 s in the world (about 4,900 draws per frame):
GPU and copy-back time are unchanged within noise in this scene. The frame-time difference is in "preparing", the CPU side, which this change does not touch and which varies about as much between runs of identical builds (another build of the same series measured 2.13 fps / 208 ms there). The marks' atomics are evidently not a large share of the GPU time here. With them in video memory they stay cheap where passes mark heavily, as the microbenchmark shows. Stable: no device removal, and world captures look like before.
A first version gave each list its own bitmap (cleared where the list first used it, read back at its end, as #2175 does). It cost about 5 ms more GPU time per frame (an extra barrier inside each list plus two 512 KiB copies per list), so this version uses one bitmap and one fixed list per submission.
cargo clippy -p victory-gpu --all-targets -- -D warnings,cargo clippy -p victory --features diagnostics --all-targets -- -D warnings: cleancargo test -p victory-gpu: 143 passed. Newshadow::tests::view_marks_are_read_back_and_cleared_each_submission: two lists mark from a shader, and both marks are read back; the next submission's read-back holds only its own mark.marked_pages_go_back_by_the_bytes_the_gpu_changednow takes the marks as read back. Two tests fail identically onmainon this host because they assume 2^21 view slots and NVIDIA caps heaps at 1,000,000:memory::tests::lists_share_a_table_and_copies_keep_their_viewsanddescriptor::host::tests::dynamic_slots_are_held_until_released.cargo xtask policy: ok🤖 Generated with Claude Code
Translated shaders mark each page they write through views ("Write marks") with an atomic OR into one bitmap. That bitmap was a shared buffer in CPU-cached system memory, where on an NVIDIA host atomics cost about 600 times what they cost in video memory (1M ORs to one dword: 18 ms against 0.03 ms), and the lanes of a pass writing one region all OR the same few dwords. The bitmap is now a video-memory buffer. A list recorded once and closed copies it into a mapped read-back buffer and clears it (a copy from zeros in upload memory); a submission runs that list after its own lists when one of them binds the bitmap (HostList::marks_views), and the copy-back reads the marks from the read-back buffer. Lists record nothing more, and two runs of one list in a submission both leave their marks. Only the last bit of the bitmap (where marks past it land) is ignored now, not its whole last dword. Co-Authored-By: Claude Opus 5.5 <[email protected]>@kotekompotek on GitHub · 2026-11-25 14:24 UTC · original
Reviewed — this is a real device-removal fix, not just perf: >2 s marking lists trip TDR, and the 600× atomic-write penalty on a shared-heap buffer explains why. Both bitmaps follow the same sound pattern:
takecleared, which only ran if the read-back ran)const— no mutation, so themem::takeclearing is correctly replaced by the GPU zeros copymarks_viewstracking meansmarks_tailis appended only when a marking list ran, socopy_back_marksalways reads a populated read-backword & !(1 << 31)— equivalent on a read-only sliceThe video-memory
view_marks_are_read_back_and_cleared_each_submissiontest exercises the full path on a real device (runs the marking pipeline).@kais7654 on GitHub · 2026-11-25 17:12 UTC · original
Verified on the branch (Windows 11, RTX 5070 Laptop GPU, driver 616.87,
hardware + WARP, rustc 1.98.1,
--locked): merge into current main(
67e8ae1) is clean, clippy-D warningsclean with and without--all-features, and the runs are green on the machines' known anomalies:
victory-gpu lib 143 passed / 2 failed (the two heap-cap tests #1943's
fix owns), victory-shader lib 244 passed / 3 failed (the gathers + 2
stride tests of the NVIDIA HEAP_VIEWS family, #2317). No new failure
against a same-base control.
@Marvisak on GitHub · 2026-11-25 18:20 UTC · original
Automated triage for the maintainers.
Needs rebase. This branch now conflicts with
mainincrates/victory-gpu/src/host.rs,memory.rsandshadow.rs. It will be reviewed once it is rebased and out of draft.Generated by Claude Code
@catminou4 on GitHub · 2026-11-25 14:57 UTC · original · reviewed
Written-pages bitmap moved to video memory (+438). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
@latentdev on GitHub · 2026-11-26 14:46 UTC · original
In the title on an RTX 4090: the bitmap's place was ~90 % of the GPU's time (on a tree with more marks)
A data point where this change matters a lot, plus notes on porting it to current
main.Setup
main63bcca4+ #1630, #1832, #2332, #2178, #2121, #439, #2214, with the structure builder held back.maindoes: #2121's views read through paged heaps set page-read marks in the same bitmap.main)¹ measured with
VICTORY_GPU_TIMING=1, which adds about a quarter here.With the bitmap in system memory,
VICTORY_GPU_TIMINGnamed:deferred_tiled:CS_ResetTilesMask(a7eeed0646be1ab7) at about 1 s per dispatch;With it in video memory, most commands drop to a few milliseconds. One program still runs long in some frames (100 ms to 1 s):
depth_pyramid:CS_InitDepthPyramidWithCpuOcclusion3x3(42683eebec081520), which I'm still looking at. Adding #3102's copies in video memory took the GPU to about 140 ms per frame (numbers on #3102).Porting it to
main63bcca4. Since this PR was written,mainhas made two changes to the bitmap:bitmap(memory); marks of shaders using title memory go back only while not withheld);VIEW_READS,take_reads,forget_read,reads_since).What worked here, keeping all of the CPU-side code:
Bitmapis aDEFAULT-heap UAV buffer (Host::uav_buffer), plus a read-back buffer, an upload buffer of zeros, and one closed tail list (UAV barrier, copy to read-back,COPY_SOURCE -> COPY_DEST, copy of zeros).Host::executeappends both tails to every submission's lists.Bitmap::datanow points at the read-back mapping.take_reads,take_page_reads,copy_back_marksandforget_readthen work unchanged on cached memory.reads_sincecalls. The GPU copy is now cleared after each submission, sotake_readskeeps their union on the CPU forreads_since.I ran it in about fifteen runs of up to 9 minutes. The removals in them were of two kinds, and neither points at this change:
vfx_proj_decal_hit_detectionprograms bind;I can post the patch if it helps the rebase.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.