GPU: Speed up shadow buffer writeback merging #2052
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2054"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by GaussianGuaicai on 2026-11-25T04:11:21Z.
Share a branch-free byte merge between the two shadow-buffer writeback paths so the compiler can vectorize the loop. The GPU byte still wins only when it differs from the saved byte; otherwise the guest byte is preserved. The helper reports whether guest memory needs to be written, as before.
Validation
cargo test --locked -p victory-gpu --lib --features diagnostics: 146 passed, 1 failed, 2 ignored. Unmodified base940d32f: 145 passed, 1 failed, 2 ignored. Both failed the same assertion indraw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view.git diff --checkpassed.An earlier diagnostic comparison measured merge cost of 0.392 vs. 0.088 ms/MB. The workloads differed; this measures only the merge step and does not establish an end-to-end frame-time improvement.
Prepared with assistance from GitHub Copilot.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:32Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Shadow buffer writeback merging sped up — perf work on the writeback path; benchmark evidence would help but the change is plausible.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:50:00Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib shadow::— 5 passed, 0 failed (includingwriteback_merge_matches_bytewise_oracle)cargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean fast-path shadow-buffer writeback merging verified against a bytewise oracle. Looks good.
AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by RKouchoo on 2026-11-25T04:19:04Z.
On 7800X3D, #2054 cut a 4 MiB writeback merge from 4.22 ms to 0.34 ms when about one byte in 64 changed. In a separate replay of Story’s buffer-copy workload, #2051 cut the median from 54.1 ms to 30.5 ms.
Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T04:33:21Z.
The 64 KiB piece size used in
shadow.rsshows a clear gain on a Ryzen 7 7435HS. The direction reverses for very short, sparsely changed spans. I compared the merge loop from940d32f6withmerge_writebackfrom857f630on identical synthetic buffers.Each row processes 1 MiB total, split into equal spans. Windows/MSVC, rustc 1.98.1
-O, standalone CPU harness with direct calls. Each range is the min/max of three process medians (30 paired samples per process, alternating order). Buffer resets were outside the timer. Both output buffers and the count of changed spans matched.The four-byte row deliberately calls the merge on every span, including unchanged ones. The saved-page path does that after clipping; the other caller first checks
host != old. Actual clipping frequency, GPU readback and frame time were outside this measurement. AI-assisted.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T04:41:41Z.
Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at
857f630.victory-gpu: 142 passed, 2 failed, 2 ignored; the newwriteback_merge_matches_bytewise_oraclepasses. The 2 failures are #1744's heap-cap failures onmain. Same asmainon this hardware. Not run: a title.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T09:49:21Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, head857f630, Windows 10 x64 19045, NVIDIA GeForce RTX 5060, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib -- --test-threads=1 shadow::tests::— 4 passed, 0 failedcargo test -p victory-gpu --lib -- --test-threads=1 host::tests::— all 6host::tests::*passed (1 unrelated baseline failure on NVIDIA indescriptor::host::tests::dynamic_slots_are_held_until_releaseddue to #1835)cargo clippy -p victory-gpu --all-targets -- -D warnings— 0 warningscargo xtask policy— 182 files okClean optimization to shadow buffer writeback merging.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:23:08Z.
Automated triage for the maintainers.
Merge candidate.
In
crates/victory-gpu/src/shadow.rs, the two copies of the byte-merge loop (incopy_back_or_notand the saved-page path) become one branch-freemerge_writeback. I checked that it does the same thing as the old loop. Where the host byte differs from the snapshot, the title byte takes the host byte; the copy then takes the title byte; it returns true when any title byte changed. The oracle test compares against that rule written out byte by byte, not against the new code. Two people measured it in the thread: about 10x faster on 64 KiB pieces, a little slower on 4-byte spans on the saved-page path.Overlap: #1867 does the same merge with AVX2,
unsafeand an added doc file. This PR is the simpler, portable version of that. #1986 (also marked merge candidate) restructures the same loop incopy_back_or_notto skip withheld ranges, and #1998/#2242 rewrite the copy-back too. Whichever of those lands second will need a rebase. Optional nit: the new test could go in the existing#[cfg(test)] mod testsat the end of the file.CI: passing (
check).Recommending a look, not approving.
Generated by Claude Code