Linux: an LD_PRELOAD shim that lets amdgpu import Wine's memfd sections as userptr #235

Open
fsrajner wants to merge 2 commits from upstream-pr/235 into main
fsrajner commented 2026-11-29 22:42:32 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by fsrajner on 2026-11-29T22:42:32Z.


Builds on #234 (its one commit is included here; it lets .c files pass the asset policy).

The finding: under Proton, vkd3d-proton opens a heap on title memory with VK_EXT_external_memory_host, which RADV makes an amdgpu userptr buffer. libdrm always asks with AMDGPU_GEM_USERPTR_ANONONLY, and Wine keeps sections (the title's physical pages) in memfds, so the kernel refuses the import and vkd3d-proton silently gives the heap memory of its own: the card reads zeros where the title's bytes are.

The shim (scripts/linux/userptr-shim) clears only that flag in only DRM_AMDGPU_GEM_USERPTR; the import then works and every view of the section sees what the card writes. The README also says what it costs: the kernel walks every userptr page at every submission (0.9 ms per 185 MB), so it is a proof and a diagnostic rather than a fast path, and points to the faster way round that was measured on another branch.

Nothing in the runtime changes. Tested: built with cc -O2 -Wall, used on an RX 9070 XT with Mesa 26.3.1 and Proton Experimental; cargo xtask policy passes.

🤖 Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5555938614 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/235). Originally posted by [fsrajner](https://github.com/fsrajner) on 2026-11-29T22:42:32Z. --- Builds on #234 (its one commit is included here; it lets `.c` files pass the asset policy). **The finding:** under Proton, vkd3d-proton opens a heap on title memory with `VK_EXT_external_memory_host`, which RADV makes an amdgpu userptr buffer. libdrm always asks with `AMDGPU_GEM_USERPTR_ANONONLY`, and Wine keeps sections (the title's physical pages) in memfds, so the kernel refuses the import and vkd3d-proton silently gives the heap memory of its own: the card reads zeros where the title's bytes are. **The shim** (`scripts/linux/userptr-shim`) clears only that flag in only `DRM_AMDGPU_GEM_USERPTR`; the import then works and every view of the section sees what the card writes. The README also says what it costs: the kernel walks every userptr page at every submission (0.9 ms per 185 MB), so it is a proof and a diagnostic rather than a fast path, and points to the faster way round that was measured on another branch. Nothing in the runtime changes. Tested: built with `cc -O2 -Wall`, used on an RX 9070 XT with Mesa 26.3.1 and Proton Experimental; `cargo xtask policy` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/235:upstream-pr/235'
git switch 'upstream-pr/235'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/235'
git switch 'upstream-pr/235'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/235'
git switch 'upstream-pr/235'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/235'
git switch 'main'
git merge --squash 'upstream-pr/235'
git switch 'main'
git merge --ff-only 'upstream-pr/235'
git switch 'main'
git merge 'upstream-pr/235'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
DexNom/VIctory!235
No description provided.