gpu(native): wrap non-linear multi-page VB, IB, and blit spans (#442) #447

Manually merged
github merged 1 commit from github-bot/gh-443 into main 2026-11-28 00:42:30 +00:00 AGit
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 19:07 UTC · original
Sheffy007:fix/multipage-vb-ib-blit-aliases → main · +439 −54 · 7 files · 1 commits · merged 2026-11-28 00:38 UTC

Summary

Fixes hardware stage-in vertex buffers, hardware index buffers, and buffer blits/indirect spans that cross 64 KiB title-page boundaries mapped in descending or non-contiguous pool order (#442, #258):

  1. Carry SizeInBytes on IASetVertexBuffers and IASetIndexBuffer and wrap non-linear mapped prefixes (list.rs, glue.rs, native/list.rs, native/memory.rs, native/host.rs):
    • glue::vertex_buffers and list::state::index_buffer now forward SizeInBytes (clearing index when address == 0 || size == 0).
    • PoolTable::resolve_prefix / NativeHost::resolve_span keep the fast linear pool-buffer path when all mapped pages of [addr, addr + size) follow linearly in one pool, and wrap the title's contiguous virtual pages via NativeHost::title_alias when the mapped prefix crosses descending or scattered pool pages (even when a reserved buffer's SizeInBytes extends past its mapped tail). This stops Metal's [[stage_in]] vertex fetcher and hardware index fetcher from reading past the first 64 KiB page into adjacent unrelated pool memory.
  2. Ignore stale IA bindings on draws that do not read them (native/host.rs):
    • prep resolves index only on DrawCall::Indexed and skips both vertex and index on DrawCall::Mesh, preventing stale IA bindings to later-unmapped pages from dropping non-indexed draws or mesh dispatches.
  3. Wrap gapless non-linear multi-page spans on blits and indirect records (native/host.rs):
    • Cmd::Copy, Cmd::Fill, Cmd::CopyBufferToTexture, Cmd::CopyTextureToBuffer, and ExecuteIndirect argument/count addresses use NativeHost::resolve_or_alias instead of dropping non-linear title ranges with NOT_MAPPED.
    • title_alias caches PoolTable::generation() alongside the mapping signature (avoiding repeated PoolTable walks across draws at the same generation) and separates the eviction limit into 1024 small wraps (< 16 MiB) and 64 large wraps (>= 16 MiB).

Verification

  • native::memory::tests::resolve_prefix_handles_linear_descending_and_partially_mapped_spans
  • native::tests::descending_pool_page_vertex_index_and_blit_spans_render_and_follow_remaps (Metal GPU quad draw straddling descending pool pages for both VB and IB with poisoned adjacent pool pages, page remap invalidation, reserved oversized SizeInBytes, stale unmapped IB on non-indexed draw, and descending-page Fill + Copy)
  • cargo test -j6 -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy -j6 --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy -j6 --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Closes #446
Refs #258
cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 19:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/443) `Sheffy007:fix/multipage-vb-ib-blit-aliases` → `main` · +439 −54 · 7 files · 1 commits · merged 2026-11-28 00:38 UTC ## Summary Fixes hardware stage-in vertex buffers, hardware index buffers, and buffer blits/indirect spans that cross 64 KiB title-page boundaries mapped in descending or non-contiguous pool order (`#442`, `#258`): 1. **Carry `SizeInBytes` on `IASetVertexBuffers` and `IASetIndexBuffer` and wrap non-linear mapped prefixes (`list.rs`, `glue.rs`, `native/list.rs`, `native/memory.rs`, `native/host.rs`):** - `glue::vertex_buffers` and `list::state::index_buffer` now forward `SizeInBytes` (clearing `index` when `address == 0 || size == 0`). - `PoolTable::resolve_prefix` / `NativeHost::resolve_span` keep the fast linear pool-buffer path when all mapped pages of `[addr, addr + size)` follow linearly in one pool, and wrap the title's contiguous virtual pages via `NativeHost::title_alias` when the mapped prefix crosses descending or scattered pool pages (even when a reserved buffer's `SizeInBytes` extends past its mapped tail). This stops Metal's `[[stage_in]]` vertex fetcher and hardware index fetcher from reading past the first 64 KiB page into adjacent unrelated pool memory. 2. **Ignore stale IA bindings on draws that do not read them (`native/host.rs`):** - `prep` resolves `index` only on `DrawCall::Indexed` and skips both `vertex` and `index` on `DrawCall::Mesh`, preventing stale IA bindings to later-unmapped pages from dropping non-indexed draws or mesh dispatches. 3. **Wrap gapless non-linear multi-page spans on blits and indirect records (`native/host.rs`):** - `Cmd::Copy`, `Cmd::Fill`, `Cmd::CopyBufferToTexture`, `Cmd::CopyTextureToBuffer`, and `ExecuteIndirect` argument/count addresses use `NativeHost::resolve_or_alias` instead of dropping non-linear title ranges with `NOT_MAPPED`. - `title_alias` caches `PoolTable::generation()` alongside the mapping signature (avoiding repeated `PoolTable` walks across draws at the same generation) and separates the eviction limit into `1024` small wraps (`< 16 MiB`) and `64` large wraps (`>= 16 MiB`). ## Verification - `native::memory::tests::resolve_prefix_handles_linear_descending_and_partially_mapped_spans` - `native::tests::descending_pool_page_vertex_index_and_blit_spans_render_and_follow_remaps` (Metal GPU quad draw straddling descending pool pages for both VB and IB with poisoned adjacent pool pages, page remap invalidation, reserved oversized `SizeInBytes`, stale unmapped IB on non-indexed draw, and descending-page `Fill` + `Copy`) - `cargo test -j6 -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - `cargo clippy -j6 --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy -j6 --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` Closes #446 Refs #258 cc @⁠Olima34
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:12:20 +00:00
Author
Owner

