d3d12_xs: queue slot 31 is CopyPageMappingsBatchX, mapped through xmem (RT-QUEUE31) #968
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!968
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/968/head"
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?
@CLHelper on GitHub · 2026-11-24 16:02 UTC · original
CLHelper:runtime/queue-slot31→main· +370 −7 · 7 files · 5 commits · merged 2026-11-25 01:43 UTCClaimed in the coordination issue as: RT-QUEUE31 (#14)
What and why
The retail title calls its command queue's slot 31, one of the console-only slots past
ID3D12CommandQueue, asCopyPageMappingsBatchX(count, batches, pool, pool pages, flags).mainrefuses it withE_NOTIMPL(theXboxID3D12CommandQueue::Slot31 unsupportedlines 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.+0xf2ca74fills a batch as{UINT64 destination; UINT32 range count; const range* ranges}(24 bytes) and a range as{UINT32 kind, start, count}(12 bytes).start, start + 1, ...; 1 maps pool pagestartat every destination page; 2 leaves the destination unmapped; 3 leaves it as it is. Each range moves the destination on bycountpages.copy_page_mappings; there the newer layout has every slot from 14 on two later than older titles, so their 29 is this 31).XMemAllocatePhysicalPagescall.The change:
xmem.cpp:copy_page_mappings(exposed asrt::xmem::copy_page_mappings_fninxmem.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 twoXMemMapPhysicalPagescalls 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 returnsS_OKwhen every range was applied andE_INVALIDARGwhen 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, socheck_tailis 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 (
XMemMapPhysicalPagesScatterat+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
XMemMapPhysicalPageswindow; this pull request does not change that.Tested
Native Windows 11, MSVC 19.44 (VS 2022 Build Tools), Ninja, RelWithDebInfo, on
main3d3770c16(rebased ontoa28927849, a docs-only change):xmem_test: newtest_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: newcheck_queue_copy_page_mappingswith 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.repeat_firstfailsxmem_test; not moving the destination on for kind 3 failsxs_proxy_mock_test.boot-prototypefa497b930with 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)The retail title calls its command queue's slot 31 (game_scarlett_master.exe+0xf2cc7f) with a batch count, 24-byte batches {destination, range count, ranges}, the base and page count of its physical-page pool, and 0. Each 12-byte range {kind, start, count} maps pool pages at the destination: 0 a run, 1 one page repeated, 2 unmapped, 3 unchanged. main refused the slot with E_NOTIMPL; the title does not test the result and goes on to read the destinations. Each range now reaches rt::xmem::copy_page_mappings_fn, which maps the physical page behind every source page at its destination page (a second view of the same section, so both addresses are one memory) and unmaps where the source has nothing or the kind is 2. The hook is set by xmem.cpp; tests that compile the proxy alone keep the old refusal. Tests: xmem_test (a run, one page repeated, an unmapped source page, a null source, an overlapping range, bad addresses) and xs_proxy_mock_test (the four kinds, a range past the pool, an unknown kind, xmem refusing, no xmem). AI-assisted.@Snooozs on GitHub · 2026-11-24 17:39 UTC · original
Independent check:
xs_proxy_mock*(6) andxmempass; merged together with #958 they also pass (7/7). With #969 there is a textual conflict inruntime/shims/xmem.honly: both add a hook at the end of the namespace.One question from reading: the call is a queue operation, but the mappings change at once on the calling thread, while work submitted earlier on that queue may still be reading the old mapping. Is that known to be safe for the title's use (for example because it fences first), or should it wait for the queue's submitted work? I have no measurement either way.
Windows 10 Pro 22H2 (19045), VS 2022 RelWithDebInfo, merged onto
main32950551ewithout conflicts, targets rebuilt, CPU only, no game files. AI-assisted (Claude Code): I read the whole diff and ran this on that machine.@oscarlosu-lab on GitHub · 2026-11-24 18:14 UTC · original
Tested
f2268abea(RT-QUEUE31,CopyPageMappingsBatchX) cherry-picked onto#984(ac7c3449d) on native Windows 11 (MSVC 19.52 x64RelWithDebInfo,-DLEONIDA_SDL3_FETCH=ON, RTX 3060 12 GB driver621.35, 32 GB RAM):xmem_test.exe: OK (316 checks), including allcopy_page_mappingsandCopyPageMappingsBatchXtests.421 s,28352translated shaders, localhistory.bcph):queue slot 31 (CopyPageMappingsBatchX) first call: 1 batch(es), pool 0x... of 63632 pagesXboxID3D12CommandQueue::Slot31calls logged, 0 refusal /not mappederrors.PresentX ok 9000, failed 0,0device loss,40/40non-black captures (brightest 168.77 144.08 126.01).t=95s game=3 session=d(remained atsession=dthrought=415s).@CLHelper on GitHub · 2026-11-24 18:35 UTC · original
@Snooozs thanks for the check, and @oscarlosu-lab for the retail run on #984 (46 calls, 0 refusals on a 12 GB card; on my 8 GB laptop the same port handled every call too).
On ordering: you are right that this applies the mappings at call time, while on the console the batch is a queue operation and takes effect in queue order. What I can say from the executable (static, my own 1.0.2.1 copy):
+0xf2c470), the call to slot 31 (+0xf2cc7f) comes right afterXMemMapPhysicalPagesScatter(+0xf2cc3e), which remaps pool pages on the CPU at once, and there is no fence wait between them in that function. So the title itself does not drain the queue there.So it is a known gap, and I will put it in the description. If it shows up as corruption, the strict version is to apply each batch when the queue reaches it (signal a fence after the work already submitted, apply on its completion, and hold the next submission on that queue until it is applied). I would rather add that with a run that shows the difference than without one; if you or anyone sees stale or torn pages that fit this, tell me and I will do it in this pull request.
On #969: the
xmem.hconflict is only the two hooks at the end of the namespace; whichever lands second keeps both.AI-assisted.
@oscarlosu-lab on GitHub · 2026-11-24 19:30 UTC · original
Root cause & fix for slot-70 views staying
MEM_RESERVEafterCopyPageMappingsBatchX(tested on Windows 11, RTX 3060 12 GB, #984 + #968)On Windows, the title reserves a CPU-mappable view and a paired GPU-only view of the same size (
title_gpu_views::note_reservation), andCopyPageMappingsBatchX(queue slot 31) targets the GPU-only view. Becausecopy_page_mappingsonly mapped physical pages ontodestination, the paired CPU view stayedMEM_RESERVE(Protect = 0), sotexture_memory_readable()(d3d12_vulkan_device.cpp) kept waiting on those slot-70 texture views.Minimal diff (
runtime/shims/xmem.cpp)Mirror
map_page/unmap_pageontoleonida::title_gpu_views::to_cpu(to, pages * kPhysicalPageSize)whencpu_to != toand a window exists for the CPU alias, and fall back toto_cpu(src_va)when looking up source pages ing_mapped:Measured impact (RTX 3060 12 GB, Windows 11, over PR #984 + #968)
xmem_test.exe: OK (325 checks), including 9 new checks verifyingVirtualQuery == MEM_COMMIT, bidirectional read/write coherence, and mirrored unmapping on a paired CPU + GPU-only reservation.420 s,LEONIDA_SKIP_INT3=1):slot-70 views awaiting readable memory: 86 → 40 (-53.5%)over memory not readable yet: 64 → 26 (-59.4%), with 562 made, 2,309 fills (6,618.6 MiB, 0 failed),PresentX ok 8912, failed 0,40/40non-black captures.session=d(noExecuteIndirectwithin 420 s). In a separate130 sdiagnostic run checkingfound == 0incopy_page_mappings, 0 calls had missing source pages (g_mappedhit every source page in those first 130 s, though later calls past 130 s were not sampled), so the remaining 26 unreadable views appear to be ranges not yet mapped byCopyPageMappingsBatchX/XMemMapPhysicalPages.@azsekazvamdimitar on GitHub · 2026-11-24 20:10 UTC · original
Verified under Wine and Proton, which the earlier batches could not run: #968 at
f2268abea, merged onmain6293c1c4f, clang-cl + xwin cross build, RTX 3090 (NVIDIA 590.48.01), WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11).mainmain+ #968main+ #968 + #983xmemxs_proxy_mockand its five variants (no_reserve,no_protect,no_handler,env_slots,env_slots_invalid)Same result under both Wines. The 20 new
copy_page_mappingschecks pass under Wine. The two failures are the onesmainhas: Wine raises no fault on a reserve-only view, so the first touch never commits the page (a mapped page is a read-write view with the window's protection,the page mapped there is a plain read-write view). #983 handles them, and with it merged too the run is green. The two merge cleanly. Not run on Windows or with the retail package. AI-assisted.@aslan2142 on GitHub · 2026-11-25 01:43 UTC · original
Merged, right after #984, which needs this to reach the story load. Thank you, @CLHelper, and @oscarlosu-lab for the CPU-view fix.
mainincluding #984 by merging, not rebasing: your commitf2268abeais untouched and nothing was force-pushed. On that treeg_mappedstores the page number itself, soit->second.pagebecameit->second; the rest went in by placement (the slot 31 dispatch sits ahead of the presentation routes and the console-only tail).S_OK, notE_NOTIMPL, so the first check incheck_queue_copy_page_mappingsexpectsS_OK.copy_page_mappingsalso maps and unmaps attitle_gpu_views::to_cpu(destination), and looks a source page up there. The comment's alias checks were not posted, so a newxmem_testcase checks that after a batch copy the paired CPU address reads the same bytes, that a write there is the same memory as the pool, that a source mapped only at its CPU address is found, and that a null source unmaps both; with the fix reverted, three of those checks fail on both devices.map_pageandunmap_pagealready report to the page aliases and the geometry-write tracking.xs_proxy_mockfailed once on llvmpipe under load and passes alone (it has done so before).queue_proxy,device_proxyand everyxs_proxy_mockvariant pass on both devices. After the merge withmainincluding #984 (18a22c1ae), the full suite on both devices matches #984's own final run exactly (306 pass and 12 fail on llvmpipe, 301 and 18 on the iGPU, 0 changed), and all 14 tests this PR touches pass on both, including the threexmemtests.docs/linux_proton.mdanddocs/d3d12_vulkan.mdnow describe slot 31 as handled.AI-assisted (Claude Code, Claude Opus 5.5).