Skip to content

GPU: title memory in place by default where the host GPU shares memory with the CPU (stacked on #2112, #2912, #2921) - #2945

Closed
0xkn0wh3r3 wants to merge 34 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/in-place-on-unified
Closed

0xkn0wh3r3 wants to merge 34 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/in-place-on-unified

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2112 (desplmfao), #2912 and #2921. New here: 7b6882b, 1c87ba0, 1fc5441 and 3ed7d72; the rest is those three PRs merged. Draft until they land.

Problem

On a host whose GPU shares memory with the CPU (an AMD or Intel APU, an integrated GPU, Apple silicon under a translation layer), host copies of title memory buy no GPU time. A synthetic benchmark on the Ryzen 7900X's integrated Radeon (the benchmark summarised in #2912) measured every placement within noise of every other: today's copies, title memory opened in place, upload heaps and "video memory".

The copies there only cost their refreshes and copy-backs, which are 45–76 ms per synthetic world frame on main. #2112 can read title memory in place, but it is opt-in on every host.

Also, while a heap is open over title memory, Windows refuses VirtualProtect, UnmapViewOfFile2 and VirtualFree (error 87), so the title cannot free or remap that memory. #2921 adds a registry for exactly this; #2112's heaps were not in it.

What this changes

  • Self-test (moved here from GPU: the host says whether its GPU shares memory with the CPU #2912 on its triage): crate::unified::self_test.

    1. A write-watched block is opened with OpenExistingHeapFromAddress1.
    2. A copy queue does a round trip through it, and both directions are checked.

    It runs once, the first time the default is asked, and only where GPU: the host says whether its GPU shares memory with the CPU #2912's detection reports UMA. Discrete hosts never run it. It catches layers that have the method but don't share the memory (vkd3d-proton without VK_EXT_external_memory_host makes new memory). It takes 3-20 ms.

  • Default: with VICTORY_IN_PLACE unset, in place is on where the host reports UMA and the self-test passes. The log says so once, or logs why the copies stay.

    • =1 keeps it on everywhere.
    • Any other value turns it off, as before.
    • Discrete GPUs are unchanged: in place there reads across the bus as the copies do, and a title-level gain is not shown yet.
  • Pins: every heap GPU: title memory in place instead of copied, opt-in (VICTORY_IN_PLACE=1; stacked on #2088, towards #880) #2112 opens is registered with crate::pinned:

    • a sub-range heap per buffer, released with let_go_in_place(start, len);
    • a whole-allocation heap on hosts without ID3D12Device13, released with let_go_heap(id).

    The title's frees, protections and remaps (HLE, GPU: title memory held in place is let go before the title or the runtime changes it #2921's wrappers, xmem's unmapping) first stop handing out what is placed there; the change then succeeds once the heap goes. The registration is forgotten when the heap is destroyed (ID3DDestructionNotifier), so pins don't pile up. Each placed buffer holds its heap through private data (SetPrivateDataInterface), so the heap, and its pin, last as long as the buffer on every backend. vkd3d-proton destroyed a sub-range heap as soon as in_place_buffer returned, while the buffer still lived (reported by pickles976 on Wine/vkd3d-proton, NVIDIA; fixed in 1fc5441). A buffer that cannot hold its heap is refused.

  • README: the VICTORY_IN_PLACE paragraph says when it is on by default.

Limits

Tests

  • shadow::tests::the_title_frees_memory_a_window_is_in_place_over:
    1. A window is put in place over a 1 MiB allocation.
    2. title_memory_change with the title's VirtualFree drops the window and its heap first.
    3. The free succeeds and the pin is gone.
    4. Then a heap that goes by itself takes its pin along.
  • shadow::tests::a_buffer_in_place_holds_its_heap_and_pin: on the sub-range and the whole-allocation path, with nothing but the returned buffer holding the heap, the pin stays while the buffer lives and goes with it. Passes on the RTX 5070 Ti; not yet rerun on vkd3d-proton. On CI's WARP the pages were let go a little after the buffer went, so the tests that free right after now retry for up to 1 s (3ed7d72), as title_memory_change does for 100 ms.
  • title_memory_is_in_place_by_default_on_a_unified_host: the default equals "UMA and self-test passed".
  • unified::tests::the_answer_names_what_was_not_shared and title_memory_opens_in_place_on_warp: the self-test.
  • On WARP (a unified host; diagnostics build with VICTORY_D3D12_WARP=1), in place came on by default, and 268 of 269 victory-gpu tests passed. The failure, frame::tests::waits_end_on_ticks_and_count_frames, is a timing test and passed three times alone.
  • On the RTX 5070 Ti (default off): 253 passed, 2 failed. The two, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, fail the same way on clean main on this machine.
  • victory-hle: 154 passed. Workspace clippy (both configurations) is clean.

Related

kxiserino and others added 29 commits November 24, 2026 23:32
…oose windows that hold a range

`shadow::find` looked at only the 64 buffers starting closest below an
address. A big buffer with more than 64 smaller buffers placed in it
before the address was missed, and the range fell through to `loose`,
which made a second 4 MiB host copy of memory the big buffer's copy
already had, not aliased with it. The search now goes back as far as the
longest buffer registered so far (`MAX_SPAN`): one starting further below
cannot hold the range.

`loose` reused a window only for the exact same (start, length), so a
range inside a window made for a range spanning two windows got another
copy. It now reuses any window holding the range. It also gives no copy
for null-page addresses, or for memory that is not committed when a new
window would be made, instead of 4 MiB of zeros.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Memory outside every buffer object gets host copies of the aligned
windows lookups touch. While Grand Theft Auto VI loads its world, about
700 such 4 MiB windows (3.4 GB of host memory) were live; the lookups
touched about 30% of their bytes (in 64 KiB pieces). With 256 KiB
windows, at the same point of loading: 5,713 windows, 2.2 GB, and the
process 15.4 GB instead of 17.3 to 20.4 GB. No descriptor-slot warnings
for the extra windows' page-table entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With VICTORY_IN_PLACE=1, a loose window is the title's memory itself:
the allocation holding it is opened as a host heap
(OpenExistingHeapFromAddress; VK_EXT_external_memory_host under
vkd3d-proton) and a buffer is placed at the window's offset. Nothing is
copied to the host or back, and the window needs no page guards. Only the
committed part of the window around the asked range, cut to 64 KiB, is
used; ranges that are not one committed allocation keep the copy. A
remap of title memory drops the in-place windows and heaps over it, so a
later lookup opens the new pages; lists still holding an old window keep
its (pinned) pages until they are reset.

Off by default. RTX 5080, proton-cachyos 11.0, vkd3d-proton 3.2.0, Grand
Theft Auto VI loading its world: 1,448 windows in place, none refused,
no device errors; loose-window host memory at the same point of loading
79 MB instead of 2.2 GB (256 KiB copies) or 3.4 GB (4 MiB copies).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ETY comments)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title buffer object's copy is, with VICTORY_IN_PLACE=1, the title's
memory too: placed from the 64 KiB boundary at or below the buffer
(views find their bytes by address), past its end by 256 bytes where the
allocation has them. A placed buffer's end only needs to be committed
pages, not 64 KiB. A remap drops in-place title buffers over it as well.

Buffers over many separately mapped 64 KiB views (MEM_MAPPED, one
allocation each) are still copied: one heap cannot span them, and tile
mappings into heaps opened over process memory were not reliable under
vkd3d-proton here.

Measured (RTX 5080, proton-cachyos 11.0, the title loading its world,
with Marvisak#259, Marvisak#177 and Marvisak#1849 on top for NVIDIA under Wine): 3,335 title
buffers and 2,117 loose windows in place, none refused, no device
errors; 8 large buffers (378 MB) over separate views still copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The title releases some of its memory itself, which we do not see. A
heap opened over an allocation that is no longer the same (released,
another size, or not all committed) is now let go, with the in-place
windows and title buffers placed in it: when the heap would be reused,
and once a frame for all opened heaps. What this cannot tell is an
allocation released and made again at the same address with the same
size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…opened heap

Windows did not release memory a heap was opened over while the heap
lived (CI: the allocation was still there after VirtualFree); Wine
releases it at once. The test now lets go of the heap in that case and
checks that the release succeeds then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the next frame

find holds BUFFERS and loose holds LOOSE when they call
in_place_buffer, and letting go of what is placed in a stale heap takes
both locks again (found by yualk in review). in_place_buffer now only
drops the stale heap from the cache and queues it; check_in_place lets
go of its windows and buffers at the next frame, outside those locks.
Test: a_stale_heap_is_replaced_under_the_callers_locks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the cache

They share the heap cache and the queue of stale heaps, and a parallel
test can get the same address back (CI). The stale-heap test now makes
the cached entry stale itself: Windows does not decommit memory a heap
was opened over while the heap lives, so the decommit did nothing there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening a title allocation as a host heap makes all of it resident: the
host memory import pins every page, also committed pages the title never
touched. Grand Theft Auto VI keeps most buffers in two large pools that
were 10% and 31% resident (2.3 and 1.2 GB), so in place cost 1.9 GB more
anonymous memory for 1.4 GB fewer copies.

An allocation now goes in place only if at least 90% of its pages are
already in memory (QueryWorkingSetEx, at most 64Ki pages sampled; asked
again after 10 s; VICTORY_IN_PLACE_DENSITY sets the percentage). Sparse
ones keep their copies. In the world: anonymous memory as without in
place (4.9 GB), 0.3 GB fewer copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Where the device has ID3D12Device13, a buffer in place is a heap over
its own pages (OpenExistingHeapFromAddress1) instead of the whole
allocation: nothing else of the allocation becomes resident, so no
density check applies, and the placed buffer holds its heap, which goes
with it. vkd3d-proton has no ID3D12Device13 and keeps the whole-
allocation heaps with the density check.

The density decisions are keyed by allocation base and size: an
allocation made again at the same address is a new one. Tests: a sparse
allocation is not opened whole; a sub-range heap covers only its
buffer (where the host has one); the heap-cache tests take the
whole-allocation path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… safety comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One run at 70% hung while the world loaded; a later run without in-place
hung the same way, so the hang is not shown to come from the threshold.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shaders reach memory in place over the bus; for small, often-touched
buffers (atomics, constants) that costs more than the copy: sirrus98
measured a once-a-frame compute pass over a tiny buffer in host memory
at 19-67 ms of GPU time instead of 1-6 ms (RTX 4090, for the in-place
work of fxceless/victory-fork#772, which keeps the same 1 MiB floor).
VICTORY_IN_PLACE_MIN_KB sets it. Loose windows are not affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A heap found stale is queued for the frame's check, and by then a new
heap may be open at the same base with buffers placed in it. Letting go
by address range dropped those too. Each opened heap now has an id; the
queue and the periodic check let go of that heap and of what is placed
in it only. Remaps still let go by address.

Reported by nathanbzrr on Marvisak#2112.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refreshing a copy also keeps it alive until the list is reset; an
in-place buffer has nothing to refresh, so `refresh` and `gpu_writes`
returned before anything held it. The title releasing the buffer, or a
stale heap being let go, between recording and submission then freed a
resource whose GPU address the list names. Both now keep the placed
buffer once per list (`HostList::keep_once`); a placed resource holds
its heap, so the heap lives as long.

Reported by nathanbzrr on Marvisak#2112.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The argument clamp writes the records where it reads them. For a copy
that is our memory; for a buffer in place it is the title's own, which
the clamp changed under it. In-place records are now copied on the GPU
(after the title's passes that wrote them) into one buffer per list,
clamped and executed there. Copies keep the clamp in place as before.

Reported by nathanbzrr on Marvisak#2112.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy-back writes title memory under `watch::writing`, so other copies
of the same pages (title buffers under the in-place floor, a structured
view's own copy, textures) see them changed and copy again. A buffer in
place has nothing to copy back: the shaders' writes land in title memory
unseen by guards and write watch, and those other copies kept their
older bytes. After the submission, the ranges written in place (declared,
or marked through the memory page table, withheld or not) are now marked
changed the same way.

Reported by nathanbzrr on Marvisak#2112.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since stale heaps are let go by id, `a_stale_heap_is_replaced_under_the_
callers_locks` left the heap opened in place of the stale one cached at
its base, and freed the memory. A later test given that address back
(`a_sub_range_heap_covers_only_the_buffer`, run after it) found the
entry and failed. The address-based let-go hid this by also dropping the
new heap, which was the bug. The test now lets go of its memory's heaps
before freeing it, and the sub-range test checks that its call adds
nothing to the cache rather than that the cache has nothing at the base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… in place

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's indirect clamp (315cea1) now reads the title's records through a
root view and writes the clamped ones into an argument buffer of the
list's own, so it no longer writes title memory: the in-place copy of the
records (indirect::copied, HostList::arguments(len), Shadow::in_place and
their test) is dropped and draw.rs, indirect.rs follow main as is. Copies
sharing a buffer (6cc6aa3): Shadow keeps both main's base/slice and the
in-place flag and heap; new, new_at and new_with all build through one
constructor, and in-place buffers (own buffer, base 0) stay untracked
(track_copy for copies). Shadow::update returns early in place as well as
when clean. keep_once, check_in_place at present and the landed marks
after withheld submissions sit unchanged beside main's drop_withheld.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecks that title memory opens in place

At host creation, `unified::detect` reads ARCHITECTURE1 (UMA, cache-coherent
UMA), OPTIONS16 (GPU upload heaps) and the DXGI budgets. It also runs a
self-test: a write-watched block, allocated as the title's pools are, is
opened with OpenExistingHeapFromAddress1, and a copy queue copies its first
half out and other bytes into its second half. The answer is what the GPU
did: a layer can report the method and still not share the memory.

The result goes on one log line and into the GPU failure text. Nothing
changes behaviour on it yet; later placements (in place on unified hosts,
video memory for hot buffers on discrete ones) can gate on it.

`uma_bench` (ignored) probes every adapter and WARP: what opening title
memory implies (protect, unmap and decommit fail with error 87 while a heap
lives; a read-only page fails the open; write watch sees CPU writes, not the
GPU's). It times GPU access per placement and pattern, and GPU copies
between video memory and the rest.
…e runtime changes it

A GPU heap opened over title memory (OpenExistingHeapFromAddress1, as
Marvisak#2112 does) locks its pages. While it lives, VirtualProtect,
UnmapViewOfFile2 and VirtualFree fail with ERROR_INVALID_PARAMETER, on
NVIDIA, AMD and WARP alike. The title frees and remaps such memory.

victory_gpu::pinned keeps a registry of held ranges, each with how to let
it go. title_memory_change(at, len, change) releases every holder
overlapping the range, then runs the host call. The system sometimes
unlocks released pages late (RTX 5070 Ti: 32 of 40 within 0.01 ms, the
slowest 5.9 ms), so after a release a call refused with that error is
tried again for up to 100 ms.

The changes go through it:
- the title's VirtualFree, VirtualFreeEx, VirtualProtect, VirtualProtectEx,
  UnmapViewOfFile, UnmapViewOfFileEx and UnmapViewOfFile2 (new HLE module
  memoryapi; everything else in those DLLs stays the host's);
- xmem's unmapping of physical pages;
- XMemFreeDefault's release of 32-bit memory.

Nothing registers a pin on main yet, so the cost is one atomic load per
call. Holders (Marvisak#2112, Marvisak#2734) register when they open a heap.
…waits for it

Review (fuzeofficlal): the pin count dropped before the release callbacks
ran. A second thread changing an overlapping range could then see nothing
held, call VirtualFree or VirtualProtect while the first was still dropping
the heap, and get ERROR_INVALID_PARAMETER without a retry.

Released pins now stay counted, as releasing, until their callback returns.
A change on another thread that overlaps one waits on a condition variable
for it, then gets the late-unlock retry. A release running on the caller's
own thread is not waited for, so a callback that changes memory itself
does not deadlock. The docs also say never to change title memory through
here from the guard handler or under watch's lock: a release may wait for
a submission.

Test: a change on a second thread waits for a 50 ms release running on the
first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	crates/victory-gpu/src/shadow.rs
…y with the CPU

Stacked on Marvisak#2112 (title memory in place, opt-in), Marvisak#2912 (host memory
detection and in-place self-test) and Marvisak#2921 (pins of title memory held in
place).

Default changes:
- VICTORY_IN_PLACE unset is now on where the host reports UMA and title
  memory passed the self-test at start. There shaders reach every placement
  at the same speed (an AMD APU: all within noise, synthetic), so copies
  only cost their refreshes and copy-backs.
- =1 stays on everywhere; another value is off.
- Discrete GPUs keep copies unless =1.

Each heap opened over title memory, per buffer or per allocation, is now
registered with crate::pinned. The title's frees, protections and remaps
there, which fail while the heap lives, first let go of what is placed in
it. The registration goes with the heap, through
ID3DDestructionNotifier.

Tests:
- the title's free of memory a window is in place over lets go of the
  window and its heap first, and succeeds;
- a heap that goes by itself takes its registration along;
- the default equals "unified and self-test passed".
On WARP, a unified host, in place came on by default, and 267 of 268 GPU
tests passed (the one failure, a frame-timing test, passes alone).
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and triple-adapter (NVIDIA RTX 5090 discrete + AMD Radeon RDNA2 iGPU + WARP) verification at head 7b6882b773c0 (stacked on #2112, #2912, #2921):

  • UMA / CacheCoherentUMA & pinning audit (title/shadow.rs:1184, 1201-1226, title/pinned.rs):
    • Defaulting in_place_enabled() to h.memory.uma && h.memory.in_place.is_ok() (without requiring CacheCoherentUMA == true, instead guarding on the startup unified::self_test bidirectional visibility + write-watch probe) is validated directly by hardware below; explicit VICTORY_IN_PLACE overrides cleanly.
    • Every opened in-place heap pins its range via pin_heap and unpins via ID3DDestructionNotifier::RegisterDestructionCallback (with immediate cleanup on registration failure).
  • Live triple-adapter uma_probe results (Windows 11, Rust 1.98.1):
    1. NVIDIA GeForce RTX 5090 (discrete): uma=false, ReBAR, 31419 MiB local / 45969 MiB non-local -> default in_place_enabled() == false.
    2. AMD Radeon(TM) Graphics (RDNA2 iGPU): unified with the CPU's, cache-coherent false; title memory opens in place; budgets 47991 MiB local, 0 MiB non-local (4.06 ms) — private 4 MiB, private write-watched 4 MiB, and section view all report GPU sees CPU writes true, CPU sees GPU writes true, GPU write triggers 0 watch pages, and CPU write to 2 pages triggers 2 watch pages. Directly confirms enabling in-place on AMD APUs despite CacheCoherentUMA=false.
    3. Microsoft Basic Render Driver (WARP): uma=true, cache-coherent true; title memory opens in place -> default in_place_enabled() == true.
  • Verified (VICTORY_D3D12_DEBUG=1):
    • cargo xtask policy: 195 files ok; cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings (default + --features diagnostics): 0 warnings
    • RTX 5090 (unified:: title_memory_is_in_place_by_default the_title_frees_memory_a_window_is_in_place_over pinned::): 10/10 passed
    • WARP (--features diagnostics, unified:: shadow:: pinned::): 33/33 passed; victory-hle -- xmem memoryapi: 16/16 passed.

Looks great once the stacked prerequisites (#2112/#2912/#2921) land; LGTM.

… the benchmark go

Triage: detection ran a self-test (a heap opened over a write-watched block,
copies on a queue of its own: 3-20 ms) at every host creation, only to log
its answer.

What stays here, for the log line and the GPU failure text:
- ARCHITECTURE1 (UMA, cache-coherent UMA);
- OPTIONS16 (GPU upload heaps);
- the DXGI budgets.
That is about 0.3 ms on an RTX 5070 Ti.

The self-test moves to the change that acts on it (Marvisak#2945). The ignored
benchmark (uma_bench.rs) leaves the repository; its results are in the PRs.
…t decides the default

Marvisak#2912's triage moved the self-test here, to the change that acts on it.
crate::unified::self_test is unchanged: a write-watched block opened with
OpenExistingHeapFromAddress1, a copy queue's round trip, both directions
checked.

It no longer runs at host creation. VICTORY_IN_PLACE unset asks it the
first time, and only where the host reports unified memory. A failure keeps
the copies and is logged with its reason. Discrete hosts never run it.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — reviewed the delta on top of the stacked PRs (7b6882b, cdf12e9).

  • in_place_enabled semantics match the PR description exactly: =1 on everywhere, any other set value off, unset → UMA + self_test pass. The OnceLock runs the self-test at most once, lazily on first use, and only on UMA hosts — discrete hosts never pay it.
  • Moving self_test out of detect is the right call: every host creation used to run a 3-20 ms GPU round trip whose answer nothing consumed. detect is now the cheap queries it's described as; Memory no longer carries the in_place field.
  • pin_heap covers both heap paths: whole-allocation opens pin [start, start+size) with let_go_in_place(start, len) releasing the placed window, and sub-range heaps pin their own range with let_go_heap(id). The two destruction outcomes are handled symmetrically — heap destroyed by itself → forget drops the registration; title tries to change pinned memory → release runs first, outside the registry lock. The RegisterDestructionCallback failure path correctly leaves the pin registered rather than silently losing it.
  • the_title_frees_memory_a_window_is_in_place_over is discriminating on both halves: held_over 1→0 across title_memory_change+VirtualFree, LOOSE entry removed, then heap self-destruction drops its own registration.
  • uma_bench.rs removal is fair — the benchmark was the justification evidence; its summary is in #2912 and history keeps it.

Noting scope per the PR description: I reviewed the new commits only; the base mechanics are #2112/#2912/#2921's.

@pickles976

pickles976 commented Nov 26, 2026 •

Copy link
Copy Markdown

Important Wine/vkd3d-proton 3.2.0 RTX 4060 Laptop GPU (discrete, 16 GiB system RAM) caveat before anyone enables VICTORY_IN_PLACE=1: on exact earlier stacked head 7b6882b7, the PR test shadow::tests::the_title_frees_memory_a_window_is_in_place_over failed 0/1 at the held_over assertion. in_place_buffer returned a valid placed buffer, but held_over had already fallen to 0, expected 1. Local logs: .compat-runtime/logs/verify-pr2945-wine-inplace-pin{,-probe}.log (not attached). In a temporary test-only diagnostic, the pin was 1 immediately after registration, then the heap destruction callback fired before the caller asserted; diagnostic edit was restored.

The opened heap COM handle appears to be dropped when in_place_buffer returns only the placed buffer/GPU address/numeric heap ID; on this Wine backend that destroys the heap COM object while the placed buffer is still alive, so its notifier forgets the pin prematurely. A later title VirtualFree/remap could bypass the intended release. Please retain a strong heap lifetime with the placed resource (or otherwise tie the pin to the lifetime of all placed resources), and add a test that asserts pin is held for as long as the returned buffer is alive, then relinquished before the title changes memory. The newer 1c87ba06 commit changes UMA-default/self-test behavior but not this failing pin path, so I have not rerun the same failure.

This is a Wine/backend-specific negative, not a claim the PR fails on native Windows or UMA. The PR defaults in-place off on this discrete GPU; it is not a safe 16 GiB loading workaround here. No title launched with this mode.

Revised-head verification: 3ed7d725f6895fe1a235eb6fa8ff2485261ca151, including the actual heap-retention fix 1fc54410, now passes the earlier title-free regression and the new both-path pin-lifetime regression on this Wine/NVIDIA backend. 3passed/0failed/0ignored,0.75s, fresh compile8.85s, NVIDIA enumerated. Third check locally invokes your unified::self_test(&host.device) on the selected discrete NVIDIA host: the real CPU→GPU→CPU aliasing round trip passed too. No forced in-place title run yet.

Local test-only differences: missing host or refused heap now fails rather than silently returning in the two lifetime fixtures, plus the selected-host self-test entry point. Production unchanged from head. This clears the specific early-pin-drop and real-aliasing gates reported above; it does not certify all release/remap or rendering behavior. Latest #2112 29decb3 changes GPU-write invalidation, which is absent from this stacked head and is a separate correctness consideration before a title experiment.

Environment: Wine11.0, NVIDIA590.48.1, DXVK3.1.1, diagnostic relaxed vkd3d-proton3.2.0 2576c0b4adfae4a+, assertions disabled and allocator/list from_iface vtable checks removed, null checks retained. Not stock-runtime certification. Same6,000MiB GPU/2,048MiB availableRAM/10GiB disk guards and9GiB/512MiB scope caps. Log .compat-runtime/logs/verify-pr2945-fixed-pin-alias.log and sampled metrics.

Mixed local title follow-through (2026-11-26, Wine/NVIDIA)

After the three exact-production-head pin/alias fixtures passed, I tested a mixed local integration, not pristine #2945: 3ed7d725f6895fe1a235eb6fa8ff2485261ca151 plus only #2112 commit 29decb3719142296cad124453a3b8651068f22f6's GPU-write notification fix, a read-only logical-span probe, and test hardening. This retains the stack's fixed 256 KiB loose window and default 1 MiB in-place floor, rather than claiming current #2112 defaults. The notification port passed a local two-real-view alias tracking regression (including subsequent CPU writes); that regression is not a GPU-dispatch test.

A fresh release build named this checkout. VICTORY_IN_PLACE=1, with account selection at 20 s, produced actual loading artwork at 60/90 s. RAM guard stopped loading at 112.88 s: available RAM 2,012.1 MiB (2,048 MiB floor); GPU peak 3,297 MiB; scope peak 7,693.2 MiB, anonymous peak 3,079.9 MiB; user-available disk minimum 19.090 GiB. Exit 137 was the guard, not an unhandled title exception. No gameplay, controls, or gameplay FPS claim.

Last logical-span probe (~112 s):

Category Copy count Copy span MiB In-place count In-place span MiB
Registered 3433 510.38 39 193.75
Loose 2813 1120.50 4866 390.94

These are logical resource spans: they can overlap and exclude allocation/driver overhead. Not total RAM or unique physical bytes. They show the in-place path is active, but copy-backed growth still exceeds this machine's safe loading budget. Different stacks/loading timing make earlier no-in-place runs unsuitable for a matched-stage savings claim. Host compute PSOs b68f0931f1f47e61, 13dfdd3b1136e407, 88994c3496045f51 still returned 0x80070057; a missing-host-pipeline dispatch was also logged.

Local artifacts: .compat-runtime/logs/20261126T062146Z-{console.log,resources.csv,guard-events.jsonl}, screenshots menu-20261126T062246996159Z.png / menu-20261126T062317003405Z.png, and verify-pr2945-gpu-write-notification.log.

Environment remains Wine 11.0, RTX 4060 Laptop 8 GiB / NVIDIA 590.48.1, 16 GiB system RAM, diagnostic relaxed vkd3d-proton 3.2.0 2576c0b4adfae4a+ (assertions disabled, allocator/list vtable identity checks removed; null checks retained), not stock-runtime certification. Same GPU 6000 MiB / RAM 2048 MiB / available-disk 10 GiB guards and 9 GiB cgroup / 512 MiB swap caps; no limits raised. No code PR/push.

…g as the buffer

The pin of a heap opened over title memory went when the heap was
destroyed. On the sub-range path nothing of ours kept the heap once
in_place_buffer returned, and vkd3d-proton destroys it then for its
destruction callbacks, though the placed buffer still lives: the pin was
forgotten early (reported by pickles976 on Wine/vkd3d-proton, NVIDIA).
The whole-allocation path had the same gap once the cache let go of a
heap a list still used.

Each placed buffer now holds its heap through private data
(SetPrivateDataInterface), on every backend; a buffer that cannot is
refused. New test: on both paths the pin stays while the buffer lives with
nothing else holding the heap, and goes with the buffer.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

@pickles976 thanks, you were right. Fixed in 1fc5441: each placed buffer now holds its heap through SetPrivateDataInterface, on both the sub-range and the whole-allocation paths. So the heap, and the pin it carries, live exactly as long as the buffer, whatever the backend does with the opened heap's handle. A buffer that can't hold its heap is refused rather than placed.

The new test a_buffer_in_place_holds_its_heap_and_pin checks both paths with only the returned buffer holding the heap: the pin stays while the buffer lives and goes with it. It passes on an RTX 5070 Ti. It hasn't been run on vkd3d-proton yet, so a rerun of your case on that backend would confirm it.

… pages

a_sub_range_heap_covers_only_the_buffer failed on CI (WARP) at 1fc5441:
the allocation's VirtualFree right after the buffer was dropped. The heap
is now held by the buffer's private data, and on the CI runner's WARP the
pages are let go a little after the buffer goes; locally (WARP and the
RTX 5070 Ti) they are not. Windows lets go of pages after the last heap
over them late on other hosts too (NVIDIA, up to 6 ms), which
title_memory_change already retries for. The two tests that free right
after a buffer goes now retry for up to 1 s and name the error if the
memory is still held.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Replaced by #3102, which combines this with the rest of the host-memory placement work in one PR, with measurements on a discrete and an integrated GPU. Closing here.

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.

6 participants