xmem: back physical pages with private memory and export backing holds #258
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/258"
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-26T18:18:00Z.
Implements the
runtime/xmem/half of #191 so RADV can import XMem physical pages directly viaVK_EXT_external_memory_hostwithout hitting libdrm'sAMDGPU_GEM_USERPTR_ANONONLYrejection or falling back to the #200 shadow copy. Pairs with #218 (already onmain) and #253.Part of #191
Summary
MEM_PRIVATE,PAGE_READWRITE):MEM_PRIVATEpages inside placeholder apertures rather than section views (runtime/xmem/src/physical_pages/private_views.rs,runtime/xmem/src/shared_pages.rs).SharedSectionso existing multi-view CPU aliases remain coherent.PrivateArena(VirtualAllocMEM_PRIVATE).runtime/xmem/src/physical_pages/backing.rs):TuxBoxAcquirePhysicalBacking,TuxBoxAcquirePhysicalBackingRuns, andTuxBoxReleasePhysicalBackingasPRIVATEsymbols inruntime/xmem/xmem.def.TuxBoxReleasePhysicalBacking(hold)drops the last reference, keeping importedMEM_PRIVATEhost pages valid across live GPU submissions.runtime/xmem/src/tests/physical_backing.rs):ERROR_NOT_FOUNDon foreign memory, held CPU views surviving unmap/free,PrivateArena+ conflicting-orderBackingRunsplitting +ERROR_MORE_DATA, and lazySharedSectionpromotion on a second CPU view.Verification
Tested on RX 6900 XT (
1002:73bf), Linux (7.3.6-1-cachyos), GE-Proton11-14 (1795427215), RADV:cargo check --locked --target x86_64-pc-windows-msvc --manifest-path runtime/xmem/Cargo.toml: passed (0 warnings)cargo test --locked --target x86_64-pc-windows-msvc --manifest-path runtime/xmem/Cargo.toml -- --test-threads=1: 4/4 passed (physical_pages::backing::tests)python -m unittest tests.test_repository_hygiene: 5/5 passedtools/check_d3d12_regressions.py --case buffer-remap --adapter 1002:73bf:PASS(4.418s,d3d12-buffer-remap PASS pci=1002:73bf words=768/768 identical=1 replacement=1,null_fallback_enabled: false)TuxBox d3d12_xs: game memory is imported through its XMem backingand threepath=importedentries, with zerocopied for the GPUmessages.tuxbox.py check --adapter 1002:73bf: all 10 groups passed:Lanes and fixtures on the GPU: 72/72 passed (170s, includingxmem-pagesandxmem-scatter)D3D12 regression controls: 19/19 passed (85s)Shader translator on the GPU: 40/40 passed (238s)Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-26T18:38:30Z.
ProjectScarlett run on the RX 6700 XT without the preload, as asked on #191. Short version: with this PR's
xmem.dllthe title hangs during start-up, before the first frame, so I can't say anything yet about the remap.Setup: RX 6700 XT (
1002:73df), Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline, shaders prepared, noLD_PRELOAD. Bothxmem.dllandd3d12_xs.dllrebuilt and staged for each row.main5c5677b(this PR's base)5c5677b+ this PR (cd8ad92)5c5677b+ this PR + #253 (f9b630d)What the failing runs have in common
Game State: System Init,Frame: 0. The stack isgame_scarlett_master.exe+0x2215C35←+0x2215ECA, which is the 30 s main-thread watchdog from #215. So the main thread stopped making progress about 20 to 30 s after launch and the watchdog ended the run.prepared compute shader loaded …,created compute pipeline with 6 reflected FSSM descriptor slots,memory wait trace #1 …andsubmitted first guest batch. With this PR none of them appear.game memory is imported through its XMem backingis never logged, the host profile issection-import=substituted, and there is no page remap and no rejected submit. It doesn't get as far as an import.I don't have a stack for the hung thread, only the watchdog's, so I can't say where it is waiting. Since the provider is identical in rows 1 and 2, it is something the title does through XMem between creating that first raster pipeline and its first compute pipeline.
tuxbox.py checkwas not part of this; I only ran the game. If it helps I can rerun with any tracing you want switched on (for example a log line per XMem export call), or try a branch.Update, same day: the runs above shared the machine with other GPU tests of mine, so I repeated them with nothing else running (no other Proton guest or compile in any 5 s sample, load below 5), alternating the two trees:
5c5677b+ this PR5c5677b5c5677b+ this PRSame crash log and same last provider line. So it is not a load effect: five of five runs with this PR's
xmem.dllhang at start-up, and both runs without it don't.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-26T18:53:26Z.
Thanks @JeffreyBytes for running that and catching the
System Inithang! We reproduced the exact same 30 s watchdog crash (game_scarlett_master.exe+0x2215C35right aftercreated pipeline from Xbox slot 86 stream) locally on RX 6900 XT withcd8ad92.Moving this PR to Draft while we track down the root cause in
xmemand verify the fix locally before marking it ready again.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-26T20:29:20Z.
Updated in
80e55e1— @JeffreyBytes this is ready for another test on your RX 6700 XT (keeping the PR as Draft until confirmed).Root causes & fixes
System Inithang (runtime/xmem):map_cpu_pagewas eagerly promoting ~99,776 pages out of the large GPU allocation in a loop. Switched partial unmaps/remaps insidePrivateSpanto in-placeMEM_DECOMMIT/MEM_COMMIT, tracked CPU vs GPU apertures viaXMemVirtualAlloc, and left secondary views asPAGE_NOACCESSwith a Vectored Exception Handler (AddVectoredExceptionHandler) for lazySharedSectionpromotion on CPU access.runtime/d3d12): A/B testing againstmaincaught a green video screen whend3d12_xsread or validated GPU-aperture addresses directly viaReadProcessMemory/WriteProcessMemory/VirtualQueryagainstGpuAliasorPAGE_NOACCESSviews. Updatedsnapshot_mip,write_mapped,validate_shared_range, and CBV/resource mirror snapshots to resolve XMem physical backings (TuxBoxAcquirePhysicalBackingRuns/TuxBoxAcquirePhysicalBacking).Verification (
80e55e1)cargo check(tuxbox-xmemandtuxbox-d3d12,x86_64-pc-windows-msvc): passed (0 warnings)tuxbox-xmem(7/7passed) andtuxbox-d3d12device::heap::backing(6/6passed)python -m unittest tests.test_repository_hygiene:5/5passedbuffer-remapon RX 6900 XT (1002:73bf,GE-Proton11-14):PASS(words=768/768,null_fallback_enabled: false,game memory is imported through its XMem backing)GE-Proton11-14): passedSystem Init, imports game memory through its XMem backing, and UI + video launch cleanly.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-26T22:07:32Z.
Rebased cleanly onto
origin/main(e76ff6a) as5a795cb(reusing #253'sTuxBoxAcquirePhysicalBackingRunsinruntime/d3d12/src/device/heap/backing.rs) and marked Ready for review.First, sorry @JeffreyBytes for asking you to test the initial revision before we had run it locally ourselves, and thank you for catching the
System Inithang and calling outsnapshot_mip(ReadProcessMemory) on #191 — our A/B test againstmaincaught a green screen on video playback from that exact path (runtime/d3d12now resolves XMem physical backings forsnapshot_mip,write_mapped,validate_shared_range, and CBV/resource mirrors).Real-world RX 6900 XT (
GE-Proton11-14) results vsmain(5c5677b)main(shadow-copy fallbackgame memory is copied for the GPU), presentation dropped to9frames in 10s (~0.9 FPS) once hitting the intro; with zero-copy XMem backing import (game memory is imported through its XMem backing), it sustained464–503frames in 10s (~46–50 FPS) through the menu and intro video.DispatchMesh), and reachedGame Running(Frame: 5215,TileHeap: 2112Mb / 6236Mb,Streaming Requests: 3608,7,319buildings,213vehicles,48peds,4,274objects).Game Running(exit code 3): hitVK_ERROR_DEVICE_LOST(vr -4) fromradv: GPUVM fault detected at address 0x8004914e0000right aftervkd3d-proton:vkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory, with zeroamdgpukernel hang/reset and no host-pointerEFAULT— confirming XMem backings and holds stayed intact intoGame Running.Verification (
5a795cb)cargo check --locked --target x86_64-pc-windows-msvc(runtime/xmem&runtime/d3d12): passed (0 warnings)tuxbox-xmem(7/7passed) andtuxbox-d3d12device::heap::backing(11/11passed,162filtered)python -m unittest tests.test_repository_hygiene:5/5passedbuffer-remapon RX 6900 XT (1002:73bf,GE-Proton11-14):PASS(4.374s,words=768/768 identical=1 replacement=1,null_fallback_enabled: false,game memory is imported through its XMem backing,buffer backing path=imported)Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-26T22:16:09Z.
Independent NVIDIA control run for
5a795cbon maine76ff6a: RTX 4080 (10de:2704), NVIDIA 620.73.4, GE-Proton11-14. Rebuilt XMem, D3D12 provider, XMem guests and Lanes. Six isolated D3D12 memory controls passed: buffer-remap, buffer-layout, buffer-import, buffer-import-reject, buffer-unmap-alive, buffer-unmap-released (2,816 checked words in first three, no stand-ins). Fresh-prefix 15/15 selected guest gates: all 12 XMem gates, heaps, tables, Lanes replay. This verifies NVIDIA synthetic compatibility, not the AMD performance claim or retail execution. No changes to your PR branch.Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-26T22:55:10Z.
Retest on the RX 6700 XT, no preload, nothing else running on the machine:
80e55e1once, then5a795cb(one76ff6a, with #253) twice. The start-up hang is gone and the game runs at full speed without the preload for the first time on this card. All three runs still lose the device on the story loading screen, with a different error than the preload gave.Setup: as above (
1002:73df, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline, shaders prepared, 3840x2160).xmem.dllandd3d12_xs.dllrebuilt and staged for each commit.What works now
System Init, reaches the Account Picker and, after A, the story loading screen with its artwork.game memory is imported through its XMem backingand, on5a795cb,game memory is imported through non-contiguous XMem backingsare logged.80e55e15a795cbrun 15a795cbrun 2For comparison, the copy path on
maingives about 6 per 10 s here.What still fails
80e55e15a795cbrun 15a795cbrun 2The order of events is the same in all three:
There is no
GPUVM faultline in any of the three, so this is not the fault from your RX 6900 XT run, and it happens earlier: none of these runs left the loading screen.The error code is the difference from the preload runs, which stopped at the same remap batch with
-14(EFAULT, nothing mapped under a live import). Here it is-1(EPERM). My reading, not checked against your code: the ranges under live imports stay mapped now, so the hold is doing its part, but at some point after the remap batch one of them has a file behind it (a section view, or a page promoted toSharedSectionon a CPU access), and the kernel's anonymous-only check refuses it when it revalidates that userptr buffer on a later submit. That is theANONONLYbranch inamdgpu_ttm_tt_get_user_pages(), which returns-EPERM; every submit carries every live import, so one such range is enough. The delay after the remap batch would fit a lazy promotion more than the remap itself.If that is right, the rule would be that an address a held backing still covers stays private memory until the hold is released, whatever a remap or a promotion wants to put there.
Two other things from the logs, in case they are useful:
RtlReleaseSRWLockExclusive Lock … is not owned exclusive!appears about 2,400 to 3,200 times per run with this PR, against about 520 per run onmainwith the preload. I have not looked at which lock it is.vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000eonce per run, about a second after device creation and before the first backing import. I assume that is the host profile's section probe. Run 1 on5a795cbhad a second one between the remap batch and the device loss; run 2 did not.Happy to rerun on a new commit, or with extra logging if you want to see which range is refused; the whole cycle takes about five minutes.
Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-26T23:42:23Z.
Thanks @JeffreyBytes for the detailed 3-run RX 6700 XT logs — especially noting that
5a795cbrun 2 hitCS has been rejected (-1)with no secondvkd3d_import_host_memorywarning. That pointed directly to a backing-lifetime / VMA-protection race on already-imported userptr BOs rather than a failed import.Pushed
0e927bewith four fixes addressing that:ID3D12Heap(d3d12BackingGuard):vkd3d-proton'sd3d12_resource_destroytears downresource->private_storebefore callingd3d12_heap_decref(resource->heap)(vkFreeMemory). KeepingHold/ShadowPagesonly onImportedHeap(attached to the resource) allowed host backings to be decommitted or freed while the RADV userptr BO was still in the global BO list, causing subsequent CS submissions to fail in the kernel with-EPERM(-1).BackingGuardis now attached via a cycle-freeIUnknownmarker directly on each nativeID3D12Heap(including every piece heap in scatteredCreateReservedResourceimports) viaSetPrivateDataInterface.PAGE_NOACCESS(xmemprivate_views.rs): When a deferred-unmap or remapped slot still has an active GPU hold (has_hold(va, va + PAGE)),apply_slot_role,map_private_page, andmap_private_contiguousnow leave itPAGE_READWRITEand out ofsecondary_aliasesinstead of flipping a live userptr page toPROT_NONE.xmembacking.rs):resolve_backingsnow returnsERROR_INVALID_ADDRESS(instead ofERROR_NOT_FOUND) when an unmapped range falls insidedeferred_unmapsor an XMem aperture sod3d12cannot create an unpinnedhold: Nonedirect import over a page about to be decommitted; runs no longer coalesce across distinct backing origins (PrivateView, distinctPrivateArenas,SharedSection); andflush_deferred_unmapsrestoresdeferred_unmaps/span.deferredstate if unmap/decommit fails.validate_shared_range(d3d12heap.rs): Revertedvalidate_shared_rangeto strictMEM_COMMIT+PAGE_READWRITE, keeping the XMem backing exemption scoped toplace_gpu_target.Verification (
0e927be)tuxbox-xmem(10/10pass),tuxbox-d3d12device::heap::backingon RADV (13/13pass, includingplaced_resource_keeps_backing_hold_alive_after_imported_heap_dropsandadjacent_placeholder_private_spans_import_check),tests.test_repository_hygiene(5/5pass).tools/check_d3d12_regressions.py, RX 6900 XT1002:73bf, GE-Proton11-14):buffer-remapPASS (words=768/768, zero-copy XMem backing) andbuffer-unmap-releasedPASS (later-submits=ok).1002:73bf, Mesa RADV 26.3.1, Linux7.3.6-1-cachyos, GE-Proton11-14):radv/amdgpu: The CS has been rejected, 0VK_ERROR_DEVICE_LOST, 0GPUVMfaults across all 3 runs.page remapbatches cleanly into the world load; 2/3 rendered live 3D world frames (Run 3 reached 2,853 presented frames and stayed alive rendering until manually stopped).RtlReleaseSRWLockExclusivedropped from ~2,400–3,200/run down to 3–5/run, matchingvkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory1:1.Would be great to hear how
0e927bebehaves on your RX 6700 XT when you get a chance to re-test.Imported from brcly/TuxBox. Originally posted by Valdi320 on 2026-11-26T23:54:21Z.
I found a separate, reproducible coherence failure on your current head
0e927be, using only synthetic XMem pages (no game or AMD GPU required).Two small regression tests in
runtime/xmem/src/tests/physical_backing.rs:The arena hold retains an Arc, not a view_holds entry.
promote_faulting_aliaschecks the mapped VA spans, but can change the canonical backing away from a still-held PrivateArena. Old imports may then write storage the CPU no longer sees. A plain ERROR_BUSY in the VEH would not be a complete solution (it would reject a legitimate CPU access); the ownership transition needs coordination with import retirement or a coherent fallback.This is a demonstrated CPU-side model of stale backing writes, not proof of the AMD EPERM/device-loss cause. The tests are on my fork only; no new PR or change to your branch.
Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-27T00:34:24Z.
Retest of
0e927beon the RX 6700 XT: the-1rejection is gone. Three no-preload runs on a quiet machine, and all three pass the page-remap batch with noCS has been rejectedline at all. They end about a minute later for a different reason, still on the story loading screen.Setup: as before (
1002:73df, 12 GB, Mesa RADV 26.3.1, Linux 7.3.6, GE-Proton11-14, 32 GB RAM, 3840x2160, shaders prepared, noLD_PRELOAD).radv/amdgpu: Not enough memory for command submission., device lost, exit code 3In all three the present rate falls steadily, then the last intervals are one to four frames in 14 to 18 s with lines like:
The kernel log has the matching
amdgpu: [drm] *ERROR* Not enough memory for command submission!for runs 1 and 2. NoGPUVM faultin any run.Memory. For run 3 I sampled the amdgpu counters (
mem_info_vram_used,mem_info_gtt_used) andMemAvailableevery 3 s, and then did the same formain(8c56463) with the preload as a control. MiB, time from launch:0e927beVRAM0e927beGTT0e927beMemAvailablemain+ preload VRAMmain+ preload GTTmain+ preload MemAvailableThe control dies at 144 s at the remap batch (
-14, as always with the preload), so the comparison only holds up to there. Up to that point the two start out the same, and from about 90 s this PR uses roughly 3 GB more VRAM, fills the card, and then GTT and system memory keep growing where the control is flat. I have not found what the extra memory is; one run each, so treat the numbers as a first look. A 16 GB card would have more room before this shows.Lock errors:
RtlReleaseSRWLockExclusive Lock … is not owned exclusive!went up here, not down: 5,084 / 5,289 / 5,877 per run on0e927be, against 2,400 to 3,200 on5a795cband about 520 onmainwith the preload.Memory allocation failed, falling back to system memoryis about 470 per run on every build includingmain, so the two are not 1:1 on this card.Happy to rerun with extra logging (for example the live hold count and total held bytes over time) if that helps.
Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-27T00:50:26Z.
Update, with a correction to the memory comparison above. I reran both sides with
TUXBOX_TRACE_BUFFER_BACKING=1and sampled the title'sRssAnonas well. The growth starts at the page-remap batch, which is exactly where themain+ preload control dies, so the control cannot tell this PR's overhead apart from what the title does after the remap. Please read the "3 GB more VRAM thanmain" above as "3 GB more thanmainhad when it died", not as overhead of this PR.What the traced runs show (
0e927beno preload, 229 s;main8c56463+ preload, 113 s; the trace is rate-limited to powers of two, so these are floors):buffer backing path0e927bebefore the remap batchmainbefore the remap batch0e927beat the endimported/ viewpage_hit/ viewspan_hit/ viewpage_open/ viewspan_open/ viewimported_scattered/place_virtual_layout0e927be, fresh opens from views go up by 8 to 16 times while hits barely move. VRAM goes from about 9.1 GB to full (12.2 GB) within 30 s of the batch, GTT then climbs from 1.5 GB to 6 to 7 GB over the next two minutes, and in the last 10 s it jumps to exactlymem_info_gtt_total(15,913 MiB), which is whenNot enough memory for command submissionappears.RssAnonlevels off at about 10 GB and stays flat while GTT keeps growing, so this is not the process's own private memory ballooning.What I can't tell from this: whether the opens after the remap are the title legitimately streaming more than a 12 GB card can hold at 3840x2160, or imports that were retired by the remap staying alive (as far as I can read
commands/page_mapping.rs, retiring only marks the pin not live, and the old heap, guard and hold stay until the title releases the resource) while their replacements are opened next to them. A count of live imported heaps and their total bytes, logged every few seconds, would settle it; I can run that if you add it or tell me where you'd want it.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-27T01:00:53Z.
Rebased onto latest
main(12e4b06) and pushedd50a51caddressing both @Valdi320'sPrivateArenafinding and @JeffreyBytes's memory/diagnostics follow-up:Re: @Valdi320 (
PrivateArenahold tracking & import retirement)Good catch —
HoldRecord.arenaswasn't tracked inPool, soPrivateArenaneither adopted a new CPU view when unheld nor notifiedd3d12when promoted under a live hold. Ind50a51c:Pool::arena_holdstracking (xmembacking.rs):commit_hold/release_holdnow maintain per-arena hold counts.PrivateView(cpu)(xmemprivate_views.rs): When aPrivateArenahas no live hold (arena_holds == 0), mapping a new CPU view adopts it directly asSlotRole::Canonical(MEM_PRIVATE+PAGE_READWRITE), preserving bytes without a VEH fault orSharedSectiondowngrade (tested inunheld_private_arena_adopts_new_cpu_view_without_section_promotion).d3d12imports (xmem+d3d12): ExportedTuxBoxSetBackingInvalidationCallback(registered once byd3d12->GPU_APERTURE.retire_range). Whenpromote_faulting_aliastransitions a still-heldPrivateArenatoSharedSection,xmemdropsPOOLand notifies all mapped guest VAs soImportedHeap::is_live()flips tofalse,TextureAddress::is_stale()triggers re-import of the promoted backing, andPagePoolsnever reuses the stale arena heap — while the oldPrivateArenaremains committedMEM_PRIVATEuntilrelease_physical_backing(hold)(tested inheld_private_arena_promotion_notifies_invalidation_and_keeps_hold_liveandretire_range_invalidates_imported_heap_and_prevents_cache_reuse).acquire_physical_backinghands out an anonymousMEM_PRIVATEarena pointer foramdgpuuserptr, Windows/Wine cannot hardware-alias a different VAcpu != backingto that same private page mid-hold without retiring the old import — which the invalidation callback now coordinates cleanly.)Re: @JeffreyBytes (memory reductions & live hold/arena trace)
Glad to hear
CS has been rejected (-1)is 0/3 on the RX 6700 XT, and thanks for theTUXBOX_TRACE_BUFFER_BACKING=1follow-up.d50a51calso adds three memory cleanups plus opt-in live hold/arena stats (TUXBOX_TRACE_XMEM_BACKING=1, logged every 5 s):GpuAliasRAM dirtying (xmem):map_private_page,map_private_contiguous,apply_alias, anddetach_private_slotno longer populate or snapshot-copySlotRole::GpuAliaspages, keeping GPU-only alias slots as untouched OS zero-pages instead of dirtying a duplicate copy of the GPU aperture.TuxBoxIsPhysicalBacked(xmem+d3d12):place_gpu_target'sis_backed_rangecheck now queriesPool.mappingsread-only instead of callingacquire_backingand allocating phantomPrivateArenas for unbacked GPU-only targets (is_physical_backed_does_not_allocate_private_arena_for_unbacked_gpu_alias).d3d12PagePools::pieces):import_scattered_buffernow reuses live pieceID3D12Heaps across scattered imports (scattered_imports_reuse_cached_piece_heaps).Live
TUXBOX_TRACE_XMEM_BACKING=1numbers on RX 6900 XT (16 GB VRAM / 64 GB RAM, 3840x2160,d50a51c):pages=114,096 (7,131 MiB)|holds=458|view_holds=9,149 (571 MiB)|live_arenas=0 (0 MiB)|deferred=0.235.4 s,0CS rejections):holdsgrows to12,865(matchingpage_open=8192++span_open=4096+), whileview_holdstotals only1,498 MiB(~1.5 GiB),live_arenas = 0 (0 MiB), anddeferreddrains cleanly across the remap (107 -> 1) before sitting at1,531pages (95 MiB) during world streaming.VRAM + GTTrises from14.8 GiB VRAM + 2.7 GiB GTTatDispatchMeshto16.2 GiB VRAM + 12.3 GiB GTT(~28.5 GiB total) once 4K world textures stream and spill out of VRAM viavkd3d_allocate_device_memory. That sits just over a 12 GB VRAM / 32 GB RAM card's~27.5 GiBcombined VRAM+GTT ceiling (12,272 + 15,913 MiB), which matches theNot enough memory for command submissionfailure you saw — with XMem holds themselves accounting for ~1.5 GiBof that total rather than leaking unboundedly.(Unit & hygiene checks on
d50a51c:tuxbox-xmem13/13pass,tuxbox-d3d12device::heap::backingon RADV15/15pass,tests.test_repository_hygiene5/5pass.)Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-27T01:43:53Z.
Retest of
d50a51con the RX 6700 XT, two no-preload runs withTUXBOX_TRACE_XMEM_BACKING=1. The trace agrees with your reading: the holds are small and nothing accumulates, and what ends the runs on this card is total GPU memory at 3840x2160.CS has been rejectedNot enough memory for command submission(3 lines), device lost, exit code 3backing stats, run 1 (run 2 is the same shape):So about 1.4 GiB under hold at the end, no live arenas, and
deferreddrains. Meanwhile the amdgpu counters go the same way as on0e927be: VRAM is full (12.2 GB) about 30 s after the remap batch, GTT climbs from 2 GB to 6 to 9 GB, and in run 1 it reachesmem_info_gtt_total(15,913 MiB) at the moment the submit is refused. That is the 12,272 + 15,913 MiB ceiling you worked out. Neither run left the loading screen, so I can't say how far past it a 12 GB / 32 GB machine would get; the three memory reductions did not visibly move the point where VRAM fills here.From this card's side I have nothing left against the PR: the
-1and-14rejections are gone in 7 of 7 no-preload runs since0e927be, the page-remap batch passes every time, and the menu and loading screen run at 300 to 1,000 presents per 10 s where the copy path onmaingives about 6. What remains here is the title's memory demand at this resolution, which is a separate problem from this PR.One thing that is still different from your card, in case it means something:
RtlReleaseSRWLockExclusive Lock … is not owned exclusive!is 6,571 and 5,331 per run here ond50a51c(about 520 onmainwith the preload), where you saw 3 to 5.Imported from brcly/TuxBox. Originally posted by gtb-sbe on 2026-11-27T13:12:07Z.
RDNA4 results for
d50a51c, and a question about acceleration structures for anyone who got past the remap batch.Setup: RX 9060 XT 16 GB (RADV GFX1200, Mesa 26.2.6), Ryzen 7 5800X, 31 GB, kernel 6.18.60, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline at 3840x2160, no preload.
What works on this card: the menu runs at about 90 fps and the loading after the picker at about 9 fps. On the copy path it was 1-2 fps and then 0.6 fps. The page-remap batch passes, holds go from about 460 to 9,600-11,000, and nothing accumulates. Card VRAM peaks at 13.7 to 15.1 of 16 GB, with no
CS has been rejectedand noNot enough memory. Three runs reachedGame Runningwith SRLfbk_stry000_FBK_STRY000_INTRO, according to the title's own crash logs. I see noRtlReleaseSRWLockExclusive ... is not ownedlines at all, so the 5-6k per run on the RX 6700 XT don't show up on RDNA4.What fails: right after the remap batch, vkd3d drops every bottom-level AS build:
There were between 147 and 776 per run, starting at world entry. To see where they go, I added a local diagnostic to
build_raytracing.rsthat logs builds whose destinationblas::resolvedoes not find (d50a51c+ #294 + the diagnostic):BOTTOM_LEVEL, 1.4 KB to 12 MB, at destinations from0x17421bb00to0x17c264500, about 128 MiB in one range.VirtualQueryputs all of them in one allocation at0x14b070000, about 2.2 GiB,MEM_PRIVATE, committed, read-write. It is not XMem-backed (is_backed_rangeis false), so #258's backing exports are probably not involved.depth::wrapreachblas.register: committed, placed-in-heap and reserved. Buffers fromplace_virtualandplace_virtual_layout(CreatePlacedResourceXat a guest address) don't. So a pool placed at a guest address would never be known toblas::resolve. I haven't confirmed yet which call creates this one.All three runs end within a few minutes. Each title crash log shows
Unsignaled CrossQueueBarrier, and the cause is not proven:0x0fromSQC (data)on a compute ring, then device lost;0x8003a8b1f000fromTCPon the gfx ring, about a minute into the intro;Game Running, which looks like #215.A ray query against BLASes that were never built would fit the two faults, but so would other things, such as the released label waits just before. With #302 and #306 merged, more of the shadow passes now trace these structures, so it will likely matter more on current
main.Question: do your logs past the remap batch contain
Failed to place destAccelerationStructure, @DrArroway (the RX 6900 XT run that reachedGame Running) and @JeffreyBytes? And @NickStallman, do the NVIDIA runs onmainwithout #258 show it? From the region above I'd expect it everywhere, which would make it a separate gap rather than something in this PR. If so, I'll open an issue for it and keep this thread for the #258 results.Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-27T14:30:43Z.
Thanks for this. On current
mainplus this PR, and on the PR head alone,buffer-remapfails on an RTX 4070 Ti SUPER and an AMD Raphael iGPU (RADV):d3d12-buffer-remap failed: initial CPU alias differs. It passes at4a8d521,0c9670b,237ef52and the base12e4b06, and fails atd50a51c. Undoing theGpuAliaspopulate skip, the unheld-arenaCanonicalrole, or the removedpopulate_page_bytescall incopy_mappings.rs, each on its own, did not fix it. Could you take a look? TheRtlReleaseSRWLockExclusive ... not ownedcount JeffreyBytes reported would be good to explain before merging too.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-27T16:26:18Z.
Quick update while a fresh test run on current
main(c2a59af) +#258finishes:buffer-remap(@brcly): Found the cause — skippingpopulate_page_bytesforSlotRole::GpuAliasin bothprivate_views.rs(initial map) andcopy_mappings.rs(apply_aliasremap) left the destination zero-filled for CPU reads inbuffer_import_guest.cpp, which is why reverting only one hunk alone didn't fix it. Reverted both locally on top ofc2a59afand verifiedbuffer-remap,buffer-unmap-released, andbuffer-unmap-aliveall PASS on RX 6900 XT (1002:73bf, GE-Proton11-14). I'll push the rebased branch once the freshmainrun finishes.RtlReleaseSRWLockExclusive ... not owned(@brcly, @JeffreyBytes): TuxBoxruntime/makes noSRWLockcalls. This is an upstreamvkd3d-protondouble-unlock inlibs/vkd3d/memory.c(vkd3d_try_allocate_device_memory): line 1061 locksmemory_info->budget_lock(rebar_budget && respect_budget), line 1114 unlocks it onvkAllocateMemoryfailure while leavingrebar_budgettrue, and line 1161 unconditionally unlocks it a second time (after lines 1130–1131 skip re-locking). Every failed ReBAR-budgeted allocation attempt therefore triggers one warning, matching0on RX 9060 XT,3–5on RX 6900 XT, and~5.3k–6.6kon 12 GB RX 6700 XT once VRAM fills.Failed to place destAccelerationStructure(@gtb-sbe): My earlier logs fromd50a51cweren't kept across reboot — running a fresh test on currentmain(c2a59af) +#258now and will report back with the numbers shortly.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T16:42:50Z.
@gtb-sbe, answering your question for NVIDIA (RTX 5090, 620.70.10, GE-Proton11-14). These are without #258, on
mainfrom9168b2fthrough95480b5plus our diagnostic branches, in runs that reached the story world:Failed to place destAccelerationStructure: 0 occurrences in 7 runs. None of those logs show aBuildRaytracingAccelerationStructurecall reaching vkd3d at all.XboxBvhBuilder.dll's own compute kernels. A probe that tagged pipelines created with that DLL on the stack found 52 kernels:xbox.*intrinsics, which dxil-spirv can't define (s_load_dword_with_cache,global_load_dword*_with_cache,LaneSwizzle,Med3_F32, …);insertvalue("Unhandled instruction!").Of 3,621 builder dispatches, 3,021 ran as stand-ins.
0x14b070000(about 2.17 GiB, 4 allocations). Its BLAS run,0x174222000–0x178088000, is inside the destination range you logged. The other 123 BLAS addresses (from the 64-byte instance records bound beside each TLAS) sit in small mapped views inside a 54 GiB reserved span at0x300200000.So on NVIDIA the structures aren't built by DXR calls that vkd3d drops; the builder's own kernels mostly don't run. Why your RDNA4 run sends the same region through DXR builds while ours doesn't isn't established. It may be a capability check in the builder; that's a guess. We're working on lowering those
xbox.*intrinsics, and 42 of the 43 lower on the CPU so far.Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T16:46:23Z.
Correction to my comment above: those NVIDIA runs had the package's own
XboxBvhBuilder.dllstaged, not TuxBox'sbuild/bvhone that docs/PROJECTSCARLETT.md says to use. Our run script missed it. That alone explains why we saw the builder's kernels and you saw DXR builds. TuxBox's builder forwards every build to the command list and never dispatches a kernel. So the "0Failed to place destAccelerationStructure" and the stand-in counts describe the retail-builder setup, not the documented one. The address findings still hold: the destination pool is0x14b070000, about 2.17 GiB,MEM_PRIVATE, and the BLAS runs fall inside your range. I'm rerunning with the documented staging and will report whether the dropped builds appear on NVIDIA too.Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-27T17:28:10Z.
RDNA4 results for
d50a51con currentmain(c2a59af, includes #294, #296, #298, #301, #303).Setup: RX 9070 XT 16 GB (RADV GFX1201, Mesa 26.3.1), kernel 7.3.6, GE-Proton11-14, ProjectScarlett 1.0.2.1 offline, no preload.
What #258 changes here: without it the menu runs at about 1 fps on the copy path; with it the menu and loading are responsive again (280-300 presents per 10 s in TuxBox's counter; that counts presents, not distinct title frames).
Things you asked about:
RtlReleaseSRWLockExclusive ... is not owned exclusive!: 1 per run, always the same lock. In theVKD3D_CONFIG=faultrun it is the line right beforevkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory, on the same thread, about 20 s afterFailed to allocate 131072 bytes on memory type 5/type 10andvkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e. So here it seems to come with the out-of-VRAM fallback, which could explain why a 12 GB card sees thousands of them. That is a correlation from line order, not proven. DefaultWINEDEBUGfrombackend_log.py(-all,err+all,warn+debugstr,warn+seh), so it is not filtered. That fits gtb-sbe's 0 on the 9060 XT: the 5-6k per run look specific to the 6700 XT.Failed to place destAccelerationStructure: 0 in every run.CS has been rejected/Not enough memory: 0, but see the allocation failures above.buffer-remap: fails here too, with the same message:d3d12-buffer-remap failed: initial CPU alias differs(tuxbox.py checkonmain+d50a51c, GE-Proton11-14, adapter1002:7550). The other 10 regression controls pass, includingbuffer-import,buffer-unmap-aliveandbuffer-unmap-released, and so do all other check steps. So it is not specific to NVIDIA or the Raphael iGPU.How far it gets (4 runs, each loading the same story save; the title's crash log reports SRL
int_prolo_int_prolo_ext, SRL statePrestream, title crash logUnsignaled CrossQueueBarrier, Game Physical ~2188/2305 MB):Title watchdog, exit code 5, no GPU fault, no devcoredump. Two
GPU memory wait released after 5son one label atvalue = target - 1.After the save loads, the game shows at most two barely recognizable frames (one with a subtitle line), then after ~2 min a gfx ring timeout (
signaled 1933026, emitted 1933028) with no page fault in the devcoredump (fault status0x0).(
RADV_DEBUG=hang) compute ringcomp_1.1.0TCP permission fault, write, at0x80032ebe0000-0x80032ebe9000(GCVM_L2_PROTECTION_FAULT_STATUS 0x741041,PERMISSION_FAULTS 0x4,MAPPING_ERROR 0), then ring timeout. The released memory wait in this run came after the hang, so it looks like a consequence, not the cause.(
VKD3D_CONFIG=fault) vkd3d's device-fault report:WriteInvalidat0x80044fd40000, "Fault address is currently unmapped. This is very likely use-after-free." The address history shows four short-lived VRAM heaps at that VA (VkBuffer [global-buffer], memory type 0; 3.68 GB, 985 MB twice with sparse unbinds, 152 MB), each bound and freed within 0.5-2.5 s. The last was freed 12 s before a compute dispatch wrote through the stale address (comp_1.0.1, TCP,0x541041). So the permission faults look like writes into freed heaps rather than read-only views. The same run retired 24 stale GPU imports after page remaps (page remap replaced imported range ... retired stale GPU import) shortly before VRAM ran out. I haven't found which path creates and frees those heaps yet, so I can't say whether #258 is involved.The fault at
0x0fromSQCthat I reported in #289 has not come back on thismain.Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-27T17:53:48Z.
Correction to my comment above: the
vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000elines (afterFailed to allocate ... on memory type 5/type 10) are not a sign of VRAM running out. In a later run they already appear right after vkd3d starts, before the menu, so they are failed host-pointer imports. The VRAM-related line is onlyvkd3d_allocate_device_memory: Memory allocation failed, falling back to system memory, and the singleRtlReleaseSRWLockExclusivewarning sits right before that line. I can't say from this whether the import failures matter for the warning on the 6700 XT.Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-27T17:59:26Z.
Rebased onto
main(c2a59af) and pushedfcb5849addressing thebuffer-remapregression (@brcly, @Kayotic1337), theRtlReleaseSRWLockExclusivequestion (@brcly, @JeffreyBytes, @Kayotic1337), and one placed-texture writeback bug surfaced onmain:1.
buffer-remapfailure (initial CPU alias differs) — FixedSlotRole::GpuAliaspopulate skip inruntime/xmem/src/physical_pages/private_views.rs(initial mapping + slot detach snapshot) andruntime/xmem/src/physical_pages/copy_mappings.rs(apply_aliasfast path), and restored CPU-read assertions inruntime/xmem/src/tests/physical_backing.rs.d3d12-buffer-remapverifies CPU reads on both initial placement and replacement remaps (initial CPU alias differs/replacement CPU alias differs).2.
try_write_xmem_bytesskipping unmapped XMem pages — Fixedmain(c2a59af), placed-texture writeback viatry_write_xmem_bytesfailed the queue batch withERROR_INVALID_ADDRESSwhenever any 64 KiB page in a multi-page span was unmapped/deferred, instead of skipping unmapped pages likewrite_mappednormally does.ERROR_INVALID_ADDRESSinruntime/d3d12/src/device/heap/backing.rsto skip unmapped/deferred XMem pages without failing the batch (tested intry_write_xmem_bytes_skips_unmapped_xmem_pages_without_failing).3.
RtlReleaseSRWLockExclusive Lock ... is not owned exclusive!— Explainedruntime/makes zeroSRWLockcalls.vkd3d-protondouble-unlock bug inlibs/vkd3d/memory.c(vkd3d_try_allocate_device_memory):memory_info->budget_lock(rebar_budget && respect_budget), backed bySRWLOCKunder mingw-w64 winpthreads.vkAllocateMemoryfails (vr != VK_SUCCESS), line 1114 unlocksbudget_lockwhile leavingrebar_budgetset totrue.if (rebar_budget || VKD3D_CONFIG_FLAG_IS_SET(LOG_MEMORY_BUDGET))at line 1126, skips the conditional lock at lines 1130–1131 (sincerebar_budget && respect_budgetis true), and unconditionally callspthread_mutex_unlock(&memory_info->budget_lock)a second time at line 1161.vkd3d_import_host_memorycalls on memory types 5/10 produce 0 lock warnings in our logs, matching @Kayotic1337's note). That explains0on RX 9060 XT,1on RX 9070 XT,2–5on RX 6900 XT, and~5.3k–6.6kon 12 GB RX 6700 XT once VRAM saturates and vkd3d-proton retries multiple ReBAR-budgeted allocations before falling back to system memory.4. Verification on
main(c2a59af) +fcb58491002:73bf, GE-Proton11-14):tuxbox.py checkall checks passed — code checks (7/7),D3D12 regression controls(20/20PASS, includingd3d12-buffer-remap PASS pci=1002:73bf words=768/768 identical=1 replacement=1),Shader translator on the GPUPASS,Lanes and fixtures on the GPU(97/97PASS,lanes-benchmark PASS pci=1002:73bf submit_us=116.3 roundtrip_us=152.9 copy64k_us=158.3 frame_us=257.1 frame_p99_us=480.7 shader_pipeline_us=476.6 dxil_pipeline_us=299.9).1002:164e, GE-Proton11-14):tuxbox.py check— code checks (7/7),D3D12 regression controls(20/20PASS,d3d12-buffer-remap PASS pci=1002:164e words=768/768 identical=1 replacement=1),Shader translator on the GPUPASS, and96/97Lanes + guest fixtures PASS (lanes-benchmark PASS pci=1002:164e submit_us=72.2 roundtrip_us=118.5 copy64k_us=93.4 frame_us=289.9 frame_p99_us=533.1 shader_pipeline_us=479.8 dxil_pipeline_us=282.6); onlyguest-present-4k-splash(added in#311) timed out at 15 s on the iGPU.c2a59af+#258, no preload): ReachedGame Running(Frame: 2577,7,006presented frames), passedpage-remap(batches=147),0CS has been rejected,0Not enough memory,live_arenas=0,view_holds=1,272 MiB,2RtlReleaseSRWLockExclusivematching2Memory allocation failed1:1. Ended onmain's world-streamingTCPGPUVM fault(0x80049e3bf000), and0Failed to place destAccelerationStructure(noting @NickStallman's note on retail vsbuild/bvhbuilder staging applies to this setup too).Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-27T19:27:59Z.
Well done persevering through this, guys.
Glad a solution was found!
Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-27T19:31:05Z.
oh my god yes! rebuilding main now.
Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-27T19:33:58Z.
Id hold off trying until I dial in these compilation changes which should speed shader compilation up, or you may be sat waiting at a black screen for a while 😂