d3d12: keep live userptr heap pages accessible to lazy publication #640
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/640"
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-12-01T21:36:16Z.
Summary
Keep all 4 KiB pages covered by live
OpenExistingHeapFromAddress*userptr imports accessible (PAGE_READWRITE) while lazy publication is active, fixing theradv/amdgpu-EPERM(-1) CS rejections introduced when lazy publication became default on.Root Cause
On Linux
amdgpu, RADV attaches every liveAMDGPU_GEM_USERPTRallocation (OpenExistingHeapFromAddress*) to the context's global BO list, whichamdgpu_cs_parser_bosvalidates viaamdgpu_hmm_range_get_pageson every CS submission.Previously,
lazy::defercould callVirtualProtect(..., PAGE_NOACCESS)on any placed-texture page unlessgpu_writes::any_import_overlapssaw an active byte range—which missed:PieceHeapextents.ID3D12Heap(includingvkd3d-proton's deferred queue/descriptor references after TuxBox drops its wrapper).lazy::defer.A single
PAGE_NOACCESSpage inside any live userptr BO causes every subsequentvkQueueSubmitto fail in the kernel with-EPERM(-1) /VK_ERROR_DEVICE_LOST.Changes
runtime/d3d12/src/device/placement/lazy.rs:UserptrRangestracking 4 KiB page intervals inSTATEand an RAIIUserptrPinguard that unpins on final drop.pin_userptr(range)which insertspages_of(&range)intoSTATE.userptrfirst, collects any overlapping livestate.heldtextures (cleaning deadWeakentries), dropsSTATElock, publishes viapublish_nowunder thePUBLISHINGreentrancy guard, and unconditionally restores page access viarelease(&texture).reason()/defer()for any 4 KiB page range overlappingSTATE.userptr, and passpages_of(range)togpu_writes::any_import_overlaps.Pages::protectandPages::releaseuntouched so this remains cleanly orthogonal to#625.runtime/d3d12/src/device/heap.rs,heap/pages.rs,heap/import.rs:UserptrPinasIUnknownprivate data (SetPrivateDataInterface) on the nativeID3D12HeapwhenOpenExistingHeapFromAddress1/OpenExistingHeapFromAddresssucceeds (non-mirrored paths), holding the pin untilvkd3d-protonreleases its final reference; dropped immediately on cache hits, shadow mirrors, or errors.pin_userptrbeforevalidate_shared_rangeinimport_bufferandimport_scattered_buffer.runtime/d3d12/src/tests/device/placement/lazy.rs,heap_backing.rs):UserptrRangesrefcounting, andpin_userptrpublishing/releasing held textures while keeping pages accessible.userptr_pin_attached_to_heap_outlives_wrapper_and_submits_cleanly) verifying the pin outlives the localID3D12Heapwrapper while placed resources remain alive, releases cleanly once dropped, and submits cleanly without CS rejection.Verification
fix/lazy-publication-userptr-634atcb4631ba):cargo fmt --all --check,tests/test_repository_hygiene.py(7/7),cargo clippy --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --all-targets -- -D warnings, andRUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --document-private-items: all passed.AMD Radeon RX 6900 XT (1002:73bf)&AMD Raphael Radeon 610M iGPU (1002:164e)):device::placement::lazy::tests:11/11passed on both adapters.userptr_pin_attached_to_heap_outlives_wrapper_and_submits_cleanly: passed on bothAMD Radeon RX 6900 XT (1002:73bf)(0.25s) andAMD Raphael Radeon 610M iGPU (1002:164e)(0.27s).AMD Radeon RX 6900 XT (1002:73bf), Mesa26.3.1RADV,TUXBOX_LAZY_PUBLICATION=1ON):1,110.1s,10,031presents (Frame: 1437),39.8 MiB/stexture readback —0CS rejections (-EPERM),0GPUVM faults,0xmemerrors (vs 100%-EPERMCS rejection in seconds without this fix).874.9s,10,201presents (Frame: 1531),33.1 MiB/sreadback,2livepublished on accessVEH fault recoveries —0CS rejections,0GPUVM faults,0xmemerrors. (Both runs later hit the unrelated game-sideUnsignaled CrossQueueBarrierbreakpoint while streaming.)tuxbox.py check --changed origin/main:AMD Radeon RX 6900 XT (1002:73bf):23/23D3D12 regression controls passed (includingmesh,buffer-remap,buffer-unmap-alive,buffer-unmap-released,alias-deferred,copy-resource,placement,heaps,tables);122/123total checks passed — the sole failure is the pre-existing#625lanes-selftest-texture-publicationcrash (confirmed unrelated: passes withTUXBOX_LAZY_PUBLICATION=0).AMD Raphael Radeon 610M iGPU (1002:164e):23/23D3D12 regression controls passed;121/122total checks passed — same sole pre-existing#625lanes-selftest-texture-publicationfailure.Evidence: TuxBox check of
cb4631ba67, no uncommitted changes, GPU 1002:73bf: 15 passed, 1 failed, 0 not runEvidence: TuxBox check of
cb4631ba67, no uncommitted changes, GPU 1002:164e: 15 passed, 1 failed, 0 not runFixes #634