Shaders: apply bitwise modifiers to v_cmp_class_f32 source operands #1327

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/1327 into main
fuzeofficlal commented 2026-11-24 17:28:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T17:28:47Z.


Fixes #830.

Summary

  • Read the raw 32-bit integer operand in Lower::compare (class) for v_cmp_class_f32 / v_cmpx_class_f32, apply SDWA sub-word selection (Self::sdwa_src + select_bits), and perform abs (& 0x7FFF_FFFF) and neg (^ 0x8000_0000) bitwise in i32, matching the existing f16 path.
  • Avoids routing v_cmp_class_f32 through fsrc (FAbs / fsub -0.0, x), which flushes denormals to ±0.0 under FTZ and quiets signaling NaNs before IEEE-754 class testing.

Verification

  • Added valu_tests::v_cmp_class_f32_matches_rdna2 testing all 10 IEEE-754 binary32 classes (±sNaN, ±qNaN, ±inf, ±normal, ±denormal, ±0.0) across plain, neg, abs, abs+neg, and v_cmp_class_f32_sdwa (-word0 preserving -denormal class 4 instead of flushing to -0.0 class 5):
    • dxil.dll validation: passed
    • NVIDIA GeForce RTX 5090: passed
    • Microsoft D3D12 WARP: passed
  • cargo test -p victory-shader, cargo clippy --workspace --all-targets --all-features, and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5477115119 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-24T17:28:47Z. --- Fixes #830. ### Summary - Read the raw 32-bit integer operand in `Lower::compare` (`class`) for `v_cmp_class_f32` / `v_cmpx_class_f32`, apply SDWA sub-word selection (`Self::sdwa_src` + `select_bits`), and perform `abs` (`& 0x7FFF_FFFF`) and `neg` (`^ 0x8000_0000`) bitwise in `i32`, matching the existing `f16` path. - Avoids routing `v_cmp_class_f32` through `fsrc` (`FAbs` / `fsub -0.0, x`), which flushes denormals to `±0.0` under FTZ and quiets signaling NaNs before IEEE-754 class testing. ### Verification - Added `valu_tests::v_cmp_class_f32_matches_rdna2` testing all 10 IEEE-754 binary32 classes (`±sNaN`, `±qNaN`, `±inf`, `±normal`, `±denormal`, `±0.0`) across `plain`, `neg`, `abs`, `abs+neg`, and `v_cmp_class_f32_sdwa` (`-word0` preserving `-denormal` class 4 instead of flushing to `-0.0` class 5): - `dxil.dll` validation: passed - **NVIDIA GeForce RTX 5090**: passed - **Microsoft D3D12 WARP**: passed - `cargo test -p victory-shader`, `cargo clippy --workspace --all-targets --all-features`, and `cargo xtask policy`: passed.
marquezinii commented 2026-11-24 19:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:10:51Z.


Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 4f2eee6. cargo test -p victory-shader --lib -- --test-threads=1 gives 121 passed, 0 failed, 1 ignored. v_cmp_class_f32_matches_rdna2 passes on the hardware adapter and WARP, with the sNaN and denormal rows included.

This is the case where the old fsrc path could differ per driver: FAbs and the -0.0 - x negate may flush denormals or quiet sNaNs. Doing abs/neg as integer ops on the raw bits avoids that. The class numbering in the test (bit 0 sNaN through bit 9 +inf) matches the ISA.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140273980 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#issuecomment-7140273980). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:10:51Z. --- Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `4f2eee6`. `cargo test -p victory-shader --lib -- --test-threads=1` gives 121 passed, 0 failed, 1 ignored. `v_cmp_class_f32_matches_rdna2` passes on the hardware adapter and WARP, with the sNaN and denormal rows included. This is the case where the old `fsrc` path could differ per driver: `FAbs` and the `-0.0 - x` negate may flush denormals or quiet sNaNs. Doing `abs`/`neg` as integer ops on the raw bits avoids that. The class numbering in the test (bit 0 sNaN through bit 9 +inf) matches the ISA.
catminou4 commented 2026-11-24 20:09:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:47Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Applies bitwise modifiers to v_cmp_class_f32 source operands and adds v_cmp_class_f32_matches_rdna2 hardware cases.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046557161 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#pullrequestreview-6046557161). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:47Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Applies bitwise modifiers to v_cmp_class_f32 source operands and adds v_cmp_class_f32_matches_rdna2 hardware cases.
Marvisak commented 2026-11-25 02:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:22:31Z.


Automated triage for the maintainers.

