d3d12: buffer-remap regression control fails on RADV, with host memory imports refused #191
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox#191
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@JeffreyBytes on GitHub · 2026-11-25 19:13 UTC · original
python tuxbox.py checkonmainat1f40ee4fails one of the 17 D3D12 regression controls here. The other 16 pass, includingbuffer-importandbuffer-import-reject. #189 notes the same control failing on an RX 9060 XT, so this looks specific to RADV and not to one card.Setup. RX 6700 XT (
1002:73df), Mesa 26.3.1 RADV, Intel i5-12600K, Linux 7.3.5, Proton Experimental 11.0-20261112.Result.
What the control's log shows. Twice, immediately before a buffer is placed, vkd3d-proton refuses to import the host memory:
The second refusal follows
page remap replaced imported range 0x37c0000..0x37d0000 ... retired stale GPU import.buffer-import, which passes, logs no refused import.In ProjectScarlett. A 300 s offline run on the same machine logs the same three lines 131 times.
Not established. I haven't found why the import is refused. One possibility is that the kernel driver only accepts anonymous memory for this kind of import and the remapped pages are a shared section, but that is a guess. I also haven't shown that the refused imports cause anything visible in the title. I'm looking into it and will post what I find.
@Exorion1er on GitHub · 2026-11-25 19:52 UTC · original
Your guess is right: amdgpu refuses the import because the pages are a shared mapping. libdrm always asks for anonymous-only memory. With that flag cleared,
buffer-remappasses and ProjectScarlett gets past the black screen on my RX 9070 XT.Setup. RX 9070 XT (
1002:7550), Mesa 26.2.7 RADV, libdrm 2.4.134, Linux 7.3.5 (Fedora 44), Proton Experimental 11.0-20261112, TuxBox7b22d71.XMem backs physical pages with pagefile sections (
CreateFileMappingW+MapViewOfFile3inruntime/xmem/src/shared_pages.rs), and Wine maps those as shared Linux mappings. RADV imports a host pointer through libdrm'samdgpu_create_bo_from_user_mem, which always setsAMDGPU_GEM_USERPTR_ANONONLY. The kernel then rejects any page backed by a file. A small native Vulkan program (no Wine) importing 64 KiB throughVK_EXT_external_memory_hostgives:With
ANONONLYcleared from theDRM_AMDGPU_GEM_USERPTRioctl, all four return 0.buffer-remapfails here too. With a local change that reports which copy differs, all three copies read zero, including the two taken before the remap:So it isn't specific to remapping: on RADV the GPU never sees the contents of a section-backed page, and the buffer reads as zeros.
In ProjectScarlett this is the black screen. Once the shader preload finishes, the title draws about 22 draws per frame and every draw's readback is zero. The UI vertex shader reads its positions and colors from a constant buffer. If that buffer reads as zeros, every vertex collapses and nothing rasterizes. I haven't traced that buffer to these pages directly, but the UI appears once the imports succeed. The same run logs 131 refused imports.
The workaround I tested is an
LD_PRELOADlibrary that interposesdrmCommandWriteReadand clears the flag on the userptr ioctl only:(
RTLD_NEXTdoesn't work here because the Vulkan loader opens libdrm locally.) With it preloaded:buffer-remap,buffer-importandbuffer-layoutpass, with no refused imports in the log.lit=0.998 mean=(32,32,44), the same value as the Account Picker sample inprojectscarlett-startup.json(RTX 4070 Ti SUPER). In my own run it got past the intro video and through the menus.This is a workaround, not a fix. As far as I can tell, the anonymous-only restriction is deliberate, because a file-backed page can be truncated while a buffer still holds it. Wine doesn't truncate these sections while they are mapped, but I haven't checked every path. A real fix probably belongs either in how TuxBox gives the GPU access to physical pages on AMD, or in libdrm/Mesa if they would accept an opt-out of
ANONONLY. I haven't tried either.This probably also explains #39 (RX 9060 XT, black after the same milestone).
@gtb-sbe on GitHub · 2026-11-25 21:00 UTC · original
I can reproduce this on an RX 9060 XT (I am OP of #189 actually), and it matches what @Exorion1er found. I have a working branch and will open a PR soon.
Setup. RX 9060 XT (
1002:7590), Mesa 26.2.6 RADV, Linux 6.18.60 (NixOS), Proton Experimental 11.0-20261112, TuxBox1b32189.Cause. Calling
DRM_IOCTL_AMDGPU_GEM_USERPTRdirectly, the kernel accepts private anonymous memory and returns EPERM for shared anonymous, memfd and temp file mappings. WithoutANONONLYit accepts all of them. Wine creates these sections withmemfd_create.The provider cannot notice the refusal. vkd3d-proton falls back to unrelated host-visible memory, reports success and still returns the guest pointer from
Map. That is why the control logsimported, even withTUXBOX_REQUIRE_BUFFER_IMPORT=1.What the PR will do.
drmCommandWriteRead, like @Exorion1er's. It repeats a userptr request withoutANONONLYonly after the kernel refused it, so anonymous imports keep the driver's behavior. It does not link libdrm or need its headers.tuxbox.py check.TUXBOX_AMDGPU_IMPORT=0turns it off in the launcher.buffer-*controls fail when vkd3d-proton logs a refused import.Result. Without the preload
buffer-remapfails with two refused imports. With it the control passes (768/768 words, none refused), and the fullcheckpasses: 67/67 guest checks, 17/17 regression controls and the translator checks.Not established. I have not finished a ProjectScarlett run with this yet. It is still a workaround: an opt-out of
ANONONLYin libdrm or Mesa would be the cleaner fix, and I haven't checked @Exorion1er's point about truncated files.@JeffreyBytes, you said you were looking into this too. If you already have something different in progress, let me know before I open the PR.
@DrArroway on GitHub · 2026-11-25 21:24 UTC · original
Heads-up @gtb-sbe / @JeffreyBytes: I just opened #200 with a
runtime/d3d12-side fix (noLD_PRELOADor libdrm changes) that detects the silent RADV section refusal once per device and mirrors committedMEM_MAPPEDranges through anonymousVirtualAllocshadow heaps with chunked pre-submit sync.d3d12-buffer-remap(768/768,identical=1 replacement=1),buffer-import,buffer-import-reject,buffer-layout, andtuxbox.py check(67/67 GPU gates) all pass on RX 6900 XT (1002:73bf).@JeffreyBytes on GitHub · 2026-11-25 21:55 UTC · original
Following up on my own "I'm looking into it".
The preload from @Exorion1er's comment reproduces here on the RX 6700 XT (
f489d3c, Linux 7.3.6, Mesa 26.3.1): refused imports go from 131 to 0, the first present samples go fromlit=0.000tolit=0.998 mean=(32,32,44), andbuffer-remappasses. So that is three RADV cards with the same cause.I'm not working on a fix of my own; #200 and #199 cover it. I tested #200 on this card and posted the results there: the controls pass and the game reached the Account Picker and the intro video, with a large slowdown and a crash in two of three runs.
@gtb-sbe on GitHub · 2026-11-26 00:32 UTC · original
Since a preload is not wanted, I measured what ProjectScarlett actually does with the pages amdgpu refuses, to see whether XMem and the provider can fix this alone, without per-submit copies.
Summary
If that holds, XMem can back every page with private memory, which amdgpu imports fine, and the provider can point every GPU alias of a page at that one backing. Details below; I'd like to know whether that direction is acceptable before I build it.
Setup: RX 9060 XT (
1002:7590), Mesa 26.2.6 RADV, Linux 6.18.60, Proton Experimental 11.0-20261112,main1b32189, ProjectScarlett 1.0.2.1 offline. Two runs: 54 minutes from a partly warm cache, then 7 minutes with a warm cache. Both reached the 22-draw state (still black) and gave the same import breakdown. Currentmain(cb8c38b) leaves XMem and the import paths unchanged. It does change the size of some small texture allocations and defaults to GE-Proton11-14, so individual import sizes may differ there; I have not rerun on it.1. What is refused
An opt-in trace classifies every import whose range contains a section view, i.e. every import amdgpu will refuse, and asks XMem which pages are behind it. Both runs: 131 such imports, the same 131 that vkd3d-proton refused.
XMemMapPhysicalPagesview, each page mapped only thereXMemMapPhysicalPagesview with GPU attributes (0x2404), each page also mapped at 1 to 7 other such addressesCopyPageMappingsdestinationThe
CopyPageMappingsdestinations are reserved with0x801(PAGE_NOACCESSplus a GPU bit), so the console gives the CPU no access there. Marking all 3,020 destination pagesPAGE_GUARDconfirmed it: no CPU access in 54 minutes. So the aperture is a small part of this, not the cause.2. Which views the CPU uses
A section view under Wine gets Linux page-table entries only once something touches the page through that view.
/proc/<pid>/pagemaptherefore shows per view whether the CPU used it, without changing protections. Three samples in the 22-draw state, all identical:PAGE_READWRITEview; their registered-pool and aperture views are never touched3. What this rules out and what it allows
ANONONLYrefuses. ProjectScarlett does not need it.Proposed design (not implemented)
MEM_REPLACE_PLACEHOLDER), so XMem's address layout stays the same.CopyPageMappingsaperture.This is not an AMD-only path: private memory can be imported on every driver, so with the pipeline separation you mentioned in #16, both vendors would keep the same memory model. NVIDIA should behave as before, but I have not tested it there.
Limits:
PAGE_READWRITEview as the CPU view comes from one title.@brcly, since you're holding #200 until there is an agreed approach: is this direction acceptable, or is there a reason XMem must keep sections? If it is, I'd measure backing contiguity next and then start with the 10 single-view imports, which need no aliasing at all.
Notes
Failed to import host memoryonly once (#16). Counting imports that contain section views on the provider side works on both Protons; I'd use that for the regression controls.mainstill setsANONONLYunconditionally.ANONONLYcause and to @JeffreyBytes for the measurements on the RX 6700 XT.@brcly on GitHub · 2026-11-26 01:46 UTC · original
Looking for help: let RADV read game memory directly
mainnow has a fallback from #200: when the host profile shows the GPU can't read imported game memory, TuxBox copies it. It passesbuffer-remap, but GPU writes stay in the copy and copying costs speed. We'd like to replace it with direct imports, without a preload library.What we know
runtime/xmem/src/shared_pages.rs,CreateFileMappingW+MapViewOfFile3), which Wine maps as shared memory.Ideas to test (none proven)
How to tell it works
section-import=aliasedon RADV with no override.python tuxbox.py checkpasses on AMD, includingbuffer-remap, and still passes on NVIDIA.TUXBOX_HOST_PROFILE=section-import=aliasedforces direct imports, which reproduces the failure on RADV.@JeffreyBytes on GitHub · 2026-11-26 02:56 UTC · original
One data point for "page remapping still behaves", from a long run with direct imports on RADV.
RX 6700 XT, Mesa 26.3.1, Linux 7.3.6, GE-Proton11-14,
cb8c38b, ProjectScarlett offline. To get direct imports I used theANONONLYpreload from earlier in this thread, as a diagnostic only. The run went through the Account Picker, intro video and first-run settings, then loaded for 82 minutes with no failed presents.At 96 minutes the title remapped pages under existing imports for the first time. The provider logged 24 lines of
page remap replaced imported range … retired stale GPU import(batches=272), and the next submit failed:The game then exited with code 3.
buffer-remappasses with the same preload, so the control does not cover this.I have not traced it further. My guess is that RADV submits every live buffer with each command stream, so a host-pointer import whose pages were remapped makes the kernel reject the whole submit with
EFAULT, even if the provider has already retired that import. If so, any design that imports the title's pages directly on amdgpu needs the old import fully destroyed before the remap, which NVIDIA would not reveal.@DrArroway on GitHub · 2026-11-26 07:10 UTC · original
Tested @brcly's Ideas #1 and #2 plus @JeffreyBytes's
-14(EFAULT) note using a standalone C++ D3D12 probe on RX 6900 XT (1002:73bf),GE-Proton11-14(vkd3d-proton 3.2.0), Mesa RADV26.3.1,TiledResourcesTier = 4,ID3D12Device13.Idea #1 — What imports directly (
OpenExistingHeapFromAddress1+ GPU copy readback)VirtualAlloc(MEM_RESERVE | MEM_COMMIT)aliasedVirtualAlloc2(MEM_RESERVE_PLACEHOLDER)split +MEM_REPLACE_PLACEHOLDER(MEM_PRIVATE)aliasedVirtualAlloc(... | MEM_WRITE_WATCH)aliasedCreateFileMappingW+MapViewOfFile(FILE_MAP_ALL_ACCESS)substituted(00000000)CreateFileMappingW+MapViewOfFile(FILE_MAP_COPY)substituted(00000000)CreateFileMappingW+MapViewOfFile3(MEM_REPLACE_PLACEHOLDER)substituted(00000000)Idea #2 — One
MEM_PRIVATEbacking + GPU-side aliases (CreatePlacedResourceandCreateReservedResource+UpdateTileMappings)CreatePlacedResourcebuffers at offset 0 on oneMEM_PRIVATEheap share writes cleanly (gpu:match,cpu:match).128 KiB)CreateReservedResourcerow-major buffers (D3D12_RESOURCE_FLAG_NONE) and mapped tiles across three separate64 KiBMEM_PRIVATEheaps (A,B,C) and a 2-tile contiguousMEM_PRIVATEheap (D) viaqueue->UpdateTileMappings:A,B) and sub-heap tile offset 1 (D) all match.res1tile 0 (heapA) is immediately visible both on CPU and viares2tile 1 (second alias ofheapA).res1tile 0 fromheapA→heapCviaUpdateTileMappingsreadsCcleanly withGetDeviceRemovedReason() == S_OK(noVirtualFree/unmap needed).(Note: this probe tested
CopyBufferRegionon reserved buffers; CBV/SRV/UAV shader access andALLOW_UNORDERED_ACCESSon reserved buffers still need a quick check.)@JeffreyBytes's
-14(EFAULT) reproductionMEM_PRIVATEpage withOpenExistingHeapFromAddress1, keeping thatID3D12Heapalive, calling eitherVirtualFree(MEM_RELEASE)orVirtualFree(MEM_DECOMMIT), and then submitting a completely unrelatedCopyBufferRegionon two ordinary committed buffers reproduces the crash in one submit:radv/amdgpu: The CS has been rejected, see dmesg for more information (-14)→VK_ERROR_DEVICE_LOST(0x80004005).MEM_PRIVATEbacking mapped until its importedID3D12Heapdrops (and remap GPU aliases in-place viaUpdateTileMappingsor new resources rather than pulling userptr pages out from under a live heap).@gtb-sbe, combined with your measurement in #191,
CreateReservedResource+UpdateTileMappingsalso removes the backing-contiguity requirement for those multi-alias imports (and handles remaps cleanly). Happy to test/benchmark if you're already moving forward with the single-CPU-backingxmemside, or collaborate on splitting thexmem+d3d12pieces once @brcly gives the green light.