Renderer port 1 placed (VICTORY_PORT_PLACED=1, off by default): Linux/RADV without userptr #420

Open
github-bot wants to merge 2 commits from github-bot/gh-420 into main AGit
Owner

@⁠jtrudeau1530 on GitHub · 2026-11-27 02:14 UTC · original
jtrudeau1530:feat/port-placed-linux → main · +1257 −9 · 9 files · 2 commits · open

Renderer port 1 placed (VICTORY_PORT_PLACED=1, with VICTORY_PORT_CONSTANTS=1; off by default)

What it does

Renderer port 1 opens the section views the title maps into its 32-bit graphics
reservation as a heap from an address (OpenExistingHeapFromAddress1). With
VICTORY_PORT_PLACED=1, at the title's first mapping of physical pages into that
reservation, xmem backs it with a D3D12 heap of the card's instead:

  1. a custom heap of the reservation's size (write-back, L0, buffers only);
  2. its VkDeviceMemory from vkd3d-proton (ID3D12DXVKInteropDevice3::GetVulkanHeapInfo, offset 0);
  3. vkd3d's CPU mapping let go with its addresses kept reserved (vkUnmapMemory2, RESERVE);
  4. the title's views unmapped and its placeholders committed read-write;
  5. the memory mapped over them at the title's address (vkMapMemory2, PLACED), and the pages the title had written copied in.

From then on the title's mapping calls in the reservation are bookkeeping only,
writes to those pages through Section::window go to the placed memory, and port 1
places its buffers in that heap at their offsets. Anything it cannot handle (pages
aliased elsewhere, other pages mapped in, VirtualFree there, a failed step) puts the
section views back and port 1 goes on as before. Each failure is logged; the
frame-rate line counts heaps placed, fallbacks and releases.

With the switch unset, nothing changes: every new path is behind port_placed::on()
or a non-empty placed list.

Why

Under Wine the heap port 1 opens is imported host memory, which RADV makes an amdgpu
userptr. Every protection change or unmap in the process then invalidates it. In a
probe, one mprotect took 29.5 ms against 1.6 ms while the GPU was busy. With the
card's own allocation mapped at the title's address, protection changes cost what they
cost on any memory.

Results

RX 7900 XT, walking route:

  • 19.2-19.9 fps against 18.5;
  • CPU prep 24 ms against 33 ms;
  • 1 heaps placed at the title's address (185 MB), 0 fallbacks.

Measured on our branch (upstream 014d52d merged, the same placed code), Wine 11.18 tree-index, vkd3d-proton master 71cae091, RADV, Series X, the same caches; ports 1 and 5 (VICTORY_PORT_CBV=1) on in both arms. Picture correct; VICTORY_PORT_CONSTANTS_ORDER's flicker fix active since port 1 runs. This branch itself is built (diag and release) but not run in game. Not tested on Windows.

Reviewer note: port_placed.rs spells out the ID3D12DXVKInteropDevice3 vtable order and IID; checked against vkd3d-proton 71cae091.

Enabling it on Linux

vkd3d-proton's device needs VK_KHR_map_memory2 and VK_EXT_map_memory_placed
enabled. The implicit layer in tools/vk-layer-placed/ does that; its README has the
build line and the manifest install (~/.local/share/vulkan/implicit_layer.d/). Then:

ENABLE_VICTORY_PLACED=1 VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_PLACED=1

Without the layer the placed mapping is refused, a warning is logged once, and port 1
runs as before.

Refs #163

AI-assisted (Claude Code).

