gpu(native): avoid unsignalled Metal waits and preserve presentation order #60
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/60"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T11:42:45Z.
A queue wait whose CPU signal arrives more than about five seconds later can time out on Metal, dropping subsequent work and fence signals. Hold waits on the CPU unless a signal reaching the requested value is already submitted to the GPU; already-completed waits need no GPU command.
Track submitted signal values per fence and release CPU-held work through the existing pump. Preserve presentation ordering by putting deferred presents in the same FIFO as fence signals, retaining their queue, surface, and texture until submission. This also prevents presents from overtaking memory-held rendering. Deferred present errors are logged.
Validation:
Refs #2. This fixes a demonstrated timeout mechanism, not a confirmed cause of the reported 53-second stall. A previously submitted signal can still be delayed behind long-running GPU work; that timeout case remains. CPU-held waits release through the approximately 1 ms pump.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:50Z.
Review: CHANGES_REQUESTED
The per-queue FIFO fixes the render → present → signal submission order. Before landing:
native/title.rs~353/364). A high-water mark recorded at commit survives an asynchronous failure, so later waits can take the same path.title.rs~367/272/397). Right now releasing the fence makes the lookup returnu64::MAXand satisfies the wait.nextDrawablecan block while the global lock is held (victory-metal/src/present.rs~179). Please add a regression that drains several deferred presents through the worker.Heads-up: this conflicts with #48 in
texture_tests.rs.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T12:09:47Z.
@LakshanSivakumar Addressed in
0a6dfc1:Unsatisfied waits stay off Metal. Removed the committed-signal high-water mark. Queue waits now remain in the CPU FIFO until the backend reports the requested value as completed, including when a producer has already committed. A delayed or asynchronously failed producer therefore cannot cause a later unsatisfied wait to be encoded on Metal. Added a regression with a committed, stalled producer that verifies the consumer remains CPU-held until completion; this test exercises the delayed-producer case, rather than injecting an asynchronous GPU failure.
Queued waits retain the backend fence. Each wait gets a unique token owning an
Rcto its specific backend fence, independent of the title-address lookup. Releasing the title fence or reusing its address cannot satisfy the old wait. The reference is released when the wait is consumed. Deferred signals also retain their queue and fence. Added a release/address-reuse regression that checks both continued blocking and eventual release of the retained fence.Drawable acquisition no longer blocks the shared pump. A per-surface worker calls
nextDrawable; the pump polls its result without blocking. A pending present stays at its FIFO head, preserving render → present → signal order while other queues can progress. Per-frame autorelease pools release temporary drawable references. The presentation regression now queues six deferred presents, signals the gate directly on the backend, and verifies that the timer worker drains all six and produces the expected pixels. A separate FIFO regression checks that a pending action blocks only its own queue.For the overlap with #48, the refactored presentation helper now uses its proposed eight-page pool for both immediate and deferred cases. #48 is still open; I have not merged that branch or claimed the textual merge conflict is resolved.
Validation passed locally on native arm64 macOS:
cargo test -j6 -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtaskcargo test -j6 -p victory-gpu -p victory-metal(GPU: 150 passed, 1 ignored; Metal unit/integration suites: 15 passed).cargo clippy -j6 --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policy(365 files checked)git diff --checkThe native build still emits existing warnings. These are local results; CI for the pushed commit is separate.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:48:25Z.
Review: CHANGES_REQUESTED
Thanks, all three earlier points are addressed (no GPU-encoded unsatisfied waits, the fence retained while a wait is queued, nextDrawable off the shared pump with the six-present regression). Small things before merge:
Metal::presentbusy-loops if no drawable arrives. It has no title caller now, but please bound it or add ashortcut:comment.This also overlaps #48 in
texture_tests.rs, so whichever lands second needs a rebase.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by shabouwcaw on 2026-11-26T12:51:38Z.
Follow-up in
12bd1b9:Documented the scheduling tradeoff in
docs/native-host.md: every unsatisfied fence wait stays CPU-held, so completion between polls can add roughly one nominal 1 ms timer interval before dependent work is submitted, potentially longer under host scheduling or lock contention. Title calls also pump. The before/after headless frame figure is still outstanding: there is no game installation available on this development machine, so I cannot provide a valid measured figure or claim unchanged performance. The docs explicitly distinguish the passing functional tests from an unmeasured frame-rate impact. A tester with a local installation will need to compare7288e18(before) against this revision with the same run duration, inputs, settings, and saved state.Reworded
docs/ROADMAP.mdto say all unsatisfied queue waits are CPU-held until observed backend completion, including waits behind already-committed signals whose producers can still be delayed or fail.Bounded the standalone blocking
Metal::presenthelper to a two-second drawable wait, returningtimed out waiting for a drawable. It sleeps between polls; the title path continues to use only nonblockingtry_present. Added a regression with a connected acquisition channel that never supplies a drawable; it verifies the timeout error and no presented frame. Also removed two redundant casts in this file flagged by the native Metal lint check.Validation:
cargo clippy -j6 -p victory-metal --all-targets -- -D warningspassed.cargo xtask policypassed (365 files);git diff --checkpassed.Acknowledged the overlap with #48: the overlapping helper already uses its eight-page pool adjustment, but whichever PR lands second still needs a rebase. This follow-up does not change
texture_tests.rsagain.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T13:26:52Z.
Review: APPROVED
Follow-up items are addressed cleanly: scheduling tradeoff and missing local frame-rate baseline are documented in
docs/native-host.md,docs/ROADMAP.mdmatches the CPU-held wait policy, blockingMetal::presentis bounded with a regression test, and the twopresent.rsclippy cast warnings are gone. CI is green; merging (before/after headless frame comparison remains open for a run with game data).