Batch contiguous GPU readback of guest memory #247
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!247
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-247"
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?
@tommiehansen on GitHub · 2026-12-02 20:55 UTC · original
tommiehansen:perf/batch-card-readback→main· +156 −22 · 2 files · 4 commits · merged 2026-12-03 17:15 UTCProblem
The GPU readback path submitted a separate copy and completed a fence for every 4 MiB of title memory read by the host. A streaming burst can therefore serialize texture preparation with many CPU-to-GPU round trips. Existing diagnostics in
pull.rsdocument 20–60 MiB of card-memory reads during frame spikes, although these reads may comprise several textures and the reported spike includes other costs.Change and correctness
Use one contiguous copy up to 16 MiB when a single existing mirror covers the whole group. If growth fails, the extra allocation budget is exhausted, or the larger interval is unavailable, the original 4 MiB progression stays available. A 128 MiB process-wide budget bounds additional readback capacity. The original source interval, destination byte order, copy-queue synchronization and completion-before-CPU-read rule are preserved. Timeout allowance scales with bytes, and source and destination retain their lifetimes when completion cannot be proved. Set
VICTORY_CARD_PULL_BATCH=0to compare with the original grouping.A contiguous 20 MiB read uses two submissions instead of five. A 60 MiB read uses four instead of fifteen. These are command counts, not hardware timings. This helps configurations that run GPU readback; the CPU BAR path is outside the change.
Quantified improvements — submission counts
For contiguous reads covered by a single mirror, when enlarged staging capacity is available:
These are copy submission counts, not reductions in readback bytes, GPU time or whole-frame time. The larger grouping avoids intermediate completion waits; the final completion-before-read requirement is unchanged.
Evidence from related implementations
Upstream #256 reports an RX 7900 XTX workload with CPU card reads at 42–44 MB/s and GPU copies at 75 MB/s, and texture-refresh spikes of 250–820 ms after the previous automatic policy selected CPU reads. Its fence-polling changes reported:
This demonstrates why synchronization overhead matters, but is a different optimization. #256 also reports that automatic GPU copying still disables itself on an RX 9070 XT configuration with faster CPU reads. This PR therefore has no direct benefit where the CPU BAR path is selected.
Why this should be merged
Where GPU readback is active, fewer intermediate submissions and fences can reduce CPU/GPU round trips during large reads. The patch preserves the updated fence-wait policy, bounds extra staging capacity and retains the original progression when batching is unavailable. Test together with #248 (which can remove certain unnecessary reads entirely), measuring remaining readback traffic and frame-time tails rather than assuming additive gains.
Validation
Windows-target
cargo checkpassed with and without diagnostics and with test targets enabled, using a check-only mimalloc override and pure Rust BLAKE3 on macOS. A portable differential test exercised 8,192 randomized source intervals, three enlarged capacities and original mirror-boundary behavior.git diff --checkpassed. Hardware benchmarking was unavailable.Please compare both grouping settings on RX 9060 XT 16 GB at native 1920×1080 and RX 9070 XT at native 2560×1440, with RT enabled, identical settings and no frame generation. Where GPU readback is active, capture readback time, copy-queue occupancy, median and P99 frame time and image parity on a reproducible streaming route. The existing ignored GPU readback test also checks returned bytes against the original data.