Repository navigation
d3d12: exclude write-combined sub-ranges from mixed copy-back (D3D12-WC-SUBRANGE-NO-BACK) - #2795
Conversation
…WC-SUBRANGE-NO-BACK) Register write-combined sub-ranges (`asked & 0x400 != 0`) in `XMemVirtualAlloc`'s `MEM_REPLACE_PLACEHOLDER` path (so split placeholders such as the 32-bit graphics heap's `0x1404`/`0x8404`/ `0x2404` parts are tracked), resolve allocation span on `MEM_RELEASE` (`len == 0`) in `watch::title_memory_freed` so split sub-ranges are forgotten on release, and add opt-in `LEONIDA_WC_SUBRANGE_NO_BACK` (off by default; `LEONIDA_AB`-switchable) in `Shadow::gpu_writes` to subtract qualifying write-combined sub-ranges after `GPU_READ_ONLY` on mixed card copies without hot-path heap allocations.
|
Verified by OreoFR on macOS 27.2.1, Apple M5, head MEASURED
READ IN CODE
ASSUMED
AI-assisted: Claude Code |
|
RUN - independent verification (Verified by OreoFR) - RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 Pro 10.0.26300.
Red / green "Main + only the new tests" does not compile: the tests import
In game. I built a diag
What the copy-back numbers say
Safe to merge into main? Yes, with one note on point 3.
Verdict:
Not covered:
AI-assisted (Claude Code, oreofr-agent). |
|
IN-GAME RUN (gate, independent): #2795 head f85d179, RTX 3090 24 GB, NVIDIA 621.40, Windows 11. Setup: leonida.exe built from this head ( Gate: PASS. No device loss, no gap over 10 s between frames, ended at the time limit: 421 s, world reached at 72 s, so 349 s in the world. One setting differs from the defaults, and why: Median 8.5 fps (p5 5.7), not comparable (see above). Unit tests for this PR were done independently by another verifier on Windows; this comment covers only the in-game gate. Not checked: Series X, walking, picture. |
|
Re-verification on current Head Tests (
No new failure. The one failure is already on main and not from this PR: In-game run on the merged build (
Verdict: no new failure and no device loss on current main + this PR. The remaining blocker is a rule one, not this PR: main is red on the test above until it is fixed or waived; the waiver is written. |
|
Question before merging, from OreoFR (maintainer). AI-assisted (Claude Code agent The description says Could you confirm it is not a real dependency, and if so change that line to something like About the rebase: #2703 (Kal0s-design) and #2569 (adrianmjim) are by other authors, so each of them would rebase their own pull request onto whatever lands first; nothing to do on your side. |
|
Confirmed — neither #2703 nor #2569 is a dependency of this PR:
Updated the description line from |
|
Merging. Head |
Claimed in the coordination issue as: D3D12-WC-SUBRANGE-NO-BACK (#2570 (comment))
Overlaps with: #2703, #2569 (same function
title_memory_freedind3d12/crates/leonida-gpu/src/watch.rs; neither is a dependency — whichever merges later needs a small rebase)What and why
Shadow::gpu_writescurrently only skips write-combined (WC) copy-back when an entire card copy sits inside a registered WC region (LEONIDA_WC_NO_BACK). For mixed reservations split withMEM_REPLACE_PLACEHOLDER— notably the 185 MiB 32-bit graphics heap split across0x1004/0x1404/0x8404/0x2404/0x2004parts — two gaps prevented skipping the0x2404WC sub-range:XMemVirtualAlloc'sMEM_REPLACE_PLACEHOLDERearly-return path registeredGPU_READ_ONLY(0x1000/0x8000) but did not register write-combined (asked & 0x400 != 0) sub-ranges (andwatch::title_memory_freedwithlen == 0onMEM_RELEASEdid not resolve the full allocation span to clear split sub-ranges).Shadow::gpu_writestreated a card copy spanning mixed classes as wholly non-WC rather than subtracting qualifying WC sub-ranges (>= LEONIDA_WC_MIN_BYTES) alongsideGPU_READ_ONLY.Changes:
d3d12/crates/leonida-hle/src/modules/xmem.rs: Registerasked & 0x400 != 0vialeonida_gpu::title_memory_write_combined(and guard both WC and GPU-RO registration with!base.is_null()) in theMEM_REPLACE_PLACEHOLDERpath; addplaceholder_replace_registers_write_combined_and_gpu_read_only.d3d12/crates/leonida-gpu/src/watch.rs: Resolve the allocation span once viaallocation_end(at, at)ontitle_memory_freed(at, 0)(whenat != 0and memory classes are registered), clearing split WC/GPU-RO sub-ranges onMEM_RELEASEand reusing the cached end forforget_views.d3d12/crates/leonida-gpu/src/lib.rs: Re-exporttitle_memory_is_write_combinedandtitle_memory_is_gpu_read_onlyunder#[cfg(windows)].d3d12/crates/leonida-gpu/src/shadow.rs:WRITE_COMBINEDandGPU_READ_ONLYtables (saturating_add), trackANY_WRITE_COMBINED, updateANY_*flags inside write locks on free, and exposehas_memory_classes().Shadow.wcto 4 states (WcKind: unknown / none / whole / partial) soShadow::gpu_writesskips extra work for non-WC and whole-WC copies and preserves standaloneLEONIDA_WC_NO_BACKbehavior.LEONIDA_WC_SUBRANGE_NO_BACK(default off;LEONIDA_AB-switchable; disabled by explicitLEONIDA_WC_NO_BACK=0unlessLEONIDA_ABoverridesLEONIDA_WC_NO_BACK).SmallRangesspilling toVeconly above 4 intervals) subtractingGPU_READ_ONLYfirst (GPU_RO_DECLARED, avoiding double-counting overlaps like0x1404/0x8404) and qualifying>= wc_minWC sub-ranges second (WC_LEFT, lock dropped beforeemit).shadow::write_combined_teststo 7 unit tests covering clipping/merging/minimum-size filtering, mixed GPU-RO + WC subtraction,WcKindclassification,SmallRangesspill, and switch policy.Kept opt-in (
LEONIDA_WC_SUBRANGE_NO_BACK=0by default) pending broader hardware/scene confirmation, since copy-back savings only translate into frame-time gains when relay landing is on the critical path.Tested
Unit tests, checks, and clippy re-run after rebasing onto
main(0b6e0e3bc):python -I scripts/check_no_game_data.pyon all 4 modified files: passcargo test --manifest-path d3d12/Cargo.toml --locked -p leonida-gpu --lib shadow::write_combined_tests: 7 passed, 0 failedcargo test --manifest-path d3d12/Cargo.toml --locked -p leonida-gpu --features diagnostics --lib shadow::write_combined_tests: 7 passed, 0 failedcargo test --manifest-path d3d12/Cargo.toml --locked -p leonida-gpu --lib -- --test-threads=4: 585 passed, 0 failed (52 ignored)cargo test --manifest-path d3d12/Cargo.toml --locked -p leonida-hle --lib: 222 passed, 0 failed (2 ignored)cargo check --manifest-path d3d12/Cargo.toml --locked -p leonida: passcargo clippy --manifest-path d3d12/Cargo.toml --locked -p leonida-hle -p leonida-gpu --features diagnostics --lib --tests: pass (0 warnings in modified lines)Live retail-package runs (Series X profile, 2560x1440, render scale
0.6667, title upscaler,LEONIDA_WC_NO_BACK=1,LEONIDA_RELAY=2,diagprofile withdiagnostics,dlss,mimalloc, run on the same patchset prior to rebasing onto0b6e0e3bc):LEONIDA_AB=4,LEONIDA_WC_SUBRANGE_NO_BACK,LEONIDA_FRAME_GEN=0, 8 min, 0 errors/TDRs):10 MiB 0x1004,1 MiB 0x1404,27 MiB 0x8404,47 MiB 0x2404,100 MiB 0x2004).n=9drift-cancelled triplets): mean-6.41 ± 4.80 ms(8/9), p90-13.59 ± 10.88 ms(8/9), jitter-7.28 ± 6.55 ms, landed new 4 KiB pages-17.4%(1,552 → 1,282), exact sawtooth on 12/12 consecutive phase flips.LEONIDA_AB=4,LEONIDA_WC_SUBRANGE_NO_BACK,LEONIDA_FRAME_GEN=0, 8 min, 56 stationary phases across 5 camera holds, 0 errors/TDRs):OFF n=77/ON n=78):WC_LEFT+1,648 MB/frame(24,225 → 25,873 MB,+6.8%),GPU_RO_DECLAREDunchanged (589.8 → 591.3 MB), landed pieces296.2 → 263.3(-11.1%), landed new 4 KiB pages1,373.7 → 1,122.1(-18.3%,5.37 → 4.38 MB/frame), compare passes439.4 → 432.9(-1.5%), relay landing11.62 → 10.57 ms(-9.0%).n=9draw-locked<=3%drift-cancelled triplets): median-1.06 ± 0.92 ms(57.96 → 57.00 ms, 6/9), mean-0.96 ± 1.11 ms(59.88 → 58.99 ms), p90-2.44 ± 2.52 ms(69.96 → 67.86 ms), submit worked-0.33 ± 0.12 ms(8/9), landed new 4 KiB pages-21.8%(1,679 → 1,313), relay landing-1.54 ms(12.80 → 11.26 ms), compare passes-13.0/frame.n=11draw-locked<=3%triplets): frame time flat (+0.30 ± 0.61 msmedian,+0.43 ± 0.89 msmean; submit worked-0.15 ± 0.14 ms) because the ~10–11 ms relay landing sits behind async submit at ~50 ms/frame.LEONIDA_WC_SUBRANGE_NO_BACK=1,LEONIDA_FRAME_GEN=2, noLEONIDA_AB): 0 errors/TDRs, 2x FG active (status=0,presented=2), reduced copy-back confirmed (290landed pieces /1,293new 4 KiB pages /5.05 MBat median10,188draws), no new visual regressions.GPUs tested: NVIDIA GeForce RTX 4080 Laptop GPU (12 GB VRAM), driver 621.40, Windows 11 (Intel Core Ultra 9 185H, 31.4 GB RAM)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a — D3D12 shadow/HLE change only)