Shaders: honor explicit half input flush in normalized conversions #3164

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/3166 into main
andrewpozdnakov7-jpg commented 2026-11-26 10:48:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T10:48:30Z.


V_CVT_NORM_I16_F16 and V_CVT_NORM_U16_F16 must read half subnormals as zero when MODE[6] disables input denormals. Lyrnc's RDNA2 sweep in #376 measured the distinction for both instructions.

Reuse the existing MODE dataflow for statically known S_DENORM_MODE and literal MODE writes. The analysis runs lazily for shaders that use either conversion. Known flush sites zero the source magnitude below the smallest normal half before scaling. Entry and runtime-unknown modes retain the current behavior.

On main, signed conversion of 0x0101 in flush mode returns 0x0001. On WARP the patch gives 0x0000, and all 274 synthetic readbacks passed across both conversions, the four denormal modes, explicit MODE bit writes and agreeing branch paths. All 36 VALU tests, strict shader Clippy and the asset policy passed.

AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If folded into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5508603337 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T10:48:30Z. --- `V_CVT_NORM_I16_F16` and `V_CVT_NORM_U16_F16` must read half subnormals as zero when MODE[6] disables input denormals. [Lyrnc's RDNA2 sweep in #376](https://github.com/Marvisak/VIctory/pull/376#issuecomment-7123514901) measured the distinction for both instructions. Reuse the existing MODE dataflow for statically known `S_DENORM_MODE` and literal MODE writes. The analysis runs lazily for shaders that use either conversion. Known flush sites zero the source magnitude below the smallest normal half before scaling. Entry and runtime-unknown modes retain the current behavior. On main, signed conversion of `0x0101` in flush mode returns `0x0001`. On WARP the patch gives `0x0000`, and all 274 synthetic readbacks passed across both conversions, the four denormal modes, explicit MODE bit writes and agreeing branch paths. All 36 VALU tests, strict shader Clippy and the asset policy passed. AI-assisted with Codex. Please retain the Git author when cherry-picking or rebasing. If folded into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
andrewpozdnakov7-jpg commented 2026-11-26 11:04:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T11:03:20Z.


Updated to b5a1678 to keep the normalized-half code and its MODE analysis in one module. The initial tree exceeded the repository's source-size limit when combined with #2623 and the independent shader fixes. The composed tree now passes the asset policy with lower.rs at 521,358 bytes. All 36 WARP VALU tests passed on the new PR head and all 44 passed with #2623 and the other shader changes. Strict shader Clippy passed.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7190202258 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166#issuecomment-7190202258). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T11:03:20Z. --- Updated to `b5a1678` to keep the normalized-half code and its MODE analysis in one module. The initial tree exceeded the repository's source-size limit when combined with #2623 and the independent shader fixes. The composed tree now passes the asset policy with `lower.rs` at 521,358 bytes. All 36 WARP VALU tests passed on the new PR head and all 44 passed with #2623 and the other shader changes. Strict shader Clippy passed.
Dukestar69 commented 2026-11-26 11:10:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T11:10:15Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib v_cvt_norm_f16_honors_input_denormal_mode -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Cleanly honors explicit half-float input denormal flush mode in normalized f16 conversions.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6073098361 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166#pullrequestreview-6073098361). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T11:10:15Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib v_cvt_norm_f16_honors_input_denormal_mode -- --test-threads=1`: passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Cleanly honors explicit half-float input denormal flush mode in normalized f16 conversions. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Lyrnc commented 2026-11-26 17:21:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-26T17:21:38Z.


Checked b5a1678 on RDNA2 hardware, using your MODE writes, with the same instruction words on both sides.

  • Hardware: Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs one of your two ways of setting the mode:

    • s_denorm_mode (d << 2) | 3, or
    • s_denorm_mode with the opposite input bit, then s_setreg_imm32_b32 hwreg(MODE, 6, 1) and an s_nop 3.

    Then it runs three v_cvt_norm_i16_f16 or three v_cvt_norm_u16_f16. The 390 halves are:

    • your 17 values;
    • every 5th positive subnormal and every 9th negative one;
    • the edge of the normal range, ±1, NaNs, and random halves.

    Each source has junk in its high half, and each destination is preset.

  • Translator: the same words through a local copy of the build_valu_cs harness (a local test, not part of this PR). I ran it on main 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in hardware_adapter).

