Shaders: reuse source-lane activity ballots #2922
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2924"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.waveActiveBallotcalls 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, andv3 = 0x00010000 + lane. With EXEC narrowed to lanes where(lane & 3) != 3, it runs DPP8v_mov_b32 v2, v1followed by DPP8v_add_nc_u32 v2, v2, v3. Both use selectors[1, 0, 3, 2, 5, 4, 7, 6]andfi:0. It restores EXEC and storesv2at byte offset4 * lane. The exact GFX10 instruction words are below.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 localdxil.dllPipeline State Validation failures:emit::rect::tests::rectangles_get_their_fourth_corneremit::tests::elements_sharing_a_row_keep_their_ordercargo 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.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:23:35Z.
Review: COMMENTED
Verified head
061e7a6ccleanly onorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + Windows SDK 10.0.26100.0dxil.dll).Cache Soundness Review
source_ballots: HashMap<(usize, V), [V; 2]>by(self.cur, bit)(current DXIL basic block + interned SSAEXECguardV) safely prevents stale reuse acrossEXECchanges (s_and_saveexec/s_xor/v_cmpxproduce distinctVunless structurally identical), block splits (newself.cur), and pixel-shaderdiscard(emit_discardclearssource_ballots), while guaranteeing dominance within the block.emit/lower.rsis521,115 B(3,173 Bbelow 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 (includingdpp8_in_one_block_shares_the_source_activity_ballot, verifying both hardware output andwave_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.
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.
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 onewaveActiveBallot. The reuse is sound: live host lanes in a block change only at a discard, and every discard now goes throughemit_discard, which clears the cache.dpp8_in_one_block_shares_the_source_activity_ballotchecks the lane results against the CPU reference and the ballot count.CI: passing.
Generated by Claude Code
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):dx.op.waveActiveBallotresults per(block, guard)insource_ballotsand invalidating the cache insideemit_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 (includingdpp8_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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.