Skip to content

GPU: back shadow buffers, page tables, and dirty bitmaps in VRAM on discrete GPUs - #3312

Open
danielibabet wants to merge 7 commits into
Marvisak:mainfrom
danielibabet:pr/vram-default-buffers
Open

danielibabet wants to merge 7 commits into
Marvisak:mainfrom
danielibabet:pr/vram-default-buffers

Conversation

@danielibabet

Copy link
Copy Markdown

Summary

Addresses part of #3028 on discrete GPUs where GPUUploadHeapSupported is false (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) and Host::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, and InterlockedOr atomic crosses the PCIe bus instead of hitting local GDDR6X / L2.

Changes

  • host.rs:
    • Added Host::is_uma() (D3D12_FEATURE_ARCHITECTURE) and Host::vram_shadow_budget() (25% of local DXGI_MEMORY_SEGMENT_GROUP_LOCAL budget on discrete GPUs so streaming textures are not evicted).
    • Added Host::default_uav_buffer(), reusable 64 MiB UPLOAD ring (upload_vram_copies), and reusable 32 MiB READBACK ring (readback_vram_copies) synchronized via run_copy_list.
  • memory.rs:
    • Backed Shared::table (title-memory page table) and Bitmap (title-memory dirty-page bitmap) with default_uav_buffer on discrete GPUs, synced pre/post submission via CopyBufferRegion.
  • shadow.rs:
    • Backed shadow::bitmap (VIEW_WRITES / VIEW_READS) with default_uav_buffer on discrete GPUs.
    • Backed Shadow allocations (find, loose, Arena) up to vram_shadow_budget() (<= 128 MiB per allocation) in D3D12_HEAP_TYPE_DEFAULT VRAM with demand-committed CpuMem (alloc_zeroed) instead of duplicating L0 D3D12 resources, falling back cleanly to shared_buffer once the VRAM budget is reached or on UMA/WARP adapters.

