The title writes most descriptor records with plain stores (~40k a frame); patching its store sites is an exact alternative to remirroring #43

Open
opened 2026-11-26 14:43:49 +00:00 by github-bot · 9 comments
Owner

@⁠64bitMango on GitHub · 2026-11-26 11:17 UTC · original

From the Wine/D3DMetal ports of the same build (1.0.2.1), relevant to NativeHost::remirror_tables, which today checks the first 16 entries of each bound table.

What the title does in the world. It fills its shader-visible view heap (its frame allocator's memory, image +0x4d9f400) mostly with plain stores and memcpy, not device calls. Measured on the Windows forks: 60k-210k records copied a frame, about 40k a frame that no call announced (fxceless/victory-fork, upstream VIctory PR #305 by Flyander); 400k slots looked at, 40k mirrored a frame (avatarmanz/VIctory-7900XTX docs/findings.md). Checking only part of each table will miss many of them once the world renders.

What worked for them.

  1. Leave draws' own tables to the draws (avatarmanz 1f1a4336): the records a draw's or dispatch's table reads are made at the draw anyway, so a whole-heap sync can skip them; only slots that heap-indexing shaders read need mirroring. Their biggest single win: frame 280 -> ~124 ms.
  2. Patch the stores (avatarmanz 9997d255 and 4cb90bee, "renderer port 2"): draws' and dispatches' tables are filled by six 32-byte stores in image +0x4d9efd0 and +0x4eec8e0. Their launcher patches those stores (original bytes checked; a site that differs is left alone and logged) to jump to code that does the store and marks the slot, and also hooks the title's memcpy/memmove for records copied into the heap. The sync then takes the marked slots instead of scanning.

Since the native port runs the title in-process with no write watch, (2) looks like the natural fit: exact, and no per-draw checks.

**@⁠64bitMango** on GitHub · 2026-11-26 11:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43) From the Wine/D3DMetal ports of the same build (1.0.2.1), relevant to `NativeHost::remirror_tables`, which today checks the first 16 entries of each bound table. **What the title does in the world.** It fills its shader-visible view heap (its frame allocator's memory, image +0x4d9f400) mostly with plain stores and memcpy, not device calls. Measured on the Windows forks: 60k-210k records copied a frame, about 40k a frame that no call announced (fxceless/victory-fork, upstream VIctory PR #305 by Flyander); 400k slots looked at, 40k mirrored a frame (avatarmanz/VIctory-7900XTX `docs/findings.md`). Checking only part of each table will miss many of them once the world renders. **What worked for them.** 1. *Leave draws' own tables to the draws* (avatarmanz 1f1a4336): the records a draw's or dispatch's table reads are made at the draw anyway, so a whole-heap sync can skip them; only slots that heap-indexing shaders read need mirroring. Their biggest single win: frame 280 -> ~124 ms. 2. *Patch the stores* (avatarmanz 9997d255 and 4cb90bee, "renderer port 2"): draws' and dispatches' tables are filled by six 32-byte stores in image +0x4d9efd0 and +0x4eec8e0. Their launcher patches those stores (original bytes checked; a site that differs is left alone and logged) to jump to code that does the store and marks the slot, and also hooks the title's memcpy/memmove for records copied into the heap. The sync then takes the marked slots instead of scanning. Since the native port runs the title in-process with no write watch, (2) looks like the natural fit: exact, and no per-draw checks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:43:49 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 13:28 UTC · original

Thanks for writing this up, @⁠64bitMango. NativeHost::remirror_tables currently only checks a prefix of each bound table, which clearly won't cover ~40k plain-store descriptor writes per frame once world draws ramp up.

Since the native host runs in-process without a write watch, patching/hooking the heap store sites (or skipping per-draw tables and tracking only heap-indexed slots) is a very helpful reference when we get to world-scale descriptor mirroring. Added enhancement and help wanted labels.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 13:28 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7193401432) Thanks for writing this up, @⁠64bitMango. `NativeHost::remirror_tables` currently only checks a prefix of each bound table, which clearly won't cover ~40k plain-store descriptor writes per frame once world draws ramp up. Since the native host runs in-process without a write watch, patching/hooking the heap store sites (or skipping per-draw tables and tracking only heap-indexed slots) is a very helpful reference when we get to world-scale descriptor mirroring. Added `enhancement` and `help wanted` labels.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 15:56 UTC · original

Status: not started. Lower priority than the story-load crash in #15. Still open and up for grabs.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 15:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7196969924) Status: not started. Lower priority than the story-load crash in #15. Still open and up for grabs.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 17:16 UTC · original

@⁠Olima34, assigning this to you, since it sits next to the descriptor mirroring and xmem work you've been doing. A first PR that measures it would be enough: which store sites write the ~40k records per frame, and how many patch sites that means. Then we can decide between patching and remirroring.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 17:16 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7198747449) @⁠Olima34, assigning this to you, since it sits next to the descriptor mirroring and xmem work you've been doing. A first PR that measures it would be enough: which store sites write the ~40k records per frame, and how many patch sites that means. Then we can decide between patching and remirroring.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 18:10 UTC · original

