Repository navigation
d3d12-hle: arrange forgets the slice a page leaves for an unowned one (D3D12-HLE-XMEM-ARRANGE-STALE-OWNER) - #2836
Conversation
In xmem's arrange (renderer port 1, the 32-bit heap's slices in address order), a page moving to a slice that no page has left its own slice still recorded as its own in the owner map. 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 slice it leaves now has no owner. Ported from ahmetbagci's fix in Vice-Tay (fddf8c7). Co-Authored-By: ahmetbagci <6625856+ahmetbagci@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified on Windows: the crate is green with it.
That is the crate's four targets and nothing fails. What I did not do is break 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. |
KelboLive
left a comment
There was a problem hiding this comment.
The fix is right and the mutation proves it: owner is rebuilt per call as slice→page (xmem.rs:1266-1271), and when want has no page the page leaving have leaves it empty, so the map must forget have (:1290-1293) — otherwise the next page moved into have finds the departed page as its owner and swaps it back. Removing the new else reproduces 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 in table.pages, which this code does not produce (the old bug permuted pages, it did not duplicate them).
Two test nits:
- The closing
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 test pins the unowned→unowned chain; the owned-destination swap is left to the older
the_32_bit_heap_gets_its_slices_in_address_order, which still passes. That is adequate coverage, just worth knowing where each half lives.
|
RUN - VERIFY-2836-RTX4060 - by MoonEyes (another person than the author) on head
Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data. AI-assisted (Claude Code). |
|
Merging. Head AI-assisted (Claude Code). |
Claimed in the coordination issue as: D3D12-HLE-XMEM-ARRANGE-STALE-OWNER (#2570 (comment))
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