Shaders: visit resource::track blocks in reverse postorder #2420

Closed
makmatvey wants to merge 1 commit from upstream-pr/2422 into main
makmatvey commented 2026-11-25 13:12:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by makmatvey on 2026-11-25T13:12:54Z.


What

resource::track walked blocks in vector index order. After CFG transforms that append blocks (for example split_irreducible), a lower-indexed consumer could run before a higher-indexed s_load producer, so out.scalar did not yet hold the load when the consumer looked it up and waterfall / descriptor tracing missed it.

Tracked as VIC-BT-024 in #1249. Focused slice of the stalled bundle in #1336 (needs rebase); does not include the SMEM alignment or lane-index pieces of that PR.

Change

In crates/victory-shader/src/resource.rs, the main walk uses reverse_postorder so producers populate out.scalar before consumers.

Tests

  • cargo test -p victory-shader --locked --lib track_visits_blocks_in_reverse_postorder — pass (fails on main without the walk change)
  • cargo test -p victory-shader --locked --lib resource:: — 34 passed
  • cargo clippy -p victory-shader --locked -- -D warnings — clean
  • cargo xtask policy — ok

No game data used.

Fixes VIC-BT-024 in #1249.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5492010776 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422). Originally posted by [makmatvey](https://github.com/makmatvey) on 2026-11-25T13:12:54Z. --- ## What `resource::track` walked blocks in vector index order. After CFG transforms that append blocks (for example `split_irreducible`), a lower-indexed consumer could run before a higher-indexed `s_load` producer, so `out.scalar` did not yet hold the load when the consumer looked it up and waterfall / descriptor tracing missed it. Tracked as VIC-BT-024 in #1249. Focused slice of the stalled bundle in #1336 (needs rebase); does not include the SMEM alignment or lane-index pieces of that PR. ## Change In `crates/victory-shader/src/resource.rs`, the main walk uses `reverse_postorder` so producers populate `out.scalar` before consumers. ## Tests - `cargo test -p victory-shader --locked --lib track_visits_blocks_in_reverse_postorder` — pass (fails on `main` without the walk change) - `cargo test -p victory-shader --locked --lib resource::` — 34 passed - `cargo clippy -p victory-shader --locked -- -D warnings` — clean - `cargo xtask policy` — ok No game data used. Fixes VIC-BT-024 in #1249.
DenRakEiw commented 2026-11-25 13:18:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:18:40Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Visiting blocks in reverse postorder in resource::track ensures dominating definitions are seen before uses regardless of block layout.
  • cargo test -p victory-shader resource::tests: 34/34 passed on RTX 5090 and WARP (including track_visits_blocks_in_reverse_postorder).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6058334317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422#pullrequestreview-6058334317). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T13:18:40Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Visiting blocks in reverse postorder in `resource::track` ensures dominating definitions are seen before uses regardless of block layout. - `cargo test -p victory-shader resource::tests`: 34/34 passed on RTX 5090 and WARP (including `track_visits_blocks_in_reverse_postorder`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 13:25:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:25:23Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — resource::track blocks visited in reverse postorder.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058435756 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422#pullrequestreview-6058435756). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:25:23Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — resource::track blocks visited in reverse postorder.
oni-swr commented 2026-11-25 14:07:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T13:34:45Z.


WARP verification

Tested: PR head 750445401e3f486a75cb58a5dcfd4d1fd01c83e2, on origin/main 940d32f69b22265690a0b5a15d6ded572ba33baf (the PR is one commit on that base, so the merge was a no-op).
Environment: VICTORY_D3D12_WARP=1 (software WARP), Windows 11 Pro 10.0.26200, rustc 1.98.1, DXC 1.9.0.5512 (dxcompiler), dxil.dll 1.8.2502.11 on PATH.

Command Result
cargo test -p victory-shader --lib --locked ok: 248 passed, 0 failed, 3 ignored (two benchmarks and one defect_ test, all ignored on main too)
cargo clippy -p victory-shader --all-targets --locked -- -D warnings exit 0
cargo xtask policy asset policy: 182 files ok, exit 0

The new test resource::tests::track_visits_blocks_in_reverse_postorder ran and passed (not skipped).

Diff review (resource.rs only): track now iterates crate::ir::reverse_postorder(&p.blocks) instead of index order. It compiles against main as-is, so the helper already exists. There are no process, network or filesystem actions. I did not check what happens to blocks that are unreachable from the entry, which reverse postorder would not visit. That is worth confirming if track previously processed them.

Limits: WARP only, no physical hardware GPU, no game files or dumps. The test uses synthetic instruction words only.

