shader: a strided region's lane privacy is bounded by the LDS window #585

Open
qnjk wants to merge 1 commit from qnjk/Darner:lds-private-window into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: region_strided_private (crates/darner-shader/src/emit/lds.rs:726) accepted a region whose every access is (counter << shift) + off on one condition:

    let Some(m) = n.checked_mul(slot).filter(|&m| m <= 1 << 32) else { return false };
    

    justified by "an address that wraps keeps its residue, as m divides 2^32". LDS has no 2^32-wide window to wrap in: a thread group's shared memory is at most 32 KiB on the host (HOST_LDS_DWORDS = 8,192 dwords, lower.rs:881; more is refused at lower.rs:2722) and 64 KiB on the console. An address that wraps keeps its residue modulo m only when m divides that window, so any period past it aliases two threads the proof called private. The shape the finding gives — threads [64, 1, 1], shift = 11, so a 2 KiB slot and m = 128 KiB — has thread t and thread t + 32 writing the same dword, yet the region was accepted and the !all region split across the two host waves: a silent write/write or read/write miscompile.

  • This change bounds the period by the group's LDS window instead of 2^32. LDS_WINDOW = 1 << 15 is 32 KiB, D3D12's group-shared limit and the only window the translated program has; because it is a power of two it divides the console's 64 KiB window as well, so a period that fits here keeps its property under either reading. A period past the window returns false, so the caller keeps the guard instead of splitting on a false proof, and the doc comment now states why the divisor is the window.

