Translate compute selects with numeric lane masks #69

Closed
github-bot wants to merge 1 commit from gh-pr/69/head into gh-pr/69/base
Owner

@⁠flapwarp78 on GitHub · 2026-11-24 00:10 UTC · original
flapwarp78:shader/numeric-compute-select → main · +144 −11 · 2 files · 1 commits · closed without merging

What changed

v_cndmask_b32 can read a mask held as ordinary scalar data. The emitter now reads the mask words from that instruction's SSA operands and tests the bit for the current console lane. Wave64 uses both words, even if different instructions wrote them.

The compiler retries with a fixed wave size only when a live numeric select blocks translation.

Verification

  • In a scan of 2,682 real compute shader inputs with #48 applied, all 291 inputs that previously stopped at an untracked select got past that error. One translated completely and passed Microsoft's DXIL validator. The other 290 stopped at later errors, including 275 descriptor reads. All 1,710 previously translating compute shaders still translated.
  • The patch applies directly to upstream main. On that base it produced byte-identical DXIL for the recovered shader, and 71 targeted tests passed.
  • Synthetic wave32 and wave64 shaders passed DXIL validation. A CPU harness checked each lane's result against a reference mask, including the transition between lanes 31 and 32.

The recovered shader requires wave64. In-game execution is still unverified.

**@⁠flapwarp78** on GitHub · 2026-11-24 00:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/69) `flapwarp78:shader/numeric-compute-select` → `main` · +144 −11 · 2 files · 1 commits · closed without merging ## What changed `v_cndmask_b32` can read a mask held as ordinary scalar data. The emitter now reads the mask words from that instruction's SSA operands and tests the bit for the current console lane. Wave64 uses both words, even if different instructions wrote them. The compiler retries with a fixed wave size only when a live numeric select blocks translation. ## Verification - In a scan of 2,682 real compute shader inputs with #48 applied, all 291 inputs that previously stopped at an untracked select got past that error. One translated completely and passed Microsoft's DXIL validator. The other 290 stopped at later errors, including 275 descriptor reads. All 1,710 previously translating compute shaders still translated. - The patch applies directly to upstream main. On that base it produced byte-identical DXIL for the recovered shader, and 71 targeted tests passed. - Synthetic wave32 and wave64 shaders passed DXIL validation. A CPU harness checked each lane's result against a reference mask, including the transition between lanes 31 and 32. The recovered shader requires wave64. In-game execution is still unverified.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:06 +00:00
github-bot closed this pull request 2026-11-26 03:49:06 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:48 UTC · original

checked: PR head 18f3937 (merge-base 35b054e), Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1, throwaway worktree, no game files used.

Ran (shader crate only):

  • cargo test -j4 -p victory-shader: 52 passed, 0 failed (includes select_tests::selects_from_independently_written_mask_words).
  • Same command on the PR merged locally onto origin/main 9aef3d9 (clean merge): 57 passed, 0 failed.
  • cargo clippy -j4 -p victory-shader --tests: no new warnings (only the existing constant_color is never used warning in emit/mod.rs tests).
  • Fail-before check: with lower.rs and structure.rs reverted to the merge-base and the new test module kept, the test fails with Unsupported { offset: 44, what: "a select on an untracked mask" }. With the PR it passes, so the test does guard the change.

Review notes:

  • The logic reads correctly to me: the null mask gives false (picks src0, matching select(cond, src1, src0)), wave64 reads both dwords from the SSA operands of the select, and the retry only happens for compute and only for that specific error, so other stages and other errors keep today's behaviour.
  • The new test checks that the shader translates and that the wave-ops feature bit in SFI0 is set only when the select result is used (all three wave32/wave64 cases). It does not check which lanes pick which value, and no DXIL validation runs in cargo test. The lane 31/32 check and the validator run described in the PR come from your external harness, which I could not rerun here.
  • Question, not a finding: the old code looked the mask up in the final st.masks (by low dword), the new code records select_masks only when mask() reports the mask as derived at that point of the pass. I could not build a case where the two differ and all existing tests pass, but a mask that only enters masks later in a pass (loop-carried) is the place I would look, and the real-shader scan you describe is the right check for it.
  • Conflicts: clean against origin/main and trial merges are clean with #25, #48, #73, #101, #110, #116, #126, #127. It conflicts with #54 in the console_lanes computation in Lower::new (#54 rewrites that closure; the fix is to add the numeric_selects && numeric_select(...) clause into #54's version).

