Shaders: lower v_cvt_pknorm_{i16,u16}_{f32,f16} in pure 32-bit DXIL #2100

Open
github-bot wants to merge 1 commit from github-bot/gh-2100 into main AGit
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 04:59 UTC · original
geiyiliyabumo:feat/shader-v-cvt-pknorm → main · +192 −0 · 2 files · 1 commits · open

Summary

  • Lowers GFX10 VOP3 packed normalized-16 conversion instructions v_cvt_pknorm_i16_f32 (0x368), v_cvt_pknorm_u16_f32 (0x369), v_cvt_pknorm_i16_f16 (0x312), and v_cvt_pknorm_u16_f16 (0x313) in crates/victory-shader/src/emit/lower.rs using pure 32-bit DXIL without enabling Int64 / WIDE_OPS.
  • Applies f32 clamping ([-1.0, 1.0] -> 32767.0 for i16, [0.0, 1.0] -> 65535.0 for u16), ties-to-even rounding, NaN -> 0, VOP3 abs/neg source modifiers, and op_sel half selection for _f16, while rejecting unsupported clamp and omod.
  • Adds 3 synthetic DXIL-validation and GPU execution tests in crates/victory-shader/src/emit/valu_tests.rs covering boundary values (0.0, -0.0, ±1.0, ±0.5, ±2.0, ±inf, NaN), abs/neg modifiers, op_sel half selection, output modifier rejection, and verifying Int64 is not set.

Verification

  • cargo xtask policy: passed
  • cargo clippy -p victory-shader --tests -- -D warnings: passed
  • cargo test -p victory-shader --lib v_cvt_pknorm -- --test-threads=1 with Microsoft dxil.dll: 3/3 passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP)
  • Zero game files or game-derived data used (synthetic tests only).
**@⁠geiyiliyabumo** on GitHub · 2026-11-25 04:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100) `geiyiliyabumo:feat/shader-v-cvt-pknorm` → `main` · +192 −0 · 2 files · 1 commits · open ## Summary - Lowers GFX10 VOP3 packed normalized-16 conversion instructions `v_cvt_pknorm_i16_f32` (`0x368`), `v_cvt_pknorm_u16_f32` (`0x369`), `v_cvt_pknorm_i16_f16` (`0x312`), and `v_cvt_pknorm_u16_f16` (`0x313`) in `crates/victory-shader/src/emit/lower.rs` using pure 32-bit DXIL without enabling `Int64` / `WIDE_OPS`. - Applies `f32` clamping (`[-1.0, 1.0]` -> `32767.0` for `i16`, `[0.0, 1.0]` -> `65535.0` for `u16`), ties-to-even rounding, NaN -> `0`, VOP3 `abs`/`neg` source modifiers, and `op_sel` half selection for `_f16`, while rejecting unsupported `clamp` and `omod`. - Adds 3 synthetic DXIL-validation and GPU execution tests in `crates/victory-shader/src/emit/valu_tests.rs` covering boundary values (`0.0`, `-0.0`, `±1.0`, `±0.5`, `±2.0`, `±inf`, `NaN`), `abs`/`neg` modifiers, `op_sel` half selection, output modifier rejection, and verifying `Int64` is not set. ## Verification - `cargo xtask policy`: passed - `cargo clippy -p victory-shader --tests -- -D warnings`: passed - `cargo test -p victory-shader --lib v_cvt_pknorm -- --test-threads=1` with Microsoft `dxil.dll`: 3/3 passed on **AMD Radeon RX 9060 XT (RDNA4)** and **Microsoft Basic Render Driver (WARP)** - Zero game files or game-derived data used (synthetic tests only).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:47 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 05:05 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at de026e8. victory-shader: 247 passed, 3 failed, 3 ignored. The new v_cvt_pknorm_rounds_clamps_and_packs, v_cvt_pknorm_honors_source_modifiers and v_cvt_pknorm_rejects_output_modifiers pass. The 3 failures are #1744's NVIDIA failures on main. Same as main on this hardware.

