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

Manually merged
github merged 2 commits from github-bot/gh-207 into main 2026-11-27 01:32:03 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 00:40 UTC · original
Olima34:fix/vertex-root-views-page-table → main · +195 −5 · 8 files · 2 commits · merged 2026-11-27 00:57 UTC

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.

**@⁠Olima34** on GitHub · 2026-11-27 00:40 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/207) `Olima34:fix/vertex-root-views-page-table` → `main` · +195 −5 · 8 files · 2 commits · merged 2026-11-27 00:57 UTC 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.
A root view of a shader that does not read title memory is a pair view of
the pool from the mapping holding its address on, so past that mapping it
reaches the pool's next bytes, not the title's next mapping. The switch
measures each bound root view's linear run and logs the short ones once
per pipeline, root parameter and mapping. Bindings now carry their
pipeline's name for it. Findings for #15 in docs/native-host.md.
On the native host a root SRV or UAV was a view of the pool from the
root address on, linear in the pool past the 64 KiB title page holding
that address. The title maps the next pages anywhere in the pool:
Grand Theft Auto VI's vertex fetch reads vertex buffers through a root
SRV, and 30 of them (VICTORY_TRACE_ROOT_SPAN) went on into a page mapped
elsewhere in pool 10, so vertices past the first page were other bytes.

With zero_copy_memory, vertex and pixel programs now use title memory
for root views (root_memory), as programs computing addresses do: each
access looks its page up in the page table. Compute keeps the views (no
such case seen, and the lookup costs). A test draws a triangle whose
first vertex ends one page and whose others start the next one, mapped
elsewhere in the pool: nothing was drawn before.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:55:01 +00:00
github manually merged commit 88441725fb into main 2026-11-27 01:32:03 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 00:57 UTC · original · approved these changes

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

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 00:57 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/207#pullrequestreview-6082114290) · **approved these changes** Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.