Repository navigation
d3d12_xs: queue slot 31 is CopyPageMappingsBatchX, mapped through xmem (RT-QUEUE31) - #968
Conversation
…m (RT-QUEUE31)
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.
|
Independent check: 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 |
|
Tested
|
|
@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):
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 AI-assisted. |
Root cause & fix for slot-70 views staying
|
|
Verified under Wine and Proton, which the earlier batches could not run: #968 at
Same result under both Wines. The 20 new |
Merges the local m984-on-main (1d89b20), main with ProjectLeonida#984 merged, into ProjectLeonida#968's head f2268ab. Conflicts and their resolutions: - runtime/shims/xmem.h: both sides appended to the end of rt::xmem. Kept geometry_aliases and transfer_physical from ProjectLeonida#984 and appended ProjectLeonida#968's CopyPageMappingsFn typedef and the inline copy_page_mappings_fn after them. - runtime/shims/xmem.cpp: copy_page_mappings and the self-registering g_copy_page_mappings_set stay right after XMemMapPhysicalPagesScatter, followed by ProjectLeonida#984's shadows_write_watch. One-line port: ProjectLeonida#984's g_mapped stores the page number itself (HostUnorderedMap<uintptr_t, uint64_t>), so `it->second.page` becomes `it->second`. - runtime/shims/d3d12_xs_device.cpp: - includes: ProjectLeonida#968's "xmem.h" beside "d3d12_trace.h", then ProjectLeonida#984's includes; - constants: ProjectLeonida#984's block kept, kQueueCopyPageMappingsBatchX = 31 added after kQueueExecuteCommandListsX and its static_assert; - the slot-31 section (ConsolePageRange/Batch, copy_console_page_range, queue_copy_page_mappings) goes after ProjectLeonida#984's queue_execute_command_lists and before the "PresentX is at queue slot 30" comment; - child_slot: ProjectLeonida#984's queue block kept; the slot-31 dispatch (beyond the PC table and with xmem's hook set) goes just before the qroutes lookup, ahead of the presentation routes and the console-only S_OK tail. Newer-layout PresentX is 32, so 31 does not clash. - runtime/test/xs_proxy_mock_test.cpp: - includes: "../shims/xmem.h" beside ProjectLeonida#984's d3d12_xs_frame_events.h; - ProjectLeonida#984's descriptor-heap and later checks kept, check_queue_copy_page_mappings after them. Without xmem the merged proxy answers slot 31 with the console-only S_OK, so that check's `== E_NOTIMPL` becomes `== S_OK` (and its summary line says so); - main: `|| check_queue_copy_page_mappings()` appended after check_presentation_wiring(). runtime/test/xmem_test.cpp merged without conflict: test_copy_page_mappings runs after test_physical_pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Applies the fix oscarlosu-lab proposed on ProjectLeonida#968: ProjectLeonida#968 (comment) What was wrong: queue slot 31 (CopyPageMappingsBatchX) targets the title's GPU-only reservation, but the D3D12 layer reads that memory at its paired CPU view (title_gpu_views::to_cpu). copy_page_mappings mapped the pages only at the GPU-only address, so the paired CPU view stayed reserved and the layer's reads of that memory (the slot-70 views waiting for readable memory) never became possible. The change, in copy_page_mappings: - when the destination is in a paired GPU-only range and its CPU range is a physical-page window, every page mapped or unmapped at the destination is mapped or unmapped at the CPU address as well, with that window's protection; - a source page not mapped at a GPU-only address is looked up at its CPU address. Cost: a second view per copied page, so such a page is mapped at three addresses (pool, GPU-only, CPU) and counts as aliased: the shadow tracker copies it at every submission. Risk: the pairing is a heuristic (the CPU reservation of the same size made just before the GPU-only one); if it is ever wrong, the mirror replaces the title's own mappings in that CPU range. The comment reports 9 alias checks but does not give them, so the test is new: xmem_test's test_copy_page_mappings_cpu_view reserves a CPU + GPU-only pair and checks that after a batch copy onto the GPU-only range the CPU range is committed and shows the same bytes (and a write there is one memory with the pool), that a GPU-only source mapped only at its CPU range is found there, and that a null source unmaps both ranges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- docs/linux_proton.md: the branch no longer ignores slot 31; say what it maps now (destination and paired CPU view) and the two gaps that remain. - docs/d3d12_vulkan.md, section 4.9: a row for queue slot 31 with how its argument layout was established (read statically from the executable's call site, corroborated by a public project's queue, the pool size matching a boot, as ProjectLeonida#968 states it) and the known gap (mappings apply when the call is made, not in queue order); the PresentX row's "every other queue slot" now points at it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) main now contains the ProjectLeonida#984 merge this branch was built on, plus its last commits (the five tests of ProjectLeonida#984 settled under Wine, and the title's hang watchdog staying armed by default). No conflicts: runtime/test/xmem_test.cpp and docs/d3d12_vulkan.md merged cleanly, with test_copy_page_mappings and test_copy_page_mappings_cpu_view each defined and called once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged, right after #984, which needs this to reach the story load. Thank you, @CLHelper, and @oscarlosu-lab for the CPU-view fix.
AI-assisted (Claude Code, Claude Opus 5.5). |
…the ProjectLeonida#939 merge main now holds the ProjectLeonida#984 merge (18a22c1) and ProjectLeonida#968, queue slot 31 as CopyPageMappingsBatchX. Two conflicts: the include list of d3d12_xs_device.cpp (both includes kept) and the call order in xmem_test.cpp (the two page-mapping tests of ProjectLeonida#968 run after test_physical_pages, after the early return of ProjectLeonida#939's file-pools mode). The slot 31 dispatch of ProjectLeonida#968 stays ahead of the presentation routes, so ProjectLeonida#939's rule for queue slots 30 to 32 on a device that had a presentation handler does not reach it where xmem is linked. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Fourteen commits main gained after ProjectLeonida#968: ProjectLeonida#413, ProjectLeonida#1114, ProjectLeonida#1090 and ProjectLeonida#1491. Two conflicts, both in the shader check lists: scripts/run_gpu_tests.py imports both sides' cases, and tests/test_shader_checks.py counts eight cases next to COMPUTE (main's cs_w32_salu_ext) and ProjectLeonida#939's IMAGE_STORE_CASES table in place of main's fixed seven store shaders. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claimed in the coordination issue as: RT-QUEUE31 (#14 (comment))
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)