gpu(native): no copy-back into a pool the view left, or into a freed range (#339) #384
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/384"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T15:57:03Z.
What this changes
Refs #339 (not
Closes: the GPU-write case below is still open).Before a GPU-written texture is written back into title memory, the copy now checks that the address still belongs where the view was placed:
Title::placedagainst the pool's ownresolve), the copy is skipped and logged once per texture, instead of writing over whatever holds the range now;VICTORY_TRACE_FREED=1, a copy-back into a range the title's allocator freed is logged throughnative::freed::checkand skipped;native::freed::overlapsis the new silent predicate behind that test.Either write would land on whatever occupies the range now, which is one way a freed block's link ends up with a garbage offset — the fault at
image+0x4dac5bfdescribed on #339.docs/native-host.mdgains the section that explains the fault, names the two host-side suspects, and says what stays open: a GPU write landing in a range after the title freed and reused it, which the host cannot see because the title's allocator reports no frees.How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass — victory-hle 321, native_probe 17, victory-loader 29, 0 failed.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: no warnings on this tree (victory-gpure-checked).cargo xtask policy: 387 files ok.VICTORY_TRACE_FREED=1, copy-backs skipped and logged, no new "not copied back" warning for a texture that is still alive, and no crash atimage+0x4dac5bfon a machine that hit it before.Checklist
VICTORY_*variable and documented: no new variable; the new skip logs under the existingVICTORY_TRACE_FREED=1Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T16:20:04Z.
What this changes
Refs #339
Two commits. (1) Title::write_back no longer copies a GPU-written texture back into whatever holds its title address now: when the address no longer resolves to the pool recorded at view placement (Title::placed vs PoolTable::resolve), the copy is skipped and logged once per texture — one way a freed block's link ends up with a garbage offset (the image+0x4dac5bf crashes). (2) Under VICTORY_TRACE_FREED=1 (main's native::freed from #378), a copy-back into a range the allocator freed is logged via freed::check("texture copy-back") and skipped; adds freed::overlaps. docs/native-host.md records the #339 analysis: crash shape (r8 = rcx + 0x0000ffff00000000, low 32 bits a garbage offset), the two host-side suspects, and why only these are checkable on native (zero-copy GPU writes can only be seen at resolve time; no block-level write-watch exists here).
How it was tested
cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
cargo xtask policy (387 files ok)
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory — not run in this environment (no Mac)
Ran the game — not run; a world run with VICTORY_TRACE_FREED=1 would exercise the new warnings
Checklist
No game files, game code, disassembly listings or SDK files included
Analysis/guesses marked in docs/native-host.md (#339 section)
New log lines are behind VICTORY_TRACE_FREED / the existing once-per-texture back.logged set
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by alicans on 2026-11-27T16:28:21Z.
Thanks for working on this. Two data points from a 24 GB M4 Pro:
image+0x4dac5bfsetVICTORY_TEXTURE_BACK=1, and their logs have no copy-back lines. As far as I can tell,Title::write_backonly has work with that switch on (Title::newcallscollect_writtenwith it), so neither change here would have acted in those runs.4cf84c83with #359 andVICTORY_TRACE_FREED=1logged no use of freed title memory in 81 s. It did not reach the crash either; my memory limit stopped it.Would a run with
VICTORY_TEXTURE_BACK=1andVICTORY_TRACE_FREED=1be useful for #339, or is there a path with copy-back off you'd like traced?Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:44:28Z.
Reviewed and merged locally with 384/385 together. Tests, Windows clippy, policy and the release build all pass. I haven't pushed it yet because it still needs a game run, and the machine's GPU memory was held by another run when I tried. I'll land it after that run.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T22:04:55Z.
@alicans — you are right, and the code says exactly why.
Title::write_backis reached only from the loop overtake_written(), andcollecting_written()is true only whenVICTORY_TEXTURE_BACK=1(title.rs:248sets it,host.rs:895reads it). With the switch off the host never copies a texture back into title memory at all — the onecopy_nonoverlappinginto a pool mapping innative/textures.rsis insidewrite_back— so neither skip here can run, never mind be what a crashing run needed. The freed-range half needs a second switch on top:freed::overlapsanswers false unlessVICTORY_TRACE_FREED=1, so it acts only with both set.So the honest scope of this PR: it hardens the copy-back path for runs that turn
VICTORY_TEXTURE_BACKon — the runs #46 and #449 want to become the default — and it is not an explanation of the crashes in your logs. I have added that sentence to the bullet indocs/native-host.md(f57aac7f) so nobody reads it as a fix for a default run.What your two data points do settle, though, is worth having on #339: with the switch off, a copy-back cannot be the writer that tramples a freed block's link, which leaves the other suspect — GPU work still writing a range after the title freed and reused it. That is the case the docs list as still open, and catching it needs the title's allocator to report frees, which no interface today provides.
@LakshanSivakumar — the branch has one commit after the copy you merged locally:
f57aac7f, the docs sentence above. Nothing else changed, so the merge you tested stands apart from that line; pull it before landing. Your point that this needs a game run still holds, and now the run worth doing is aVICTORY_TEXTURE_BACK=1world load: withVICTORY_TRACE_FREED=1too, the useful evidence is a "not copied back"/"skipped" line, or its absence for textures that are alive.