Skip to content

Shaders: a lane-mask join of masks and numbers, read as a number - #1407

Open
marquezinii wants to merge 1 commit into
Marvisak:mainfrom
marquezinii:shader/lane-mask-elsewhere
Open

marquezinii wants to merge 1 commit into
Marvisak:mainfrom
marquezinii:shader/lane-mask-elsewhere

Conversation

@marquezinii

@marquezinii marquezinii commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Update (2026-11-25, head ad8e76a): main's mask_number now 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_b32 of 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 = s20 failed with "a lane mask read as data": only scalar instructions and v_cndmask resolved mask joins, so a v_mov_b32 v1, s20 after 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, so structure only allows that before the first loop (where a block's reach is 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 = 0 before the branch passes (the compare is clear in the lanes that skip it); s20 = -1 before 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.rs has five tests on synthetic wave32 programs (32 lanes, v0 is the lane):

  • three run on the GPU and compare every lane with the console's result: s_not of a compare in a branch counted with s_bcnt1 (27), the lanes that skipped a branch read as a number (0xFFFFFC00), and a compare from a branch read after the join (0x1F);
  • two check that the unsound joins above are refused.

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_OPTIONS1 for 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 --locked passes and cargo clippy --workspace --all-targets --locked -- -D warnings is clean. rustfmt --check passes on the new file. The diffs it reports in structure.rs and lower.rs are 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 mesh ExecuteIndirect arguments, which start at zero. That is why I picked these patterns.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested head 82ad8ac (fast-forward on main ffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC):

  • cargo test -p victory-shader emit::lower: 11 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: ok (156 files ok)

Clean handling of lane masks and mask joins read as numbers. Approving.

AI-assisted (Gemini 4 Neon).

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Independent verification of \�855757\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200, native wave32 + wave64) / Rust 1.98.1 MSVC:

  • Merge check vs \main\ (\ fe310e): clean
  • \cargo test -p victory-shader --lib lane_mask_tests\ (real RX 9060 XT GPU execution): 5 passed, 0 failed
  • \cargo clippy -p victory-shader --all-targets -- -D warnings\ (default and --all-features): clean
  • \cargo xtask policy: 155 files ok

AI-assisted; synthetic tests only, no game files.

MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 24, 2026
…umbers

Port of upstream Marvisak#1407 (marquezinii, a855757). A mask set in every lane outside EXEC where it is written (s_not of a compare in a branch, saved EXEC without the current one) is the ballot of the lanes there plus every lane not there (~WaveActiveBallot(true)); a join of masks and constants read as a number takes the constant where the join was checked per lane. 39 compute programs refused this way in the user's gameplay log.

Adapted to JMAN730#439: the structure's `numbers` are JMAN730#439's `others`; the console flow keeps its own exchange.

Co-authored-by: CitizenCInema <fredericlaura.fl@pm.me>

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96. GPU/valu execution tests are Windows-gated and were not run here.

Lane masks that hold lanes from elsewhere (negated compares, masks surviving branch joins) now read as numbers: the structure tracks which lanes a mask covers across CFG joins and lower.rs ballots/composes them instead of erroring. New lane_mask_tests.rs (315 lines) with five hardware cases — Windows-gated, so not run here; macOS suite stays green (96).

Note: #1420 adds the same file with the same helpers and the same five tests plus three loop cases — the two PRs conflict textually; whichever lands second needs a rebase (and #1420 looks like the superset).

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head a855757 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 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 --lib passed 125, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@marquezinii

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown

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"):

On an RTX 5070 (Blackwell, driver 621.24, Windows 11), each head's cargo test -p victory-shader --locked passes: #1407 125 passed, #1423 121 passed, #1270 123 passed, 0 failed. All three are 28 commits behind main (70564ae).

git merge-tree of each pair, and against main:

main #1423 #1270
#1407 conflict conflict conflict
#1423 conflict – clean

