Shaders: support clamp output modifier on v_cvt_pkrtz_f16_f32 #1339

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

@⁠AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/v-cvt-pkrtz-f16-f32-clamp → main · +109 −2 · 2 files · 1 commits · open

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
**@⁠AscilCH** on GitHub · 2026-11-24 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1339) `AscilCH:fix/v-cvt-pkrtz-f16-f32-clamp` → `main` · +109 −2 · 2 files · 1 commits · open ### 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`
In crates/victory-shader/src/emit/lower.rs, v_cvt_pkrtz_f16_f32 finished
with int(self, r), which calls write_i() and rejects VOP3 clamp with
Err("integer output modifiers").

On RDNA2 (GFX10.3), v_cvt_pkrtz_f16_f32 (VOP2 0x2f / VOP3 0x12f) supports
the clamp output modifier, saturating both converted f16 results to
[0.0, 1.0] (with NaN -> +0.0) while preserving round-toward-zero semantics
on values in (0.0, 1.0).

Fix:
- Reject unsupported v.omod, saturate both f32 inputs via
  dx.op.unary.f32(Saturate) when v.clamp is set before f16_toward_zero(),
  and write the packed result directly via self.write().
- Add hardware + WARP + dxil.dll test
  emit::valu_tests::v_cvt_pkrtz_f16_f32_supports_clamp_and_rtz covering
  unclamped RTZ/overflow/inf/subnormal cases, clamped range/NaN/inf/sub-ULP
  cases, and abs/neg input modifiers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:28:09 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:33 UTC · original

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.

**@⁠marquezinii** on GitHub · 2026-11-24 18:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7140819837) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:23 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 01:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7149490882) <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 01:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1339#issuecomment-7149987473) ### 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).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.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/1339/head:github-bot/gh-1339'
git switch 'github-bot/gh-1339'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1339'
git switch 'github-bot/gh-1339'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1339'
git switch 'github-bot/gh-1339'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1339'
git switch 'main'
git merge --squash 'github-bot/gh-1339'
git switch 'main'
git merge --ff-only 'github-bot/gh-1339'
git switch 'main'
git merge 'github-bot/gh-1339'
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!1339
No description provided.