**@⁠jtrudeau1530** on GitHub · 2026-11-27 02:14 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/420) `jtrudeau1530:feat/port-placed-linux` → `main` · +1257 −9 · 9 files · 2 commits · open Renderer port 1 placed (`VICTORY_PORT_PLACED=1`, with `VICTORY_PORT_CONSTANTS=1`; off by default) ## What it does Renderer port 1 opens the section views the title maps into its 32-bit graphics reservation as a heap from an address (`OpenExistingHeapFromAddress1`). With `VICTORY_PORT_PLACED=1`, at the title's first mapping of physical pages into that reservation, `xmem` backs it with a D3D12 heap of the card's instead: 1. a custom heap of the reservation's size (write-back, L0, buffers only); 2. its `VkDeviceMemory` from vkd3d-proton (`ID3D12DXVKInteropDevice3::GetVulkanHeapInfo`, offset 0); 3. vkd3d's CPU mapping let go with its addresses kept reserved (`vkUnmapMemory2`, `RESERVE`); 4. the title's views unmapped and its placeholders committed read-write; 5. the memory mapped over them at the title's address (`vkMapMemory2`, `PLACED`), and the pages the title had written copied in. From then on the title's mapping calls in the reservation are bookkeeping only, writes to those pages through `Section::window` go to the placed memory, and port 1 places its buffers in that heap at their offsets. Anything it cannot handle (pages aliased elsewhere, other pages mapped in, `VirtualFree` there, a failed step) puts the section views back and port 1 goes on as before. Each failure is logged; the frame-rate line counts heaps placed, fallbacks and releases. With the switch unset, nothing changes: every new path is behind `port_placed::on()` or a non-empty placed list. ## Why Under Wine the heap port 1 opens is imported host memory, which RADV makes an amdgpu userptr. Every protection change or unmap in the process then invalidates it. In a probe, one `mprotect` took 29.5 ms against 1.6 ms while the GPU was busy. With the card's own allocation mapped at the title's address, protection changes cost what they cost on any memory. ## Results RX 7900 XT, walking route: - 19.2-19.9 fps against 18.5; - CPU prep 24 ms against 33 ms; - `1 heaps placed at the title's address (185 MB), 0 fallbacks`. Measured on our branch (upstream `014d52d` merged, the same placed code), Wine 11.18 tree-index, vkd3d-proton master `71cae091`, RADV, Series X, the same caches; ports 1 and 5 (`VICTORY_PORT_CBV=1`) on in both arms. Picture correct; `VICTORY_PORT_CONSTANTS_ORDER`'s flicker fix active since port 1 runs. This branch itself is built (diag and release) but not run in game. Not tested on Windows. Reviewer note: `port_placed.rs` spells out the `ID3D12DXVKInteropDevice3` vtable order and IID; checked against vkd3d-proton `71cae091`. ## Enabling it on Linux vkd3d-proton's device needs `VK_KHR_map_memory2` and `VK_EXT_map_memory_placed` enabled. The implicit layer in `tools/vk-layer-placed/` does that; its README has the build line and the manifest install (`~/.local/share/vulkan/implicit_layer.d/`). Then: ```sh ENABLE_VICTORY_PLACED=1 VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_PLACED=1 ``` Without the layer the placed mapping is refused, a warning is logged once, and port 1 runs as before. Refs #163 *AI-assisted (Claude Code).*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:15:43 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 02:25 UTC · original

I’ve staged this on linux-amd-best for the RX 7900 XT. One thing I spotted in the layer while setting up the probe: the existing-feature branch casts away const and writes memoryMapPlaced and memoryUnmapReserve into the caller’s VkDeviceCreateInfo::pNext. Could that branch keep the supplied features untouched, and fall back if either flag is already disabled? It would also be worth checking both bits with vkGetPhysicalDeviceFeatures2 before injecting the layer-owned struct. Right now the extension names are the only check before enabling both.

**@⁠UwUCammie** on GitHub · 2026-11-27 02:25 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/420#issuecomment-7208110350) I’ve staged this on `linux-amd-best` for the RX 7900 XT. One thing I spotted in the layer while setting up the probe: the existing-feature branch casts away `const` and writes `memoryMapPlaced` and `memoryUnmapReserve` into the caller’s `VkDeviceCreateInfo::pNext`. Could that branch keep the supplied features untouched, and fall back if either flag is already disabled? It would also be worth checking both bits with `vkGetPhysicalDeviceFeatures2` before injecting the layer-owned struct. Right now the extension names are the only check before enabling both.
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 02:53 UTC · original