Overlap, from reading: #596 (open, conflicting with main) lowers the same four v_cvt_pknorm_{i16,u16}_{f32,f16} instructions with exact rounding.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 05:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7153440368) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `de026e8`. `victory-shader`: 247 passed, 3 failed, 3 ignored. The new `v_cvt_pknorm_rounds_clamps_and_packs`, `v_cvt_pknorm_honors_source_modifiers` and `v_cvt_pknorm_rejects_output_modifiers` pass. The 3 failures are #1744's NVIDIA failures on `main`. Same as `main` on this hardware. Overlap, from reading: #596 (open, conflicting with `main`) lowers the same four `v_cvt_pknorm_{i16,u16}_{f32,f16}` instructions with exact rounding. AI-assisted (Claude Code).
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 05:08 UTC · original · edited 2026-11-25 05:14 UTC

I replayed two of Lyrnc's native gfx1036 measurements on de026e8 with synthetic VOP3 programs. Set both source registers to the input bits and read back the packed destination. RTX 3050 Laptop and WARP returned the same words:

Opcode Input bits This PR, both backends Native RDNA2 desktop, from #596
v_cvt_pknorm_i16_f32 3f7334e6 799a799a 79997999
v_cvt_pknorm_u16_f32 3e2abaab 2aae2aae 2aaf2aaf

These two inputs would make regression cases for a 32-bit implementation that preserves the native result. Rounding the product to f32 first changes each converted half by one.

For the f16 forms, the 422-input native sample in #596 did not distinguish the rounding rules. I compared both models over all 65,536 half encodings on CPU; only four encodings per signedness distinguish them. If someone still has the native probe, one input covers both forms: put half 0x3801 in both sources. For signed/unsigned the exact-product predictions are 400f400f / 801f801f. This PR returned 40104010 / 80208020 on both backends. A native readback of those two words would settle this fixture's expectation.

AI-assisted. Synthetic inputs only.

Tested f32-only alternative that keeps Int64 off. After NaN handling and clamping, take the magnitude m and set P to 32768 (signed) or 65536 (unsigned). In f32, compute a = m * P and q = roundEven(a). The integer magnitude is int(q) - int((a - (q - 0.5)) < m); then restore the sign for SNORM. Keep the subtractions in that order. Scaling by the power of two is exact. The only exact halfway input magnitude is 0.5, for which q is even.

I checked every nonnegative binary32 encoding from 0 through 1 against an exact-product reference for each scale. An experimental lowering passed 94 packed readbacks each on RTX 3050 Laptop and WARP, including the two native f32 witnesses above. SFI0 Int64 stayed clear. The same probe failed on the unmodified PR at the first native witness. This experiment leaves the f16 decision open.

