metal: an indirect dispatch or mesh dispatch of more than 2^22 groups runs nothing (#79) #386

Manually merged
github merged 2 commits from github-bot/gh-383 into main 2026-11-27 16:23:13 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 15:33 UTC · original
Olima34:fix/indirect-group-limit → main · +0 −0 · 0 files · 2 commits · closed without merging

Refs #79. Tarraga's claim there covers splitting submissions into pieces; this is a different cause.

What stops world runs here. On an M5 Pro 48 GB, Series S, headless, main 905e7aad, all 5 of 5 runs stopped between +110 and +190 s.

  • A wait, not long work. Each kIOGPUCommandBufferCallbackErrorTimeout is a wait. The kernel logs (IOGPUFamily) Cmd queue … sleep port_name … value: v timed out! 5 s after the stall, and v is the value our encodeWaitForEvent waits for (the queue's order event, or a piece event with VICTORY_PASSES_PER_BUFFER). The failed command buffer is the one behind a command buffer that never ends.
  • Not memory: 48–50% was free, with no swap.

What never ends. An ExecuteIndirect dispatch whose record the GPU read as [510, 1182027346, 1314076063] (compute 0af6bb55602abf70).

  • Its writer is refused. Compute eee76bf6265f33bb stores [0, 1, 1] into 25 dispatch records, but it is dropped: "a cross-lane operation between host waves in divergent code".
  • So the records keep whatever was there. Most frames they stay [n, 0, 0], so the ray-traced passes never run. When the memory is reused, they hold leftovers.

Change. Every indirect dispatch and indirect mesh dispatch goes through the Metal gate. A record of more than 2^22 groups in all runs nothing, and the first cases are logged. The limit is on the product of the counts, not 65,535 per dimension: other ports report the title asking for more than that in x on larger targets (not measured here).

Runs with the limit: 5 of 6 had no GPU error (170–300 s). One stopped at +126 s with every dispatch count sane; mesh dispatches weren't gated in that run, and its cause isn't found yet. VICTORY_PASSES_PER_BUFFER=1 doesn't protect against a pass that never ends (3 runs).

Traces, behind existing switches:

  • VICTORY_TRACE_GPU_FAILS: pieces, the record at encode time, and the counts the GPU read;
  • VICTORY_TRACE_DISPATCH_FLAGS: the first three indirect dispatches of each pipeline;
  • VICTORY_TRACE_RECORD_WRITERS=<hashes>: dispatch records.

Tests:

  • victory-metal an_indirect_dispatch_past_the_most_groups_runs_nothing and victory-gpu an_indirect_mesh_dispatch_past_the_most_groups_draws_nothing. Both fail without the change.
  • Three tests of buffer_atomic_cmpswap, which had none. They pass before and after.

Checks: victory-hle, victory, victory-gpu, xtask and victory-metal tests pass (arm64). Windows clippy is clean with -D warnings, and cargo xtask policy passes (385 files).

Also measured: each command buffer that attaches the heaps' residency sets costs about 0.35 s of kernel time (the slow lines under VICTORY_TRACE_GPU_FAILS). That's about the world's 1.3 fps.

Not in this PR: the Windows D3D12 host has no such limit. The real fix for those passes is translating eee76bf6265f33bb.

@⁠LakshanSivakumar, this is ours, so it needs your approval and merge.

**@⁠Olima34** on GitHub · 2026-11-27 15:33 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383) `Olima34:fix/indirect-group-limit` → `main` · +0 −0 · 0 files · 2 commits · closed without merging Refs #79. Tarraga's claim there covers splitting submissions into pieces; this is a different cause. **What stops world runs here.** On an M5 Pro 48 GB, Series S, headless, main 905e7aad, all 5 of 5 runs stopped between +110 and +190 s. - **A wait, not long work.** Each `kIOGPUCommandBufferCallbackErrorTimeout` is a wait. The kernel logs `(IOGPUFamily) Cmd queue … sleep port_name … value: v timed out!` 5 s after the stall, and `v` is the value our `encodeWaitForEvent` waits for (the queue's order event, or a piece event with `VICTORY_PASSES_PER_BUFFER`). The failed command buffer is the one *behind* a command buffer that never ends. - **Not memory:** 48–50% was free, with no swap. **What never ends.** An ExecuteIndirect dispatch whose record the GPU read as **[510, 1182027346, 1314076063]** (compute `0af6bb55602abf70`). - **Its writer is refused.** Compute `eee76bf6265f33bb` stores [0, 1, 1] into 25 dispatch records, but it is dropped: "a cross-lane operation between host waves in divergent code". - **So the records keep whatever was there.** Most frames they stay [n, 0, 0], so the ray-traced passes never run. When the memory is reused, they hold leftovers. **Change.** Every indirect dispatch and indirect mesh dispatch goes through the Metal gate. A record of more than 2^22 groups in all runs nothing, and the first cases are logged. The limit is on the product of the counts, not 65,535 per dimension: other ports report the title asking for more than that in x on larger targets (not measured here). **Runs with the limit:** 5 of 6 had no GPU error (170–300 s). One stopped at +126 s with every dispatch count sane; mesh dispatches weren't gated in that run, and its cause isn't found yet. `VICTORY_PASSES_PER_BUFFER=1` doesn't protect against a pass that never ends (3 runs). **Traces, behind existing switches:** - `VICTORY_TRACE_GPU_FAILS`: pieces, the record at encode time, and the counts the GPU read; - `VICTORY_TRACE_DISPATCH_FLAGS`: the first three indirect dispatches of each pipeline; - `VICTORY_TRACE_RECORD_WRITERS=<hashes>`: dispatch records. **Tests:** - victory-metal `an_indirect_dispatch_past_the_most_groups_runs_nothing` and victory-gpu `an_indirect_mesh_dispatch_past_the_most_groups_draws_nothing`. Both fail without the change. - Three tests of `buffer_atomic_cmpswap`, which had none. They pass before and after. **Checks:** victory-hle, victory, victory-gpu, xtask and victory-metal tests pass (arm64). Windows clippy is clean with `-D warnings`, and `cargo xtask policy` passes (385 files). **Also measured:** each command buffer that attaches the heaps' residency sets costs about 0.35 s of kernel time (the `slow` lines under `VICTORY_TRACE_GPU_FAILS`). That's about the world's 1.3 fps. **Not in this PR:** the Windows D3D12 host has no such limit. The real fix for those passes is translating `eee76bf6265f33bb`. @⁠LakshanSivakumar, this is ours, so it needs your approval and merge.
Metal runs whatever counts an indirect buffer holds. In a world run the record of
a plain dispatch (compute 0af6bb55602abf70) held [510, 1182027346, 1314076063]
when the GPU read it: that command buffer never ended, and every command buffer
behind it on its queue failed with kIOGPUCommandBufferCallbackErrorTimeout. This
is the stop that ended world runs after two to four minutes on an M5 Pro (5 runs
of 5 on main 905e7aad; 5 of 6 without a GPU error with the limit).

Every indirect dispatch and indirect mesh dispatch now goes through the gate,
which runs nothing for a record of more than 2^22 groups in all. The limit is on
the product, not D3D12's 65,535 a dimension: the title asks for more than that
in x on larger targets.

The records hold leftovers because their writer is refused: compute
eee76bf6265f33bb stores [0, 1, 1] in 25 dispatch records and is dropped
("a cross-lane operation between host waves in divergent code"). Not fixed here.

Traces, all behind existing switches:
- VICTORY_TRACE_GPU_FAILS: each piece of a split submission is traced under its
  own passes (slow, failed, in flight), an indirect dispatch's label shows its
  record at encode time, and the lines end with the counts the GPU read.
- VICTORY_TRACE_DISPATCH_FLAGS: the first three indirect dispatches of each
  pipeline, with the record's address and words.
- VICTORY_TRACE_RECORD_WRITERS=<hashes>: watches those shaders' dispatch records.

docs/native-host.md: what a GPU time-out is (a 5 s wait behind a command buffer
that never ends, per the kernel log), and the limit.

Tests: an_indirect_dispatch_past_the_most_groups_runs_nothing (victory-metal),
an_indirect_mesh_dispatch_past_the_most_groups_draws_nothing (victory-gpu), and
three of buffer_atomic_cmpswap, which had none.
# Conflicts:
#	docs/native-host.md
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 15:45:56 +00:00
github manually merged commit 885d142576 into main 2026-11-27 16:23:13 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 16:15 UTC · original

The guard (f2b476da) is on main as part of 4cf84c83, merged with the maintainer's push. After merging main, this branch has no remaining difference, so I'm closing it. Thanks!

**@⁠Olima34** on GitHub · 2026-11-27 16:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383#issuecomment-7223038757) The guard (f2b476da) is on main as part of 4cf84c83, merged with the maintainer's push. After merging main, this branch has no remaining difference, so I'm closing it. Thanks!
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:15 UTC · original

Merged in 4cf84c83 (your commit f2b476da is on main; the later head only merges main in, so nothing else is left). Tests, Windows clippy, policy and a release build passed, and a 170 s headless game run of that tree entered the world and kept presenting to the end with 0 GPU errors. Closing since it is fully on main. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383#issuecomment-7223048270) Merged in 4cf84c83 (your commit f2b476da is on main; the later head only merges main in, so nothing else is left). Tests, Windows clippy, policy and a release build passed, and a 170 s headless game run of that tree entered the world and kept presenting to the end with 0 GPU errors. Closing since it is fully on main. Thanks.
This discussion has been locked. Commenting is limited to contributors.
No description provided.