xshader: select what a mesh program's skipped block writes #459

Closed
NickStallman wants to merge 2 commits from upstream-pr/459 into main
NickStallman commented 2026-11-29 08:53:58 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T08:53:58Z.


On hold: the control in #458 doesn't support the explanation below. Please don't merge on it.

Summary

A forward branch of a translated mesh program that votes across its group is if (tb_skip < T) { ... }. On an RTX 5090 (620.70.10) the first lanes of the group then get wrong values in registers the block sets, although no lane skips it. This is #458.

With this change such a block is not a block:

  • each register write selects on the skip, including exec, vcc, scc, tb_skip and loop conditions;
  • memory reads, stores, atomics and heap handles keep a branch of one statement, and a read's value is selected;
  • arms of a nested if are handled the same way;
  • a block the pass cannot parse is left as it was (none in the recorded shaders).

It runs on the text after select_writes, in mesh programs that use the lane votes, on every host. control_flow.rs is not touched.

Tested

Translated programs against their compute forms, all vertex counts up to the limit, every export:

Program before, RTX 5090 after, RTX 5090 AMD iGPU, before and after
program 1 wrong right right
program 2 wrong right right
program 3 wrong right right
program 4 right right right

The last three had bindless resources stubbed. As compute the new output equals the old on lavapipe for the first three.

Survey of 47,367 recorded requests, main (75453953) and this change:

Changed 13,852 of 19,866 mesh programs, all of which vote
Other programs changed 0
Newly refused 0
Guarded blocks left 0
Register writes left in a skip's branch 0

DXC 1.8.2505.1, 600 of the changed programs at random and the 10 largest, 0 errors, the same number of barriers:

600 10 largest
DXIL bytes +0.6% (worst one +9.3%) +3.6%
instruction lines +2.6% +5.8%
phis 353,410 to 171,036 43,713 to 22,400
compile time +31% (160 to 210 s) +70% (worst one 3.6 to 6.9 s)

Checks: python tuxbox.py check --no-gpu passed at 2b5bc898. Full tuxbox.py check at 2b5bc898: RTX 5090 (620.70.10) 181 pass, 0 fail; AMD iGPU (RADV) 180 pass, 0 fail, guest-present-4k-splash skipped. Held as a draft: the control below doesn't support the explanation, and no game run has been done. translated-mesh has new cases skip-16, skip-64, skip-112. They don't fail with main's emitter: 41 live-value counts, translated with and without the change, were all right on the 5090, so the cases are correctness tests, not regression tests. No Lanes scenario: a title mesh shader is not part of Lanes; the check covers it on the GPU.

Two of the unit tests fail with the pass off.

Not measured

  • GPU time and frame time.
  • A game run with this change. In a swap test of one shader (always running the one block of program 1, not this change) ProjectScarlett device losses whose fault program counter ends in 0x70 were 5 of 10 with the original and 0 of 10 with that shader swapped (one-sided Fisher p = 0.016).
  • Other NVIDIA cards and drivers, a discrete AMD card.
  • Why the driver gets it wrong. A control with the criterion set beforehand came out against this PR's explanation: on 64 edits of the reduced shaders, 45 wrong, changes that keep the branches (selects elsewhere, four more live values) made all 45 right, as removing the branch does (#458). So the change avoids the fault in the programs tested, but the branch isn't shown to be the trigger, and other programs can fail in a shape this leaves alone. Helper inlining, the driver's optimiser and reconvergence modes don't fix the reduced shaders.

Risk

