[PR #968] [MERGED] d3d12_xs: queue slot 31 is CopyPageMappingsBatchX, mapped through xmem (RT-QUEUE31) #1006

Closed
opened 2026-11-26 20:19:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/968
Author: @CLHelper
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: runtime/queue-slot31


📝 Commits (5)

  • f2268ab d3d12_xs: queue slot 31 is CopyPageMappingsBatchX, mapped through xmem (RT-QUEUE31)
  • 6fdeadf Merge main with #984 into RT-QUEUE31 (#968)
  • 255f170 xmem: map slot-31 copies at the GPU-only range's paired CPU view too
  • 7fcbf1f docs: queue slot 31 (CopyPageMappingsBatchX) is handled
  • c551073 Merge main (with #984) into RT-QUEUE31 (#968)

📊 Changes

7 files changed (+370 additions, -7 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+2 -1)
📝 docs/linux_proton.md (+9 -5)
📝 runtime/shims/d3d12_xs_device.cpp (+87 -0)
📝 runtime/shims/xmem.cpp (+56 -0)
📝 runtime/shims/xmem.h (+8 -0)
📝 runtime/test/xmem_test.cpp (+124 -0)
📝 runtime/test/xs_proxy_mock_test.cpp (+84 -1)

📄 Description

Claimed in the coordination issue as: RT-QUEUE31 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136768155)

What and why

The retail title calls its command queue's slot 31, one of the console-only slots past ID3D12CommandQueue, as CopyPageMappingsBatchX(count, batches, pool, pool pages, flags). main refuses it with E_NOTIMPL (the XboxID3D12CommandQueue::Slot31 unsupported lines in the #432 and #602 runs). The title does not test the result: it goes on to use the destinations as if the pages were mapped there.

The shape, read statically from my own 1.0.2.1 copy (RVAs and instruction shapes only):

  • game_scarlett_master.exe+0xf2cc7f: call [vtable + 0xf8] with EDX the batch count, R8 the batches, R9 the base of the title's physical-page pool, the pool's size in 64 KiB pages as the fifth argument and 0 as the sixth.
  • +0xf2ca74 fills a batch as {UINT64 destination; UINT32 range count; const range* ranges} (24 bytes) and a range as {UINT32 kind, start, count} (12 bytes).
  • Kinds: 0 maps pool pages start, start + 1, ...; 1 maps pool page start at every destination page; 2 leaves the destination unmapped; 3 leaves it as it is. Each range moves the destination on by count pages.
  • The same call shape is in VIctory's queue (copy_page_mappings; there the newer layout has every slot from 14 on two later than older titles, so their 29 is this 31).
  • In a boot, the pool size argument equals the page count of the title's own XMemAllocatePhysicalPages call.

The change:

  • xmem.cpp: copy_page_mappings (exposed as rt::xmem::copy_page_mappings_fn in xmem.h) maps at each destination page the physical page that is mapped at its source page, as a second view of the same section, so both addresses are one memory, exactly what two XMemMapPhysicalPages calls with one page give. Every source page is looked up before any destination page changes, so an overlapping range maps what was there before. A source page with nothing mapped, or a null source, leaves the destination unmapped.
  • d3d12_xs_device.cpp: queue slot 31 walks the batches and hands each range to that hook. It returns S_OK when every range was applied and E_INVALIDARG when one was refused (outside the pool, an unknown kind, or xmem refusing it, logged once). When xmem is not linked (tests that compile the proxy alone) the slot is refused as before, so check_tail is unchanged.

Known gap (raised in review): the mappings change when the call is made, while on the console the batch takes effect in queue order. The title does not drain the queue before the call in the function that makes it (XMemMapPhysicalPagesScatter at +0xf2cc3e, then slot 31 at +0xf2cc7f); whether earlier work can still read a destination page then is not measured. A strict version would apply each batch when the queue reaches it.

Not in scope: the console maps GPU page tables, the layer maps CPU views. Whether the GPU sees a destination page follows from how that window reaches the GPU, the same as for any XMemMapPhysicalPages window; this pull request does not change that.

Tested

Native Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, on main 3d3770c16 (rebased onto a28927849, a docs-only change):

  • xmem_test: new test_copy_page_mappings (a run, one page repeated, a run ending in an unmapped pool page, a null source, an overlapping range, a destination outside any window, unaligned destination and source); a write through the destination is read back through the pool. All checks pass.
  • xs_proxy_mock_test: new check_queue_copy_page_mappings with a recording stand-in for the hook (the four kinds, the destination moving on past a kind-3 range, a range past the pool, an unknown kind, xmem refusing, no batches, and the old refusal without xmem). PASS.
  • Mutation check: making xmem ignore repeat_first fails xmem_test; not moving the destination on for kind 3 fails xs_proxy_mock_test.
  • On the retail boot (RTX 4060 Laptop, NVIDIA 576.80, @DadaCap's boot-prototype fa497b930 with an earlier local version of the same mapping): by the 32nd call every page the title sent was handled (3,150 mapped, 211 unmapped, none refused). What it changes further on I cannot say yet: on that machine the run ends at about 25 s on a lost Vulkan device first, which this does not touch.

GPUs tested: none needed for the two tests (no GPU); the boot above on an RTX 4060 Laptop, NVIDIA 576.80, Windows 11.

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/968 **Author:** [@CLHelper](https://github.com/CLHelper) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `runtime/queue-slot31` --- ### 📝 Commits (5) - [`f2268ab`](https://github.com/ubiquitarianism/leonida/commit/f2268abeadb9c57f675c43805a622d5e43628739) d3d12_xs: queue slot 31 is CopyPageMappingsBatchX, mapped through xmem (RT-QUEUE31) - [`6fdeadf`](https://github.com/ubiquitarianism/leonida/commit/6fdeadfe509f37203317a967bf28e57fc75676b2) Merge main with #984 into RT-QUEUE31 (#968) - [`255f170`](https://github.com/ubiquitarianism/leonida/commit/255f17001705101aa2e484b9e2caaf1daab275e3) xmem: map slot-31 copies at the GPU-only range's paired CPU view too - [`7fcbf1f`](https://github.com/ubiquitarianism/leonida/commit/7fcbf1fde67dffb641e0fa018aca80c15558561c) docs: queue slot 31 (CopyPageMappingsBatchX) is handled - [`c551073`](https://github.com/ubiquitarianism/leonida/commit/c5510733e9696cac6f3839b472e517725607c1d5) Merge main (with #984) into RT-QUEUE31 (#968) ### 📊 Changes **7 files changed** (+370 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+2 -1) 📝 `docs/linux_proton.md` (+9 -5) 📝 `runtime/shims/d3d12_xs_device.cpp` (+87 -0) 📝 `runtime/shims/xmem.cpp` (+56 -0) 📝 `runtime/shims/xmem.h` (+8 -0) 📝 `runtime/test/xmem_test.cpp` (+124 -0) 📝 `runtime/test/xs_proxy_mock_test.cpp` (+84 -1) </details> ### 📄 Description Claimed in the coordination issue as: RT-QUEUE31 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7136768155) ### What and why The retail title calls its command queue's slot 31, one of the console-only slots past `ID3D12CommandQueue`, as `CopyPageMappingsBatchX(count, batches, pool, pool pages, flags)`. `main` refuses it with `E_NOTIMPL` (the `XboxID3D12CommandQueue::Slot31 unsupported` lines in the #432 and #602 runs). The title does not test the result: it goes on to use the destinations as if the pages were mapped there. The shape, read statically from my own 1.0.2.1 copy (RVAs and instruction shapes only): - `game_scarlett_master.exe+0xf2cc7f`: `call [vtable + 0xf8]` with EDX the batch count, R8 the batches, R9 the base of the title's physical-page pool, the pool's size in 64 KiB pages as the fifth argument and 0 as the sixth. - `+0xf2ca74` fills a batch as `{UINT64 destination; UINT32 range count; const range* ranges}` (24 bytes) and a range as `{UINT32 kind, start, count}` (12 bytes). - Kinds: 0 maps pool pages `start, start + 1, ...`; 1 maps pool page `start` at every destination page; 2 leaves the destination unmapped; 3 leaves it as it is. Each range moves the destination on by `count` pages. - The same call shape is in VIctory's queue (`copy_page_mappings`; there the newer layout has every slot from 14 on two later than older titles, so their 29 is this 31). - In a boot, the pool size argument equals the page count of the title's own `XMemAllocatePhysicalPages` call. The change: - `xmem.cpp`: `copy_page_mappings` (exposed as `rt::xmem::copy_page_mappings_fn` in `xmem.h`) maps at each destination page the physical page that is mapped at its source page, as a second view of the same section, so both addresses are one memory, exactly what two `XMemMapPhysicalPages` calls with one page give. Every source page is looked up before any destination page changes, so an overlapping range maps what was there before. A source page with nothing mapped, or a null source, leaves the destination unmapped. - `d3d12_xs_device.cpp`: queue slot 31 walks the batches and hands each range to that hook. It returns `S_OK` when every range was applied and `E_INVALIDARG` when one was refused (outside the pool, an unknown kind, or xmem refusing it, logged once). When xmem is not linked (tests that compile the proxy alone) the slot is refused as before, so `check_tail` is unchanged. Known gap (raised in review): the mappings change when the call is made, while on the console the batch takes effect in queue order. The title does not drain the queue before the call in the function that makes it (`XMemMapPhysicalPagesScatter` at `+0xf2cc3e`, then slot 31 at `+0xf2cc7f`); whether earlier work can still read a destination page then is not measured. A strict version would apply each batch when the queue reaches it. Not in scope: the console maps GPU page tables, the layer maps CPU views. Whether the GPU sees a destination page follows from how that window reaches the GPU, the same as for any `XMemMapPhysicalPages` window; this pull request does not change that. ### Tested Native Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, on `main` `3d3770c16` (rebased onto `a28927849`, a docs-only change): - `xmem_test`: new `test_copy_page_mappings` (a run, one page repeated, a run ending in an unmapped pool page, a null source, an overlapping range, a destination outside any window, unaligned destination and source); a write through the destination is read back through the pool. All checks pass. - `xs_proxy_mock_test`: new `check_queue_copy_page_mappings` with a recording stand-in for the hook (the four kinds, the destination moving on past a kind-3 range, a range past the pool, an unknown kind, xmem refusing, no batches, and the old refusal without xmem). PASS. - Mutation check: making xmem ignore `repeat_first` fails `xmem_test`; not moving the destination on for kind 3 fails `xs_proxy_mock_test`. - On the retail boot (RTX 4060 Laptop, NVIDIA 576.80, @DadaCap's `boot-prototype` `fa497b930` with an earlier local version of the same mapping): by the 32nd call every page the title sent was handled (3,150 mapped, 211 unmapped, none refused). What it changes further on I cannot say yet: on that machine the run ends at about 25 s on a lost Vulkan device first, which this does not touch. GPUs tested: none needed for the two tests (no GPU); the boot above on an RTX 4060 Laptop, NVIDIA 576.80, Windows 11. AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:46 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1006
No description provided.