#119 and #127 are merged. VICTORY_TRACE_DESCRIPTORS=1 counts the remirrored records, and =sites lists the title's store sites. Next is a world-load run with =sites to get the numbers.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 18:10 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7200140302) #119 and #127 are merged. `VICTORY_TRACE_DESCRIPTORS=1` counts the remirrored records, and `=sites` lists the title's store sites. Next is a world-load run with `=sites` to get the numbers.
Author
Owner

@⁠derz92 on GitHub · 2026-11-27 14:50 UTC · original

A first VICTORY_TRACE_DESCRIPTORS=sites data point, plus a pointer to a working store-site patch for the same title in another fork.

Run: Apple M5 Max, 36 GB, macOS 26.5, --console series-s, main 728845d1 plus four open PRs that don't touch descriptors (#335, #342, #343, #361). The run reached the story load and the first world frames (frame ~1600) before my memory guard stopped it at 82 s (other apps were open), so these are world-entry numbers, not steady world.

Store sites at frame 1600 (descriptor store sites since the start, distinct=9, overflow=0):

Site Stores
image+0x124a4f 1599
image+0x18849c 1599
image+0x4fb05b8 589
image+0x4d9f059 461
image+0x3a18377 453
image+0x3a1b9c0 453
image+0x4d9f117 42
image+0x4d9f25f 7
image+0x4e9b4e2 2

descriptor remirror went from 2–3 changed records a frame in the menus to 77–84 a frame (about 5,000 of 15,000 checked per 64 frames, all in heap 0x20230000) at world entry.

A cross-check from another fork: Belobug/VIctory-Belobug-AMD (GPL-3.0, a Windows fork of Marvisak's VIctory) already patches this title's descriptor-table stores (VICTORY_PORT_DESCRIPTORS=1). Its notes (crates/victory-loader/src/descriptor_sites.rs) say the draws' and dispatches' tables are filled by two functions:

  • +0x4d9efd0 for graphics, +0x4eec8e0 for compute;
  • three loops each, one 32-byte record at a time (and r, 7FE0h / vmovups ymm0, [record] / vmovups [table + r], ymm0);
  • six stores in all, each patched (after a byte check) to jump to a stub that does the store and marks the slot.

Three of the sites above (+0x4d9f059, +0x4d9f117, +0x4d9f25f) fall inside the +0x4d9efd0 function, so it looks like the same title build. On their RX 7900 XTX the patch replaced a scan of ~600,000 slots a frame and saved 15–16 ms a frame.

Before any port, the native host's own cost needs measuring. The remirror here only checks the first entries of bound tables, so its cost isn't the same as theirs. I can do a longer world run with =sites once I have memory headroom, to get steady-world numbers. @⁠Olima34, are you working on the patch side? If not, I'm happy to port Belobug's site patch (with credit) behind a switch and measure it here.

**@⁠derz92** on GitHub · 2026-11-27 14:50 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7221302544) A first `VICTORY_TRACE_DESCRIPTORS=sites` data point, plus a pointer to a working store-site patch for the same title in another fork. **Run:** Apple M5 Max, 36 GB, macOS 26.5, `--console series-s`, main 728845d1 plus four open PRs that don't touch descriptors (#335, #342, #343, #361). The run reached the story load and the first world frames (frame ~1600) before my memory guard stopped it at 82 s (other apps were open), so these are **world-entry numbers, not steady world**. Store sites at frame 1600 (`descriptor store sites since the start`, distinct=9, overflow=0): | Site | Stores | |---|---| | `image+0x124a4f` | 1599 | | `image+0x18849c` | 1599 | | `image+0x4fb05b8` | 589 | | `image+0x4d9f059` | 461 | | `image+0x3a18377` | 453 | | `image+0x3a1b9c0` | 453 | | `image+0x4d9f117` | 42 | | `image+0x4d9f25f` | 7 | | `image+0x4e9b4e2` | 2 | `descriptor remirror` went from 2–3 changed records a frame in the menus to **77–84 a frame** (about 5,000 of 15,000 checked per 64 frames, all in heap `0x20230000`) at world entry. **A cross-check from another fork:** [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD) (GPL-3.0, a Windows fork of Marvisak's VIctory) already patches this title's descriptor-table stores (`VICTORY_PORT_DESCRIPTORS=1`). Its notes (`crates/victory-loader/src/descriptor_sites.rs`) say the draws' and dispatches' tables are filled by two functions: - `+0x4d9efd0` for graphics, `+0x4eec8e0` for compute; - three loops each, one 32-byte record at a time (`and r, 7FE0h` / `vmovups ymm0, [record]` / `vmovups [table + r], ymm0`); - six stores in all, each patched (after a byte check) to jump to a stub that does the store and marks the slot. Three of the sites above (`+0x4d9f059`, `+0x4d9f117`, `+0x4d9f25f`) fall inside the `+0x4d9efd0` function, so it looks like the same title build. On their RX 7900 XTX the patch replaced a scan of ~600,000 slots a frame and saved 15–16 ms a frame. Before any port, the native host's own cost needs measuring. The remirror here only checks the first entries of bound tables, so its cost isn't the same as theirs. I can do a longer world run with `=sites` once I have memory headroom, to get steady-world numbers. @⁠Olima34, are you working on the patch side? If not, I'm happy to port Belobug's site patch (with credit) behind a switch and measure it here.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 14:52 UTC · original

