Repository navigation
GPU: opt-in video-memory side for host copies of title buffers - #2705
MrEjecutor wants to merge 4 commits into
Conversation
|
If the card copy-down list fails to reset or close, Could AI-assisted with Codex. |
|
Read the core paths - the design is sound: strict =1 opt-in with a thread-local test override (no env races), cap accounting via reserve/release, the three-ECL split relying on COMMON promotion (legal for buffer copies), copy-down waited on its own fence before CPU copy-back, and download selection keeps the ~800MB/frame whole-range blowup out via marked pages + page-table bits. The negative controls (remove the copy-up -> reads fail, remove copy-down -> writes fail) are the strongest part of the test story. One ordering question: copy_up_cards submits the ECL, then clear_stale() drops the marks for the copied range. If the CPU writes a stale-marked page in the window between ExecuteCommandLists returning and clear_stale running, and the GPU has already executed the copy by then, that write's mark is cleared without its data ever reaching the card side - the page stays stale on the GPU indefinitely (until another write re-marks it). Narrow window, but real: a write to page X after the copy executes and before clear_stale loses both ways. Clearing the marks before recording the copies, or snapshotting the stale set and clearing only what was snapshotted, would close it - worth a thought while this is still opt-in. |
|
@DrDarkDK thanks, agreed: both directions had the same hole. On the regression test: Not tested: an injected failure (no hook yet); AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor. |
|
Thanks. The failure handling you described resolves my concern in both directions. The explicit If you add a regression later, I’d prefer a child-process test that also checks a completion sentinel. The exit status alone can’t show whether the completion write happened before the process exited. AI-assisted with Codex. |
|
@kotekompotek thanks for reading it closely. On the ordering question: writes into a copy's system-memory side run on the submitting thread, under the same lock as the copy-up, so I don't think the window can be hit today; but nothing in the code says so, and the fix is free. @DrDarkDK thanks; noted on the child-process test if I add one. Not tested: a concurrent writer (none exists today); the suite gives the same 193 pass / 2 pre-existing failures, clippy clean on the changed code. AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor. |
|
Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of Verification (
|
|
@fuzeofficlal thank you for running it on the pinned toolchain, on WARP and on a 5090; that covers the two things I could not (rustc 1.98.1, and a card other than mine). On #2120: agreed, a copy whose buffer is already placed in Not tested: #2120 together with this. AI use: Claude Code (Claude Opus 5.5); checked by mrejecutor. |
|
Automated triage for the maintainers. Merge candidate (recommending a look, not an approval). Thanks for the rebase. This adds an opt-in ( It is large (≈925 lines across Generated by Claude Code |
With VICTORY_CARD_COPIES=1, a host copy of a title buffer of at least VICTORY_CARD_COPIES_MIN_MB (1) gets a DEFAULT-heap side that views, root descriptors and title-address page tables use; the system-memory copy stays the CPU's side (`Shadow::data`). Runs of a shared buffer stay single-sided. VICTORY_CARD_COPIES_MB (1024) caps the card sides. A submission runs as three ExecuteCommandLists, so buffers decay to COMMON between them and promote implicitly as before: a copy-up list for every page whose system-memory side is newer (each write into `data` marks its 64 KiB page), the title's lists, then after their fence a copy-down list for the pages that may hold GPU writes (unmarked declared ranges whole, marked ranges by their marked pages, title-memory page table bits), before the CPU copy-back runs unchanged. Off by default; with the switch off nothing changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… title's completion writes copy_up_cards and copy_down_cards return a Result; a list that does not reset or close, a fence that is not signalled or a wait that fails go through fail(), as a removed device does, so neither stale card data reaches title lists nor stale system-memory bytes reach title memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inel Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
185e36f to
7dcc595
Compare
|
Rebased onto
Checked on an RTX 5060 Ti: the 4 card-copy GPU tests pass. The whole AI use: the rebase, the conflict resolution and the checks above were done with Claude Code. |
|
Per-pipeline data from an RTX 4070 SUPER (12 GB, driver 32.0.16.1742, Windows 11 26300, Ryzen 7 7700X), title 1.0.2.1, Series X profile, diag build, 6-minute runs with scripted Enter presses, Tree:
So the passes that move whole buffers gain 10-90x. Most others are unchanged. The ray-march lighting passes ( AI-assisted (Claude Code). Runs done on my machine. |
|
AMD RDNA4 under Wine: card copies off and on, in the title Setup: RX 9070 XT (RDNA4), RADV / Mesa 26.3, Wine 11.22 with vkd3d-proton 3.1-83 from GE-Proton11-14. Diag builds of this PR merged onto
No fault, device loss or kernel message in either run. This is the same picture as your RTX 5060 Ti numbers: the GPU side moves a little and the frame doesn't, because preparing and copy-back run before and after each submission here too. Both runs had the same local changes: queues on a worker thread (local, opt-in), #3071, and a wineserver that keeps memory views in a tree. Merged for Wine: #2913, #2919, #2723, #2977, #2703, #1722, #2101, #2249; and #2644 and #454, their switches on. AI-assisted (Claude Code); numbers from my own runs. |
|
Thanks, that is a useful third card. Taken together for whoever reviews this:
So the PR does what it claims on the GPU side on three vendors and stays off by default, but it does not make frames faster on its own while preparing and copy-back are serial with the submission. That limit is in the description; this confirms it on AMD too. No change planned to the PR from this; it stays rebased on Not tested: overlapping preparing or copy-back with the GPU (a separate change). AI use: this summary was written with Claude Code. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed 7dcc5954 across host.rs, memory.rs, shadow.rs, and switch.rs, and verified cleanly against current origin/main (63bcca43; git merge-tree --write-tree reports zero conflicts).
Lifecycle and synchronization checks look sound:
Shadowfield drop order releasesbufferbefore_budgetreturns bytes toCARD_ALLOCATED; arena slices stay single-sided; all staging-side mutations (copy(), unmapped zero-fills,copy_back_or_not,copy_back_marked,write_host) mark pages stale, andcard_uploads()drains stale marks under a single lock.- Both
shadow::marked_card_pages()andmemory::marked_card_pages()read dirty bitmaps without clearing beforecopy_down_cardsfences, leavingPooledBitmapalive inlist.deferred.afteruntilreset(). - Copy-up/copy-down failures terminate via
fail(...)so stale data cannot silently reach title lists or title memory.
Verified locally on Windows 11 (RTX 5090 + WARP + VICTORY_D3D12_DEBUG=1):
cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean;cargo xtask policy:190 files ok.- Default (opt-in off):
switch::4/4,shadow::10/10, and all 4 newmemory::tests::card_*tests pass on RTX 5090, RTX 5090 + Debug Layer, and WARP + Debug Layer with zero D3D12 Debug Layer errors on the implicitCOMMONtransitions across the threeExecuteCommandListscalls. - With
VICTORY_CARD_COPIES=1(default 1 MiB threshold) +VICTORY_D3D12_DEBUG=1:- RTX 5090:
bindless::3/3,draw::tests::20/20 (includingroot_views_reach_their_copy_and_read_zeros_past_itwith a 4 MiB card-backed source and all 5marked_subpage_uav_*tests),host::tests::+descriptor::host::tests::+pipeline::host::tests::30/31 (only the pre-existing NVIDIA 1M-capdynamic_slots_are_held_until_releasedfailure). - WARP (
--features diagnostics,VICTORY_D3D12_WARP=1):bindless::3/3,draw::tests::20/20,host::tests::+descriptor::host::tests::+pipeline::host::tests::31/31.
- RTX 5090:
- Stress check with
VICTORY_CARD_COPIES=1 VICTORY_CARD_COPIES_MIN_MB=0 VICTORY_D3D12_DEBUG=1(forcing 64 KiB test shadows onto card sides):shadow::10/10,memory::tests::12/12 on WARP (includinga_submission_that_missed_leaves_the_copies_at_onceon both RTX 5090 and WARP), and all 5marked_subpage_uav_*tests pass with zero Debug Layer issues.
Three minor non-blocking follow-ups worth noting:
- Empty
groupsfence gap underVICTORY_GPU_TIMING=1(host.rs:1497-1567): when diagnosticstiming()is active andrunsis empty,groupsis empty (vec![]), socopy_up_cards(&card_uploads)would submitcommands.upwithout a subsequent fence signal/wait beforecard_uploadsdrops and before the nextcommands.up.begin()resets the allocator. Guardingcopy_up_cardson!groups.is_empty()(or skipping card copies whenruns.is_empty()) closes that edge case. - Redundant
live_cards()scans (host.rs:1508-1514, 1648,shadow.rs:829-831):has_cards()locksCARDS, upgrades every weak pointer into aVec, and immediately drops it — running twice per submission even whenVICTORY_CARD_COPIESis off, and twice back-to-back beforecopy_up_cardswhen on. CheckingCARD_ALLOCATED.load(Ordering::Relaxed) != 0inhas_cards()(and callingcard_uploads()directly whenhas_cards()is true without re-scanning) would make the default-off path lock-free and trim a scan per submission when enabled. - Initial
stalebitmap (shadow.rs:375): newly committedDEFAULTbuffers withoutD3D12_HEAP_FLAG_CREATE_NOT_ZEROEDare zero-initialized by D3D12 just likeshared_buffer. Startingstaleasvec, unmapped zero-fills, merges, andwrite_hostall callmark_stale) would avoid an initial full-buffer PCIe upload of untouched zero pages when a large heap gets its card side.
LGTM.
Claimed in #1633; design and the A/B that led to it are in #407.
What
An opt-in video-memory side for host copies of title buffers. Today every copy is one
Host::shared_buffer(custom heap, write-back,MEMORY_POOL_L0), so every shader read of title buffer data crosses PCIe. WithVICTORY_CARD_COPIES=1:VICTORY_CARD_COPIES_MIN_MB(1) gets a DEFAULT-heap buffer that views, root descriptors and title-address page tables use;Shadow::datastays the system-memory side the CPU reads and writes. Runs of a shared buffer stay single-sided (their card side would be the whole shared buffer).VICTORY_CARD_COPIES_MB(1024) caps the card sides; past it a copy stays single-sided.ExecuteCommandLists, so buffers decay to COMMON between them and promote implicitly as they do now: a copy-up list for every 64 KiB page whose system-memory side is newer (every write intodatamarks its page: refreshes, zero fills, copy-back merges,write_host), the title's lists unchanged, then after their fence a copy-down list for the pages that may hold GPU writes (declared unmarked ranges whole, marked ranges by their marked pages, the title-memory page tables' bits), before the CPU copy-back runs unchanged.Why
On the fork
fxceless/victory-fork, which has a similar card side on by default, an RTX 5060 Ti runs a frame in ~315 ms with it and ~2,084 ms without it; the hair strand constraint solvers and the skinning that feeds ray tracing are what slows down without it (#407).Measured here (RTX 5060 Ti 16 GB, driver 621.24, Windows 11 26200)
Tests: four new GPU tests in
memory.rs(a title write reaches a shader through the card side, first and later; a declared GPU write comes back to title memory; a write through the title-memory page table comes back; a page both the title and the GPU wrote is seen whole by the next submission). Negative controls: with the copy-up removed the two read tests fail, with the copy-down removed the three write tests fail.cargo test -p victory-gpu --lib -- --test-threads=1: 193 pass, 2 fail; the same 2 fail on13f91cawithout this change on this card (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views).In the title,
main+ this + GPU: capped view heaps keep the full dynamic range (NVIDIA) #1751 + GPU: refuse typed UAVs in unsupported formats regardless of family or castability #1763 (the stack that boots on NVIDIA here), the three programs of NVIDIA Blackwell (RTX 5060 Ti), 70564ae + #1775 + #1800: three compute programs stall or hang the world; with them skipped it runs 15 min with no device removal (black scene) #1968 skipped (so the world is black and the strand simulation does not run),VICTORY_GPU_TIMING=1, 600–900 s runs:With the world drawn:
main+ this + GPU: capped view heaps keep the full dynamic range (NVIDIA) #1751 + GPU: refuse typed UAVs in unsupported formats regardless of family or castability #1763 + GPU: view addresses for tables made afresh (dynamic slots) #1906 + GPU: an acceleration structure's view address is its location #2098 (the last two merged by hand onto currentmain: its 16-byte view-address entries with GPU: view addresses for tables made afresh (dynamic slots) #1906's dynamic slots and GPU: an acceleration structure's view address is its location #2098'sview_address; their tests adapted to 16 bytes and passing), nothing skipped, the warnings GPU: log title slots past a capped heap once per 64 Ki, not each #1800 rate-limits silenced by log level, one binary, 900 s each, no removal in either:VICTORY_CARD_COPIESunset=1VICTORY_GPU_TIMING)The GPU does a third more draws in less time; the frame barely moves because on
mainthe CPU's preparing and copy-back run before and after each submission, not beside it.Review
@DrDarkDK's point is in
0af0273: a failed copy list or wait ends the run throughfail()before stale data can reach title lists or title memory.Not tested
Other cards; AMD; Linux; a second run of each; the same scene in both runs (draws differ). @desplmfao offered a Linux/NVIDIA run in #407.
AI use: implemented with Codex (gpt-6-luna) from a design reviewed by Codex (gpt-6-sol), then reviewed, fixed, tested and measured with Claude Code (Claude Opus 5.5); checked by mrejecutor. No game data attached.
🤖 Generated with Claude Code