Measured Results (NVIDIA RTX 4070 12 GB, Windows 11, i9-14900KF)

  • GPU command timing (VICTORY_GPU_TIMING=1) with VRAM-backed shadow buffers + page tables/bitmaps:
    • Total GPU command time: 297.6 ms/frame -> 90.5–91.6 ms/frame (3.25x faster)
    • Top compute shaders in world scenes dropped from 75.81 ms / 30.22 ms / 19.29 ms / 14.26 ms down to < 0.33–1 ms.
  • Pure release runs with bounded 2.5 GB VRAM budget (no texture eviction):
    • 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 require HEAP_VIEWS <= 1_000_000 or 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.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fuzeofficlal 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.

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 0x1337c0de into a VRAM shadow and setting its view_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.

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::WRITE shader storing 0xcafef00d through 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.

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 L1 and L2 are both recorded with memory::bind and submitted separately (host.execute(&[&L1]) then host.execute(&[&L2])), submitting L1 drains L2's bitmap too. When L2 later executes, its VRAM dirty bitmap is never zeroed before L2 and never copied back to RAM after L2, silently dropping both L2's missed-region withholding and its page writebacks.
  • Conversely, if a recorded list is reset/dropped without being executed, ACTIVE_BITMAPS still holds clones of a bitmap already returned to BITMAP_POOL.
  • Reproduced live: recording L1 and L2 (L2 setting region-1 missed bit in map2.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.
  • Fix: associate the (vram, ram) bitmap pair with the specific HostList (Deferred) rather than a global vec, and only zero/read back the bitmaps belonging to runs.

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: calling sh.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 to let mut dummy = 0u64; when self.submitted.try_lock() fails can signal the monotonic self.fence to 1 while the fence is already past 1, causing SetEventOnCompletion(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() calls bitmap(false) and bitmap(true) on every Host::execute, eagerly allocating both bitmaps on the first submission and forcing both upload_vram_copies and a second synchronous readback_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 either OnceLock is 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_shadow checks VRAM_BYTES.load(Relaxed) + size > budget before fetch_add (non-atomic TOCTOU across threads), and if CpuMem::new(size) fails at line 154, VRAM_BYTES is never decremented. Also note Shadow::peek (under diagnostics) still reads self.data without a VRAM readback.

@danielibabet

Copy link
Copy Markdown
Author

Thanks for the thorough review and live RTX 5090 + VICTORY_D3D12_DEBUG=1 repros @fuzeofficlal! Pushed fixes for all four blocking issues and the two notes in fc39e73:

  1. VIEW_WRITES readback before copy_back_marks (shadow.rs, host.rs): added shadow::vram_marked_reads() so after bitmap readbacks, any marked pages belonging to VRAM-backed shadows are copied back to CpuMem in a batch before copy_back_marks runs. Covered by new test shadow::tests::vram_marked_view_writes_go_back_to_title.
  2. Page-table writes readback before defer_after (memory.rs, host.rs): added Deferred::vram_probes / defer_vram_probe so memory::bind collects dirty pages backed by VRAM shadows (without clearing the bitmap) and reads them back to CpuMem before copy_back_page. Covered by new test memory::tests::vram_page_table_writes_go_back_to_title.
  3. Per-list dirty bitmaps instead of global ACTIVE_BITMAPS (memory.rs, host.rs): removed ACTIVE_BITMAPS and stored each list's (vram, ram) bitmap pair in Deferred::vram_bitmaps, so sync_vram_pre / sync_vram_post only zero and read back bitmaps belonging to the executed runs. Covered by new test memory::tests::separate_memory_bind_submissions_keep_their_own_bitmaps.
  4. D3D12 copy allocator lifetime & fence safety (host.rs): upload_vram_copies now waits on the final flush, run_copy_list uses its own dedicated ID3D12Fence and monotonic counter under CMD (avoiding both Reset-while-in-flight and any self.submitted/1 collision from flush_test_vram_uploads), and checks Reset/Close results.
  5. Additional notes:
    • has_vram_bitmaps, sync_bitmaps_pre, and sync_bitmaps_post now use existing_bitmap() (OnceLock::get()) so unused bitmaps are never eagerly initialized.
    • try_vram_shadow now reserves VRAM_BYTES atomically via fetch_update and rolls back on allocation failure in try_vram_shadow / alloc_backing.

Verified locally on Windows 11 x64 (RTX 4070, is_uma() == false) with VICTORY_D3D12_DEBUG=1: all 3 new regression tests + a_submission_that_missed_leaves_the_copies_at_once pass with zero D3D12 debug errors, cargo clippy -p victory-gpu --all-targets -- -D warnings is clean, and cargo xtask policy passes (191 files ok).

@fuzeofficlal fuzeofficlal 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.

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 without Step::GpuWrite): passes on both RTX 5090 and WARP (0x1337c0de reaches title memory).
  • Page-table shader writeback via memory::bind: passes on both RTX 5090 and WARP (0xcafef00d reaches title memory).
  • Separate memory::bind submissions (L1/L2): passes on both (missed_regions_delta = 1).
  • Repeated Shadow::copy + read_host under VICTORY_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) and crates/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:

  1. Host::run_test_copy_sync (crates/victory-gpu/src/host.rs:2989-3005) calls self.run_copy_list(record, None) (releasing the CMD mutex before GPU execution finishes, allowing another thread to reset CMD's allocator while in flight) and then waits on the shared auto-reset self.event (host.rs:3002) without holding self.submitted, violating Host's safety contract (host.rs:69) and racing with Host::execute / run_copy_list (host.rs:3072). Giving CMD its own private event handle created alongside its dedicated fence and having run_test_copy_sync pass Some(0) into run_copy_list keeps allocator reset and wait serialization strictly inside CMD (and avoids re-entrant deadlock on self.submitted when write_host runs inside defer_host).
  2. Host::flush_test_vram_uploads (host.rs:3019-3025) drains global VRAM_UPLOADS and 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 across take_vram_uploads() + upload_vram_copies(...) in flush_test_vram_uploads eliminates this race.
  3. shadow::tests::vram_marked_view_writes_go_back_to_title (shadow.rs:1949) submits via Host::execute while other shadow::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 global BITMAPS via copy_back_marks(...) without serialization, causing intermittent left: 0, right: 322420958 failures in parallel runs. (Also note that vram_marked_view_writes_go_back_to_title uses copy_w.write_host(...), which writes to CPU self.data as well as VRAM, so it would still pass even without VRAM readback; writing only to copy.buffer on the GPU via CopyBufferRegion from an upload buffer makes the regression test strictly exercise vram_marked_reads.)

Minor note (non-blocking)

  • In Host::execute, readback_vram_copies (host.rs:1357) runs before GetDeviceRemovedReason() (host.rs:1380). If the main submission triggers device removal, alloc.Reset().expect(...) inside run_copy_list (host.rs:3061) can panic before Host::execute reaches fail(...) and reports DRED breadcrumbs / removal_data(runs). Moving the GetDeviceRemovedReason() check ahead of the VRAM readback block preserves crash diagnostics.

…map sync, and check device removal before readback
@danielibabet

Copy link
Copy Markdown
Author

Thanks @fuzeofficlal for the detailed review and live RTX 5090 repros! Fixed both blocking issues and the minor note:

  1. VRAM upload after concurrent merge_writeback (crates/victory-gpu/src/shadow.rs):

    • Added self.queue_vram_upload(at as u64, n as u64) right after merge_writeback(title, host, old) + write_mapped in copy_back_or_not.
    • Added self.queue_vram_upload((from - start) as u64, n as u64) in the Some(before) arm of copy_back_marked when merge_writeback writes merged bytes.
  2. Parallel test races (crates/victory-gpu/src/host.rs & shadow.rs):

    • Host::run_copy_list (CMD) now owns a private CreateEventW handle alongside its fence, and Host::run_test_copy_sync calls self.run_copy_list(record, Some(0)) so allocator reset and fence wait stay strictly serialized inside CMD without touching self.event.
    • Serialized Host::flush_test_vram_uploads with a dedicated FLUSH mutex across take_vram_uploads() + upload_vram_copies(...).
    • Serialized the global BITMAPS tests (marked_pages_go_back_by_the_bytes_the_gpu_changed, marks_of_shaders_using_title_memory_are_held_back, vram_marked_view_writes_go_back_to_title) with TEST_BITMAP_LOCK, and updated vram_marked_view_writes_go_back_to_title to write 0x1337_c0de directly to copy.buffer on the GPU via CopyBufferRegion so it strictly exercises vram_marked_reads.
  3. Device-removal diagnostics order (Host::execute):

    • Moved GetDeviceRemovedReason() ahead of the VRAM readback block so fail(...) preserves DRED / removal_data diagnostics instead of panicking inside run_copy_list.

Verified locally on RTX 4070 (Windows 11):

  • cargo test --locked -p victory-gpu --features diagnostics -- shadow::tests:: (parallel, 2 consecutive runs: 10 passed / 0 failed each)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings
  • cargo xtask policy

@neonbyte1

Copy link
Copy Markdown

In-game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with vkd3d-proton, GTA VI's opening yard.

Setup:

ms/frame (min) fps on the GPU preparing copying back
base (2 runs) 553 / 563 (527 / 534) 1.8 438 / 443 63 48 / 49
+ this PR 386 (369) 2.6 245 85 52

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 fc39e73f:

  1. Every submission becomes synchronous once a VRAM bitmap exists. Host::run uploads before and reads back after the lists with run_copy_list(.., wait = true) on the direct queue (host.rs ~2840/2871 and ~2915/2945, called from ~1357/1365; the wait is at ~3038 and ~3066–3072). So the CPU waits for each submission's GPU work: average GPU utilisation fell from 64% to 37% here, and GPU: with VICTORY_GPU_OVERLAP=1, the title's submissions return before the host GPU has run them #3120's overlap stops helping. Completing the read-back on its own fence, for example on the completion thread that already owns in-flight submissions, might give some of that back. I haven't tried that yet.
  2. The 128 MiB cap (shadow.rs ~1294, ~1333) leaves this title's 174 MiB descriptor heap copy in system memory.
  3. Refreshes into VRAM copies go title → CPU mirror → upload ring → GPU copy, so preparing rose from 63 to 85 ms (copies 28 → 32–36 ms).

AI-assisted (Claude); measured on my machine, no game data shared.

@fuzeofficlal fuzeofficlal 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.

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 write 0xdeadbeef at +64):
    written=0, clean=true, next_update=0, title=0xdeadbeef, staging=0xdeadbeef, vram=0x22222222 (stale).
  • copy_back (GPU writes 0xaaaaaaaa at +0 while CPU writes the same 0xaaaaaaaa at +0 and a new 0xcafebabe at +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)
  1. upload_vram_copies and readback_vram_copies lock static RING, clone (ring_buf, ring_ptr), and immediately drop the mutex guard before copying through ring_ptr and submitting CopyBufferRegion.
  2. flush_test_vram_uploads only locks its own static FLUSH and does not acquire self.submitted, so it runs concurrently with Host::execute. That both races on ring_ptr at offset 0 and allows Host::execute to drain VRAM_UPLOADS via take_vram_uploads() while its GPU upload is still in flight; flush_test_vram_uploads then sees an empty queue and returns early before the copy completes, causing subsequent VRAM reads to observe zeros.
  3. TEST_BITMAP_LOCK only covers tests inside shadow.rs, while draw::tests exercises the same global VIEW_WRITES bitmap concurrently via Host::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 (0 vs 0xdeadbeef), 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 (0 vs 9034).

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
@danielibabet