First-use compile time. In the tests each job is one process on a cold cache, so this is about the time of one pipeline plus start-up: program 4 took 7.9 s before and 11.5 s after on the 5090, 1.0 and 1.2 s on AMD; program 2 1.8 and 2.2 s; program 3 1.8 and 1.9 s; program 1 1.5 and 1.6 s. Of the changed programs 117 have at least 700 KB of HLSL before the change (program 4 has 753 KB), 846 at least 500 KB, and half are under 105 KB.
On lavapipe program 4 did not finish creating its pipeline in 240 s (7 s before). RADV and NVIDIA do not show that.
The DXIL in the store and every driver cache entry of the 13,852 programs changes, so they recompile once.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5549180999 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/459). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T08:53:58Z. --- **On hold: the control in #458 doesn't support the explanation below. Please don't merge on it.** ## Summary A forward branch of a translated mesh program that votes across its group is `if (tb_skip < T) { ... }`. On an RTX 5090 (620.70.10) the first lanes of the group then get wrong values in registers the block sets, although no lane skips it. This is #458. With this change such a block is not a block: - each register write selects on the skip, including exec, vcc, scc, `tb_skip` and loop conditions; - memory reads, stores, atomics and heap handles keep a branch of one statement, and a read's value is selected; - arms of a nested `if` are handled the same way; - a block the pass cannot parse is left as it was (none in the recorded shaders). It runs on the text after `select_writes`, in mesh programs that use the lane votes, on every host. `control_flow.rs` is not touched. ## Tested Translated programs against their compute forms, all vertex counts up to the limit, every export: | Program | before, RTX 5090 | after, RTX 5090 | AMD iGPU, before and after | | --- | --- | --- | --- | | program 1 | wrong | right | right | | program 2 | wrong | right | right | | program 3 | wrong | right | right | | program 4 | right | right | right | The last three had bindless resources stubbed. As compute the new output equals the old on lavapipe for the first three. Survey of 47,367 recorded requests, main (75453953) and this change: | | | | --- | --- | | Changed | 13,852 of 19,866 mesh programs, all of which vote | | Other programs changed | 0 | | Newly refused | 0 | | Guarded blocks left | 0 | | Register writes left in a skip's branch | 0 | DXC 1.8.2505.1, 600 of the changed programs at random and the 10 largest, 0 errors, the same number of barriers: | | 600 | 10 largest | | --- | --- | --- | | DXIL bytes | +0.6% (worst one +9.3%) | +3.6% | | instruction lines | +2.6% | +5.8% | | phis | 353,410 to 171,036 | 43,713 to 22,400 | | compile time | +31% (160 to 210 s) | +70% (worst one 3.6 to 6.9 s) | Checks: `python tuxbox.py check --no-gpu` passed at 2b5bc898. Full `tuxbox.py check` at 2b5bc898: RTX 5090 (620.70.10) 181 pass, 0 fail; AMD iGPU (RADV) 180 pass, 0 fail, guest-present-4k-splash skipped. **Held as a draft:** the control below doesn't support the explanation, and no game run has been done. `translated-mesh` has new cases `skip-16`, `skip-64`, `skip-112`. They don't fail with `main`'s emitter: 41 live-value counts, translated with and without the change, were all right on the 5090, so the cases are correctness tests, not regression tests. No Lanes scenario: a title mesh shader is not part of Lanes; the check covers it on the GPU. Two of the unit tests fail with the pass off. ## Not measured - GPU time and frame time. - A game run with this change. In a swap test of one shader (always running the one block of program 1, not this change) ProjectScarlett device losses whose fault program counter ends in `0x70` were 5 of 10 with the original and 0 of 10 with that shader swapped (one-sided Fisher p = 0.016). - Other NVIDIA cards and drivers, a discrete AMD card. - **Why the driver gets it wrong.** A control with the criterion set beforehand came out against this PR's explanation: on 64 edits of the reduced shaders, 45 wrong, changes that keep the branches (selects elsewhere, four more live values) made all 45 right, as removing the branch does (#458). So the change avoids the fault in the programs tested, but the branch isn't shown to be the trigger, and other programs can fail in a shape this leaves alone. Helper inlining, the driver's optimiser and reconvergence modes don't fix the reduced shaders. ## Risk First-use compile time. In the tests each job is one process on a cold cache, so this is about the time of one pipeline plus start-up: program 4 took 7.9 s before and 11.5 s after on the 5090, 1.0 and 1.2 s on AMD; program 2 1.8 and 2.2 s; program 3 1.8 and 1.9 s; program 1 1.5 and 1.6 s. Of the changed programs 117 have at least 700 KB of HLSL before the change (program 4 has 753 KB), 846 at least 500 KB, and half are under 105 KB. On lavapipe program 4 did not finish creating its pipeline in 240 s (7 s before). RADV and NVIDIA do not show that. The DXIL in the store and every driver cache entry of the 13,852 programs changes, so they recompile once. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-11-29 11:13:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T11:13:04Z.


The control I wanted before un-drafting this came out against it: changes that keep the branches hide the fault in the reduced shaders as often as this does (details). I've put the PR on hold and rewritten its claims. Both full checks pass at 2b5bc898, so it isn't known to break anything, but it isn't an explained fix.

<!-- greyfinch-sync:brcly/TuxBox:comment:7254960014 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/459#issuecomment-7254960014). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T11:13:04Z. --- The control I wanted before un-drafting this came out against it: changes that keep the branches hide the fault in the reduced shaders as often as this does ([details](https://github.com/brcly/TuxBox/issues/458)). I've put the PR on hold and rewritten its claims. Both full checks pass at 2b5bc898, so it isn't known to break anything, but it isn't an explained fix.
NickStallman commented 2026-11-29 13:17:00 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T13:17:00Z.


Closing this, and please don't use it. On an RTX 5090 (620.70.10) it makes programs wrong that are right today. Of two copies of one recorded mesh program (the same HLSL under two keys), base is right and this change's form is wrong in 906 lanes; the third program I compared (285bbd5c) goes the other way. The reason is the one in #458: the fault moves with the instruction stream, and selects are just another stream.

The eight game runs of mine that contained it (builds on 75453953 and d2eb99ed) used that form of those programs, so what they ended on isn't evidence about main. The results I posted about readback, #460, #462, #464, #465 and the copies are about CPU-side data or counts and don't depend on it, but any statement of mine about "how far a run got" from those builds should be read with that in mind.

Superseded by a much smaller change (one xor of the lane number, in the programs that vote) with a population test: 48 of 147 unseen programs wrong as translated, 0 with the change. It will be a separate PR.

<!-- greyfinch-sync:brcly/TuxBox:comment:7256422760 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/459#issuecomment-7256422760). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T13:17:00Z. --- **Closing this, and please don't use it.** On an RTX 5090 (620.70.10) it makes programs wrong that are right today. Of two copies of one recorded mesh program (the same HLSL under two keys), base is right and this change's form is wrong in 906 lanes; the third program I compared (285bbd5c) goes the other way. The reason is the one in #458: the fault moves with the instruction stream, and selects are just another stream. The eight game runs of mine that contained it (builds on 75453953 and d2eb99ed) used that form of those programs, so what they ended on isn't evidence about `main`. The results I posted about readback, #460, #462, #464, #465 and the copies are about CPU-side data or counts and don't depend on it, but any statement of mine about "how far a run got" from those builds should be read with that in mind. Superseded by a much smaller change (one xor of the lane number, in the programs that vote) with a population test: 48 of 147 unseen programs wrong as translated, 0 with the change. It will be a separate PR.

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