victory-shader: resolve Structured::other and constant masks in v_cndmask_b32 (port of VIctory#1221) #193

Open
github-bot wants to merge 1 commit from github-bot/gh-193 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:26 UTC · original
lcg007xd-c:port/vic-1221 → main · +43 −0 · 1 files · 1 commits · open

Port of Marvisak/VIctory#1221 by bartikele. It is cherry-picked with -x, so the commit keeps its author and its upstream hash. This fork's main (000ffdd) does not have it, and it is not in #142.

What it fixes

v_cndmask_b32 with a constant mask, or a mask the structure pass tracks among its other values, was refused in pixel programs (compute programs got by through the numeric-select retry). The fork already keeps the same map under the name others, so no new field: the constant case and an others lookup go into the fork's select_condition; a miss still reports an untracked select, so the retry is unchanged.

Tested (Linux, Rust 1.98.1)

  • v_cndmask_accepts_uniform_and_constant_masks (uses the fork's lowers_rsrc2) fails on this fork's main and passes with the port; a temporary pixel-shader test also failed without it.
  • cargo test -p victory-shader --lib on this branch alone: no failures.
  • It applies to main without conflicts, and does not depend on the other open ports.

Not run here: Windows/GPU tests, since I have no Windows machine.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:26 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/193) `lcg007xd-c:port/vic-1221` → `main` · +43 −0 · 1 files · 1 commits · open Port of [Marvisak/VIctory#1221](https://github.com/Marvisak/VIctory/pull/1221) by bartikele. It is cherry-picked with `-x`, so the commit keeps its author and its upstream hash. This fork's `main` (000ffdd) does not have it, and it is not in #142. ## What it fixes `v_cndmask_b32` with a constant mask, or a mask the structure pass tracks among its other values, was refused in pixel programs (compute programs got by through the numeric-select retry). The fork already keeps the same map under the name `others`, so no new field: the constant case and an `others` lookup go into the fork's `select_condition`; a miss still reports an untracked select, so the retry is unchanged. ## Tested (Linux, Rust 1.98.1) - `v_cndmask_accepts_uniform_and_constant_masks` (uses the fork's `lowers_rsrc2`) fails on this fork's main and passes with the port; a temporary pixel-shader test also failed without it. - `cargo test -p victory-shader --lib` on this branch alone: no failures. - It applies to `main` without conflicts, and does not depend on the other open ports. **Not run here:** Windows/GPU tests, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
(cherry picked from commit 67c4f53109ab3a903d782733c5e8704ab3a0e3bb)

Conflict resolved against the fork's select_condition and its existing Structured::others (the same map, so upstream's other field is not added): constant masks and an others lookup are added there; a failed others lookup still reports an untracked select, so a compute program keeps its retry with numeric selects. The test uses the fork's lowers_rsrc2.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:41 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 04:58 UTC · original

One case where the new inline-constant branch in v_cndmask_b32 (lower.rs, around line 3756 of the PR) gives a wrong select instead of an error, from reading the code (not seen in a real program):

  • It calls lane_bit whenever self.console_lanes is set. lane_bit says it is not for programs split in halves: debug_assert!(!self.split || self.console_cf).
  • split can be true with console_lanes true and console_cf false. That happens for a wave64 compute program on a host that does not run 64 lanes, where console_lanes comes from in_half instructions (DPP, ds_swizzle, quad derivatives) and nothing marks reads_whole or masks_held.
  • A v_cndmask_b32 whose mask is an inline constant does not set either of those with numeric_selects off. Before this PR it failed with UNTRACKED_SELECT, so the program was retried with numeric selects and not split. Now it takes the new branch.
  • In a split program, lane_bit's non-console-flow path takes the host lane index (0-31) in both halves, so console lanes 32-63 read lo instead of hi. With mask 1, for example, lane 32 picks src1 where the console picks src0. Debug builds hit the assert.

This only concerns hosts that do not run 64-lane waves (RDNA cards do), so it is narrow. A guard like else if self.console_lanes && (!self.split || self.console_cf), falling through to the Err otherwise, would keep the old retry for that case.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 04:58 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/193#issuecomment-7183066236) One case where the new inline-constant branch in `v_cndmask_b32` (`lower.rs`, around line 3756 of the PR) gives a wrong select instead of an error, from reading the code (not seen in a real program): - It calls `lane_bit` whenever `self.console_lanes` is set. `lane_bit` says it is not for programs split in halves: `debug_assert!(!self.split || self.console_cf)`. - `split` can be true with `console_lanes` true and `console_cf` false. That happens for a wave64 compute program on a host that does not run 64 lanes, where `console_lanes` comes from `in_half` instructions (DPP, `ds_swizzle`, quad derivatives) and nothing marks `reads_whole` or `masks_held`. - A `v_cndmask_b32` whose mask is an inline constant does not set either of those with `numeric_selects` off. Before this PR it failed with `UNTRACKED_SELECT`, so the program was retried with numeric selects and not split. Now it takes the new branch. - In a split program, `lane_bit`'s non-console-flow path takes the host lane index (0-31) in both halves, so console lanes 32-63 read `lo` instead of `hi`. With mask `1`, for example, lane 32 picks `src1` where the console picks `src0`. Debug builds hit the assert. This only concerns hosts that do not run 64-lane waves (RDNA cards do), so it is narrow. A guard like `else if self.console_lanes && (!self.split || self.console_cf)`, falling through to the `Err` otherwise, would keep the old retry for that case. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:45 UTC · original

Tested on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010) and Rust 1.98.1. I tested head 2222cef merged onto main 4f62c2a. The branch sits on 000ffdd, but it merges onto 4f62c2a without conflicts.