Copy link
Copy Markdown
Author

Thanks @fuzeofficlal for catching both remaining issues! Fixed in HEAD:

  1. merge_writeback returning (title_changed, host_changed) (crates/victory-gpu/src/shadow.rs):

    • merge_writeback now returns (title_changed, host_changed) (tracking host_changed |= prev_host ^ *title_byte before *host_byte = *title_byte).
    • Both copy_back_or_not and copy_back_marked write back to title memory when title_changed is true and call self.queue_vram_upload(...) whenever host_changed is true, preventing stale VRAM when self.data absorbs CPU writes while title itself did not change.
  2. RING, flush_test_vram_uploads, and TEST_BITMAP_LOCK coordination (crates/victory-gpu/src/host.rs, shadow.rs, draw.rs):

    • upload_vram_copies and readback_vram_copies now hold the RING mutex guard for the entire copy + CopyBufferRegion + readback loop.
    • flush_test_vram_uploads now acquires self.submitted before take_vram_uploads() (skipping via thread-local TEST_IN_EXECUTE only when called re-entrantly from Host::execute on the same thread).
    • Added re-entrant lock_test_bitmaps() (TEST_BITMAP_LOCK acquired before self.submitted in Host::execute and in the shadow::tests / draw::tests that mutate/read BITMAPS).

