Game: short-circuit pipeline state enumeration once wanted hashes are found #2573

Open
reeledMarek wants to merge 1 commit from upstream-pr/2575 into main
reeledMarek commented 2026-11-25 16:08:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T16:08:30Z.


Summary

Short-circuits pipeline state enumeration in victory_game::pipelines as soon as all wanted hashes are resolved, instead of always exhausting the entire search space.

Changes

  • Skip name_from_registers, depth_space, and raster_space in Named::find when their corresponding want sets are already empty.
  • Propagate std::ops::ControlFlow<()> from raster_space, depth_space, depth_from_registers, and blend_from_registers so Named::find and name_from_registers stop immediately once every wanted hash (or the current record's target hash) has been matched.
  • Updated existing unit tests and added raster_space_short_circuits_on_break to verify early termination.

Scope

Trimmed to only the ControlFlow early exits per triage feedback; candidate generation in blend_from_registers and raster_space is unchanged.

Verification

  • cargo test -p victory-game --locked
  • cargo clippy -p victory-game --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings
  • cargo test -p xtask --locked
<!-- greyfinch-sync:Marvisak/VIctory:issue:5494830278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T16:08:30Z. --- ### Summary Short-circuits pipeline state enumeration in `victory_game::pipelines` as soon as all wanted hashes are resolved, instead of always exhausting the entire search space. ### Changes - Skip `name_from_registers`, `depth_space`, and `raster_space` in `Named::find` when their corresponding `want` sets are already empty. - Propagate `std::ops::ControlFlow<()>` from `raster_space`, `depth_space`, `depth_from_registers`, and `blend_from_registers` so `Named::find` and `name_from_registers` stop immediately once every wanted hash (or the current record's target hash) has been matched. - Updated existing unit tests and added `raster_space_short_circuits_on_break` to verify early termination. ### Scope Trimmed to only the `ControlFlow` early exits per triage feedback; candidate generation in `blend_from_registers` and `raster_space` is unchanged. ### Verification - `cargo test -p victory-game --locked` - `cargo clippy -p victory-game --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings` - `cargo test -p xtask --locked`
Marvisak commented 2026-11-25 23:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:16:39Z.


Automated triage for the maintainers.

Needs work. Re-reviewed at dfcfa60. The visited < 2_000_000 assertion is gone, and the rewrite of crates/victory-game/src/pipelines.rs still reads as behaviour-preserving (ControlFlow early exits, the array forms of per_target/twins, the reused targets buffers, bases dedup).

Reply to the author: you are right, and our earlier comment was wrong: apps/victory/src/prebuild.rs calls Named::find during victory prebuild. That is still a one-off offline step, though. Your benchmark uses a pack whose wanted states are all D3D12 defaults. That is the best case for the early exits, because enumeration stops at once. With a real pack, any hash that is never named still walks the whole space. What would change the verdict: the time of Named::find in a real victory prebuild run, before and after, as a share of the whole command. Timings only, no title data. If that gain is small, a smaller change limited to the early exits would be easier to take.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176159187 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7176159187). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:16:39Z. --- <!-- victory-triage v1 head=dfcfa60fb785a5ba6a271d511ca444a25c83fdec verdict=needs-work at=2026-11-26T07:18:12Z --> Automated triage for the maintainers. **Needs work.** Re-reviewed at `dfcfa60`. The `visited < 2_000_000` assertion is gone, and the rewrite of `crates/victory-game/src/pipelines.rs` still reads as behaviour-preserving (`ControlFlow` early exits, the array forms of `per_target`/`twins`, the reused `targets` buffers, `bases` dedup). **Reply to the author:** you are right, and our earlier comment was wrong: `apps/victory/src/prebuild.rs` calls `Named::find` during `victory prebuild`. That is still a one-off offline step, though. Your benchmark uses a pack whose wanted states are all D3D12 defaults. That is the best case for the early exits, because enumeration stops at once. With a real pack, any hash that is never named still walks the whole space. What would change the verdict: the time of `Named::find` in a real `victory prebuild` run, before and after, as a share of the whole command. Timings only, no title data. If that gain is small, a smaller change limited to the early exits would be easier to take. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-26 06:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:56:05Z.


Updated to address the triage feedback:

  • Removed the iteration-order visited < 2_000_000 assertion from the_depth_space_holds_the_d3d12_default.
  • Note: Named::find is called by apps/victory/src/prebuild.rs:92 during victory prebuild.
  • Release-mode benchmark (cargo test --release -p victory-game, 9 runs, synthetic pack with matched D3D12 default depth-stencil and default rasterizer states, main 63bcca4 vs this PR):
    • main: median 153.94 ms (min 153.66 ms, max 157.13 ms)
    • this PR: median 12.22 ms (min 12.21 ms, max 12.32 ms) — 12.6× faster (-92.1%).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7183937594 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7183937594). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:56:05Z. --- Updated to address the triage feedback: - Removed the iteration-order `visited < 2_000_000` assertion from `the_depth_space_holds_the_d3d12_default`. - Note: `Named::find` is called by `apps/victory/src/prebuild.rs:92` during `victory prebuild`. - Release-mode benchmark (`cargo test --release -p victory-game`, 9 runs, synthetic pack with matched D3D12 default depth-stencil and default rasterizer states, `main` `63bcca4` vs this PR): - `main`: median **153.94 ms** (min 153.66 ms, max 157.13 ms) - this PR: median **12.22 ms** (min 12.21 ms, max 12.32 ms) — **12.6× faster (-92.1%)**.
