Shaders: honor directed rounding in v_mul_f16 #3804

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3804 into main
andrewpozdnakov7-jpg commented 2026-11-28 23:06:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:06:04Z.


v_mul_f16 now uses the active half-precision rounding mode for modes 1 and 2. A product of two finite binary16 values fits exactly in f32. Start with the existing truncation, widen that half, and step one half encoding outward when the comparison shows truncation landed on the wrong side. AMD documents that the instruction honors the rounding mode. RDNA 2 ISA, sections 6.4 and 12.7

The synthetic test compares 529 pairs in each of the four modes against the CPU reference, with signed zeros, subnormals, overflow, infinities and NaNs. On 63bcca4, each WARP invocation had 65 mismatches in mode 1 and 58 in mode 2. The proposed build matched all 4,232 readbacks across both software-device invocations. The existing FP16 rounding and arithmetic tests and all 33 lowerer tests passed. Both strict shader Clippy configurations and the asset policy passed.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5545467582 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3804). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:06:04Z. --- `v_mul_f16` now uses the active half-precision rounding mode for modes 1 and 2. A product of two finite binary16 values fits exactly in f32. Start with the existing truncation, widen that half, and step one half encoding outward when the comparison shows truncation landed on the wrong side. AMD documents that the instruction honors the rounding mode. [RDNA 2 ISA, sections 6.4 and 12.7](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) The synthetic test compares 529 pairs in each of the four modes against the CPU reference, with signed zeros, subnormals, overflow, infinities and NaNs. On `63bcca4`, each WARP invocation had 65 mismatches in mode 1 and 58 in mode 2. The proposed build matched all 4,232 readbacks across both software-device invocations. The existing FP16 rounding and arithmetic tests and all 33 lowerer tests passed. Both strict shader Clippy configurations and the asset policy passed. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 23:11:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:11:37Z.


Windows CI passed on 386cc0f, including both Clippy configurations and workspace tests. In the signed WARP comparison, the 529 pairs matched in each of the four rounding modes on both software invocations. Main differed on 65 pairs in mode 1 and 58 pairs in mode 2 per invocation.

The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247262770 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3804#issuecomment-7247262770). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:11:37Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46199930098/job/141149605824) passed on `386cc0f`, including both Clippy configurations and workspace tests. In the signed WARP comparison, the 529 pairs matched in each of the four rounding modes on both software invocations. Main differed on 65 pairs in mode 1 and 58 pairs in mode 2 per invocation. The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 23:22:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:22:23Z.


The exact heads of #3803 (fda9900) and #3804 (386cc0f) conflict in the FP16 narrowing code and where the two regression tests are added. I resolved both conflicts in 9248dba. It keeps both tests and uses the same directed narrowing for conversion and multiply in modes 1 and 2. The helper preserves the existing signed-zero flush for FP32 subnormals. A nonzero product of two finite FP16 values is normal in FP32, so that rule does not flush a multiply result.

Test Main 63bcca4 with both tests, per WARP invocation Combined 9248dba, both WARP invocations
v_cvt_f16_f32 modes 1 and 2 26 of 50 inputs differ 200 of 200 readbacks match
v_mul_f16 modes 0–3 65 of 529 mode 1 pairs and 58 of 529 mode 2 pairs differ 4,232 of 4,232 readbacks match

WARP 1.0.22 with Agility 1.620.2. The existing mode 0 and 3 conversion test, the nearest-even and single-rounding tests, and all 33 lowerer tests also passed. Strict shader Clippy passed with default and all features. Asset policy passed for 191 files (lower.rs is 522,296 bytes). These combined results are from the software adapter.

