xshader: run lane permutes behind branches with the whole wave #548

Closed
NickStallman wants to merge 1 commit from upstream-pr/548 into main
NickStallman commented 2026-11-29 21:28:10 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T21:28:10Z.


The branch is 5b3975d3 on f482572a; the patch is identical to 69596066 (39463ea5) and 58198ae6 (97f21fad), which earlier results below name.

A 32-lane compute program whose ds_bpermute_b32 sits behind a branch was refused. Where nothing else translates it, it now takes the whole-wave translation that lane reads in divergent loops already use. Every branch is proved to be uniform or is voted across the wave, so every lane reaches the permute and holds the value and EXEC bit another lane reads. A program that mixes masks and numbers is still refused, and so is ds_permute_b32 behind a branch.

To run the programs that use it:

  • v_and_b32 of the wave's mask with a lane's own bit takes the ballot (32-lane waves only).
  • A DPP8, row_mirror or quad_perm first source feeds any short vector instruction. quad_perm needs FI or BOUND_CTRL, full masks and no modifiers.
  • A lane read by number is allowed under the block dispatcher, which this translation keeps together.

It recovers four CS_GenerateShadowMasks_* programs and CS_ComputeStickyLips in ProjectScarlett. Of the recorded programs, only those 15 requests (three recordings of each) change.

Rebase onto e5d2e913 (eb8c05a9): main's formatting put pipeline.rs over 1,200 lines, so the retry wrapper is now lockstep::translate_outputs, the branch test lockstep::permutes_apart, and the main path translate_outputs_before_lockstep. The logic is the same, and the HLSL of 1,600 random recorded jobs and the 15 programs is identical to the old head's.

Tested

  • Recorded requests (6,170 compute, 11,537 request/host pairs), on 97f21fad: 10,923 translate before, 10,953 after. 30 pairs recovered, 0 lost, 0 outputs changed, 0 refusal reasons changed, so no recorded program that translates today recompiles. All 15 recovered passed DXC and DXV (at most 1.9 s and 243 KB DXIL for those measured) on the 2d6dc338 output.
  • The same survey of all recorded requests on f482572a (47,526 containers, linked pairs, stride retry): 15 compute programs newly accepted, none newly refused, none changed; all 15 compile and pass dxv.
  • Unit tests for the permute, the dispatcher, the DPP controls, the 64-lane refusal and the ds_permute_b32 refusal. Nine mutations each fail a unit test (three repeated after the rebase onto 4198b48c).
  • check_lockstep_gpu.py gains four programs. Off the GPU, the emitted HLSL of 11 lockstep programs, those four included, matches the reference model in 336 input cases each on a 32-lane CPU simulator that fails when lanes diverge at a wave operation (repeated on 4198b48c). These are synthetic programs.
  • check_lockstep_gpu.py on 69596066: RTX 5090 (10de:2b85, 620.70.10) and AMD iGPU (1002:13c0, RADV): 720 cases, 276,480 words, all match the reference on both, with the four new programs.
  • python tuxbox.py check --no-gpu at 58198ae6: passed.
  • Full python tuxbox.py check of eb8c05a9 (rebased onto e5d2e913; retry code moved for the line limit, HLSL unchanged, see the rebase note above): RTX 5090 (10de:2b85, 620.70.10) 200 pass, 0 fail; AMD iGPU (1002:13c0, RADV) 199 pass, 0 fail. GE-Proton11-14.

Not run: driver compile time, and the game for these programs. Game logs on an RTX 5090 (our integration builds) and an RX 9070 XT (@Kayotic1337) name none of the four shadow-mask programs, neither as unsupported, queued nor finished; the 5090 runs ended on a loading screen. So nothing yet shows the game using them. Host lane n being thread n of the wave is assumed, as in the existing wave lowerings.

Evidence: TuxBox check of eb8c05a9d8, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run
Evidence: TuxBox check of eb8c05a9d8, no uncommitted changes, GPU 1002:13c0: 16 passed, 0 failed, 0 not run

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5555306106 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/548). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T21:28:10Z. --- The branch is 5b3975d3 on f482572a; the patch is identical to 69596066 (39463ea5) and 58198ae6 (97f21fad), which earlier results below name. A 32-lane compute program whose `ds_bpermute_b32` sits behind a branch was refused. Where nothing else translates it, it now takes the whole-wave translation that lane reads in divergent loops already use. Every branch is proved to be uniform or is voted across the wave, so every lane reaches the permute and holds the value and EXEC bit another lane reads. A program that mixes masks and numbers is still refused, and so is `ds_permute_b32` behind a branch. To run the programs that use it: - `v_and_b32` of the wave's mask with a lane's own bit takes the ballot (32-lane waves only). - A DPP8, row_mirror or quad_perm first source feeds any short vector instruction. quad_perm needs FI or BOUND_CTRL, full masks and no modifiers. - A lane read by number is allowed under the block dispatcher, which this translation keeps together. It recovers four `CS_GenerateShadowMasks_*` programs and `CS_ComputeStickyLips` in ProjectScarlett. Of the recorded programs, only those 15 requests (three recordings of each) change. **Rebase onto e5d2e913 (eb8c05a9):** main's formatting put `pipeline.rs` over 1,200 lines, so the retry wrapper is now `lockstep::translate_outputs`, the branch test `lockstep::permutes_apart`, and the main path `translate_outputs_before_lockstep`. The logic is the same, and the HLSL of 1,600 random recorded jobs and the 15 programs is identical to the old head's. ## Tested - **Recorded requests** (6,170 compute, 11,537 request/host pairs), on 97f21fad: 10,923 translate before, 10,953 after. 30 pairs recovered, 0 lost, 0 outputs changed, 0 refusal reasons changed, so no recorded program that translates today recompiles. All 15 recovered passed DXC and DXV (at most 1.9 s and 243 KB DXIL for those measured) on the 2d6dc338 output. - The same survey of all recorded requests on f482572a (47,526 containers, linked pairs, stride retry): 15 compute programs newly accepted, none newly refused, none changed; all 15 compile and pass dxv. - Unit tests for the permute, the dispatcher, the DPP controls, the 64-lane refusal and the `ds_permute_b32` refusal. Nine mutations each fail a unit test (three repeated after the rebase onto 4198b48c). - `check_lockstep_gpu.py` gains four programs. Off the GPU, the emitted HLSL of 11 lockstep programs, those four included, matches the reference model in 336 input cases each on a 32-lane CPU simulator that fails when lanes diverge at a wave operation (repeated on 4198b48c). These are synthetic programs. - `check_lockstep_gpu.py` on 69596066: RTX 5090 (`10de:2b85`, 620.70.10) and AMD iGPU (`1002:13c0`, RADV): 720 cases, 276,480 words, all match the reference on both, with the four new programs. - `python tuxbox.py check --no-gpu` at 58198ae6: passed. - Full `python tuxbox.py check` of eb8c05a9 (rebased onto e5d2e913; retry code moved for the line limit, HLSL unchanged, see the rebase note above): RTX 5090 (`10de:2b85`, 620.70.10) 200 pass, 0 fail; AMD iGPU (`1002:13c0`, RADV) 199 pass, 0 fail. GE-Proton11-14. **Not run:** driver compile time, and the game for these programs. Game logs on an RTX 5090 (our integration builds) and an RX 9070 XT (@Kayotic1337) name none of the four shadow-mask programs, neither as unsupported, queued nor finished; the 5090 runs ended on a loading screen. So nothing yet shows the game using them. Host lane n being thread n of the wave is assumed, as in the existing wave lowerings. Evidence: TuxBox check of eb8c05a9d8d3, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run Evidence: TuxBox check of eb8c05a9d8d3, no uncommitted changes, GPU 1002:13c0: 16 passed, 0 failed, 0 not run 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Kayotic1337 commented 2026-11-30 00:50:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-30T00:50:04Z.


Game runs on an RX 9070 XT (1002:7550, RDNA 4, RADV / Mesa 26.3.1, GE-Proton11-14, Linux 7.3.6). Build: main f482572a + #557 + #546 (70781497) + #548 (58198ae6) + #535 (fbbe6e0e), all merged cleanly.

  • Cold run (2271 s, full recompile): 0 failed pipelines. The worker reported 338 new unsupported translations, against 349 in an earlier run on f360038d without these PRs. That is roughly the 5 + 5 programs these PRs recover, but the runs differ in length and the log only names programs by hash, so I can't say which programs these are.
  • Warm run (363 s, TUXBOX_XMEM_PRIVATE_VIEWS=1): the menus run at about 300 presents per 10 s. It reaches frame 2716 of the first cutscene (int_prolo), then hits the same compute TCP write permission fault (0x741041) I saw on main before these PRs.
  • No new GPU faults, hangs or pipeline failures in either run. So nothing gets worse on RDNA 4, but I can't show that the recovered programs were dispatched. If there's a way to map the hashes to names, I'm happy to rerun and check.