Verified locally on RTX 4070 (Windows 11):

  • cargo test --locked -p victory-gpu --features diagnostics -- --skip dynamic_slots_are_held_until_released --skip lists_share_a_table_and_copies_keep_their_views (2 consecutive parallel runs: 247 passed; 0 failed; 1 ignored; 2 skipped)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings
  • cargo xtask policy (191 files ok)

@fuzeofficlal fuzeofficlal 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.

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:

  1. VRAM writeback merge (crates/victory-gpu/src/shadow.rs:138-153, 616-625, 689-709):

    • Splitting merge_writeback into (title_changed, host_changed) ensures queue_vram_upload runs 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 both copy_back (overlapping identical GPU/CPU byte + concurrent neighbor CPU byte: written = 0, VRAM reads (0xaa, 0xbb)) and copy_back_marked (idempotent GPU write + concurrent CPU byte: VRAM reads (0x22, 0xcc)).
  2. 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 RING mutexes across submission + wait, synchronizing flush_test_vram_uploads with self.submitted (with re-entrant TEST_IN_EXECUTE), and coordinating global VIEW_WRITES bitmaps via lock_test_bitmaps() eliminated all parallel test races.

Checks run:

  • cargo xtask policy — pass
  • cargo 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 diagnostics on 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), and memory::tests (9/9) on RTX 5090 with VICTORY_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.
@neonbyte1

Copy link
Copy Markdown

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 main plus the unmerged PRs this setup needs.

One integration point is missing when a refresh is deferred rather than made where it is asked for. Shadow::copy uploads the refreshed range to VRAM, but #2051's Shadow::copy_queued / Shadow::queued_made do the copy later and upload nothing, and queued_made returns early when the copy has no tracker. A VRAM-backed copy then keeps what the GPU read before the update. With both PRs on, the world's title-written page tables and arguments reached the GPU stale: frames ran 1.0-1.3 s instead of ~0.4 s, the refresh set grew from 137 to 166-226 MB per frame, and the title eventually took an access violation in a DirectStorage inflate writing into a reserved title page.

Fix (in shadow.rs): copy_queued uploads a range it makes at once and remembers a queued one when self.vram || self.tracked.is_some(); queued_made uploads every remembered range before filling armed pages' saved bytes, without the tracker-only early return. Reference: 0b22c702 (on my test stack, so only its shadow.rs hunk applies here), with tests a_deferred_refresh_of_a_vram_copy_is_uploaded_to_vram (device) and a_vram_copy_defers_every_refresh (CPU only; fails without the vram term).

