Shaders: reuse source-lane activity ballots #2922

Open
Ingenioeren wants to merge 1 commit from upstream-pr/2924 into main
Ingenioeren commented 2026-11-26 00:13:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-26T00:13:38Z.


What

Reuse the source-lane activity ballot for DPP and LDS swizzle instructions that share a DXIL block and an EXEC predicate. Each instruction still checks the bit for its own source lane. Every emitted discard clears the cache because discarded lanes become helpers and stop contributing to wave ballots.

Why

The ballot depends on which host lanes are active at the call and which of those lanes satisfy the EXEC predicate. Between discards, the DXIL block and EXEC predicate determine when a ballot can be reused.

Numbers

dx.op.waveActiveBallot calls written 2 → 1 (50% fewer). The second DPP8 instruction reuses the first instruction's ballot. The count measures emitted DXIL calls, and whether a driver compiler would already merge the two ballots was not measured.

The test builds a wave32 compute shader with one 32-thread group and a raw output UAV in table slot 0. It initializes v1 = 0x10000001 + lane, v2 = 0xdead0000 + lane, and v3 = 0x00010000 + lane. With EXEC narrowed to lanes where (lane & 3) != 3, it runs DPP8 v_mov_b32 v2, v1 followed by DPP8 v_add_nc_u32 v2, v2, v3. Both use selectors [1, 0, 3, 2, 5, 4, 7, 6] and fi:0. It restores EXEC and stores v2 at byte offset 4 * lane. The exact GFX10 instruction words are below.

be810380 f4080100 fa000000 4a0200ff 10000001 4a0400ff
dead0000 4a0600ff 00010000 36080083 be8c037e 7daa0883
7e0402e9 de54c101 4a0406e9 de54c102 befe030c 340a0082
e0701000 80010205 bf810000

How tested

  • cargo test --locked --offline -p victory-shader dpp8_in_one_block_shares_the_source_activity_ballot -- --nocapture — all 32 output dwords matched the CPU reference before and after on an AMD Radeon RX 6750 XT. The baseline failed the structural assertion with two calls. The updated test passed with one call.
  • cargo test --locked --offline -p victory-shader — baseline 300 passed, 2 failed, 3 ignored. After the discard fix, 301 passed, 2 failed, 3 ignored. Both runs reported the same local dxil.dll Pipeline State Validation failures:
    • emit::rect::tests::rectangles_get_their_fourth_corner
    • emit::tests::elements_sharing_a_row_keep_their_order
  • cargo test --locked --offline -p victory-shader --test resource_tracking — 3 passed, 0 failed, 1 ignored.
  • cargo clippy --locked --offline -p victory-shader --all-targets — passed.
  • cargo run -p xtask -- policy --staged — passed for the two staged files in the original change and again for the staged discard fix.

No game launch or hardware run of the title. The hardware check used only the synthetic shader.

AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6616484970 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2924). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-26T00:13:38Z. --- ## What Reuse the source-lane activity ballot for DPP and LDS swizzle instructions that share a DXIL block and an EXEC predicate. Each instruction still checks the bit for its own source lane. Every emitted discard clears the cache because discarded lanes become helpers and stop contributing to wave ballots. ## Why The ballot depends on which host lanes are active at the call and which of those lanes satisfy the EXEC predicate. Between discards, the DXIL block and EXEC predicate determine when a ballot can be reused. ## Numbers `dx.op.waveActiveBallot` calls written **2 → 1** (50% fewer). The second DPP8 instruction reuses the first instruction's ballot. The count measures emitted DXIL calls, and whether a driver compiler would already merge the two ballots was not measured. The test builds a wave32 compute shader with one 32-thread group and a raw output UAV in table slot 0. It initializes `v1 = 0x10000001 + lane`, `v2 = 0xdead0000 + lane`, and `v3 = 0x00010000 + lane`. With EXEC narrowed to lanes where `(lane & 3) != 3`, it runs DPP8 `v_mov_b32 v2, v1` followed by DPP8 `v_add_nc_u32 v2, v2, v3`. Both use selectors `[1, 0, 3, 2, 5, 4, 7, 6]` and `fi:0`. It restores EXEC and stores `v2` at byte offset `4 * lane`. The exact GFX10 instruction words are below. ```text be810380 f4080100 fa000000 4a0200ff 10000001 4a0400ff dead0000 4a0600ff 00010000 36080083 be8c037e 7daa0883 7e0402e9 de54c101 4a0406e9 de54c102 befe030c 340a0082 e0701000 80010205 bf810000 ``` ## How tested - `cargo test --locked --offline -p victory-shader dpp8_in_one_block_shares_the_source_activity_ballot -- --nocapture` — all 32 output dwords matched the CPU reference before and after on an AMD Radeon RX 6750 XT. The baseline failed the structural assertion with two calls. The updated test passed with one call. - `cargo test --locked --offline -p victory-shader` — baseline 300 passed, 2 failed, 3 ignored. After the discard fix, 301 passed, 2 failed, 3 ignored. Both runs reported the same local `dxil.dll` Pipeline State Validation failures: - `emit::rect::tests::rectangles_get_their_fourth_corner` - `emit::tests::elements_sharing_a_row_keep_their_order` - `cargo test --locked --offline -p victory-shader --test resource_tracking` — 3 passed, 0 failed, 1 ignored. - `cargo clippy --locked --offline -p victory-shader --all-targets` — passed. - `cargo run -p xtask -- policy --staged` — passed for the two staged files in the original change and again for the staged discard fix. No game launch or hardware run of the title. The hardware check used only the synthetic shader. AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
fuzeofficlal commented 2026-11-26 01:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:23:35Z.

Review: COMMENTED


Verified head 061e7a6c cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0 dxil.dll).

Cache Soundness Review

  • Keying source_ballots: HashMap<(usize, V), [V; 2]> by (self.cur, bit) (current DXIL basic block + interned SSA EXEC guard V) safely prevents stale reuse across EXEC changes (s_and_saveexec/s_xor/v_cmpx produce distinct V unless structurally identical), block splits (new self.cur), and pixel-shader discard (emit_discard clears source_ballots), while guaranteeing dominance within the block.
  • File size: emit/lower.rs is 521,115 B (3,173 B below the 512 KiB policy cap).

Local Verification

  • cargo test --locked -p victory-shader --lib -- emit::crosslane_tests emit::lower::tests emit::flow_tests (RTX 5090 + WARP + dxil.dll): 40/40 passed (including dpp8_in_one_block_shares_the_source_activity_ballot, verifying both hardware output and wave_ballot_calls == 1).
  • cargo clippy --locked -p victory-shader --tests -- -D warnings (default and --all-features) & cargo xtask policy (191 files ok): clean.

Looks clean and ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066876669 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2924#pullrequestreview-6066876669). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:23:35Z. **Review:** COMMENTED --- Verified head `061e7a6c` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0 `dxil.dll`). ### Cache Soundness Review - Keying `source_ballots: HashMap<(usize, V), [V; 2]>` by `(self.cur, bit)` (current DXIL basic block + interned SSA `EXEC` guard `V`) safely prevents stale reuse across `EXEC` changes (`s_and_saveexec`/`s_xor`/`v_cmpx` produce distinct `V` unless structurally identical), block splits (new `self.cur`), and pixel-shader `discard` (`emit_discard` clears `source_ballots`), while guaranteeing dominance within the block. - **File size**: `emit/lower.rs` is `521,115 B` (`3,173 B` below the 512 KiB policy cap). ### Local Verification - `cargo test --locked -p victory-shader --lib -- emit::crosslane_tests emit::lower::tests emit::flow_tests` (RTX 5090 + WARP + `dxil.dll`): **40/40 passed** (including `dpp8_in_one_block_shares_the_source_activity_ballot`, verifying both hardware output and `wave_ballot_calls == 1`). - `cargo clippy --locked -p victory-shader --tests -- -D warnings` (default and `--all-features`) & `cargo xtask policy` (`191 files ok`): clean. Looks clean and ready to merge.
kotekompotek commented 2026-11-26 01:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T00:26:35Z.

