pipeline: a stale frame number does not reset the wait budget #98

Manually merged
github merged 1 commit from github-bot/gh-98 into main 2026-12-01 20:58:42 +00:00 AGit
Owner

@⁠coil111 on GitHub · 2026-12-01 19:06 UTC · original
coil111:pipeline-wait-budget → main · +6 −1 · 1 files · 1 commits · merged 2026-12-01 20:55 UTC

When the title first uses a pipeline that isn't ready yet, wait() in pipeline/make.rs blocks for at most a shared budget per frame. All threads share the Waited record, and the budget is reset whenever a caller's frame differs from the stored one (waited.frame != frame).

A thread that read the frame number just before another thread moved it on still enters with the older frame. The record goes back to that older frame and spent goes to zero. The next caller on the newer frame sees a frame change again and resets again. Each time a stale reader comes in, the current frame gets its full budget back, so one frame can stall longer than wait_budget() / screen_budget() allow.

The fix:

  • Frames only move forward: a caller with an older frame returns without waiting and leaves the record alone.
  • A newer frame resets the budget as before.

6 lines, one file. Within a single frame nothing changes.

**@⁠coil111** on GitHub · 2026-12-01 19:06 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/98) `coil111:pipeline-wait-budget` → `main` · +6 −1 · 1 files · 1 commits · merged 2026-12-01 20:55 UTC When the title first uses a pipeline that isn't ready yet, `wait()` in `pipeline/make.rs` blocks for at most a shared budget per frame. All threads share the `Waited` record, and the budget is reset whenever a caller's frame differs from the stored one (`waited.frame != frame`). A thread that read the frame number just before another thread moved it on still enters with the older frame. The record goes back to that older frame and `spent` goes to zero. The next caller on the newer frame sees a frame change again and resets again. Each time a stale reader comes in, the current frame gets its full budget back, so one frame can stall longer than `wait_budget()` / `screen_budget()` allow. The fix: - Frames only move forward: a caller with an older frame returns without waiting and leaves the record alone. - A newer frame resets the budget as before. 6 lines, one file. Within a single frame nothing changes.
A thread that read the frame number before another moved it on reset the shared
budget to its older frame, so the newer frame could wait its budget again.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 19:07:19 +00:00
github-bot referenced this pull request from a commit 2026-12-01 20:58:42 +00:00
github manually merged commit 8ba89a6a61 into main 2026-12-01 20:58:42 +00:00
github-bot referenced this pull request from a commit 2026-12-01 21:04:22 +00:00
Author
Owner

@⁠EdouardSence on GitHub · 2026-12-01 21:25 UTC · original

I read this against wait() / ready() on 37bb30f. The race is real but narrow. ready() reads frame::current() right before it takes the WAITED lock, so a caller is "stale" only when the frame advances in that window (microseconds). It can still reset the budget, so the fix is worth having.

One suggestion: the early return turns that stale caller into a guaranteed miss. Its draw goes out without the pipeline for that frame, even when the current frame still has budget left. Treating the caller as the newer frame gives the same protection without the forced drop:

waited.count(started);
// A caller that read the frame number just before it moved on counts
// against the newer frame's budget, never resets it.
if frame > waited.frame {
    waited.frame = frame;
    waited.spent = Duration::ZERO;
}
if waited.spent >= budget {
    return;
}

Since frame < waited.frame no longer resets anything, the stale caller waits on whatever is left of the current frame's budget, which is what the budget is for. Nothing else in wait() uses frame, so this is the whole change.

(Review only. I have not measured it in a run: with all pipelines warm, my runs on an RX 9070 XT hardly enter wait().)

**@⁠EdouardSence** on GitHub · 2026-12-01 21:25 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/98#issuecomment-7326232334) I read this against `wait()` / `ready()` on `37bb30f`. The race is real but narrow. `ready()` reads `frame::current()` right before it takes the `WAITED` lock, so a caller is "stale" only when the frame advances in that window (microseconds). It can still reset the budget, so the fix is worth having. One suggestion: the early `return` turns that stale caller into a guaranteed miss. Its draw goes out without the pipeline for that frame, even when the current frame still has budget left. Treating the caller as the newer frame gives the same protection without the forced drop: ```rust waited.count(started); // A caller that read the frame number just before it moved on counts // against the newer frame's budget, never resets it. if frame > waited.frame { waited.frame = frame; waited.spent = Duration::ZERO; } if waited.spent >= budget { return; } ``` Since `frame < waited.frame` no longer resets anything, the stale caller waits on whatever is left of the current frame's budget, which is what the budget is for. Nothing else in `wait()` uses `frame`, so this is the whole change. (Review only. I have not measured it in a run: with all pipelines warm, my runs on an RX 9070 XT hardly enter `wait()`.)
github-bot referenced this pull request from a commit 2026-12-04 19:05:27 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.