Skip to content

GPU: in-place guarded writes for write_mapped when VICTORY_COPY_PLAIN=1 (-20 ms copy-back) - #1032

Open
UwUCammie wants to merge 1 commit into
fxceless:mainfrom
UwUCammie:pr/plaincopy-write
Open

UwUCammie wants to merge 1 commit into
fxceless:mainfrom
UwUCammie:pr/plaincopy-write

Conversation

@UwUCammie

Copy link
Copy Markdown

When VICTORY_COPY_PLAIN=1 is on, reads from title memory already run in place via victory_copy_guarded, but write_mapped was still sending every shader-written copy-back chunk through NtWriteVirtualMemory even though watch::writing just opened the guards right before it.

What changed

  • Added a victory_write_guarded twin in plaincopy.rs (rep movsb with WRITE-fault handling in the existing vectored exception handler).
  • host::write_mapped tries plaincopy::write first when VICTORY_COPY_PLAIN=1 (opt-out with VICTORY_WRITE_PLAIN=0) and falls back to the existing NtWriteVirtualMemory / per-page path if any destination page is unmapped or read-only.
  • Added write-back counters to the plaincopy frame line and a unit test (a_readonly_or_unmapped_destination_ends_the_write_without_a_fault) covering writable, uncommitted, and read-only pages.

Tested

  • RX 7900 XT, CachyOS Linux, Wine 11.22 + vkd3d-proton + RADV (VICTORY_LATE_WAIT=3, VICTORY_COPY_PLAIN=1, VICTORY_QUEUE2=1, VICTORY_ASYNC_SUBMIT=1, VICTORY_JOIN_PARTS=1, VICTORY_BACK_OWN_VIEW=1).
  • 540 s gameplay run to frame 4200: 4,250–4,740 writes/frame (61–64 MB/frame) completed in place with 0.0 fallbacks.
  • Copy-back dropped from 49.4 ms to 29.6 ms (~20 ms/frame saved); overall frame time moved from 202–207 ms (4.9–5.0 fps) to 184–186 ms (5.4 fps) with zero visual regressions or faults.
  • plaincopy::tests (5/5) pass under Wine on 465b94f.

ExoCalibra added a commit to ExoCalibra/victory-exo that referenced this pull request Nov 25, 2026
… VICTORY_COPY_PLAIN=1, -20 ms copy-back)
@Xeltax

Xeltax commented Nov 25, 2026 •

Copy link
Copy Markdown

Tested on an RTX 4080 (Windows 11, D3D12, Ryzen 9 9900X), on a branch that is fork main 465b94f plus the BVH builder work from Xeltax/VIcky rt. Same scene every run (no input), builder on, VICTORY_COPY_PLAIN=1 VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_INDIRECT_GATHER=1.

usual frame submit thread at work copy-back
without this PR 260–265 ms 232–240 ms 57–59 ms, 74 MB
with this PR, run 1 228–234 ms 202–217 ms 49–51 ms
with this PR, run 2 231–239 ms 206–215 ms 51–53 ms
  • 741–780 writes back in place a frame (32–35 MB of ~75 MB).
  • No device removal; the picture is unchanged.

So about 11% on the frame here, two runs each.

AI-assisted (Claude Code ran the measurements and wrote this up).

@Ym1r1710

Copy link
Copy Markdown

Tried this on Windows, RTX 5080, on top of ca8829f with COPY_PLAIN=1, RELAY=2, QUEUE2=1, ASYNC_SUBMIT=1 (no JOIN_PARTS / BACK_OWN_VIEW). The new counter stayed at "writes back in place: 0, 0.0 MB, 0.0 fell back" for the whole run and frame time was the same as without it (~122 ms median at world+800). Looks like with these switches the copy-back never reaches write_mapped, it goes through the exact merge in copy_back_with instead. So no gain here, but no harm either, picture unchanged.

@Proudnoob4

Copy link
Copy Markdown

