Design question: read title memory in place (OpenExistingHeap*) instead of host copies; copies and RAM bound a 16 GB laptop #880
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-24T13:17:28Z.
Summary
On a 16 GB laptop the world is bound by host copies of title memory, in time and in RAM. D3D12 can open title memory as a heap in place (
OpenExistingHeapFromAddress,OpenExistingHeapFromAddress1for a sub-range,OpenExistingHeapFromFileMappingfor the physical-page sections), and all four cases VIctory would need succeed on an RTX 4050. Placed buffers in such heaps would let draws read title memory directly: no shadow copy to keep, no refresh per submission, no write watching for those ranges.I'm raising it as a design question before writing it, since it changes decision 0007's "Copies of title memory".
Measured (title 1.0.2.1,
--console series-s, in the world)RTX 4050 Laptop 6 GB (driver 32.0.16.2114, 32-lane waves), Ryzen 7 7735HS, 15.2 GB RAM, Windows 11 26300.
diagbuild ofmainffe310eplus #694/#704/#705/#233/#550/#581, driven withVICTORY_KEYS.Per frame, from
victory_gpu::hostandcopystat:One 174 MB buffer (
0x257d0000, a physical-page view) is refreshed about 20 times a frame, once per submission.Memory: the process had 17.7 GB private on the 15.2 GB machine with Series S settings, 0.64 GB free, Windows paging at ~8,000 pages/s. In run 2 the copies went from 0.67 s to 6.2 s a frame as that set in; the page faults above are mostly that. Every buffer a draw uses has a second, persistent copy in host memory, so this doubles the title's GPU-visible data.
Probe
OpenExisting*on this machine (64 MB allocations, a test invictory-gpu):VirtualAlloc(MEM_RESERVE | MEM_COMMIT)MEM_WRITE_WATCH(as xmem reserves title GPU memory)ID3D12Device13::OpenExistingHeapFromAddress1)OpenExistingHeapFromFileMapping)I have not yet placed buffers in them or drawn from them.
Open questions
Shadow::gpu_writes). In place, they would land there directly; the CPU side would need the fences VIctory already waits on.OpenExistingHeapFromAddress1takes any range, so the title's large pools can be opened per buffer or per region and kept while mapped (title_memory_remappedtells when views change).Would a branch along these lines be welcome? I can start with read-only buffer ranges behind a switch, and measure frame time and memory against
mainon this machine.Smaller thing in the meantime
Copies that hit unmapped title pages fall back to 64 KiB and then 4 KiB
ReadProcessMemorypieces, asked again every time: on the order of 34,000 failing reads a frame in run 1 (139 MB unmapped). Run 2 has a change that remembers 64 KiB blocks found wholly unmapped and asks about them with one 4 KiB read instead of 17 (so memory committed later without a remap notification is still seen; a test commits a block after it was cached). Its first world frames spent 0.67-0.70 s on copies against 1.4-2.1 s in run 1, but run 2 then went into paging, so I don't have a clean measurement yet. I'll post a branch once it has one and passes CI.Runs: run 1 is the tree above; run 2 is the same plus that change.
Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T13:21:23Z.
This is the direction proposed in #407, and some of it has already been measured there. aycow ran
OpenExistingHeapFromAddressandOpenExistingHeapFromFileMappingon AMD, an RTX 5070 Laptop and WARP with Agility 1.620.2, and both passed. nullmarsh covered vkd3d-proton and measured what the copy bridge costs per world frame. qntic added RX 6600 XT bandwidth numbers. #501 (ToxicmaggotRP) is an open PR for a CPU-visible placed-buffer arena. pushkarreddyy has a step-1 probe branch.Your RTX 4050 results,
OpenExistingHeapFromAddress1for sub-ranges in particular, and the 16 GB laptop RAM numbers would fit well on #407, so the design discussion stays in one place.Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T13:30:34Z.
Daniel tested GPU visibility after placement on an RTX 4090 with Wine/vkd3d-proton 3.2. Ordinary and MEM_WRITE_WATCH 4 MiB allocations both opened successfully with heap flags 0xe1. Each accepted the same 64 KiB buffer placed at +64 KiB. The probe wrote a CPU word, copied four bytes from the placed buffer to readback on the GPU, waited for the fence, then repeated with a different word.
Touching the watched source before import gave the same two zero readbacks. A further arm that also reset the write watch between copies gave the same result. The pagefile-backed section opened, but this probe did not read it on the GPU.
For a read-only prototype on this Wine backend, keep the existing shadow-copy path for write-watched allocations. The same two-write, two-readback check on the native RTX 4050 would establish which allocation types are candidates for your frame-time and memory comparison. We have no native result or title timing from this probe.
Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-24T13:39:05Z.
Follow-up probes on the same machine (RTX 4050 Laptop, driver 32.0.16.2114), aimed at the physical-page views, which are where the copy time goes. In the run above, copies of
MEM_MAPPEDranges took 8,885 ms of 9,042 ms in the per-buffercopystatlines;MEM_PRIVATEtook the rest.OpenExistingHeapFromFileMappingon aSEC_RESERVEsection committed in part (as xmem creates them)E_INVALIDARG); a committed pagefile section opensOpenExistingHeapFromAddress1over committed pages inside oneMapViewOfFile3view of such a sectionE_INVALIDARG)So a heap per section is out unless sections are committed whole (more commit charge, on machines that already hit the limit). What does work is a heap per view run, the runs
XMemMapPhysicalPagesalready makes. A title buffer spanning several runs would then be a reserved buffer whose 64 KiB tiles (the console's page) are mapped onto those heaps withUpdateTileMappings, and remapped wheremap/unmapalready calltitle_memory_remapped. The GPU's own page-mapping copies (map_alias) would go through the same path.Not yet tried:
UpdateTileMappingsonto heaps fromOpenExistingHeapFromAddress1(only onto committed heaps), and how many such heaps a frame's buffers need, given views of one page each frommap_alias.Imported from Marvisak/VIctory. Originally posted by Xeltax on 2026-11-24T13:48:21Z.
Two measurements on an RTX 4080 (driver 621.01, Windows 11) that bear on the plan above. Both come from a probe test in
victory-gpuand one local tree.1. The tile route removed the device here.
OpenExistingHeapFromFileMapping. Heap flags 0x421 (SHARED | SHARED_CROSS_ADAPTER | ALLOW_SHADER_ATOMICS), CUSTOM, WRITE_BACK, L0.ALLOW_UNORDERED_ACCESS | ALLOW_CROSS_ADAPTER) is created fine.UpdateTileMappingsof two of its tiles onto pages 3 and 1 of that heap is accepted. The next submission (aCopyBufferRegionfrom the reserved buffer) removed the device with0x887A0005.OpenExistingHeapFromAddress1, so that case is still open. On NVIDIA, though, tiles onto a shared, cross-adapter heap look like a dead end.2. A section opens only below 4 GiB.
OpenExistingHeapFromFileMappingopens a committed section of 4,095 MB and refuses one of 4,096 MB (and 4,200 or 6,236 MB) withE_INVALIDARG.What it bought in practice (in-place placed buffers for the title buffers that are one run of a section, world frames):
So whole-buffer placement covers little of the cost. It's the scattered pages that need covering.
AI use: Claude Code (Claude Opus 5.5) wrote the probe and the local change, ran them on my machine and wrote this.
Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-24T14:02:02Z.
Tried it on the title: a prototype behind
VICTORY_ZERO_COPY(on the testers tree) that makes a title buffer a placed buffer on a heap fromOpenExistingHeapFromAddress1when one committed region (one view) holds its 64 KiB pages, with refresh, snapshot and copy-back skipped for it, and the buffer dropped ontitle_memory_remapped. A standalone probe of that path works on the RTX 4050: the GPU reads the view's pages through the placed buffer and sees a later CPU write with no copy.On the title it does not hold up yet. With it on, the per-frame
copystaton the loading screen showed refreshes that checked nothing (in-place buffers), but loading never finished: 12 minutes on the loading screen and then no log lines at all (the process stayed up), where the same tree without it reached the world in about 5 minutes.My reading, not verified: a remap drops the shadow, but views already written into descriptor tables keep the old placed buffer, which still holds the pages it was opened over. A copy re-reads the current mapping at every submission; a buffer in place does not. So zero-copy for physical-page views needs the views that name a buffer to be remade when its pages are remapped, not only the shadow. Also:
UpdateTileMappingsonto a heap fromOpenExistingHeapFromAddress1removed the device here; those heaps come backSHARED | SHARED_CROSS_ADAPTER | ALLOW_SHADER_ATOMICS(0x421), and tiled resources on cross-adapter heaps are not allowed, so buffers spanning several views cannot be stitched that way.Imported from Marvisak/VIctory. Originally posted by MrEjecutor on 2026-11-24T19:07:29Z.
A measurement of reading title memory in place on NVIDIA (RTX 5060 Ti): the heap opens, but in this form it is slower than the copies, and with every eligible buffer it hangs the GPU
A data point for this design question, from a prototype on a fork (not for merging): https://github.com/MrEjecutor/VIctory/tree/inplace-prototype. It sits on
ffe310e+ #578 +MIN_DYNAMIC = 1 << 18+ #322 (no hang without it, see #747). BehindVICTORY_INPLACE=1, a title buffer inside one committedMEM_PRIVATEallocation gets a UAV-capable buffer placed in a heap opened over the title's own memory (ID3D12Device3::OpenExistingHeapFromAddressat the allocation base), and its refresh, write watch, snapshot and copy-back are skipped; everything else keeps the copied path. Physical-page views (MEM_MAPPED) are not covered.Setup: RTX 5060 Ti 16 GB, driver 621.24; Intel Core Ultra 5 225F; 32 GB; Windows 11 26200; diag build, Rust 1.100.0;
--console series-x; Enter every 10 s; 200–240 s runs.What I found
D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER. The opened heap reports flags0x621, type CUSTOM,WRITE_BACK, pool L0. Without the cross-adapter flag everyCreatePlacedResourcereturnedE_INVALIDARG(0x80070057). Placement also has to start on a 64 KiB boundary of the allocation, below the title buffer.slow host submission ms=2570) and the device was removed withDXGI_ERROR_DEVICE_HUNGat ~62 s, still loading; DRED breadcrumbs all done.MEM_PRIVATErange (the costliest private one, ~100 ms of copies in the top ranges) drops out of the copy statistics. But the world runs at 0.7 fps against 1.9–2.1 fps with the switch off in the same build, andpreparing: copiesis 600–970 ms against 60–150 ms. The remaining big copies (MEM_MAPPED) take about as long as before; I have not found where the extra time goes.So on this NVIDIA card, opening title memory with
OpenExistingHeapFromAddressand reading it in place is slower than VIctory's copies, at least forMEM_PRIVATEbuffers placed this way. In-place reads may still win in another form; this only measures this one.Not tested:
MEM_MAPPEDphysical pages (78 % of the copied bytes here),OpenExistingHeapFromAddress1or file-mapping heaps, other GPUs and AMD, why the copies got slower (my guess, unchecked: the driver handling the opened allocation's 4 KiB pages), more than 1–2 runs per configuration.AI use: Claude Code (Claude Opus 5.5) and Codex (gpt-6-sol for the design, gpt-6-luna for the first version of the code), with Claude Code reviewing, fixing, building and running; checked by mrejecutor.
Imported from Marvisak/VIctory. Originally posted by anasssssssss1 on 2026-11-24T19:25:14Z.
Measurements on a 6 GB / 16 GB laptop, to show where the memory goes. They support doing this in place rather than with copies.
Machine: RTX 4050 Laptop 6 GB, 15.2 GB RAM, Windows 11 26300.
Build: diag build of r4tedx
integration/testersupdate 9 (94e0ea5) plus #1010, #1277 and #1433,--console series-s, first-mission world.The process. Private bytes 20–22 GB, of which the working set is 2 GB. Free RAM is 0.3 GB, with about 37,000 page-ins/s and 190,000 page faults/s. Most of each 8–14 s world frame is spent waiting on the disk; the GPU is busy 0.4–0.9 s of it.
Where it goes. By
VirtualQueryEx, grouped by type, protection and allocation size, plus the per-process GPU counters:A diagnostic on
Host::upload_bufferlogged no allocation of 16 MB or more in 19 minutes. So the 31–32 MB write-combined blocks are not VIctory's own upload buffers. They are the title's resources that the driver moved out of the full card into system memory.Copies per world frame (copystat):
Textures per world frame: 112 MB hashed, 0 changed. Staging buffers were kept per texture, and every list copied them into the card. Dropping the staging of textures that stay the same, and skipping their per-list copy, took texture preparation from 180–320 ms to under 2 ms per frame. That change is on a local branch and needs a longer run before a PR.
Prior art for in place. XCL (
ivall/xcl,crates/xcl/src/gpu/uma.rs) keeps the title's graphics memory in up to four fully committed windows of up to 4095 MB each, opened withOpenExistingHeapFromAddress. Shaders reach memory by window (address >> 32 & 3) and 32-bit offset, with no per-buffer copies. Its notes say a heap must cover a fully committed allocation; a reservation with partial commit is rejected, which matches what I measured here.fxceless/victory-gta6has a first stage of this behindVICTORY_INPLACE.On a machine like this one the copies and the overflow out of the card are the whole frame, so I think this is the change that matters most for small machines.
No game data attached.
Imported from Marvisak/VIctory. Originally posted by Witredd on 2026-11-25T00:05:39Z.
An AMD data point for the in-place route, from @MrEjecutor's
inplace-prototype(aec1b40) run as is withVICTORY_INPLACE=1(default 16 MiB minimum).RX 5600 XT 6 GB (RDNA1, driver 32.0.21045.16010), Ryzen 7 5700X, 16 GB RAM, Windows 11. The card has no mesh shaders, so the branch is merged locally with #961, plus #1296 at
VICTORY_TEXTURE_MIP_DROP=2(all onffe310e; the conflicts were only imports and struct fields). Memory is the process'sGPU Process Memorycounters, sampled every 2 s.in-place heap opened size=2305818624 flags=0x621 kind=4 cpu_page=3 pool=1, and two title buffers (90 MiB and 24 MiB) went in place. Five others were refused withreason=Mapped, as the prototype intends.heap openedline, then → 7.4 GB within 3 s of the second. With 16 GB RAM the shared limit is about 8 GB, so the next allocations failed (no shared buffer, thena host command list did not close (0x8007000E)).no shader-writable buffer, dedicated at 5.8 of 6 GB); with it there were 2 of those and dedicated peaked at 5.6 GB.So on a 16 GB host, opening the whole allocation costs more shared memory than it saves in copies. Opening only the buffer's range (
OpenExistingHeapFromAddress1with a sub-range, as this issue mentions) looks needed for it to help low-memory machines.Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T05:12:21Z.
A data point for this design:
OpenExistingHeapFromAddressworks under Wine with vkd3d-proton on NVIDIA (RTX 5080, proton-cachyos 11.0, vkd3d-proton 3.2.0). It worked on all three kinds of memory VIctory gives the title: a plainVirtualAlloc, a write-watchedVirtualAlloc, and a view of a section (also a second view of the same section). The GPU wrote to a buffer placed in such a heap, and the CPU read the result right away at the right offset. The address has to be the allocation's base; a buffer is then placed at its offset.#2112 uses it, opt-in (
VICTORY_IN_PLACE=1), for loose windows only. While Grand Theft Auto VI loads its world, their host memory goes from about 3.4 GB (main) to 79 MB: 1,448 windows in place, none refused, no device errors. Title buffer objects (about 1.2 GB here) are still copied.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T06:53:09Z.
Automated triage for the maintainers.
This is a design question for the maintainer about the GPU memory model (reading title memory in place instead of the host copies kept in
crates/victory-gpu), so it stays open for that decision. The same direction is being discussed in #407, which is where the design discussion should be kept together; the measurements in this thread (sub-range heaps, the refusal of partly committed sections and of sections of 4 GiB or more, the NVIDIA tile-mapping device removal, the shared-memory growth on AMD, and the slower in-place reads on an RTX 5060 Ti) are useful there too. Open pull request #2112 already usesOpenExistingHeapFromAddressopt-in (VICTORY_IN_PLACE=1) for loose windows. It fits the project's scope.Generated by Claude Code
upstream-sync referenced this issue2026-11-25 15:04:06 +00:00
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T07:21:18Z.
A comparison of the three open in-place PRs, for whoever has to decide the order. Facts are read from the PRs at the heads below (2026-11-27), not from their descriptions.
4466264)1a20686)616b6f9)VirtualAllocallocations)xmem),SEC_COMMIT, ≤ 512 MiB eachOpenExistingHeapFromAddress; a buffer placed at the window's offset; everyShadowcopy path returns early for that window;watch::gpu_wrotemarks trackers when the GPU wrote it, without opening a guardOpenExistingHeapFromFileMappingon the sectionxmemmade;title_memory_mapped(at, len, section, size, offset)+title_memory_section_freed, so a remap needs no re-importport.rsheap + descriptor marks, raw CBV, per-block guard journal, sharded journalshadow.rsshadow.rs(+1210/−16),host.rs,memory.rs(+4),watch.rs(+17)memory.rs(+593/−20),xmem.rs(+110/−18),watch.rs(+2)descriptor.rs(+51),watch.rs(+194/−8),xmem.rs(+4),loader/descriptor_sites.rs,shader/lower.rswatch.rs,memory.rswatch.rs,xmem.rswatch.rs,xmem.rsgpu_wrote(GPU writes in place are marked, nothing saved, no guard opened)title_memory_remappedVICTORY_PORT_GUARD,VICTORY_PORT_JOURNAL)The three do not compete for the same memory: #2494 takes the physical-page sections, #2112 the loose windows and buffer objects, #3470 adds a heap plus descriptor/guard work of its own. They compete for two files —
watch.rs(all three) andxmem.rs(#2494 vs #3470).What none of the three covers is the other half of the same cost: the title's own stores into guarded memory still open a guard (a protection change, ~5 µs, one process-wide at a time). codec-d/cool_fox measures that at 590 write faults a frame and 69 ms of thread time → ~6 ms by writing the store's bytes through a second, unguarded view of the same pages and telling the tracker the block changed (
titlewrite.rs, 417 lines, an instruction-level store replay,inplace.rsfor the views). It cannot exist before a section can be mapped twice on the CPU — #2494 is the PR that makes that true, and it already handsvictory-gputhe section handle, length and offset a second view needs.So, if the order is mine to suggest: #2494 first (self-contained, no
shadow.rs, and it is the answer to #1905's remap problem), #2112 once #402 is rebased (its coverage is disjoint, but nobody should merge a 1,690-line chain whose base conflicts), and #3470 split — the in-place heap can then be judged against the other two, and the descriptor/CBV/journal pieces should not wait on the memory decision.I am not asking for either to be mine: I would offer the store-through-alias piece as an increment on top of whichever of #2494/#2112 lands first, coordinated with its author, and I can also just verify the winner on this card (Arc B580) instead. Measurements only, no game data.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-27T23:02:35Z.
A measurement from xcl that bears on in place, and that none of the three PRs in borosf's table measures yet: the GPU's cost of reaching an imported heap on NVIDIA. Read from xcl#2844 (merged into xcl
maintoday), not run here.xcl keeps the title's memory in coherent windows opened with
OpenExistingHeapFromAddress, the approach cited above as prior art. Kalmarv captured one world frame and replayed it with only the window's memory home changed. Draws 1-1704 took 164.6 ms of GPU time with the window in a driverCUSTOMwrite-back L0 heap, against 1,427.3 ms imported (8.7×). The hot compute programs were 18-39× slower each. Their standalone probe on an RTX 5070 Ti, in ns per loop iteration (atomics / loads):OpenExistingHeapFromAddress)Their checks rule out write watch (imported without it gives the same rows) and the cross-adapter flags (a DEFAULT heap with
SHARED_CROSS_ADAPTERruns at CUSTOM L0 speed). In the world it took them from 0.62 to 3.03 fps.For VIctory:
OpenExistingHeapFromAddress(#2112's mechanism) may swap the copy cost for a per-access GPU cost. The CPU-side numbers in this issue would not show that, but GPU timing (VICTORY_GPU_TIMING=1) of the same scene with and without it would.OpenExistingHeapFromFileMapping(#2494), so whether sections behave like the address import is open.CUSTOML0 heap. Briefly reserving the other large free ranges forces the driver's CPU mapping into the hole the window left, so the title's pointers stay valid. Then copy the pages back. If the mapping lands anywhere else, they re-import as before. It needsALLOW_WRITE_WATCHon the heap, so the title's CPU writes are still seen. This is an idea to compare against, not code to port, since xcl is GPL-2.0-only.The forks that run fastest on NVIDIA use VRAM copies of title memory, and VRAM is the fastest column above. That fits this picture.
AI-assisted (Claude Code, Claude Opus 5.5 read xcl#2844 and this thread).