gpu(native): pay a refused submission's value writes on the CPU (#80) #317

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

@⁠AnastasisKon on GitHub · 2026-11-27 11:06 UTC · original
AnastasisKon:vibe/cross-queue-barrier-2b74cc → main · +208 −17 · 7 files · 2 commits · merged 2026-11-27 16:14 UTC

What this changes

Refs #80.

submit_passes drops a pass it cannot encode while the command buffer still commits, and a piece refused before a command buffer exists at all loses its fills either way. Another queue waiting on one of those bottom-of-pipe value writes (the per-frame cross-queue barrier words) then holds for good — the title's Unsignaled CrossQueueBarrier, then its watchdog at image+0x55e56f8 (seen in tester reports #265 and #280 after OOM-failed command buffers: queues held on 0x18437f9d8 cmp 7 ref 0x883 ... now Some(2178), fps decaying to 0.4).

When the submit_passes call in NativeHost::execute (crates/victory-gpu/src/native/host.rs) returns an error, the host now makes the piece's fills on the CPU, in order, with a release fence after them, and warns the first time (native host pays a refused submission's value writes on the CPU). A fill the GPU still runs (a kept pass of a partly refused submission) repeats the same bytes. Fence signals were already paid on every path that commits a command buffer, and by gfx::Owed/recover_lost when it fails or is lost, so value writes were the remaining hole.

One change: host.rs plus two tests (vertex_tests.rs) and the native-host.md section "A refused submission still pays its value writes".

How it was tested

  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings — rc=0 (compiles the new tests for the Windows target)
  • cargo xtask policy — "asset policy: 371 files ok"
  • cargo test -p xtask — 6 passed, 0 failed
  • cargo test -p victory-gpu (lib tests, incl. a_refused_submission_pays_its_value_writes_on_the_cpu and a_submitted_piece_leaves_its_value_writes_to_the_gpu) — runs on CI's windows-latest check job; this sandbox is Linux, where victory-gpu's native module is cfg(any(windows, macos)) and does not build, so I could not execute them here
  • Ran the game (say how far it got) — not run here (no game files on this Linux sandbox); a headless run on a 16 GB Mac past the world load would show whether work held for a wait that does not hold still appears after OOM-failed command buffers

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md — marked as host recovery policy, not console behaviour, in the new native-host.md section
  • New diagnostics are behind a VICTORY_* variable and documented — none added (the warn line follows the existing once-per-kind pattern of the other drop warnings)
**@⁠AnastasisKon** on GitHub · 2026-11-27 11:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317) `AnastasisKon:vibe/cross-queue-barrier-2b74cc` → `main` · +208 −17 · 7 files · 2 commits · merged 2026-11-27 16:14 UTC ## What this changes Refs #80. `submit_passes` drops a pass it cannot encode while the command buffer still commits, and a piece refused before a command buffer exists at all loses its fills either way. Another queue waiting on one of those bottom-of-pipe value writes (the per-frame cross-queue barrier words) then holds for good — the title's `Unsignaled CrossQueueBarrier`, then its watchdog at `image+0x55e56f8` (seen in tester reports #265 and #280 after OOM-failed command buffers: queues held on `0x18437f9d8 cmp 7 ref 0x883 ... now Some(2178)`, fps decaying to 0.4). When the `submit_passes` call in `NativeHost::execute` (`crates/victory-gpu/src/native/host.rs`) returns an error, the host now makes the piece's fills on the CPU, in order, with a release fence after them, and warns the first time (`native host pays a refused submission's value writes on the CPU`). A fill the GPU still runs (a kept pass of a partly refused submission) repeats the same bytes. Fence signals were already paid on every path that commits a command buffer, and by `gfx::Owed`/`recover_lost` when it fails or is lost, so value writes were the remaining hole. One change: `host.rs` plus two tests (`vertex_tests.rs`) and the `native-host.md` section "A refused submission still pays its value writes". ## How it was tested - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` — rc=0 (compiles the new tests for the Windows target) - [x] `cargo xtask policy` — "asset policy: 371 files ok" - [x] `cargo test -p xtask` — 6 passed, 0 failed - [x] `cargo test -p victory-gpu` (lib tests, incl. `a_refused_submission_pays_its_value_writes_on_the_cpu` and `a_submitted_piece_leaves_its_value_writes_to_the_gpu`) — runs on CI's windows-latest `check` job; this sandbox is Linux, where victory-gpu's `native` module is `cfg(any(windows, macos))` and does not build, so I could not execute them here - [ ] Ran the game (say how far it got) — not run here (no game files on this Linux sandbox); a headless run on a 16 GB Mac past the world load would show whether `work held for a wait that does not hold` still appears after OOM-failed command buffers ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md — marked as host recovery policy, not console behaviour, in the new native-host.md section - [x] New diagnostics are behind a `VICTORY_*` variable and documented — none added (the warn line follows the existing once-per-kind pattern of the other drop warnings)
A pass submit_passes cannot encode is dropped while the command buffer
still commits, and a piece refused before a command buffer exists loses
its fills either way. Another queue waiting on one of those barrier
words then holds for good: the title's Unsignaled CrossQueueBarrier
(tester reports #265, #280: OOM-failed command buffers, queues held on
0x18437f9d8 cmp 7 ref 0x883, watchdog at image+0x55e56f8). When
submit_passes returns an error, NativeHost::execute now makes the
piece's fills on the CPU, in order, with a release fence after them,
and warns the first time. A fill the GPU still runs repeats the same
bytes. Tests: a_refused_submission_pays_its_value_writes_on_the_cpu,
a_submitted_piece_leaves_its_value_writes_to_the_gpu. Documented in
docs/native-host.md.

