Skip to content

Use pageable process memory for CPU-only GPU buffer mirrors - #1823

Open
ihyajb wants to merge 3 commits into
trustno1-coder:mainfrom
ihyajb:perf/pageable-card-mirrors
Open

ihyajb wants to merge 3 commits into
trustno1-coder:mainfrom
ihyajb:perf/pageable-card-mirrors

Conversation

@ihyajb

@ihyajb ihyajb commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #1815

What it changes

VICTORY_CARD_CPU_HEAP=1 gives the CPU mirror of a two-sided buffer ordinary pageable Windows memory. The GPU reads the submission’s immutable upload. Single-sided buffers, VICTORY_SEND_OWN=0, and the GPU upload checker retain their shared D3D12 resources. The switch defaults off. If the packed upload cannot be allocated, the fallback snapshots each affected shadow’s dirty ranges and retains those uploads through GPU retirement.

The original design is crossducking’s RAZDA4A-XEN 76b58130, carried by vix0e0e in VIctory-LITE e66dcc25 and adapted by advantyx in VIctyx 7f5497c8. This port adds the fallback and a byte-exact GPU readback regression test.

How it was tested

RTX 5070 12 GB, Windows 11, driver 621.40. The isolated test uses only the GPU library and synthetic data. It allocates eight persistent 32 MiB CPU mirrors, writes every byte, verifies a sentinel in each, and samples the process's DXGI nonlocal usage before allocation and while the mirrors are live. It checks the private-byte accounting again after release. Each measurement runs in a fresh process.

VICTORY_CARD_CPU_HEAP DXGI nonlocal before DXGI nonlocal with mirrors live Increase Private mirror bytes
0 22.96 MiB 284.74 MiB 261.78 MiB 0
1 22.96 MiB 22.96 MiB 0 MiB 256 MiB

Both orders (off/on, on/off) gave identical byte counts. With the switch on, Windows accounts for the mirror as ordinary process memory. The table measures DXGI accounting only.

Gameplay context. In the earlier paired comparison on upstream d4b5d517, both arms used the same 512 MiB upload segmentation. On Series S, 720p scene, DLSS Quality to 1080p, 2× DLSS FG and RT off, DXGI nonlocal usage at the engine's 240-FG-present checkpoint measured 6,540 MiB before and 4,572 MiB after. The two-minute settled samples averaged 26.52 and 27.04 base FPS at 4,172 and 4,131 draws/frame respectively. The evidence supports a shared-memory reduction; FPS remains inconclusive. The separate gameplay A/B on this exact branch stopped during the control run and produced no valid pair.

Reproduce the standalone measurement in PowerShell:

foreach ($setting in @('0','1','1','0')) {
    $env:VICTORY_CARD_CPU_HEAP = $setting
    cargo test --locked -p victory-gpu --lib shadow::land_tests::measure_cpu_mirror_nonlocal_usage -- --exact --ignored --nocapture --test-threads=1
}
Remove-Item Env:VICTORY_CARD_CPU_HEAP
  • Release build and staged asset-policy checks passed.
  • cargo test --locked -p victory-gpu passed (551 passed, 44 ignored). The suite includes a GPU readback of two partial dirty ranges with sentinel bytes between them and a CPU source changed before submission. The ignored DXGI measurement above was explicitly run four times.
  • No shader code changed. Both strict workspace Clippy configurations stop in unchanged victory-shader/src/emit/lower.rs (unused colour, manual checked division). The workspace test run reached the repository policy test, which rejects that same existing file at 667,523 bytes against a 655,360-byte limit.

Checked for overlap

Credit crossducking/RAZDA4A-XEN 76b58130, vix0e0e/VIctory-LITE e66dcc25 and advantyx/VIctyx 7f5497c8. Preserve fallback dirty uploads through retirement and cover them with a GPU readback test.
@github-actions github-actions Bot added memory RAM or VRAM use, out of memory, leaks pr-performance Pull request: makes it faster or use less memory labels Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-performance] [memory] Use pageable process memory for CPU-only GPU buffer mirrors Use pageable process memory for CPU-only GPU buffer mirrors Nov 29, 2026
@ihyajb
ihyajb marked this pull request as ready for review November 29, 2026 00:35
@eleboucher

