xshader: run lane-read loops that spill scalars as paired waves #546

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

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


#492 runs a constant lane read in a non-uniform loop as a paired wave, but refuses a program that also spills scalars with v_writelane_b32. ProjectScarlett's five transmission-volumetrics programs are of that kind: one whole wave64 per group, sums over the wave in a loop lanes leave at different times, and SGPR spills.

  • Admit the documented v_writelane_b32 in the whole-wave proof. Like v_readlane_b32 it ignores EXEC and takes one scalar of the wave. Barrier, branch, width and encoding requirements are unchanged.
  • Keep each spilled scalar of such a program in a scalar of its own, so the resource dataflow follows a spilled descriptor. A register anything else may touch stays a vector. A lane read's destination also becomes the scalar it names: otherwise the dataflow keeps what that scalar held before.
  • v_cvt_f32_f64 takes an aligned scalar pair.

Only programs refused today change. The explicit wave32-host paired form is left as it was.

Tested

  • New unit tests; 11 mutations of the change each make one fail (three repeated on 70781497). python tuxbox.py check --no-gpu: passed on 70781497 (4198b48c).

  • All recorded requests (47,526 containers, compute also with --wave32-host, 1,908 linked pairs, and the runtime's stride retry) on f482572a: 17 compute programs newly accepted, none newly refused, none changed. All 17 compile and pass dxv (DXC 1.9.2609.5, without -fnew-inlining-behavior).

  • Of 5,366 recorded compute requests, the 1,999 that contain either affected instruction were translated before and after, plain and with --wave32-host: 17 newly translate, none newly refused, 1,685 accepted outputs byte-identical.

  • The five programs compile without -fnew-inlining-behavior and pass dxv at DXC 1.9.2609.5. Times at load 20: 11 to 69 s on the CLI, 9 to 60 s with the helper, so the largest (Submerged) sits at the runtime's 60 s -O1 limit. On f482572a (70781497's patch) its three recordings took 75, 89 and 126 s at load 10 to 13, so compilation at -O0 looks likely there. With the flag, all five fail validation (Instructions must be of an allowed type, at <2 x i32> vectors): the helper's output is rejected, the CLI's retry fails too, and the runtime drops the flag. The trigger is the soft-f64 helper tb_f64_unpack, whose out uint2 is written in three branches. A change that builds it from scalars avoids it (14 lines, tried on lavapipe, not in this PR because it changes the HLSL of every f64 program).

  • lavapipe, with the wave intrinsics replaced by group-shared exchanges: the three new check_paired_wave64.py programs match its model in 64-thread groups. main refuses them.

  • check_paired_wave64.py (branch merged into main 39463ea5): RTX 5090 (10de:2b85, 620.70.10) and AMD iGPU (1002:13c0, RADV): 84 programs, all words match the model on both, including the nine new cases (spill, spill with vector registers, f64 sums; 1, 2 and 4 waves).

  • Full python tuxbox.py check of ab18a46c (rebased onto e5d2e913; three lint fixes, no change in behaviour; HLSL of 1,597 random and the 17 named programs unchanged): RTX 5090 (10de:2b85, 620.70.10) 200 pass, 0 fail; AMD iGPU (1002:13c0, RADV) 199 pass, 0 fail. GE-Proton11-14.

Known hazard, not touched here: main's explicit wave32-host paired form can bind an old buffer after a lane read overwrites a loaded descriptor (a synthetic test shows it); none of 217 recorded programs with an accepted paired output shows a difference at a memory instruction.

Game (RTX 5090 10de:2b85, 620.70.10, GE-Proton11-14; an integration build of 007b982d with this and other open PRs, two runs): the five pipelines finished compiling in the driver, in the second run (a part-filled driver cache) after 6, 6, 24, 31 and 407 s. In the first, with a cold cache, four finished after 41 to 268 s and the largest (4.1 MB DXIL) was still compiling, for over five minutes, when the run ended. Until then they're stand-ins.

On an RX 9070 XT (RDNA 4, @Kayotic1337, with this and other PRs), four of the five finished compiling in the driver in 6 to 12 s; the fifth (0a927142) isn't in that log, which only names pipelines that took 5 s or more.

Not run: the programs in a drawn frame; nothing yet shows them dispatched. No claim about the picture or speed.

Prepared with AI assistance.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5555159982 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T21:10:55Z. --- #492 runs a constant lane read in a non-uniform loop as a paired wave, but refuses a program that also spills scalars with `v_writelane_b32`. ProjectScarlett's five transmission-volumetrics programs are of that kind: one whole wave64 per group, sums over the wave in a loop lanes leave at different times, and SGPR spills. - Admit the documented `v_writelane_b32` in the whole-wave proof. Like `v_readlane_b32` it ignores EXEC and takes one scalar of the wave. Barrier, branch, width and encoding requirements are unchanged. - Keep each spilled scalar of such a program in a scalar of its own, so the resource dataflow follows a spilled descriptor. A register anything else may touch stays a vector. A lane read's destination also becomes the scalar it names: otherwise the dataflow keeps what that scalar held before. - `v_cvt_f32_f64` takes an aligned scalar pair. Only programs refused today change. The explicit wave32-host paired form is left as it was. ## Tested - New unit tests; 11 mutations of the change each make one fail (three repeated on 70781497). `python tuxbox.py check --no-gpu`: passed on 70781497 (4198b48c). - All recorded requests (47,526 containers, compute also with `--wave32-host`, 1,908 linked pairs, and the runtime's stride retry) on f482572a: 17 compute programs newly accepted, none newly refused, none changed. All 17 compile and pass dxv (DXC 1.9.2609.5, without `-fnew-inlining-behavior`). - Of 5,366 recorded compute requests, the 1,999 that contain either affected instruction were translated before and after, plain and with `--wave32-host`: 17 newly translate, none newly refused, 1,685 accepted outputs byte-identical. - The five programs compile without `-fnew-inlining-behavior` and pass dxv at DXC 1.9.2609.5. Times at load 20: 11 to 69 s on the CLI, 9 to 60 s with the helper, so the largest (Submerged) sits at the runtime's 60 s -O1 limit. On f482572a (70781497's patch) its three recordings took 75, 89 and 126 s at load 10 to 13, so compilation at -O0 looks likely there. **With the flag, all five fail validation** (`Instructions must be of an allowed type`, at `<2 x i32>` vectors): the helper's output is rejected, the CLI's retry fails too, and the runtime drops the flag. The trigger is the soft-f64 helper `tb_f64_unpack`, whose `out uint2` is written in three branches. A change that builds it from scalars avoids it (14 lines, tried on lavapipe, not in this PR because it changes the HLSL of every f64 program). - lavapipe, with the wave intrinsics replaced by group-shared exchanges: the three new `check_paired_wave64.py` programs match its model in 64-thread groups. `main` refuses them. - `check_paired_wave64.py` (branch merged into main 39463ea5): RTX 5090 (`10de:2b85`, 620.70.10) and AMD iGPU (`1002:13c0`, RADV): 84 programs, all words match the model on both, including the nine new cases (spill, spill with vector registers, f64 sums; 1, 2 and 4 waves). - Full `python tuxbox.py check` of ab18a46c (rebased onto e5d2e913; three lint fixes, no change in behaviour; HLSL of 1,597 random and the 17 named programs unchanged): RTX 5090 (`10de:2b85`, 620.70.10) 200 pass, 0 fail; AMD iGPU (`1002:13c0`, RADV) 199 pass, 0 fail. GE-Proton11-14. **Known hazard, not touched here:** main's explicit wave32-host paired form can bind an old buffer after a lane read overwrites a loaded descriptor (a synthetic test shows it); none of 217 recorded programs with an accepted paired output shows a difference at a memory instruction. **Game** (RTX 5090 `10de:2b85`, 620.70.10, GE-Proton11-14; an integration build of 007b982d with this and other open PRs, two runs): the five pipelines finished compiling in the driver, in the second run (a part-filled driver cache) after 6, 6, 24, 31 and 407 s. In the first, with a cold cache, four finished after 41 to 268 s and the largest (4.1 MB DXIL) was still compiling, for over five minutes, when the run ended. Until then they're stand-ins. On an RX 9070 XT (RDNA 4, @Kayotic1337, with this and other PRs), four of the five finished compiling in the driver in 6 to 12 s; the fifth (`0a927142`) isn't in that log, which only names pipelines that took 5 s or more. **Not run:** the programs in a drawn frame; nothing yet shows them dispatched. No claim about the picture or speed. Prepared with AI assistance. Evidence: TuxBox check of ab18a46cb6b4, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run Evidence: TuxBox check of ab18a46cb6b4, 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:03 +00:00 (Migrated from github.com)

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


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:7265616349 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546#issuecomment-7265616349). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T00:50:03Z. --- 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.
NickStallman commented 2026-11-30 01:20:18 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T01:20:18Z.