@⁠alexballvideos-netizen on GitHub · 2026-11-27 21:28 UTC · original

Tested this PR (4ff27ec0, on b998bb65) against main on an M3 Max, 36 GB, macOS 27.2.1, Series X, headless, 300 s, with VICTORY_DEPTH_TWINS=0 so the scene is lit enough to judge geometry. Dumps every 20 s from 110 s. Counts only.

main b998bb65 this PR
mesh draws, last counter line 4,138 7,347
GPU errors / OOM 0 / 0 0 / 0
end crash at about 270 s (the #460 0x2215c35 path) ran to the timer
scene F10 1280x720 lit=, peak 0.84 0.72
  • No regressions seen. It drew more meshes and ran the full 300 s (one run each).
  • The flying shards are still there in the lit frames at 150 s and 270 s: large flat sheets across the picture, plus black rectangular holes with straight edges. So the page wrap here isn't the cause of those, at least not the main one, on Series X.
  • One frame (210 s) was clean, with lights and some geometry, but those are night shots where shards would be hard to see anyway.
  • Caveat: world entry lands at a different second in each run, so the frames aren't identical shots.

The black holes are axis-aligned and look like blocks of the lit target left unwritten, rather than triangles. That's a guess, but it would point at a tiled lighting or classification pass that drops tiles, not at vertex fetch.

**@⁠alexballvideos-netizen** on GitHub · 2026-11-27 21:28 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/443#issuecomment-7228469706) Tested this PR (4ff27ec0, on b998bb65) against main on an M3 Max, 36 GB, macOS 27.2.1, Series X, headless, 300 s, with `VICTORY_DEPTH_TWINS=0` so the scene is lit enough to judge geometry. Dumps every 20 s from 110 s. Counts only. | | main b998bb65 | this PR | |---|---|---| | mesh draws, last counter line | 4,138 | **7,347** | | GPU errors / OOM | 0 / 0 | 0 / 0 | | end | crash at about 270 s (the #460 `0x2215c35` path) | ran to the timer | | scene F10 1280x720 `lit=`, peak | 0.84 | 0.72 | - **No regressions seen.** It drew more meshes and ran the full 300 s (one run each). - **The flying shards are still there** in the lit frames at 150 s and 270 s: large flat sheets across the picture, plus black rectangular holes with straight edges. So the page wrap here isn't the cause of those, at least not the main one, on Series X. - One frame (210 s) was clean, with lights and some geometry, but those are night shots where shards would be hard to see anyway. - Caveat: world entry lands at a different second in each run, so the frames aren't identical shots. The black holes are axis-aligned and look like blocks of the lit target left unwritten, rather than triangles. That's a guess, but it would point at a tiled lighting or classification pass that drops tiles, not at vertex fetch.
github-bot force-pushed github-bot/gh-443 from 4ff27ec09a to 014f943878 2026-11-27 23:55:19 +00:00 Compare
github-bot referenced this pull request from a commit 2026-11-28 00:29:35 +00:00
github manually merged commit d1d4dffb69 into main 2026-11-28 00:42:30 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.