Skip to content

GPU: make already-used pipeline lookups read-only - #3005

Open
AwsAli05 wants to merge 1 commit into
Marvisak:mainfrom
AwsAli05:gpu/ready-pipeline-fast-path
Open

AwsAli05 wants to merge 1 commit into
Marvisak:mainfrom
AwsAli05:gpu/ready-pipeline-fast-path

Conversation

@AwsAli05

Copy link
Copy Markdown
Contributor

Change

Avoid an unconditional atomic exchange and a second readiness check on every draw or dispatch using a finished pipeline. An atomic exchange still chooses one thread to record first use. Unfinished pipelines still enter the existing queue and wait within the existing frame budget.

I checked the open queue for matching work. #275 changes the wait after a cache miss. #2986 changes how the warm-up key is formed.

Verification

  • Focused Windows victory-gpu pipeline tests passed with default features (3) and diagnostics enabled (4).
  • The new test covers first-use recording and repeated lookup of a completed pipeline without queueing it again.
  • In an isolated optimized Rust probe with four threads sharing a single finished pipeline, median aggregate CPU lookup time moved from 11.84 to 0.36 ns per lookup. The probe measures lookup contention in isolation.
  • Staged asset policy and git diff --check passed.

AI-assisted with Codex.

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

Code review on f962bf02 (static source inspection):

  • crates/victory-gpu/src/pipeline/make.rs:193-212 cleanly avoids atomic RMW traffic on the hot path by checking p.used.load(Ordering::Relaxed) before falling back to p.used.swap(true, Ordering::Relaxed) (preserving single-recorder election under contention) and returning early from p.made.get() without re-calling start/wait.
  • first_use_of_a_finished_pipeline_is_recorded_without_queueing cleanly covers both used recording and non-queueing on an already-completed pipeline.

@steven-seagull27

Copy link
Copy Markdown

Confirmed the first-use race and the throughput gain through pipeline::host_pipeline, the entry point used by draws and dispatches. Each worker held the same valid guest graphics pipeline. With 32 callers starting together, all obtained the same host object. I counted calls at the entry to library::note_used, before its set deduplicates keys. It ran exactly once per guest object. Each of 16 fresh objects built once, and none of 16 prebuilt objects entered the queue. This passed on RTX 5080 and WARP at both 63bcca43 and f962bf0. Cold callers could retry after the frame wait budget expired.

On a Ryzen 7 9850X3D, the completed-pipeline measurements below use aggregate wall ns per lookup.

CPU workload Parent PR
1 worker 5.15 1.39
4 workers sharing one pipeline 13.54 0.62
8 workers sharing one pipeline 13.30 0.32
8 workers, a separate pipeline object per worker 0.79 0.33
8 workers sharing one pipeline, SetPipelineState every 16 lookups 15.36 1.97

There is a separate opportunity if recording threads bind the shared PSO frequently. With an actual SetPipelineState on each worker's own guest command list before every lookup, the PR measured 18.0 ns. Each bind still exchanges Pipeline::bound. Adding the same relaxed load before that exchange in a local control reduced the median to 2.85 ns, with one first-bind event per guest object in the race. The parent varied from 14.55 to 38.15 ns between processes on this workload.

The timing used WARP to create the finished D3D12 PSOs, with one recording worker pinned per physical core. The table gives the median of four fresh-process medians, seven batches per process and 320,000 lookups per worker in the multithreaded batches. The timings cover CPU lookup and the indicated binding calls. To reproduce, set VICTORY_PROBE_DXC to the SDK compiler and PROBE_CORES to eight comma-separated affinity masks, then run cargo test --release -p victory-gpu --features diagnostics --lib actual_guest_pipeline_lookups -- --ignored --nocapture. Standalone review fixture

@kotekompotek kotekompotek 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.

LGTM — read-then-swap preserves the single note_used winner under races; the made.get() early return is equivalent to the old is_none() gate (made pipelines skipped start/wait before too) while staying read-only. Test asserts queued stays clear for finished lookups.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (small). In pipeline::make::ready, a relaxed load of used now comes before the swap, so a pipeline already recorded no longer does an atomic exchange on every draw. The swap still makes sure only one thread calls library::note_used. A finished pipeline returns from made.get() straight away. The not-yet-made path (start(p, true), wait, then made.get()) is unchanged. I checked that this is equivalent to the old code. The new test first_use_of_a_finished_pipeline_is_recorded_without_queueing covers first-use recording and that a finished pipeline isn't queued again.

The gain is small per lookup (a tester measured about 13 → 0.6 ns with 4 threads sharing one pipeline, and confirmed note_used still runs exactly once per object under a 32-caller race on RTX 5080 and WARP), but the change is simple and safe.

CI: passing.

Recommending a look, not approving.


Generated by Claude Code

@Dukestar69 Dukestar69 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.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Guarding p.used.swap(true, Relaxed) behind !p.used.load(Relaxed) and returning early on p.made.get() avoids dirtying the shared cache line on every hot-path lookup after first use while still recording first use exactly once.
  • cargo test -p victory-gpu --features diagnostics pipeline::make::tests: 4 passed, 0 failed (including first_use_of_a_finished_pipeline_is_recorded_without_queueing).
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

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

6 participants