d3d12-hle: arrange forgets the slice a page leaves for an unowned one (D3D12-HLE-XMEM-ARRANGE-STALE-OWNER) #2836
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2836"
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 ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-01T05:11:59Z.
Claimed in the coordination issue as: D3D12-HLE-XMEM-ARRANGE-STALE-OWNER (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7277198683)
What and why
arrange(d3d12/crates/leonida-hle/src/modules/xmem.rs, renderer port 1: the 32-bit heap's slices put in address order) swaps physical pages between slices of one section. When a page moves to a slice that no page has, theownermap still recorded the slice it left as that page's. A later page of the same call moving into that slice then found the first page there and swapped it back, so the first page lost the place it had just been given.The change: in that case the slice the page leaves is removed from
owner(owner.remove(&have)), so it has no owner, as is now true.This ports ahmetbagci's fix from the sibling VIctory tree (TaynanGT/Vice-Tay
fddf8c7, GPL-3.0), credited as co-author.Tested
modules::xmem::tests::arrange_forgets_the_slice_a_page_left_for_an_unowned_one: four pages, slice 1 freed, thenpages[2]moves to the free slice 1 andpages[3]into slice 2, whichpages[2]just left. Onmain(10bed9ff2) it fails (pages[2]ends back at slice 3); with the change both pages are where they were sent.cargo test -p leonida-hle --lib: 241 passed, 0 failed, 2 ignored. The existingthe_32_bit_heap_gets_its_slices_in_address_orderis unchanged and passes.cargo clippy -p leonida-hle --lib --tests: no warning in the changed lines.xmem.rs, notarrange.GPUs tested: n/a (CPU unit tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T05:37:59Z.
Verified on Windows: the crate is green with it.
main640b0d0df, cherry-picked (one commit,merge-base10bed9ff2),cargo 1.98.1:That is the crate's four targets and nothing fails. What I did not do is break
arrangeto watch a specific test fail, so this is an execution check and not a mutation one -xmem.rsgains 23 lines and the suite is green either way.What I could not test: what the page's slice being forgotten does to a title's memory, which needs the game. The unit tests are what I ran.
AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T05:58:10Z.
Review: COMMENTED
The fix is right and the mutation proves it:
owneris rebuilt per call as slice→page (xmem.rs:1266-1271), and whenwanthas no page the page leavinghaveleaves it empty, so the map must forgethave(:1290-1293) — otherwise the next page moved intohavefinds the departed page as its owner and swaps it back. Removing the newelsereproduces exactly that ([Some(3), Some(2)]against[Some(1), Some(2)]), while the head is 241 passed / 0 failed / 2 ignored.The ownership reasoning holds: the map stays a bijection over the section's occupied slices (each move removes one key and inserts one), no slice is allocated or freed, early returns (
:1242-1263) happen before any mutation, and the map is local so nothing persists across calls. I could not construct a double-free or leak path; the only way to corrupt it would be duplicate slice indices intable.pages, which this code does not produce (the old bug permuted pages, it did not duplicate them).Two test nits:
XMemFreePhysicalPages(...) == 1assertions cannot fail for ownership — that function returns1unless the pointer is null and silently drops numbers not in the table — so they are cleanup, not evidence. Asserting the pages are still inpage_table()before freeing would make the cleanup meaningful; the index assertion is the real check.the_32_bit_heap_gets_its_slices_in_address_order, which still passes. That is adequate coverage, just worth knowing where each half lives.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T08:33:25Z.
RUN - VERIFY-2836-RTX4060 - by MoonEyes (another person than the author) on head
3b5e702f8, with #2836, #2835, #2695, #2696, #2689, #2699 and #2705 merged together intomain9372a4d4f(clean).main9372a4d4fand thenmain+ the seven, one run each, same save: 0 device lost, 0 panics, 0 exceptions in both, about 490 s in the world each, alive at the time limit. Frame rate median 17.8 with the seven and 15.0 onmain, not a comparison: other work ran on the PC during themainrun.main9372a4d4f+ the seven (Windows): leonida-hle 243, leonida-gpu 602, leonida-formats 47, leonida 47, leonida-shader 403 of 405: twosource_hash_testsfailed on a stale build script of mine (a target folder shared with an older branch) and pass after a rebuild of it (3 of 3).Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T08:55:42Z.
Merging. Head
3b5e702f8merges cleanly withmainad7c62edband does not force a rebase of #2566. CI green on this head and on main. In-game run on the RTX 4060 posted above (this head, with the six others, about 490 s in the world, 0 device lost, pictures compared with main). Tests on main + the seven: leonida-hle, leonida-gpu, leonida-formats, leonida, leonida-shader, 0 failed. Verified on it by fiestorra (Windows) and KelboLive (mutation). Merged by MoonEyes.AI-assisted (Claude Code).