metal: a refused pass keeps the submission's fence signals and barrier writes #78

Manually merged
github merged 3 commits from github-bot/gh-78 into main 2026-11-26 17:09:33 +00:00 AGit
Owner

@⁠AeroUp on GitHub · 2026-11-26 13:43 UTC · original
AeroUp:fix/refused-pass-keeps-signals → main · +133 −11 · 2 files · 3 commits · merged 2026-11-26 17:05 UTC

What

When a pass cannot be encoded, submit_passes returned before cb.commit(), so the whole submission vanished — including its encodeSignalEvent calls for the title's fences and the bottom-of-pipe value writes other queues wait on. title.rs then logged a piece of title work was refused and consumed the held item. The title's own crash log names the result: Unsignaled CrossQueueBarrier, followed by 0xc0000005 at image+0x55e56f8.

The command buffer now always commits: the failing pass is dropped, the signals and value writes go out, and the caller is still told which pass failed. Two related fixes in the same path:

  • a pass after a failed one still runs (one bad pass no longer empties the frame);
  • a draw pass with no render targets (0 colour [], depth None) is skipped as the no-op D3D12 makes of it, instead of being refused — Metal cannot create an encoder without an attachment.

Evidence

From a run that reaches the world load (Series S profile, 4K output; the process runs the game's x86_64 code, Metal backend native):

WARN victory_gpu::native::title: a piece of title work was refused error=no render encoder: 0 colour [], depth None, 1 draws
WARN victory_gpu::native::glue: work held for a wait that does not hold:
  ["fence 0x…: signal of 3 queued 4.8s ago, GPU at 2",
   "queue 0x…: 2 held, head for 5.6s, waits ["0x18437f9e8 cmp 7 ref 0x749 now Some(0)"]"]
… 0xc0000005 at image+0x55e56f8

and the title's crash log: Unsignaled CrossQueueBarrier.

Testing

  • cargo build --release --target x86_64-apple-darwin clean.
  • Ran the world load with it: the refused-piece and 20 s value-wait messages no longer appear before the transition; frames continue past the point where they used to stop. The 4K world still stalls for other reasons (being tracked separately).
  • The render-target list is now in the error, so a future no render encoder says which attachments Metal disliked.
**@⁠AeroUp** on GitHub · 2026-11-26 13:43 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78) `AeroUp:fix/refused-pass-keeps-signals` → `main` · +133 −11 · 2 files · 3 commits · merged 2026-11-26 17:05 UTC ## What When a pass cannot be encoded, `submit_passes` returned before `cb.commit()`, so the **whole submission** vanished — including its `encodeSignalEvent` calls for the title's fences and the bottom-of-pipe value writes other queues wait on. `title.rs` then logged `a piece of title work was refused` and consumed the held item. The title's own crash log names the result: **`Unsignaled CrossQueueBarrier`**, followed by `0xc0000005 at image+0x55e56f8`. The command buffer now always commits: the failing pass is dropped, the signals and value writes go out, and the caller is still told which pass failed. Two related fixes in the same path: - a pass after a failed one still runs (one bad pass no longer empties the frame); - a draw pass with **no render targets** (`0 colour [], depth None`) is skipped as the no-op D3D12 makes of it, instead of being refused — Metal cannot create an encoder without an attachment. ## Evidence From a run that reaches the world load (Series S profile, 4K output; the process runs the game's x86_64 code, Metal backend native): ``` WARN victory_gpu::native::title: a piece of title work was refused error=no render encoder: 0 colour [], depth None, 1 draws WARN victory_gpu::native::glue: work held for a wait that does not hold: ["fence 0x…: signal of 3 queued 4.8s ago, GPU at 2", "queue 0x…: 2 held, head for 5.6s, waits ["0x18437f9e8 cmp 7 ref 0x749 now Some(0)"]"] … 0xc0000005 at image+0x55e56f8 ``` and the title's crash log: `Unsignaled CrossQueueBarrier`. ## Testing - `cargo build --release --target x86_64-apple-darwin` clean. - Ran the world load with it: the refused-piece and 20 s value-wait messages no longer appear before the transition; frames continue past the point where they used to stop. The 4K world still stalls for other reasons (being tracked separately). - The render-target list is now in the error, so a future `no render encoder` says which attachments Metal disliked.
encode_* returning early left the command buffer uncommitted, so the whole
submission vanished: its fence signals and the bottom-of-pipe value writes
the title's other queues wait on. The title calls that
"Unsignaled CrossQueueBarrier" in its own crash log and then dies. The failing
pass is dropped, the command buffer still commits with the signals, and the
caller is told which pass failed. A pass after a failed one still runs, so one
bad pass does not cost the frame's whole picture, and a draw pass with no
render targets at all (Metal cannot make an encoder without an attachment) is
skipped as the no-op it is instead of being refused.

