Repository navigation
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>
…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>
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shadow::— 10 passed, 0 failedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean opt-in VICTORY_IN_PLACE=1 loose title-memory mapping with remap tracking and solid shadow:: test coverage. Looks good.
AI-assisted (Gemini 4 Neon).
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>
|
A note on why this is opt-in and untested in the world: on this machine I currently can't get into the world at all. On the RTX 5080 (16 GB) under Wine, every run fills video memory while the world loads, before the first world frame. That's mostly driver memory that grows while pipelines are created, not these copies, and it's what I'm working on next. So the missing world test is a limit of my setup, not something this PR has been seen to break. Once the world loads here, I'll:
Tests on a machine that already reaches the world (Windows or AMD in particular) would help a lot before that. |
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>
|
#2112 did map real game memory on Windows. In my last loading sample, 243 MiB used that path and 1.11 GiB still used copies. That sample took 2.8 seconds per frame. |
…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>
|
Scoped native Windows result on RTX 5070 Ti Separate hold on |
…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>
|
Update: CI on Windows showed that Windows doesn't release memory that a heap was opened over while that heap exists; Wine releases it at once. The test now accounts for that ( @RKouchoo thanks for the Windows sample (243 MiB in place, 1.11 GiB still copied, 2.8 s per frame). Two things would help:
@yualk thanks, both very useful. It's good to have the native Windows placements confirmed, and the reentrancy is a real bug: my release test called the helper directly, without the locks |
…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>
catminou4
left a comment
There was a problem hiding this comment.
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Title memory in place instead of copied, opt-in via VICTORY_* env — zero-copy path behind a flag; risky default-off is right, needs Windows validation.
|
World result, and it's not a gain yet on Linux/NVIDIA. With #2143 (code tables) I can now get into the world, so here's an A/B on the same build, with and without
In-place works as intended: every loose window and title buffer went in place, The likely cause: Next, on this branch: before going in place, check how much of the allocation is already resident ( |
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>
|
Update: two changes for the residency problem from my last comment. 1. Density check (
Opening those whole pinned about 2.9 GB that the title had committed but never touched. A whole allocation now goes in place only if at least 90% of its pages are already resident ( Same build, in the world, average of 9 samples per run:
So on Linux this is now no worse than copies (anonymous memory stays where it is without in-place), but the gain is small. The buffers that matter live in the sparse pools. 70% matches what MrEjecutor saw in #880: putting more in place hangs the GPU. 2. Sub-range heaps where the host has them ( Tests on the RTX 5080 under Proton: |
A range in one window, then a range across its end, which gets a window of its own over both: the title's writes reach both copies at their refresh, and a shader's write through the spanning copy goes back to title memory and into the first copy at its next refresh. 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>
Clean merge: 256 KiB windows only with VICTORY_LOOSE_WINDOW_KIB=256; the in-place code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No range: sizes far from the default are the user's own experiment. Only a value that is not a power of two, or one whose bytes overflow, falls back to 4 MiB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_KIB Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n place, opt-in) A plain merge would have dropped Marvisak#2112: the old fork main merged an earlier Marvisak#2112 head (cd079af), so it is a merge base, and the current main left Marvisak#2112 out, which reads as a deletion. Merged against the right base instead: upstream main (67e8ae1) with Marvisak#2088's two commits Marvisak#2112 stacks on (b670a33), and Marvisak#2112's head applied over that file by file (README, host.rs, memory.rs, shadow.rs, watch.rs; no conflicts). Marvisak#2088's reverted two-step lookup is not in Marvisak#2112 and stays out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The previous renderer (old upstream base 940d32f) is the first parent and is also kept as the branch renderer-2026-11-25-oldbase; the second parent is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with the renderer stack merged on it: Marvisak#439 (on main: update/439-main's resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292, Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes. Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by main: Marvisak#1769, Marvisak#1763, Marvisak#2366. The picture on this base still shows the overlay that plain upstream main shows too; that is being looked into. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@0xKaji thanks, this is the measurement this PR was missing. With 8 GB of video memory and 16 GiB RAM in Series S mode, 15.67 GiB RSS down to 11.25 GiB at world entry, and a 4-minute run without running out of memory, is a real benefit on exactly the kind of machine that needs it. The threshold check helps too: it confirms that the 1 MiB / 90 % defaults are the right side of the trade-off. Still open before this leaves draft: the skinning artifacts with the switch on (stretched arms, a tilted NPC; see the A/B above). Did you see anything like that on characters in your runs? |
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — reviewed the delta over #2088 (8aef2dd..f83faa7).
The coherence story holds at every seam:
in_placeno-ops the whole copy pipeline (refresh/gpu_writes/writing/copy_back*/update) except two deliberate paths:keep_in_placeretains the placed buffer — hence its heap, hence the pinned pages — for any list whose commands name the GPU address, andlandedmarks title pages changed so other shadows (sub-floor buffers, view copies, textures) refresh from memory the shaders wrote in place.memory::bindcallslandedon computed-address writes even while withholding — the one path that must not be skipped.committed_part: the VirtualQuery walk down/up one AllocationBase with the 64 KiB floor / 4 KiB ceiling cut andlo <= address && end <= higuard is exact — including the alignment push-up being guarded rather than clamped silently.in_place_buffer: single-allocation verification walks every region (refuses multi-allocation), offset%64KiB enforced, sub-range opens viaOpenExistingHeapFromAddress1keep heap lifetime bound to the placed buffer, whole-allocation path goes through the cache with extent staleness + thedense()working-set gate (64Ki-page sampling, 10 s cache, 90 % default — the GTA6-on-Linux measurement justifies it).- Stale-heap sweep:
check_in_placeonce a frame drains the deferred STALE list plus a fresh extent scan;let_go_heap(id)filters by HeapId so a new heap at the same base survives; deferral under STALE_IN_PLACE correctly avoids re-entering BUFFERS/LOOSE from callers that hold them. keep_once's raw-pointer key contract is documented andkeep_in_placeuses the buffer pointer — no aliasing.- The
in_place_remappedhook ontitle_memory_remappedcloses the runtime-map/unmap hole;pin_heap(from #2945) closes the title-side free/protect one — the two halves compose correctly. - Tests serialize on IN_PLACE_TESTS and cover committed-part geometry, real heap opens, stale eviction, and overlapping windows.
Noting scope: this reviews #2112's own commits; the 256 KiB loose-window lookup rework is #2088's.
|
A data point from Windows with native D3D12, not vkd3d-proton: RTX 5070 Ti, Windows 11. I merged #2112 with #402 and #2088 on top of current main plus #2870 (copies in GPU upload heaps), and ran it with
The same build without the variable renders normally. So on Windows/NVIDIA the opt-in currently costs far more than it saves. I'm happy to run a diagnostics build of a newer revision if that helps. 🤖 Generated with Claude Code (Claude Opus 5.5) |
|
@kawaii-shakal thanks, the first native D3D12 numbers for this, and they're clear. With the switch on, copies per frame go from ~420 MB to ~1.6 GB while almost nothing goes in place, and cutscenes go flat. So on a discrete NVIDIA card under Windows the opt-in costs far more than it saves. That matches my Linux A/B (no clear gain at 90 %). The benefit so far has only shown up where system RAM is the limit (0xKaji's 16 GiB RAM machine with an 8 GB card: RSS down from 15.67 to 11.25 GiB) and on shared-memory hosts (#2945). The switch stays off by default, and this PR stays a draft. Three things would help pin down where the extra 1.2 GB per frame comes from:
The flat cutscenes are probably the same problem as the stretched arms I saw: a buffer the title writes every frame, read in place mid-write. The fix I have in mind keeps a buffer copied until the title has left it unwritten for a few seconds. |
|
@desplmfao answers in order:
The only So almost all of the extra time is in watches: about 2.5× as many bytes checked per frame, at roughly 400× the time. Refreshes and snapshots actually go down. That looks like whatever the in-place buffers still go through in 🤖 Generated with Claude Code (Claude Opus 5.5) |
…saving them or opening guards landed() used watch::writing, which is for kernel writes into title memory: every tracker holding a page saved its bytes first, and the guards were opened, so the pages had to be compared at every refresh after. In place, every submission marks the whole ranges its shaders may write, so that was GBs a frame: on Windows with VICTORY_IN_PLACE=1 the watches took 5.7-7.7 s a frame against 13-19 ms, checking 11-13 GB (9-11 GB unchanged). watch::gpu_wrote marks the pages (and their aliases) changed in every tracker, as before, with nothing saved (the write happened; there is no 'before' to keep) and no guard opened (a GPU write does not go through the CPU's page protection, so the title's writes stay seen). Found from kawaii-shakal's copystat lines on Marvisak#2112 (RTX 5070 Ti, Windows 11, native D3D12). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@kawaii-shakal thanks, the watches line pinned it down. It was this PR, in
If you can, the same A/B on |
…without saving or opening guards Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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.
|
Tested Unit Tests
Live Title Run (
|
…o demo # Conflicts: # crates/victory-gpu/src/shadow.rs
|
A data point from AMD on Linux, where this ends differently than on the 5080 or on Windows: RX 6800 XT, RADV
All four in-place runs end the same way, with no GPU fault and no reset in the kernel log: The crate's tests pass under Wine at So the kernel refuses a submission instead of the GPU faulting. What I think happens, from the sources (I have not
That fits the fresh allocation in the tests importing fine (one anonymous VMA), the failed imports in the game, and a If that's right, on amdgpu an allocation can only go in place if nothing guards any page of it for as long as it's AI-assisted (Claude Code). No game data attached. |
|
Unit-test run on native Windows with NVIDIA, the combination the description lists as untested: RTX 4060 8 GB (PCIe 4.0 x8, Resizable BAR on), driver 621.14, Windows 11 Pro 26300. Head
A cost data point for in place on a discrete card, from #3102's synthetic benchmark on the same 4060 (its in-place path also opens title memory as heaps; comment there). 200 dispatches over 320 MiB of title buffers, ms per submission: copies in system memory 160.8, in place 113-122, copies in video memory 53-106. On a narrow link, shaders reading title memory across the bus cost more than keeping a VRAM copy. That fits #2734 putting hot buffers in VRAM on top of this. AI-assisted (Claude) |
…end on it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@desplmfao — facts about the three in-place PRs are in #880 (comment 7212390146). One thing from it worth your attention: #402 is CONFLICTING with main, and #2088 → #2112 sit on top of it, so the chain cannot be judged until it is rebased — 1,210 of the 1,690 lines are in |
|
Thanks @MeMako, @crashbashash and @potatoe0100. Together these settle where the switch stands:
So in place only helps where RAM is the limit (0xKaji's 16 GiB machine) or the GPU shares memory with the CPU (#2945). It stays opt-in and stays a draft, and I'd not use it on AMD or discrete NVIDIA. @borosf, on the chain: #2088 doesn't wait for #402. It carries #402's commit with current |
Stacked on #2088, which is itself stacked on #402. The new commits are the last two here. This is a first, opt-in step towards #880 (reading title memory in place instead of copying it). It covers loose windows (memory outside every buffer object) and, since the third commit, title buffer objects.
Change
With
VICTORY_IN_PLACE=1, a loose window is the title's memory itself. The allocation holding it is opened as a host heap withID3D12Device3::OpenExistingHeapFromAddress(under vkd3d-proton that isVK_EXT_external_memory_host), 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: every copy path ofShadowreturns early for such a window.watch::title_memory_remappeddrops in-place windows and heaps over the remapped range, so a later lookup opens the new pages. Lists that still hold an old window keep its pinned pages until they are reset.Measured
RTX 5080, Linux, proton-cachyos 11.0, vkd3d-proton 3.2.0,
main+ #1849. Grand Theft Auto VI, Series X 1.0.2.1, from start into world loading:main(4 MiB copies)VICTORY_IN_PLACE=1No device-removed errors or GPU faults in any of these runs. Before the patch above, a quick probe showed that process memory opens as a heap here for a plain
VirtualAlloc, a write-watched one and a view of a section (also a second view of the same section). The GPU wrote to such memory, and the CPU read the result at the right offset.Released title memory
Most of what goes in place (about 570 of 572 MB here) is private memory the title allocates and frees itself, partly through calls VIctory doesn't see. A heap opened over an allocation that is no longer the same (released, another size, or not all committed) is let go, together with the in-place windows and buffers in it. That's checked both when the heap would be reused and once per frame for all opened heaps. Test:
a_heap_over_a_released_allocation_is_let_go. Known gap: an allocation that is released and made again at the same address with the same size can't be told apart. Under vkd3d-proton, the GPU would then read the old, still pinned pages: stale data, not someone else's memory. This is one reason the switch is opt-in.Not measured / limits
MEM_MAPPED, each its own allocation). Here that's 8 large buffers, 378 MB. One heap can't span them, and tile mappings into heaps opened over process memory weren't reliable under vkd3d-proton (a probe worked once, then not).Tested
the_committed_part_of_a_window_holds_the_range_or_is_none(pure CPU, a reservation with a committed middle) andcommitted_memory_opens_as_a_buffer_in_place(GPU; skipped where the host can't open process memory as a heap).cargo test -p victory-gpu -- --test-threads 1: 136 passed, 14 failed. Plainmainfails the same 14 on this machine.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean for these files.AI-assisted (Claude Code).
🤖 Generated with Claude Code