How it was tested

  • Tested revision: 16dfa4e (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-shader --lib -- a_stride_cycle_past_the_lds_window — 1 passed.
    • New emit::lds::tests::a_stride_cycle_past_the_lds_window_is_not_lane_private pins both sides of the bound on 64 threads: shift = 9 (512-byte slot, m = 32 KiB, exactly the window) is still private; shift = 10 (1 KiB slot, 64 KiB) and shift = 11 (2 KiB slot, 128 KiB) are not, because thread t and thread t + 32 are the same dword once the address passes the window.
    • Fail-before, with the old bound restored and the test kept:
      a_stride_cycle_past_the_lds_window_is_not_lane_private panicked at crates\darner-shader\src\emit\lds.rs:4096:
      m = 64 << 10 = 64 KiB is past the 32 KiB LDS window
      test result: FAILED. 0 passed; 1 failed
      
      (the private 32 KiB case passed under the old code, as it must).
    • cargo clippy --locked -p darner-shader --all-targets -- -D warnings passes.
  • Changes a default: no. A period that fits the window is accepted exactly as before; a larger one now keeps its guard.
  • A/B result: not applicable — no default changes and no speed claim. Where the proof fails the guard stays, which is the conservative direction.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here. darner-shader's full lib suite takes ~40 minutes on this machine and contains emit::waterfall_tests, which fails on a clean main (#227); the change was gated by its own test plus clippy. darner-shader is the only crate touched.
  • Gameplay, when relevant: no gameplay run. The change affects whether a region is split across waves; a wrong split is a miscompile that a short run would not prove either way, so no gameplay claim is made.
  • Shader wave sizes tested, when relevant: the test uses 64 threads in one group (a 32-lane host wave pair); the 32-lane single-wave shape takes the same path.
  • Hardware dependence: none — the window is a property of the translation, not the card.
  • Coverage gaps: the same "differ by 64 KiB so they are different bytes" assumption sits under region_disjoint_ranges (lds.rs:745), region_same_constants (:696) and has_provable_shared_waw (:812); they compare constant offsets and do not take the window into account. They are deliberately untouched here (one change per commit) and are the same class of defect — worth a follow-up.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the defect is a wrong wave split, and a short run cannot distinguish a rare dword alias from correct output. The evidence is the test, which fails on main; no frame-rate or visual claim is made.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's 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. No open pull request changes crates/darner-shader/src/emit/lds.rs (checked against the file list of all 189 open pull requests), and no open or closed issue mentions region_strided_private, the LDS window or lane privacy.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `region_strided_private` (`crates/darner-shader/src/emit/lds.rs:726`) accepted a region whose every access is `(counter << shift) + off` on one condition: ```rust let Some(m) = n.checked_mul(slot).filter(|&m| m <= 1 << 32) else { return false }; ``` justified by "an address that wraps keeps its residue, as `m` divides 2^32". LDS has no 2^32-wide window to wrap in: a thread group's shared memory is at most **32 KiB on the host** (`HOST_LDS_DWORDS` = 8,192 dwords, `lower.rs:881`; more is refused at `lower.rs:2722`) and 64 KiB on the console. An address that wraps keeps its residue modulo `m` only when `m` divides that window, so any period past it aliases two threads the proof called private. The shape the finding gives — threads `[64, 1, 1]`, `shift = 11`, so a 2 KiB slot and `m = 128 KiB` — has thread `t` and thread `t + 32` writing the same dword, yet the region was accepted and the `!all` region split across the two host waves: a silent write/write or read/write miscompile. - This change bounds the period by the group's LDS window instead of 2^32. `LDS_WINDOW = 1 << 15` is 32 KiB, D3D12's group-shared limit and the only window the translated program has; because it is a power of two it divides the console's 64 KiB window as well, so a period that fits here keeps its property under either reading. A period past the window returns `false`, so the caller keeps the guard instead of splitting on a false proof, and the doc comment now states why the divisor is the window. ## How it was tested - Tested revision: `16dfa4e` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-shader --lib -- a_stride_cycle_past_the_lds_window` — 1 passed. - New `emit::lds::tests::a_stride_cycle_past_the_lds_window_is_not_lane_private` pins both sides of the bound on 64 threads: `shift = 9` (512-byte slot, `m = 32 KiB`, exactly the window) is still private; `shift = 10` (1 KiB slot, 64 KiB) and `shift = 11` (2 KiB slot, 128 KiB) are not, because thread `t` and thread `t + 32` are the same dword once the address passes the window. - Fail-before, with the old bound restored and the test kept: ``` a_stride_cycle_past_the_lds_window_is_not_lane_private panicked at crates\darner-shader\src\emit\lds.rs:4096: m = 64 << 10 = 64 KiB is past the 32 KiB LDS window test result: FAILED. 0 passed; 1 failed ``` (the private 32 KiB case passed under the old code, as it must). - `cargo clippy --locked -p darner-shader --all-targets -- -D warnings` passes. - Changes a default: no. A period that fits the window is accepted exactly as before; a larger one now keeps its guard. - A/B result: not applicable — no default changes and no speed claim. Where the proof fails the guard stays, which is the conservative direction. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here. `darner-shader`'s full lib suite takes ~40 minutes on this machine and contains `emit::waterfall_tests`, which fails on a clean `main` (#227); the change was gated by its own test plus clippy. `darner-shader` is the only crate touched. - Gameplay, when relevant: no gameplay run. The change affects whether a region is split across waves; a wrong split is a miscompile that a short run would not prove either way, so no gameplay claim is made. - Shader wave sizes tested, when relevant: the test uses 64 threads in one group (a 32-lane host wave pair); the 32-lane single-wave shape takes the same path. - Hardware dependence: none — the window is a property of the translation, not the card. - Coverage gaps: the same "differ by 64 KiB so they are different bytes" assumption sits under `region_disjoint_ranges` (`lds.rs:745`), `region_same_constants` (`:696`) and `has_provable_shared_waw` (`:812`); they compare constant offsets and do not take the window into account. They are deliberately untouched here (one change per commit) and are the same class of defect — worth a follow-up. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the defect is a wrong wave split, and a short run cannot distinguish a rare dword alias from correct output. The evidence is the test, which fails on `main`; no frame-rate or visual claim is made. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's 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. No open pull request changes `crates/darner-shader/src/emit/lds.rs` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions `region_strided_private`, the LDS window or lane privacy. - Replaces or overlaps: none found
`region_strided_private` accepted a region whose every access is
`(counter << shift) + off` on the single condition that the period
`n * slot` fits in 2^32, justified by "an address that wraps keeps its
residue, as m divides 2^32". LDS has no 2^32-wide window to wrap in: a
group's shared memory is at most 32 KiB on the host (HOST_LDS_DWORDS,
lower.rs:881) and 64 KiB on the console, so a period past that window
aliases two threads the proof called private. With threads [64, 1, 1]
and shift 11, thread t and thread t + 32 write the same dword while the
region was split across the two host waves: a silent write/write or
read/write miscompile.

The period is now bounded by LDS_WINDOW (32 KiB, the only window the
translated program has, and a power of two so it divides the console's
window too). A period past it returns false, so the caller keeps the
guard instead of splitting on a false proof.

The test pins both sides on 64 threads: a 32 KiB period is still
private, a 64 KiB and a 128 KiB one are not.
TrustNo1 changed title from [pr-fix][shaders] shader: a strided region's lane privacy is bounded by the LDS window to shader: a strided region's lane privacy is bounded by the LDS window 2026-12-06 03:26:51 +00:00
Owner

Test needed — commit 16dfa4ef; what to check:

  • The problem on main: region_strided_private (crates/darner-shader/src/emit/lds.rs:726) accepted a region whose every access is (counter << shift) + off on one condition:

    let Some(m) = n.checked_mul(slot).filter(|&m| m <= 1 << 32) else { return false };
    

    justified by "an address that wraps keeps its residue, as m divides 2^32". LDS has no 2^32-wide window to wrap in: a thread group's shared memory is at most 32 KiB on the host (HOST_LDS_DWORDS = 8,192 dwords, lower.rs:881; more is refused at lower.rs:2722) and 64 KiB on the console. An address that wraps keeps its residue modulo m only when m divides that window, so any period past it aliases two threads the proof called private. The shape the finding gives — threads [64, 1, 1], shift = 11, so a 2 KiB slot and m = 128 KiB — has thread t and thread t + 32 writing the same dword, yet the region was accepted and the !all region split across the two host waves: a silent write/write or read/write miscompile.

  • This change bounds the period by the group's LDS window instead of 2^32. LDS_WINDOW = 1 << 15 is 32 KiB, D3D12's group-shared limit and the only window the translated prog

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 `16dfa4ef`; what to check: - The problem on main: `region_strided_private` (`crates/darner-shader/src/emit/lds.rs:726`) accepted a region whose every access is `(counter << shift) + off` on one condition: ```rust let Some(m) = n.checked_mul(slot).filter(|&m| m <= 1 << 32) else { return false }; ``` justified by "an address that wraps keeps its residue, as `m` divides 2^32". LDS has no 2^32-wide window to wrap in: a thread group's shared memory is at most **32 KiB on the host** (`HOST_LDS_DWORDS` = 8,192 dwords, `lower.rs:881`; more is refused at `lower.rs:2722`) and 64 KiB on the console. An address that wraps keeps its residue modulo `m` only when `m` divides that window, so any period past it aliases two threads the proof called private. The shape the finding gives — threads `[64, 1, 1]`, `shift = 11`, so a 2 KiB slot and `m = 128 KiB` — has thread `t` and thread `t + 32` writing the same dword, yet the region was accepted and the `!all` region split across the two host waves: a silent write/write or read/write miscompile. - This change bounds the period by the group's LDS window instead of 2^32. `LDS_WINDOW = 1 << 15` is 32 KiB, D3D12's group-shared limit and the only window the translated prog 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 'lds-private-window:qnjk-lds-private-window'
git switch 'qnjk-lds-private-window'

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 'qnjk-lds-private-window'
git switch 'qnjk-lds-private-window'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-lds-private-window'
git switch 'qnjk-lds-private-window'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-lds-private-window'
git switch 'Main'
git merge --squash 'qnjk-lds-private-window'
git switch 'Main'
git merge --ff-only 'qnjk-lds-private-window'
git switch 'Main'
git merge 'qnjk-lds-private-window'
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!585
No description provided.