The layer test passed on the RX 7900 XT with RADV. Both placement feature bits were available, the layer added both extensions to a generated device request, and Vulkan created the device. I also tried a request that supplied both feature bits disabled. The patched layer passed it through and preserved the caller’s values. The AMD MSVC runtime check passed too.

I’m treating this as a device-creation check. The heap mapping and CPU/GPU round trip are the next runtime tests here. Layer change · Fixture and results

**@⁠UwUCammie** on GitHub · 2026-11-27 02:53 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/420#issuecomment-7208519551) The layer test passed on the RX 7900 XT with RADV. Both placement feature bits were available, the layer added both extensions to a generated device request, and Vulkan created the device. I also tried a request that supplied both feature bits disabled. The patched layer passed it through and preserved the caller’s values. The AMD MSVC runtime check passed too. I’m treating this as a device-creation check. The heap mapping and CPU/GPU round trip are the next runtime tests here. [Layer change](https://github.com/UwUCammie/VIctory-7900XTX/commit/dc1d9798) · [Fixture and results](https://github.com/UwUCammie/victory-amd/commit/c7eb574a)
Author
Owner

@⁠jtrudeau1530 on GitHub · 2026-11-27 03:06 UTC · original

Thanks, @⁠UwUCammie. Good catch. I took your layer change as is (92dd8cf). It no longer writes into the caller's pNext, it checks both bits with vkGetPhysicalDeviceFeatures2, and it passes the request through if the caller supplied either bit disabled.

Checked on an RX 7900 XT with RADV: the native placed-map test passes with maintenance5 both off and on. vkMapMemory2 PLACED lands at the requested address, the old map stays reserved, and the CPU and GPU bytes match. The layer installed here locally is now this version.

AI-assisted (Claude Code).

**@⁠jtrudeau1530** on GitHub · 2026-11-27 03:06 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/420#issuecomment-7208714023) Thanks, @⁠UwUCammie. Good catch. I took your layer change as is (92dd8cf). It no longer writes into the caller's `pNext`, it checks both bits with `vkGetPhysicalDeviceFeatures2`, and it passes the request through if the caller supplied either bit disabled. Checked on an RX 7900 XT with RADV: the native placed-map test passes with `maintenance5` both off and on. `vkMapMemory2` PLACED lands at the requested address, the old map stays reserved, and the CPU and GPU bytes match. The layer installed here locally is now this version. *AI-assisted (Claude Code).*
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-27 05:03 UTC · original

The D3D12 round trip passed here on the RX 7900 XT with Wine 11.22 and RADV 26.3.1, on both GE cae8353ed7959c4 and 71cae091b06571e. I used the placed layer in a scratch prefix. The runtime made the D3D12 heap, reserved its old CPU mapping, placed it at the test address, and used the port to make a buffer across a 64 KiB boundary. The GPU read the bytes the CPU had written, and the CPU saw a fenced GPU write across that boundary. Both runs verified the device and the result. Fixture

That's the heap path with generated data. The saved route still needs to show that the title selects the placed heap and renders with it.

**@⁠UwUCammie** on GitHub · 2026-11-27 05:03 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/420#issuecomment-7210309726) The D3D12 round trip passed here on the RX 7900 XT with Wine 11.22 and RADV 26.3.1, on both GE `cae8353ed7959c4` and `71cae091b06571e`. I used the placed layer in a scratch prefix. The runtime made the D3D12 heap, reserved its old CPU mapping, placed it at the test address, and used the port to make a buffer across a 64 KiB boundary. The GPU read the bytes the CPU had written, and the CPU saw a fenced GPU write across that boundary. Both runs verified the device and the result. [Fixture](https://github.com/UwUCammie/VIctory-7900XTX/commit/e4a28eba) That's the heap path with generated data. The saved route still needs to show that the title selects the placed heap and renders with it.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/420/head:github-bot/gh-420'
git switch 'github-bot/gh-420'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-420'
git switch 'github-bot/gh-420'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-420'
git switch 'github-bot/gh-420'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-420'
git switch 'main'
git merge --squash 'github-bot/gh-420'
git switch 'main'
git merge --ff-only 'github-bot/gh-420'
git switch 'main'
git merge 'github-bot/gh-420'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.