<!-- greyfinch-sync:brcly/TuxBox:comment:7265616605 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/548#issuecomment-7265616605). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T00:50:04Z. --- Game runs on an RX 9070 XT (`1002:7550`, RDNA 4, RADV / Mesa 26.3.1, GE-Proton11-14, Linux 7.3.6). Build: `main` `f482572a` + #557 + #546 (`70781497`) + #548 (`58198ae6`) + #535 (`fbbe6e0e`), all merged cleanly. - **Cold run** (2271 s, full recompile): 0 failed pipelines. The worker reported 338 new unsupported translations, against 349 in an earlier run on `f360038d` without these PRs. That is roughly the 5 + 5 programs these PRs recover, but the runs differ in length and the log only names programs by hash, so I can't say which programs these are. - **Warm run** (363 s, `TUXBOX_XMEM_PRIVATE_VIEWS=1`): the menus run at about 300 presents per 10 s. It reaches frame 2716 of the first cutscene (`int_prolo`), then hits the same compute TCP write permission fault (`0x741041`) I saw on `main` before these PRs. - No new GPU faults, hangs or pipeline failures in either run. So nothing gets worse on RDNA 4, but I can't show that the recovered programs were dispatched. If there's a way to map the hashes to names, I'm happy to rerun and check.
brcly commented 2026-11-30 04:12:14 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T04:12:14Z.


Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase.

  • Formatting: the whole workspace is now formatted with rustfmt (see the new rustfmt.toml).
  • Lints: every crate denies unwrap(), lossy as casts and undocumented unsafe outside tests.
  • CI: it now also runs cargo fmt --check, rustdoc with warnings denied, and Miri on the providers' unit tests.

The least painful way is to format your branch first, so the rebase only shows real changes:

git fetch origin
git checkout origin/main -- rustfmt.toml
cargo fmt --all && git commit -am "rustfmt"
git rebase origin/main

Then run python tuxbox.py check --no-gpu, which now includes the format step.

If clippy flags something new:

  • A cast: use From for widening, TryFrom for narrowing, and a mask for bit fields.
  • An unwrap(): use ?, or expect with the reason it can't fail.
  • An unsafe block: it needs a // SAFETY: comment.

CONTRIBUTING's "Code checks" section lists the commands. Thanks!

<!-- greyfinch-sync:brcly/TuxBox:comment:7268560991 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/548#issuecomment-7268560991). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:14Z. --- Heads-up: main just landed a large cleanup (up to e5d2e913), so this PR needs a rebase. - **Formatting:** the whole workspace is now formatted with rustfmt (see the new `rustfmt.toml`). - **Lints:** every crate denies `unwrap()`, lossy `as` casts and undocumented `unsafe` outside tests. - **CI:** it now also runs `cargo fmt --check`, rustdoc with warnings denied, and Miri on the providers' unit tests. The least painful way is to format your branch first, so the rebase only shows real changes: ```sh git fetch origin git checkout origin/main -- rustfmt.toml cargo fmt --all && git commit -am "rustfmt" git rebase origin/main ``` Then run `python tuxbox.py check --no-gpu`, which now includes the format step. If clippy flags something new: - **A cast:** use `From` for widening, `TryFrom` for narrowing, and a mask for bit fields. - **An `unwrap()`:** use `?`, or `expect` with the reason it can't fail. - **An `unsafe` block:** it needs a `// SAFETY:` comment. CONTRIBUTING's "Code checks" section lists the commands. Thanks!
brcly commented 2026-11-30 09:26:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:26:04Z.


Merged into main as 647ef91d (squashed and credited to you), thanks!

What I checked:

  • Recorded requests: all 46,664, squashed onto current main. 19 gained (your 15 plus another recording), 0 lost, 0 changed, no refusal message changed.
  • The 19 gained: each compiles with DXC at cs_6_6 and passes dxv.
  • Tests: the unit tests pass, and clippy is clean on 1.95 and current stable.

Thanks also to @Kayotic1337 for the RDNA 4 game run.

<!-- greyfinch-sync:brcly/TuxBox:comment:7274201252 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/548#issuecomment-7274201252). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T09:26:04Z. --- Merged into main as 647ef91d (squashed and credited to you), thanks! What I checked: - **Recorded requests:** all 46,664, squashed onto current main. 19 gained (your 15 plus another recording), 0 lost, 0 changed, no refusal message changed. - **The 19 gained:** each compiles with DXC at `cs_6_6` and passes dxv. - **Tests:** the unit tests pass, and clippy is clean on 1.95 and current stable. Thanks also to @Kayotic1337 for the RDNA 4 game run.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!548
No description provided.