Shaders: honor directed rounding in v_cvt_f16_f32 #3803

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

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


The FP16 field of FP_ROUND selects rounding toward positive infinity in mode 1 and negative infinity in mode 2 (AMD RDNA2 ISA, section 6.4). On current main, v_cvt_f16_f32 uses nearest-even for both modes. For example, 0x3f800800 (+1.000244140625) rounds to 0x3c00 in mode 1, where the next higher FP16 value is 0x3c01.

For this conversion, start with the existing truncation and step one half encoding outward when the finite input is inexact and the direction requires it. A bitwise comparison with the widened half handles underflow into the FP16 subnormal range and overflow to half infinity. The path retains the emitter's signed-zero handling for FP32 subnormals and the existing NaN encoding and high-half destination behavior.

Verification

  • On upstream 63bcca4 with only the new test applied, 26 of 50 signed inputs differed from the expected result in each of two WARP invocations.
  • At fda9900, all 200 readbacks match (50 signed inputs × 2 modes × 2 invocations on WARP 1.0.22 / Agility 1.620.2). The existing 38-input test for modes 0 and 3 also passes.
  • Shader Clippy passes with warnings denied for default and all features. Asset policy passes for 191 files.
  • These are synthetic WARP results. A physical Radeon run remains pending.

Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7246795231

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

AI-assisted contribution.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5545258411 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3803). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T22:37:22Z. --- The FP16 field of `FP_ROUND` selects rounding toward positive infinity in mode 1 and negative infinity in mode 2 (AMD [RDNA2 ISA, section 6.4](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content)). On current main, `v_cvt_f16_f32` uses nearest-even for both modes. For example, `0x3f800800` (+1.000244140625) rounds to `0x3c00` in mode 1, where the next higher FP16 value is `0x3c01`. For this conversion, start with the existing truncation and step one half encoding outward when the finite input is inexact and the direction requires it. A bitwise comparison with the widened half handles underflow into the FP16 subnormal range and overflow to half infinity. The path retains the emitter's signed-zero handling for FP32 subnormals and the existing NaN encoding and high-half destination behavior. ### Verification - On upstream `63bcca4` with only the new test applied, 26 of 50 signed inputs differed from the expected result in each of two WARP invocations. - At `fda9900`, all 200 readbacks match (50 signed inputs × 2 modes × 2 invocations on WARP 1.0.22 / Agility 1.620.2). The existing 38-input test for modes 0 and 3 also passes. - Shader Clippy passes with warnings denied for default and all features. Asset policy passes for 191 files. - These are synthetic WARP results. A physical Radeon run remains pending. Claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7246795231 Please retain the Git author when cherry-picking or rebasing. If squashing into another commit, please add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`. AI-assisted contribution.
andrewpozdnakov7-jpg commented 2026-11-28 22:40:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T22:40:52Z.


Windows CI passed on fda9900, including the workspace tests and both Clippy configurations.

I also checked the directed conversion separately on WARP 1.0.22. With the regression test applied to 63bcca4, 26 of 50 signed inputs differed from the expected result in each of two invocations. With fda9900, all 200 readbacks matched across modes 1 and 2. The existing 38-input test for modes 0 and 3 passed. A physical Radeon run is still pending.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246905821 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3803#issuecomment-7246905821). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T22:40:52Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46197583554) passed on `fda9900`, including the workspace tests and both Clippy configurations. I also checked the directed conversion separately on WARP 1.0.22. With the regression test applied to `63bcca4`, 26 of 50 signed inputs differed from the expected result in each of two invocations. With `fda9900`, all 200 readbacks matched across modes 1 and 2. The existing 38-input test for modes 0 and 3 passed. A physical Radeon run is still pending.
ColorMeBoom commented 2026-11-28 23:37:47 +00:00 (Migrated from github.com)

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


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

  • f16_conversion_honors_both_directed_modes: pass.
  • 1 case, 50 inputs. It had no mismatch against the model on either adapter, and hardware and WARP agreed on every input. The case:
    • s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000001); v_cvt_f16_f32 v5, v1; s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000002); v_cvt_f16_f32 v6, v1
  • 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:7247558180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3803#issuecomment-7247558180). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T23:37:47Z. --- Hardware run on AMD: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `fda990023` on `63bcca4`. The fixture runs the hardware adapter and WARP in turn, and neither was skipped. - `f16_conversion_honors_both_directed_modes`: pass. - 1 case, 50 inputs. It had no mismatch against the model on either adapter, and hardware and WARP agreed on every input. The case: - `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000001); v_cvt_f16_f32 v5, v1; s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), lit(0x00000002); v_cvt_f16_f32 v6, v1` - 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-29 04:36:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-29T04:36:05Z.


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

  • PR #3803 at head fda9900236892b9fbf3a616c28f120d753ebeeb6, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_conversion_honors_both_directed_modes --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the test name on the parent returned no match (exit 1; test is new on this PR); git diff --check HEAD^ HEAD clean (2 files, +93/-2).
  • Used a per-worktree CARGO_TARGET_DIR (target-3803-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 here.
  • GPU/driver: N/A (CPU-only shader semantics test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7250750194 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3803#issuecomment-7250750194). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-29T04:36:05Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3803 at head `fda9900236892b9fbf3a616c28f120d753ebeeb6`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_conversion_honors_both_directed_modes --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the test name on the parent returned no match (exit 1; test is new on this PR); `git diff --check HEAD^ HEAD` clean (2 files, +93/-2). - Used a per-worktree `CARGO_TARGET_DIR` (`target-3803-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 here. - GPU/driver: N/A (CPU-only shader semantics test). 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/3803:upstream-pr/3803'
git switch 'upstream-pr/3803'

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