Not verified: Windows runtime, GPU, in-game execution, or the 2,682-shader scan (needs game data I did not use).

**@⁠tedin7** on GitHub · 2026-11-24 00:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/69#issuecomment-7118446166) checked: PR head `18f3937` (merge-base `35b054e`), Linux x86_64 (Debian, kernel 6.12), rustc/cargo 1.98.1, throwaway worktree, no game files used. Ran (shader crate only): - `cargo test -j4 -p victory-shader`: 52 passed, 0 failed (includes `select_tests::selects_from_independently_written_mask_words`). - Same command on the PR merged locally onto `origin/main` `9aef3d9` (clean merge): 57 passed, 0 failed. - `cargo clippy -j4 -p victory-shader --tests`: no new warnings (only the existing `constant_color is never used` warning in `emit/mod.rs` tests). - Fail-before check: with `lower.rs` and `structure.rs` reverted to the merge-base and the new test module kept, the test fails with `Unsupported { offset: 44, what: "a select on an untracked mask" }`. With the PR it passes, so the test does guard the change. Review notes: - The logic reads correctly to me: the null mask gives false (picks src0, matching `select(cond, src1, src0)`), wave64 reads both dwords from the SSA operands of the select, and the retry only happens for compute and only for that specific error, so other stages and other errors keep today's behaviour. - The new test checks that the shader translates and that the wave-ops feature bit in `SFI0` is set only when the select result is used (all three wave32/wave64 cases). It does not check which lanes pick which value, and no DXIL validation runs in `cargo test`. The lane 31/32 check and the validator run described in the PR come from your external harness, which I could not rerun here. - Question, not a finding: the old code looked the mask up in the final `st.masks` (by low dword), the new code records `select_masks` only when `mask()` reports the mask as derived at that point of the pass. I could not build a case where the two differ and all existing tests pass, but a mask that only enters `masks` later in a pass (loop-carried) is the place I would look, and the real-shader scan you describe is the right check for it. - Conflicts: clean against `origin/main` and trial merges are clean with #25, #48, #73, #101, #110, #116, #126, #127. It conflicts with #54 in the `console_lanes` computation in `Lower::new` (#54 rewrites that closure; the fix is to add the `numeric_selects && numeric_select(...)` clause into #54's version). Not verified: Windows runtime, GPU, in-game execution, or the 2,682-shader scan (needs game data I did not use).
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 00:59 UTC · original

Tested 18f3937 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 52 passed, 0 failed (2 test binaries), including the test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425; the shader crate itself is green.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/69#issuecomment-7118647914) Tested `18f3937` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **52 passed, 0 failed** (2 test binaries), including the test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425; the shader crate itself is green. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠ordis-labs on GitHub · 2026-11-24 15:00 UTC · original

Measured this on current main (ffe310e) over the 1.0.2.1 shaders.rpf (translate --list --validate, outcomes matched program by program). It needed a small local rebase: structure.rs now has main's paired_masks next to this PR's select_masks (kept both), and the test's resource::track call takes Some(&st) since ffe310e.

"A select on an untracked mask" disappears for all 288 programs main refuses with it, and nothing that validates on main breaks. Only 2 fully validate yet. The rest stop at the next gap: 205 at "a descriptor read only as data", 33 at "a descriptor's address or format read as data", 32 at "a structured buffer of unknown stride" (which #704 covers). cargo test -p victory-shader: 106 passed, and the only failures are the same 15 GPU tests that fail on main here (Windows 10, no SM 6.6 device).

Tested and written up with Claude's help.

**@⁠ordis-labs** on GitHub · 2026-11-24 15:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/69#issuecomment-7135315072) Measured this on current main (`ffe310e`) over the 1.0.2.1 `shaders.rpf` (`translate --list --validate`, outcomes matched program by program). It needed a small local rebase: `structure.rs` now has main's `paired_masks` next to this PR's `select_masks` (kept both), and the test's `resource::track` call takes `Some(&st)` since `ffe310e`. "A select on an untracked mask" disappears for all 288 programs main refuses with it, and nothing that validates on main breaks. Only 2 fully validate yet. The rest stop at the next gap: 205 at "a descriptor read only as data", 33 at "a descriptor's address or format read as data", 32 at "a structured buffer of unknown stride" (which #704 covers). `cargo test -p victory-shader`: 106 passed, and the only failures are the same 15 GPU tests that fail on main here (Windows 10, no SM 6.6 device). Tested and written up with Claude's help.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!69
No description provided.