gpu/shadow: opt-in VEH lazy GPU-to-CPU copy-back (4/4 of #51, stable-amd) #190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/190"
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 PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:39:48Z.
Clean port of #59 (part 4/4 of #51) onto origin/stable-amd (
75022ba, Cargo.lock untouched).Supersedes #59.
Verification (clean port on
75022ba)Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-28T19:16:02Z.
I ran the same readback and queue-wait counters in both arms, following the A/B request in #51. The existing 64 MiB compute workload ran for 5 warmup frames and 30 measured frames per arm on Windows WARP. Each wait below is an actual CPU wait on a copy-back fence.
The sparse workload made 20 times as many, smaller waits in lazy mode. Both arms returned the expected CPU-visible checksum of 191,900. The measured byte counts are D3D12 copy sizes. Physical PCIe traffic, hardware wait times and in-game FPS still need the card A/B.
The test-only patch on this head also prints the actual adapter name so testers can distinguish software and hardware captures. Complete four-arm Windows run.
Imported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T00:03:16Z.
Tested
bf931f3withVICTORY_LAZY_COPYBACK=1on my machine, results below in case they help.Ryzen 5 8500G (6C/12T) + RX 6750 XT, 32 GB RAM, Win 11,
--console series-s, no FG. Base is v26.11.6 with PR #26, 4,096 shard locks,VICTORY_ABSENT_CACHE=1, Port 2 (6/6 offsets),VICTORY_LEAN_MATH=247and the 8-prefix filter for the heavy GPU passes (RT, reflections, Strands). No THIN. Same scene (bm-v1), warm cache, 0 pipelines being made. I'm CPU-bound here, GPU is only 4.3–8.7 ms.Cherry-pick only conflicted in two small spots in
watch.rs(uncommitted_stale()andport_descriptors::faulted). No crashes in ~6 min, 0 view records missed on Port 2.Counters: 66 pages armed, 65.5–68.7 steady hits, 0.0 VEH faults, 0.00 MB read back, 22.3–26.5 self-bypassed.
So copying back basically didn't change and copies went up 7–11 ms, ended up ~2 FPS worse for me. What I don't get is why copy-back is still ~24 MB/frame with zero faults and nothing read back. Is that expected? Can grab more logs if you tell me what to look for.
Full breakdown of the setup and measurements: #219
Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-29T01:49:33Z.
@Habluer Yes, those two readings can occur in the same frame. I instrumented this PR's existing mixed-page compute test at
bf931f3and read both counters before the CPU touched either deferred page. Two whole pages were eligible to defer. A pinned page and a half-page boundary were copied back immediately.The existing readback checks then verified the contents of both eager ranges. The frame line counts bytes merged into title memory. That merge can come from a GPU fetch or an already CPU-visible mapping. The lazy line counts the separate on-demand path. Your zero on that line therefore leaves the ~24 MB on the frame line entirely possible.
For your existing diagnostics run, the most useful line from the same interval would be “host copies in the card's memory … pieces compared … fetched (… MB)”. Alongside the frame-line bytes, it would show how much data was fetched by that eager card path. These counters by themselves don't establish the source of the additional 7–11 ms. Instrumented test · Both Windows readbacks.
Imported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T02:08:07Z.
Thanks @HandshakeHackin, that table clears it up completely. Here are the exact lines from the same steady-state (
0 being made) intervals in both runs:PR #190 run (
VICTORY_LAZY_COPYBACK=1,23:19:15.153Z):Diagnostics run without PR #190 (
00:33:25.853Z):So your explanation matches the numbers: in the PR #190 run, eager card fetches were 2.6 MB per frame (vs. 7.6 MB in the diagnostics run), so most of the
24.1 MBon the frame line seems to come from the already CPU-visible merge path rather than card fetches.One thing that stands out between the two:
15291ranges sent up per frame with PR #190 vs.5402without. Not sure if that's related to the extra 7–11 ms incopies, but mentioning it in case it helps. (The second run is the diagnostics build, so it's not a perfectly clean A/B.)Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-29T02:15:39Z.
@Habluer, the upload pattern changed quite a bit in those samples: 22.5 MB across 15,291 ranges averages about 1.47 kB per range on #190, versus 4.66 kB for 25.2 MB across 5,402. The 2.6 MB eager fetch also confirms how little went through that specific readback path in the first sample.
I checked what the upload range count means on this exact PR head. On Windows WARP I staged an identical 4,096-byte payload size two ways. A contiguous range produced one buffer-copy run. Splitting it into 1,024 aligned four-byte writes produced zero buffer-copy runs and 1,024 scatter words. The test verified every staged offset and value. Short aligned runs can share a compute dispatch, so 15,291 input ranges alone doesn’t tell us how many native copy commands ran. Test and readbacks
On this head the submission thread takes and records these sends in
card_before(split 4). The frame line’scopiestimer is charged separately during list preparation. To distinguish extra range-packing work from the extra time incopies, the two lines I’d look for in your existing captures are “bytes of submissions’ own sent up per frame” (copy runs, scatter words, CPU packing time) and, where diagnostics are available, “copies in the card’s memory per frame, the submitting thread” (gathering, packing and recording times). The different builds still leave the cause of the 7–11 ms open. Upload accounting · Submission phasesImported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T02:28:46Z.
@HandshakeHackin, here are the exact lines from those two existing captures, plus the exact 25 s steady-state window ending at each cited tick (all
0 being made).VICTORY_SEND_OWNlogs every ~1 s; thehost copiesand frame/copiessummary lines log every ~5 s, so sample counts are noted.1. PR #190 build (
201321, built without--features diagnostics, so thesubmitting threadbreakdown line is absent)Exact tick (
13.0 fps, 77.1 ms/frame,preparing: 59.1 ms,copies: 27.1 ms 89.7 MB):25 s window ending at that tick (23:18:50–23:19:15Z):
VICTORY_SEND_OWN(n=24, 1 s lines): 234–272 runs, 44,051–91,015 scatter words, 1.23–1.90 ms CPU packinghost copiesranges (n=5, ~5 s lines): 15,291–24,534 rangespreparing: copies(n=5, ~5 s lines): 23.5–29.2 ms2. Diagnostics build (
212623, without PR #190, built with--features diagnostics)Exact tick (
13.2 fps, 75.7 ms/frame,preparing: 53.3 ms,copies: 19.7 ms 94.4 MB):25 s window ending at that tick (00:33:00–00:33:25Z):
VICTORY_SEND_OWN(n=25, 1 s lines): 255–279 runs, 3,506–41,573 scatter words, 1.45–2.50 ms CPU packinghost copiesranges (n=5, ~5 s lines): 2,937–8,084 ranges (the 1 ssubmitting threadline across n=25 spans 1,634–14,793 ranges)preparing: copies(n=5, ~5 s lines): 18.0–22.0 msSummary
Across both 25 s windows,
VICTORY_SEND_OWNCPU packing did not increase on the #190 run (1.23–1.90 ms vs 1.45–2.50 ms), copy runs stayed in the same band (234–272 vs 255–279), and the extra time showed up incopiesduring list preparation (23.5–29.2 ms vs 18.0–22.0 ms). The caveat stands that these are two different builds, and the #190 build had no diagnostics enabled. Let me know if you want a matched A/B on the same build with diagnostics on.Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-29T02:45:14Z.
@Habluer, yes, the matched A/B would help. At the cited ticks, the #190 build packed 47,653 scatter words in 1.29 ms and the comparison build packed 15,384 in 1.47 ms. The extra 7.4 ms on the frame line was in list preparation. Your two 25-second windows also have overlapping packing times and no overlap in the five
preparing: copiessamples. A same-binary comparison can now test whether toggling lazy copy-back changes that separate cost.I built the unchanged PR head
bf931f3with diagnostics. Two separate Windows test processes on that source observed lazy copy-back off at0and on at1. Exact build and switch checks · Windows executable and checksum. Thevictory.exeSHA-256 is722917941CA4016246FBBDBA6B3785EAB78F81A945C0FDA1978885C85B8F779A. Your own diagnostics build of that head also works if you already have one.Use the same executable, warm shader cache, save, camera position and settings for both runs. Restart the process between
VICTORY_LAZY_COPYBACK=0and=1, keepingVICTORY_SEND_OWNand any other switches identical. One comparable 25-second interval with0 being madefrom each log is enough to start. The most helpful extra line this time is “preparing per frame, the submitting thread” for the refreshes, copies and fills, alongside the main frame and lazy copy-back counters. The two run logs are enough; I can line up the intervals.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-29T08:24:47Z.
@Habluer thanks for the careful numbers, and @HandshakeHackin for the same-binary build. for now lazy copy-back stays out of our line: on your 6750 XT it came out about 2 fps lower and nothing has shown it faster yet. thanks @Vladimir-Human for the port all the same, the PR stays open while this is measured.
Habluer, when you do the matched run (same exe,
VICTORY_LAZY_COPYBACK=0then=1), drop the two run logs here and we'll read them tooImported from PastiiJay/klbf-lab. Originally posted by Habluer on 2026-11-29T18:14:03Z.
Thanks for the patience on this one. I reran the A/B cleanly on a single binary, so this replaces my earlier numbers.
Setup: same executable for both arms, same warmed cache (25717 shaders / 3797 early / 8073 warm), isolated save with an identical hash before and after, same input script.
VICTORY_LAZY_COPYBACK=0(A) vs=1(B). In both runs the auto input was never interrupted (AUTO_INPUT_CANCELLED=False, 0 hits), andview records missedstayed at 0.Method: I only counted blocks after
KLBF Lab Bench BM-v1: measuring ... from the first world framethat report0 being made. This drops the menu/loading blocks that would otherwise pull the medians down. That leaves 13 blocks for A and 14 for B.LAZY=0)LAZY=1)Lazy copy-back counters (B): the mechanism is active (median ~91 pages armed, ~34 steady hits per frame), but the VEH path is almost idle: median 0 read/write faults and 0.005 MB read back per frame, with 0 explicit flushes. So in this scenario the copy-back itself still moves ~24 MB per frame in both arms, and I don't see a reduction in
copying backtime.I'm not drawing any FPS conclusion from this run. Arm A has a few multi-hundred-millisecond stalls near the end of the window and I can't explain them, and A ran before B.
Hardware: Windows 11, Ryzen 5 8500G, RX 6750 XT 12 GB.
Based on this, I don't think #190 gives a measurable gain here, so I'd leave it as is. Happy to rerun with the arm order swapped if that would help.
Attachments: the two run logs (A:
LAZY=0, B:LAZY=1). No in-game screenshots.a9v2-arma-20261129-145127.stderr.log
a9v2-armb-20261129-145411.stderr.log
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.