xshader: read whole lane masks where a program counts one #197
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/brcly--TuxBox!197
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-197"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Jerkin42 on GitHub · 2026-11-25 21:03 UTC · original
Jerkin42:fix/mask-ballots→main· +831 −10 · 15 files · 2 commits · openSummary
A translated thread holds only its own bit of a lane mask, in the register's bit 0. Instructions that use a mask as a number see that single bit:
s_bcnt1andv_mbcntgave 0 or 1 for a whole wave, ands_ff1always gave lane 0.Compute programs use these to hand out list slots, so every thread got one of the same few slots. In ProjectScarlett this hits the shadow mask tiles: lit surfaces and people showed 16-pixel blocks. With the first version of this change their shadows were smooth in the game. The shadow tile passes are among the programs the current version changes, but I have not rerun the game with it.
The masks such instructions read are found by their reaching definitions. The wave's ballot is taken right after each definition and the counting instruction reads that. It is only taken where every lane that can be in the mask runs together: not in code that a branch on another mask skips or repeats, and not after some lanes have left the program. Both words of a wave64 mask have to come from the same definitions. A register that holds anything else on some path keeps the old translation, and so does a group that is not made of whole waves.
The program then runs in waves of the guest's width:
WaveSize(32)orWaveSize(64). A wave64 program therefore needs an adapter with wave64. The alternative, reading half a wave on a 32-lane host, gives different counts. #201's portable Wave64 lowering could lift this later. Ray tracing resolve programs keep whole masks already and are left alone. Shader Model 6.5 is used where a ballot is taken.Over the 24,463 ProjectScarlett programs I have, 76 change and none is newly refused. 33 of them, among them the shadow tile passes, now require wave64.
Verified on Lanes
python tuxbox.py checkpassed on this branchGPU, driver and backend: RX 9060 XT, RADV (Mesa 26.1.8), Proton Experimental
The same seven cases fail on plain main (
7b22d71) on this machine, where I run the check in a private Xwayland inside a container. The branch only touches the translator. The full check above ran on the second commit.Not a Lanes scenario because it is about single instructions. A new GPU check,
mask-ballots, assembles 300 small programs, runs them and compares every word with a reference: 300 of 300 pass. On plain main 200 of the 300 give wrong words. The unit tests cover each review point, and each of the six new ones fails on the first commit.Checks
cargo checkof tuxbox-d3d12 for x86_64-pc-windows-msvcdocs/SHADERS.mdhas a paragraph on it🤖 Generated with Claude Code
@tsunderejay on GitHub · 2026-11-25 21:15 UTC · original
Static review against current main found multiple high-risk correctness issues before merge: (1) 64-bit counts can combine a captured low mask with a stale high word; (2) implicit scalar writes such as v_readfirstlane and VOP3B carry outputs are missing from reaching definitions; (3) WaveActiveBallot cannot reconstruct a 64-lane mask on a wave32 host, so the advertised wave64 fallback changes results; (4) partial waves can produce wrong counts because the width requirement is applied after complete-wave validation; (5) operand width is used as wave-width evidence, causing false SGPR aliases; (6) captures under divergent control flow do not see the whole wave; (7) high-word ballot names/declarations are incomplete. Please address these with focused regressions before merging.
@Jerkin42 on GitHub · 2026-11-26 01:41 UTC · original
Ai
Thanks, these were right, and fixing them turned up a worse problem. All in
1270654:both_words_of_a_mask_come_from_the_same_place).v_readfirstlane(VOP1 and VOP3),v_readlaneand VOP3B carries (withv_mad_*64andv_div_scale) now count as writes, and a VOP2 carry writes VCC (every_scalar_write_is_seen).WaveSize(64), so a host without wave64 refuses it as it does other wave64 requirements. 33 programs need it, the shadow tile passes among them. #201's portable lowering could lift that later.partial_waves_keep_the_old_translation).v_mbcnt_hiin a 32-lane program) means no ballots (a_pair_is_not_a_mask_of_32_lanes). I found no wave-size field in the extract. If there is one, I'll use it.lanes_that_parted_are_not_counted).The worse problem: ray tracing resolve programs (
resolve_wave32) already keep whole masks, so the first version's ballot of one lane's bit broke about 1,000 of them. They're excluded now (resolve_counts_its_whole_masks). The branch now changes 76 programs instead of 1,179. Each of the six new mask tests fails on the first commit, andmask-ballots(300 cases) andlockstep(245) pass on the GPU.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.