Skip to content

perf(gpu): read the title's physical pages in place (VICTORY_PHYSICAL_TILES=1) - #653

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:claude/physical-tiles
Nov 28, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:claude/physical-tiles

Conversation

@Nick233x

Copy link
Copy Markdown
Contributor

Follow-up to #584. It got merged just before this commit was pushed to its branch, so this is the commit again, on current main.

What

VICTORY_PHYSICAL_TILES=1 (off by default; Rosetta and D3DMetal only) lets title buffers on the title's physical pages be read in place, with no host copy to refresh.

In the world (run I), the largest refreshed host copies are title buffers on physical pages (XMemAllocatePhysicalPages / XMemMapPhysicalPages). The new "physical pages … runs" line shows 576 pages in 4 runs and 384 in 7, one section each. The title writes them page by page, and they are refreshed accordingly: about 75 of the 175 MB refreshed per frame.

With the switch:

  • Sections as GPU heaps. Each section of physical pages is a CPU-visible L0 heap. This is alias::PhysicalHeap, until now a diagnostics-only trial, now behind the switch. The title's views of a section are remapped onto its heap (mach_vm_remap), so the title's CPU writes, and DirectStorage's, land in GPU memory.
  • Zero-copy host copies. A title buffer whose pages all lie on such heaps when it is first used gets a zero-copy host copy (crate::tiled): a reserved buffer whose 64 KiB tiles are its pages in the title's order (UpdateTileMappings, one call per run). Nothing is refreshed into it or copied back, and what shaders write the title reads at once.
  • Remaps. When the title maps other pages there or unmaps them, victory-hle passes the new tiles (victory_gpu::physical_retiled) and the tiles follow at once on the host queue.
  • Unmapped pages. D3DMetal ignores null tile mappings: the tile keeps its old page. The inplace probe passed only because its fresh readback buffer held zeros anyway; that is now noted in the probe. Unmapped pages therefore show a tile of zeros of our own.
  • Lock order. The tiles are asked for without the buffers' lock held. victory-hle holds its own lock while it tells the trackers about a mapping, and those trackers may read the buffers.
  • A buffer with any page not on a GPU heap when first used is copied as before.

Tests

  • victory-gpu, on D3DMetal: title pages are remapped onto heap tiles 2, 0, 3, 1.
    • The GPU reads the title's bytes with no refresh, and the title reads a GPU write at once.
    • A retiled page shows its new tile.
    • An unmapped page reads zeros, and the other pages stay as they were.
    • A buffer with a page off GPU memory is copied.
  • victory-hle, with the switch: mapped physical pages name their tiles in the title's order, the title's writes land in the heap, and unmapped pages name none.
  • Other test changes:
    • own_section_views_start_above_two_tib_under_wine skips the address floor when the whole view is the GPU heap.
    • Two prep-ahead tests asserted on something another test's synchronous submission can undo (it lands the flight they hold in the air). They now retry, as until_taken intended.

Under Wine on #584's branch: victory-gpu 641/0 in four of five runs. The fifth failed in shadow::marked_pages_go_back_by_the_bytes_the_gpu_changed, which also fails without this change while other sessions' GPU tests run.

Not run yet: Wine tests are paused while the game runs (they share 24 GB with it; run K1 hit a Metal OOM). Still open:

  • the victory-hle suite with VICTORY_PHYSICAL_TILES=1 after the floor-test fix;
  • a Wine run on this exact base.

Clippy is clean with and without --all-features, and cargo xtask policy is ok.

Re-test

Compare VICTORY_ASYNC_SUBMIT=1 VICTORY_PHYSICAL_TILES=1 VICTORY_VIEW_PROBE=1 against the same without VICTORY_PHYSICAL_TILES.

What to look at:

  • In host copies refreshed per frame, the physical-page copies should be gone.
  • The refreshes phase should shrink.
  • The log should have the line first title buffer read on its physical pages in place.
  • Watch for corrupt geometry or textures.

Memory cost: physical pages become wired GPU heaps.

🤖 Generated with Claude Code

…_TILES=1)

Run I: the largest refreshed copies (37.7 MB on 576 physical pages in 4
runs, 25.2 MB on 384 in 7, one section each) are title buffers on the
title's physical pages, refreshed page by page as the title writes them,
~175 MB a frame with the rest.

With VICTORY_PHYSICAL_TILES=1 (off by default; Rosetta and D3DMetal only)
those pages are GPU memory, and such buffers need no copy:

- Each section of physical pages is a CPU-visible L0 heap
  (alias::PhysicalHeap, the diagnostics trial made a switch), and the
  title's views of it are remapped onto it (mach_vm_remap): the title's
  CPU writes land in GPU memory, and DirectStorage writes the heap.
- A title buffer whose pages all lie on such heaps when first used gets a
  zero-copy host copy (crate::tiled): a reserved buffer whose 64 KiB tiles
  are its pages in the title's order (UpdateTileMappings, one call a run
  of a heap's consecutive tiles). Nothing is refreshed into it or copied
  back; what shaders write the title reads at once.
- When the title maps other pages there or unmaps them, victory-hle passes
  the new tiles (victory_gpu::physical_retiled, under its own lock: no
  call back) and the copy's tiles follow on the host queue at once.
  D3DMetal ignores null tile mappings (the tile keeps its old page; the
  inplace probe only passed as its fresh buffer held zeros anyway), so an
  unmapped page shows a tile of zeros of ours.
- The tiles are asked of victory-hle without the buffers' lock: it holds
  its own while it tells the trackers of a mapping, which may read the
  buffers (VICTORY_SHADOW_KEEP).

Tests: on a CPU-visible heap with title pages remapped onto tiles 2, 0, 3,
1, the GPU reads what the title wrote with no refresh, the title reads
what the GPU wrote, a page retiled shows the new tile, an unmapped page
reads zeros and the others stay (victory-gpu); a buffer with a page off
GPU memory is copied; with the switch, mapped physical pages name their
tiles in the title's order, the title's writes land in the heap, and
unmapped they name none (victory-hle). own_section_views_start_above_two_tib
skips the floor when the whole view is the GPU heap.

Two prep-ahead tests asserted what another test's synchronous submission
can undo (it lands the flight held in the air), and failed more often with
the new test's tile updates on the queue: they now retry, as until_taken
meant them to.

Suites under Wine: victory-gpu 641/0 in four of five runs (the fifth:
shadow::marked_pages_go_back_by_the_bytes_the_gpu_changed, which fails as
often without this change while other sessions' GPU tests run).

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

Copy link
Copy Markdown
Contributor

Heads-up on the switch name: #410's view space (my de3e10f, which @mikebuckets171 rebased onto main tonight as contrib/page-pool-zero-copy) also uses VICTORY_PHYSICAL_TILES=1, for the page pool's placeholder chunks rather than physical-page sections. If both land they'd share one switch, so it may be worth agreeing on names or folding them into one.

One lesson from #410 that may apply here too. With the page pool read in place, tiles not shown read as zeros without counting as misses, and the title's writes can't be withheld without a copy. On my lab base that let the BVH builder write empty bounding boxes over its own data, and the title crashed at about 180 to 260 s. The builder is held back by default now (#591, VICTORY_BVH_BUILDER=1), so a run with this switch and the builder on would be the case to watch.

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