Merge candidate (unchanged). The new head is one commit on current main and merges cleanly. The change is the same as before. In emit/lower.rs::Lower::compare (class), v_cmp_class_f32 reads the raw operand through operand, applies the SDWA selection (sdwa_src + select_bits), and applies abs/neg as bit operations (& 0x7FFF_FFFF, ^ 0x8000_0000). The f16 path now shares that modifier code. This keeps fsrc's float abs/negate from flushing denormals or quieting sNaNs before the class test (#830). v_cmp_class_f32_matches_rdna2 in valu_tests.rs covers all ten classes with each modifier combination, plus an SDWA case.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149480508 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#issuecomment-7149480508). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:22:31Z. --- <!-- victory-triage v1 head=7c4663f856987472b0e5805526f5ddfd06237afd verdict=merge-candidate at=2026-11-26T01:19:00Z --> Automated triage for the maintainers. **Merge candidate (unchanged).** The new head is one commit on current `main` and merges cleanly. The change is the same as before. In `emit/lower.rs::Lower::compare` (`class`), `v_cmp_class_f32` reads the raw operand through `operand`, applies the SDWA selection (`sdwa_src` + `select_bits`), and applies `abs`/`neg` as bit operations (`& 0x7FFF_FFFF`, `^ 0x8000_0000`). The f16 path now shares that modifier code. This keeps `fsrc`'s float `abs`/negate from flushing denormals or quieting sNaNs before the class test (#830). `v_cmp_class_f32_matches_rdna2` in `valu_tests.rs` covers all ten classes with each modifier combination, plus an SDWA case. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 03:03:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T02:09:27Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 4f2eee6 onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150384004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#issuecomment-7150384004). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T02:09:27Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 4f2eee6 onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
andrewpozdnakov7-jpg commented 2026-11-27 14:21:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T14:21:08Z.


I tested this PR with the FP16 operand-selection fixes from #926 and #3364 on main 63bcca4. Combined branch 62b8716 retains the three PR heads and their original tests.

I also preserved the old fsrc source-selection order for F32 class compares. SDWA uses its selected subword first. Otherwise the lowering uses the lane-selected source when one was already computed and applies ABS/NEG to the bits. The FP16 path keeps its own half selection.

With the unchanged F32 class fixture on the earlier #926/#3364 integration e002024, WARP gives 0 for the negated signalling NaN 0x7f800001 tested against class mask 1, where the test expects 1. The combined branch passes that fixture, the F16 class fixture, both FP16 operand-selection regressions, and all 39 VALU tests on app-local WARP 1.0.22 with DXIL validation. Strict shader Clippy and the asset check passed.

If folding the merge resolution into another commit, please retain Git authorship or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with Codex. Synthetic shader tests only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7220673419 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#issuecomment-7220673419). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T14:21:08Z. --- I tested this PR with the FP16 operand-selection fixes from #926 and #3364 on main `63bcca4`. [Combined branch 62b8716](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/cmp-class-f32-and-f16-selection) retains the three PR heads and their original tests. I also preserved the old fsrc source-selection order for F32 class compares. SDWA uses its selected subword first. Otherwise the lowering uses the lane-selected source when one was already computed and applies ABS/NEG to the bits. The FP16 path keeps its own half selection. With the unchanged F32 class fixture on the earlier #926/#3364 integration `e002024`, WARP gives 0 for the negated signalling NaN `0x7f800001` tested against class mask 1, where the test expects 1. The combined branch passes that fixture, the F16 class fixture, both FP16 operand-selection regressions, and all 39 VALU tests on app-local WARP 1.0.22 with DXIL validation. Strict shader Clippy and the asset check passed. If folding the merge resolution into another commit, please retain Git authorship or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with Codex. Synthetic shader tests only.
andrewpozdnakov7-jpg commented 2026-11-28 14:07:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:07:30Z.


I combined your exact 7c4663f with #3743 5397722 on current main in 1d9d947. Both PR commits are direct parents. The constant-mask predicate uses the same raw source bits produced by your modifier handling.

The two trees matched all 2,655,576 generated output words on Microsoft WARP 1.0.22 with Agility 1.620.2. The comparison covered CMP, CMPX, literal masks, and both plain and abs/neg source forms. Your f32 class modifier test, including SDWA, passed alongside the f16 class test and the new immediate-mask regression. The f32 NaN and finite fixtures emitted 37 DXIL instructions instead of 57, and the generic mask remained at 57. Strict all-feature shader Clippy and the asset policy passed.

@fuzeofficlal, the combined tree is available for merge coordination. Please retain Git authorship on cherry-pick or rebase. If folding #3743 into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240434775 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1327#issuecomment-7240434775). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:07:30Z. --- I combined your exact `7c4663f` with #3743 `5397722` on current `main` in [`1d9d947`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/1d9d947e1357a2c876a2980412a999c12d967c0b). Both PR commits are direct parents. The constant-mask predicate uses the same raw source bits produced by your modifier handling. The two trees matched all 2,655,576 generated output words on Microsoft WARP 1.0.22 with Agility 1.620.2. The comparison covered CMP, CMPX, literal masks, and both plain and abs/neg source forms. Your f32 class modifier test, including SDWA, passed alongside the f16 class test and the new immediate-mask regression. The f32 NaN and finite fixtures emitted 37 DXIL instructions instead of 57, and the generic mask remained at 57. Strict all-feature shader Clippy and the asset policy passed. @fuzeofficlal, the combined tree is available for merge coordination. Please retain Git authorship on cherry-pick or rebase. If folding #3743 into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1327:upstream-pr/1327'
git switch 'upstream-pr/1327'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1327'
git switch 'upstream-pr/1327'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1327'
git switch 'upstream-pr/1327'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1327'
git switch 'main'
git merge --squash 'upstream-pr/1327'
git switch 'main'
git merge --ff-only 'upstream-pr/1327'
git switch 'main'
git merge 'upstream-pr/1327'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1327
No description provided.