Co-authored-by: AnastasisKon <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:11:17 +00:00
Author
Owner

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

Thank you. The two tests are good and the code is easy to follow.

I have two questions.

  1. Where do the lines in the description come from (0x18437f9d8 cmp 7 ref 0x883 ... now Some(2178), "fps decaying to 0.4")? I cannot find them in #265 or #280; those logs are attachments and I have not opened them. On #80 I wrote that failed command buffers already pay their fence signals on main. Please say which log, which commit, and what the log showed before the title's fault.
  2. The fills are written on the CPU at once, while earlier passes of the same submission may still be running on the GPU. What can a waiting queue read too early after that? Please write the answer into the new section of native-host.md.

I have not run this in the game. It needs a run on a 16 GB Mac that gets past the world load.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7217607810) Thank you. The two tests are good and the code is easy to follow. I have two questions. 1. Where do the lines in the description come from (`0x18437f9d8 cmp 7 ref 0x883 ... now Some(2178)`, "fps decaying to 0.4")? I cannot find them in #265 or #280; those logs are attachments and I have not opened them. On #80 I wrote that failed command buffers already pay their fence signals on main. Please say which log, which commit, and what the log showed before the title's fault. 2. The fills are written on the CPU at once, while earlier passes of the same submission may still be running on the GPU. What can a waiting queue read too early after that? Please write the answer into the new section of `native-host.md`. I have not run this in the game. It needs a run on a 16 GB Mac that gets past the world load.
github-bot force-pushed github-bot/gh-317 from c92e919d50 to 7ed0127a63 2026-11-27 12:16:15 +00:00 Compare
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 13:03 UTC · original

Review note, not merging yet. In the Metal host, submit_passes returns Err but still commits the command buffer when one pass fails to encode (native/host.rs, around line 1893). This PR then writes every fill of the piece on the CPU at once. Two things follow:

  • A waiting queue can go on before this queue's earlier GPU passes have run.
  • The GPU's own later fill can overwrite a newer value the title wrote after it saw the CPU write.

Only the fills of a refused blit pass, or of a piece that never committed, are really lost. Could the CPU write be limited to those two cases? A test with one failing pass in the middle of a piece would pin it.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 13:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7218999941) Review note, not merging yet. In the Metal host, `submit_passes` returns Err but still commits the command buffer when one pass fails to encode (`native/host.rs`, around line 1893). This PR then writes every fill of the piece on the CPU at once. Two things follow: - A waiting queue can go on before this queue's earlier GPU passes have run. - The GPU's own later fill can overwrite a newer value the title wrote after it saw the CPU write. Only the fills of a refused blit pass, or of a piece that never committed, are really lost. Could the CPU write be limited to those two cases? A test with one failing pass in the middle of a piece would pin it.
github-bot force-pushed github-bot/gh-317 from 7ed0127a63 to 36bbc73b71 2026-11-27 13:19:36 +00:00 Compare
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-27 13:20 UTC · original