@⁠derz92 no, we're not on the patch side, so go ahead. Two points before porting:

  • Game bytes. Belobug's descriptor_sites.rs embeds the title's original instruction bytes for its byte check. AGENTS.md doesn't allow anything from the game in the repo, so the check would need another form: for example a hash of the expected bytes, or only offsets plus a structural check at run time. Worth confirming that form with the maintainer before you write it.
  • Measure first, as you say. Steady-world numbers for the native host's remirror (=sites and the remirror counters over a few hundred world frames) will show whether a store patch saves anything here. Our remirror only checks the first entries of bound tables, which isn't the 600,000-slot scan the 15–16 ms were saved against.

GPL-3.0 on both sides, so porting with credit is fine.

**@⁠Olima34** on GitHub · 2026-11-27 14:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7221338502) @⁠derz92 no, we're not on the patch side, so go ahead. Two points before porting: - **Game bytes.** Belobug's `descriptor_sites.rs` embeds the title's original instruction bytes for its byte check. AGENTS.md doesn't allow anything from the game in the repo, so the check would need another form: for example a hash of the expected bytes, or only offsets plus a structural check at run time. Worth confirming that form with the maintainer before you write it. - **Measure first, as you say.** Steady-world numbers for the native host's remirror (`=sites` and the remirror counters over a few hundred world frames) will show whether a store patch saves anything here. Our remirror only checks the first entries of bound tables, which isn't the 600,000-slot scan the 15–16 ms were saved against. GPL-3.0 on both sides, so porting with credit is fine.
Author
Owner

@⁠jamal-fv on GitHub · 2026-11-29 23:15 UTC · original

/claim
Resuming on perf/descriptor-store-sites (wt-storepatch). Mechanism: arm store-hook slot marks (VICTORY_STORE_SITES), not PE jump patches (lift ignores x86). Measuring steady-world sites first (run 2500), then A/B prove.

**@⁠jamal-fv** on GitHub · 2026-11-29 23:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7264315230) /claim Resuming on `perf/descriptor-store-sites` (wt-storepatch). Mechanism: arm store-hook slot marks (`VICTORY_STORE_SITES`), not PE jump patches (lift ignores x86). Measuring steady-world sites first (run 2500), then A/B prove.
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-29 23:15 UTC · original

Claimed by @⁠jamal-fv. Open a draft pull request with Refs #43 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-29 23:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7264318129) Claimed by @⁠jamal-fv. Open a draft pull request with `Refs #43` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠jamal-fv on GitHub · 2026-11-30 00:13 UTC · original

Sites measure on aarch64+lift (run 2503, VICTORY_TRACE_DESCRIPTORS=sites, frame 4096):

  • Under the lift, fault PC is host-unit code; without mapping it to a guest function RVA, distinct stayed 0 (run 2500). With on_watch_fault → guest function start, distinct=26, overflow=0.
  • Top sites (function grain): +0x4d9efd0 32.8%, +0x325b4f0 21.1%, +0x188430 17.0%, +0x4d9f200 12.2%; Belobug compute fill +0x4eec8e0 at 1.4%. Top 4 ≈ 83% of first-faults.
  • Remirror still ~65k changed records/frame in the world. PE jump patches do not run under the lift; mechanism on this host is destination slot marks via the store hook (VICTORY_STORE_SITES), draft PR #663. Quiet A/B prove queued.
**@⁠jamal-fv** on GitHub · 2026-11-30 00:13 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7265081515) Sites measure on aarch64+lift (run 2503, `VICTORY_TRACE_DESCRIPTORS=sites`, frame 4096): - Under the lift, fault PC is host-unit code; without mapping it to a guest function RVA, `distinct` stayed 0 (run 2500). With `on_watch_fault` → guest function start, `distinct=26`, `overflow=0`. - Top sites (function grain): `+0x4d9efd0` 32.8%, `+0x325b4f0` 21.1%, `+0x188430` 17.0%, `+0x4d9f200` 12.2%; Belobug compute fill `+0x4eec8e0` at 1.4%. Top 4 ≈ 83% of first-faults. - Remirror still ~65k changed records/frame in the world. PE jump patches do not run under the lift; mechanism on this host is destination slot marks via the store hook (`VICTORY_STORE_SITES`), draft PR #663. Quiet A/B prove queued.
This discussion has been locked. Commenting is limited to contributors.
No description provided.