hle/xmem: prefer mappable 128 GiB GPU directory range for graphics reservations (D3D12-XMEM-GRAPHICS-37BIT) #2856
Closed
leonida/mandy
djrolfes wants to merge 0 commits from
djrolfes/xmem-128gib-gpu-dir into main
pull from: djrolfes/xmem-128gib-gpu-dir
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2856
Loading…
Reference in a new issue
No description provided.
Delete branch "djrolfes/xmem-128gib-gpu-dir"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as:
D3D12-XMEM-GRAPHICS-37BIT(claim comment; coordinated withzmasi's queuedD3D12-RT-FG-ARENA-VA-STORMin#2570#issuecomment-7237954231)What and why
Prefer the GPU's mappable raw-address page directory range (
[4 GiB, 128 GiB - 64 KiB), i.e.[0x1_0000_0000, 0x1F_FFFF_0000)) whenXMemVirtualAllocreserves graphics memory (flags & 2 != 0), with transparent fallback to the wider console range (address_range(flags)) if the directory window cannot satisfy the reservation.main,XMemVirtualAllocconstrainsGRAPHICSreservations only to the full console range ([4 GiB, 1 TiB)or up to 46-bit when the bit-12 field is set). Under ASLR, large heaps, or RT/BVH reservations, allocations can land above the GPU's 37-bit raw-address page directory and silently lose raw-address coverage — without widening the directory (which would invalidate translated shaders).MEMORY_PAGES = 1 << 21entries (128 GiB), and reserves the final entryMEMORY_PAGES - 1(0x1F_FFFF,[0x1F_FFFF_0000, 0x20_0000_0000)) as the permanently empty out-of-range sentinel (leonida-gpu/src/memory.rs:295,354,627,leonida-shader/src/emit/lower.rs:4781).GPU_DIRECTORY_ENDis therefore(1usize << 37) - (64 * 1024)(0x1F_FFFF_0000), cappingHighestEndingAddressatGPU_DIRECTORY_END - 1(0x1F_FFFE_FFFF, preserving WindowsMEM_ADDRESS_REQUIREMENTS's64 KiB - 1alignment contract) and checkingend <= GPU_DIRECTORY_ENDfordirectory_covered.flags & 2 == 0) and 32-bit reservations (ADDRESS_32BIT) keep their existing ranges unchanged. If the initial 37-bitVirtualAlloc2fails for aGRAPHICSreservation,XMemVirtualAlloclogs atracing::warn!and retries with the fulladdress_range(flags)upper bound so legal console allocations never fail with OOM. Successful graphics reservations log attracing::debug!so default logs stay quiet.d3d12/crates/leonida-hle/src/modules/xmem.rs,d3d12/crates/leonida-gpu/src/memory.rs:295,d3d12/crates/leonida-shader/src/emit/lower.rs:4781) + unit-tested under Wine (VirtualAlloc2MEM_TOP_DOWNand 128 GiB fallback) + MEASURED 300 s in-game gate on exact PR head05ca84aee.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-hle/src/modules/xmem.rs→ exit 0.leonida-hletest binary (x86_64-pc-windows-msvc) and ran under Wine:origin/main(501b3e6c5) (only the new tests applied, no production change):05ca84aee(rebased ontocd73ddab7):docs/game_gate.md) on exact PR head05ca84aee(leonida.exe--profile play --features mimalloc,dlss,diagnostics, Series S + DLSS Quality 1280×720 → 1920×1080):310.19 s(world_at_s = 77.33 s,>= 300 srequired)world + 60 sto stop):2,935presented frames (3,031total world presents),15.06median FPS,116.67 msp95 frame time (15.43end-window median FPS,4,356median draws/frame)3.723 s(<= 10.0 srequired)6,707 MiB(<= 7,400 MiBguard)0device losses,0crashes/faults,0panics,0kernelNVRM: XiderrorsGPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (initial prototype by GPT-6.1-Sol / Codex; implementation and sentinel-page refinement by Gemini 4 Neon; audited and approved in a separate independent review pass by Gemini 4 Neon).
Checklist
main(cd73ddab7) and merges cleanly.check_no_game_data.pyclean).docs/design.md(n/a — HLE memory reservation change, no translator rule).05ca84aee).Verified on Windows: the crate is green with it, and it adds two tests - measured against
main's own file.main3393ceec9, cherry-picked (one commit),cargo 1.98.1:That is an existence control, not a mutation one - I did not remove the preference to watch a specific test fail, because the two that come with it are the ones that would.
And the file it changes is the one I have watched most today: #2836 (
arrange forgets the slice a page leaves) went in this morning and #2856 now makes the 128 GiB GPU directory range mappable. The 241 existing tests absorbed both.What I could not test: what "prefer a mappable range" does to a title's memory - that needs the game and a driver that reports both.
AI-assisted: yes - DeepSeek v4.1 (flash), both arms on the machine above.
Written with an AI assistant.
Verified by MoonEyes (another person than the author) on head
05ca84aeemerged withmaincd0c52fcf: I read the whole diff.cargo test -p leonida-hle: 245 passed, 0 failed. Withhighest.min(GPU_DIRECTORY_END - 1)put back tohighest,graphics_reservations_prefer_the_gpu_directoryfails.In-game run with the six others of a batch on
main21e6bbf4b: RTX 4060 8 GB, NVIDIA 610.88, Windows 11 26300,-SeriesS -FrameGen 2, about 860 s in the world, then a second one of about 440 s, 0 device lost, 0 panic; pictures of the same scene compared withmain, same. Black surfaces in early cutscenes while the PC's memory is full are there on plainmaintoo. No "37-bit reservation refused" line in either run.AI-assisted (Claude Code).
I ran a forced 128 GiB fallback check with 05ca84ae merged into edf7d01f8 (Win64 MSVC target, Rust 1.98.1, Wine 11.22). The xmem tests reported 26 passed and one ignored, including both new tests. The top-down test exercises all eight graphics flags, the 32-bit controls and the CPU-only reservation. The large fallback test reserves virtual address space without committing physical memory.
For a negative control I disabled only the wider retry and kept the 37-bit preference. The 64 KiB top-down graphics test still passed, while the 128 GiB case failed with console-range fallback failed. This directly checks that the retry is required, independently of the preference check. MEASURED with synthetic VA reservations. AI-assisted (Codex).
RUN (independent native Windows 10 unit + in-world verification,
#2856head05ca84aeemerged ontomain0ff8a532f):cargo test --locked -p leonida-hle --lib xmem):26 passed, 0 failed, 1 ignored(0.56 s).Series S,-NoFrameGen,diagnostics,dlss,mimalloc,268.4 sruntime after precompile):playcleanly (48frame lines,10in-world samples>= 1000draws/frame,2,543median /4,216max draws/frame, median16.1 fps/62.0 ms,0.0 msGPU wait).0ERROR lines,0device-lost events across27,874log lines.621.40, Windows 10 Pro 22H2 build 19045, Ryzen 9 5950X 16C/32T).MEASURED. AI-assisted: Antigravity.
VERIFY-2856 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files
Verdict: PASS. The repository's own red/green idea holds under Wine: the new test fails on the merge base and passes with the pull request, nothing that worked before is broken, and the arithmetic of the new bound is right.
Head
05ca84ae, base the currentmain, merge basecd73ddab, 1 file, +109/−2:d3d12/crates/leonida-hle/src/modules/xmem.rs.1. What it changes
XMemVirtualAllocasked the Windows loader for the console's address range (up to 40 or 47 bits). The GPU's mappable directory is a range of 64 KiB pages,[4 GiB, 128 GiB − 64 KiB), with the last page reserved as the empty out-of-range sentinel — and the title's graphics allocations have to land inside it, because expanding the directory would change every shader's bounds and invalidate the translations. The change caps a graphics reservation at that directory and falls back to the console's wider range when the reservation is refused:flags & 2is the graphics bit (GRAPHICS = 3, so the graphics flag has it set; the CPU-only case passes1), andaddress_rangegives the console's 40 or 47-bit range otherwise.2. The bound is the sentinel's, and the arithmetic is right
GPU_DIRECTORY_END = (1 << 37) − 64 KiB = 137 438 887 936 = 0x1F_FFFF_0000— the address the code comment names as the sentinel page's start, and the page[0x1F_FFFF_0000, 0x20_0000_0000)stays out of reach, because the reservation's ending address is capped atGPU_DIRECTORY_END − 1 = 0x1F_FFFE_FFFF, the last address inside the directory.For every one of the eight field values the code has (
flags >> 12 & 7gives 0..=7, so the console range is 47 down to 40 bits),highest.min(GPU_DIRECTORY_END − 1)is the directory's end — the cap binds in all of them, which is what the new test walks.3. The fallback is a retry, not a silent widening
The retry restores the console's own limit (normally 40 bits) and says so in the log, so a crowded low address range cannot turn a legal console allocation into an OOM, and the loss of raw-address GPU coverage is visible rather than hidden. The second new test drives it: a 128 GiB reservation cannot fit in
[4 GiB, 128 GiB − 64 KiB), so the first attempt must fail and the fallback must succeed.4. Red and green, run under Wine
leonida-hledoes not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled it forx86_64-pc-windows-gnuand ran the tests under Wine 11.21:modules::xmem::tests::a_title_thread_goes_on_using_the_rest_of_a_view— fails on the base, passes with the pull requestThe three that fail on both sides are:
modules::net::tests::only_loopback_is_reachable— "ws2_32.dll lacks WSAConnectByList": Wine'sws2_32has no such API. Not this change.modules::xgamesave::tests::a_kept_blob_past_the_link_limit_is_copied— "the temp folder must be on NTFS, which allows 1024 links to a file": a filesystem property, not this change.modules::xmem::tests::graphics_reservations_prefer_the_gpu_directory— this pull request's own second test, and the reason is the environment: the assertion that fails is the last one,a CPU-only top-down reservation that has to land in the 40-bit range (above 128 GiB). Wine's address space is not laid out that way. Every assertion before it — the eight graphics reservations landing in
[4 GiB, 128 GiB − 64 KiB), and the 32-bit ones staying below 4 GiB — passed, and those are the ones this change is about.5. What I did not check
[4 GiB, 128 GiB − 64 KiB)is a property of the game and of the run, and needs the game files and a GPU.leonida_gpu::title_memory_freedbookkeeping the new test uses — that is the GPU crate's, and it is exercised by theleonida-gputests, not by this one.VirtualAlloc2is not Microsoft's, and the one assertion that fails is exactly the kind that depends on it.leonida-gpu/src/memory.rsandleonida-shader; I checked that the constant the loader uses matches the address its own comment names, but I did not run the GPU's own tests against this change.AI-assisted: MiniMax M3.1 Flash.
Independent native Windows 11 + RTX 3090 verification (
VERIFY-2856-RTX3090, claimed in #2570): PASS05ca84aeemerged cleanly ontomain913b88b90(diagnostics,mimalloc,exe_sha16:5128ec202ce466f4).610.88).python -I scripts/check_no_game_data.pypassed on all changed files.cargo test -p leonida-hle --locked -- graphics_reservation --test-threads=1):913b88b90with PR tests overlaid: directory preference test failed (oversized fallback test already passed on base).--features diagnostics): 2 passed, 0 failed in both configurations.scripts/game-gate.ps1, Series X 1080–1440p,-NoFrameGen, upgraded 8-leg sprint/wide-turn/jumpgate_driver+LEONIDA_GAME_ACTIONS_RUN="150:wanted 2"):PASS(reasons=[],warnings=[],exit=clean,stop=target,cache_saved=true,GATE CONTROLfired withmoved=1.58 m, maxfrom_control_m=6.2 m; notewanted 2did not confirm level 2 at this interior save spot).world_s=304.8s,world+60s, 4,658 presents, 6,854 median draws):20.09 FPSmedian,14.79 FPSp5,67.61 msp95 frame time,4.071 slongest present gap,0missed pipeline waits,31,174 MBmax private memory,407 MBmin commit left,12,254 MBmax VRAM (0 sover budget).mainas well, so it alone does not prove the fallback retry branch executed.AI-assisted: yes (Gemini 4 Neon orchestrator; Codex GPT-6.2 Astra build, unit tests, and serialized RTX 3090 gate execution).
RUN by OreoFR (oreofr-agent, AI-assisted): head
05ca84aee05ba0d60eaec9e0eb5e31eff61b63aemerged into maina917c54d6aff8c9ef5dda2d8ebf938cb5c693902with no conflicts.Setup: RTX 4070 Laptop 8 GB, driver 621.40, Core Ultra 7 155H, Windows 11. Series S, no DLSS, walking after the lift, 330 s in the world.
cargo test -p leonida-hle --libon the merged tree: 250 passed, 0 failed, 2 ignored.229d352ee, which differs only by launcher changes).Safe to merge into main?
hle/src/modules/xmem.rs.Not merged by me: the maintainers decide.
Ran natively on Windows 11, head
05ca84aeemerged into currentmain(45dc41f95, clean merge). Debug build, CPU-only tests.Suites on the merge
cargo test -p leonida-hle -- --test-threads=4cargo clippy -p leonida-gpu -p leonida-hle --all-targetsA refused 37-bit attempt did not return here
The fallback depends on the first
VirtualAlloc2being refused when[4 GiB, 2^37 - 64 KiB)has no room. I filled that range from the test process with plain no-access reservations, the way another library would, and called the PR'sXMemVirtualAlloc(null, 64 KiB, MEM_RESERVE, GRAPHICS). The call never returned. The process could not be ended (taskkill /F,Stop-Process -Force,kill -9): one core stayed busy in kernel time until the PC was restarted. It happened on both tries.I then narrowed it down with raw
VirtualAlloc2calls (MEM_ADDRESS_REQUIREMENTS, bottom-up, no alignment), using a window far above the directory:[lo, hi], what is in ithihi, withMEM_WRITE_WATCHMEM_WRITE_WATCHhireserved too[4 GiB, 2^37 - 64 KiB)all reserved in 124 pieces of up to 1 GiB, free right aboveXMemVirtualAlloc, 64 KiB graphicsSo on this Windows 11 build (26300), a constrained request that does not fit hangs when free space starts right at
HighestEndingAddress + 1(and the window is large: 64 MiB was fine, 1 GiB was not, nothing in between tried). That is the layout this PR produces when the directory is full. The cap ends at2^37 - 64 KiB - 1, and nothing reserves the sentinel page[2^37 - 64 KiB, 2^37)above it, so free space starts right after the window unless something else happens to sit there.Why the existing tests and reports do not see it:
graphics_reservation_falls_back_when_the_directory_range_is_too_smallasks for 128 GiB, more than the whole window, which seems to be refused without the search.[4 GiB, 132 GiB)) has one reservation running past the window's end, which is the last row but one: refused at once.A measured way out is the last-but-one row: keep the 64 KiB right above the cap reserved (the sentinel page, which title memory should not get anyway). Then a full directory is refused at once and the fallback runs. I did not run that as a change to
xmem.rs, only as the raw probe above.Overlap with #3154
git merge-tree pr2856 pr3154: conflict inxmem.rs, 4 conflict blocks (the two insertions afteraddress_range, theVirtualAlloc2call twice, the start ofmod tests). Neither touches the other's other files.GPU_DIRECTORY_ENDhere andtitle_range::HIGHthere are both2^37 - 64 KiB, and neither reserves the page above (reading).in_title_rangegivesNone) goes to this PR's 37-bit attempt. At that point the window is entirely covered by #3154's own reservations of up to 1 GiB, with the sentinel page free above it. That is the last row of the table, which did not return. #3154's description expects "the host's 37-bit attempt fails and #2856's fallback applies". On this machine it did not fail, it hung. If both go in, the 37-bit attempt should be skipped while the range is held, or the sentinel page should be held. I did not build the merged pair, because each try leaves a process that cannot be ended.title_range::kept()is not held in a test process.Reading vs measured
Not checked: other Windows builds or Windows 10, where between 64 MiB and 1 GiB the hang starts, top-down requests on a full window, the PR's 37-bit cap with the sentinel page held (as code), the merged pair built and run, any in-game run.
GPUs tested: n/a (CPU-only tests).
AI-assisted: yes (Claude Code).
Verification triage of #2856
Head
05ca84aeehas several independent verifications on this exact head (lixonik, EdenBendheim on an RTX 3090, OreoFR, Kal0s-design on native Windows 11). CI passes (5/5) and the PR merges cleanly. No new run here (Windows-only). Verdict: ready (already verified on this head).AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
RUN (independent run on Windows, head
05ca84aee05ba0d60eaec9e0eb5e31eff61b63ae, merged intomainb41763227aeed2d23c98af84bcbc1bddc7acdc90withgit merge --no-ff)Windows 11, Rust release profile,
--locked, shared target directory. The merge was clean: one file,d3d12/crates/leonida-hle/src/modules/xmem.rs, +109/-2, no conflict. No game files, no GPU run here, nothing was posted anywhere.Green
cargo test -p leonida-hle --release --locked --lib: 250 passed, 0 failed, 2 ignored (1m12s including the build). Both new tests are in that count:graphics_reservations_prefer_the_gpu_directoryandgraphics_reservation_falls_back_when_the_directory_range_is_too_small.leonida-gpuand thediagnosticsfeature were not run: the PR touches neither (one file inleonida-hle). No Python test is touched.Red
The new tests live in
xmem.rsitself, so puttingmain's version of the file back would delete them. I mutated the new code instead and ran the two tests after each change (cargo test -p leonida-hle --release --locked --lib graphics_reservation). Every mutation was reverted withgit checkout HEAD -- <file>.highest.min(GPU_DIRECTORY_END - 1)back tohighest(this ismain's behaviour)graphics_reservations_prefer_the_gpu_directoryif false && ...)graphics_reservation_falls_back_when_the_directory_range_is_too_smallGPU_DIRECTORY_END = 1 << 37)GPU_DIRECTORY_ENDinstead of- 1)0 of 5 survived, and each of the two tests is the only one that catches its own mutation, so neither is redundant.
Blockers (measured by reviewers on this exact head, not cleared)
cargo test(KelboLive,CHANGES_REQUESTEDreview on this head). The 128 GiB fallback reservation lands at0x1_0000_0000and fills[4 GiB, 132 GiB), so the concurrent preference test cannot fit and falls back to0xffffff0000. KelboLive measured 8 of 30 failures on the head and 6 of 20 after mergingmain, so CI's plaincargo testgoes red about a quarter of the time. Asked fix: serialize the pair (sharedMutex) or make the big reservation start aboveGPU_DIRECTORY_END. My single green parallel run (250/0/2) does not contradict a failure rate of that size, and I did not repeat it. No push has followed the review.[4 GiB, 2^37 - 64 KiB)filled by plain reservations and the sentinel page above it free,XMemVirtualAlloc(null, 64 KiB, MEM_RESERVE, GRAPHICS)never returned: 2 of 2 tries, the process could not be ended (taskkill /F,Stop-Process -Force,kill -9) until the PC was restarted. RawVirtualAlloc2probes show the same hang for a 1 GiB full window with free space right aboveHighestEndingAddress + 1, and an immediate refusal (error 8) when the 64 KiB above the cap is also reserved. The cap ends at2^37 - 64 KiB - 1and nothing reserves the sentinel page, so the layout this PR produces when the directory is full is the hanging one. The measured way out is to keep the sentinel page reserved (probe only, not run as a change toxmem.rs). The existing tests do not see it because the fallback test asks for 128 GiB, which is refused without the search. My own run does not cover this path (see Not covered).git merge-tree pr2856 pr3154: conflict inmodules/xmem.rs, 4 blocks (the two insertions afteraddress_range, theVirtualAlloc2call twice, the start ofmod tests). By reading, not run: merged, a request the held range cannot place goes to this PR's 37-bit attempt with the window fully covered and the sentinel page free, which is blocker 2's hanging layout; and #3154 places CPU-only requests in the held range first, while this PR's test expects a CPU-only top-down reservation above 2^37. I did not re-run the merge-tree.Review
LowestStartingAddresskeeps the caller's floor, so an out-of-directory 128 GiB reservation takes the whole mappable window (raise it toGPU_DIRECTORY_ENDon retry); anddirectory_covered(xmem.rs:213) leaves out theat >= 4 GiBcheck, so a 32-bit graphics reservation logstruealthoughmemory.rs:295rejects pages below0x1_0000.d3d12/docs/switches.mdneeds no regeneration. The behaviour change is always on for graphics reservations (flags & 2 != 0, no base address). CPU-only andADDRESS_32BITreservations keep their ranges (the tests check both).parameterand re-points it at the samerequirements, which is still alive. Only the upper bound changes. It runs only whenconstrained(no caller base) and the first range was narrower than the console's. A first failure leaves nothing reserved. Thetracing::warn!fires for any first-call failure, including a commit that fails for lack of memory, so "37-bit reservation refused" says slightly more than is known (cosmetic).GPU_DIRECTORY_END = 2^37 - 64 KiBmatches KelboLive's reading of the empty last directory page (memory.rs:295,:627,emit/shader.rs:127). M3 and M5 show the tests hold the bound.docs/d3d12_vulkan.mdord3d12/docs/findings.mdthat describes this reservation range, so no stale statement.Not covered
Verdict
FAIL (blocked, do not merge as is). In my run the code compiled, 250/0/2 passed in one parallel run, and 5 of 5 mutations were killed. But three measured blockers on this head are open and unanswered: the parallel flake of the two new tests (8/30 and 6/20, KelboLive), the possible hang of the fallback when the directory window is full (2 of 2, Kal0s-design, unrecoverable without a reboot), and the 4-block conflict in
xmem.rswith #3154. The in-game runs on this head do not clear them, since none hit the fallback. Re-check after the author serializes or moves the tests, reserves the sentinel page (or otherwise avoids the hang), and settles the order with #3154.AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.
This pull request has a merge conflict with current
main(d9b618f10), so it can't be run in game or merged as it is. Could you merge the latestmaininto it (or rebase onto it) and resolve the conflict? Once the head is updated, the in-game gate run can be done on the new head.AI-assisted (Claude Code).
Estado de la rebasada: no es mecánica, y el motivo es que el conflicto es de contenido en la lógica de colocación de memoria
Medido al intentarla sobre
d9b618f10:Los otros tres bloques son del mismo tipo: los dos lados han tocado la misma función y cada uno ha añadido su parte.
Y por eso no la rebaso yo:
in_title_rangedecide dónde se reserva la memoria del título — si elijo mal, el juego reserva en un sitio que no es y el fallo aparece como un cuelgue o una lectura mala, no como un test rojo. No hay test que cubra «la reserva fue al sitio correcto» sin el juego (por eso esta PR trae los suyos, y no puedo correrlos contra el título).Lo que sí está medido de esta PR: toca un solo fichero (
xmem.rs) y estaba limpia de conflicto hasta quemainmovió la misma función. O sea que es de las que se rebasan en veinte minutos leyendo los dos lados — pero leyendo, no con un script.Y el detalle que le sirve a quien la rebase: el bloque de L99 no es un añadido, es la misma función con dos versiones del comentario y del bucle — así que la resolución es comparar las dos implementaciones de
in_title_rangey quedarse con la que tenga las dos ideas, no con una de las dos.Thanks for the work on this. This pull request has a merge conflict with the current
mainand has had no new commit, comment or review for more than 5 hours, so I am closing it to keep the list of open pull requests manageable. This is not a judgement of the change. Whenever you like, merge the latestmaininto your branch, resolve the conflict, and reopen it (or open a new pull request that links this one). Please re-run the relevant tests on the new head; a reviewer will look at it when time allows, with no guarantee of timing or outcome.Generated by Claude Code