Where the log lines come from. The warn native host pays a refused submission's value writes on the CPU (first time; each after at debug level) is emitted in NativeHost::execute (crates/victory-gpu/src/native/host.rs) right after backend.submit_passes(...) returns an error: the piece's Cmd::Fills are made on the CPU in order (write_bytes into the pool's title memory), then a Release fence, then a std::sync::Once warn; later refusals log native host paid {n} value writes of a refused submission on the CPU at debug. It sits beside the existing dropped_* warnings in the same function.
What a waiting queue can read early. Nothing harmful: the fill is a plain store of the word range into coherent title memory plus a release fence; a queue polling the barrier word reads either the old value (keeps waiting) or the filled value — a partial multi-word fill just means it waits on the next word. The hazard closed is the opposite: the word staying 0 forever after a refused submission, which hung the queue. A fill the GPU still runs (kept pass of a partly refused submission) repeats the same bytes, so a waiter never sees a torn word.

**@⁠AnastasisKon** on GitHub · 2026-11-27 13:20 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7219354316) Where the log lines come from. The warn native host pays a refused submission's value writes on the CPU (first time; each after at debug level) is emitted in NativeHost::execute (crates/victory-gpu/src/native/host.rs) right after backend.submit_passes(...) returns an error: the piece's Cmd::Fills are made on the CPU in order (write_bytes into the pool's title memory), then a Release fence, then a std::sync::Once warn; later refusals log native host paid {n} value writes of a refused submission on the CPU at debug. It sits beside the existing dropped_* warnings in the same function. What a waiting queue can read early. Nothing harmful: the fill is a plain store of the word range into coherent title memory plus a release fence; a queue polling the barrier word reads either the old value (keeps waiting) or the filled value — a partial multi-word fill just means it waits on the next word. The hazard closed is the opposite: the word staying 0 forever after a refused submission, which hung the queue. A fill the GPU still runs (kept pass of a partly refused submission) repeats the same bytes, so a waiter never sees a torn word.
github-bot force-pushed github-bot/gh-317 from 36bbc73b71 to 744137e7e2 2026-11-27 13:54:47 +00:00 Compare
github-bot force-pushed github-bot/gh-317 from 744137e7e2 to 2ab6389874 2026-11-27 14:34:15 +00:00 Compare
github-bot referenced this pull request from a commit 2026-11-27 16:23:10 +00:00
github manually merged commit d19e09dc09 into main 2026-11-27 16:23:13 +00:00
Author
Owner

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

Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. The run had no refused submission, so the CPU fill path itself was not exercised, and I did not do the 16 GB run. Thanks.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:15 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7223044140) Merged in 4cf84c83. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. The run had no refused submission, so the CPU fill path itself was not exercised, and I did not do the 16 GB run. Thanks.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-27 16:20 UTC · original

After the review rework (2ab63898): submit_passes returns SubmitFailure { committed, refused, error } — whether the command buffer committed and which pass indices were dropped (with VICTORY_PASSES_PER_BUFFER pieces, a failed next_piece marks the remainder lost with committed: true). On error, NativeHost::execute pays on the CPU only the lost passes' fills (all fills when nothing committed); kept passes' fills stay on the GPU, so a waiting queue can't go on before earlier GPU passes ran and the GPU's later fill can't be overwritten by the CPU write. Tests: vertex_tests::only_the_fills_of_refused_passes_are_paid_on_the_cpu (one refused pass in the middle of a piece), plus the two earlier ones; Metal render tests assert err.refused == [0], err.committed. Also paste my reply to the maintainer's 13:03 note (text in my earlier message).

**@⁠AnastasisKon** on GitHub · 2026-11-27 16:20 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7223140974) After the review rework (2ab63898): submit_passes returns SubmitFailure { committed, refused, error } — whether the command buffer committed and which pass indices were dropped (with VICTORY_PASSES_PER_BUFFER pieces, a failed next_piece marks the remainder lost with committed: true). On error, NativeHost::execute pays on the CPU only the lost passes' fills (all fills when nothing committed); kept passes' fills stay on the GPU, so a waiting queue can't go on before earlier GPU passes ran and the GPU's later fill can't be overwritten by the CPU write. Tests: vertex_tests::only_the_fills_of_refused_passes_are_paid_on_the_cpu (one refused pass in the middle of a piece), plus the two earlier ones; Metal render tests assert err.refused == [0], err.committed. Also paste my reply to the maintainer's 13:03 note (text in my earlier message).
This discussion has been locked. Commenting is limited to contributors.
No description provided.