GPU: free memory is not the runtime's to watch (fixes a world-load deadlock under Wine) #1849
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!1849
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1849"
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?
@crashbashash on GitHub · 2026-11-24 23:24 UTC · original
crashbashash:fix/watch-free-memory→main· +46 −12 · 1 files · 1 commits · openUnder Wine/Proton,
mainat70564aestops at the end of loading or just after entering the world: no frames, no audio, the title idle, no GPU fault. Six of six runs here (RX 6800 XT, RADV, GE-Proton11-14). This is the cause and a one-condition fix.What happens
shadow::loose()makes a 4 MiB window copy for an address outside every known buffer. For a null address that window is0x0..0x400000, andShadow::newaskswatch::track(0, 4 MiB, true)to track it.runtime_memory(0, true)accepts it:GetWriteWatchfails, and the view test is "anything but committed private memory", which free memory (MEM_FREE) passes.VirtualProtectcalls just fail (I haven't checked on Windows). Under Wine the process heap lives there (here, heap writes faulted on guarded blocks from0x140000to0x260000), and its pages become read-only.on_write. When the faulting thread already holdsGUARDS(it allocates insideTracked::take,writing(), oron_writeitself),on_writewaits for the lock its own thread holds, forever. Audio (apu::XApuEnqueueCommand), GPU submission (Host::execute→Tracked::take) and the title's workers then queue behind it.Evidence
xmem::map_alias→watch::title_memory_remappedfaulting intoon_write→Mutex::lock_contended; others waiting inon_write(audio) andTracked::take(GPU submission).GUARDSlogged faults at0x1400d8(RtlEnterCriticalSectionon the process heap's lock) and0x1de770(ucrtbasememcpyinto the heap), with the lock taken inTracked::take,writing()andon_write. With those faults let through, the title ran 5 minutes in the world.track():0x0+0x400000fromshadow.rs:205,VirtualQuerystate0x10000(MEM_FREE).The change
runtime_memoryalso requiresState != MEM_FREE. Placeholders and views, which it is meant to accept, are reserved or mapped, never free. New testfree_memory_is_not_tracked(track(0, 4 MiB, true)isNone): it fails without the change and passes with it. All 7watchtests pass under Wine.In the title
70564ae+ the watchdog hook (#454) + three of #994's Proton commits (4828716,e5a8c2f,d469fe9), shaders and pipelines precached withtranslate --cache --pipelines, RX 6800 XT, RADV / Mesa 26.2.6, GE-Proton11-14:With it, the opening renders: sky, skyline, characters and credits, 2,500–3,600 draws per frame, 4.8–6.2 s per frame. One of the three runs ended at 5 minutes in an access violation in title code (
+0x35a4245, reading-1, no VIctory frames on the stack); the other two didn't, so I take it to be unrelated.Not tested on Windows. The change only turns away free memory, so there it should only mean fewer
VirtualProtectcalls that fail anyway.AI-assisted (Claude Code). No game data attached.
@astrosteveo on GitHub · 2026-11-25 03:57 UTC · original
Tested on an RTX 5080, Wine 11.22, on
940d32fplus open PRs.free_memory_is_not_trackedfails without the change and passes with it, in MinGW and MSVC builds.I forced the hang by allocating plain memory at
0x200000aftertrack(0, 4 MiB): it became read-only, and a write with the guard lock held never returned. With the change it stays writable.On this Wine the process heap was above 4 GiB in 13 of 13 probes, so the null window wouldn't reach it here.
A gap that remains:
runtime_memorychecks only the first page, so private committed memory later in a range that starts in a reservation is still guarded (shown with a synthetic test; I don't know if the title hits it). Not tested: Windows, the title. AI-assisted (Claude).@coil111 on GitHub · 2026-11-25 04:34 UTC · original
Tested on Linux/Proton with an AMD RDNA4 card: without this PR, current
mainfreezes at the end of loading in the same way the description says; with it, the title reaches the world and keeps running.Setup: RX 9070 XT (RDNA4), Mesa RADV, Gentoo, kernel 7.3.4, 64 GB RAM. Proton Experimental
experimental-11.0-20261112(its Wine; vkd3d-proton2576c0b4a; DXVK dxgi). Diagnostics build ofmain940d32f, cross-built with cargo-xwin (x86_64-pc-windows-msvc). Title 1.0.2.1, Series X, pipelines prebuilt withtranslate --cache --pipelines.What the freeze looked like here (
940d32falone):winedbgcould not attach to the process (error 87), so I have no stacks of my own. The symptoms match the description, but I have not shown it is the same lock.With this pr the 7
watchtests pass under this Wine (cargo xwin test -p victory-gpu -- watch, Wine as the runner), including the newfree_memory_is_not_tracked. In the title, the run went from loading into the world without stopping.@Marvisak on GitHub · 2026-11-25 07:25 UTC · original · edited 2026-11-25 18:24 UTC
Automated triage for the maintainers.
runtime_pagesincrates/victory-gpu/src/watch.rsno longer countsMEM_FREEregions as the runtime's GPU memory, so free parts of a tracked range (for example the 4 MiB window around a null address) are never guarded. I checked this againstorigin/main. Since280b150, the region walk counts free memory as "ours". Under Wine the process heap is later committed there and gets guarded, and a heap write made while holding the guard lock deadlocks. The change only moves free pages into the untracked set, whichShadow::update_freecopies whole each use, so correctness on Windows is unchanged. Reserved memory and placeholders are still tracked. The new testfree_memory_is_not_trackedreserves and releases a block and fails without the change. Several independent Wine/Proton runs in the thread (NVIDIA and AMD) report that the freeze at world entry is gone.One thing to keep an eye on: free pages inside a tracked range are now copied whole (as failing reads) on every use instead of counted as zero pages, so a range with large free parts may cost a bit more per frame.
CI: passing.
Generated by Claude Code
@crashbashash on GitHub · 2026-11-25 11:14 UTC · original
Thanks for testing this on NVIDIA, and for the gap.
You're right:
runtime_memorylooks only at the first page, so a range that starts in a reservation with plain committed memory further in is still guarded. That's older than this PR, so I've kept the fix separate to leave this one as reviewed: #2345 checks every region of the range, with your case as a test (a reserved block plus a committed one is refused; the reserved block alone is still tracked).I don't know whether the title hits it either; in our runs the change made no measurable difference.
AI-assisted (Claude Code). No game data attached.
@Impre-visible on GitHub · 2026-11-25 14:43 UTC · original
Test report, as asked in #1921: five runs with this PR on the setup where
mainfroze at world entry.Setup: Linux (Arch, kernel 6.18 LTS), GTX 1660 6 GB, NVIDIA 620.73.04 (open modules), Wine from GE-Proton11-6 with vkd3d-proton
2576c0b. Tree:mainas fetched this morning (after86a5ed6) plus a few other open PRs (#1722, #1769, #1583's branch, #1523, #454) and this PR atde95e51.VICTORY_NO_WATCHDOG=1, 15-minute limit per run, one run at a time.Xidin the kernel logAll five runs with the PR ran to the 15-minute limit in the world. Two started from warm shader and pipeline caches, three from empty ones. Per run: 788 to 855 compute pipelines made, last frame 2,834 to 3,002, frame time in the world about 1.3 s once loading settles (one run 2.4 s at the cut), 0.3 to 24 s during loading.
The freeze without the PR was the one described in #1921: no log line and no present any more,
sync_heapsstuck insideViewed::setwith the other threads behindSHADER_HEAPS.Not part of this PR, but for the record on this card with that tree: 153 compute pipelines refused per run (wave64 on a 32-lane host) and 149 to 195
no dynamic slots for its tablesdrops per run (#1548 is not in it).Not tested: Windows, AMD, anything past the first playable scene (the runs only press Enter).
🤖 Generated with Claude Code
@crashbashash on GitHub · 2026-11-25 16:49 UTC · original
Rebased onto
main(67e8ae1). Since280b150checks every region of a tracked range, this PR is down to one condition in that check: free memory is not the runtime's.280b150still counts free memory as the runtime's (itsshortcut:note says so). Under Wine that's the deadlock this PR was opened for: Wine's process heap gets committed where the range was free, and the heap's writes fault into the guard handler while a thread holds the guard lock.The test changed with it. The old one tracked the window of a null address, but with the region walk that window is no longer all free under Wine: Wine maps read-only locale files there, which count as views. The new test reserves a block and releases it, so it has free memory at a known address, and checks that it isn't tracked. It fails without the change.
Tests:
victory-gpuunder Wine (GE-Proton11-14 with vkd3d-proton, RX 6800 XT): 193 passed, 3 failed. The same 3 fail onmainthere:a_texture_written_in_one_format_reads_in_another_through_a_placed_view(castable formats, #2101) and the twopipeline::libraryblob tests.cargo clippyis clean with and without--all-features.@Impre-visible, thanks for the five runs on the GTX 1660. That's the clearest evidence this PR has had.
AI-assisted (Claude Code). No game data attached.
@catminou4 on GitHub · 2026-11-24 23:47 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Free memory is not the runtime's to watch (fixes a world-load…): stops the runtime treating free pages as its own — likely a crash/OOM fix on world load. Windows-only.
@fuzeofficlal on GitHub · 2026-11-26 16:40 UTC · original · approved these changes
Verified
4f6bacef7f53e781bf0a48eca8cd223402092d76merged cleanly onto63bcca43on Windows 11 with both an RTX 5090 (VICTORY_D3D12_DEBUG=1) and WARP (--features diagnostics,VICTORY_D3D12_DEBUG=1).Code review
info.State != MEM_FREEinruntime_pages(crates/victory-gpu/src/watch.rs:333-368, condition atwatch.rs:361) cleanly excludes free address space from being treated as runtime GPU memory while keeping write-watched pools (watched(...)),MEM_RESERVEreservations/placeholders, andMEM_COMMIT | MEM_MAPPEDviews tracked, and keepingMEM_IMAGEand plainMEM_COMMIT | MEM_PRIVATEexcluded.MEM_FREEregion is added tootherand removed byruntime.difference(&other)(watch.rs:364-367), a range straddling a reservation and adjacent free space leaves the free page untracked and never registers it ing.protected, preventing future allocations into that free region from faulting intoon_writewhileGUARDSis held.Verification
cargo xtask policy:191 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.VICTORY_D3D12_DEBUG=1:watch::16 passed, 0 failed (includingfree_memory_is_not_trackedatwatch.rs:1049).--features diagnostics+VICTORY_D3D12_DEBUG=1:watch::16 passed, 0 failed.MEM_FREErange returnsNonefromtrack_copy, (2) a mixed[MEM_RESERVE 64 KiB | MEM_FREE 64 KiB]range tracks page 0 and puts page 1 inuntrackedwithout ever inserting page 1 intog.protected, (3) committing plainPAGE_READWRITEmemory at that formerly free page 1 and writing to it while holdingguards()completes with no fault or deadlock, and (4) a write-watched pool remains 100% tracked with zero untracked bytes.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.