Shaders: emit fewer instructions for FP16 denormal rounding #3620

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

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:34:12Z.


For #2384. Narrowing f32 to f16 still uses the software path in several shader instructions. This shortens the calculation for magnitudes below the smallest normal half by adding the nearest-even bias to the mantissa before shifting it. The clamped shift already yields zero for f32 subnormals, so the explicit zeroing step can go.

For a generated compute shader with one runtime v_cvt_f16_f32 and a readback, DXIL instructions fell from 62 to 55 under nearest-even and from 46 to 44 under round-to-zero. The same shader passed readback and validation on Windows WARP 1.0.22 with D3D12 Agility 1.620.2.

A CPU sweep compared both integer calculations for every magnitude below the smallest normal half, including zero, across both rounding modes. All 947,912,704 magnitudes match. The expanded WARP regression passes 62 inputs under both modes, including both signs and values around four subnormal midpoints. Both strict shader Clippy configurations and the asset policy passed.

Coordination claim

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5533962560 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3620). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T22:34:12Z. --- For #2384. Narrowing f32 to f16 still uses the software path in several shader instructions. This shortens the calculation for magnitudes below the smallest normal half by adding the nearest-even bias to the mantissa before shifting it. The clamped shift already yields zero for f32 subnormals, so the explicit zeroing step can go. For a generated compute shader with one runtime `v_cvt_f16_f32` and a readback, DXIL instructions fell from **62 to 55** under nearest-even and from **46 to 44** under round-to-zero. The same shader passed readback and validation on Windows WARP 1.0.22 with D3D12 Agility 1.620.2. A CPU sweep compared both integer calculations for every magnitude below the smallest normal half, including zero, across both rounding modes. All 947,912,704 magnitudes match. The expanded WARP regression passes 62 inputs under both modes, including both signs and values around four subnormal midpoints. Both strict shader Clippy configurations and the asset policy passed. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7229366274) AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-27 22:37:14 +00:00 (Migrated from github.com)

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


Verified 0fcf49d on Windows with app-local WARP 1.0.22 and the DXIL validator. For one runtime conversion, the disassembler counts 62 → 55 instructions under nearest-even and 46 → 44 under round-to-zero. The DXIL containers also shrink from 2,392 to 2,356 bytes and from 2,316 to 2,304 bytes, respectively.

The CPU comparison covered all 947,912,704 magnitudes below the smallest normal FP16 value in each mode. The expanded WARP test passed 62 inputs under both settings, including ties at zero, odd and even retained bits, the normal boundary, and their signed counterparts. Both strict shader Clippy configurations and the asset policy passed. Windows CI for this head

Git's merge checks with #3617, #2943 and #3365 are clean. These are useful as independent changes to the rounding rule, the NaN path and the output denormal setting.

Please keep the Git author on a cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if this work is folded into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7229479382 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3620#issuecomment-7229479382). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-27T22:37:14Z. --- Verified `0fcf49d` on Windows with app-local WARP 1.0.22 and the DXIL validator. For one runtime conversion, the disassembler counts **62 → 55** instructions under nearest-even and **46 → 44** under round-to-zero. The DXIL containers also shrink from 2,392 to 2,356 bytes and from 2,316 to 2,304 bytes, respectively. The CPU comparison covered all 947,912,704 magnitudes below the smallest normal FP16 value in each mode. The expanded WARP test passed 62 inputs under both settings, including ties at zero, odd and even retained bits, the normal boundary, and their signed counterparts. Both strict shader Clippy configurations and the asset policy passed. [Windows CI for this head](https://github.com/Marvisak/VIctory/actions/runs/46077449048/job/140768389654) Git's merge checks with #3617, #2943 and #3365 are clean. These are useful as independent changes to the rounding rule, the NaN path and the output denormal setting. Please keep the Git author on a cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if this work is folded into another commit. AI-assisted with OpenAI Codex.
ColorMeBoom commented 2026-11-28 00:24:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T00:24:29Z.


Hardware run on AMD, since the report so far is WARP: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head 0fcf49d on 63bcca4.

  • semantics_tests: 34 passed, 1 ignored. Every row of the arithmetic matrix has zero mismatches on the card and on WARP.
  • Full victory-shader --lib --features host: 302 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7230887896 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3620#issuecomment-7230887896). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T00:24:29Z. --- Hardware run on AMD, since the report so far is WARP: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `0fcf49d` on `63bcca4`. - `semantics_tests`: 34 passed, 1 ignored. Every row of the arithmetic matrix has zero mismatches on the card and on WARP. - Full `victory-shader --lib --features host`: 302 passed, 0 failed, 3 ignored. AI use: Claude Code (Claude Opus 5.5).
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/3620:upstream-pr/3620'
git switch 'upstream-pr/3620'

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