gpu(native): stage-in vertex buffers, index buffers, and blits resolve only the first pool page instead of wrapping non-linear title pages #446

Closed
opened 2026-11-27 18:54:46 +00:00 by github-bot · 2 comments
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 18:52 UTC · original

Problem

In #258 (and docs/native-host.md, World geometry drawn as shards / Loads whose dwords cross a title page), the title allocates vertex and index buffers across 64 KiB virtual pages mapped in descending or non-contiguous pool order.

While shader-fetched root views can look up each page in the page table, hardware vertex/index fetches and buffer blits on the native host still assume a single contiguous pool run from the first byte:

  1. IASetVertexBuffers (glue::vertex_buffers) and IASetIndexBuffer (list::state::index_buffer) discard SizeInBytes and call self.resolve(addr, 1) (host.rs:2486-2492):
    • self.resolve(addr, 1) checks only byte 0 and binds (pool_buffer, pool.base + m.offset + (addr - at)) to Metal's [[stage_in]] vertex slots and hardware index fetcher (drawIndexedPrimitives / indirect DrawIndexed).
    • Whenever a stage-in vertex buffer (graphics::VERTEX_TABLE) or hardware index buffer crosses a 64 KiB title page boundary into a page mapped elsewhere in the pool (e.g. descending pool order), Metal reads linearly past m.offset + 0x1_0000 into unrelated physical pool pages:
      • Stage-in vertices past 64 KiB read garbage positions -> flying shards, fence panels, and rays across the lit scene.
      • Triangle indices past 64 KiB (affecting both stage-in and root-SRV vertex pipelines) read arbitrary 16-bit/32-bit pool bytes -> random vertices stitched into shards and valid triangles dropped on characters, clothing, and world meshes.
  2. Stale IA bindings resolved on draws that do not read them (host.rs:2486-2492):
    • p.index is resolved even for non-indexed draws (DrawCall::Arrays, DrawCall::Rects), and both p.vertex and p.index are resolved on DrawCall::Mesh. If an earlier draw left an IA buffer bound whose pages were later unmapped, resolving it drops subsequent non-indexed draws or mesh dispatches with NOT_MAPPED. Also, an IASetIndexBuffer view with address == 0 || size == 0 records address 0 instead of clearing the binding.
  3. Cmd::Copy, Cmd::Fill, Cmd::CopyBufferToTexture, Cmd::CopyTextureToBuffer, and indirect spans drop work over non-linear title mappings (host.rs:2401, 2445, 2494-2504):
    • self.resolve(addr, len) requires [addr, addr + len) to lie in one linear physical run of a single pool, dropping copies/fills/uploads over gapless descending or multi-pool title ranges with title address ... is not in a mapped pool instead of wrapping the title's contiguous virtual pages via title_alias.
  4. Repeated title_alias lookups re-walk PoolTable and cap total wraps at 64:
    • Caching PoolTable::generation() alongside signature avoids re-locking/walking PoolTable::maps on every draw that shares a multi-page VB/IB within the same pool generation, and keeping a separate cap for small wraps (< 16 MiB) prevents churning MTLBuffer no-copy wrappers across draws while keeping large wraps (>= 16 MiB) bounded at 64.

Refs #258

**@⁠Sheffy007** on GitHub · 2026-11-27 18:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442) ## Problem In `#258` (and `docs/native-host.md`, *World geometry drawn as shards* / *Loads whose dwords cross a title page*), the title allocates vertex and index buffers across 64 KiB virtual pages mapped in **descending or non-contiguous pool order**. While shader-fetched root views can look up each page in the page table, hardware vertex/index fetches and buffer blits on the native host still assume a single contiguous pool run from the first byte: 1. **`IASetVertexBuffers` (`glue::vertex_buffers`) and `IASetIndexBuffer` (`list::state::index_buffer`) discard `SizeInBytes` and call `self.resolve(addr, 1)` (`host.rs:2486-2492`):** - `self.resolve(addr, 1)` checks only byte `0` and binds `(pool_buffer, pool.base + m.offset + (addr - at))` to Metal's `[[stage_in]]` vertex slots and hardware index fetcher (`drawIndexedPrimitives` / indirect `DrawIndexed`). - Whenever a stage-in vertex buffer (`graphics::VERTEX_TABLE`) or hardware index buffer crosses a 64 KiB title page boundary into a page mapped elsewhere in the pool (e.g. descending pool order), Metal reads linearly past `m.offset + 0x1_0000` into unrelated physical pool pages: - Stage-in vertices past 64 KiB read garbage positions -> flying shards, fence panels, and rays across the lit scene. - Triangle indices past 64 KiB (affecting **both** stage-in and root-SRV vertex pipelines) read arbitrary 16-bit/32-bit pool bytes -> random vertices stitched into shards and valid triangles dropped on characters, clothing, and world meshes. 2. **Stale IA bindings resolved on draws that do not read them (`host.rs:2486-2492`):** - `p.index` is resolved even for non-indexed draws (`DrawCall::Arrays`, `DrawCall::Rects`), and both `p.vertex` and `p.index` are resolved on `DrawCall::Mesh`. If an earlier draw left an IA buffer bound whose pages were later unmapped, resolving it drops subsequent non-indexed draws or mesh dispatches with `NOT_MAPPED`. Also, an `IASetIndexBuffer` view with `address == 0 || size == 0` records address `0` instead of clearing the binding. 3. **`Cmd::Copy`, `Cmd::Fill`, `Cmd::CopyBufferToTexture`, `Cmd::CopyTextureToBuffer`, and `indirect` spans drop work over non-linear title mappings (`host.rs:2401, 2445, 2494-2504`):** - `self.resolve(addr, len)` requires `[addr, addr + len)` to lie in one linear physical run of a single pool, dropping copies/fills/uploads over gapless descending or multi-pool title ranges with `title address ... is not in a mapped pool` instead of wrapping the title's contiguous virtual pages via `title_alias`. 4. **Repeated `title_alias` lookups re-walk `PoolTable` and cap total wraps at `64`:** - Caching `PoolTable::generation()` alongside `signature` avoids re-locking/walking `PoolTable::maps` on every draw that shares a multi-page VB/IB within the same pool generation, and keeping a separate cap for small wraps (`< 16 MiB`) prevents churning `MTLBuffer` no-copy wrappers across draws while keeping large wraps (`>= 16 MiB`) bounded at `64`. Refs #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:54:46 +00:00
Author
Owner

@⁠Sheffy007 on GitHub · 2026-11-27 18:52 UTC · original

/claim

**@⁠Sheffy007** on GitHub · 2026-11-27 18:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442#issuecomment-7225968020) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 18:53 UTC · original

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

**@⁠github-actions[bot]** on GitHub · 2026-11-27 18:53 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442#issuecomment-7225970726) Claimed by @⁠Sheffy007. Open a draft pull request with `Refs #442` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.