With the hunk, the same build runs the full 600 s without a crash, and both tests plus the other 14 shadow:: tests pass on the GPU. Whichever of this PR and #2051 lands second needs the hunk.

AI-assisted (Claude); measured on my machine, no game data shared.

@neonbyte1

Copy link
Copy Markdown

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 0837b47e, suggest/3312-copies-in-submission — two commits, crates/victory-gpu/src/host.rs only, +298/−112.

Your two new commits and these touch the same functions; both are kept: your CopyCmd with its own event, the RING/submitted holding across the VRAM copy sync, the flush_test_vram_uploads guard, and the device-removal check before the read-back (so a removed device is reported instead of panicking in run_copy_list's allocator reset). Only the wait_fence: Option<u64> parameter became wait: bool, which is all it was ever tested for, and run_test_copy_sync passes true.

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:

  • vram_before, executed as its own ExecuteCommandLists right before the submission's lists: the refreshed ranges through your 64 MiB upload ring, the dirty page tables, the zeroing of the lists' page bitmaps, and — only for a submission that marks — the views' bitmaps RAM → VRAM.
  • vram_after, executed right after the lists and before the submission's Signal: the declared write ranges VRAM → your 32 MiB read-back ring, the lists' page bitmaps VRAM → RAM, and the views' bitmaps back, again for a marking submission.
  • So the one wait the submission already does covers both. vram_ran, after it, copies the ring into the CpuMem mirrors; then, still waited for as before, the pages only the bitmaps name (vram_marked_reads, the probes) and any declared ranges past the ring.
  • Bursts past the ring (a copy made in video memory is filled whole) still go through your waited-for path first.
  • The second commit stops reading back a marked declared range whole (Step::GpuWrite(.., marked, ..) in vram_after). Such a range keeps no snapshot when its copy is tracked (Shadow::writing returns after arming), so copy_back compares nothing in it; its pages already go back by their marks. Reading it back whole as well was 742 MB a frame in Grand Theft Auto VI's world on an RTX 5090, all of it discarded.

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 main, so it is not what this suggestion branch is; this one is the part that stands on its own, and its effect here is ~24 fewer round trips per world frame rather than overlap.

Tests. Wine 11 + vkd3d-proton (GE-Proton11-14) on an RTX 5090, --test-threads=1, suites shadow:: host:: memory::, present tests skipped (they fault in a null read under a headless compositor on every branch and end the test process):

your head 0837b47e this branch 576188a1
passed / failed 50 / 5 52 / 5
failed the same 5 the same 5
  • The two new tests pass: host::vram_around::ranges_take_the_ring_in_order_at_16_byte_offsets (no device) and host::vram_around::vram_writes_go_back_within_and_past_the_readback_ring — two declared ranges of a copy in video memory, written by the list's own commands, one inside the 32 MiB read-back ring and one past it, both in title memory once the submission returns. Your shadow::tests::vram_marked_view_writes_go_back_to_title passes on both heads.
  • The 5 failures are the same list on both heads, so they come from this environment: four memory:: tests whose pipeline Wine's builtin d3dcompiler_47 cannot compile (E5017: not yet implemented feature: Unbounded resource arrays, InterlockedOr is not defined on type RWByteAddressBuffer), and descriptor::host::tests::dynamic_slots_are_held_until_released asserting that the heap vkd3d-proton reports has at least HEAP_VIEWS descriptors. So vram_page_table_writes_go_back_to_title and separate_memory_bind_submissions_keep_their_own_bitmaps are not exercised here; a run on Windows would cover them.

Branch: https://github.com/neonbyte1/VIctory/tree/suggest/3312-copies-in-submission

AI-assisted (Claude); measured on my machine, no game data shared.

@Desamodeth

Copy link
Copy Markdown

Native Windows follow-up to the proposed in-submission copies. Both requested hardware tests pass on the PR head and the proposed tip: vram_page_table_writes_go_back_to_title and separate_memory_bind_submissions_keep_their_own_bitmaps. I made their missing-device/heap paths fail the run. The view-mark test passed on both, and the in-ring/overflow test passed on the 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 Host::execute for 24 submissions.

Writes per submission PR head 0837b47e Fold copies into submission 4b40d5c6 Also skip whole marked ranges 576188a1 Shadow payload read back, head → tip
1 marked page 42.18 ms 40.30 ms 5.64 ms 745.5 → 1.5 MiB
32 marked pages 55.18 ms 53.37 ms 17.50 ms 792 → 48 MiB
Unmarked 1 MiB declaration, 1 page written 8.02 ms 6.25 ms 6.32 ms 24 → 24 MiB

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 failures

Windows, 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 63bcca43, the PR head and the proposed tip: memory::tests::lists_share_a_table_and_copies_keep_their_views (“past the dynamic slots”) and descriptor::host::tests::dynamic_slots_are_held_until_released (heap has fewer than HEAP_VIEWS). Each also failed in isolation. All ten shadow::tests passed on both PR versions.

AI-assisted with Codex Astra 6.2 High.

@danielibabet

Copy link
Copy Markdown
Author

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:

  • \cargo test -p victory-gpu --features diagnostics -j 16 shadow::tests\ (parallel & serial): 10 passed, 0 failed
  • \cargo test -p victory-gpu --features diagnostics -j 16 host::vram_around -- --test-threads=1: 2 passed, 0 failed
  • \cargo test -p victory-gpu --features diagnostics -j 16 host::tests:: -- --skip descriptor::\ (parallel): all passed
  • \cargo clippy -p victory-gpu --all-targets -- -D warnings\ (default & --features diagnostics): clean
  • \cargo xtask policy: 191 files ok

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.

@borosf

borosf commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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
is unusually sensitive to exactly this kind of traffic. It does not survive the menus on Battlemage.

Setup: Windows 11 x64, Intel Arc B580 12 GB (driver default), Ryzen 5 5600, 32 GB, retail 1.0.2.1, my own
dump, --console series-x, diag build, VICTORY_GPU_TIMING=1 VICTORY_D3D12_DRED=1.

Tree: main 63bcca4 + #2958 (already verified separately: world reached, 1298.8 ms/frame, no device
removal in runs of 230 s and 300 s), then this PR's 576188a1 applied on top. Same base commit, so the four
files (host.rs, memory.rs, shadow.rs, draw.rs) applied cleanly with no conflict.

