Skip to content

feat(gpu): alias title memory outside buffers instead of copying it (VICTORY_ALIAS_LOOSE=1) - #669

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
sentaxic:pr/alias-loose
Nov 28, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
sentaxic:pr/alias-loose

Conversation

@sentaxic

Copy link
Copy Markdown
Contributor

What

VICTORY_ALIAS_LOOSE=1 (off by default): a window of title memory outside any buffer object is remapped onto its host buffer, zero copy (alias_region), where every page of the window is committed, instead of being copied on every submission that reaches it.

That memory is Grand Theft Auto VI's interface vertices, from its own allocator. It is not a buffer the title asks the device for, so nothing aliases it at allocation the way XMemVirtualAlloc does.

  • Whole window committed. alias_region preserves the contents by reading every page first, so one uncommitted page would fault. The existing check only vouched for the address asked about.
  • Small windows. It pays only with 256 KiB windows, now the default on a Mac with 32 GB or less: a 256 KiB window is committed whole far more often. In the world, 4 MiB windows aliased 19 regions; 256 KiB windows, 2,793.
  • Refused. If another window aliased over it first or the remap fails, it falls back to the copy, as before.

Measurements

M5 MacBook Air (16 GB), macOS 27.2, Series build 1.0.2.1, 1280x720, VICTORY_FAULT_TRACKING=1, 256 KiB windows:

without with
aliased regions 9 1,902
loose window memory 3,527 MB 541 MB
copy time, heaviest frame 7,248 ms 2,033 ms
copy time, 5 heaviest frames 4,965 ms 1,771 ms (mean)

No mach_vm_remap failure, host GPU failure or exception across the runs. The runs were compared by elapsed time rather than frame for frame, so take the ratios as approximate.

Why off by default

A window is not an allocation of the title's: it is cut around whatever address a draw referenced, so nothing says when the title frees or reuses the memory under it, as XMemFree does for buffers aliased at allocation.

Tests

  • victory-gpu under Wine (M5, D3DMetal): 648 passed, 0 failed, 29 ignored.
  • Clippy is clean for x86_64-pc-windows-gnullvm on the workspace with and without --all-features, and cargo xtask policy is ok.
  • One file, 40 lines.

Not run on this exact base: the measurements above; rebased onto current main, where the only conflict was the new loose-window default next to it.

Re-test

VICTORY_FAULT_TRACKING=1 into the world with and without VICTORY_ALIAS_LOOSE=1, comparing the host buffer copies held and copies per frame lines.

🤖 Generated with Claude Code

`VICTORY_ALIAS_LOOSE=1` (off without it): a window of title memory
outside any buffer object is remapped onto its host buffer, zero copy,
where every page of the window is committed.

Such memory is Grand Theft Auto VI's interface vertices, from its own
allocator. It is not a buffer the title asks the device for, so nothing
aliases it at allocation the way `XMemVirtualAlloc` does, and each
window is copied again on every submission that reaches it.

The whole window must be committed because `alias_region` preserves the
contents by reading every page of it first; the check already there only
vouches for the address asked about.

It pays only with small loose windows, which are now the default on a
Mac with 32 GB or less: a 256 KiB window is committed whole far more
often than a 4 MiB one. In the world with 4 MiB windows 19 regions were
aliased; with 256 KiB windows, 2,793.

Measured on an M5 MacBook Air (16 GB), macOS 27.2, Series build 1.0.2.1
at 1280x720, with `VICTORY_FAULT_TRACKING=1` and 256 KiB windows:

    aliased regions                 9  ->  1,902
    loose window memory      3,527 MB  ->  541 MB
    copy time, heaviest frame  7,248 ms  ->  2,033 ms
    copy time, 5 heaviest      4,965 ms  ->  1,771 ms (mean)

No `mach_vm_remap` failures, no host GPU failure and no exception across
the runs. The runs were compared by elapsed time, not frame for frame,
so take the ratios as approximate.

Off by default. A window is not an allocation of the title's: it is cut
around whatever address a draw referenced, so nothing tells us when the
title frees or reuses the memory under it, as `XMemFree` does for the
buffers aliased at allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 8b4a2ac into pragyaangaur:main Nov 28, 2026
1 check passed
@4TheDoctor

Copy link
Copy Markdown
Contributor

A Mac number for this and #653, one run each on an M3 Max (48 GB, CrossOver 26.1, D3DMetal 4.0b3, Series X). Main cade9e02, diagnostics build, 1920x1080 output at render scale 0.5, VICTORY_GPU_TIMING=0, cold cache, scripted opening into the cell, 720 s. The second run has VICTORY_PHYSICAL_TILES=1 VICTORY_ALIAS_LOOSE=1 both on, so I can't split what each one does.

Fast-level frame Prep Watches Protecting Copies held Loose windows Aliased regions
both off 394 ms 161 ms 53 ms 11 ms 4,318 MB 760 (3,716 MB) 9 (4,822 MB)
both on 412 ms 182 ms 100 ms 26 ms 4,164 MB 768 (3,561 MB) 26 (4,893 MB)
  • Both switches did something. large title buffer aliased zero-copy shows 4 times, and the aliased regions go from 9 to 26.
  • But on this scene the copies held only drop by about 150 MB, and the loose windows barely change.
  • In return the watching roughly doubles and protecting more than doubles.
  • The frame is a little slower, and there were 5-10 s frames between 450 and 520 s that the run without the switches didn't have.
  • No ended submissions, and the cell looks the same (median luma 27-28 against 28-29).

The largest refreshed copies still say [private, …, physical pages 34 in 18 runs over 1 sections], so those buffers didn't qualify for the zero-copy path here. Happy to run each switch alone if that helps narrow it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants