deduplicate equivalent wrexec loop mask phis #625

Open
RileyW wants to merge 1 commit from RileyW/Darner:pr/wrexec-mask-phis into Main
First-time contributor

Not yet run in-game on this Darner branch (synthetic wave32 and wave64 unit tests run on this revision; previously verified on RTX 3080 SM86 in a downstream fork).

What it changes

  • The problem on main: read from code and synthetic waterfall reproduction (crates/darner-shader/src/structure.rs:1096, Lanes::join).

When a guarded s_andn2_wrexec descriptor waterfall loop misses Tracer::waterfall_shape (for example because of extra work in the loop body) and enters with a non-constant EXEC mask (so neither value = true nor value = false holds across the entry reach), Lanes::join creates two distinct PhiJoin atoms: one for EXEC and one for the saved remaining-mask SGPR initialized from EXEC and updated identically by the same s_wrexec instruction on the back-edge. Because the two Atom::Phi nodes differ, the general BDD waterfall recognizer cannot prove the retry mask equals waiting-and-not-selected and fails to recognize the waterfall.

This change:

  1. Adds Lanes::equivalent_phi_join in crates/darner-shader/src/structure.rs, deduplicating a mask phi against an existing PhiJoin at the same block when every forward edge has the exact same resolved Bool mask and every back-edge either has the same SSA key or pairs EXEC with the scalar destination written identically by the same s_wrexec_b32 or s_wrexec_b64 instruction.
  2. Adds guarded_wrexec_waterfall_missed_by_shape_is_recognized_via_phi_dedup in crates/darner-shader/src/resource.rs testing both wave32 and wave64: verifies by_shape returns None, st.phi_masks deduplicates to 1, waterfall recognition succeeds, and a negative control with a differing initial mask is rejected.

How it was tested

  • Tested revision: 4f1b93c (based on c8258f9)
  • Commands and results:
    • cargo test -p darner-shader --lib structure::tests --locked (16 passed)
    • cargo test -p darner-shader --lib resource::tests --locked (61 passed)
    • cargo clippy --workspace --all-targets --locked -- -D warnings (0 warnings)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (0 warnings)
    • cargo xtask policy and cargo xtask policy --staged (ok)
  • Changes a default: yes, for all hosts (deduplicates provably identical wrexec loop mask phis during structuring).
  • A/B result: correctness fix (enables waterfall recognition on guarded wrexec loops missed by waterfall_shape); not a speed claim.
  • Gates run on that revision: both workspace clippy gates, cargo xtask policy, structure::tests, and resource::tests.
  • Gameplay: not yet re-run in-game on this Darner branch.
  • Shader wave sizes tested: wave32 and wave64 in resource::tests.
  • Hardware dependence: general (CPU shader structuring and resource tracking).
  • Coverage gaps: unit tests only on this revision; in-game Darner run pending.

Checklist

  • I ran this change in the game, or say below why it cannot be (CPU structuring and resource tests run; in-game Darner run pending).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found.
  • Replaces or overlaps: none found.
Not yet run in-game on this Darner branch (synthetic wave32 and wave64 unit tests run on this revision; previously verified on RTX 3080 SM86 in a downstream fork). ## What it changes - The problem on main: read from code and synthetic waterfall reproduction (crates/darner-shader/src/structure.rs:1096, Lanes::join). When a guarded s_andn2_wrexec descriptor waterfall loop misses Tracer::waterfall_shape (for example because of extra work in the loop body) and enters with a non-constant EXEC mask (so neither value = true nor value = false holds across the entry reach), Lanes::join creates two distinct PhiJoin atoms: one for EXEC and one for the saved remaining-mask SGPR initialized from EXEC and updated identically by the same s_*_wrexec_* instruction on the back-edge. Because the two Atom::Phi nodes differ, the general BDD waterfall recognizer cannot prove the retry mask equals waiting-and-not-selected and fails to recognize the waterfall. This change: 1. Adds Lanes::equivalent_phi_join in crates/darner-shader/src/structure.rs, deduplicating a mask phi against an existing PhiJoin at the same block when every forward edge has the exact same resolved Bool mask and every back-edge either has the same SSA key or pairs EXEC with the scalar destination written identically by the same s_*_wrexec_b32 or s_*_wrexec_b64 instruction. 2. Adds guarded_wrexec_waterfall_missed_by_shape_is_recognized_via_phi_dedup in crates/darner-shader/src/resource.rs testing both wave32 and wave64: verifies by_shape returns None, st.phi_masks deduplicates to 1, waterfall recognition succeeds, and a negative control with a differing initial mask is rejected. ## How it was tested - Tested revision: 4f1b93c (based on c8258f9) - Commands and results: - cargo test -p darner-shader --lib structure::tests --locked (16 passed) - cargo test -p darner-shader --lib resource::tests --locked (61 passed) - cargo clippy --workspace --all-targets --locked -- -D warnings (0 warnings) - cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (0 warnings) - cargo xtask policy and cargo xtask policy --staged (ok) - Changes a default: yes, for all hosts (deduplicates provably identical wrexec loop mask phis during structuring). - A/B result: correctness fix (enables waterfall recognition on guarded wrexec loops missed by waterfall_shape); not a speed claim. - Gates run on that revision: both workspace clippy gates, cargo xtask policy, structure::tests, and resource::tests. - Gameplay: not yet re-run in-game on this Darner branch. - Shader wave sizes tested: wave32 and wave64 in resource::tests. - Hardware dependence: general (CPU shader structuring and resource tracking). - Coverage gaps: unit tests only on this revision; in-game Darner run pending. ## Checklist - [ ] I ran this change in the game, or say below why it cannot be (CPU structuring and resource tests run; in-game Darner run pending). - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. - Replaces or overlaps: none found.
TrustNo1 changed title from [pr-fix][shaders] deduplicate equivalent wrexec loop mask phis to deduplicate equivalent wrexec loop mask phis 2026-12-06 03:25:59 +00:00
Owner

Test needed — commit 4f1b93c0; what to check:

  • The problem on main: read from code and synthetic waterfall reproduction (crates/darner-shader/src/structure.rs:1096, Lanes::join).

When a guarded s_andn2_wrexec descriptor waterfall loop misses Tracer::waterfall_shape (for example because of extra work in the loop body) and enters with a non-constant EXEC mask (so neither value = true nor value = false holds across the entry reach), Lanes::join creates two distinct PhiJoin atoms: one for EXEC and one for the saved remaining-mask SGPR initialized from EXEC and updated identically by the same s_wrexec instruction on the back-edge. Because the two Atom::Phi nodes differ, the general BDD waterfall recognizer cannot prove the retry mask equals waiting-and-not-selected and fails to recognize the waterfall.

This change:

  1. Adds Lanes::equivalent_phi_join in crates/darner-shader/src/structure.rs, deduplicating a mask phi against an existing PhiJoin at the same block when every forward edge has the exact same resolved Bool mask and every back-edge either has the same SSA key or pairs EXEC with the scalar destination written identically by the same s_wrexec_b32 or s_wrexec_b64 instruction.
  2. Adds guarded_wrexec_waterfall_missed

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `4f1b93c0`; what to check: - The problem on main: read from code and synthetic waterfall reproduction (crates/darner-shader/src/structure.rs:1096, Lanes::join). When a guarded s_andn2_wrexec descriptor waterfall loop misses Tracer::waterfall_shape (for example because of extra work in the loop body) and enters with a non-constant EXEC mask (so neither value = true nor value = false holds across the entry reach), Lanes::join creates two distinct PhiJoin atoms: one for EXEC and one for the saved remaining-mask SGPR initialized from EXEC and updated identically by the same s_*_wrexec_* instruction on the back-edge. Because the two Atom::Phi nodes differ, the general BDD waterfall recognizer cannot prove the retry mask equals waiting-and-not-selected and fails to recognize the waterfall. This change: 1. Adds Lanes::equivalent_phi_join in crates/darner-shader/src/structure.rs, deduplicating a mask phi against an existing PhiJoin at the same block when every forward edge has the exact same resolved Bool mask and every back-edge either has the same SSA key or pairs EXEC with the scalar destination written identically by the same s_*_wrexec_b32 or s_*_wrexec_b64 instruction. 2. Adds guarded_wrexec_waterfall_missed Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 'pr/wrexec-mask-phis:RileyW-pr/wrexec-mask-phis'
git switch 'RileyW-pr/wrexec-mask-phis'

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 'RileyW-pr/wrexec-mask-phis'
git switch 'RileyW-pr/wrexec-mask-phis'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'RileyW-pr/wrexec-mask-phis'
git switch 'RileyW-pr/wrexec-mask-phis'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'RileyW-pr/wrexec-mask-phis'
git switch 'Main'
git merge --squash 'RileyW-pr/wrexec-mask-phis'
git switch 'Main'
git merge --ff-only 'RileyW-pr/wrexec-mask-phis'
git switch 'Main'
git merge 'RileyW-pr/wrexec-mask-phis'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!625
No description provided.