Shaders: honor directed rounding in integer-to-FP16 conversions #3807

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

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


On main, v_cvt_f16_u16 and v_cvt_f16_i16 round to nearest-even in modes 1 and 2. AMD documents rounding support for both instructions. For example, unsigned 2049 rounds to 2048 on main in mode 1, where the expected half value is 2050. AMD RDNA2 ISA, VOP1 instructions and section 6.4

The source first widens to an exact FP32 integer. When the nearest half lands on the wrong side for the selected direction, step one half encoding toward that direction. The original exact-input test from #990 remains in place.

Verification

  • The same synthetic test covers all 65,536 input bit patterns as both signed and unsigned values in all four modes. On 63bcca4, 35,584 input patterns had at least one mismatched output in each of modes 1 and 2 per WARP invocation. Modes 0 and 3 passed.
  • On afadaa9, all 1,048,576 readbacks matched across two invocations of WARP 1.0.22 with Agility 1.620.2, including both destination high-half sentinels.
  • The #990 exact-input test, the existing mode 0 and 3 FP32 conversion control, and all 33 lowerer tests passed. Strict shader Clippy passed with default and all features, and asset policy passed for 191 files.
  • A textual merge with the #3803/#3804 comparison branch at 9248dba was clean and left lower.rs at 523,645 bytes. The runtime checks above are for this PR's standalone head. A physical GPU run is pending.

Coordination claim

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:5545743326 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3807). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:45:40Z. --- On main, `v_cvt_f16_u16` and `v_cvt_f16_i16` round to nearest-even in modes 1 and 2. AMD documents rounding support for both instructions. For example, unsigned 2049 rounds to 2048 on main in mode 1, where the expected half value is 2050. [AMD RDNA2 ISA, VOP1 instructions and section 6.4](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content) The source first widens to an exact FP32 integer. When the nearest half lands on the wrong side for the selected direction, step one half encoding toward that direction. The original exact-input test from #990 remains in place. ### Verification - The same synthetic test covers all 65,536 input bit patterns as both signed and unsigned values in all four modes. On `63bcca4`, 35,584 input patterns had at least one mismatched output in each of modes 1 and 2 per WARP invocation. Modes 0 and 3 passed. - On `afadaa9`, all 1,048,576 readbacks matched across two invocations of WARP 1.0.22 with Agility 1.620.2, including both destination high-half sentinels. - The #990 exact-input test, the existing mode 0 and 3 FP32 conversion control, and all 33 lowerer tests passed. Strict shader Clippy passed with default and all features, and asset policy passed for 191 files. - A textual merge with the #3803/#3804 comparison branch at `9248dba` was clean and left `lower.rs` at 523,645 bytes. The runtime checks above are for this PR's standalone head. A physical GPU run is pending. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7247602662) 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:48:43 +00:00 (Migrated from github.com)

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


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

The separate WARP 1.0.22 run covered all 65,536 16-bit input codes as both signed and unsigned operands in all four rounding modes. It matched all 1,048,576 readbacks across both software-device invocations. With the same test on 63bcca4, 35,584 input codes had a mismatch in each of modes 1 and 2 per invocation. Modes 0 and 3 passed on both builds. A physical GPU run is pending.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247679378 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3807#issuecomment-7247679378). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:48:43Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46203143512) passed on `afadaa9`, including the workspace tests and both Clippy configurations. The separate WARP 1.0.22 run covered all 65,536 16-bit input codes as both signed and unsigned operands in all four rounding modes. It matched all 1,048,576 readbacks across both software-device invocations. With the same test on `63bcca4`, 35,584 input codes had a mismatch in each of modes 1 and 2 per invocation. Modes 0 and 3 passed on both builds. A physical GPU run is pending.
cloph-dsp commented 2026-11-28 23:51:32 +00:00 (Migrated from github.com)

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


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

  • PR #3807 at head afadaa9b129e7ebafa81a5a7bfeb7ff01a4045e7, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_integer_conversions_honor_round_mode --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check HEAD^ HEAD clean (2 files, +61/-1).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • 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:7247709962 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3807#issuecomment-7247709962). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T23:51:32Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3807 at head `afadaa9b129e7ebafa81a5a7bfeb7ff01a4045e7`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::semantics_tests::f16_integer_conversions_honor_round_mode --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check HEAD^ HEAD` clean (2 files, +61/-1). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - 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/3807:upstream-pr/3807'
git switch 'upstream-pr/3807'

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