Tested in-game on Windows 10 Pro (22H2), Intel i5-13600K (6P+8E), RTX 4080 16 GB (driver 621.01, Series X profile), 420 s run in the prison cell scene (ca8829f + #1014 + #1015 + #1016 + #1029 + #1032 stacked, compared against our 600 s 465b94f run with the same base switches VICTORY_ASYNC_SUBMIT=1 VICTORY_QUEUE2=1 VICTORY_COPY_PLAIN=1 VICTORY_INDIRECT_WINDOW=1 VICTORY_JOIN_PARTS=1 VICTORY_BACK_OWN_VIEW=1 VICTORY_INDIRECT_GATHER=1 plus VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_GROUP_SYNC=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024).

Windows 10 RTX 4080 measurement with VICTORY_COPY_PLAIN=1 (VICTORY_WRITE_PLAIN default on):

  • writes back in place: 552-576, 22.9-23.5 MB, 0.0 fell back (100% of write_mapped chunks ran in place with zero fallbacks).
  • Note: in this RTX 4080 + VICTORY_RELAY=2 + VICTORY_LATE_WAIT=3 configuration, overall copy-back in ramelog usual frame was 33.8 ms (58.25 MB) vs 32.6 ms (59.20 MB) on 465b94f (so WriteProcessMemory wasn't the bottleneck on Windows 10 here like under Wine, though all writes stayed in place cleanly with

@UwUCammie

Copy link
Copy Markdown
Author

Thanks for testing on Windows everyone!

Good to see 0 fallbacks across all three setups — and interesting how much bigger the win is under Wine (~20 ms) and on Xeltax's setup (~11%) compared to Win10 RELAY=2 where NtWriteVirtualMemory overhead is smaller.

@Ym1r1710 curious why you got 0 there — both copy_back_with and relay_merge/card_merge_relay still call host::write_mapped, and in my RELAY=2 + BACK_OWN_VIEW=1 run here (and Proudnoob4's RELAY=2 run above) it's still doing ~550-650 writes back in place (~23-26 MB/frame) with 0 fallbacks. Worth checking if host.rs had the plaincopy::write line applied or if another switch was bypassing write_mapped?

@Ym1r1710

Copy link
Copy Markdown

Found it, my fault for not saying. My tree also has the #690 exact copy-back on top (VICTORY_EXACT_BACK, on by default there), and with that every merge path returns through putback before it gets to write_mapped. So on plain main it should behave like your runs. I'll try it again without #690 when I get a chance.

Copy link
Copy Markdown

Linux/Proton validation of an adapted d919676 on CachyOS / Ryzen 7 9800X3D / RTX 5090 / NVIDIA 620.73.04 / GE-Proton 11-14.

Local adaptations keep writes explicitly opt-in (both COPY_PLAIN=1 and WRITE_PLAIN=1), handle both source and destination faults, and exercise complete-range fallback after partial copies/remaps. Relevant tests pass in the GPU suite (211 passed, 4 existing runtime failures, 8 ignored).

A synthetic Windows debug-profile test under Proton compares the production helper with NtWriteVirtualMemory: 64 KiB copies, 12 ABBA cycles, 24 samples/path, same stable VirtualAlloc mappings, canaries/readback outside timing. Median guarded/kernel time: hot 64 KiB 553/14,464 ns (26.1x); rotating 16 MiB 2,258/22,972 ns (10.2x). These are cached CPU-copy measurements, not FPS gains or section-view/remap atomicity proof. The benchmark is retained as an ignored test.

The guarded-copy title trial actually exercised write_mapped, with zero reported write fallbacks across its telemetry, normal incomplete visuals and no Xid. It ended after 421.64 s at the same existing title assertion. Scene/cache differences prevent a causal FPS comparison; recent combined trials did show occasional guarded-write fallbacks. Writes remain default-off here.

Source, benchmark and limits: https://github.com/ThomasHFWright/LinVictory/blob/linux-edge/docs/linux-improvements.md
AI-assisted integration/testing with OpenAI Codex; aggregate results only.

@gmankab

gmankab commented Nov 25, 2026 •

Copy link
Copy Markdown

I tested this PR’s d919676c5b775408296cea28489e786c5d5cc78d change on an RX 6800 under Wine and RADV. Both Series S runs used the same integration executable, copies of the same prefix, the same input sequence, and VICTORY_COPY_PLAIN=1 VICTORY_RELAY=2 VICTORY_LATE_WAIT=2. Only VICTORY_WRITE_PLAIN changed.

In the first common 34-second interval after the heavy scene started, there were two host reports per run with at least 1 MB/frame copied back. The median of their copy-back time per MB was 74.46 ms/MB with guarded writes off and 21.49 ms/MB with guarded writes on. The enabled run reported 450–608 direct writes per frame, 15.8–20.2 MB per frame, and 0.0 fallbacks in the qualifying direct-write reports. Draw and copy volumes differed between the runs, so these samples are too small for a sustained performance estimate.

The enabled run hit the title’s known watchdog. The guest deliberately writes to address zero at that site after the main thread stops advancing. Both runs used the default watchdog behavior. Earlier FX and KLBF builds hit the same site before this PR. Watchdog report · Watchdog implementation The disabled run reached the 420-second timeout. The kernel reported no GPU reset. All five plaincopy::tests passed in the same Wine environment.

Tested-on: RX 6800, Xeon E5-2670 v3, Fedora Linux 45 Silverblue, Wine and RADV 26.2.5 in the Victory Flatpak.
Assisted-by: gpt-6.2 sol xhigh

@Filip722

Copy link
Copy Markdown
Contributor

I tested d919676 on a local integration based on upstream dc4c0fc, using Bazzite 44, GE-Proton11-14 and an RTX 5060 Laptop GPU. All six focused plaincopy::tests:: cases passed, including the read-only and unmapped destination test.

With both VICTORY_COPY_PLAIN=1 and VICTORY_WRITE_PLAIN=1, the offline Series S transition reached DXGI Present. A recorded frame issued about 299,000 in-process writes for 2.7 MB with zero fallbacks. The frame still spent about 30 seconds in synchronous copy-back and the title hit its stall watchdog (#416). The render thread ran for 0.34 seconds and the GPU wait was 0.14 seconds for that frame. This confirms the guarded write path was exercised and points to a remaining wait in the copy-back sequence on this setup.

Codex assisted with the integration and tests.

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