Shaders: support clamp output modifier on v_cvt_pkrtz_f16_f32 #1339

Open
AscilCH wants to merge 1 commit from upstream-pr/1339 into main
AscilCH commented 2026-11-24 17:33:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AscilCH on 2026-11-24T17:33:08Z.


Bug

In crates/victory-shader/src/emit/lower.rs, v_cvt_pkrtz_f16_f32 (VOP2 0x2f / VOP3 0x12f) finished with int(self, r) → write_i(), which rejects the VOP3 clamp output modifier with Unsupported { what: "integer output modifiers" }.

On RDNA2 (GFX10.3), v_cvt_pkrtz_f16_f32 supports clamp, saturating both converted f16 lanes to [0.0, 1.0] (with NaN → +0.0) while preserving round-toward-zero semantics for values in (0.0, 1.0).

Reproduction (Before Fix)

Lowering a synthetic RDNA2 compute shader with v_cvt_pkrtz_f16_f32_e64 ... clamp:

lower: Unsupported { offset: 36, what: "integer output modifiers" }

Fix

  • Reject unsupported v.omod explicitly, saturate both f32 operands via dx.op.unary.f32(Saturate) when v.clamp is set before calling f16_toward_zero(), and write the packed u32 directly via self.write(inst, Reg::V(reg), r, guard).
  • Added hardware + WARP + dxil.dll test emit::valu_tests::v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz covering unclamped RTZ/overflow/infinity/subnormal values, clamped [0.0, 1.0]/NaN/infinity/sub-ULP values, and VOP3 abs/neg input modifiers.

Verification

Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK dxil.dll:

  • rustfmt --edition 2024 --check on valu_tests.rs: clean
  • cargo xtask policy: 154 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked -- v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz --nocapture --test-threads=1: passed (hardware + WARP + dxil.dll)
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1: 121 passed, 0 failed, 1 ignored
<!-- greyfinch-sync:Marvisak/VIctory:issue:5477179408 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-24T17:33:08Z. --- ### Bug In `crates/victory-shader/src/emit/lower.rs`, `v_cvt_pkrtz_f16_f32` (`VOP2 0x2f` / `VOP3 0x12f`) finished with `int(self, r)` → `write_i()`, which rejects the VOP3 `clamp` output modifier with `Unsupported { what: "integer output modifiers" }`. On RDNA2 (GFX10.3), `v_cvt_pkrtz_f16_f32` supports `clamp`, saturating both converted `f16` lanes to `[0.0, 1.0]` (with `NaN → +0.0`) while preserving round-toward-zero semantics for values in `(0.0, 1.0)`. ### Reproduction (Before Fix) Lowering a synthetic RDNA2 compute shader with `v_cvt_pkrtz_f16_f32_e64 ... clamp`: ```text lower: Unsupported { offset: 36, what: "integer output modifiers" } ``` ### Fix - Reject unsupported `v.omod` explicitly, saturate both `f32` operands via `dx.op.unary.f32(Saturate)` when `v.clamp` is set before calling `f16_toward_zero()`, and write the packed `u32` directly via `self.write(inst, Reg::V(reg), r, guard)`. - Added hardware + WARP + `dxil.dll` test `emit::valu_tests::v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz` covering unclamped RTZ/overflow/infinity/subnormal values, clamped `[0.0, 1.0]`/NaN/infinity/sub-ULP values, and VOP3 `abs`/`neg` input modifiers. ### Verification Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK `dxil.dll`: - `rustfmt --edition 2024 --check` on `valu_tests.rs`: clean - `cargo xtask policy`: `154 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test -p victory-shader --locked -- v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz --nocapture --test-threads=1`: passed (hardware + WARP + `dxil.dll`) - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1`: `121 passed, 0 failed, 1 ignored`
marquezinii commented 2026-11-24 19:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:33:50Z.


Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at b686bcc. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 121 passed, 0 failed, 1 ignored. v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz passes on the hardware adapter and WARP.

Clamping in f32 before the round-toward-zero conversion gives the same result as clamping after it: 0 and 1 are exact in f16, and DXIL Saturate maps NaN to +0, which matches your table.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140819837 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7140819837). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:33:50Z. --- Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `b686bcc`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 121 passed, 0 failed, 1 ignored. `v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz` passes on the hardware adapter and WARP. Clamping in f32 before the round-toward-zero conversion gives the same result as clamping after it: 0 and 1 are exact in f16, and DXIL `Saturate` maps NaN to +0, which matches your table.
catminou4 commented 2026-11-24 20:09:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:58Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests.

Supports the clamp output modifier on v_cvt_pkrtz_f16_f32 (and rtz); v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046559617 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339#pullrequestreview-6046559617). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:58Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96 passed, 0 failed. Execution/valu tests are #[cfg(all(test, windows))] and only run on Windows; macOS covers lowering/structure/IR unit tests. Supports the clamp output modifier on v_cvt_pkrtz_f16_f32 (and rtz); v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz.
Marvisak commented 2026-11-25 02:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:23:10Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149490882 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7149490882). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:23:10Z. --- <!-- victory-triage v1 head=b686bcc5d9290b671d855e7c5c6d431eb2ec9d66 verdict=needs-rebase at=2026-11-25T01:23:08Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 02:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T01:48:53Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head b686bcc onto main ffe310e (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: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149987473 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7149987473). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T01:48:53Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head b686bcc onto `main` ffe310e (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: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
andrewpozdnakov7-jpg commented 2026-11-28 18:08:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T18:08:44Z.


I resolved the rebase conflict in the test file and replayed your commit on current main (63bcca4). Rebase 954e814 retains AscilCH's Git authorship and the original clamp/RTZ test alongside the tests added to main.

If #3773 lands first, combined 62ab0dd preserves both exact PR heads. The literal fold runs for the unclamped conversion. Clamped operands go through the original saturation and RTZ path.

On WARP 1.0.22 the author's clamp/RTZ regression passed on both branches. All 5,005 generated output words matched across 455 modules, including the 32 added clamped-literal modules. All 66 control modules were byte-identical, including those 32. The unclamped literal modules kept the emitted instruction savings. Strict all-feature shader Clippy and the asset policy passed on both exact trees.

AscilCH can take the rebase for the PR or use the combined branch if the literal change lands first. The next step after that is maintainer review. Please retain both Git authors when taking the combined change, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding my part into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7243565231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7243565231). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T18:08:44Z. --- I resolved the rebase conflict in the test file and replayed your commit on current main (63bcca4). [Rebase 954e814](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/954e81401829b29a011e76fccedf4deb9fdff933) retains AscilCH's Git authorship and the original clamp/RTZ test alongside the tests added to main. If #3773 lands first, [combined 62ab0dd](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/62ab0ddefd1f54aa6117df80f730bbf7ea74c605) preserves both exact PR heads. The literal fold runs for the unclamped conversion. Clamped operands go through the original saturation and RTZ path. On WARP 1.0.22 the author's clamp/RTZ regression passed on both branches. All 5,005 generated output words matched across 455 modules, including the 32 added clamped-literal modules. All 66 control modules were byte-identical, including those 32. The unclamped literal modules kept the emitted instruction savings. Strict all-feature shader Clippy and the asset policy passed on both exact trees. AscilCH can take the rebase for the PR or use the combined branch if the literal change lands first. The next step after that is maintainer review. Please retain both Git authors when taking the combined change, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding my part into another commit. AI-assisted with OpenAI Codex.
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/1339:upstream-pr/1339'
git switch 'upstream-pr/1339'

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