Skip to content

Shaders: handle dead mask dwords at data joins and wave-uniform s_bcnt1 SCC - #1269

Closed
Sakura-Byte wants to merge 1 commit into
Marvisak:mainfrom
Sakura-Byte:pr/mask-dword-joins-878
Closed

Sakura-Byte wants to merge 1 commit into
Marvisak:mainfrom
Sakura-Byte:pr/mask-dword-joins-878

Conversation

@Sakura-Byte

Copy link
Copy Markdown

Fixes #878.

Summary

  • Dead lane-mask dwords at data joins (fill_phis): When a scalar register previously held a lane-mask dword before being overwritten on the live data path, the dead mask dword incoming edge at a phi that has at least one live scalar data (Val::I32) predecessor now lowers to undef on the mask edge rather than failing the whole join as a mask read, while mask-only joins continue to be rejected.
  • Wave-uniform SCC from s_bcnt1 and mask SOP ops (mask_sccs, mask_any, mask_any_in):
    • Tracks SCC values produced by exact-width s_bcnt1_i32_b32 (Wave32) / s_bcnt1_i32_b64 (Wave64) on tracked lane masks, saveexec forms, and mask-writing SOP ops.
    • Lowers those SCC uses (directly via get or across Reg::Scc phis in fill_phis) as dx.op.waveActiveBallot(...) != 0 so SCC stays wave-uniform on Wave32 and Wave64 without per-lane divergence (avoiding the Wave32 scc_lane regression noted on the earlier attempt).
    • Keeps numeric popcount reads of s_bcnt1's scalar destination rejected in MaskData::None and rejects mismatched-width s_bcnt1_i32_b32 in Wave64 programs.

Files Changed

  • crates/victory-shader/src/emit/lower.rs: mask_sccs, is_mask_value, mask_scc_source, mask_any, mask_any_in, updated get / fill_phis, and synthetic DXIL/WARP tests (mask_dword_at_data_join_emits_undef_and_rejects_mask_only_joins, s_bcnt1_scc_only_translates_while_numeric_popcount_still_fails, s_bcnt1_scc_branch_stays_wave_uniform_on_warp).
  • crates/victory-shader/src/emit/bitcode.rs: #[cfg(test)] inspection helpers Module::func_names and Module::inst_lines.

Verification

Ran cleanly on clean origin/main (ffe310e):

  • cargo xtask policy: asset policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
  • VICTORY_D3D12_WARP=1 VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 123 passed; 0 failed; 1 ignored (only the existing release-only benchmark emit::bitcode::tests::bench_write is ignored; dxil.dll validation ran; in s_bcnt1_scc_branch_stays_wave_uniform_on_warp, the Wave32 Mesh shader executes end-to-end on WARP checking [0.75, 0.75, 0.75, 1.0], and the Wave32 Compute shader verifies dx.op.waveActiveBallot, cmp:33 ... k0 (!= 0), and dxil.dll validation while skipping fixed [WaveSize(32)] PSO creation on WARP which returns E_INVALIDARG).

AI-assisted; synthetic tests only, zero game assets.

…t1 SCC

Allow dead lane-mask dwords reaching a scalar data join (from register reuse after the mask dies) to lower as undef on that incoming edge rather than rejecting the join, while still rejecting mask-only joins.

Also track wave-uniform SCC results from s_bcnt1_i32_b32/b64 (matching program wave width) and mask-writing SOP ops when their scalar count is unread or cannot be lowered as numeric data (such as Mesh MaskData::None), lowering SCC via waveActiveBallot != 0 without per-lane Wave32 popcount divergence.
@pablogonz12

Copy link
Copy Markdown
Contributor

Setup: Linux, RX 9070 XT, RADV (Mesa 26.3.1), dxil-spirv master, spirv-val 1.3. Your head folded onto a base of origin/main ffe310e plus #1017 — main's host build is broken without it (E0425 host_resource in victory-gpu), so the base is that pair. Ran the four-stage offline check (translate, dxil-spirv, spirv-val, RADV pipeline) over 768 programs: the 751-program world dump plus a 52-program BVH capture, 35 duplicate containers skipped.

translate valid SPIR-V RADV pipeline
base 666 / 768 656 656
your head 666 / 768 656 656

No program gained or lost. The only difference in the failure table: two compute programs that read a lane mask as data now report "a lane mask holding lanes elsewhere read as data" instead of "a lane mask read as data", which is the new distinction working. No new failure, same 10 SPIR-V validation failures as the base.

Not tested: in-game.

@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.

Dead mask dwords at data joins emit undef instead of a stale ballot, scalar ops writing tracked masks (and s_bcnt1 testing them) get their SCC mapped back to the mask's low dword (saveexec forms map EXEC's new value), so wave-uniform SCC branches on masks translate. Structure tests for the join/undef and s_bcnt1 SCC cases run on macOS. Local verification: macOS arm64, rustc 1.98.1, PR head merged into main ffe310e, cargo test -p victory-shader --locked. Shader execution tests (valu_tests/host) are #[cfg(all(test, windows))], so macOS covers lowering/decode/unit tests only. 98 passed, 0 failed. Note: adds the same #[cfg(test)] op_names/insts helpers as #1275 — the second of the two to land will conflict textually.

@rafaconvaitis

Copy link
Copy Markdown

I replayed the two mesh-shader containers reported as the largest and packed drops in the recent update-9 run on #293. Both runtime hash prefixes resolved in the local shader archive. Here is the direct comparison on Windows 11 build 26300 with the RTX 4070 selected explicitly.

Runtime shader hash main ffe310e #1269 8c3092f #1269 + #953 c42cbb0
ef5409053e14aa82 lane mask read as data scalar memory read as data descriptor address or format read as data
235e56869c1ea883 scalar memory read as data scalar memory read as data descriptor address or format read as data

#1269 gets the first program past the lane-mask refusal. Adding #953 makes both reach the remaining descriptor-data case tracked in #798. Both still stop before DXIL validation or D3D12 PSO creation in the tested builds. These are offline translation results, so the in-game dropped-draw counts remain unmeasured for the stack.

AI-assisted test harness and reporting.

yourmomsbasement pushed a commit to yourmomsbasement/VIctory_Dev that referenced this pull request Nov 24, 2026
yourmomsbasement pushed a commit to yourmomsbasement/VIctory_Dev that referenced this pull request Nov 24, 2026
Conflicts kept both sides: the split execute/submit (breadcrumbs cleared at the start of submit), the debug pixel shader and the breadcrumb stage notes, the view-heap-cap and wave keys of the shader cache with the breadcrumb key, and the single-exit block with the breadcrumb loops. Tests added by Marvisak#1084/Marvisak#1130/Marvisak#1269 initialise Parts with crumbs: None.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

Stale mask dwords at data joins and bit counts of masks in mesh programs are both handled in main (dead_on_edge/live_edges/joins_loaded in fill_phis; host-wave bit count for mesh). This version gives the mask edge undef whenever another edge carries data, which is the unsound shortcut main moved away from.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Ready to merge] Shaders: mask dwords at data joins, and s_bcnt1's SCC of a mask (+47 mesh/vertex programs)

5 participants