Result, twice:

ERROR victory_gpu::host: host GPU device removed after a submission of 34 lists; page fault at 0x80000ccff000;
      no title memory copy below it; the nearest above: 0xd6263d370
VIctory: host GPU failure: … (run 2: 33 lists, page fault at 0x800002d2f000)
  • run 1: device removed after 12 five-second reports (about a minute in), still menus/loading
  • run 2: device removed after 11 reports, different fault address
  • with this PR reverted and everything else identical: no device removal, both runs reach the world

A fault address with no title memory copy below it reads like a shader reading an address nothing backs, which
is what I would expect if the page table or the dirty bitmap is being read from VRAM while the shader's address
is not mapped there — this PR is the change that moves exactly those structures and adds the 64 MiB upload and
32 MiB readback rings. It could equally be the ring's sync; I have not bisected the four files.

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
failure rather than a speedup. Happy to bisect per-file (or per-switch, if there is one that isolates the VRAM
backing from the rings) and to run it again with VICTORY_D3D12_DEBUG=1 if the extra validation would help
narrow it.

Synthetic runs only beyond the title itself; no game data included.

@danielibabet

Copy link
Copy Markdown
Author

@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 \

@borosf

borosf commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

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
throughout (Arc B580 12 GB, series-x, my own dump, diag, 130-230 s runs, VICTORY_GPU_TIMING=1 +
VICTORY_D3D12_DRED=1 unless noted).

build runs device removals
main 63bcca4 + #2958, this PR not applied 3 1 (16 reports in, page fault at 0x800003d2f000)
main + #2958 + this PR 576188a1 5 5

So the fault also happens without this PR — the same build that had run 230 s clean earlier removed the device
on a later run. What I can say is that it looks far more likely with the PR (5/5 against 1/3), which is a lead,
not a diagnosis. My earlier sentence "with this PR reverted and everything else identical: no device removal,
both runs reach the world" does not hold up: a control run did remove the device. Apologies for the noise.

What the bisect does rule out: I put the PR's two new VRAM substrates behind local switches and ran the
three combinations:

