Shaders: a lane mask read as a number keeps the console's bits for the lanes outside a partial group #3917
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!3917
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3917"
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?
@dyshay on GitHub · 2026-11-30 11:30 UTC · original
fix/mask-not-popcount→main· +402 −9 · 2 files · 2 commits · closed without mergingFixes #3916.
What was wrong
On a 32-lane host, the plain wave64 lowering (the default path since folding is off,
5c262d7b) reads a lane mask as a number by taking a ballot of the lanes' booleans (Lower::mask_dword). In a group that is not a multiple of 64 threads (a group of 96: the second console wave has lanes 0..31 only), the lanes that do not exist had no bit, whatever the mask:s_not_b64of a compare has those bits set on the console (the compare writes 0 for lanes outside EXEC, the complement sets them).s_bcnt1_i32_b64of it gave 32 instead of 64 fors0 = 0in the program below, 26 instead of 58 fors0 = 70. The structure takes EXEC on entry as every lane, so the complement looked like a mask set only where lanes run, ands_andn2_b64 exec, vcc(0 there on the console) is the same lane boolean to it: the lane boolean alone cannot say.What this does
crates/victory-shader/src/emit/lower.rsonly; no switch (a correctness fix checked against the console's semantics).Lower::outside_pair: for a compute program with console lanes not in the group (a partial console wave, or lanes past the dispatched count underpartial_active), the two dwords of the mask as the console has them in those lanes, followed back through the instructions that made it: EXEC on entry and VALU compare/carry masks are 0 there;s_mov,s_not,s_and,s_or,s_xor,s_andn2,s_orn2,s_nand,s_nor,s_xnor,s_cselectand the_saveexecforms work on those bits as on the others; inline constants and literals are what they are. A mask made another way (a join, a load) keeps the host's ballot, 0 there, as before. Folded programs and local waves are left as they are.Lower::mask_dword: a lane past the dispatched count takes its bit from that value before the ballot; after the exchange, the bits of the console lanes past the group take it too (fill_outside_lanes).Lower::exchange_halves: a console wave with no upper host wave reads 0 for that half, as its comment already said.Masks with no lanes outside the group, and groups that are a multiple of 64 without a thread count, are lowered as before.
Test
emit::folded_tests::a_mask_complement_counts_the_lanes_outside_the_group_by_default: the program ofa_mask_with_lanes_outside_exec_is_read_as_the_consoles_numberthroughemit()with the default switches (folding off) on a 32-lane host, group of 96,s0in 0, 20, 70, 96:It fails before the change (
lane 64, bcnt of the complement: left 32, right 64) and passes after, on an RTX 4090. It also tries WARP, which does not take aWaveSize(32)program here, so on a machine without a 32-lane card it compiles and validates only.Checks:
victory-shadertests namedfold(24),wave(81, 1 ignored),mask(26), all ok, includingthreads_past_a_dispatch_x_count_do_nothing(s_bcnt1of EXEC past the count stays 0).cargo clippy -p victory-shader --all-targets: no new warning. Diagnostics build ofvictoryok.Credit: found while testing the fold default; ISA semantics from AMD RDNA2.
🤖 Generated with Claude Code
s_bcnt1of a mask complement misses the lanes outside a partial group (32 instead of 64) #3916@mstrmoos on GitHub · 2026-11-30 19:22 UTC · original
Picked onto our branch together with #3896, #3918 and #3894. The merge applied cleanly, and all of victory-gpu's and victory-shader's tests passed (gpu 947, shader 469). Over the following benches on the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, I saw no regressions or visual problems. I didn't measure this PR on its own.
@dyshay on GitHub · 2026-11-30 19:39 UTC · original
@mstrmoos thanks for the clean merge and the test counts. That fits: the fix only changes what a lane mask read as a number gives for lanes outside a partial group, so it shows only in programs that count a complemented mask, and no visible regression is the expected result elsewhere.
s_bcnt1of a mask complement misses the lanes outside a partial group (32 instead of 64) #3916@tyr0nsur on GitHub · 2026-11-30 20:06 UTC · original
A small gap here, found while building #4400 on top of this PR:
outside_dwordstrips only_saveexec_b64and_b64, so a wave32 console's mask operations (s_not_b32 vcc_lo,s_and_saveexec_b32, ...) returnNoneand keep the host's zeros. In a wave32 group of 48 threads,s_bcnt1_i32_b32ofs_not_b32of a compare gave 16 where the console gives 32 (RTX 4060, 32-lane host waves, default switches). A_b32operation works on its dword as the_b64one does on each of its two, so following both suffixes is enough. #4400 carries that fix as684da387, with a test (a_wave32_mask_complement_counts_the_lanes_outside_the_group_by_default), in case you'd rather fold it in here.AI-assisted with Claude Code.
@dyshay on GitHub · 2026-11-30 20:39 UTC · original
@tyr0nsur good catch, thanks. Folding
684da387into this PR (your authorship kept, test included); I'll push once the tests pass here. #4400 can then stack on the updated head.@dyshay on GitHub · 2026-11-30 20:47 UTC · original
Folded in as
628f25de(authored by @tyr0nsur), with the wave32s_bcnt1_i32_b32test. One note: in the test I kept only the popcount check. The SCC check ofs_not_b32depends on yourscc_somework in #4400, so it belongs there (it fails on this PR alone, lane 32 with s0=48: 0 instead of 1). Mask/fold/wave tests: 117 passed on an RTX 4090. Clippy shows 4 lints in files this PR doesn't touch (lower/analysis.rs,native.rs), coming from the base.@VibeCodeGuy on GitHub · 2026-11-30 23:24 UTC · original
Offline corpus check (every shader container in a v1.0.2.1 dump: 25,699 unique programs), this PR at
628f25deagainst its merge-base withmain,41adb551(it does not merge cleanly ontomaine1251c31).The 6 changed programs
25328ea424d08c00CsShallowWaterSim:CS_GenerateDisturbOverlappingPairs53c21e950d143cc7CsavgLuminanceCompute:LuminanceFromHDRBinkCSe18931c72af42e46Csdeferred_lighting:CS_ComputeInfiniteRRIntensity49460c1d1b5fafa0Cssubsurfacescatter:CS_SSSTileClassification665b261b36552c65Cswater_shading:CS_FoamTestDecale81fd01512ba1002CsweatherParticle:CS_UpdateDecalArgsHow:
victory translate <dump> --validate --listbuilt for each side (release, cross-built with cargo-xwin, run under Wine),VICTORY_HOST_WAVE=32, plus the four shader-cache-key settingsplaystarts with (VICTORY_EARLY_DEPTH=1,VICTORY_NAN_SCRUB=1,VICTORY_BVH_MISS=1,VICTORY_SAMPLED_MARKS=1). Validator:dxil.dllfrom DXC v1.9.2609. "Changed" compares translate'semittedhash of each module and its bindings. There was no GPU on this side, so no host pipelines were made and nothing was run on a card. At the merge-base the same run has the same 72 failures: 71 mesh programs over the 32 KiB output limit (the known shortcut inmesh_prologue) andCS_TraceShadowRays_FullAdaptive(#2993).Pull request closed