Skip to content

Translate compute selects with numeric lane masks - #69

Closed
flapwarp78 wants to merge 1 commit into
Marvisak:mainfrom
flapwarp78:shader/numeric-compute-select
Closed

flapwarp78 wants to merge 1 commit into
Marvisak:mainfrom
flapwarp78:shader/numeric-compute-select

Conversation

@flapwarp78

Copy link
Copy Markdown

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 Translate 64-bit texture atomics and follow proven shader branches #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.

@tedin7

tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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:

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

@DaviTostes

Copy link
Copy Markdown

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

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

@ordis-labs

Copy link
Copy Markdown

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.

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.

5 participants