Copy link
Copy Markdown
Contributor

On a 16 GB PC this PR fixes the shared-memory crash we get with the RT structure builder on.

Setup. RTX 4070 Ti SUPER 16 GB, Ryzen 7 9800X3D, 16 GB RAM, Windows 11 build 26300. Native 1440p, VICTORY_BVH_BUILDER=1 VICTORY_ACTIVATE_RAYS=1, diagnostics build. Base is main f9dfb76 + #1640 + #1700 (builder on 32 lanes), which merges clean with this PR and #477. Windows' shared-memory cap here is 7224 MB.

Without it. Each run of this base died at 2-10 min. Shared GPU memory reached 6.5-7.4 GB of 7224, then either a command list close failed with 0x8007000E or the device was removed. Settings tried without this PR, all with the builder on:

  • VICTORY_WINDOWS_BAR_MB=4608 / 6144, with and without TEXTURE_ROOM_PERCENT: died at 2-3 min.
  • WINDOW_KB=1024 WINDOW_TAILS=1 RT_FAULT_MB=384: died at 3 min.

With VICTORY_CARD_CPU_HEAP=1. The log shows CPU mirrors in pageable process memory private_mib=3483-3726. Shared memory stayed at 3.5-3.8 GB, and every leg was alive at 420 s:

leg 180 s 240 s 300 s 420 s shared
CARD_CPU_HEAP=1 10.8 fps 11.4 7.1 7.2 3.8 GB
+ #477 WINDOW_GROW=1 17.8 18.3 18.2 16.0 3.6 GB
+ RT_FAULT_MB=384 17.0 15.6 17.9 7.7 3.5 GB