shadow twins (#3312 shadow.rs) bitmap + page table twins (memory.rs) result
on on device removed (12 reports)
off on device removed (11)
on off device removed (18)
off off device removed (11)

So it is not the VRAM-backed shadow buffers and not the VRAM-backed bitmap/page table — with both disabled
almost all of the PR is dormant and it still faults. The fault address is also not inside any of the twins:
they land at 0xffffb802…/0xffffb806…, and every fault I have seen is 0x8000_xxxx_xxxx.

Two other facts that may help whoever owns this:

  • Every fault is a page fault at 0x8000… with no title memory copy below it, after a submission of 33-34
    lists, always before the world is reached.
  • All my runs without VICTORY_D3D12_DRED (i.e. no per-command notes) have been clean; the only runs that
    fault are the ones with DRED's marker commands and per-list timing on. That may be coincidence, but if the
    fault needs DRED to show up, it is a different bug from the one this PR is about, and it would explain why
    it is intermittent.

I am happy to bisect further (per hunk, or with VICTORY_D3D12_DEBUG=1) if that is useful, but I did not want
the earlier "hard failure" claim to stand in the thread. The timings I posted first are unaffected — those runs
completed, and the numbers are medians over their own frame reports.

@Desamodeth

Copy link
Copy Markdown

Native RTX 5070 12 GB, driver 621.40, Series X profile, opening car sequence. Tested 576188a1 against 63bcca43 with #2885, #2958 and the same instrumentation on both sides. Same save and application cache seed, one warm-up per build, then PR/control/control/PR. Each run supplied 98 matched Present intervals after excluding capture frames and their successors.

Control → PR Median frame p95 frame FPS by elapsed time Host submit + wait, median
PR ran first 554.9 → 471.2 ms 991.5 → 962.6 ms 1.74 → 2.01 497.8 → 304.1 ms
Control ran first 486.4 → 357.9 ms 742.8 → 615.1 ms 2.02 → 2.76 508.7 → 345.0 ms

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.

@Desamodeth

Copy link
Copy Markdown

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 HostHeap::evict. The affected draw used live dynamic slots in one run and ordinary title slots 733044–733046 in another (heap title count 934464). #2598 protects the dynamic range. Its live-slot test failed with the old eviction behavior and passed with protection on native D3D12. With #2598 applied, two short scene traces had 54/54 matching SRV checks and no solid green frame through world +8. The ordinary-slot case and whether #3312 changes the likelihood of eviction remain open.

The ordinary slots were evicted about 111 seconds after process start, before the 120-second idle threshold in resource::choose. That narrows this eviction to the local-memory budget path. Three control runs had zero solid-green images in 27 captures over world +0…+8.

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.

@Desamodeth

Copy link
Copy Markdown

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, HostHeap::evict nulled all three ordinary slots, and the same draw had three null bindings at submission. The full captured image was RGB (0, 135, 0). All 21 dynamic SRV checks across those runs retained the expected resource. A separate old-policy control lost three live dynamic slots on its green frame.

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.

@JurajSimicevic

Copy link
Copy Markdown

Native Windows, RTX 5080, on a tree with #439, #2121 and #2958: 576188a takes the frame from 1,743 to 530 ms, and the GPU time from 1,482 to 150 ms.

Method (the same as my rows on #3425):

Frame fps On the GPU Preparing (of it: title copies) Copy-back Draws/frame
Tree above 1,743 ms 0.6 1,482 76 (32 ms, 122 MB) 179 4,941
+ #3312 530 ms 1.9 150 96 (47 ms, 151 MB) 195 4,941

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 main + #2885. On this tree, most of the GPU time went to the shadow buffers, page tables and bitmaps that #3312 moves into video memory. Preparing rises by 20 ms, mostly in title copies (about 30 MB more a frame), and copy-back by 16 ms.

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 vram_page_table_writes_go_back_to_title needs #2121's paged test setup.

576188a merges with #2121 (0bc5edb) with two small conflicts. Both sides are kept: the test bitmap lock in draw.rs, and forget_reads_now next to the VRAM copies in Host::execute. After that, the new test fails on a host that pages its view heap (RTX 5080, and WARP). The title word stays 0x11 instead of 0xcafef00d.

The cause is the test's setup, not the write-back. #2121 extends the shared WRITE test shader:

  • a sixth root constant, paged;
  • the page table at root 4 (SRV(t1, space=2));
  • the view pair's slot taken through that table.

#2121's own tests pass paged, bind the page table, and bind the heap from its start. The new test still binds as on main. With the three changes below it passes on both, and leaving out any one of them still fails:

-        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 63bcca4 + #2121 + #3312, the whole victory-gpu suite with --features diagnostics (RTX 5080, two runs) fails only:

The two descriptor-capacity tests that fail on main on NVIDIA pass there.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants