keep pair meetings between LDS atomics and subsequent reads #623

Open
RileyW wants to merge 1 commit from RileyW/Darner:pr/paired-lds-order into Main
First-time contributor

Not yet run in-game on this Darner branch (synthetic unit and DXIL validation 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 (crates/darner-shader/src/emit/lower/analysis.rs:1139, lds_order).

In lds_order, both Kind::Read and Kind::Atomic were marked ordered only when writes was true. In a barrier-free piece where an LDS atomic reduction (such as ds_add_u32, ds_min_u32, or ds_max_u32) precedes a plain ds_read_b32 with no plain ds_write in the piece (either in the same piece or across a predecessor piece), both accesses were marked unordered. Under with_pair_meetings, the two 32-lane host halves of a 64-lane console wave could omit the meeting between the atomic and the read, allowing half 0 to read a partial reduction before half 1 executes its atomic.

This change:

  1. Marks a Kind::Read ordered when a non-CAS atomic precedes it in the same piece or in a predecessor piece, and marks that atomic ordered when a read follows it in the same piece or in a successor piece.
  2. Preserves all existing upstream semantics: acyclic read-before-atomic remains unordered/unstable (keeping lds_accesses_after_the_last_plain_write_need_no_meeting), cyclic compare-exchange retry loops (ds_cmpst*) remain unordered, and pure atomic loops remain in out.looped (keeping cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only).
  3. Adds paired_lds_order_keeps_meetings_for_atomic_before_read in crates/darner-shader/src/emit/wave64_tests.rs covering same-piece atomic-before-read, cross-block atomic-before-read, divergent-branch widening under with_pair_meetings, post-barrier read-only pieces, cyclic CAS retry loops, and cyclic non-CAS atomic plus read.

How it was tested

  • Tested revision: 3400e27 (based on c8258f9)
  • Commands and results:
    • cargo test -p darner-shader --lib paired_lds_order_keeps_meetings_for_atomic_before_read --locked (1 passed, DXIL validated by dxil.dll)
    • cargo test -p darner-shader --lib lds_accesses_after_the_last_plain_write_need_no_meeting --locked (1 passed)
    • cargo test -p darner-shader --lib cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only --locked (1 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 multi-wave paired Wave64-to-Wave32 shaders with barrier-free LDS atomic-to-read sequences.
  • A/B result: correctness fix (prevents cross-half RAW races on LDS atomic reductions); not a speed claim.
  • Gates run on that revision: both workspace clippy gates, cargo xtask policy, and targeted darner-shader tests.
  • Gameplay: not yet re-run in-game on this Darner branch.
  • Shader wave sizes tested: 32-lane paired lowering of 64-lane console compute shaders.
  • Hardware dependence: likely general across 32-lane host GPUs (NVIDIA, Intel).
  • Coverage gaps: On Windows 10 22H2, unit test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll, so GPU dispatch in wave64_tests skips while lds_order, paired widening, and dxil.dll validation all run.

Checklist

  • I ran this change in the game, or say below why it cannot be (unit and DXIL validation 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: #585 (touches emit/lds.rs only; this PR touches emit/lower/analysis.rs and emit/wave64_tests.rs).
  • Replaces or overlaps: none found.
Not yet run in-game on this Darner branch (synthetic unit and DXIL validation 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 (crates/darner-shader/src/emit/lower/analysis.rs:1139, lds_order). In lds_order, both Kind::Read and Kind::Atomic were marked ordered only when writes was true. In a barrier-free piece where an LDS atomic reduction (such as ds_add_u32, ds_min_u32, or ds_max_u32) precedes a plain ds_read_b32 with no plain ds_write in the piece (either in the same piece or across a predecessor piece), both accesses were marked unordered. Under with_pair_meetings, the two 32-lane host halves of a 64-lane console wave could omit the meeting between the atomic and the read, allowing half 0 to read a partial reduction before half 1 executes its atomic. This change: 1. Marks a Kind::Read ordered when a non-CAS atomic precedes it in the same piece or in a predecessor piece, and marks that atomic ordered when a read follows it in the same piece or in a successor piece. 2. Preserves all existing upstream semantics: acyclic read-before-atomic remains unordered/unstable (keeping lds_accesses_after_the_last_plain_write_need_no_meeting), cyclic compare-exchange retry loops (ds_cmpst*) remain unordered, and pure atomic loops remain in out.looped (keeping cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only). 3. Adds paired_lds_order_keeps_meetings_for_atomic_before_read in crates/darner-shader/src/emit/wave64_tests.rs covering same-piece atomic-before-read, cross-block atomic-before-read, divergent-branch widening under with_pair_meetings, post-barrier read-only pieces, cyclic CAS retry loops, and cyclic non-CAS atomic plus read. ## How it was tested - Tested revision: 3400e27 (based on c8258f9) - Commands and results: - cargo test -p darner-shader --lib paired_lds_order_keeps_meetings_for_atomic_before_read --locked (1 passed, DXIL validated by dxil.dll) - cargo test -p darner-shader --lib lds_accesses_after_the_last_plain_write_need_no_meeting --locked (1 passed) - cargo test -p darner-shader --lib cs_sort_ray_tiles_divergent_loop_atomics_stay_wave32_with_fence_only --locked (1 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 multi-wave paired Wave64-to-Wave32 shaders with barrier-free LDS atomic-to-read sequences. - A/B result: correctness fix (prevents cross-half RAW races on LDS atomic reductions); not a speed claim. - Gates run on that revision: both workspace clippy gates, cargo xtask policy, and targeted darner-shader tests. - Gameplay: not yet re-run in-game on this Darner branch. - Shader wave sizes tested: 32-lane paired lowering of 64-lane console compute shaders. - Hardware dependence: likely general across 32-lane host GPUs (NVIDIA, Intel). - Coverage gaps: On Windows 10 22H2, unit test binaries without Agility SDK exports see SM 0x65 from system d3d12.dll, so GPU dispatch in wave64_tests skips while lds_order, paired widening, and dxil.dll validation all run. ## Checklist - [ ] I ran this change in the game, or say below why it cannot be (unit and DXIL validation 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: #585 (touches emit/lds.rs only; this PR touches emit/lower/analysis.rs and emit/wave64_tests.rs). - Replaces or overlaps: none found.
TrustNo1 changed title from [pr-fix][shaders] keep pair meetings between LDS atomics and subsequent reads to keep pair meetings between LDS atomics and subsequent reads 2026-12-06 03:26:01 +00:00
Owner

Test needed — commit 3400e276; what to check:

  • The problem on main: read from code (crates/darner-shader/src/emit/lower/analysis.rs:1139, lds_order).

In lds_order, both Kind::Read and Kind::Atomic were marked ordered only when writes was true. In a barrier-free piece where an LDS atomic reduction (such as ds_add_u32, ds_min_u32, or ds_max_u32) precedes a plain ds_read_b32 with no plain ds_write in the piece (either in the same piece or across a predecessor piece), both accesses were marked unordered. Under with_pair_meetings, the two 32-lane host halves of a 64-lane console wave could omit the meeting between the atomic and the read, allowing half 0 to read a partial reduction before half 1 executes its atomic.

This change:

  1. Marks a Kind::Read ordered when a non-CAS atomic precedes it in the same piece or in a predecessor piece, and marks that atomic ordered when a read follows it in the same piece or in a successor piece.
  2. Preserves all existing upstream semantics: acyclic read-before-atomic remains unordered/unstable (keeping lds_accesses_after_the_last_plain_write_need_no_meeting), cyclic compare-exchange retry loops (ds_cmpst*) remain unordered, and pure atomic loops remain in out.looped (keeping cs_sort_ray_tiles_d

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 `3400e276`; what to check: - The problem on main: read from code (crates/darner-shader/src/emit/lower/analysis.rs:1139, lds_order). In lds_order, both Kind::Read and Kind::Atomic were marked ordered only when writes was true. In a barrier-free piece where an LDS atomic reduction (such as ds_add_u32, ds_min_u32, or ds_max_u32) precedes a plain ds_read_b32 with no plain ds_write in the piece (either in the same piece or across a predecessor piece), both accesses were marked unordered. Under with_pair_meetings, the two 32-lane host halves of a 64-lane console wave could omit the meeting between the atomic and the read, allowing half 0 to read a partial reduction before half 1 executes its atomic. This change: 1. Marks a Kind::Read ordered when a non-CAS atomic precedes it in the same piece or in a predecessor piece, and marks that atomic ordered when a read follows it in the same piece or in a successor piece. 2. Preserves all existing upstream semantics: acyclic read-before-atomic remains unordered/unstable (keeping lds_accesses_after_the_last_plain_write_need_no_meeting), cyclic compare-exchange retry loops (ds_cmpst*) remain unordered, and pure atomic loops remain in out.looped (keeping cs_sort_ray_tiles_d 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/paired-lds-order:RileyW-pr/paired-lds-order'
git switch 'RileyW-pr/paired-lds-order'

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/paired-lds-order'
git switch 'RileyW-pr/paired-lds-order'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'RileyW-pr/paired-lds-order'
git switch 'RileyW-pr/paired-lds-order'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'RileyW-pr/paired-lds-order'
git switch 'Main'
git merge --squash 'RileyW-pr/paired-lds-order'
git switch 'Main'
git merge --ff-only 'RileyW-pr/paired-lds-order'
git switch 'Main'
git merge 'RileyW-pr/paired-lds-order'
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!623
No description provided.