Full game shaders.rpf, translate --validate --host-lanes 32-64, compared with 4f62c2a:

  • 26084 of 26084 programs translated. VS/PS 14247/14247, CS 2682/2682 and mesh 8694 of 8765 validated. These are the same counts as main, with the same refusals (195 SGPR address, 71 mesh outputs).
  • 0 of 25623 per-program DXIL hashes differ.
  • Main has no "a select on an untracked mask" refusals on this title.
  • None of the 1,490,352 v_cndmask_b32 in the archive uses an inline-constant mask.

So on this title the PR changes no output.

Tests (cargo test -p victory-shader --lib -- --test-threads=1):

  • PR on 4f62c2a: 278 passed, 0 failed, 6 ignored. Main 4f62c2a: 277 passed, 0 failed, 6 ignored.
  • With only the new test applied to 4f62c2a, v_cndmask_accepts_uniform_and_constant_masks fails with "a select on an untracked mask".
  • That failure comes from the -1 mask only. A copy of the test with only the s_cselect_b32 select passes on main.
  • With the compute retry turned off locally, that s_cselect_b32-only case fails on main and passes with this PR. So the others lookup works, but no committed test covers it. It could be added as its own test, for example as a pixel program.

One thing from reading the code (not hit in this corpus, not tested): in wave64 the constant branch sign-extends the 32-bit value from inline() for every code. That is right for the integer constants (128-208). The fork's own s_mov_b64 folding in resource.rs sign-extends only those codes. The float constants (240-248) in a 64-bit operand should be the f64 encodings, not sign-extended f32 bits.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:45 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/193#issuecomment-7201928592) Tested on Windows 11 with an RX 7900 XT (RDNA3, driver 32.0.32029.2010) and Rust 1.98.1. I tested head 2222cef merged onto main 4f62c2a. The branch sits on 000ffdd, but it merges onto 4f62c2a without conflicts. Full game shaders.rpf, `translate --validate --host-lanes 32-64`, compared with 4f62c2a: - 26084 of 26084 programs translated. VS/PS 14247/14247, CS 2682/2682 and mesh 8694 of 8765 validated. These are the same counts as main, with the same refusals (195 SGPR address, 71 mesh outputs). - 0 of 25623 per-program DXIL hashes differ. - Main has no "a select on an untracked mask" refusals on this title. - None of the 1,490,352 `v_cndmask_b32` in the archive uses an inline-constant mask. So on this title the PR changes no output. Tests (`cargo test -p victory-shader --lib -- --test-threads=1`): - PR on 4f62c2a: 278 passed, 0 failed, 6 ignored. Main 4f62c2a: 277 passed, 0 failed, 6 ignored. - With only the new test applied to 4f62c2a, `v_cndmask_accepts_uniform_and_constant_masks` fails with "a select on an untracked mask". - That failure comes from the `-1` mask only. A copy of the test with only the `s_cselect_b32` select passes on main. - With the compute retry turned off locally, that `s_cselect_b32`-only case fails on main and passes with this PR. So the `others` lookup works, but no committed test covers it. It could be added as its own test, for example as a pixel program. One thing from reading the code (not hit in this corpus, not tested): in wave64 the constant branch sign-extends the 32-bit value from `inline()` for every code. That is right for the integer constants (128-208). The fork's own `s_mov_b64` folding in `resource.rs` sign-extends only those codes. The float constants (240-248) in a 64-bit operand should be the f64 encodings, not sign-extended f32 bits.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/193/head:github-bot/gh-193'
git switch 'github-bot/gh-193'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-193'
git switch 'github-bot/gh-193'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-193'
git switch 'github-bot/gh-193'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-193'
git switch 'main'
git merge --squash 'github-bot/gh-193'
git switch 'main'
git merge --ff-only 'github-bot/gh-193'
git switch 'main'
git merge 'github-bot/gh-193'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.