Shaders: compute exact SCC for s_lshl{1..4}_add_u32 and s_min/s_max_{u32,i32} #350

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

@⁠AscilCH on GitHub · 2026-11-24 23:49 UTC · original
AscilCH:fix/shader-scalar-lshl-add-and-minmax-scc → main · +94 −3 · 2 files · 1 commits · open

Problem

In crates/victory-shader/src/emit/lower.rs, Lower::scalar returned carry = None for:

  1. s_lshl1_add_u32, s_lshl2_add_u32, s_lshl3_add_u32, s_lshl4_add_u32
  2. s_min_u32, s_max_u32, s_min_i32, s_max_i32

Because carry was None, all eight instructions fell through to the default SCC = (r != 0) path:

  • For s_lshl{1..4}_add_u32, any subsequent s_addc_u32 (used in 64-bit scalar address arithmetic) received SCC = 1 whenever the low 32-bit result was non-zero (adding a spurious +4 GiB to the high word) and SCC = 0 when an overflow wrapped the low word to 0.
  • For s_min/s_max_{u32,i32}, SCC reflected r != 0 instead of whether src0 won the comparison (src0 < src1 or src0 > src1), breaking s_cselect_b32 / s_cbranch_scc* consumers.

Fix

  • For s_lshl{1..4}_add_u32, compute the exact 32-bit unsigned carry-out ((a >> (32 - shift)) != 0) || (r < (a << shift)) and return Some(carry).
  • For s_min_{u32,i32} and s_max_{u32,i32}, return Some(t) where t is the src0 < src1 / src0 > src1 comparison result already used for select.
  • Add emit::valu_tests::scalar_lshl_add_and_minmax_set_scc covering all four s_lshl{1..4}_add_u32 + s_addc_u32 combinations and all four s_min/s_max_{u32,i32} + s_cselect_b32 combinations across signed/unsigned/zero/overflow/equal edge cases.

Verification

  • cargo test -p victory-shader --locked scalar_lshl_add_and_minmax_set_scc: passed (hardware D3D12 + WARP + dxil.dll)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-24 23:49 UTC · [original](https://github.com/fxceless/victory-fork/pull/350) `AscilCH:fix/shader-scalar-lshl-add-and-minmax-scc` → `main` · +94 −3 · 2 files · 1 commits · open ## Problem In `crates/victory-shader/src/emit/lower.rs`, `Lower::scalar` returned `carry = None` for: 1. `s_lshl1_add_u32`, `s_lshl2_add_u32`, `s_lshl3_add_u32`, `s_lshl4_add_u32` 2. `s_min_u32`, `s_max_u32`, `s_min_i32`, `s_max_i32` Because `carry` was `None`, all eight instructions fell through to the default `SCC = (r != 0)` path: - For `s_lshl{1..4}_add_u32`, any subsequent `s_addc_u32` (used in 64-bit scalar address arithmetic) received `SCC = 1` whenever the low 32-bit result was non-zero (adding a spurious `+4 GiB` to the high word) and `SCC = 0` when an overflow wrapped the low word to `0`. - For `s_min/s_max_{u32,i32}`, `SCC` reflected `r != 0` instead of whether `src0` won the comparison (`src0 < src1` or `src0 > src1`), breaking `s_cselect_b32` / `s_cbranch_scc*` consumers. ## Fix - For `s_lshl{1..4}_add_u32`, compute the exact 32-bit unsigned carry-out `((a >> (32 - shift)) != 0) || (r < (a << shift))` and return `Some(carry)`. - For `s_min_{u32,i32}` and `s_max_{u32,i32}`, return `Some(t)` where `t` is the `src0 < src1` / `src0 > src1` comparison result already used for `select`. - Add `emit::valu_tests::scalar_lshl_add_and_minmax_set_scc` covering all four `s_lshl{1..4}_add_u32` + `s_addc_u32` combinations and all four `s_min/s_max_{u32,i32}` + `s_cselect_b32` combinations across signed/unsigned/zero/overflow/equal edge cases. ## Verification - `cargo test -p victory-shader --locked scalar_lshl_add_and_minmax_set_scc`: passed (hardware D3D12 + WARP + `dxil.dll`) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic tests only, no game data.)*
In `Lower::scalar`, `s_lshl{1,2,3,4}_add_u32` and `s_min/s_max_{u32,i32}`
returned `(r, None)`, falling through to the generic `SCC = (r != 0)`
fallback instead of their architectural RDNA2/GFX10 `SCC` semantics:

- `s_lshl{1..4}_add_u32`: `SCC` must be the 32-bit unsigned carry-out of
  `((u64)src0 << N) + (u64)src1`, i.e. `((src0 >> (32 - N)) != 0) || (r < (src0 << N))`.
  Returning `r != 0` corrupted 64-bit scalar address arithmetic paired
  with `s_addc_u32` whenever the low 32-bit result was non-zero without
  overflow (adding +4 GiB) or wrapped cleanly to zero on carry.
- `s_min_{u32,i32}` / `s_max_{u32,i32}`: `SCC` must be `1` iff `src0` won
  the comparison (`src0 < src1` or `src0 > src1`), which is already the
  comparison bit `t`.

Add `emit::valu_tests::scalar_lshl_add_and_minmax_set_scc` testing all
eight instructions end-to-end on hardware D3D12, WARP, and `dxil.dll`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:25 +00:00
Author
Owner

@⁠BTekV4 on GitHub · 2026-11-25 00:48 UTC · original

Tested this PR on top of 31714de (i.e. after yesterday's 3bff182 and 31714de merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with A pressed by a script so the world actually loads (~5000 draws/frame, 150 s).

Result: no measurable change on this title. missing-shader 10, pipeline-refused 7, mesh-pipeline-refused 1 — identical to the same build without this PR.

  • baseline (main + #376): a8826150ef94847a
  • this PR (main + #376 + PR): 378fb4f54b93f1f5

The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the a whole-wave section step the simulation does not follow (15 occurrences) and a lane mask exchanged where not every lane runs (15) failures are gone. What remains is:

  • 7× a descriptor read only as data (pixel)
  • 1× a descriptor's address or format read as data
  • 1× a lane mask exchanged where not every lane runs
  • 1× a lane mask holding lanes elsewhere read as data
  • 7× pipeline-refused, all E_INVALIDARG (0x80070057) on compute pipelines

So this may be superseded — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does).

Two practical notes:

  1. Against 31714de this PR conflicts only in crates/victory-shader/src/emit/valu_tests.rs (a test file); the functional code applies cleanly, so a rebase is trivial.
  2. Same-run context and the full shader-diag.jsonl (34k records, 11.8 MB) are in #394.
**@⁠BTekV4** on GitHub · 2026-11-25 00:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/350#issuecomment-7148902505) Tested this PR on top of `31714de` (i.e. after yesterday's `3bff182` and `31714de` merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with `A` pressed by a script so the world actually loads (~5000 draws/frame, 150 s). **Result: no measurable change on this title.** `missing-shader` 10, `pipeline-refused` 7, `mesh-pipeline-refused` 1 — identical to the same build without this PR. - baseline (`main` + #376): `a8826150ef94847a` - this PR (`main` + #376 + PR): `378fb4f54b93f1f5` The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the `a whole-wave section step the simulation does not follow` (15 occurrences) and `a lane mask exchanged where not every lane runs` (15) failures are gone. What remains is: - 7× `a descriptor read only as data` (pixel) - 1× `a descriptor's address or format read as data` - 1× `a lane mask exchanged where not every lane runs` - 1× `a lane mask holding lanes elsewhere read as data` - 7× `pipeline-refused`, all `E_INVALIDARG (0x80070057)` on compute pipelines So this may be **superseded** — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does). Two practical notes: 1. Against `31714de` this PR conflicts **only** in `crates/victory-shader/src/emit/valu_tests.rs` (a test file); the functional code applies cleanly, so a rebase is trivial. 2. Same-run context and the full `shader-diag.jsonl` (34k records, 11.8 MB) are in #394.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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