xmem, xcrdapi, d3d12: fix hybrid private-views aliasing and mixed buffer imports #501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/501"
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 brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T17:22:17Z.
Summary
Resolves the #456 secondary-alias,
xcrdapi, and mixed-buffer import blockers when running hybrid private views (TUXBOX_XMEM_PRIVATE_VIEWS=1), keeping private views opt-in until story-mission verification confirms before considering a default flip (#472).Rebased onto
main(2d6dc338), integrating #495 (MappingMutationGuard) and #508 (write_decoded_output), plus two additionalxmemfixes discovered during follow-up testing:xcrdapi(runtime/xcrdapi/src/access.rs,runtime/xcrdapi/src/queue.rs): Route VA destination writes (both decoded payloads viawrite_decoded_output— including #508's zlib continuation cache path — and plain VA reads, with zero-copyReadFilewhen a single contiguous canonical run is resolved) throughTuxBoxAcquirePhysicalAccess/TuxBoxReleasePhysicalBacking, while preserving #486'sunwritable()check on non-XMem fallback ranges and anyrun.address == 0chunks. Moved the XMem physical-access helpers (BackingRun,AccessHold,acquire_physical_access,copy_to_runs) intoruntime/xcrdapi/src/access.rssoqueue.rsstays under the 1,200-line repository hygiene limit.xmem(runtime/xmem/src/physical_pages/):SharedSectionwhen a second CPU (0x21) aperture mapping arrives (eager_promote_dual_cpu_aliases,promote_token_to_section), while keeping single-CPU-view +gpu_poolmappings on write-watchedMEM_PRIVATE(0shadows).secondary_alias_vehretry briefly whenERROR_BUSYis caused strictly by a transient non-import hold (!has_import_hold && !deferred_unmaps).!write) asPAGE_READONLY(mirror_readonly_secondary_alias, tracked inreadonly_secondary_aliases) when promotion returnsERROR_BUSYbecause another alias's canonical span is import-held or has deferred unmaps, while keeping secondary-alias write faults trapping insecondary_aliases.[email protected](page_imp=...,span_imp=...,span_held=...,def=...)inlog_veh_failureandlog_readonly_fallback(blocking_promotion_span/format_blocker) when another alias span blocks promotion.BackingOrigin::PrivateView(span_id)byPrivateSpanbase inruntime/xmem/src/physical_pages/backing.rsso adjacent 4 MiB OS allocations are never merged into a single cross-VMA backing run.map/map_scatterafter releasingPOOL(integrated with #495'sMappingMutationGuard).sections_only()guards incopy_mappings.rsso hybrid mode handles promotedSharedSectionGPU aliases andDeferredKind::SectionPlaceholdercleanly.d3d12(runtime/d3d12/src/device/heap/): Support per-pieceShadowPagesmirroring (open_shadow_piece+BackingGuard::with_parent) inPagePools::import_piece/import_scattered_bufferwhen a buffer spans mixedMEM_PRIVATEand promotedMEM_MAPPEDruns onsection-import=substitutedhosts instead of failing withE_NOTIMPL(0x80004001).(Kept
TUXBOX_XMEM_PRIVATE_VIEWS=1opt-in in this PR so testers can verify past the first story mission before changing the default.)Tested
GE-Proton11-14,cbb6a2df):tuxbox-xcrdapi --lib: 13 passed, 0 failed (including #486 unwritable-destination and #508 BC6H/zlib/overlapped/GDKX ABI tests).tuxbox-xmem --lib physical_pages: 36 passed, 0 failed, 1 ignored (scan_cost) (includingsecond_cpu_aperture_mapping_eagerly_promotes_unheld_page_to_section,transient_access_hold_does_not_block_secondary_alias_promotion,adjacent_private_views_in_separate_spans_are_not_merged, andsecondary_alias_read_succeeds_via_readonly_mirror_while_canonical_span_is_import_held).tuxbox-d3d12 --lib shadow: 5 passed, 0 failed.python3 -m unittest tests.test_repository_hygiene): 7 passed, 0 failed.TUXBOX_XMEM_PRIVATE_VIEWS=1on RX 6900 XT (1002:73bf):buffer-import,buffer-remap,buffer-unmap-alive,buffer-unmap-released,buffer-layout: 5/5 passed.tuxbox.py checkon RX 6900 XT (1002:73bf, Mesa RADV, GE-Proton11-14,cbb6a2df):lanes-benchmark:submit_us=115.1 roundtrip_us=153.4 copy64k_us=162.7 frame_us=256.0 frame_p99_us=463.7 shader_pipeline_us=457.4 dxil_pipeline_us=249.1), 22/22 D3D12 synthetic regression controls, and 66/66 shader translator GPU checks passed.tuxbox.py checkon AMD Raphael iGPU (1002:164e, Mesa RADV, GE-Proton11-14,cbb6a2df):1skipped;lanes-benchmark:submit_us=67.0 roundtrip_us=128.5 copy64k_us=92.2 frame_us=289.1 frame_p99_us=367.0 shader_pipeline_us=371.8 dxil_pipeline_us=220.9), 22/22 D3D12 synthetic regression controls, and 66/66 shader translator GPU checks passed.TUXBOX_XMEM_PRIVATE_VIEWS=1,2d6dc338+ rebasedcbb6a2df, offline):15,484total presents; ended only on the pre-existingTCPhost-page fault without#389).secondary aliaserrors, 0heap import failure, 0xcrdapibacking failures, and 0 MiB section/shadow buffers (section=0/0.0MiB).Fixes #456 (for
TUXBOX_XMEM_PRIVATE_VIEWS=1); related to #472.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T18:30:48Z.
We merged a batch of eleven PRs into
main(now2d6dc338), and this one was on the list, but it no longer merges cleanly. It conflicts with two PRs that went in:runtime/xcrdapi/src/queue.rs. That PR's description already flagged that whichever of the two landed second would need a rebase.runtime/xmem/src/physical_pages.rs,runtime/xmem/src/physical_pages/private_views.rsandruntime/xmem/src/tests/physical_backing.rs.I didn't want to resolve your XMem changes by hand, so I left it out. Could you rebase onto
main? Once it merges cleanly we'll run the full check on NVIDIA (RTX 4070 Ti SUPER) as well, since your runs so far are AMD only, and then merge it.Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-29T18:34:48Z.
I tested this with
TUXBOX_XMEM_PRIVATE_VIEWS=1on my RX 9060 XT (RDNA 4,1002:7590, RADV, Mesa 26.2.6, GE-Proton11-14, Linux 6.18.60), Ryzen 7 5800X with dual-channel DDR4-3600, 32 GB RAM.To avoid a full shader prep I didn't build the branch as is. My base is
main6e2c5dabwith #441 (closed since in favour of #389, which has the same root-view change plus an NVIDIA check), withruntime/xmemandruntime/xcrdapibrought up tofd636d09and this PR (f0dc9d98) on top. The Lanes self-test passes in both modes. Since today's batch merge the branch no longer merges cleanly intomain(xcrdapi/src/queue.rsand three XMem files).What changed
Compared with the default mode on the same base:
How it ended
It didn't get past the intro. It reached game time 6:14, and then died on a CPU write through a secondary alias:
The access violation followed on the same thread (write of
0x313cacf20atexe+0x4e95778).The faulting alias's own span has no hold. So I think the
ERROR_BUSYcomes from the loop over the token's other views inpromote_token_to_section, andis_transient_promotion_holdturned the retry down because one of those spans has an import hold or a deferred unmap. That would mean #456 is still reachable when a page's canonical backing is imported. I haven't confirmed which view blocked it, because the line only covers the faulting span; logging the blocking view's span and hold kind would show it.For comparison, of my default-mode runs on the same base that got that far, two ended on the title's hang watchdog at game time 3:00, and the third ran 35 minutes in the world until I stopped it.
What the shadow sync was finding (default mode, before #498)
Before that, I had counters inside the old single-threaded sync on the same base:
VirtualQueryWhat this says about the default mode:
VirtualQuerywas half the cost: about half of the old sync in the world, which #498 now removes.So for RADV, not making the shadows, as this PR does, still looks like the real fix.
Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T19:21:44Z.
@brcly Rebased onto
main(2d6dc338), resolved the conflicts with #495 (MappingMutationGuard) and #508 (write_decoded_output, with XMem physical-access helpers moved toruntime/xcrdapi/src/access.rssoqueue.rsstays under the 1,200-line hygiene limit), and force-pushed (cbb6a2df).Re-ran full
tuxbox.py checkon both RX 6900 XT (1002:73bf: 126/126 Lanes & fixtures, 22/22 D3D12 regressions, 66/66 shader GPU) and AMD Raphael iGPU (1002:164e: 125/125 Lanes & fixtures, 22/22 D3D12 regressions, 66/66 shader GPU), plus the Wine unit tests,TUXBOX_XMEM_PRIVATE_VIEWS=1buffer controls (5/5), and a 460.9s live ProjectScarlett run on2d6dc338(0shadows,0secondary-alias errors,0xcrdapifailures). Ready for your NVIDIA check when you have a moment.@gtb-sbe Thanks a lot for the RX 9060 XT test data and the shadow-sync breakdown — seeing
99.75%of shadow pages unchanged per sync really underlines why avoiding shadows underTUXBOX_XMEM_PRIVATE_VIEWS=1is the right direction on RADV.On the
ERROR_BUSYsecondary-alias fault you hit, I had hit the exact same failure pattern on a secondary-alias read (write=false) on RX 6900 XT, as well as a cross-VMA backing run issue across adjacent 4 MiBPrivateSpanallocations, so this rebased update also includes two fixes from that testing:PrivateSpanbacking-run splitting (e0ea9a05): KeysBackingOrigin::PrivateView(span_id)byPrivateSpanbase inruntime/xmem/src/physical_pages/backing.rsso adjacent OS allocations aren't merged into one cross-VMA userptr run.PAGE_READONLYmirror +blocker=diagnostic (09b0ff35): For!writefaults wherepromote_token_to_sectionreturnsERROR_BUSY,mirror_readonly_secondary_aliaspopulates the unheld secondary alias asPAGE_READONLY(keeping it insecondary_aliasesso any subsequent write still traps to promote). Bothlog_veh_failureandlog_readonly_fallbacknow also log the exact blocker view/span and hold kind you asked for:[email protected](page_imp=...,span_imp=...,span_held=...,def=...).Since
TUXBOX_XMEM_PRIVATE_VIEWS=1stays opt-in here, handlingwrite=truewhen the canonical span is held (onceblocker=confirms whether thatexe+0x4e95778write hit a sibling page in the 4 MiBPrivateSpanwithpage_imp=false, span_imp=trueor a held canonical page withpage_imp=true) can cleanly land in a focused follow-up PR without blocking the #495/#508 rebase.Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-29T19:57:41Z.
Thanks! The
blocker=line is exactly what I was missing. I'll run the rebased branch (cbb6a2df) withTUXBOX_XMEM_PRIVATE_VIEWS=1on my RX 9060 XT and post the line if the write fault comes back.For the default mode, there's news on #472: with #474, #475, #495 and #498 on my old base, the intro got past the point where it always died here. Frames went from ~21 s to ~12 s, and the game clock reached 11:28 instead of the watchdog ending it at 3:00. The numbers are in my comment there.
Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-29T20:24:15Z.
Tested on an RX 9070 XT (
1002:7550, 16 GB, RDNA 4), RADV / Mesa 26.3.1, GE-Proton11-14, Linux 7.3.6, Ryzen 7 9800X3D, 32 GB RAM, withTUXBOX_XMEM_PRIVATE_VIEWS=1. Story save, offline. The host profile reportssection-import=substituted.fd636d09without #501, default section backingfd636d09+ #501 before the rebase (f0dc9d98) + #4982d6dc338+ #501 (cbb6a2df)2d6dc338+ #501 (cbb6a2df)signaller_worker wait timed out) after the same fallback, then the title watchdogWhat #501 changes here:
cbb6a2df. Two runs isn't enough to call it gone.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T20:53:58Z.
NVIDIA run: full
python tuxbox.py checkpasses on an RTX 5090 (10de:2b85, 620.70.10, GE-Proton11-14, Linux,windows-dxc1.8.2505.1).main2d6dc338(control, same card and prefix)cbb6a2df(its base is2d6dc338)No GPU errors in the kernel log. That's the default mode; I haven't run
TUXBOX_XMEM_PRIVATE_VIEWS=1here, or the game. Main has moved since (4198b48c); I checked the PR's head, not a merge with that.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T21:41:20Z.
@NickStallman Thanks for running the RTX 5090
tuxbox.py checkverification oncbb6a2df(192/192 pass)!@gtb-sbe @brcly We also caught the exact
blocker=diagnostic for thatwrite=true#456secondary-alias fault on RX 6900 XT (after running 584.7s /15,653presents with0GPUVM faults and0shadows underTUXBOX_XMEM_PRIVATE_VIEWS=1):Note the blocker span
0xf00200000..0x1085e00000: it is a 6.09 GiB singlePrivateSpancreated bymap_private_contiguous(runtime/xmem/src/physical_pages/private_views.rs), which usesprivate_span_boundswithout splitting multi-chunk contiguous ranges intoPRIVATE_SPAN_CHUNK(4 MiB) spans. As a result, a single GPU import hold anywhere inside that 6.09 GiB contiguous reservation holds the entirePrivateSpan(span_imp=true) and blocks promoting an unheld page (page_imp=false) at0xf3c900000.Chunking
map_private_contiguousintoPRIVATE_SPAN_CHUNKspans (plus isolating/handling held canonical pages if needed) looks like the clean follow-up once#501lands.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T22:13:28Z.
Merged as
22e529cbonmain(squashed into one commit). The full check passed on an RTX 4070 Ti SUPER and a Radeon 610M. Thanks!Pull request closed