upstream-sync changed title from [PR #2575] Game: skip redundant pipeline state enumeration and eliminate inner-loop blend Vec allocations to [PR #2575] Game: short-circuit pipeline state enumeration once wanted hashes are found 2026-11-26 11:03:19 +00:00
reeledMarek commented 2026-11-26 11:04:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T10:39:34Z.


Trimmed this PR down to only the ControlFlow early exits (and rebased onto current main), dropping the blend_from_registers allocation rewrite so the change stays small and focused as suggested.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189659581 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7189659581). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T10:39:34Z. --- Trimmed this PR down to only the `ControlFlow` early exits (and rebased onto current `main`), dropping the `blend_from_registers` allocation rewrite so the change stays small and focused as suggested.
andrewpozdnakov7-jpg commented 2026-11-28 08:51:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T08:51:11Z.


I found a case where the early exit changes which pipeline states Named::find can recover on a894f0d. In a generated two-record pack, both records have stencil disabled. The first register image retains the inactive masks and can supply both depth hashes, while the second image omits the masks. The PR finds the first hash, stops enumerating that image, and leaves the second hash unnamed. The same test finds both on #3698.

dd74dc4 is a follow-up directly on your current head. It keeps the early exit once no depth or blend hashes of that kind remain, and adds the two-record regression. The test fails on a894f0d and passes with the follow-up. All 17 victory-game tests, strict Clippy for that crate and the asset policy check passed. I also resolved the overlapping hunk with #3698 locally and all 17 tests passed together.

@reeledMarek, could you review the follow-up for inclusion here? Please retain the Git author if you cherry-pick or rebase it, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7236853503 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7236853503). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T08:51:11Z. --- I found a case where the early exit changes which pipeline states `Named::find` can recover on `a894f0d`. In a generated two-record pack, both records have stencil disabled. The first register image retains the inactive masks and can supply both depth hashes, while the second image omits the masks. The PR finds the first hash, stops enumerating that image, and leaves the second hash unnamed. The same test finds both on #3698. [`dd74dc4`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/dd74dc43c0fbb67bd82f2ff3abf56784c53f5de2) is a follow-up directly on your current head. It keeps the early exit once no depth or blend hashes of that kind remain, and adds the two-record regression. The test fails on `a894f0d` and passes with the follow-up. All 17 `victory-game` tests, strict Clippy for that crate and the asset policy check passed. I also resolved the overlapping hunk with #3698 locally and all 17 tests passed together. @reeledMarek, could you review the follow-up for inclusion here? Please retain the Git author if you cherry-pick or rebase it, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 10:08:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T10:08:22Z.


I combined your current head and the two-state regression follow-up with #3698, #3700 and #3707 in 7b1113d. The branch keeps all four PR heads and the regression commit in its history. The one overlapping register hunk retains the per-record skip and stops enumerating a kind only when its wanted set is empty.

I checked full Named::find on Windows with 25,003 generated graphics records and 25,000 effects. The state bytes and source labels matched main across separate release binaries. With all hashes named by the first effect, the two process medians were 140–160 ms on main and 2.75–3.79 ms on the combined tree. With a remaining depth hash and two register-derived states, the medians were 159–160 ms and 136–137 ms. These are generated prebuild fixtures.

All 17 game tests passed, including the two-state regression, along with strict Clippy and asset policy. @reeledMarek, this branch is available for your review. Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the changes into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7237696594 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7237696594). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T10:08:22Z. --- I combined your current head and the [two-state regression follow-up](https://github.com/Marvisak/VIctory/pull/2575#issuecomment-7236853503) with #3698, #3700 and #3707 in [7b1113d](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/7b1113d9a99932234bc11e3e16ece249e26e1f84). The branch keeps all four PR heads and the regression commit in its history. The one overlapping register hunk retains the per-record skip and stops enumerating a kind only when its wanted set is empty. I checked full `Named::find` on Windows with 25,003 generated graphics records and 25,000 effects. The state bytes and source labels matched main across separate release binaries. With all hashes named by the first effect, the two process medians were 140–160 ms on main and 2.75–3.79 ms on the combined tree. With a remaining depth hash and two register-derived states, the medians were 159–160 ms and 136–137 ms. These are generated prebuild fixtures. All 17 game tests passed, including the two-state regression, along with strict Clippy and asset policy. @reeledMarek, this branch is available for your review. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the changes into another commit. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2575:upstream-pr/2575'
git switch 'upstream-pr/2575'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2575'
git switch 'upstream-pr/2575'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2575'
git switch 'upstream-pr/2575'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2575'
git switch 'main'
git merge --squash 'upstream-pr/2575'
git switch 'main'
git merge --ff-only 'upstream-pr/2575'
git switch 'main'
git merge 'upstream-pr/2575'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2573
No description provided.