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

Closed
opened 2026-11-27 18:52:57 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 18:52:57 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T18:52:57Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6652740242 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T18:52:57Z. --- ## 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 commented 2026-11-27 18:52:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T18:52:59Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7225968020 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442#issuecomment-7225968020). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T18:52:59Z. --- /claim
github-actions[bot] commented 2026-11-27 18:53:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T18:53:09Z.


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7225970726 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/442#issuecomment-7225970726). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T18:53:09Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #442` in its description within 24 hours, or the claim expires.
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#442
No description provided.