Seen with the world load: 'no render encoder: 0 colour [], depth None, 1
draws', two queues held >20 s on value waits, then 'Unsignaled
CrossQueueBarrier' and 0xc0000005.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:45:24 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 14:54 UTC · original · requested changes

Thanks, the direction is right, but there's a crash risk: in crates/victory-metal/src/gfx.rs (~1222) the "indexed draw without an index buffer" ? returns from encode_render with the render encoder still open, and the patch now keeps encoding later passes and commits that command buffer, which Metal asserts on. Please call endEncoding on that path and add a test where a pass is refused but its fence signals still land.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 14:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#pullrequestreview-6076253159) · **requested changes** Thanks, the direction is right, but there's a crash risk: in crates/victory-metal/src/gfx.rs (~1222) the "indexed draw without an index buffer" `?` returns from encode_render with the render encoder still open, and the patch now keeps encoding later passes and commits that command buffer, which Metal asserts on. Please call endEncoding on that path and add a test where a pass is refused but its fence signals still land.
A draw that names no index buffer returned from encode_render with the render encoder
still open; since a refused pass now still commits (for its fence signals and value
writes), Metal would assert on the open encoder. That draw is dropped instead.

Attachments of different size or sample count are refused rather than rendered to the
intersection (Metal's silent behaviour hides a title or decoder bug behind a cropped
picture), and that refusal is now what the new test builds: a pass with a mismatched
depth attachment is refused, its fence signal still lands, and the pass after it draws.
Author
Owner

@⁠AeroUp on GitHub · 2026-11-26 16:16 UTC · original

Both points are fixed in the branch (force-pushed):

  • The indexed-draw-without-an-index-buffer path no longer returns from encode_render with the encoder open: that draw is dropped (continue) and logged once, so nothing can reach commit with a live encoder.
  • Added a_refused_pass_keeps_its_fence_signal_and_the_passes_after_it in crates/victory-metal/tests/render.rs. A pass with a depth attachment of another size than the colour one is refused (new: attachments of different size or sample count are refused instead of Metal rendering to the intersection), its fence signal still lands, and the pass after it draws into the target — cargo test -p victory-metal --test render is 4 passed.

The mismatch check doubles as the deterministic refusal the test needs: Metal's encoder creation does not fail for bad attachment formats with validation off.

**@⁠AeroUp** on GitHub · 2026-11-26 16:16 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#issuecomment-7197423189) Both points are fixed in the branch (force-pushed): - The indexed-draw-without-an-index-buffer path no longer returns from `encode_render` with the encoder open: that draw is dropped (`continue`) and logged once, so nothing can reach `commit` with a live encoder. - Added `a_refused_pass_keeps_its_fence_signal_and_the_passes_after_it` in `crates/victory-metal/tests/render.rs`. A pass with a depth attachment of another size than the colour one is refused (new: attachments of different size or sample count are refused instead of Metal rendering to the intersection), its fence signal still lands, and the pass after it draws into the target — `cargo test -p victory-metal --test render` is 4 passed. The mismatch check doubles as the deterministic refusal the test needs: Metal's encoder creation does not fail for bad attachment formats with validation off.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:37 UTC · original · approved these changes

The encoder-open path is closed, attachment mismatches are refused up front, and the new test shows a refused pass still lands its fence signal and the next pass draws. Merged onto main, victory-metal and the native tests pass, clippy and policy are clean, CI is green.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#pullrequestreview-6077667287) · **approved these changes** The encoder-open path is closed, attachment mismatches are refused up front, and the new test shows a refused pass still lands its fence signal and the next pass draws. Merged onto main, victory-metal and the native tests pass, clippy and policy are clean, CI is green.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:38 UTC · original

Approved. The branch is behind main (no conflicts, but main requires it up to date). Please merge main into the branch and I will merge it right after.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:38 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#issuecomment-7197917951) Approved. The branch is behind main (no conflicts, but main requires it up to date). Please merge main into the branch and I will merge it right after.
Author
Owner

@⁠AeroUp on GitHub · 2026-11-26 16:48 UTC · original

Merged upstream/main into the branch (clean, 29 files) and re-ran the render test on x86_64-apple-darwin: 4 passed, including a_refused_pass_keeps_its_fence_signal_and_the_passes_after_it.

**@⁠AeroUp** on GitHub · 2026-11-26 16:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#issuecomment-7198112779) Merged `upstream/main` into the branch (clean, 29 files) and re-ran the render test on `x86_64-apple-darwin`: 4 passed, including `a_refused_pass_keeps_its_fence_signal_and_the_passes_after_it`.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 16:58 UTC · original · approved these changes

Rechecked on the updated head: victory-metal and native tests, windows clippy and policy are clean, CI is green.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 16:58 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/78#pullrequestreview-6077955887) · **approved these changes** Rechecked on the updated head: victory-metal and native tests, windows clippy and policy are clean, CI is green.
github manually merged commit 7108e796cc into main 2026-11-26 17:09:33 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.