Skip to content

perf(gpu): alias title buffers by default under Rosetta with D3DMetal - #293

Closed
earpjonathan wants to merge 1 commit into
pragyaangaur:mainfrom
earpjonathan:gpu/alias-buffers-default
Closed

earpjonathan wants to merge 1 commit into
pragyaangaur:mainfrom
earpjonathan:gpu/alias-buffers-default

Conversation

@earpjonathan

Copy link
Copy Markdown
Contributor

VICTORY_ALIAS_BUFFERS (#207, from #204) is now on by default under Rosetta with D3DMetal, and never with WARP. VICTORY_ALIAS_BUFFERS=0 keeps the host copies. The start-up probe still falls back to the copies wherever mach_vm_remap onto a D3DMetal buffer does not work, so those hosts behave as before.

Why: with host copies, the pages that shaders wrote in a submission are copied back into title memory after the submission runs.

  • Each copy-back opens the page's write guard and closes it again, under the guard lock. Under Wine that costs one VirtualProtect per 64 KiB view.
  • This is part of the queue's post-run work, which runs while HELD is locked.
  • The submission's bottom-of-pipe writes (Written, list::defer_write) land only after it.

So held work on other queues that waits for those values waits for the copy-back too, and so does every queue call behind HELD. Aliased buffers need no copy-back and no refresh, so none of this happens for them.

Changes

  • alias::decide_enabled takes the switch as Option<bool>: unset is on.
  • Tests: the existing cases now set the switch. New cases leave it unset and check that aliasing is on under Rosetta only, and never with WARP.
  • docs/macos.md: the switch moves out of "Optional switches", none of which changes the default, into a section of its own that documents VICTORY_ALIAS_BUFFERS=0.

Tested

  • Under Wine (CrossOver 26.3's wine under Rosetta, with Wine's own d3d12, not D3DMetal):
    • Full suite (tools/macos/test-wine.sh --workspace --no-fail-fast): 1062 passed, 0 failed, 23 ignored. This ran before a final change that only reformatted one line and edited the docs. The 11 alias tests pass after that change.
    • A temporary print confirmed that aliased_buffer_is_coherent_with_gpu_copies aliases on a device rather than returning early.
  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features, for x86_64-pc-windows-gnullvm.

🤖 Generated with Claude Code

VICTORY_ALIAS_BUFFERS is now on unless set to 0, under Rosetta with
D3DMetal only (never WARP); the start-up probe still falls back to the host
copies where the remap does not work. Aliased buffers need no copy-back
after a submission, which otherwise runs under HELD before the submission's
bottom-of-pipe writes land. docs/macos.md gives it a section of its own,
out of the table of switches that change nothing by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur

Copy link
Copy Markdown
Owner

Thank you. The idea is sound, and the held-work cost you describe in the body is real. I am not turning VICTORY_ALIAS_BUFFERS on by default yet, because the only runs so far are synthetic ones under Wine's own d3d12, and the docs still say it needs a run in the game. A default that touches every title buffer needs at least one real in-game run on D3DMetal first. If you or a tester can post one (frame times, copy bytes and whether the scene looks the same, text only) on #131 or #135 with VICTORY_ALIAS_BUFFERS=1, please reopen this or send it again and I will merge it.

@earpjonathan

earpjonathan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Posted the in-game results on #131: #131 (comment)

In short, on an M5 Pro with D3DMetal 4.0 beta 3:

  • Aliasing made the world-load stall rarer, but it isn't gone. It stalled in 1 of 3 aliased runs, against 5 watchdog stops in 9 runs without aliasing.
  • The closest pair of 10-minute runs gave 561 ms against 615 ms a frame, and 327 MB against 448 MB copied a frame. That pair is two different builds, so not all of the difference is aliasing.
  • The saved frames show the same shot. A translucent foreground layer is lighter in the aliased run, and I can't tell whether that's timing or rendering.

GitHub didn't let me reopen this one, so I sent it again, rebased on main, as #322. Whether that's enough for a default is your call.

AI-assisted, prepared with Claude Code.

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.

2 participants