Both original heads remain parents of the comparison branch. Please retain the Git authors on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my changes into another commit. Comparison branch

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247386476 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3804#issuecomment-7247386476). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:22:23Z. --- The exact heads of #3803 (`fda9900`) and #3804 (`386cc0f`) conflict in the FP16 narrowing code and where the two regression tests are added. I resolved both conflicts in `9248dba`. It keeps both tests and uses the same directed narrowing for conversion and multiply in modes 1 and 2. The helper preserves the existing signed-zero flush for FP32 subnormals. A nonzero product of two finite FP16 values is normal in FP32, so that rule does not flush a multiply result. | Test | Main `63bcca4` with both tests, per WARP invocation | Combined `9248dba`, both WARP invocations | | --- | --- | --- | | `v_cvt_f16_f32` modes 1 and 2 | 26 of 50 inputs differ | 200 of 200 readbacks match | | `v_mul_f16` modes 0–3 | 65 of 529 mode 1 pairs and 58 of 529 mode 2 pairs differ | 4,232 of 4,232 readbacks match | WARP 1.0.22 with Agility 1.620.2. The existing mode 0 and 3 conversion test, the nearest-even and single-rounding tests, and all 33 lowerer tests also passed. Strict shader Clippy passed with default and all features. Asset policy passed for 191 files (`lower.rs` is 522,296 bytes). These combined results are from the software adapter. Both original heads remain parents of the comparison branch. Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my changes into another commit. [Comparison branch](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/3803-3804-directed-fp16) AI-assisted with OpenAI Codex.
ColorMeBoom commented 2026-11-28 23:37:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T23:37:46Z.


Hardware run on AMD: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head 386cc0fcc on 63bcca4. The fixture runs the hardware adapter and WARP in turn, and neither was skipped.

  • f16_multiply_honors_round_mode: pass.
  • 4 cases (one per MODE round field value 0-3), 2,116 inputs in all. No case had a mismatch against the model on either adapter, and hardware and WARP agreed on every input. Examples:
    • s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000000); v_mul_f16 v5, v1, v2
    • s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000001); v_mul_f16 v5, v1, v2
    • s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000002); v_mul_f16 v5, v1, v2
    • s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000003); v_mul_f16 v5, v1, v2
  • Full victory-shader --lib --features host: 303 passed; 0 failed; 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247557989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3804#issuecomment-7247557989). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T23:37:46Z. --- Hardware run on AMD: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `386cc0fcc` on `63bcca4`. The fixture runs the hardware adapter and WARP in turn, and neither was skipped. - `f16_multiply_honors_round_mode`: pass. - 4 cases (one per `MODE` round field value 0-3), 2,116 inputs in all. No case had a mismatch against the model on either adapter, and hardware and WARP agreed on every input. Examples: - `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000000); v_mul_f16 v5, v1, v2` - `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000001); v_mul_f16 v5, v1, v2` - `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000002); v_mul_f16 v5, v1, v2` - `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000003); v_mul_f16 v5, v1, v2` - Full `victory-shader --lib --features host`: 303 passed; 0 failed; 3 ignored. AI use: Claude Code (Claude Opus 5.5).
cloph-dsp commented 2026-11-28 23:39:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T23:39:28Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3804 at head 386cc0fcc55351a2d8722f0a0ceef7c20423d185, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_multiply_honors_round_mode --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the new test name on the parent returned no match (test is new on this PR); git diff --check HEAD^ HEAD clean (2 files, +57/-2).
  • Used a per-worktree CARGO_TARGET_DIR (target-3804-watch, never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed locally; the full workspace suite and clippy were not run.
  • GPU/driver: N/A (CPU-only shader-lowering test with synthetic f16 inputs). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247576673 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3804#issuecomment-7247576673). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T23:39:28Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3804 at head `386cc0fcc55351a2d8722f0a0ceef7c20423d185`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_multiply_honors_round_mode --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the new test name on the parent returned no match (test is new on this PR); `git diff --check HEAD^ HEAD` clean (2 files, +57/-2). - Used a per-worktree `CARGO_TARGET_DIR` (target-3804-watch, never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed locally; the full workspace suite and clippy were not run. - GPU/driver: N/A (CPU-only shader-lowering test with synthetic f16 inputs). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
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/3804:upstream-pr/3804'
git switch 'upstream-pr/3804'

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