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

Merged
AnastasisKon merged 2 commits from upstream-pr/317 into main 2026-11-27 16:14:20 +00:00
AnastasisKon commented 2026-11-27 11:06:51 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T11:06:51Z.


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)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5525583311 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T11:06:51Z. --- ## 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)
LakshanSivakumar commented 2026-11-27 11:54:12 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:12Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217607810 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7217607810). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:12Z. --- 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 commented 2026-11-27 13:03:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T13:03:17Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218999941 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7218999941). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T13:03:17Z. --- 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.
AnastasisKon commented 2026-11-27 13:20:17 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T13:20:17Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219354316 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7219354316). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T13:20:17Z. --- 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.
LakshanSivakumar commented 2026-11-27 16:15:26 +00:00 (Migrated from github.com)

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


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.

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

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T16:20:18Z.


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).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223140974 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/317#issuecomment-7223140974). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T16:20:18Z. --- 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).
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!317
No description provided.