**@⁠Dathinel** on GitHub · 2026-11-25 05:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7153492372) · edited 2026-11-25 05:14 UTC I replayed two of [Lyrnc's native gfx1036 measurements](https://git.gtahub.st/github/Marvisak--VIctory/pulls/596) on `de026e8` with synthetic VOP3 programs. Set both source registers to the input bits and read back the packed destination. RTX 3050 Laptop and WARP returned the same words: | Opcode | Input bits | This PR, both backends | Native RDNA2 desktop, from #596 | |---|---|---|---| | `v_cvt_pknorm_i16_f32` | `3f7334e6` | `799a799a` | `79997999` | | `v_cvt_pknorm_u16_f32` | `3e2abaab` | `2aae2aae` | `2aaf2aaf` | These two inputs would make regression cases for a 32-bit implementation that preserves the native result. Rounding the product to f32 first changes each converted half by one. For the **f16** forms, the 422-input native sample in #596 did not distinguish the rounding rules. I compared both models over all 65,536 half encodings on CPU; only four encodings per signedness distinguish them. If someone still has the native probe, one input covers both forms: put half `0x3801` in both sources. For signed/unsigned the exact-product predictions are `400f400f` / `801f801f`. This PR returned `40104010` / `80208020` on both backends. A native readback of those two words would settle this fixture's expectation. AI-assisted. Synthetic inputs only. **Tested f32-only alternative that keeps Int64 off.** After NaN handling and clamping, take the magnitude `m` and set `P` to 32768 (signed) or 65536 (unsigned). In f32, compute `a = m * P` and `q = roundEven(a)`. The integer magnitude is `int(q) - int((a - (q - 0.5)) < m)`; then restore the sign for SNORM. Keep the subtractions in that order. Scaling by the power of two is exact. The only exact halfway input magnitude is 0.5, for which q is even. I checked every nonnegative binary32 encoding from 0 through 1 against an exact-product reference for each scale. An experimental lowering passed 94 packed readbacks each on RTX 3050 Laptop and WARP, including the two native f32 witnesses above. SFI0 Int64 stayed clear. The same probe failed on the unmodified PR at the first native witness. This experiment leaves the f16 decision open.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 08:38 UTC · original

Confirmed the two packed f32 rounding differences on an RTX 5080 (driver 621.40) at de026e8418ef97cf3531888e4a77204a86f5e5a6. Built-in WARP 10.0.26100.10068 returned the same words on Windows 11 build 26300.10075.

Both adapters passed all 56 round/clamp/pack readbacks and all 8 source-modifier readbacks in the PR. I then ran the two additional inputs below, putting the same f32 bit pattern in both source registers and reading back the packed 32-bit destination.

Instruction Input to each source RTX 5080 Built-in WARP Native Radeon RDNA2 from #596
v_cvt_pknorm_i16_f32 (0x368) 0x3f7334e6 0x799a799a 0x799a799a 0x79997999
v_cvt_pknorm_u16_f32 (0x369) 0x3e2abaab 0x2aae2aae 0x2aae2aae 0x2aaf2aaf

Each adapter completed both extra dispatches. Relative to the native measurements, each signed half is one high and each unsigned half is one low. This reproduces the earlier RTX 3050 Laptop result on Blackwell. Native Radeon measurements · Earlier RTX 3050 Laptop replay

**@⁠steven-seagull27** on GitHub · 2026-11-25 08:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7157284576) Confirmed the two packed f32 rounding differences on an RTX 5080 (driver 621.40) at `de026e8418ef97cf3531888e4a77204a86f5e5a6`. Built-in WARP 10.0.26100.10068 returned the same words on Windows 11 build 26300.10075. Both adapters passed all 56 round/clamp/pack readbacks and all 8 source-modifier readbacks in the PR. I then ran the two additional inputs below, putting the same f32 bit pattern in both source registers and reading back the packed 32-bit destination. | Instruction | Input to each source | RTX 5080 | Built-in WARP | Native Radeon RDNA2 from #596 | | --- | --- | --- | --- | --- | | `v_cvt_pknorm_i16_f32` (`0x368`) | `0x3f7334e6` | `0x799a799a` | `0x799a799a` | `0x79997999` | | `v_cvt_pknorm_u16_f32` (`0x369`) | `0x3e2abaab` | `0x2aae2aae` | `0x2aae2aae` | `0x2aaf2aaf` | Each adapter completed both extra dispatches. Relative to the native measurements, each signed half is one high and each unsigned half is one low. This reproduces the earlier RTX 3050 Laptop result on Blackwell. [Native Radeon measurements](https://git.gtahub.st/github/Marvisak--VIctory/pulls/596) · [Earlier RTX 3050 Laptop replay](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2100)
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:50 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head de026e84 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7157534303) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head de026e84 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:38 UTC · original · edited 2026-11-25 22:21 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/lower.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7159964436) · edited 2026-11-25 22:21 UTC <!-- victory-triage v1 head=bb36e8e79443b31de7e32adf421bb536b6b29785 verdict=needs-rebase at=2026-11-25T22:25:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/lower.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 13:23 UTC · original

Updated \ cvt_pknorm{i16,u16}_{f32,f16}\ (head $sha) to round from the exact product in pure 32-bit DXIL using @⁠Dathinel's power-of-two scaling method (\ = |x| * P, \q = roundEven(a), \mag = int(q) - int((a - (q - 0.5)) < |x|), keeping \SFI0 Int64\ clear). Added the native RDNA2 f32 witnesses (\

**@⁠geiyiliyabumo** on GitHub · 2026-11-25 13:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2100#issuecomment-7163711633) Updated \ _cvt_pknorm_{i16,u16}_{f32,f16}\ (head \$sha\) to round from the exact product in pure 32-bit DXIL using @⁠Dathinel's power-of-two scaling method (\ = |x| * P\, \q = roundEven(a)\, \mag = int(q) - int((a - (q - 0.5)) < |x|)\, keeping \SFI0 Int64\ clear). Added the native RDNA2 f32 witnesses (\
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2100/head:github-bot/gh-2100'
git switch 'github-bot/gh-2100'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2100'
git switch 'github-bot/gh-2100'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2100'
git switch 'github-bot/gh-2100'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2100'
git switch 'main'
git merge --squash 'github-bot/gh-2100'
git switch 'main'
git merge --ff-only 'github-bot/gh-2100'
git switch 'main'
git merge 'github-bot/gh-2100'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2100
No description provided.