Review: COMMENTED


Scoped review: reusing the source-lane activity ballot for a second DPP8 in the same block is safe when the mask didn't change between them — the test's Guarded divergence case pins exactly that. The wave_ballot_calls counter makes the dedup observable. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066897644 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2924#pullrequestreview-6066897644). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T00:26:35Z. **Review:** COMMENTED --- Scoped review: reusing the source-lane activity ballot for a second DPP8 in the same block is safe when the mask didn't change between them — the test's Guarded divergence case pins exactly that. The wave_ballot_calls counter makes the dedup observable. LGTM.
Marvisak commented 2026-11-26 05:04:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T04:23:16Z.


Automated triage for the maintainers.

Merge candidate. Lower::source_active (emit/lower.rs) caches the source-lane activity ballot per (DXIL block, EXEC predicate), so DPP and swizzle ops in one block share one waveActiveBallot. The reuse is sound: live host lanes in a block change only at a discard, and every discard now goes through emit_discard, which clears the cache. dpp8_in_one_block_shares_the_source_activity_ballot checks the lane results against the CPU reference and the ballot count.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182549862 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2924#issuecomment-7182549862). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:23:16Z. --- <!-- victory-triage v1 head=061e7a6cbbb989649c4c140d1eaa919e65112db3 verdict=merge-candidate at=2026-11-26T04:23:09Z --> Automated triage for the maintainers. **Merge candidate.** `Lower::source_active` (`emit/lower.rs`) caches the source-lane activity ballot per (DXIL block, EXEC predicate), so DPP and swizzle ops in one block share one `waveActiveBallot`. The reuse is sound: live host lanes in a block change only at a discard, and every discard now goes through `emit_discard`, which clears the cache. `dpp8_in_one_block_shares_the_source_activity_ballot` checks the lane results against the CPU reference and the ballot count. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 06:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:33:07Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • Diff review: Caching dx.op.waveActiveBallot results per (block, guard) in source_ballots and invalidating the cache inside emit_discard (when discarded lanes turn into helpers) cleanly eliminates redundant source-lane activity ballots within the same block without breaking pixel-discard semantics.
  • cargo test -p victory-shader emit::crosslane_tests -- --test-threads=1 (RTX 5090): 6 passed, 0 failed (including dpp8_in_one_block_shares_the_source_activity_ballot).
  • VICTORY_WARP=1 cargo test -p victory-shader emit::crosslane_tests -- --test-threads=1 (WARP): 6 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6069024852 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2924#pullrequestreview-6069024852). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:33:07Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Caching `dx.op.waveActiveBallot` results per `(block, guard)` in `source_ballots` and invalidating the cache inside `emit_discard` (when discarded lanes turn into helpers) cleanly eliminates redundant source-lane activity ballots within the same block without breaking pixel-discard semantics. - `cargo test -p victory-shader emit::crosslane_tests -- --test-threads=1` (RTX 5090): 6 passed, 0 failed (including `dpp8_in_one_block_shares_the_source_activity_ballot`). - `VICTORY_WARP=1 cargo test -p victory-shader emit::crosslane_tests -- --test-threads=1` (WARP): 6 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2924:upstream-pr/2924'
git switch 'upstream-pr/2924'

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/2924'
git switch 'upstream-pr/2924'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2924'
git switch 'upstream-pr/2924'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2924'
git switch 'main'
git merge --squash 'upstream-pr/2924'
git switch 'main'
git merge --ff-only 'upstream-pr/2924'
git switch 'main'
git merge 'upstream-pr/2924'
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!2922
No description provided.