Skip to content

GPU: account for pending pipelines before promotion - #2223

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/pso-queue-accounting
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/pso-queue-accounting

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

An early enqueue marks a PSO as queued before it increments the pending count. A concurrent first draw can promote that entry and send it to a worker in between. If the worker finishes first, it can decrement the pending count from zero.

Run the first count through a per-pipeline Once so any concurrent promotion waits for the count to be registered. Urgent and early queue selection remains in the same code path.

The regression pauses the early enqueue before its count and then starts a concurrent promotion. The simulated worker saw 0 before the fix and 1 after it. The existing first-use test also exercises the worker queue.

  • Windows/WARP GPU library suite with the same regression on both builds went from 145 passed, 2 failed, 2 ignored to 146 passed, 1 failed, 2 ignored. The placed-view texture-format test failed in both builds.
  • Clippy passed for victory-gpu all targets with warnings denied, with and without diagnostics.

Coordination claim in #1633.

AI-assisted using Codex. Synthetic data only.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib pipeline::make:: — 3 passed, 0 failed (including an_urgent_enqueue_cannot_overtake_the_first_queue_count)
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean ordering fix accounting for pending pipelines before urgent promotion. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Account for pending pipelines before promotion; replaces queued AtomicBool with Once and adds a PEAK waiting metric. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. The branch now merges cleanly into current main (4f2b0f3). The race is real in main's pipeline/make.rs. enqueue sets queued before it increments WAITING. A draw that promotes the entry in between can send it to a worker, and the worker's WAITING.fetch_sub then wraps below zero. After that, drained() no longer fires at the right time and making() reports nonsense. Turning Pending::queued into a std::sync::Once, with the count taken inside call_once, makes a concurrent promotion wait until the count is in. The queue-selection logic is unchanged. The new test forces the interleaving with channels, and the existing enqueue test no longer adjusts the global WAITING by hand. CI (check) passes on this head.


Generated by Claude Code

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…with the branch

The refreshed community PRs merge cleanly as text but did not build
together with the branch:

- Marvisak#2935 returns `None` for an unaccepted present, but on this branch
  `present_planes_with_compositor` returns the primary plane's state
  too. The unaccepted present now returns `(None, primary_state)`: the
  present copy has already run, so the plane is back in that state.
- Marvisak#2509 makes `Staging::layout` the whole texture (all planes). The
  levels-on-demand check (Marvisak#2389) reads plane 0's level layout, so it
  now passes `layout.planes[0].layout`, as before Marvisak#2509.
- Tests from Marvisak#1933, Marvisak#2336 and Marvisak#2729 used older APIs: the depth twin test
  imports `D3DCompile` itself (the branch's twin.rs writes its DXIL and no
  longer imports it), `HostShader` and `Translated` gained
  `written_root_uavs`, `threads` and `atomics64`, `hand_out` takes the
  title's bytecode pointers and `emit::emit` a `Target`. Marvisak#3005's test
  reads `queued` as the `Once` Marvisak#2223 makes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified 4f2b0f33975ecc38a7b8d786405fe40d5823ada3 merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (RTX 5090 + Microsoft WARP, Rust 1.98.1 MSVC).

Code & Concurrency Audit

  • Replacing Pending::queued: AtomicBool with std::sync::Once (crates/victory-gpu/src/pipeline/make.rs:33) and running note_waiting() inside p.queued.call_once(...) (L221-230) closes the early-vs-urgent promotion race cleanly: any concurrent urgent caller blocks in call_once until WAITING.fetch_add(1) completes, so a worker picking up the promoted entry can never execute WAITING.fetch_sub(1) (L331) before the count is registered.
  • Queue selection (first || ahead && !p.taken.load(Relaxed)) and worker single-claim deduplication via p.taken.swap(true, Relaxed) (L327) remain intact, so WAITING is still incremented and decremented strictly once even when an entry enters both queues.
  • start (L210-214) and count_waiting (L216-218) keep PEAK tracking accurate without altering external behavior.

Local Verification

  • cargo xtask policy — pass.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --lib pipeline::make:: (RTX 5090 and WARP) — all passed, including an_urgent_enqueue_cannot_overtake_the_first_queue_count.
  • Additional synthetic stress probe racing 8 threads across 500 barrier-synchronized early + urgent enqueue iterations on a single Pending instance — passed (counted strictly once, worker always observed waiting == 1 before decrement, final waiting == 0).

Looks good to merge.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I tested #2223 at 4f2b0f3 with #3353 at df15a80 and #3025 at 018b56a. The new presentation path can hit the same accounting race via hurry: the regression pauses the first enqueue before its count and checks whether the presentation path can promote it. The two-PR control admitted the uncounted pipeline.

Combined commit 335eb7b uses #2223's completed registration for both promotion paths. The presentation path can promote it as soon as the count completes. Graphics still goes first, compute keeps its cap, and a worker claims a promoted entry once. The two new presentation tests from df15a80 pass too.

Windows: 15/15 queue and presentation tests with default features, 16/16 with diagnostics, strict Clippy in both configurations, and the asset policy check passed. This was a scheduler test with synthetic pipelines. Maintainers can carry the combined resolution forward if #3353 or #3025 lands first. Please keep the Git author or use Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com> if folding the resolution into another commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants