Repository navigation
Description
The problem
On 16 to 18 GB Macs the world is memory bound, and the biggest avoidable cost is duplicate host copies of the title's physical pages.
GTA VI asks for its physical pages as one section of about 6.1 GiB (XMemAllocatePhysicalPages) and maps them into its address space 64 KiB at a time, each page at about three addresses. A measurement on Series S found 165,000 view pieces, which are 14.5 GB of addresses over 4.7 GB of pages. Under Wine the CPU side is fine, because every view of a section shows the same pages. VIctory keys its host copies (shadow::find, buffer copies and loose windows) by title address, so a page shown at three addresses gets up to three copies, and each is refreshed, compared and copied back on its own.
On an 18 GB M3 Pro running Series S under D3DMetal, free memory is about 80 MB from 30 s into the world, the compressor holds 5 to 7 GB, swap grows and wired memory is 10 to 12 GB.
What does not work (measured)
- Zero copy of the whole pool on D3DMetal (
VICTORY_GPU_POOLS=1andVICTORY_ALIAS_BUFFERS=1) loses. GPU-visible memory is wired on Apple silicon, so all 4.7 GB of physical pages become unswappable, untouched pages included (wired 14.5 GB against 10.4 GB at the same point). D3DMetal cannot wrap existing memory, so "zero copy, wired only where used" is not possible there. - Shaders must never write title memory in place. The title keeps CPU objects in its physical pages, and a translated byte or half store is a read-merge-write over a whole word. The copy path's write-back of changed bytes (
Shadow::gpu_writes) has to stay.
Proposal: one host copy per backing, not per address
Key copies of physical-page memory by (section, offset) instead of title address, so every alias of a page binds the same host copy at its offset.
- The runtime already knows every view's section and offset (
victory-hlexmem.rs:Physical::views,Slice,Section::whole). The GPU side hears of maps and unmaps (title_memory_remapped,title_memory_aliased). - A copy's source for refreshes would be the runtime's whole view of the section (
Section::whole), which never moves, instead of whichever title address asked first. - Write tracking: a title write through any alias must dirty the backing copy.
watchalready follows aliases (title_memory_aliased, theshowntable), and the copy's changed pages would key on the backing page. - A range over several views whose pages are not consecutive in the section still needs a contiguous GPU range. Copy those as today at first, and count how often it happens (about half of view-memory ranges in a census on a native layer: 4,252 from one run, 3,789 from several places).
Expected: up to about 3 times fewer bytes copied, refreshed and compared for view memory, fewer wired host buffers, and only GPU-used ranges copied.
How to measure
- A 5 s
vm_statsampler (free, wired, compressor, swap) during a run. - VIctory's own line
host copies of title memory: N alive X MB(copystat), before and after.
A first step that pays on its own
A census of host copies by size, age and last use, plus how many title addresses share a backing page.
Text findings and numbers only, please. No game files, shaders, dumps, logs with game data or recordings.
Activity
fix(gpu): title memory in place is read-only; what GPU work writes is…
hackgods commentedon Nov 27, 2026
Some measurements that bear on keying copies by backing page. They are from synthetic tests under Wine with D3DMetal on an M5 Pro (macOS 27), with no game data. The tests are on our fork (
crates/victory-gpu/src/tiles.rs, branchperf/inplace-tiles).Reserved buffers with tiles mapped onto heaps (
CreateReservedResource+UpdateTileMappings) work under D3DMetal, and they would give each alias range a contiguous GPU range over one backing copy:UpdateTileMappingson the queue, and executed after it, reads the new tile. So the mapping is taken at execution, as on the console, and a remap needs no re-recording. Mapping a range again six times in a row read the right tile each time.Cost of the tile mapping:
Coherence of one page at several GPU addresses, within one list. The test fills a 64 KiB page with zeros and writes 7s into its first half through one address. After a UAV barrier, a second dispatch reads them through another address and writes them plus one into the second half. That half is copied out in a submission of its own and checked word by word, 8,192 words per case:
So under D3DMetal, each alias address could map as tiles onto one backing copy without losing coherence between aliases inside a submission, at least for compute work separated by barriers. Reads with no barrier inside one dispatch were not tested.
A side finding. A
CopyBufferRegionin the same list after compute writes is not ordered behind them by a UAV barrier alone:D3D12 requires the transition anyway. But any host path that copies out of a buffer just written by shaders in the same list, with only UAV barriers between, would read stale data under D3DMetal.
On never writing title memory in place: agreed, and we have made our in-place experiments read-only.
buffer_store_byte/shortas two dword atomics (clear the field, then set it). Other bytes of the dword are not rewritten. But the field reads 0 between the two, and a CPU write to the same byte in between is OR-merged, so the copy path's merge is needed.global_store_byte/shortare refused by the translator.🤖 Generated with Claude Code
The count of pages the title shows at more than one address will follow from a game run.
Measured and written with Claude Code (Claude Opus 5.5).
fix(gpu): title memory in place is read-only; what GPU work writes is…
fix(gpu): title memory in place is read-only; what GPU work writes is…
Stefa008 commentedon Nov 27, 2026
Some numbers from a 16 GB M4 (MacBook Pro, Series S, 1280x720 output, CrossOver Wine + D3DMetal 4.0 beta 3). It looks like the same picture you describe.
Build: main
a31fcca1plus halfwave50's mesh row merge (now #578), withVICTORY_RAM_LOW=0.15 VICTORY_RAM_FREE=0.20 VICTORY_SMALL_LOOSE_WINDOWS=1 VICTORY_ALIAS_BUFFERS=0 VICTORY_EVICT_HEAP_UAV=1 VICTORY_SPILL_SHADERS=1 VICTORY_CENSUS_FAST=1. Prison cell, full scene (~4,550 draws), three runs back to back:VICTORY_ATOMIC_LOCKS=0VICTORY_MERGE_MESH_ROWS=0In all three, free memory stays at 16–21% and swap sits at 5–5.8 GB once the world loads. So the GPU time isn't the atomic locks (the same with them off) or the mesh layout. The GPU costs about 130–140 ms per 1,000 draws here, where 24 GB Macs report far less (#577), so the memory pressure looks like the likely cause, as in your 18 GB numbers.
Happy to test a branch of this on 16 GB when there is one.
AI-assisted, prepared with Claude Code.
maxdp66 commentedon Nov 27, 2026
More numbers from a 16 GB Mac (M1 Pro), same picture as above, plus one thing I could not explain: a constant 5.2 GB of native heap.
Setup: M1 Pro, 16 GB, macOS 27.2, D3DMetal 4.0 beta 3,
--console series-s, 1280x720 (default), host FidelityFX 3.1.6 viaVICTORY_FIDELITYFX_DIR,VICTORY_PATCH_MASKED=all VICTORY_FAULT_TRACKING=1 VICTORY_NO_HANG_WATCHDOG=1 VICTORY_EVICT_HEAP_UAV=1 VICTORY_SPILL_SHADERS=1 VICTORY_RAM_LOW=0.20 VICTORY_RAM_FREE=0.26 VICTORY_STEP_OVER=pool VICTORY_AMBIENT=1.Build
main
8baba18(the world draws lit there), release build unless noted. Pre-build: 260 refused containers, 55 compute pipelines skipped, 13 refused by the host.Speed and memory
0.3 to 0.8 fps in the world (1.3 to 3 s a frame) in a release build. The process sits at 17 to 18 GB with 9 to 11 GB of swap, so most of the CPU-side time is paging:
footprintcategoryPer frame in a diagnostics build (
copystat, one interval in the world):Host buffer copies held 2.35 GB (title buffers 0.92 GB, loose windows 1.43 GB with the 256 KiB windows).
What I tried (all on 16 GB)
VICTORY_HEAP_WORKER=1 VICTORY_TABLE_MEMO=1 VICTORY_CENSUS_FAST=1kIOGPUCommandBufferCallbackErrorOutOfMemory, then "a new queue does not run it either")VICTORY_ALIAS_BUFFERS=1SMALL_WINDOW) +VICTORY_IDLE_RELEASE_S=20HostListreset (local experiment)Malloc Medium is 5.2 GB in every run
Across all the runs above it stayed between 5.17 and 5.22 GB, while the host copies varied from 2.4 to 5.2 GB. A local diagnostics count of every upload, readback and write-back custom buffer VIctory creates (by call site) came to about 3 GB, so the 5.2 GB is not ours.
heapshows about 2 million non-object allocations (7.1 GB), 44,000 of them 64 KB or larger (6.1 GB). D3DMetal'sshaders.cacheforvictory.exe(6.6 GB) is memory-mapped, not on the heap. I could not attribute it further:MallocStackLogging=liteandMallocStackLogging=mallocboth crash Wine at start (Unhandled page fault on read access to 000000000011D7B0, right afterlow_guards), so allocation stacks are not available this way.lldbto the game stalled for minutes, even with symbol preloading off.If anyone knows what D3DMetal keeps on the heap at this size, that would be the next thing to cut on 16 GB.
Observation: unattended runs stall at loading
Runs started while nobody was at the Mac (release and diagnostics, with my changes and on unmodified upstream) stopped on the loading artwork about 2 minutes in, at 0.8 fps with 11 draws a frame and about 1.1 s of "preparing" a frame. The same builds passed that point when I was at the Mac. A
--cachepre-build run while away also paused for about 16 minutes. My guess is macOS throttling (App Nap or display sleep), not confirmed.ottco-dev commentedon Nov 27, 2026
@Stefa008 the branch you asked about is up now:
ottco-dev/VIctory-macOS-halfwave50cherrypicker-ottco(cd65104).It is halfwave50's
main-mac(cbf96d2) with upstream #381 #415 #416 #436 #452 #456 #495 #499 #530 #533 #535 #551 #567 #571–#576 #579 #580 #582 #583 picked on top, plus a fewmac:commits (oneInstant::nowper copy instead of per range, one periodic waitable timer for the held-work tick, a multiply hasher forBatch's address maps, diagnostics counters).On a 24 GB M5 Pro (Series X, CrossOver Wine, D3DMetal 4.0b3) it runs the prison cell at ~180–187 ms a frame (5.3–5.5 fps) with:
(everything else as
tools/macos/play-main-mac.shsets it). Measured per step in #505's follow-up. I have not run it on 16 GB; with 16 GB the RAM marks above are probably too low, the 0.15/0.20 you use is a better start.AI use: Claude Code (Claude Opus 5.5) built and benchmarked the branch and wrote this comment.
maxdp66 commentedon Nov 27, 2026
Follow-up to my comment above: the constant 5.2 GB of native heap is D3DMetal's own per-exe shader cache, which it reads into memory when the device is created. On a 16 GB Mac that was about a third of the process.
Measurements (M1 Pro 16 GB, main
d1609d9, D3DMetal 4.0 beta 3, Series S)footprintsampled every 3 to 5 s from launch:$(getconf DARWIN_USER_CACHE_DIR)d3dm/victory.exeas it was (6.7 GB)With the folder renamed, the device was also ready after about 6 s instead of about 15 s.
Our cache was 6.7 GB because
victory translate --cache --pipelinescompiles every pipeline in the shader pack (28,164 here) into that cache. The game itself started 2,614 pipelines early and made or loaded about 2,500 in the world.A normal run on a cache the game filled by itself (260 MB after one session): footprint 17–18 GB → 12 GB, Malloc Medium 5.2 GB → 0.6 GB, no GPU out-of-memory. The first trip into the world compiles what is missing (1,509 made and 981 loaded, finished about 4 minutes after the world appeared); frame times on heavy frames were in the same range as with the full cache.
So on 16 to 32 GB Macs, pre-building the whole pack with
--pipelinescosts about as much memory as it saves compile time. It may be worth a note indocs/backend.md(which recommendstranslate --cache --pipelines) that D3DMetal keeps its whole per-exe cache in memory, and perhaps a pre-build of only the pipelines a run actually used (VICTORY_PIPELINE_LOGalready lists them).Smaller findings from the same runs
shared_buffers (custom heap, write-back) went intoIOAccelerator (graphics), not the malloc heap. So the copies [macOS] One host copy per physical-page backing instead of per title address (16-18 GB Macs) #554 is about count against GPU memory.dispatch_data_tfor 8, small 48-byte nodes for 3 and a D3DMetal command list for 1; which fits the cache explanation better than command lists.Stefa008 commentedon Nov 27, 2026
Tried @ottco-dev's
cherrypicker-ottco(cd65104) on the 16 GB M4 (MacBook Pro, Series S, 1280x720 output, CrossOver Wine + D3DMetal 4.0 beta 3). On top ofplay-main-mac.shI keepVICTORY_ALIAS_BUFFERS=0 VICTORY_RAM_LOW=0.15 VICTORY_RAM_FREE=0.20 VICTORY_SMALL_LOOSE_WINDOWS=1 VICTORY_EVICT_HEAP_UAV=1 VICTORY_SPILL_SHADERS=1, because aliasing ran this Mac out of GPU memory before.Big step up from main here. Prison yard/cell, numbers taken a few minutes after world entry (the first minutes are still loading the scene and look 3–5x worse):
a31fcca1(my earlier comment)cherrypicker-ottcocherrypicker-ottco+ #534One thing worth picking: the branch doesn't have #534 yet, and on 16 GB that shows.
Rust heapin the frame report grows from about 1.4 GB at world entry to 3.6 GB 7 minutes later. The allocation trace points at thedescriptor::VIEWSlist doubling (34 → 272 → 544 → 1088 MB blocks). Swap fills up and fps drops over time. With #534 ported by hand (it doesn't apply cleanly, sincedescriptor.rsdiffers, but onlyrecord,forget,view_atandviews_current_intoneed the decode), it stays flat: 1.17 GB → 1.27 GB over the same 7 minutes. Its tests pass on the branch.Also tried #596 (
VICTORY_HOT_PAGES=1) on this branch. Measured after the scene settled, it's neutral here: 2.5–2.8 fps, about the same guard handler and lock wait times.What's left per frame: preparing 135–200 ms (host copies ~250 MB/frame take 85–160 of it), GPU ~150 ms, copy-back ~35 ms. Swap still sits around 5.5 GB, but that's video memory (~6.9 GB) plus loose windows (~1.4 GB), not growth.
AI-assisted, prepared with Claude Code.
Stefa008 commentedon Nov 27, 2026
Small follow-up on
cherrypicker-ottcoon the 16 GB M4 (Series S, 1280x720, D3DMetal).The ~265 draws/frame the frame report shows as "dropped without a host pipeline" in the prison cell weren't missing shaders. They're the BVH builder's dispatches: all 53 of its pipelines are made (0 refused), but
pipeline::builder::opensholds it back becauseplay-main-mac.shturns onVICTORY_HALVES_LOCAL/VICTORY_HALVES_SHARED_LDS, so it never runs on a Mac with that script. The diagnostics drop list doesn't name them either, since they have a host pipeline and no reason gets recorded.I added a switch locally to let it run anyway (
VICTORY_BVH_HALVES=1, off by default) to see if the RTX 4070 hang shows up on Apple GPUs:No hang in ~10 minutes in the world, no device-removed errors. Main doesn't have the halves gate at all, so this matches what main does on Macs. Maybe the gate could be keyed on the host (Apple vs the 4070 case) rather than on the halves switches?
AI-assisted, prepared with Claude Code.
pragyaangaur commentedon Nov 28, 2026
Thank you Stefa008, this is a real finding:
pipeline::builder::opensholds the BVH builder back wheneverVICTORY_HALVES_LOCALorVICTORY_HALVES_SHARED_LDSis on, so a Mac that runsplay-main-mac.shnever runs it, and the dropped draws are not missing shaders. #591 (merged today) lets the builder translate on a 32-lane host, so the hold-back is now the only thing in the way. Please send yourVICTORY_BVH_HALVES=1switch as a small PR, off by default, with a line indocs/macos.md, and say in the PR what the frame looked like with it. 4TheDoctor's notes on #410 and #442 say the builder can break the picture when it does run, so the switch should stay opt-in.Stefa008 commentedon Nov 28, 2026
Thanks! Went to make the PR against main and it turns out there's nothing to send: main never had the halves hold-back, that's only in the
main-mac/cherrypicker-ottcofork. On main #591 already added its own opt-in,VICTORY_BVH_BUILDER=1, and its notes say why it stays off (the builder's lists read title memory with no host copy, the cell goes dark, macOS kills submissions). SoVICTORY_BVH_HALVESwould just be a second switch for the same thing.On the fork it's still useful, so I'll offer it there instead (off by default, same as now).
Numbers on the fork with it on, for the record (16 GB M4, Series S, 1280x720, flights +
VICTORY_SHADER_OPT=64): cell 3.7–3.9 fps, GPU 114–119 ms, and the builder costs nothing measurable there (3.79 without it vs 3.86 with). Moving around it's worse: walking out of the cell into the corridor drops to 1.6–2.0 fps with host copies at 330–380 MB a frame, and textures are wrong for the first few minutes.AI-assisted, prepared with Claude Code.