Repository navigation
GPU: back shadow buffers, page tables, and dirty bitmaps in VRAM on discrete GPUs - #3312
danielibabet wants to merge 7 commits into
Conversation
Dukestar69
left a comment
There was a problem hiding this comment.
Reviewed the diff and verified locally on Windows 11 x64 with a discrete NVIDIA RTX 5090 (is_uma() == false, exercising the VRAM-backed shadow buffers, page tables, and dirty bitmaps path):
cargo test -p victory-gpu --lib shadow:: -- --test-threads=1(RTX 5090): 10 passed, 0 failed.cargo test -p victory-gpu --lib memory::tests:: -- --test-threads=1 --skip lists_share_a_table_and_copies_keep_their_views(RTX 5090): 7 passed, 0 failed (pre-existing #1744 test skipped).cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 20 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
Moving hot shadow buffers, page tables, and dirty bitmaps into DEFAULT VRAM on discrete GPUs (!is_uma()) while keeping UMA/APU/WARP on shared memory is a great direction, and the clippy / policy checks and WARP (UMA=true) suite pass cleanly.
Testing on a discrete GPU (NVIDIA GeForce RTX 5090, UMA=false, vram_shadow_budget=8,236,302,336 bytes, VICTORY_D3D12_DEBUG=1) versus WARP (UMA=true) and probing an integrated GPU (AMD Radeon(TM) Graphics, UMA=true) uncovered four blocking correctness/synchronization bugs on the discrete VRAM path:
1. Silent data loss for marked-page UAV writes (VIEW_WRITES) into VRAM shadows (crates/victory-gpu/src/host.rs:1315-1339)
Host::execute only schedules VRAM -> CpuMem readbacks for explicit Step::GpuWrite entries before running shadow::copy_back_marks. Any shader write through a heap/bindless/marked UAV that sets a bit in VIEW_WRITES without a matching Step::GpuWrite leaves Shadow::data (CpuMem) holding the old pre-GPU bytes; Shadow::copy_back_marked then compares stale CpuMem against title memory and writes back zero bytes.
- Reproduced live: dispatching a compute shader writing
0x1337c0deinto a VRAM shadow and setting itsview_writes(false)bit:- RTX 5090 (
is_uma=false):gpu_word=0x1337c0de,title_word=0x00000000(write lost). - WARP (
is_uma=true):gpu_word=0x1337c0de,title_word=0x1337c0de.
- RTX 5090 (
2. Silent data loss for title-memory shader writes via the page table (crates/victory-gpu/src/host.rs:1315-1339, crates/victory-gpu/src/memory.rs:689-691)
Similarly, shaders writing through the title-memory page table mark pages in map.dirty (no Step::GpuWrite), and memory::bind's defer_after closure calls copies[k].copy_back_page(at). Because those dirty pages are never copied back from VRAM into copies[k].data (CpuMem) after sync_vram_post reads back the dirty bitmap, copy_back_page sees unchanged CpuMem and writes nothing to title memory. (Existing test a_submission_that_missed_leaves_the_copies_at_once did not catch this because its non-missed branch only checked GPU-side read(), not CPU title().)
- Reproduced live using the
memory::tests::WRITEshader storing0xcafef00dthrough the page table:- RTX 5090 (
is_uma=false):gpu_word=0xcafef00d,title_word=0x00000000(write lost). - WARP (
is_uma=true):gpu_word=0xcafef00d,title_word=0xcafef00d.
- RTX 5090 (
3. Global ACTIVE_BITMAPS.drain(..) drops dirty/missed bitmaps across separate submissions (crates/victory-gpu/src/memory.rs:205, 239-254, 695-703)
memory::bind pushes (vram, ram) into the process-global ACTIVE_BITMAPS at record time, and sync_vram_post drains the entire vector on whichever Host::execute runs next:
- If lists
L1andL2are both recorded withmemory::bindand submitted separately (host.execute(&[&L1])thenhost.execute(&[&L2])), submittingL1drainsL2's bitmap too. WhenL2later executes, its VRAM dirty bitmap is never zeroed beforeL2and never copied back to RAM afterL2, silently dropping bothL2's missed-region withholding and its page writebacks. - Conversely, if a recorded list is reset/dropped without being executed,
ACTIVE_BITMAPSstill holds clones of a bitmap already returned toBITMAP_POOL. - Reproduced live: recording
L1andL2(L2setting region-1 missed bit inmap2.dirty), then executing[&L1]followed by[&L2]:- RTX 5090 (
is_uma=false):missed_regions_delta=0(L2's miss completely lost). - WARP (
is_uma=true):missed_regions_delta=1.
- RTX 5090 (
- Fix: associate the
(vram, ram)bitmap pair with the specificHostList(Deferred) rather than a global vec, and only zero/read back the bitmaps belonging toruns.
4. ID3D12CommandAllocator::Reset called while previous copy list is still executing (crates/victory-gpu/src/host.rs:2861, 2959-2970, 2983-3017)
upload_vram_copies submits its final flush(..., wait = false) on static CMD's single (alloc, list) without signaling/waiting on a fence, and run_copy_list unconditionally calls let _ = alloc.Reset(); on the next call (also discarding Reset/Close HRESULTs). This immediately violates D3D12 allocator lifetime rules whenever another copy runs before the previous GPU submission finishes (e.g., Shadow::read_host/write_host calling flush_test_vram_uploads() immediately followed by test_readback_buffer/test_upload_buffer, or Host::execute(&[])).
- Reproduced live on RTX 5090 with
VICTORY_D3D12_DEBUG=1: callingsh.copy(...)+sh.read_host(...)produced 16/16 D3D12 Debug Layer errors:
ID3D12CommandAllocator::Reset: A command allocator ... is being reset before previous executions associated with the allocator have completed.(0/16 on WARP). - Relatedly, in
flush_test_vram_uploads(host.rs:2963-2967), falling back tolet mut dummy = 0u64;whenself.submitted.try_lock()fails can signal the monotonicself.fenceto1while the fence is already past1, causingSetEventOnCompletion(1, ...)to return immediately without waiting.
Additional notes
- Unconditional eager bitmap allocation & extra fence wait per submission (
crates/victory-gpu/src/shadow.rs:970-975,host.rs:2798, 2867):has_vram_bitmaps()callsbitmap(false)andbitmap(true)on everyHost::execute, eagerly allocating both bitmaps on the first submission and forcing bothupload_vram_copiesand a second synchronousreadback_vram_copies+ fence wait on every single submission on discrete GPUs even when no shader uses view write marks or VRAM shadows. Consider checking whether eitherOnceLockis actually initialized (and whether the submission used view marks/reads) instead. - Budget accounting race & leak (
crates/victory-gpu/src/shadow.rs:133-157):try_vram_shadowchecksVRAM_BYTES.load(Relaxed) + size > budgetbeforefetch_add(non-atomic TOCTOU across threads), and ifCpuMem::new(size)fails at line 154,VRAM_BYTESis never decremented. Also noteShadow::peek(underdiagnostics) still readsself.datawithout a VRAM readback.
|
Thanks for the thorough review and live RTX 5090 +
Verified locally on Windows 11 x64 (RTX 4070, |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround — I re-verified all four issues from the previous round on a discrete RTX 5090 (is_uma = false) and on WARP (is_uma = true) with VICTORY_D3D12_DEBUG=1:
- Marked-page UAV writeback via
VIEW_WRITES(compute shader writing directly to VRAM withoutStep::GpuWrite): passes on both RTX 5090 and WARP (0x1337c0dereaches title memory). - Page-table shader writeback via
memory::bind: passes on both RTX 5090 and WARP (0xcafef00dreaches title memory). - Separate
memory::bindsubmissions (L1/L2): passes on both (missed_regions_delta = 1). - Repeated
Shadow::copy+read_hostunderVICTORY_D3D12_DEBUG=1: passes on both with zero debug layer errors.
However, discrete-GPU testing uncovered two remaining blocking issues:
1. Concurrent title + GPU writes merged in Shadow::copy_back and Shadow::copy_back_marked never upload the merged bytes back to VRAM
crates/victory-gpu/src/shadow.rs:585-600(copy_back_or_not) andcrates/victory-gpu/src/shadow.rs:659-669(copy_back_marked)
When both the GPU and a title thread write different offsets of the same 64 KiB page during a submission, merge_writeback(...) copies the title's new bytes into CPU self.data (CpuMem) and then t.taken(...) marks the page clean in Tracked. Because self.queue_vram_upload(...) is not called, the VRAM buffer (self.buffer) keeps the stale pre-merge bytes, and subsequent Shadow::refresh / Shadow::update calls return 0 immediately (self.clean() == true), leaving the title's concurrent write permanently invisible to the GPU.
Live reproduction on RTX 5090 (is_uma = false) vs WARP (is_uma = true) — initial page [0x11111111, 0x22222222] (and [0x33333333, 0x44444444]), submission 1 writes word 0 on GPU while the title writes word 1 (0xbbbbbbbb / 0xdddddddd), submission 2 calls refresh and reads both words in a compute shader:
- RTX 5090 (
copy_back):title_after_s1 = [0xaaaaaaaa, 0xbbbbbbbb],clean = true,gpu_saw_s2 = [0xaaaaaaaa, 0x22222222](expected[0xaaaaaaaa, 0xbbbbbbbb]) - RTX 5090 (
copy_back_marked):title_after_s1 = [0x1337c0de, 0xdddddddd],clean = true,gpu_saw_s2 = [0x1337c0de, 0x44444444](expected[0x1337c0de, 0xdddddddd]) - WARP: both return the expected merged words.
Calling self.queue_vram_upload(at as u64, n as u64) right after merge_writeback(title, host, old) in copy_back_or_not and self.queue_vram_upload((from - start) as u64, n as u64) in the Some(before) arm of copy_back_marked resolves both cases (verified live on RTX 5090: both submissions read back [0xaaaaaaaa, 0xbbbbbbbb] and [0x1337c0de, 0xdddddddd]).
2. Existing shadow::tests:: fail under default parallel test execution on discrete GPUs (self.event / CMD / VRAM_UPLOADS / BITMAPS races)
Running cargo test --locked -p victory-gpu --features diagnostics -- shadow::tests:: on RTX 5090 fails 3/3 times (while passing 10/10 on WARP and 10/10 with --test-threads=1):
shadow::tests::bytes_off_the_runtimes_memory_are_copied_at_each_use(shadow.rs:1690):left: [0], right: [4660]shadow::tests::title_writes_under_a_busy_range_are_copied(shadow.rs:1625):left: 0, right: 85
There are three concurrency bugs interacting here:
Host::run_test_copy_sync(crates/victory-gpu/src/host.rs:2989-3005) callsself.run_copy_list(record, None)(releasing theCMDmutex before GPU execution finishes, allowing another thread to resetCMD's allocator while in flight) and then waits on the shared auto-resetself.event(host.rs:3002) without holdingself.submitted, violatingHost's safety contract (host.rs:69) and racing withHost::execute/run_copy_list(host.rs:3072). GivingCMDits own private event handle created alongside its dedicatedfenceand havingrun_test_copy_syncpassSome(0)intorun_copy_listkeeps allocator reset and wait serialization strictly insideCMD(and avoids re-entrant deadlock onself.submittedwhenwrite_hostruns insidedefer_host).Host::flush_test_vram_uploads(host.rs:3019-3025) drains globalVRAM_UPLOADSand flushes without serializing concurrent callers: thread B can drain thread A's pending upload, and thread A then observes an empty queue and reads zeroed VRAM before thread B's copy finishes. Holding a dedicated mutex acrosstake_vram_uploads()+upload_vram_copies(...)inflush_test_vram_uploadseliminates this race.shadow::tests::vram_marked_view_writes_go_back_to_title(shadow.rs:1949) submits viaHost::executewhile othershadow::tests(marked_pages_go_back_by_the_bytes_the_gpu_changed,marks_of_shaders_using_title_memory_are_held_back) concurrently mutate and clear the globalBITMAPSviacopy_back_marks(...)without serialization, causing intermittentleft: 0, right: 322420958failures in parallel runs. (Also note thatvram_marked_view_writes_go_back_to_titleusescopy_w.write_host(...), which writes to CPUself.dataas well as VRAM, so it would still pass even without VRAM readback; writing only tocopy.bufferon the GPU viaCopyBufferRegionfrom an upload buffer makes the regression test strictly exercisevram_marked_reads.)
Minor note (non-blocking)
- In
Host::execute,readback_vram_copies(host.rs:1357) runs beforeGetDeviceRemovedReason()(host.rs:1380). If the main submission triggers device removal,alloc.Reset().expect(...)insiderun_copy_list(host.rs:3061) can panic beforeHost::executereachesfail(...)and reports DRED breadcrumbs /removal_data(runs). Moving theGetDeviceRemovedReason()check ahead of the VRAM readback block preserves crash diagnostics.
…map sync, and check device removal before readback
|
Thanks @fuzeofficlal for the detailed review and live RTX 5090 repros! Fixed both blocking issues and the minor note:
Verified locally on RTX 4070 (Windows 11):
|
|
In-game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with vkd3d-proton, GTA VI's opening yard. Setup:
That's about 31% less frame time, the biggest single gain I've measured here, with no faults or device removal. VRAM peaks at 21.8 GB instead of ~14 GB. Three things I noticed reading it, with line numbers at
AI-assisted (Claude); measured on my machine, no game data shared. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Re-tested 317ea6fb on a discrete GPU (is_uma() == false, VICTORY_D3D12_DEBUG=1) and WARP. The previous fixes for the normal merge_writeback == true upload path, CopyEvent isolation, and standalone shadow::tests parallel execution (5/5 parallel rounds passed 10/10 on discrete GPU with zero D3D12 Debug Layer errors) are working as intended.
However, live discrete-GPU testing uncovered two remaining blocking issues:
1. Permanent silent VRAM data loss when merge_writeback returns false
crates/victory-gpu/src/shadow.rs:27-37(merge_writeback),crates/victory-gpu/src/shadow.rs:585-601(copy_back_or_not),crates/victory-gpu/src/shadow.rs:661-674(copy_back_marked)
merge_writeback(title, host, old) updates *host_byte = *title_byte to absorb concurrent CPU writes into the CPU staging slice (self.data) unconditionally, but its bool return value only reflects whether any byte in title changed (changed != 0). Both copy_back_or_not (line 588) and copy_back_marked (line 668) only call self.queue_vram_upload(...) when merge_writeback returns true, yet both still unconditionally mark the 64 KiB page clean via t.taken(...) right afterward (lines 591/601 and 672-674).
On a discrete GPU (copy.vram == true), whenever CPU staging absorbs CPU writes while merge_writeback returns false, t.taken(...) clears the dirty bit without queueing a VRAM upload, so subsequent Shadow::update() calls return 0 and VRAM permanently retains stale pre-CPU-write data. Reproduced live on discrete hardware (is_uma=false, copy.vram=true):
copy_back_marked(idempotent GPU UAV write marking the page + concurrent CPU write0xdeadbeefat+64):
written=0, clean=true, next_update=0, title=0xdeadbeef, staging=0xdeadbeef, vram=0x22222222(stale).copy_back(GPU writes0xaaaaaaaaat+0while CPU writes the same0xaaaaaaaaat+0and a new0xcafebabeat+64):
written=0, clean=true, next_update=0, title=0xcafebabe, staging=0xcafebabe, vram=0x22222222(stale).
Fix: Have merge_writeback return (title_changed, host_changed) (tracking host_changed |= prev_host ^ *title_byte before writing *host_byte = *title_byte), write back to title memory when title_changed is true, and call self.queue_vram_upload(...) whenever host_changed is true (which also avoids redundant VRAM uploads when only title changed).
2. Unlocked RING buffer and flush_test_vram_uploads / Host::execute concurrency races break parallel victory-gpu tests on discrete GPUs
crates/victory-gpu/src/host.rs:2855-2906(upload_vram_copies),crates/victory-gpu/src/host.rs:2929-2970(readback_vram_copies),crates/victory-gpu/src/host.rs:3007-3015(flush_test_vram_uploads),crates/victory-gpu/src/host.rs:1261-1272(Host::execute)
upload_vram_copiesandreadback_vram_copieslockstatic RING, clone(ring_buf, ring_ptr), and immediately drop the mutex guard before copying throughring_ptrand submittingCopyBufferRegion.flush_test_vram_uploadsonly locks its ownstatic FLUSHand does not acquireself.submitted, so it runs concurrently withHost::execute. That both races onring_ptrat offset0and allowsHost::executeto drainVRAM_UPLOADSviatake_vram_uploads()while its GPU upload is still in flight;flush_test_vram_uploadsthen sees an empty queue and returns early before the copy completes, causing subsequent VRAM reads to observe zeros.TEST_BITMAP_LOCKonly covers tests insideshadow.rs, whiledraw::testsexercises the same globalVIEW_WRITESbitmap concurrently viaHost::execute(sync_bitmaps_pre/copy_back_marks).
Running the full victory-gpu unit suite in parallel on discrete hardware (--features diagnostics, VICTORY_D3D12_DEBUG=1) failed 2/2 runs with zeroed-readback/bitmap failures that all pass serially (--test-threads=1):
- Run 1:
shadow::tests::bytes_off_the_runtimes_memory_are_copied_at_each_use([0]vs[22136]),draw::tests::marked_subpage_uav_writes_copy_back_and_keep_neighbor_bytes(0vs0xdeadbeef),draw::tests::compute_view_marks_rebind_after_depth_twin_conversion(0x0). - Run 2:
shadow::tests::what_a_frame_withholds_leaves_the_copies_at_its_end((0, 0)vs(17, 17)),bindless::tests::heap_views_follow_writes_through_another_mapping(0vs9034).
Fix: Hold the RING mutex guard for the full duration of upload_vram_copies and readback_vram_copies, acquire self.submitted in flush_test_vram_uploads before calling take_vram_uploads(), and coordinate tests that mutate/read the global VIEW_WRITES bitmap across shadow::tests and draw::tests.
…s VRAM copy sync, and coordinate test bitmap lock
|
Thanks @fuzeofficlal for catching both remaining issues! Fixed in
Verified locally on RTX 4070 (Windows 11):
|
fuzeofficlal
left a comment
There was a problem hiding this comment.
Re-verified 0837b47ed0710d23603721878d6d52cd9bca5984 on discrete RTX 5090 (is_uma = false) and WARP with VICTORY_D3D12_DEBUG=1. Both previously reported discrete-GPU blockers are cleanly resolved:
-
VRAM writeback merge (
crates/victory-gpu/src/shadow.rs:138-153, 616-625, 689-709):- Splitting
merge_writebackinto(title_changed, host_changed)ensuresqueue_vram_uploadruns whenever host staging picks up concurrent CPU writes, even when title RAM bytes do not change. - Re-ran live discrete-GPU (
is_uma = false) probes covering bothcopy_back(overlapping identical GPU/CPU byte + concurrent neighbor CPU byte:written = 0, VRAM reads(0xaa, 0xbb)) andcopy_back_marked(idempotent GPU write + concurrent CPU byte: VRAM reads(0x22, 0xcc)).
- Splitting
-
Parallel discrete-GPU synchronization (
crates/victory-gpu/src/host.rs:1174, 2870, 2944, 3022-3034,shadow.rs:108-136,draw.rs:2185, 3316):- Holding the upload/readback
RINGmutexes across submission + wait, synchronizingflush_test_vram_uploadswithself.submitted(with re-entrantTEST_IN_EXECUTE), and coordinating globalVIEW_WRITESbitmaps vialock_test_bitmaps()eliminated all parallel test races.
- Holding the upload/readback
Checks run:
cargo xtask policy— passcargo clippy --tests -p victory-gpu -- -D warnings(default and--features diagnostics) — clean- 5/5 consecutive rounds of default-parallel
cargo test -p victory-gpu --features diagnosticson RTX 5090 (247/247 passed every round, excluding the two pre-existing NVIDIA heap-cap baseline failures) - 3/3 parallel rounds of
shadow::tests(10/10),draw::tests(20/20), andmemory::tests(9/9) on RTX 5090 withVICTORY_D3D12_DEBUG=1— 0 failures, 0 Debug Layer errors - WARP (
VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1):shadow::tests(10/10),draw::tests(20/20),memory::tests(10/10) — all pass with 0 Debug Layer errors.
LGTM!
The uploads of copies in video memory before a submission and their read-back after it were copy lists of their own, each waited for: three waits per submission. They are now lists run in the submission, one executed before its lists and one after them, before its fence value, so the one wait for the submission covers them. The read-back goes through the 32 MiB ring into the mirrors once it has run; the views' written pages and the pages the lists' page bitmaps name, known only from the bitmaps, are read back then, waited for, as before. Uploads and read-backs past their ring still go through it in waited-for passes. run_copy_list takes `wait` instead of a fence value the upload and read-back advanced the submission counter for without signalling it.
A declared range shaders mark keeps no snapshot when its copy is tracked (Shadow::writing): copy_back compares nothing in it, and its pages go back by their marks, which vram_ran reads back. Reading the range back whole as well was 742 MB a frame in Grand Theft Auto VI's world (RTX 5090), all of it unused.
|
Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, with this PR and #2051 both on a stack of One integration point is missing when a refresh is deferred rather than made where it is asked for. Fix (in With the hunk, the same build runs the full 600 s without a crash, and both tests plus the other 14 AI-assisted (Claude); measured on my machine, no game data shared. |
|
Following up on my earlier comment (each submission waits for its own upload and read-back before it can be prepared): here is a branch on your new head Your two new commits and these touch the same functions; both are kept: your What the two commits do. The uploads into copies in video memory and their read-back are no longer copy lists of their own, each with its own fence and wait. Per submission they are two lists of ours, run by the submission:
Why it matters. A submission used to make three round trips on its own GPU work: its lists, the upload before them, the read-back after them. Round trips on a submission's own work cannot be hidden by anything else — whoever prepares the next submission must know the previous one is done. That is precisely what keeps a submission from staying in flight, so removing them is the prerequisite for overlap, not just the saving of the waits themselves. Measured, for context. On my test stack I carry the same in-submission folding on top of an asynchronous submission (a submission stays in flight while the next is prepared): 372 ms → 320 ms per frame on an RTX 5090, GPU time 243 → 179 ms. That branch needs the asynchronous submission, which is not on Tests. Wine 11 + vkd3d-proton (GE-Proton11-14) on an RTX 5090,
Branch: https://github.com/neonbyte1/VIctory/tree/suggest/3312-copies-in-submission AI-assisted (Claude); measured on my machine, no game data shared. |
|
Native Windows follow-up to the proposed in-submission copies. Both requested hardware tests pass on the PR head and the proposed tip: On an RTX 5070, skipping the whole-range readback accounts for most of the saving in a 24-submission replay with sparse GPU writes. Each marked submission declares a 31 MiB VRAM buffer. Times are total wall time inside
The unmarked control still reads back the full declaration. The separate bitmap readbacks totalled another 36 MiB per 24 submissions on all three versions. The two commits are worth taking together on this evidence. Method and remaining failuresWindows, Ryzen 7 9800X3D, RTX 5070 driver 621.40, Rust 1.98.1, release. One real tracked VRAM shadow, a 64 KiB page, a real D3D12 list per submission. GPU copies wrote a changing word to each selected page and set the corresponding view-mark bits on the card. Checked each changed word in title memory as soon as the submission returned and compared the entire 31 MiB backing to an independent expected image after every 24 submissions. Counted bytes at the D3D12 ring and bitmap copy commands. The shadow was already resident; the measured cycles had no shadow payload upload. All six orders of the three binaries, fresh process per version, one warm-up and three measured cycles per case per process. No game FPS inferred. In the wider checks, the same two descriptor-capacity assertions failed on unmodified upstream code at AI-assisted with Codex Astra 6.2 High. |
|
Thank you @neonbyte1 for \suggest/3312-copies-in-submission\ (\4b40d5c\ + \576188a) and @Desamodeth for the native Windows RTX 5070 verification! I've fast-forwarded \pr/vram-default-buffers\ to \576188a\ (retaining @neonbyte1's Git authorship on both commits). Verified on Windows 11 / RTX 4070:
cc @fuzeofficlal — these two commits fold the VRAM upload/readback into the submission's own command lists and skip whole-range readback on marked ranges. |
|
Intel Arc B580: device removed twice within a minute, before the world is reached Tested because the GPU-command claim here (297.6 -> 90.5 ms/frame) is the largest on the board, and this card Setup: Windows 11 x64, Intel Arc B580 12 GB (driver default), Ryzen 5 5600, 32 GB, retail 1.0.2.1, my own Tree: Result, twice:
A fault address with no title memory copy below it reads like a shader reading an address nothing backs, which There are no Intel reports in this thread that I can find, so this is the first: on this card the PR is a hard Synthetic runs only beyond the title itself; no game data included. |
|
@borosf Thank you for testing on Intel Arc B580 and reporting the exact page-fault addresses! Since \576188a\ added the in-submission \�ram_before\ / \�ram_after\ lists on top of \ |
|
Correction to my comment above: I cannot pin this on the PR, and my "reverted, no device removal" line was wrong Following up honestly because I kept digging after posting and the picture is not what I first said. Same setup
So the fault also happens without this PR — the same build that had run 230 s clean earlier removed the device What the bisect does rule out: I put the PR's two new VRAM substrates behind local switches and ran the
So it is not the VRAM-backed shadow buffers and not the VRAM-backed bitmap/page table — with both disabled Two other facts that may help whoever owns this:
I am happy to bisect further (per hunk, or with |
|
Native RTX 5070 12 GB, driver 621.40, Series X profile, opening car sequence. Tested
The median frame improved 15–26%. The direction held when comparing the same elapsed-time window and when restricting to offsets with ≥500 draws in every run. Camera cuts varied across runs. In the 20–48 s window, median DXGI process-local usage rose 1.15–1.28 GB and non-local usage fell 2.77–3.20 GB (decimal). The PR reported about 2.73 GiB allocated for shadows. Both native GPU writeback tests reached their final value checks and passed. Image regression to investigate before merge. Offset +2 after the first ≥500-draw frame was solid green across the entire image (RGB 0,135,0) in both timed PR runs and neither control. A separate pair capturing every frame from +1 through +8 reproduced green at +2 only on the PR. The PR had visible image variation again at +3. This pair was excluded from timing. The cause is still open. |
|
Reproduced the early green frame on a native RTX 5070 (12 GB, driver 621.40). In three traces the video draw's three R8 SRVs pointed to the expected resources when recorded. All three were null at submission on the exact present that turned solid RGB (0, 135, 0). GPU readback shows the video pass produces that color and the final overlay covers an already rendered scene with it. I traced the clear to The ordinary slots were evicted about 111 seconds after process start, before the 120-second idle threshold in In the opening car sequence, repeating A/B/B/A on the original binaries gave median Present intervals of 470.1 → 385.8 ms and 473.0 → 367.5 ms (96 common intervals per run). Timing runs used the same save, cache seed and Series X profile, with per-draw readbacks disabled. Camera and draw counts vary. With #2598 stacked on #3312, a separate A/C/C/A gave 491.4 → 347.8 ms and 470.5 → 442.9 ms (98 common intervals per run). The larger gain came with fewer draws. The closely matched pair averaged 2,415 vs 2,418 draws and improved by 5.9%. All timed runs reached world +144 with successful Presents. Measured with Codex assistance. |
|
Follow-up on the RTX 5070: reproduced the ordinary title-slot case with #2598 active in two of three new opening-scene traces. The three solid-green presents were world +2, +2 and +5. On each one, the video draw's three R8 SRVs matched at recording, The separate timing binary (#3312 + #2598, no per-draw probes) also produced a solid-green image at world +2 on its first rerun. Both affected instrumented runs reached the flash within 45 seconds of process start, before the 120-second idle threshold. The remaining fix needs to preserve the recorded draw's ordinary SRVs during budget eviction while allowing legitimate title rewrites. AI-assisted with Codex. |
|
Native Windows, RTX 5080, on a tree with #439, #2121 and #2958: Method (the same as my rows on #3425):
The draw count is the same, so the GPU does the same work about 10 times faster. That is much more than the 15-26% Desamodeth measured on No device errors or alerts in about 10 minutes in the world. The image looks as it did before. I didn't see a solid-green frame, but I didn't capture frame by frame. For whichever of #3312 and #2121 lands second: the new
The cause is the test's setup, not the write-back. #2121 extends the shared
#2121's own tests pass - let constants = [at as u32, (at >> 32) as u32, 0xcafe_f00d, 0, 0];
+ let paged = u32::from(crate::descriptor::view_pages());
+ let constants = [at as u32, (at >> 32) as u32, 0xcafe_f00d, 0, 0, paged];
// SAFETY: open list with live test pipeline and heaps.
unsafe {
list.list.SetDescriptorHeaps(&[Some(views.heap.clone())]);
list.list.SetComputeRootSignature(&write_root);
- list.list.SetComputeRootDescriptorTable(0, views.gpu(0));
+ // The whole host heap, as translated shaders index it.
+ let start = views.heap.GetGPUDescriptorHandleForHeapStart();
+ list.list.SetComputeRootDescriptorTable(0, start);
list.list.SetComputeRootShaderResourceView(1, map.table);
list.list.SetComputeRootUnorderedAccessView(2, map.dirty);
list.list.SetComputeRoot32BitConstants(3, constants.len() as u32, constants.as_ptr().cast(), 0);
+ let strides = views.strides().unwrap().GetGPUVirtualAddress();
+ list.list.SetComputeRootShaderResourceView(4, strides);
list.list.SetPipelineState(&writer);With that change, on
The two descriptor-capacity tests that fail on AI-assisted. |
Summary
Addresses part of #3028 on discrete GPUs where
GPUUploadHeapSupportedisfalse(e.g., NVIDIA RTX 4070 / Ada Lovelace without ReBAR enabled).Root Cause
On discrete GPUs without
GPUUploadHeapSupported,Host::shared_buffer(D3D12_HEAP_TYPE_CUSTOM,WRITE_BACK,MEMORY_POOL_L0) andHost::upload_buffer(MEMORY_POOL_L0) place all shadow buffers, title-memory page tables, and atomic dirty-page bitmaps in system RAM over PCIe. Every shader buffer load, UAV store, page-table lookup, andInterlockedOratomic crosses the PCIe bus instead of hitting local GDDR6X / L2.Changes
host.rs:Host::is_uma()(D3D12_FEATURE_ARCHITECTURE) andHost::vram_shadow_budget()(25% of localDXGI_MEMORY_SEGMENT_GROUP_LOCALbudget on discrete GPUs so streaming textures are not evicted).Host::default_uav_buffer(), reusable 64 MiBUPLOADring (upload_vram_copies), and reusable 32 MiBREADBACKring (readback_vram_copies) synchronized viarun_copy_list.memory.rs:Shared::table(title-memory page table) andBitmap(title-memory dirty-page bitmap) withdefault_uav_bufferon discrete GPUs, synced pre/post submission viaCopyBufferRegion.shadow.rs:shadow::bitmap(VIEW_WRITES/VIEW_READS) withdefault_uav_bufferon discrete GPUs.Shadowallocations (find,loose,Arena) up tovram_shadow_budget()(<= 128 MiBper allocation) inD3D12_HEAP_TYPE_DEFAULTVRAM with demand-committedCpuMem(alloc_zeroed) instead of duplicatingL0D3D12 resources, falling back cleanly toshared_bufferonce the VRAM budget is reached or on UMA/WARP adapters.Measured Results (NVIDIA RTX 4070 12 GB, Windows 11, i9-14900KF)
VICTORY_GPU_TIMING=1) with VRAM-backed shadow buffers + page tables/bitmaps:on the GPU(5.1k–5.3k draws/frame): ~405–417 ms -> ~285–323 ms (total frame time ~545 ms -> ~440 ms).Verification
cargo test -p victory-gpu --locked -- --test-threads=1 --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views: 229 passed, 0 failed (the 2 skipped tests requireHEAP_VIEWS <= 1_000_000or WARP on this NVIDIA driver; tested separately on WARP in PR GPU: track dynamic descriptor slots in a 64-bit word bitmap #3218).cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings.cargo run -p xtask --locked -- policy: asset policy: 191 files ok.