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

Closed
Olima34 wants to merge 2 commits from upstream-pr/383 into main
Olima34 commented 2026-11-27 15:33:43 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T15:33:43Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5529207939 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T15:33:43Z. --- 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 commented 2026-11-27 16:15:10 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T16:15:10Z.


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!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223038757 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383#issuecomment-7223038757). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T16:15:10Z. --- 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!
LakshanSivakumar commented 2026-11-27 16:15:37 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:37Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223048270 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/383#issuecomment-7223048270). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:15:37Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
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!383
No description provided.