Shaders: a lane-mask join of masks and numbers, read as a number #1407
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1407
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1407"
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?
@marquezinii on GitHub · 2026-11-24 17:47 UTC · original
marquezinii:shader/lane-mask-elsewhere→main· +421 −6 · 4 files · 1 commits · openUpdate (2026-11-25, head
ad8e76a):main'smask_numbernow covers masks holding lanes elsewhere, so the first part below (the~WaveActiveBallot(true)fallback) has been dropped. This PR now adds only the second part, the per-lane-checked join of masks and numbers. Details are in the latest comment.Two lane-mask reads that were refused now lower in compute programs.
A mask set in every lane outside EXEC where it is written.
s_not_b32of a compare inside a branch, or the saved EXEC without the current one (s_andn2_b32 s20, s6, exec_lo), holds lanes that do not run the writing block, so the ballot there missed them ("a lane mask holding lanes elsewhere read as data"). When the analysis proves that every lane with EXEC clear at the write has its bit set, the mask is now the ballot of the lanes that run there, plus every lane that does not (~WaveActiveBallot(true)). Compute only, where host lane n is console lane n (reading a mask as a number already fixes the wave size).A join of masks read by a VALU instruction.
s20 = 0; if (lane < 10) s20 = (lane < 5); v1 = s20failed with "a lane mask read as data": only scalar instructions andv_cndmaskresolved mask joins, so av_mov_b32 v1, s20after the branch saw an untracked value. VALU reads of a join now resolve it too. Reading it as a number takes each lane's own incoming mask, sostructureonly allows that before the first loop (where a block'sreachis exactly the lanes that get there) and when every lane's own mask is the wave's: the wave leaves a join from its last predecessor in program order, so a lane arriving over an edge must find the mask of every later edge there.s20 = 0before the branch passes (the compare is clear in the lanes that skip it);s20 = -1before it, or a mask both arms of an if/else write, is still refused, and a test checks each. A constant joined in is taken by its lane bit only in joins that passed this check.How I checked it
lane_mask_tests.rshas five tests on synthetic wave32 programs (32 lanes,v0is the lane):s_notof a compare in a branch counted withs_bcnt1(27), the lanes that skipped a branch read as a number (0xFFFFFC00), and a compare from a branch read after the join (0x1F);On an RTX 5070 (driver 621.40), all five pass. The GPU tests skip a device that does not run 32-lane waves (they ask
D3D12_OPTIONS1for the wave lane range): WARP and the CI's adapter, where creating the pipeline failed in the first CI run. Without the per-lane check, both refusal tests fail (the programs lower).cargo test --workspace --lockedpasses andcargo clippy --workspace --all-targets --locked -- -D warningsis clean.rustfmt --checkpasses on the new file. The diffs it reports instructure.rsandlower.rsare lines already on main.Not checked: wave64 programs on a GPU (NVIDIA runs no 64-lane waves), and the change against the title's shaders, since I have no dump. Masks accumulated in a loop are still refused ("a lane-mask join of an untracked mask").
The AnyXboxX notes on the world's black image (
docs/running-gta6.md) name "a lane mask holding lanes elsewhere read as data" among the refusals of the compute passes that produce the meshExecuteIndirectarguments, which start at zero. That is why I picked these patterns.@geiyiliyabumo on GitHub · 2026-11-24 18:03 UTC · original
Independent verification of \855757\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200, native wave32 + wave64) / Rust 1.98.1 MSVC:
AI-assisted; synthetic tests only, no game files.
@sinan-cmyk on GitHub · 2026-11-24 19:50 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
a855757ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.5 programs move from "a lane mask holding lanes elsewhere read as data" to later failures.
Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 125, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@marquezinii on GitHub · 2026-11-24 19:56 UTC · original
Thanks for running it on the dump. So these patterns are not what stops those programs: 5 programs only get past this refusal and then fail on something else. Could you post which reasons those 5 now fail with? That tells me where to look next. #1420 (the loop case, stacked on this one) would be worth the same comparison, if you have the time.
@kappalegoat on GitHub · 2026-11-24 21:49 UTC · original
Three open PRs lift the same lane-mask refusals; a note for whoever reviews them.
#1407 (this one), #1423 and #1270 all target the refusals that FIND-6 in #1633 lists ("a lane mask holding lanes elsewhere read as data", "a select on an untracked mask"):
mask_dword.v_cndmask_b32selects ("a select on an untracked mask").On an RTX 5070 (Blackwell, driver 621.24, Windows 11), each head's
cargo test -p victory-shader --lockedpasses: #1407 125 passed, #1423 121 passed, #1270 123 passed, 0 failed. All three are 28 commits behindmain(70564ae).git merge-treeof each pair, and againstmain:mainSo #1407 and #1423 overlap in code as well as in purpose, and all three need a rebase. #1270 and #1423 combine cleanly. I did not run the combinations or count refusals on a shader archive.
No game files used. AI-assisted (Claude Code).
@marquezinii on GitHub · 2026-11-24 22:05 UTC · original
Rebased onto
main70564ae(heade193474). @kappalegoat, thanks for the map; it changes what this PR is worth.Since
8af0472("lane masks spilled and combined in compute programs"),mainhasmask_number. It replays the scalar op that writes a mask on its operands' numbers, which is the lazy evaluation #1423 proposes. So most of the "holding lanes elsewhere" refusal is now handled onmainitself. To check what is left, I ran this PR's lane-mask tests (emit::lane_mask_tests) against plainmainon an RTX 5070 (driver 621.40):maina_compare_from_a_branch_reads_as_a_number_after_the_joinmainrefuses "a register joining a lane mask and data")So in the rebase,
main'smask_numbergoes first. The ballot with the outside lanes added is kept only as a fallback, for a mask whose writing opmask_numbercannot replay. What this PR still adds is the per-lane-checked join of masks and numbers, and the loop case stacked on it in #1420. I resolved the conflicts that way rather than putting my version back overmain's.cargo test -p victory-shader --lockedon the RTX 5070: 214 passed, 3 failed, 2 ignored. The 3 failures (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware) fail the same way on plainmain70564aeon this card, so they come frommain, not from this PR.cargo clippy -p victory-shader: clean.@sinan-cmyk's dump run found no count change on the old base; with
mainnow covering the replayable masks, a fresh offline count would tell whether the join case alone still moves any program.@Marvisak on GitHub · 2026-11-25 02:38 UTC · original · edited 2026-11-25 16:04 UTC
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
@marquezinii on GitHub · 2026-11-25 04:41 UTC · original
Following the triage: I took the first option and dropped the
outsidefallback. It was the ballot with~WaveActiveBallot(true)OR-ed in whenmask_numberfails, and no test reached it. The PR is now one commit,ad8e76a, rebased onmain940d32f. What it adds is only the per-lane-checked join of masks and numbers:joined_masks/per_laneinstructure.rs, and thenumbersfallback in the mask-join arm oflower.rs, now taken only where the join is inactive. Masks holding lanes elsewhere are left entirely tomask_number.On an RTX 5070 (driver 621.40):
cargo test -p victory-shader --locked -- lane_mask: 6 passed.a_compare_from_a_branch_reads_as_a_number_after_the_joinand the two refusal tests pass, and the "elsewhere" tests pass throughmask_number.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.cargo test -p victory-shader --locked: 3 failures.stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardwarefail the same way on plainmain940d32fon this card. CI'sgathers_at_a_level…andpermutes_read_the_lane_named…failures are also outside this PR, as the triage notes.The overlap with #1423 now comes down to
mask_dword's refusal message: this PR no longer changes how a mask holding lanes elsewhere is read.@Mericas77 on GitHub · 2026-11-25 09:40 UTC · original
Tested
ad8e76aon an RTX 4070 (driver 32.0.16.2101,dxil.dll1.9.2602.17 from SDK 10.0.26100), plus a read of the diff.lane_mask_testson the PR head: 5/5 pass. The three GPU tests ran on the 4070 with DXIL validation; WARP skipped each one (no 32-lane waves).A/B with
structure.rsandlower.rstaken frommain940d32f: onlya_compare_from_a_branch_reads_as_a_number_after_the_joinfails (a lane mask read as data, offset 56). The other four pass onmainas well: the two negated/andn2tests cover whatmain'smask_numberalready does (as your update says), and the two refusal tests pass trivially there becausemainrefuses both programs anyway. So the new code is exercised by one positive GPU test; the refusal tests only guard it once the change is in. Maybe worth saying in the description, or adding a second positive case.Crate:
cargo test --locked -p victory-shadergives 249 passed / 3 failed on the PR head vs 244 / 3 onmain940d32f, same 3 failures on both (the known NVIDIA ones:stride_testsby_element and where_no_buffer_view,gathers_at_a_level_match_the_hardware). No new failure.Two extra cases I tried on the lowering only (no GPU), both behave as expected:
vcc = lanes < 20before the branch,s20 = vcccopied only inside the branch (lanes < 10),s20 = 0otherwise, read after the join: refused (lanes 10-19 would read their own 0 while the wave's s20 has their bit). Good.s20 = exec_loinside the branch, 0 before, read after the join: lowers.Nit:
Structured::numbersis built from exactly the same map as the existingStructured::other(self.other.iter().map(|(&(lo, _), &m)| (lo, m))), solower.rscould readst.otherinstead of adding a field.AI-assisted.
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.