fold: a thread group with one z gives its third thread id zero #652

Open
qnjk wants to merge 1 commit from qnjk/Darner:fold-thread-group-third-id into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: the fold admits a thread group whose sides are not powers of two when it has one z — if !flat_x && !(pow2(tx) && (pow2(ty) || tz == 1)) (crates/darner-shader/src/fold.rs:1475), so an 8 × 3 × 1 group folds — but the prologue wrote its third console thread id as a shift by ly = ty.trailing_zeros(), and trailing_zeros is log2 only for a power of two. With ty = 3 the folded code computed id.z = flat >> 3, i.e. the y id, where the console's id.z = flat / (tx * ty) is 0 for every thread of the group (flat < 24). Every folded program of such a group that declares three thread-id VGPRs (ComputeIo::thread_id_vgprs() == 3) then read a z the console never produced, and ir::build and oracle64 both index v2 with it. The y id was unharmed (a shift by lx alone, and flat < tx * ty keeps it below ty).

  • This change writes 0 for the third id when tz == 1 — the console's value for every thread of such a group — and keeps the shift for tz != 1, which the guard already limits to a power of two.

How it was tested

  • Tested revision: ef6314b (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-shader --lib -- fold — 33 passed, 0 failed.
    • New test oracle64::tests::a_thread_group_of_no_power_of_two_folds_the_consoles_three_ids: it folds an 8 × 3 × 1 group whose program stores all three thread ids, runs the folded program through the model, and checks the ids each thread gets against the console formula — which is 0 for z.
    • Fail-before, with the old shift restored: the test fails on the first thread whose z the console says is 0 and the fold said otherwise.
    • cargo clippy --locked -p darner-shader --all-targets -- -D warnings passes.
  • Changes a default: no. A group whose y side is a power of two takes the same path as before; only the non-power-of-two shape with one z changes, and it now matches the console.
  • A/B result: not applicable — no default change and no speed claim.
  • 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: the crate's fold tests are green; the full darner-shader suite is minutes long because of the pre-existing exhaustive oracle sweep (see #619), and the whole-workspace run is not green on this machine for the pre-existing darner-gpu reasons (#224, #150), neither of which this touches.
  • Gameplay, when relevant: no gameplay run. The shape is a thread group with a non-power-of-two y and one z; no visual or frame-rate claim is made.
  • Shader wave sizes tested, when relevant: the group is 8 × 3 × 1 console threads, folded onto the host's 32-lane waves; the 64-lane folded shape is covered by the existing fold tests.
  • Hardware dependence: none.
  • Coverage gaps: only the 8 × 3 × 1 shape is pinned; other non-power-of-two sides with one z (for example 3 × 8 × 1) take the same new branch but are not covered, and the tz != 1 path is unchanged and only covered by its existing tests.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the miscomputed id would show as a wrong dispatch in a folded program of that shape, which a short run cannot isolate. The evidence is the test, which fails on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md (cargo xtask policy: passes).
  • 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: #312 changes crates/darner-shader/src/fold.rs; it does not mention the prologue's thread ids. No open or closed issue mentions a thread group's third id or a non-power-of-two group.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: the fold admits a thread group whose sides are not powers of two when it has one z — `if !flat_x && !(pow2(tx) && (pow2(ty) || tz == 1))` (`crates/darner-shader/src/fold.rs:1475`), so an 8 × 3 × 1 group folds — but the prologue wrote its third console thread id as a shift by `ly = ty.trailing_zeros()`, and `trailing_zeros` is `log2` only for a power of two. With `ty = 3` the folded code computed `id.z = flat >> 3`, i.e. the **y** id, where the console's `id.z = flat / (tx * ty)` is 0 for every thread of the group (`flat < 24`). Every folded program of such a group that declares three thread-id VGPRs (`ComputeIo::thread_id_vgprs() == 3`) then read a z the console never produced, and `ir::build` and `oracle64` both index v2 with it. The y id was unharmed (a shift by `lx` alone, and `flat < tx * ty` keeps it below `ty`). - This change writes 0 for the third id when `tz == 1` — the console's value for every thread of such a group — and keeps the shift for `tz != 1`, which the guard already limits to a power of two. ## How it was tested - Tested revision: `ef6314b` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-shader --lib -- fold` — 33 passed, 0 failed. - New test `oracle64::tests::a_thread_group_of_no_power_of_two_folds_the_consoles_three_ids`: it folds an 8 × 3 × 1 group whose program stores all three thread ids, runs the folded program through the model, and checks the ids each thread gets against the console formula — which is 0 for z. - Fail-before, with the old shift restored: the test fails on the first thread whose z the console says is 0 and the fold said otherwise. - `cargo clippy --locked -p darner-shader --all-targets -- -D warnings` passes. - Changes a default: no. A group whose y side is a power of two takes the same path as before; only the non-power-of-two shape with one z changes, and it now matches the console. - A/B result: not applicable — no default change and no speed claim. - 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: the crate's `fold` tests are green; the full `darner-shader` suite is minutes long because of the pre-existing exhaustive oracle sweep (see #619), and the whole-workspace run is not green on this machine for the pre-existing `darner-gpu` reasons (#224, #150), neither of which this touches. - Gameplay, when relevant: no gameplay run. The shape is a thread group with a non-power-of-two y and one z; no visual or frame-rate claim is made. - Shader wave sizes tested, when relevant: the group is 8 × 3 × 1 console threads, folded onto the host's 32-lane waves; the 64-lane folded shape is covered by the existing fold tests. - Hardware dependence: none. - Coverage gaps: only the 8 × 3 × 1 shape is pinned; other non-power-of-two sides with one z (for example 3 × 8 × 1) take the same new branch but are not covered, and the `tz != 1` path is unchanged and only covered by its existing tests. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the miscomputed id would show as a wrong dispatch in a folded program of that shape, which a short run cannot isolate. The evidence is the test, which fails on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md` (`cargo xtask policy`: passes). - [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: #312 changes `crates/darner-shader/src/fold.rs`; it does not mention the prologue's thread ids. No open or closed issue mentions a thread group's third id or a non-power-of-two group. - Replaces or overlaps: none found
The guard admits a thread group whose sides are not powers of two when it
has one z: `if !flat_x && !(pow2(tx) && (pow2(ty) || tz == 1))`, so an
8 x 3 x 1 group folds. The prologue then wrote the third console thread
id as a shift by `log2` of the y side, and `trailing_zeros` is log2 only
for a power of two: with `ty = 3` the folded code computed the y id where
the console's `id.z` is 0 for every thread of the group (`flat < 24`).
Every folded program of such a group that declares three thread-id VGPRs
then read a z the console never produced; `ir::build` and `oracle64` both
index v2 with it. The y id was unharmed.

For a group with one z the console's third id is 0 for every thread, so
the prologue writes 0 there; the shift stays for `tz != 1`, which the
guard already limits to a power of two.

The test folds an 8 x 3 x 1 group, runs it through the model, and checks
the three ids the console would give each thread.
TrustNo1 changed title from [pr-fix][shaders] fold: a thread group with one z gives its third thread id zero to fold: a thread group with one z gives its third thread id zero 2026-12-06 03:25:30 +00:00
Owner

Test needed — commit ef6314bf; what to check:

  • The problem on main: the fold admits a thread group whose sides are not powers of two when it has one z — if !flat_x && !(pow2(tx) && (pow2(ty) || tz == 1)) (crates/darner-shader/src/fold.rs:1475), so an 8 × 3 × 1 group folds — but the prologue wrote its third console thread id as a shift by ly = ty.trailing_zeros(), and trailing_zeros is log2 only for a power of two. With ty = 3 the folded code computed id.z = flat >> 3, i.e. the y id, where the console's id.z = flat / (tx * ty) is 0 for every thread of the group (flat < 24). Every folded program of such a group that declares three thread-id VGPRs (ComputeIo::thread_id_vgprs() == 3) then read a z the console never produced, and ir::build and oracle64 both index v2 with it. The y id was unharmed (a shift by lx alone, and flat < tx * ty keeps it below ty).

  • This change writes 0 for the third id when tz == 1 — the console's value for every thread of such a group — and keeps the shift for tz != 1, which the guard already limits to a power of two.

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 `ef6314bf`; what to check: - The problem on main: the fold admits a thread group whose sides are not powers of two when it has one z — `if !flat_x && !(pow2(tx) && (pow2(ty) || tz == 1))` (`crates/darner-shader/src/fold.rs:1475`), so an 8 × 3 × 1 group folds — but the prologue wrote its third console thread id as a shift by `ly = ty.trailing_zeros()`, and `trailing_zeros` is `log2` only for a power of two. With `ty = 3` the folded code computed `id.z = flat >> 3`, i.e. the **y** id, where the console's `id.z = flat / (tx * ty)` is 0 for every thread of the group (`flat < 24`). Every folded program of such a group that declares three thread-id VGPRs (`ComputeIo::thread_id_vgprs() == 3`) then read a z the console never produced, and `ir::build` and `oracle64` both index v2 with it. The y id was unharmed (a shift by `lx` alone, and `flat < tx * ty` keeps it below `ty`). - This change writes 0 for the third id when `tz == 1` — the console's value for every thread of such a group — and keeps the shift for `tz != 1`, which the guard already limits to a power of two. 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 'fold-thread-group-third-id:qnjk-fold-thread-group-third-id'
git switch 'qnjk-fold-thread-group-third-id'

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-fold-thread-group-third-id'
git switch 'qnjk-fold-thread-group-third-id'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-fold-thread-group-third-id'
git switch 'qnjk-fold-thread-group-third-id'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-fold-thread-group-third-id'
git switch 'Main'
git merge --squash 'qnjk-fold-thread-group-third-id'
git switch 'Main'
git merge --ff-only 'qnjk-fold-thread-group-third-id'
git switch 'Main'
git merge 'qnjk-fold-thread-group-third-id'
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!652
No description provided.