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

Open
github-bot wants to merge 1 commit from github-bot/gh-3005 into main AGit
Owner

@⁠AwsAli05 on GitHub · 2026-11-26 03:09 UTC · original
AwsAli05:gpu/ready-pipeline-fast-path → main · +24 −5 · 1 files · 1 commits · open

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.

**@⁠AwsAli05** on GitHub · 2026-11-26 03:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3005) `AwsAli05:gpu/ready-pipeline-fast-path` → `main` · +24 −5 · 1 files · 1 commits · open ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:19:55 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 03:34 UTC · original

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

**@⁠steven-seagull27** on GitHub · 2026-11-26 03:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3005#issuecomment-7181843785) 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](https://github.com/steven-seagull27/VIctory/commit/63195c02a9805b1d9e6e097ffcfd1692dce4c369)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:49 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 05:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3005#issuecomment-7183840351) <!-- victory-triage v1 head=f962bf029ff456abf23b89e104fe1ea4f2f38840 verdict=merge-candidate at=2026-11-26T05:49:26Z --> 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](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3005/head:github-bot/gh-3005'
git switch 'github-bot/gh-3005'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3005'
git switch 'github-bot/gh-3005'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3005'
git switch 'github-bot/gh-3005'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3005'
git switch 'main'
git merge --squash 'github-bot/gh-3005'
git switch 'main'
git merge --ff-only 'github-bot/gh-3005'
git switch 'main'
git merge 'github-bot/gh-3005'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3005
No description provided.