Repository navigation
perf(gpu): stop recopying overlapping write snapshots - #436
pragyaangaur merged 2 commits into
Conversation
Port Yumaste’s Marvisak/VIctory#3211 (d5128bce, ebd01cdd) to the Mac tree. Keep the port’s recent-buffer pool, widened views and untracked refresh path. Count moves on growth as snapshot traffic. A 64 MiB growing-range capture on M5 Pro falls from 18.686 to 1.530 ms with the same copy-back result. Co-authored-by: Yumaste <yumaste@outlook.fr>
|
Independent run of the benchmark and the suites on an M5 Pro. MacBook Pro, Apple M5 Pro, 24 GB, macOS 26.6.2, Game Porting Toolkit 4.0 beta 3 (D3DMetal), Wine built by
The growing case is 12.6× faster here, in line with your 12.2× on macOS 27.2.1. The two controls stay within run-to-run spread, though the disjoint case read 3–9% slower in both port runs.
AI-assisted, prepared with Claude Code. |
|
Correction: this PR is not the cause. More runs show the dark first indoor area and grey, ashen skin come and go with the host pipeline library. The dark runs, with or without this PR, each had 35 to 42 frames that dropped work while about 2,000 pipelines were still being made after the library was replaced. The lit runs had 1 to 3. Switching between builds is what emptied the library in my comparison, so the earlier result here was an artifact of how I tested, and I'm sorry for the noise. The likely mechanism: one-time setup work at the start of the scene, probably the lighting, gets dropped because its pipeline isn't ready yet, and the scene stays wrong afterwards. I'll test this PR again with a warm library. Prepared with Claude Code.
In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's current patches, D3DMetal 4.0 beta 3, Series X). Runs with the same opening and the same scripted input, on
The darkness points at write snapshots that come out incomplete. One guess: data written by the GPU into a range that an earlier snapshot already covers, which then never goes back to title memory. If a debug switch or more logging would help, I can run it again. Prepared with Claude Code. |
|
@earpjonathan Thanks for running the control again. The lights returning without #436 is a correctness concern; I would hold this port until we understand it. Nick’s independent benchmark confirms the capture speedup, but neither that benchmark nor our existing byte fixtures tests this lighting pass. I’m not using the removed timing comparison. I’ve started a local control on The old capture code also retained previously captured bytes when a declaration grew, so that fact alone doesn’t explain a difference. I’ll check the fragmented baseline, refresh and copy-back against the old path before proposing a fix. Prepared by GPT-6.2 Astra. |
|
On this M5 Pro (48 GB, macOS 27.2.1, Wine 11.0, mapped D3DMetal 4.0 beta 3), I compared the first indoor room with and without #436. I used Both runs used the same Series X profile and retained caches, 720p, fast heap sync and queue coalescing on, fault tracking and diagnostics on. I checked the release binary against its source tree, checked the mapped graphics runtime, and compared the recorded launch settings. From the initial window I used the same bounded camera and movement holds to frame the blue door and overhead lights. This is a comparison of that room, not a frame-time benchmark. I did not reproduce the missing lights in this pair. All three overhead fixtures and the illuminated wall beside the blue door were visible at both observations on both builds. With no input between observations, the captures were 64 seconds apart on the control and 70 seconds apart with #436. The character remained in shadow in both. For a check beyond visual judgment, I selected three small patches on the first control capture and used the same normalized coordinates in all four captures after checking landmark alignment. Median 8-bit display luma (0–255; not linear scene lighting):
This local pair and the reporter's lit → dark → lit sequence differ. I would keep the report open rather than infer either a general lighting fix or an incomplete snapshot from the timings. Matching the reporter's exact combined revision, nondefault switches, and camera landmark is more useful than another unchanged run here. No game images or raw logs are needed. Prepared and tested by GPT-6.2 Astra. |
Port of Marvisak/VIctory#3211 by Yumaste (
d5128bce,ebd01cdd). Based on macOSbf99e728.Why this matters on the Mac
In a retained M5 Pro Series X opening, the per-shadow diagnostics attributed up to 2,016 MB/frame of snapshot copying to one 64 MiB buffer. A separate 720p run reached 1,035 MB/frame on a buffer of the same size. Those are reporting-interval averages across submissions, not evidence that every copy was redundant. The specific waste we can reproduce is that declaring a write overlapping an earlier one copies the previous snapshot into a new buffer each time the covered range grows.
Change
Keep the bytes in capture order in one pooled buffer. Sorted spans map shadow offsets to those bytes. A declaration adds only missing bytes. Refreshes replace only the captured bytes they intersect. Copy-back compares a contiguous piece directly; it gathers the old bytes of a fragmented piece only if they changed. It still compares each whole 64 KiB piece only once and merges concurrent title writes.
The Mac adaptation uses the port’s sorted, age-trimmed pool and preserves its memory cap, widened-view updates, and tracked/untracked refresh paths.
SnapshotBytesincludes both newly saved bytes and saved bytes moved on pool growth so a reduction is not just a change in the definition of the counter.Synthetic measurement
The first commit is a standalone ignored benchmark that also applies to
bf99e728. The time coversShadow::writingon a mapped D3D12 buffer, not command execution or copy-back. Each iteration changes a byte in the shadow and checks it in title memory after copy-back, outside the timer. M5 Pro / 48 GB, macOS 27.2.1, x86-64 release under Rosetta, private Wine 11.0 with #211, D3DMetal 4.0b3. Median of 9 warm captures after 2 warm-ups per case:The growing case is 12.2× faster in capture. The other two controls stayed close. To reproduce, on each commit run
tools/macos/test-wine.sh --release -p victory-gpu --lib --locked -- --ignored --exact shadow::snapshot_bench::growing_write_ranges --test-threads=1 --nocapture.A separate instrumented run in base → port → port → base order read
SnapshotBytesaround the same calls. On every warm iteration, the growing case copied 816 MiB → 64 MiB (92.2% less). One range copied 64 MiB on both, and the two disjoint ranges copied 32 MiB on both. The growing medians in that order were 17.855, 1.471, 1.514 and 17.238 ms. These are measured bytes, including moves during growth.Tradeoff: a separate deliberately fragmented case declared 512 out-of-order 512-byte stripes across four pages, refreshed part of the buffer halfway through capture, then interleaved synthetic CPU and GPU writes. An independent per-byte model matched all 2,883,584 final bytes checked per tree run (11 submissions). Copy-back of the four changed pages alone took 31.5/31.8 µs on base versus 59.1/69.3 µs on the port. Gathering scattered originals costs time in that shape; the 12.2× result applies only to growing-range capture.
Title smoke: the port reached the changing Series X opening at 720p with the same recorded settings as the control. The visibility watchdog stopped the run at 217 s, after only 8 of the preselected 60 reporting intervals. No comparable frame-rate result or gameplay claim.
Validation
shadow::tests: 34 passed, 0 failed, 4 ignored; the timing fixture then passed explicitly. Tests exercise overlapping and fragmented snapshots, copy-back across fragments, the actual copied-byte counter, and preserving a later CPU write after an untracked refresh crosses a fragment.git diff --check.cargo fmt --all -- --checkflags the same 81 existing files on base and head; both new Rust files pass rustfmt.bf99e728has two native test failures (UAV clear slot addresses and installation progress unregister) and one under Wine (UAV clear slots); the standard suites above use their documented debug profile. No full-release-suite pass is claimed.Prepared and tested with GPT-6.2 Astra. No game data, captures or Apple components are included.