Skip to content

Under Wine: title pages shown with the host's mmap, and renderer port 1's heap opened in place (VICTORY_WINE_MAP, VICTORY_PORT_HOME) - #2455

Open
borntofrag34 wants to merge 3 commits into
trustno1-coder:mainfrom
borntofrag34:wine-map-port-home
Open

borntofrag34 wants to merge 3 commits into
trustno1-coder:mainfrom
borntofrag34:wine-map-port-home

Conversation

@borntofrag34

Copy link
Copy Markdown

Two changes for running under Wine/Proton, each behind its own switch. On Windows nothing changes: both act only when ntdll exports wine_get_version. They come from borntofrag34/VIctory-7900XTX's linux-wine branch, where they have been in use since 2026-11-26/27. They are ported here onto this tree's xmem, which has soft and lazy views, file-backed sections and the batched page mapper.

What changes

VICTORY_WINE_MAP (on under Wine; =0 brings back today's behaviour)

  • The problem: the title shows its physical pages one 64 KiB view at a time. The stock Wine server walks a linked list of all the process's views for every map and unmap (is_valid_view_addr, find_mapped_view). It does that while the calling thread holds ntdll's virtual_mutex, the lock every NtProtectVirtualMemory, NtGetWriteWatch, query and fault also takes. (docs/linux-proton.md already describes this list, with a patched wineserver as the workaround.)
  • What it does: where the host would have a placeholder, the reservation is a plain one.
    • A page is shown by mapping its section's file there with the C library's mmap (MAP_SHARED | MAP_FIXED; the descriptor comes from wine_server_handle_to_fd), then committing the range.
    • A page is taken away with MEM_DECOMMIT.
    • The title's VirtualFree of placeholders (split, coalesce, release) is done on pieces of the reservation that we keep track of.
  • Telling the GPU side: a query calls these pages "private", so the GPU side learns where these reservations are through title_view_space, which watch's is_view / readable_view / placeholder and inplace::private_whole use.
  • Safety net: at start-up, a page of a section of our own is shown this way, then read, written, protected and taken away. If any step fails, pages are shown as views, as before.

VICTORY_PORT_HOME (on with VICTORY_PORT_CONSTANTS=1 and VICTORY_WINE_MAP; =0: off)

  • The problem: vkd3d-proton opens a host heap on existing memory by importing it into Vulkan. With RADV that works for private memory and fails for a view of a section. vkd3d-proton then gives the heap memory of its own and reports success, so the card reads zeros and renderer port 1's frames are black. The kernel (amdgpu_ttm_tt_get_user_pages) also takes memory by address only as one mapping that the process owns.
  • What it does: before the 32-bit graphics heap's section is first shown, its whole stretch is made one anonymous mapping. Its pages then live there as private memory at the address the title maps them at; their bytes are copied in from the section, and back out when the title unmaps them.
    • If the title shows a page at a second address, the section goes back to being its file everywhere.
  • Opening the heap: port.rs opens the heap right there, with no view of ours. It checks through the card that the bytes really arrive, makes up to four attempts, and otherwise gives the stretch up (copied and guarded as before).
  • Guard rule: the guards never make these pages read-only. While one is read-only, the kernel refuses every submission and the device is lost. That rule is UwUCammie's 73d7b690 in the fork, credited in the commit.
  • Views under Wine: a stretch that is a view is now refused for the port under Wine, unless a one-time probe at start shows the card reads a view's bytes through such a heap. This avoids the black picture.

Side note, not changed here: with VICTORY_PORT_CONSTANTS unset, the GPU side's port is on by default (except on Ampere), but xmem's half (port_on, which runs arrange) defaults to off. The 32-bit heap is then never in one stretch, the log says not one native-import-eligible stretch of a section: Scattered, and nothing is ported. I think the same happens on Windows, but I have not checked. VICTORY_PORT_HOME only acts where VICTORY_PORT_CONSTANTS=1 is set explicitly.

Measured

  • Machine: RX 7900 GRE 16 GB + Ryzen 9 9900X, Arch with CachyOS kernel 7.3.6.
  • Software: Proton Experimental 11.0-20261112 (Wine 11.0, ntsync), vkd3d-proton 3.2.0, RADV (Mesa 26.3.1).
  • Settings: this tree's victory play settings with the frame clock at 16.667 ms. A save another player shared (issue 332) in a town, the same scripted walk each time. 300 s per run, read from 150 s on, diagnostics build, one run per setting.
Run Build / settings Frame (median) fps Submitting thread Waiting for the guards Changing protections Card busy
287 main 829188e (+ #2048 to build diagnostics) 63.5 ms 15.7 51.2 ms 49.4 ms 29.7 ms 68 %
291 this PR, VICTORY_WINE_MAP=0 62.2 ms 16.1 49.5 ms 44.3 ms 28.4 ms 70 %
292 this PR (defaults) 64.7 ms 15.5 51.5 ms 41.0 ms 28.0 ms 69 %
293 this PR, VICTORY_PORT_CONSTANTS=1 55.0 ms 18.2 40.8 ms 31.3 ms 20.9 ms 78 %
  • VICTORY_WINE_MAP alone does not make the frame shorter here. It takes the Wine server from 6.1 % to 0.4 % of a processor, the write-watch askings from 7.1 to 3.1 ms a frame and the texture refreshes from 9.9 to 5.5 ms. This tree's soft views and section windows already avoid most mapping calls. In the fork, which has neither, the same change took the guards' wait from 171 to 23 ms a frame and protection changes from 48 to 11 ms (first scene, 4K).
  • With the 32-bit heap in place (run 293):
    • 334 blocks a frame are made read-only instead of 494;
    • the frame is about 7 ms shorter, while drawing more per frame (6,435 draws against 5,771);
    • the card is busier (78 % against 70 %).
  • Noise: two runs of one setting lie 1 to 2 ms apart (287 against 291).
  • Still unexplained: each protection change still costs about 60 µs in this tree, against 17 µs in the fork on the same PC.
  • Picture: the frames kept from runs 291 to 293 are whole. The colour noise on the parked car's sill is there on main too.
  • Stability: no device lost and no amdgpu timeout in any of the runs.
  • The same numbers are written up in docs/linux-proton.md.

Not verified

  • Windows: not run. The code paths are behind on_wine(), but nothing was measured there.
  • Other hardware: NVIDIA under Proton, and any card other than this RX 7900 GRE. VICTORY_WINE_MAP is on by default under Wine for every card. Whether NVIDIA's driver imports private memory the same way was not checked; the port's own check through the card guards against zeros.
  • Scenes: only the town walk in these runs. In the fork, both changes have also run in the opening, the prison and missions since 2026-11-27.
  • Soft pool views: with VICTORY_SOFT_VIEWS covering the pool (1 or pool), the 32-bit heap is shown lazily and the port finds it uncommitted, so it falls back to copies. The launcher uses copies, which is fine.

Tests (under Wine, in a headless gamescope, on the card)

  • victory-hle xmem and wine_map: 49 passed, 1 failed. The failure, a_read_by_range_waits_only_for_a_remapping_that_meets_it, also fails on main. main gives 44 passed, 2 failed (that one and a_title_thread_goes_on_using_the_rest_of_a_view).
  • New tests, all passing:
    • under_wine_the_32_bit_heap_is_shown_as_memory_of_its_own;
    • under_wine_a_stretch_at_home_is_opened_where_it_is_and_a_view_only_if_shared, which runs on the card;
    • pages_at_home_are_never_made_read_only;
    • wine_map's three.
  • victory-gpu watch::, inplace::, port::: 73 passed, 4 failed. The four are many_askers_tests ×3 and what_is_left_alone_is_no_known_hole; main gives 71 passed and the same 4 failed.
  • Builds: release and diagnostics (with Clippy -D warnings clean across the workspace (main's CI gate) #2048) build.
  • Clippy: finds nothing new in the changed files. cargo clippy -D warnings and cargo xtask policy already fail on main (victory-shader, victory-loader, heap_sites/frame_users.rs).

🤖 Generated with Claude Code

borntofrag and others added 3 commits November 29, 2026 14:03
…side Wine's server (VICTORY_WINE_MAP=0: views in placeholders, as before)

The title shows its physical pages one 64 KiB view at a time
(XMemMapPhysicalPagesScatter and the GPU's page-mapping copies), with tens
of thousands of views there. Wine's server keeps a process's views in a
linked list and walks it for every view mapped (is_valid_view_addr) and
unmapped (find_mapped_view), while the calling thread holds ntdll's
virtual_mutex: the lock every NtProtectVirtualMemory, NtQueryVirtualMemory,
NtGetWriteWatch and every fault of the process takes too. So the guards'
protection changes and faults wait behind the title's mapping calls.

Under Wine only (wine_get_version in ntdll), where the host would have a
placeholder the reservation is a plain one; a page is shown by mapping the
section's file there with the C library's mmap (MAP_SHARED | MAP_FIXED; the
descriptor from ntdll's wine_server_handle_to_fd, the same pages as any
view of the section), then committing the range, which under Wine sets its
books and protection and nothing else. It is taken away by MEM_DECOMMIT.
Protections, queries and faults go through Wine as before. A query calls
such a page private, so the GPU side is told where these reservations are
(victory_gpu::title_view_space). The title's VirtualFree of placeholders
(split, coalesce, release) is done on pieces kept of the reservation. A
page of a section of our own is shown this way at the start, read, written,
protected and taken away; if any of that fails, pages are shown as views.
On Windows nothing changes.

Measured on an RX 7900 GRE + Ryzen 9 9900X, Proton Experimental (Wine 11.0,
ntsync), vkd3d-proton 3.2, in the borntofrag34/VIctory-7900XTX fork where
it was written (2026-11-26): in the first scene 768 -> 13 ms of every
second in mapping calls, waiting for the guards 171 -> 23 ms a frame,
changing protections 48 -> 11 ms (runs 9 and 11); with the pipeline
workers' fix as well, 136 -> 11 ms and 41 -> 7.7 ms (runs 21 and 19).

Ported from borntofrag34/VIctory-7900XTX 94530f03 onto this tree's xmem
(soft and lazy views, file-backed sections, batched page mapper).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ics pages where the title has them (VICTORY_PORT_HOME=0: as before)

vkd3d-proton opens a host heap on memory by importing it into Vulkan
(VK_EXT_external_memory_host); where the import fails it gives the heap
memory of its own and reports success. With RADV it works for private
memory and fails for a view of a section: the card reads zeros there and
every frame of the port is black. And the kernel (amdgpu's
amdgpu_ttm_tt_get_user_pages) takes memory by address only as one mapping
of the process's own, from first byte to last.

With VICTORY_PORT_CONSTANTS=1 and VICTORY_WINE_MAP on, under Wine only:
before the 32-bit heap's section is first shown, its whole stretch is made
one anonymous mapping (one mmap, then committed); its pages are then shown
as that private memory at the one address the title maps them at, their
bytes copied in from the section and back out when they are unmapped. If
the title shows one of them at a second address, the section goes back to
being its file everywhere. The port opens its heap right there (no view of
ours), asks the card what it reads through it, and tries four times before
giving the stretch up (copied and guarded as before). The guards never make
such pages read-only: while one is, the kernel refuses every submission and
the device is lost (UwUCammie, borntofrag34/VIctory-7900XTX 73d7b690). A
stretch that is a view is refused under Wine unless the card reads the
view's bytes through such a heap (one probe at the start).

Today, with VICTORY_PORT_CONSTANTS unset, the GPU side's port is on but
xmem's half (arrange) is off, so the heap is "Scattered" and never in
place; this commit does not change that: PORT_HOME acts only where the
switch is set to 1.

Measured in borntofrag34/VIctory-7900XTX (RX 7900 GRE, Proton Experimental,
first scene at 1920x1080, 2026-11-27): 40.5 -> 33.4 ms a frame, changing
protections 7.7 -> 3.7 ms, the submitting thread 37.7 -> 29.0 ms (runs 30
and 33). On Windows nothing changes.

Ported from borntofrag34/VIctory-7900XTX 1be9bdaa and 73d7b690.

Co-Authored-By: UwUCammie <UwUCammie@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in town on an RX 7900 GRE (55.0 ms a frame against 62.2 to 64.7)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@borntofrag34

Copy link
Copy Markdown
Author

Follow-up on "each protection change still costs about 60 µs here … not explained yet": a run with VICTORY_AB=10,VICTORY_FAULT_UNLOCKED (run 294, same town walk, 600 s, 22 phases each side) explains it. With unlocked faults (default) protections are 20.4 ms a frame and the faults never wait for the guards' lock. With the locked way they are 6.2 ms, but the faults wait 28.9 ms for the guards' lock, and the frame is the same (45.5 against 46.4 ms). About 310 faults a frame either way. The 55-60 µs is the faults' VirtualProtect calls queuing on Wine's virtual_mutex with each other, so the wait only moves from one counter to the other. Nothing to change there; the gap to the fork is elsewhere (its submitting thread works ~30 ms a frame here against ~40).

@Kassadd

Kassadd commented Nov 29, 2026

Copy link
Copy Markdown

A Wine run on the current tree, and one number that may be worth a look.

Built main at cec481f4 (the tree of v2026.11.29.03) with this PR merged on top — it
applied with no conflict — plus #2585, and ran it under Proton.

Environment: RTX 4080 SUPER 16 GB, i9-14900K, 62 GB, CachyOS, Hyprland (Wayland),
NVIDIA 620.73.04, Proton Experimental ...-20261128 (vkd3d-proton 71cae0), Series X
1.0.2.1, --res 1080to1440, shader cache emptied first as the release notes ask.

The start-up check runs. The log has
wine_map: title pages are shown with the host's mmap, beside Wine's server (VICTORY_WINE_MAP=0: as views), then the VirtualFree lines for reservations that stand
for placeholders. Nothing warns and nothing falls back to views. VICTORY_PORT_HOME I
did not test separately.

The run: 6m 13s, 19–29 fps, up to 11,795 draws/frame, no Xid in the kernel log and
no device lost; I stopped it, it did not die. That is the longest run I have had under
Wine, but I cannot attribute it to this PR. Three runs, one variable apart:

run duration ended
.03 as released 1–3 min 0xc000001d
.03 + #2585 only 5m 06s stopped; no fault
.03 + #2585 + #2455 6m 13s stopped; no fault

The difference between the last two is 1m 7s and I did not exercise VICTORY_WINE_MAP=0
to isolate it, so I am not claiming the extra minute as this PR's. What this run does
establish is that the Wine mmap path works for six minutes of play without a fault of
its own.

The number I think matters. With the camera still, a frame is 51 ms, and the layer's
own breakdown puts 34 ms in preparing, 18 ms of it in copies for 77 MB, with the
card at 3.8 ms (7% busy) and 67,000 list calls a frame. Turning the camera makes it
worse — the frame goes to 8 fps — but I do not have that breakdown for a turning frame,
so I cannot say the 34 ms is what grows. If this PR is meant to help the memory path
rather than to fix a fault, that 18 ms is where I would expect it to show, and on this
one machine and this one measurement I did not see it move. I have no A/B for copies
without the PR, so that is an observation to check, not a finding against it.

What I did not do: Windows, a patched wineserver to compare against, or a longer run.
Logs and the exact invocation are available on request.

JustOptimize added a commit to JustOptimize/VIctory-Enhanced that referenced this pull request Nov 29, 2026
… heap opened in place (PR trustno1-coder#2455)

Port of trustno1-coder#2455 (VICTORY_WINE_MAP on under Wine,
VICTORY_PORT_HOME with VICTORY_PORT_CONSTANTS=1) onto this fork's main, applied
with a 3-way merge; no conflicts. Nothing changes on Windows (both act only when
ntdll exports wine_get_version).

Tried here, RTX 3080 10 GB, Proton, native 1080p, pool at its default, same scene,
played: no Xid in 484 s, Wine server CPU about 3%, game memory unchanged (about
19 GB, so RAM stays tight). Frame rate over the whole run is on par with the build
without it (14.2 fps / 74 ms against 14.6 fps / 74 ms); the first minutes looked
faster (15.8 fps / 68 ms) but that did not hold. The user reported it feels good.
One run each: an indication, not a benchmark. PORT_HOME is a RADV fix and was not
exercised on this card.
JustOptimize added a commit to JustOptimize/VIctory-Enhanced that referenced this pull request Nov 29, 2026
…one lock (PR trustno1-coder#3268, shadow.rs part)

From trustno1-coder#3268 (banaanpapa): Shadow::take_all groups the
parts of a refresh into tasks of about 256 KiB; a task's marks are kept on its
thread and told once ([`Shadow::telling_once`]). The PR's host.rs/bus.rs/placement.rs
benches and audit text come with it. One conflict, in take_all: the PR's `wide_each`
with a pointer cast is replaced by this tree's `wide_each_scoped`.

Tried here (RTX 3080, Proton, native 1080p, pool at default, played): no Xid in
5:24; the user reports it is better. The logs do not show it clearly: frame rate
within noise of the build without it (15.7 fps / 73 ms against 14.6 fps / 74 ms);
texture refresh CPU per frame about 5 ms against about 24 ms in the run with trustno1-coder#2455
alone (4 ms in a baseline without trustno1-coder#2455, so scene or trustno1-coder#2455 may explain part). Put on
main at the user's call; a longer, repeated run has not been done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants