Repository navigation
GPU: title memory in place by default where the host GPU shares memory with the CPU (stacked on #2112, #2912, #2921) - #2945
0xkn0wh3r3 wants to merge 34 commits into
Conversation
…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
…in-place-on-unified
…u/in-place-on-unified
…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).
|
Code review and triple-adapter (NVIDIA RTX 5090 discrete + AMD Radeon RDNA2 iGPU + WARP) verification at head
Looks great once the stacked prerequisites ( |
… 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.
…in-place-on-unified
…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
left a comment
There was a problem hiding this comment.
LGTM — reviewed the delta on top of the stacked PRs (7b6882b, cdf12e9).
in_place_enabledsemantics match the PR description exactly:=1on everywhere, any other set value off, unset → UMA +self_testpass. TheOnceLockruns the self-test at most once, lazily on first use, and only on UMA hosts — discrete hosts never pay it.- Moving
self_testout ofdetectis the right call: every host creation used to run a 3-20 ms GPU round trip whose answer nothing consumed.detectis now the cheap queries it's described as;Memoryno longer carries thein_placefield. pin_heapcovers both heap paths: whole-allocation opens pin[start, start+size)withlet_go_in_place(start, len)releasing the placed window, and sub-range heaps pin their own range withlet_go_heap(id). The two destruction outcomes are handled symmetrically — heap destroyed by itself →forgetdrops the registration; title tries to change pinned memory →releaseruns first, outside the registry lock. TheRegisterDestructionCallbackfailure path correctly leaves the pin registered rather than silently losing it.the_title_frees_memory_a_window_is_in_place_overis discriminating on both halves:held_over1→0 acrosstitle_memory_change+VirtualFree, LOOSE entry removed, then heap self-destruction drops its own registration.uma_bench.rsremoval 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.
|
Important Wine/vkd3d-proton 3.2.0 RTX 4060 Laptop GPU (discrete, 16 GiB system RAM) caveat before anyone enables The opened heap COM handle appears to be dropped when 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: 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 Environment: Wine11.0, NVIDIA590.48.1, DXVK3.1.1, diagnostic relaxed vkd3d-proton3.2.0 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: A fresh release build named this checkout. Last logical-span probe (~112 s):
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 Local artifacts: 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 |
…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.
|
@pickles976 thanks, you were right. Fixed in 1fc5441: each placed buffer now holds its heap through The new test |
… 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.
…o demo # Conflicts: # crates/victory-gpu/src/shadow.rs
|
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. |
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,UnmapViewOfFile2andVirtualFree(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.OpenExistingHeapFromAddress1.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_hostmakes new memory). It takes 3-20 ms.Default: with
VICTORY_IN_PLACEunset, 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.=1keeps it on everywhere.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:let_go_in_place(start, len);ID3D12Device13, released withlet_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 asin_place_bufferreturned, 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_PLACEparagraph says when it is on by default.Limits
keep_in_place). If the title frees memory a not-yet-reset list still names, the free is still refused after HLE, GPU: title memory held in place is let go before the title or the runtime changes it #2921's 100 ms retry, as on GPU: title memory in place instead of copied, opt-in (VICTORY_IN_PLACE=1; stacked on #2088, towards #880) #2112 today.Tests
shadow::tests::the_title_frees_memory_a_window_is_in_place_over:title_memory_changewith the title'sVirtualFreedrops the window and its heap first.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), astitle_memory_changedoes 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_sharedandtitle_memory_opens_in_place_on_warp: the self-test.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.dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views, fail the same way on clean main on this machine.Related