native: vertex and pixel programs read root views through the page table #207

Merged
Olima34 merged 2 commits from upstream-pr/207 into main 2026-11-27 00:57:39 +00:00
Olima34 commented 2026-11-27 00:40:26 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T00:40:26Z.


Vertex fetch through root SRVs read the wrong memory when a vertex buffer's range ran past its 64 KiB mapping. Found and verified on a real game run (Apple M5 Pro, 48 GB, Series S, windowed).

Why. addr::root_view hands a shader a view pair that is linear in the pool, starting from the mapping that holds the root address. Accesses past the end of that mapping land in whatever pool pages follow, not in the title's next mapping. The title maps consecutive pages at non-adjacent pool offsets, often in descending order (e.g. title 0x849fb0000 → pool 0x2e9b0000, 0x849fc0000 → pool 0x2e9a0000).

Diagnostic (first commit, off by default): VICTORY_TRACE_ROOT_SPAN[=<bytes>] logs each root view whose address range stays pool-contiguous for less than the given bytes from its start (1 MiB by default), once per case, with the shader hashes and whether the next title page is mapped elsewhere. It's documented in docs/native-host.md, and addr::linear_run has a unit test.

On a world-frame run it found 117 such root views, all vertex shaders' root SRVs (root parameter 3, vertex fetch). 30 of them have a next title page elsewhere in pool 10, so those draws fetched wrong vertices. There were no dispatches and no root UAVs, so this is not the prologue crash.

Fix (second commit): with zero_copy_memory, vertex and pixel programs read their root views through the title-memory page table, the path compute already uses for computed addresses (root_memory in lower.rs). Compute programs keep the linear view: none had a short run.

Tests.

  • addr_tests::a_vertex_root_view_follows_the_title_across_pages_apart_in_the_pool (Metal): two consecutive title pages mapped to non-adjacent pool offsets, and a root SRV 8 bytes before the end of the first, so vertex 0 is in page 1 and vertices 1 and 2 are in page 2. On main nothing is drawn; with the fix the triangle is drawn. As a sanity check, it passes on main when the two pages are pool-contiguous.
  • victory-shader (281) and victory-gpu (261, arm64, Metal) tests, Windows clippy and cargo xtask policy pass.

In game, with VICTORY_TRACE_ROOT_SPAN=16 MiB: every vertex root view logged now goes through="table" (123 cases, all 64 KiB mappings). There are 0 linear pair cases, where there were 117 before (30 of them wrong). No GPU errors, and no slowdown: frames 2300→2700 took 22 s, against 26 s on the earlier base.

Cost: one page-table lookup per vertex fetch in graphics programs. It didn't show in the frame times above. Note that the change retranslates every graphics shader with root views once, so the first run after it is a cold one.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5519192728 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/207). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T00:40:26Z. --- Vertex fetch through root SRVs read the wrong memory when a vertex buffer's range ran past its 64 KiB mapping. Found and verified on a real game run (Apple M5 Pro, 48 GB, Series S, windowed). **Why.** `addr::root_view` hands a shader a view pair that is **linear in the pool**, starting from the mapping that holds the root address. Accesses past the end of that mapping land in whatever pool pages follow, not in the title's next mapping. The title maps consecutive pages at non-adjacent pool offsets, often in descending order (e.g. title `0x849fb0000` → pool `0x2e9b0000`, `0x849fc0000` → pool `0x2e9a0000`). **Diagnostic** (first commit, off by default): `VICTORY_TRACE_ROOT_SPAN[=<bytes>]` logs each root view whose address range stays pool-contiguous for less than the given bytes from its start (1 MiB by default), once per case, with the shader hashes and whether the next title page is mapped elsewhere. It's documented in docs/native-host.md, and `addr::linear_run` has a unit test. On a world-frame run it found **117 such root views, all vertex shaders' root SRVs** (root parameter 3, vertex fetch). 30 of them have a next title page elsewhere in pool 10, so those draws fetched wrong vertices. There were no dispatches and no root UAVs, so this is not the prologue crash. **Fix** (second commit): with `zero_copy_memory`, vertex and pixel programs read their root views through the title-memory page table, the path compute already uses for computed addresses (`root_memory` in `lower.rs`). Compute programs keep the linear view: none had a short run. **Tests.** - `addr_tests::a_vertex_root_view_follows_the_title_across_pages_apart_in_the_pool` (Metal): two consecutive title pages mapped to non-adjacent pool offsets, and a root SRV 8 bytes before the end of the first, so vertex 0 is in page 1 and vertices 1 and 2 are in page 2. On main nothing is drawn; with the fix the triangle is drawn. As a sanity check, it passes on main when the two pages are pool-contiguous. - victory-shader (281) and victory-gpu (261, arm64, Metal) tests, Windows clippy and `cargo xtask policy` pass. **In game**, with `VICTORY_TRACE_ROOT_SPAN=16 MiB`: every vertex root view logged now goes `through="table"` (123 cases, all 64 KiB mappings). There are **0** linear `pair` cases, where there were 117 before (30 of them wrong). No GPU errors, and no slowdown: frames 2300→2700 took 22 s, against 26 s on the earlier base. Cost: one page-table lookup per vertex fetch in graphics programs. It didn't show in the frame times above. Note that the change retranslates every graphics shader with root views once, so the first run after it is a cold one.
LakshanSivakumar commented 2026-11-27 00:57:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T00:57:36Z.

Review: APPROVED


Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6082114290 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/207#pullrequestreview-6082114290). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T00:57:36Z. **Review:** APPROVED --- Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
Sign in to join this conversation.
No reviewers
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!207
No description provided.