AI use: Claude Code (Claude Sonnet 5.5)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163981377 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422#issuecomment-7163981377). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T13:34:45Z. --- **WARP verification** Tested: PR head `750445401e3f486a75cb58a5dcfd4d1fd01c83e2`, on `origin/main` `940d32f69b22265690a0b5a15d6ded572ba33baf` (the PR is one commit on that base, so the merge was a no-op). Environment: `VICTORY_D3D12_WARP=1` (software WARP), Windows 11 Pro 10.0.26200, rustc 1.98.1, DXC 1.9.0.5512 (dxcompiler), dxil.dll 1.8.2502.11 on `PATH`. | Command | Result | |---|---| | `cargo test -p victory-shader --lib --locked` | ok: 248 passed, 0 failed, 3 ignored (two benchmarks and one `defect_` test, all ignored on main too) | | `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` | exit 0 | | `cargo xtask policy` | `asset policy: 182 files ok`, exit 0 | The new test `resource::tests::track_visits_blocks_in_reverse_postorder` ran and passed (not skipped). Diff review (`resource.rs` only): `track` now iterates `crate::ir::reverse_postorder(&p.blocks)` instead of index order. It compiles against main as-is, so the helper already exists. There are no process, network or filesystem actions. I did not check what happens to blocks that are unreachable from the entry, which reverse postorder would not visit. That is worth confirming if `track` previously processed them. Limits: WARP only, no physical hardware GPU, no game files or dumps. The test uses synthetic instruction words only. AI use: Claude Code (Claude Sonnet 5.5)
Marvisak commented 2026-11-25 16:09:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:32:21Z.


Automated triage for the maintainers.

Needs work (test). This makes the main walk of crates/victory-shader/src/resource.rs track use ir::reverse_postorder, the order lowering already uses (emit/lower.rs); it is plausible and small, and unreachable blocks are now skipped, matching what lowering emits. In track, only one lookup depends on the order: out.scalar.iter().find(|s| s.0 == load), which decides whether an access joins the waterfall offset path (offset_at -> waterfall.loads). The new test does not check that effect: it checks the order of entries in out.scalar (what the code does, not what the result should be), and descriptors[0].source == Loaded { load: (2, 0), .. }, which Tracer::descriptor computes independently of the order, so it holds on main too. Please add a test whose result differs on main, for example a lower-indexed block reading a table offset through v_readfirstlane and loading the descriptor from a higher-indexed block, asserting r.waterfall.loads; ideally also name a shader that hits this. CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166998829 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422#issuecomment-7166998829). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:32:21Z. --- <!-- victory-triage v1 head=750445401e3f486a75cb58a5dcfd4d1fd01c83e2 verdict=needs-work at=2026-11-25T15:36:00Z --> Automated triage for the maintainers. **Needs work (test).** This makes the main walk of `crates/victory-shader/src/resource.rs` `track` use `ir::reverse_postorder`, the order lowering already uses (`emit/lower.rs`); it is plausible and small, and unreachable blocks are now skipped, matching what lowering emits. In `track`, only one lookup depends on the order: `out.scalar.iter().find(|s| s.0 == load)`, which decides whether an access joins the waterfall offset path (`offset_at` -> `waterfall.loads`). The new test does not check that effect: it checks the order of entries in `out.scalar` (what the code does, not what the result should be), and `descriptors[0].source == Loaded { load: (2, 0), .. }`, which `Tracer::descriptor` computes independently of the order, so it holds on `main` too. Please add a test whose result differs on `main`, for example a lower-indexed block reading a table offset through `v_readfirstlane` and loading the descriptor from a higher-indexed block, asserting `r.waterfall.loads`; ideally also name a shader that hits this. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
kotekompotek commented 2026-11-25 17:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:53:24Z.


Right fix for the ordering bug: index order isn't a topological order — a producer in a higher-indexed block (e.g. appended by split_irreducible) was visited after a consumer that needed it. RPO gives producer-before-consumer for every reachable edge except irreducible-loop backedges, which is the best a forward dataflow can do anyway. ir::reverse_postorder exists and the regression test pins exactly the split-block scenario.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168684934 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2422#issuecomment-7168684934). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T16:53:24Z. --- Right fix for the ordering bug: index order isn't a topological order — a producer in a higher-indexed block (e.g. appended by `split_irreducible`) was visited after a consumer that needed it. RPO gives producer-before-consumer for every reachable edge except irreducible-loop backedges, which is the best a forward dataflow can do anyway. `ir::reverse_postorder` exists and the regression test pins exactly the split-block scenario.

Pull request closed

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!2420
No description provided.