Design question: read title memory in place (OpenExistingHeap*) instead of host copies; copies and RAM bound a 16 GB laptop #880
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#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?
@anasssssssss1 on GitHub · 2026-11-24 13:17 UTC · original
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.
github-bot referenced this issue2026-11-26 05:07:28 +00:00
@Sunkiller-qc on GitHub · 2026-11-24 13:21 UTC · original
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.@MichaelSmithAI on GitHub · 2026-11-24 13:30 UTC · original
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.
@anasssssssss1 on GitHub · 2026-11-24 13:39 UTC · original
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.@Xeltax on GitHub · 2026-11-24 13:48 UTC · original
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.
@anasssssssss1 on GitHub · 2026-11-24 14:02 UTC · original
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.@MrEjecutor on GitHub · 2026-11-24 19:07 UTC · original
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.
@anasssssssss1 on GitHub · 2026-11-24 19:25 UTC · original
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.
@Witredd on GitHub · 2026-11-25 00:05 UTC · original
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.@desplmfao on GitHub · 2026-11-25 05:12 UTC · original
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.@Marvisak on GitHub · 2026-11-25 06:53 UTC · original
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