xmem: keep the space below 4 GiB for the title's 32-bit memory #1009
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1009
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1009/head"
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?
@NuraadGit on GitHub · 2026-11-24 14:56 UTC · original
NuraadGit:xmem/guard-32bit-window→main· +203 −2 · 2 files · 3 commits · merged 2026-11-25 21:49 UTCFixes #790.
What
At startup Grand Theft Auto VI asks
XMemVirtualAllocfor a 185 MB placeholder with the 32-bit address flag (size=193986560 kind=0x42000 flags=0x7, soaddress_rangegives0..4 GiB). Windows places allocations bottom up, so the host's own early memory (the driver, heap segments, the image read inrun, the caches) can fill the space below 4 GiB first.VirtualAlloc2then fails withERROR_NOT_ENOUGH_MEMORY,maindoesn't log it, and the title stops at its own assertion (0x80000003at+0x19f4f58) about 3 s after the device is made.This keeps that space for the title:
xmem::low_guards::install()runs at the start ofrunwhen executing, before the image read, the device and the caches. It reserves the free space below 4 GiB except the lowest 256 MB, which is left to the host.XMemVirtualAllocreleases the smallest guard that fits it (else the largest) and retries the same call, then guards again whatever is still free of that hole.low_guards::tests::a_released_guard_is_guarded_again_around_what_took_it.Measured (RTX 2080, Windows 11, 32 GB)
A temporary probe in the refusal path (not part of this PR) found only 22 MB free below 4 GiB at the failure, in pieces, with a largest hole of 14 MB.
VICTORY_D3D12_DEBUG=1The second row matters for debugging: the D3D12 debug layer's memory caused the same failure, so on machines like this one the debug layer and GPU-based validation were unusable. With the guards, the debug layer has since named a device-removal cause in one run (see my comment on #55).
cargo test -p victory-hle --lib low_guardspasses, andcargo clippy -p victory-hle -p victory --all-targets -- -D warningsis clean.AI-assisted (Claude Code): the probe, fix, test and runs were automated. The hardware, title copy and runs are the user's.
A real-world trigger (from @ryosen0, RTX 3060 Ti)
After a driver TDR, the NVIDIA driver maps its ~1 GB shader cache (
%LOCALAPPDATA%\NVIDIA\DXCache\*.nvph) into every new process. That mapping can take the space below 4 GiB, so the title's 185 MBADDRESS_32BITplaceholder is refused and startup stops at an int3 about 3 s in. It fails every time until the file is removed or the machine reboots. With this PR, startup succeeds with the file in place (report).@MichaelSmithAI on GitHub · 2026-11-24 15:04 UTC · original
The guest successfully allocated and released the 185 MiB placeholder in an isolated Wine 11.22 process. We also checked the retry path and opened a follow-up on your branch that tries each original guard at most once per request. Both guard controls passed, including restoration after a simulated allocation refusal. Our Wine result covers the allocation calls; the native startup A/B in this PR remains the title evidence.
@Zipettte on GitHub · 2026-11-24 15:12 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at ab749fd:
cargo test -p victory -p victory-hlepasses, 97 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@NuraadGit on GitHub · 2026-11-24 15:16 UTC · original
Updated with @MichaelSmithAI's follow-up from NuraadGit/VIctory#1 (
75f1e99). A refused retry used to be able to loop on the same guard forever. It now tries each existing guard once, under the guard lock, and keeps the allocation's error. I added7ea9112on top: safety comments forclippy::undocumented_unsafe_blocks, and rustfmt.cargo test -p victory-hle --lib low_guards(2 passed), clippy with-D warningsand rustfmt are clean.DXGI_ERROR_DEVICE_HUNG/0x887A0004/0x887A0006#1440DXGI_ERROR_DEVICE_HUNG/0x887A0004/0x887A0006#1440@ryosen0 on GitHub · 2026-11-24 19:10 UTC · original
@NuraadGit RTX 3060 Ti (Ampere) confirmation, including the post-TDR case and a real driver-cache pressure source. Windows 11 Pro 22631, RTX 3060 Ti 8 GB, driver 617.42 (32.0.16.1742), title 1.0.2.1 (
b99f876b), diag build.The chain, one run per step:
0x80000003attitle+0x19f4f58about 3 s in, before the xmem hooks. The log up to the crash was byte-for-byte identical to a successful run. Quarantining VIctory's caches, saves and telemetry changed nothing.%LOCALAPPDATA%\NVIDIA\DXCache\408da9dbd953f4b6.nvph, a 1 GB file the driver had written during the long run that ended in the TDR. Quarantining that single file let the title start (17 min, 30 fps, 0 device removals). The large driver-cache mapping takes the space below 4 GiB, the 185 MB ADDRESS_32BIT placeholder is refused (unlogged onmain), and the bring-up gate hits the int3. This also explains "broken forever after a TDR" without a reboot: the driver maps the cache into every new process.7ea9112onffe310e+ #493 + #206 + #454 + #1322):low_guards: space below 4 GiB kept for the title guards=2 mb=3796, startup succeeds. A direct confirmation of the fix under real pressure, not only the debug layer.AI-assisted; measurements are from a real RTX 3060 Ti run.
@NuraadGit on GitHub · 2026-11-24 19:35 UTC · original
@ryosen0 thank you, that's the real-world trigger this PR was missing, and it explains why a machine can stay broken after one TDR until a reboot.
To restate the chain for anyone landing here:
%LOCALAPPDATA%\NVIDIA\DXCache\*.nvph), and it maps that file into every new process.ADDRESS_32BITplaceholder is refused. Onmainthat refusal isn't logged, and the title stops at the int3 about 3 s in.The workarounds without this PR are to quarantine that one cache file or to reboot. With
7ea9112the space below 4 GiB is kept for the title early (low_guards … guards=2 mb=3796), and your run starts with the file in place.I'll add the DXCache case to the PR description as the motivating example.
@Marvisak on GitHub · 2026-11-25 00:32 UTC · original · edited 2026-11-25 01:19 UTC
Automated triage for the maintainers.
Merge candidate.
The rebase onto
mainresolved the conflict. Reviewed at48a40d2.xmem::low_guards::installis called fromrunbefore the image read and before the device is created. It reserves the free space below 4 GiB, except for the lowest 256 MB, which stays available to the host.XMemVirtualAllocis refused for a constrained 32-bit request (constrained && highest < FOUR_GIB),low_guards::retryreleases one guard at a time. It tries each existing guard once, smallest fitting first, and re-guards whatever stays free in that guard. It also restores the allocation's own last error, so the refusal log thatmainadded still reports the right cause.Evidence: native A/B startup runs on two machines, including the NVIDIA DXCache case after a TDR, plus a Wine check of the allocation calls.
One thing for the maintainer to keep in mind: only 256 MB below 4 GiB is left for host components that need low addresses.
CI: failing. The only failures are
emit::synthetic_tests::gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_outinvictory-shader, andmain's own CI fails both of them too. The xmem tests pass.Generated by Claude Code
@NuraadGit on GitHub · 2026-11-25 01:01 UTC · original
Rebased onto
main(4118f33). The only conflict was inXMemVirtualAlloc:mainnow logs a refused allocation, and this PR retries a 32-bit allocation after releasing the low guards. Both stay, in that order: retry first, then log if it still fails, with the error kept from the allocation attempt itself (low_guards::retrypreserves it across its own system calls).cargo test -p victory-hle --lib xmem: 12 passed.cargo clippy -p victory-hle --all-targetsadds no warnings.