Thanks, that's useful, and you're right that it doesn't show the programs dispatched. The log names programs by source digest and, for compute pipelines, by request. Filter on these:

Programs Source digest
TransmissionVolumetrics* (#546) 07e0061f, 0a927142, 3f81993d, 4efd015d, f9c81a48
GenerateShadowMasks* and ComputeStickyLips (#548) 1a703579, a3c29b75, ae88c100, d7965490 (the four I recorded for the masks)

On an RTX 5090, our log has the first five compiled in the driver after 6 to 407 s (they're stand-ins until then) and none of the other four at all. Neither log of ours shows a dispatch. If yours names any of the nine, I'd like to know whether as "unsupported", "queued" or "finished".

<!-- greyfinch-sync:brcly/TuxBox:comment:7266051744 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546#issuecomment-7266051744). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T01:20:18Z. --- Thanks, that's useful, and you're right that it doesn't show the programs dispatched. The log names programs by source digest and, for compute pipelines, by request. Filter on these: | Programs | Source digest | |---|---| | `TransmissionVolumetrics*` (#546) | `07e0061f`, `0a927142`, `3f81993d`, `4efd015d`, `f9c81a48` | | `GenerateShadowMasks*` and `ComputeStickyLips` (#548) | `1a703579`, `a3c29b75`, `ae88c100`, `d7965490` (the four I recorded for the masks) | On an RTX 5090, our log has the first five compiled in the driver after 6 to 407 s (they're stand-ins until then) and none of the other four at all. Neither log of ours shows a dispatch. If yours names any of the nine, I'd like to know whether as "unsupported", "queued" or "finished".
Kayotic1337 commented 2026-11-30 02:01:44 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by Kayotic1337 on 2026-11-30T02:01:44Z.


Thanks, filtering on those works. Both runs from my comment above (0102 cold, 0142 warm, same build with #546 and #548), RX 9070 XT:

#546: four of the five appear, all as compute pipelines that finished in the driver:

Source Request Translation (cold run) Driver (warm run)
f9c81a48 ecd781dc… compiled; fast path dxc failed (5) -> without-inlining finished in 7 s
07e0061f b5fb0324… compiled; dxc failed (5) -> without-inlining finished in 7 s
3f81993d e8570a69… compiled; fast path timed out -> O0 finished in 12 s
4efd015d 1564849c… compiled; dxc failed (5) -> without-inlining finished in 6 s (cold run)
0a927142 not in either log

Each of the four logs "still running 5s" before "finished", and big_stack.rs only logs a pipeline that takes 5 s or more (unless its request is traced). So 0a927142 may simply have been faster, and its absence doesn't show it was refused. None is logged as unsupported.

#548: none of 1a703579, a3c29b75, ae88c100 or d7965490 appears in either log: not as unsupported, queued or finished.

As in your logs, I see nothing that shows a dispatch of any of the nine. Both runs ended in the first cutscene (int_prolo).

<!-- greyfinch-sync:brcly/TuxBox:comment:7266643715 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546#issuecomment-7266643715). Originally posted by [Kayotic1337](https://github.com/Kayotic1337) on 2026-11-30T02:01:44Z. --- Thanks, filtering on those works. Both runs from my comment above (`0102` cold, `0142` warm, same build with #546 and #548), RX 9070 XT: **#546**: four of the five appear, all as compute pipelines that **finished** in the driver: | Source | Request | Translation (cold run) | Driver (warm run) | |---|---|---|---| | `f9c81a48` | `ecd781dc…` | compiled; fast path `dxc failed (5)` -> without-inlining | finished in 7 s | | `07e0061f` | `b5fb0324…` | compiled; `dxc failed (5)` -> without-inlining | finished in 7 s | | `3f81993d` | `e8570a69…` | compiled; fast path `timed out` -> O0 | finished in 12 s | | `4efd015d` | `1564849c…` | compiled; `dxc failed (5)` -> without-inlining | finished in 6 s (cold run) | | `0a927142` | | not in either log | | Each of the four logs "still running 5s" before "finished", and `big_stack.rs` only logs a pipeline that takes 5 s or more (unless its request is traced). So `0a927142` may simply have been faster, and its absence doesn't show it was refused. None is logged as unsupported. **#548**: none of `1a703579`, `a3c29b75`, `ae88c100` or `d7965490` appears in either log: not as unsupported, queued or finished. As in your logs, I see nothing that shows a dispatch of any of the nine. Both runs ended in the first cutscene (`int_prolo`).
brcly commented 2026-11-30 04:12:15 +00:00 (Migrated from github.com)

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


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:7268561289 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546#issuecomment-7268561289). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T04:12:15Z. --- 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 11:22:44 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T11:22:44Z.


Merged into main as 3926959e (squashed and credited to you). Thanks, and thanks @Kayotic1337 for the RDNA 4 runs.

Checked here:

  • Corpus: 18 gained (46,664 requests, plain translation), 0 lost, 0 changed.
  • Validation: all 18 compile and pass dxv. The 12 smaller programs pass at -O3; the six large volumetrics programs pass at -O1, and the largest also at -O0.

Compile cost, for whoever picks up the speed side next. On a 16-core machine at load 3 to 4, the four ~3.3 MB HLSL programs took about 12 minutes each at -O1 (six compiles in parallel), and two smaller ones took about 3 minutes. That's far slower than the 11 to 69 s you saw, so in the runtime they'll always miss the 60 s -O1 limit and fall back to -O0. For 3f81993d, -O0 takes 35 s at a 3.3 GB peak and gives 5.3 MB of DXIL. That DXIL is what the driver then spends minutes on, as in your cold 5090 run. Your tb_f64_unpack scalar rewrite, or anything else that shrinks these programs, would be well worth a follow-up.

<!-- greyfinch-sync:brcly/TuxBox:comment:7276942117 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/546#issuecomment-7276942117). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T11:22:44Z. --- Merged into main as 3926959e (squashed and credited to you). Thanks, and thanks @Kayotic1337 for the RDNA 4 runs. Checked here: - **Corpus:** 18 gained (46,664 requests, plain translation), 0 lost, 0 changed. - **Validation:** all 18 compile and pass dxv. The 12 smaller programs pass at -O3; the six large volumetrics programs pass at -O1, and the largest also at -O0. **Compile cost, for whoever picks up the speed side next.** On a 16-core machine at load 3 to 4, the four ~3.3 MB HLSL programs took about **12 minutes each at -O1** (six compiles in parallel), and two smaller ones took about 3 minutes. That's far slower than the 11 to 69 s you saw, so in the runtime they'll always miss the 60 s -O1 limit and fall back to -O0. For `3f81993d`, -O0 takes **35 s at a 3.3 GB peak** and gives 5.3 MB of DXIL. That DXIL is what the driver then spends minutes on, as in your cold 5090 run. Your `tb_f64_unpack` scalar rewrite, or anything else that shrinks these programs, would be well worth a follow-up.

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!546
No description provided.