Commit. It stays at 32-34 GB (it includes the card's 14 GB) with 0.3-0.5 GB of RAM free. The mirrors still use RAM, but Windows can now trim them instead of failing at the shared cap.

Suggestion. Consider turning this on by default on < 24 GiB hosts, as #1640 does for its caches. A 10-minute pair with captures is queued; I'll add the result.

@eleboucher

Copy link
Copy Markdown
Contributor

The 10-minute pair finished, with captures: same base, VICTORY_CARD_CPU_HEAP=1 VICTORY_WINDOW_GROW=1, RT structure builder on.

start 180 s 300 s 420 s 600 s shared at 600 s
1 14.5 fps 12.3 12.9 13.9 3650 MB
2 12.3 fps 10.3 14.0 9.2 3466 MB
  • Both were alive at 600 s, with 0 device removals and 0 failed list closes.
  • Picture check against the same base without this PR (frames paired by content): 2 of 614 pairs flagged, within our same-build noise. Violet 0.00% in every frame.
  • Now CPU-bound: the submit thread works ~63 ms of a ~80 ms frame.

@upipibi

upipibi commented Nov 29, 2026

Copy link
Copy Markdown

Test report for #1823 (head 6b85f68), merged --no-ff onto main 0338ec6. Synthetic tests only: no title run, no
game files.

Setup: RTX 3070 8 GB, driver 616.56, Windows 11 (10.0.26100), rustc 1.98.1. WARP runs use
VICTORY_D3D12_WARP=1 with --features diagnostics. Every run logged the GPU and driver from nvidia-smi before
it started. A temporary print (not committed) showed the host device on "NVIDIA GeForce RTX 3070" for the hardware
runs and on "Microsoft Basic Render Driver" for the WARP runs.

host::upcheck::tests::private_upload_fallback_snapshots_only_dirty_bytes: 3/3 pass on hardware, 3/3 on WARP.
It reaches the device: it records the fallback's copies into a host list, runs it to the fence, and reads the
destination back.

Negative control: in snapshot_private_ranges, the dirty bytes are not copied into the fallback upload. The test
fails on hardware and on WARP at upcheck.rs:690:

  • got [204, 204, 0, 0, 0, 204, 204, 204, 204, 0, 0, 0, 0, 204, 204, 204];
  • expected [204, 204, 2, 3, 4, 204, 204, 204, 204, 9, 10, 11, 12, 204, 204, 204].

So the test catches a fallback that does not send the CPU's bytes. It also shows that only the two dirty ranges are
written.

shadow::land_tests::measure_cpu_mirror_nonlocal_usage (--ignored, one fresh process per setting, in the
PR's order 0, 1, 1, 0, hardware only):

VICTORY_CARD_CPU_HEAP DXGI nonlocal before With eight 32 MiB mirrors live Increase Private mirror bytes
0 22.77 MiB 284.54 MiB 261.78 MiB 0
1 22.77 MiB 22.77 MiB 0 MiB 256 MiB

Both runs of each setting gave the same bytes. The increase with the switch off and the zero increase with it on
match the PR's table on the RTX 5070 exactly. Only the starting point differs, by 0.19 MiB.

cargo test -p victory-gpu --lib --locked

Run PR Main 0338ec6
default 590 passed, 0 failed, 45 ignored 589 passed, 0 failed, 44 ignored
--features diagnostics 644 passed, 0 failed, 45 ignored 643 passed, 0 failed, 44 ignored

The extra passed test is the upcheck test; the extra ignored one is the measurement. The suites ran with my
temporary probe as one more ignored test; it is subtracted here.

Not tested: the effect in a title.

Tested with the help of Claude Code (Claude Opus 5.5).

@pickles976

Copy link
Copy Markdown

Linux/Wine follow-through on the RTX 4060 Laptop 8 GiB / 16 GiB host: I backported the private-mirror mechanism from 6b85f68d5cc6e014fd5bc878397ae355fdb3017b onto our older rendered Wine-support stack, rather than replacing its renderer with current main. Exact local implementation: 057bdd79, based on Wine PR #1226 plus a separate completed-send-pool cap. This is not an exact-head #1823 test.

Three isolated checks pass on physical NVIDIA hardware, Wine 11 / Linux 6.17 / NVIDIA 590.48.1 / stock assertion-enabled vkd3d-proton 2576c0b4adfae4a:

  • Production private mirror: real title allocation/lookup yields no CPU-side D3D12 resource; 4 MiB private counter rises and returns to zero after release; partial refresh/send GPU readback and untouched sentinels pass (0.85 s).
  • Fallback-copy helper: dirty byte ranges are snapshotted before source mutation; GPU readback preserves those bytes and untouched sentinels (0.59 s). This is not actual packed-upload OOM injection or an end-to-end failed-retirement test.
  • Existing 128 KiB disk-backed alias/GPU-copy fixture still passes all-word checks across three CPU-update/writeback rounds (0.71 s). Native imports of disk-backed title memory remain disabled.

A guarded title observation at 2026-11-29 02:47:08 UTC reached an actual captured cutscene with characters, geometry and colour. The capture remains local. Logical private mirrors reached about 1004 MiB; this is not residency. All 320 independent persistent-NVML memory queries completed, with max native query time 451 ms, and the original nvidia-smi safety guard remained active. The run stopped on global GPU use 6005 MiB at317.53 s, not a telemetry timeout or title crash. Kernel interval had no entries; no cgroup OOM. Minimum available RAM3737.7 MiB, scope peak9216 MiB with452 cap events. Earlier configurations did encounter telemetry deadlines; different input/cache/progress conditions prohibit claiming this patch alone fixed them.

Performance is still poor: eight high-draw host reports had median2.25 FPS/460.1 ms per frame, with253 ms preparing and164.35 ms copying/refreshing101.15 MB. These are overlapping host counters, not GPU timestamps or a matched A/B. Scene-aligned I/O-full pressure remained roughly18–19%; controllable gameplay, native30 FPS and long-run stability are unverified.

Useful implementation detail: this older fork already used CPU WRITE_BACK for shared buffers, so I am not attributing a CPU cache-mode speedup to VirtualAlloc. The current benefit under investigation is ownership/pageability and reduced driver-managed host memory, not disappearance of the mirror bytes. Our next controlled setting is the existing80% texture-admission line, with unchanged resolution, rendering exclusions, native-import prohibition and all safety limits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

memory RAM or VRAM use, out of memory, leaks pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use pageable process memory for CPU-only card buffer mirrors

4 participants