The runs cover 2 opcodes × 4 FP16 denormal modes × 2 ways of writing MODE, which gives 6,240 results.

Host branch matches the hardware bit for bit other differences
Radeon gfx1036 main 4,536 1,704
Radeon gfx1036 #3166 6,240 0
RTX 5080 main 4,536 1,704
RTX 5080 #3166 6,240 0
  • main: every difference is a subnormal input in modes 0 and 2 (input denormals flushed), where the hardware gives 0. For example:
    • v_cvt_norm_i16_f16(0x0101) gives 0x0001, and (0x83ff) gives 0xfffe;
    • v_cvt_norm_u16_f16(0x0081) gives 0x0001.
  • This PR: it matches every result, in both ways of writing MODE.
  • On the hardware, s_setreg_imm32_b32 on MODE[6] gives the same results as s_denorm_mode in all 8 combinations. So the bit your analysis reads is the one the hardware uses.
  • Modes 1 and 3 (input denormals kept) match on both branches, as in #376.

I did not run the case where two branches join, because the hardware side would need one SGPR value per wave.

No game data was used.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7198882909 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166#issuecomment-7198882909). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-26T17:21:38Z. --- Checked `b5a1678` on RDNA2 hardware, using your MODE writes, with the same instruction words on both sides. - **Hardware:** Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs one of your two ways of setting the mode: - `s_denorm_mode (d << 2) | 3`, or - `s_denorm_mode` with the opposite input bit, then `s_setreg_imm32_b32 hwreg(MODE, 6, 1)` and an `s_nop 3`. Then it runs three `v_cvt_norm_i16_f16` or three `v_cvt_norm_u16_f16`. The 390 halves are: - your 17 values; - every 5th positive subnormal and every 9th negative one; - the edge of the normal range, ±1, NaNs, and random halves. Each source has junk in its high half, and each destination is preset. - **Translator:** the same words through a local copy of the `build_valu_cs` harness (a local test, not part of this PR). I ran it on `main` 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in `hardware_adapter`). The runs cover 2 opcodes × 4 FP16 denormal modes × 2 ways of writing MODE, which gives 6,240 results. | Host | branch | matches the hardware bit for bit | other differences | |---|---|---|---| | Radeon gfx1036 | main | 4,536 | 1,704 | | Radeon gfx1036 | #3166 | 6,240 | **0** | | RTX 5080 | main | 4,536 | 1,704 | | RTX 5080 | #3166 | 6,240 | **0** | - **main:** every difference is a subnormal input in modes 0 and 2 (input denormals flushed), where the hardware gives 0. For example: - `v_cvt_norm_i16_f16(0x0101)` gives `0x0001`, and `(0x83ff)` gives `0xfffe`; - `v_cvt_norm_u16_f16(0x0081)` gives `0x0001`. - **This PR:** it matches every result, in both ways of writing MODE. - On the hardware, `s_setreg_imm32_b32` on MODE[6] gives the same results as `s_denorm_mode` in all 8 combinations. So the bit your analysis reads is the one the hardware uses. - Modes 1 and 3 (input denormals kept) match on both branches, as in #376. I did not run the case where two branches join, because the hardware side would need one SGPR value per wave. No game data was used. AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.
andrewpozdnakov7-jpg commented 2026-11-26 21:31:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T21:31:29Z.


I tested b5a1678 with #3365 at 2c7372e and the #2623/#3192/#3364 integration in a6ba20e. Both input and output analyses use the same MODE propagation. Input analysis still runs only when the shader needs a normalized half conversion.

The new regression produces two values in one shader. A normalized integer conversion reads a subnormal input, and a fused multiply-add with normal inputs produces a signed subnormal. Across s_denorm_mode 0, 4, 8, 12, the two output words verify independent control by bits 6 and 7, for both signs. The control without #3166 differs on four input-flush cases. The combined commit gives the expected two words for all eight cases in three app-local WARP runs. The affected suite had 125 passed and one ignored. Strict Clippy in both configurations and the asset policy check pass, with lower.rs at 519,273 bytes.

The gfx1036 hardware result above covers this PR at b5a1678. The combined result is a WARP check. If you take the shared MODE resolution or the new test, please keep the Git author or use Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203808376 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166#issuecomment-7203808376). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T21:31:29Z. --- I tested `b5a1678` with #3365 at `2c7372e` and the #2623/#3192/#3364 integration in [`a6ba20e`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/a6ba20e6a36f3bed5f86c22eaf01a5f3158f6d47). Both input and output analyses use the same MODE propagation. Input analysis still runs only when the shader needs a normalized half conversion. The new regression produces two values in one shader. A normalized integer conversion reads a subnormal input, and a fused multiply-add with normal inputs produces a signed subnormal. Across `s_denorm_mode 0, 4, 8, 12`, the two output words verify independent control by bits 6 and 7, for both signs. The control without #3166 differs on four input-flush cases. The combined commit gives the expected two words for all eight cases in three app-local WARP runs. The affected suite had 125 passed and one ignored. Strict Clippy in both configurations and the asset policy check pass, with `lower.rs` at 519,273 bytes. The gfx1036 hardware result above covers this PR at `b5a1678`. The combined result is a WARP check. If you take the shared MODE resolution or the new test, please keep the Git author or use `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
fuzeofficlal commented 2026-11-26 21:52:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:52:36Z.

Review: APPROVED


Verified on b5a16783:

  • cargo xtask policy: 192 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • rustfmt --edition 2024 --check: clean on crates/victory-shader/src/emit/lower/norm16.rs and on the modified hunks in lower.rs and valu_tests.rs.
  • crates/victory-shader/src/emit/lower.rs size is 517,554 bytes (under the 512 KiB ceiling).
  • cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::valu_tests:: emit::lower::: 69 passed, 0 failed under both VICTORY_WARP=0 and VICTORY_WARP=1, including emit::valu_tests::v_cvt_norm_f16_honors_input_denormal_mode.

s_denorm_mode bit 2 and literal s_setreg* writes targeting MODE[6] (id == 1) are decoded accurately, and magnitude-only flushing in norm16.rs preserves -0.0 before exact scaling and integer conversion (0x0000 for signed/unsigned ±0.0 and NaNs). As a non-blocking follow-up note (matching the pre-existing round16 pattern), entry starts at None and disagreeing CFG joins, loop backedges, SGPR-sourced s_setreg_b32, and initial COMPUTE_PGM_RSRC1.FLOAT_MODE fall back to preserving subnormals; the new join test at valu_tests.rs:1183 exercises an agreeing flush path only. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6080885920 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3166#pullrequestreview-6080885920). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:52:36Z. **Review:** APPROVED --- Verified on `b5a16783`: - `cargo xtask policy`: `192 files ok`. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `rustfmt --edition 2024 --check`: clean on `crates/victory-shader/src/emit/lower/norm16.rs` and on the modified hunks in `lower.rs` and `valu_tests.rs`. - `crates/victory-shader/src/emit/lower.rs` size is `517,554` bytes (under the 512 KiB ceiling). - `cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::valu_tests:: emit::lower::`: **69 passed, 0 failed** under both `VICTORY_WARP=0` and `VICTORY_WARP=1`, including `emit::valu_tests::v_cvt_norm_f16_honors_input_denormal_mode`. `s_denorm_mode` bit 2 and literal `s_setreg*` writes targeting `MODE[6]` (`id == 1`) are decoded accurately, and magnitude-only flushing in `norm16.rs` preserves `-0.0` before exact scaling and integer conversion (`0x0000` for signed/unsigned `±0.0` and NaNs). As a non-blocking follow-up note (matching the pre-existing `round16` pattern), entry starts at `None` and disagreeing CFG joins, loop backedges, SGPR-sourced `s_setreg_b32`, and initial `COMPUTE_PGM_RSRC1.FLOAT_MODE` fall back to preserving subnormals; the new join test at `valu_tests.rs:1183` exercises an agreeing flush path only. LGTM.
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/3166:upstream-pr/3166'
git switch 'upstream-pr/3166'

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/3166'
git switch 'upstream-pr/3166'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3166'
git switch 'upstream-pr/3166'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3166'
git switch 'main'
git merge --squash 'upstream-pr/3166'
git switch 'main'
git merge --ff-only 'upstream-pr/3166'
git switch 'main'
git merge 'upstream-pr/3166'
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!3164
No description provided.