Repository navigation
xmem: keep the space below 4 GiB for the title's 32-bit memory - #1009
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Tested merged cleanly onto main (ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):
cargo test -p victory-hle: 95 passed, 0 failed (plusno_dll_planting: 1 passed)cargo clippy -p victory-hle --all-targets: 0 warningscargo xtask policy: ok
Clean fix preserving low 32-bit virtual address space below 4 GiB for title allocations. Approving.
AI-assisted (Gemini 4 Neon).
|
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. |
|
Updated with @MichaelSmithAI's follow-up from NuraadGit#1 ( |
|
@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 ( The chain, one run per step:
AI-assisted; measurements are from a real RTX 3060 Ti run. |
|
@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:
The workarounds without this PR are to quarantine that one cache file or to reboot. With I'll add the DXCache case to the PR description as the motivating example. |
|
Automated triage for the maintainers. Merge candidate. The rebase onto
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 Generated by Claude Code |
XMemVirtualAlloc with the 32-bit address flag has to fit below 4 GiB, where Windows also puts the host's own memory first (it allocates bottom up). With a large pipeline cache read at startup, the driver's, heap and cache memory left 22 MB there, in pieces of at most 14 MB, when Grand Theft Auto VI asked for a 185 MB 32-bit placeholder; the request was refused (ERROR_NOT_ENOUGH_MEMORY) and the title stopped at an assertion (+0x19f4f58). The D3D12 debug layer's memory did the same. `low_guards::install`, at the start of `run`, reserves the free space below 4 GiB but the lowest 256 MB (left to the host). A 32-bit request that finds no room releases the smallest guard that fits it (else the largest) and tries again, then guards what is still free of it. Tested: the new test releases a guard, takes part of the hole and checks the rest is guarded again. In the title (RTX 2080, a build with a large cache): without this the startup failed 2 of 3 times; with it, 5 of 5 starts passed, 3.7 GB below 4 GiB kept for the title.
|
Rebased onto |
7ea9112 to
48a40d2
Compare
… 32-bit memory
…32, #854, #768, #812, #860, #864, #868, #896, #922, #936, #964) Takes in the fork of this tree that targets 8 GB NVIDIA cards (Wave32), which carries those pull requests merged on top of `0b0074e` plus one fix of its own: `xmem` keeps its guards below the low 4 GiB on machines with more than 32 GB (`Marvisak/VIctory#1009`). Conflicts, and what was kept: - `crates/victory-gpu/src/descriptor/host.rs`: both tests (our tiled slot test and their dynamic run across the cursor), and our `cbv_size` — `checked_next_multiple_of(256)` before the 64 KiB clamp, so a size near `u32::MAX` cannot wrap. - `crates/victory-gpu/src/shadow.rs`: one `use` for the merge tests, ours and theirs joined (`SNAPS`, `give_back`, `pooled`, `take_snapshots` on top of `PIECE`, `back_piece`, `changed_runs`, `join_runs`). - `crates/victory-shader/src/emit/mod.rs`: their `exactly(...)` returns for the loose-LDS forms. Their tree has the same `exactly` closure ours does (an approximate form reported as such), so this is the form ours wants too. `with_loose_lds` and its `LDS_LOOSE` were defined twice after the automatic merge; one copy is left. - `crates/victory-gpu/src/watch.rs`: their `VICTORY_VIEW_KNOWN` view set (off by default) beside our `views` ranges, and our `title_memory_ committed` alongside their parked-block handling. - `crates/victory-gpu/src/pipeline/host.rs`: one `integer_format` and one `host_blend` — ours, which keeps a logic op on an integer target valid when that target does not blend (#922 as we have it). - `crates/victory-gpu/src/texture.rs`: their `VICTORY_TEXTURE_DROP_MIPS` test, moved to our staging signatures (`staged_memory` returns the mips, `refresh_unlocked` takes the frame, `fingerprint` the mips, `Staging` wants `first_mip` and `title_bytes`). - `README.md`: our title, their measured result and the list of PRs taken in, under one heading. Defaults are theirs where they changed one, except that `VICTORY_SKIP_WC_COMPARE` stays off (it breaks the hull physics of the first chapter) and `VICTORY_TEXTURE_DROP_MIPS` stays 0: it is worth `=2` only where VRAM is short, and it costs resolution everywhere.
A port of Marvisak/VIctory#1009 (NuraadGit, with the bounded retry from MichaelSmithAI). At startup the title asks XMemVirtualAlloc for a 185 MB placeholder below 4 GiB. Windows places the host's own memory bottom up, so the drivers' mapped shader caches, heaps and the image read can fill that space first; the request is refused and the title stops at its own assertion (int3 at +0x19f4f58), with nothing in the log. With the system's bottom-up ASLR turned off (Exploit protection) it happens on every start. The free space below 4 GiB (but the lowest 256 MB) is reserved at the start of `run`; a 32-bit request that finds no room releases guards one at a time and tries again, guarding again what stays free. A request still refused is logged. RX 9070 XT, bottom-up ASLR off, 2.3 GB of the driver's shader cache mapped below 4 GiB: this fork's 4cbe9d7 stopped at the assertion at start; with this, it reaches the menus (3.7 GB kept for the title). Co-authored-by: NuraadGit <81594937+NuraadGit@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 32-bit memory
…sak#1009) * xmem: keep the space below 4 GiB for the title's 32-bit memory XMemVirtualAlloc with the 32-bit address flag has to fit below 4 GiB, where Windows also puts the host's own memory first (it allocates bottom up). With a large pipeline cache read at startup, the driver's, heap and cache memory left 22 MB there, in pieces of at most 14 MB, when Grand Theft Auto VI asked for a 185 MB 32-bit placeholder; the request was refused (ERROR_NOT_ENOUGH_MEMORY) and the title stopped at an assertion (+0x19f4f58). The D3D12 debug layer's memory did the same. `low_guards::install`, at the start of `run`, reserves the free space below 4 GiB but the lowest 256 MB (left to the host). A 32-bit request that finds no room releases the smallest guard that fits it (else the largest) and tries again, then guards what is still free of it. Tested: the new test releases a guard, takes part of the hole and checks the rest is guarded again. In the title (RTX 2080, a build with a large cache): without this the startup failed 2 of 3 times; with it, 5 of 5 starts passed, 3.7 GB below 4 GiB kept for the title. * Bound low-address allocation retries to existing guards * xmem: safety comments and formatting for the bounded guard retry --------- Co-authored-by: swarm <swarm@swarm.swarm> Co-authored-by: NuraadGit <NuraadGit@users.noreply.github.com> (cherry picked from commit d1dfbbd) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
XMemVirtualAlloc with the 32-bit address flag has to fit below 4 GiB, where Windows also puts the host's own memory first (bottom up). With a large pipeline cache read at start-up only 22 MB was left there, in pieces, when the title asked for a 185 MB 32-bit placeholder; the request failed and the title stopped at an assertion. `low_guards::install`, at the start of `run` when the title is to be executed, reserves the free space below 4 GiB but the lowest 256 MB (left to the host). A 32-bit request that finds no room releases the smallest guard that fits it (else the largest), tries again, and guards what is still free of it. From Marvisak/VIctory d1dfbbd (Marvisak#1009, Nuraad), merged upstream; measured there on an RTX 2080: 2 of 3 starts failed without it, 5 of 5 passed with it. Not seen to fail here, a robustness fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #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).