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 11:17:31 +00:00 by 64bitMango · 9 comments
64bitMango commented 2026-11-26 11:17:31 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:17:31Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625496845 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T11:17:31Z. --- 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.
LakshanSivakumar commented 2026-11-26 13:28:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T13:28:31Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193401432 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7193401432). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T13:28:31Z. --- 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 commented 2026-11-26 15:56:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T15:56:58Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7196969924 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7196969924). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T15:56:58Z. --- Status: not started. Lower priority than the story-load crash in #15. Still open and up for grabs.
LakshanSivakumar commented 2026-11-26 17:16:13 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T17:16:13Z.


@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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7198747449 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7198747449). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T17:16:13Z. --- @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 commented 2026-11-26 18:10:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T18:10:31Z.


#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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7200140302 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7200140302). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T18:10:31Z. --- #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.
derz92 commented 2026-11-27 14:50:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T14:50:49Z.


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, #341, #342, #358). 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221302544 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7221302544). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T14:50:49Z. --- 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, #341, #342, #358). 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.
Olima34 commented 2026-11-27 14:52:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T14:52:31Z.


@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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221338502 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7221338502). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T14:52:31Z. --- @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.
jamal-fv commented 2026-11-29 23:15:01 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by jamal-fv on 2026-11-29T23:15:01Z.


/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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7264315230 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7264315230). Originally posted by [jamal-fv](https://github.com/jamal-fv) on 2026-11-29T23:15:01Z. --- /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.
github-actions[bot] commented 2026-11-29 23:15:14 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-29T23:15:14Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7264318129 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7264318129). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T23:15:14Z. --- Claimed by @jamal-fv. Open a draft pull request with `Refs #43` in its description within 24 hours, or the claim expires.
jamal-fv commented 2026-11-30 00:13:48 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by jamal-fv on 2026-11-30T00:13:48Z.


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 #659. Quiet A/B prove queued.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7265081515 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/43#issuecomment-7265081515). Originally posted by [jamal-fv](https://github.com/jamal-fv) on 2026-11-30T00:13:48Z. --- 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 #659. Quiet A/B prove queued.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#43
No description provided.