So #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
marquezinii force-pushed the shader/lane-mask-elsewhere branch from a855757 to e193474 Compare November 24, 2026 22:03
@marquezinii

Copy link
Copy Markdown
Contributor Author

Rebased onto main 70564ae (head e193474). @kappalegoat, thanks for the map; it changes what this PR is worth.

Since 8af0472 ("lane masks spilled and combined in compute programs"), main has mask_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 on main itself. To check what is left, I ran this PR's lane-mask tests (emit::lane_mask_tests) against plain main on an RTX 5070 (driver 621.40):

tests plain main with this PR
the "elsewhere" cases (complement in a branch, saved EXEC without the current one) pass pass
a_compare_from_a_branch_reads_as_a_number_after_the_join fails (the join's arg is a constant: main refuses "a register joining a lane mask and data") pass
the two loop tests of #1420 fail pass with #1420

So in the rebase, main's mask_number goes first. The ballot with the outside lanes added is kept only as a fallback, for a mask whose writing op mask_number cannot 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 over main's.

cargo test -p victory-shader --locked on 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 plain main 70564ae on this card, so they come from main, not from this PR. cargo clippy -p victory-shader: clean.

@sinan-cmyk's dump run found no count change on the old base; with main now covering the replayable masks, a fresh offline count would tell whether the join case alone still moves any program.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

A join of masks read by a VALU instruction (a compare written in a branch,
read after EXEC is restored) is tracked as a mask and read as one, before
the first loop, when every lane's own incoming mask is the wave's: the wave
leaves a join from its last predecessor in program order, so a lane must
find there the mask of every later edge. A constant joined in (s20 = 0
before the branch) is taken by its lane bit in such joins only.

Masks holding lanes elsewhere are left to mask_number, which replays the
scalar operation that writes them. The lane-mask tests run only where
32-lane waves run.
@marquezinii

Copy link
Copy Markdown
Contributor Author

Following the triage: I took the first option and dropped the outside fallback. It was the ballot with ~WaveActiveBallot(true) OR-ed in when mask_number fails, and no test reached it. The PR is now one commit, ad8e76a, rebased on main 940d32f. What it adds is only the per-lane-checked join of masks and numbers: joined_masks/per_lane in structure.rs, and the numbers fallback in the mask-join arm of lower.rs, now taken only where the join is in active. Masks holding lanes elsewhere are left entirely to mask_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_join and the two refusal tests pass, and the "elsewhere" tests pass through mask_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_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware fail the same way on plain main 940d32f on this card. CI's gathers_at_a_level… and permutes_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.

@marquezinii marquezinii changed the title Shaders: lane masks holding lanes elsewhere, and mask joins, read as numbers Shaders: a lane-mask join of masks and numbers, read as a number Nov 25, 2026
@Mericas77

Copy link
Copy Markdown

Tested ad8e76a on an RTX 4070 (driver 32.0.16.2101, dxil.dll 1.9.2602.17 from SDK 10.0.26100), plus a read of the diff.

lane_mask_tests on 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.rs and lower.rs taken from main 940d32f: only a_compare_from_a_branch_reads_as_a_number_after_the_join fails (a lane mask read as data, offset 56). The other four pass on main as well: the two negated/andn2 tests cover what main's mask_number already does (as your update says), and the two refusal tests pass trivially there because main refuses 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-shader gives 249 passed / 3 failed on the PR head vs 244 / 3 on main 940d32f, same 3 failures on both (the known NVIDIA ones: stride_tests by_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 < 20 before the branch, s20 = vcc copied only inside the branch (lanes < 10), s20 = 0 otherwise, read after the join: refused (lanes 10-19 would read their own 0 while the wave's s20 has their bit). Good.
  • s20 = exec_lo inside the branch, 0 before, read after the join: lowers.

Nit: Structured::numbers is built from exactly the same map as the existing Structured::other (self.other.iter().map(|(&(lo, _), &m)| (lo, m))), so lower.rs could read st.other instead of adding a field.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants