Shaders: allow abs/neg source modifiers on v_cvt_{u16,i16}_f16 #2963

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

@⁠Dukestar69 on GitHub · 2026-11-26 01:44 UTC · original
Dukestar69:fix/valu16-omod-and-cvt-saturation → main · +92 −3 · 2 files · 1 commits · open

Summary

Allow VOP3 abs/neg source modifiers on v_cvt_u16_f16 and v_cvt_i16_f16 in valu16_op (crates/victory-shader/src/emit/lower.rs).

Testing

  • Added synthetic RDNA2 hardware/WARP test cvt_16bit_int_from_f16_saturates_and_honors_modifiers in crates/victory-shader/src/emit/valu_tests.rs.
  • cargo test -p victory-shader cvt_16bit_int_from_f16_saturates_and_honors_modifiers: passed on RTX 5090 and WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 01:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963) `Dukestar69:fix/valu16-omod-and-cvt-saturation` → `main` · +92 −3 · 2 files · 1 commits · open ## Summary Allow VOP3 `abs`/`neg` source modifiers on `v_cvt_u16_f16` and `v_cvt_i16_f16` in `valu16_op` (`crates/victory-shader/src/emit/lower.rs`). ## Testing - Added synthetic RDNA2 hardware/WARP test `cvt_16bit_int_from_f16_saturates_and_honors_modifiers` in `crates/victory-shader/src/emit/valu_tests.rs`. - `cargo test -p victory-shader cvt_16bit_int_from_f16_saturates_and_honors_modifiers`: passed on RTX 5090 and WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:18:45 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 02:01 UTC · original

Independent Windows WARP report: head 81cf605968dbbacdfe167d20421c0f262f903848, exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0

Setup: Windows 11 Pro 26200, Rust MSVC, VICTORY_D3D12_WARP=1 and VICTORY_WARP=1 (so run_cases' "hardware" pass also goes through EnumWarpAdapter), VICTORY_DXIL= SDK 10.0.26100.0 x64\dxil.dll, -j 4, fresh target dir. No physical adapter was used.

Forcing confirmed (local-only probe, not pushed): Host::new(false) and Host::new(true) both report adapter Microsoft Basic Render Driver, DXGI_ADAPTER_FLAG_SOFTWARE set, host.warp = true. The SDK validator loaded from that path and validated all five synthetic shaders below (u16, u16 |src0|, i16, i16 -src0, u16 -|src0|).

Results

parent 63bcca4 head 81cf605
cvt_16bit_int_from_f16_saturates_and_honors_modifiers (PR test file applied to parent) fails: the abs/neg shaders are refused at build, modifiers on a 16-bit integer operation is not supported passes (both passes on WARP)
unmodified saturation cases from the PR test (6 u16 + 7 i16: ±inf, NaN, ±40000, 65504, ±123.75, -1.0) pass pass
extra local modifier cases: u16 -|123.75|→0, u16 -(-123.75)→123, u16 |-inf|→0xFFFF, i16 |-40000|→0x7FFF, i16 -(-inf)→0x7FFF, i16 -|40000|→0x8000, i16 -|NaN|→0 refused at build all pass, so abs is applied before neg and the result saturates after the modifiers
cargo test -p victory-shader --no-fail-fast (lib) 298 passed, 4 failed, 3 ignored 299 passed, 4 failed, 3 ignored

On both commits the same 4 tests fail. They are WARP baseline failures, unrelated to this PR: emit::synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}. The only difference is the one new test, which passes. Other test targets: 3 passed / 1 ignored on both.

Lint/policy at head: cargo clippy -p victory-shader --all-targets -- -D warnings clean; cargo xtask policy: 191 files ok. Nit: cargo fmt --check shows 2 new hunks in valu_tests.rs (the alignment of the trailing comments in i16_cases). The parent isn't rustfmt-clean either, so this doesn't block anything.

Verdict: on WARP the fix does what it says. The abs/neg relaxation covers only v_cvt_{u16,i16}_f16, the diff still refuses clamp/omod (I read that, I didn't test it), and no WARP regressions show up compared with the parent.

Synthetic shaders only; no game files, dumps or title shaders. AI-assisted: Claude Code (Claude Opus 5.5).

**@⁠oni-swr** on GitHub · 2026-11-26 02:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#issuecomment-7180387141) **Independent Windows WARP report: head `81cf605968dbbacdfe167d20421c0f262f903848`, exact parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`** Setup: Windows 11 Pro 26200, Rust MSVC, `VICTORY_D3D12_WARP=1` **and** `VICTORY_WARP=1` (so `run_cases`' "hardware" pass also goes through `EnumWarpAdapter`), `VICTORY_DXIL=` SDK 10.0.26100.0 `x64\dxil.dll`, `-j 4`, fresh target dir. No physical adapter was used. **Forcing confirmed** (local-only probe, not pushed): `Host::new(false)` and `Host::new(true)` both report adapter `Microsoft Basic Render Driver`, `DXGI_ADAPTER_FLAG_SOFTWARE` set, `host.warp = true`. The SDK validator loaded from that path and validated all five synthetic shaders below (u16, u16 `|src0|`, i16, i16 `-src0`, u16 `-|src0|`). **Results** | | parent `63bcca4` | head `81cf605` | |---|---|---| | `cvt_16bit_int_from_f16_saturates_and_honors_modifiers` (PR test file applied to parent) | **fails**: the abs/neg shaders are refused at build, `modifiers on a 16-bit integer operation is not supported` | **passes** (both passes on WARP) | | unmodified saturation cases from the PR test (6 u16 + 7 i16: ±inf, NaN, ±40000, 65504, ±123.75, -1.0) | pass | pass | | extra local modifier cases: u16 `-\|123.75\|`→0, u16 `-(-123.75)`→123, u16 `\|-inf\|`→0xFFFF, i16 `\|-40000\|`→0x7FFF, i16 `-(-inf)`→0x7FFF, i16 `-\|40000\|`→0x8000, i16 `-\|NaN\|`→0 | refused at build | all pass, so abs is applied before neg and the result saturates after the modifiers | | `cargo test -p victory-shader --no-fail-fast` (lib) | 298 passed, 4 failed, 3 ignored | 299 passed, 4 failed, 3 ignored | On both commits the same 4 tests fail. They are WARP baseline failures, unrelated to this PR: `emit::synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}`. The only difference is the one new test, which passes. Other test targets: 3 passed / 1 ignored on both. **Lint/policy at head:** `cargo clippy -p victory-shader --all-targets -- -D warnings` clean; `cargo xtask policy`: 191 files ok. Nit: `cargo fmt --check` shows 2 new hunks in `valu_tests.rs` (the alignment of the trailing comments in `i16_cases`). The parent isn't rustfmt-clean either, so this doesn't block anything. Verdict: on WARP the fix does what it says. The abs/neg relaxation covers only `v_cvt_{u16,i16}_f16`, the diff still refuses clamp/omod (I read that, I didn't test it), and no WARP regressions show up compared with the parent. Synthetic shaders only; no game files, dumps or title shaders. AI-assisted: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 02:15 UTC · original

I checked the full binary16 input range on 81cf6059, including source and destination half selection. For each of v_cvt_u16_f16 and v_cvt_i16_f16, I ran all four abs/neg combinations, both source halves and both destination halves. Each of the 32 shaders consumed all 65,536 bit patterns from a raw SRV and wrote the entire destination register to a UAV.

Adapter 32-bit readbacks Mismatches
NVIDIA GeForce RTX 5080, driver 621.40 2,097,152 0
Built-in Microsoft WARP 2,097,152 0

For each row, the other source half contained input ^ 0xc535 so an incorrect source selector would be visible. The initial destination was 0xa53cf139. The CPU reference applied absolute value, then negation, then Rust's saturating float-to-integer cast, and compared the unselected destination half as well. This covers signed zero, subnormals, infinities, and every NaN payload/sign combination. I couldn't reproduce a selector, modifier-order, or partial-write regression on either adapter.

**@⁠steven-seagull27** on GitHub · 2026-11-26 02:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#issuecomment-7180615202) I checked the full binary16 input range on `81cf6059`, including source and destination half selection. For each of `v_cvt_u16_f16` and `v_cvt_i16_f16`, I ran all four `abs`/`neg` combinations, both source halves and both destination halves. Each of the 32 shaders consumed all 65,536 bit patterns from a raw SRV and wrote the entire destination register to a UAV. | Adapter | 32-bit readbacks | Mismatches | | --- | ---: | ---: | | NVIDIA GeForce RTX 5080, driver 621.40 | 2,097,152 | 0 | | Built-in Microsoft WARP | 2,097,152 | 0 | For each row, the other source half contained `input ^ 0xc535` so an incorrect source selector would be visible. The initial destination was `0xa53cf139`. The CPU reference applied absolute value, then negation, then Rust's saturating float-to-integer cast, and compared the unselected destination half as well. This covers signed zero, subnormals, infinities, and every NaN payload/sign combination. I couldn't reproduce a selector, modifier-order, or partial-write regression on either adapter.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 05:43 UTC · original

Automated triage for the maintainers.

Verdict: merge candidate. This is a small change in crates/victory-shader/src/emit/lower.rs (the 16-bit integer arm of the VALU lowering). v_cvt_u16_f16 and v_cvt_i16_f16 with VOP3 abs/neg were refused before; now they translate. clamp and omod are still refused, as before.

The change is safe because those two conversions read their source through half_fsrc, which already applies abs and then neg per operand. Before this, the shared modifier check refused them anyway. abs/neg on a float input is standard GFX10 VOP3 behaviour. Every other 16-bit integer op still refuses source modifiers.

The new test cvt_16bit_int_from_f16_saturates_and_honors_modifiers covers saturation, NaN and the modifier forms. Testers above report it passing on WARP and an RTX 5080, and one checked all 65,536 inputs with every modifier and half combination against a CPU reference: 0 mismatches.

CI: not run on this head (no check runs reported). Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 05:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#issuecomment-7183746675) <!-- victory-triage v1 head=81cf605968dbbacdfe167d20421c0f262f903848 verdict=merge-candidate at=2026-11-26T05:43:14Z --> Automated triage for the maintainers. **Verdict: merge candidate.** This is a small change in `crates/victory-shader/src/emit/lower.rs` (the 16-bit integer arm of the VALU lowering). `v_cvt_u16_f16` and `v_cvt_i16_f16` with VOP3 `abs`/`neg` were refused before; now they translate. `clamp` and `omod` are still refused, as before. The change is safe because those two conversions read their source through `half_fsrc`, which already applies `abs` and then `neg` per operand. Before this, the shared modifier check refused them anyway. `abs`/`neg` on a float input is standard GFX10 VOP3 behaviour. Every other 16-bit integer op still refuses source modifiers. The new test `cvt_16bit_int_from_f16_saturates_and_honors_modifiers` covers saturation, NaN and the modifier forms. Testers above report it passing on WARP and an RTX 5080, and one checked all 65,536 inputs with every modifier and half combination against a CPU reference: 0 mismatches. CI: not run on this head (no check runs reported). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:54 UTC · original · reviewed

Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll) — clean and ready to merge:

  • crates/victory-shader/src/emit/lower.rs:7107-7129 restricts abs/neg relaxation to v_cvt_u16_f16 / v_cvt_i16_f16 (still rejecting clamp/omod and modifiers on other 16-bit integer ops); half_fsrc(inst, 0) applies legacyF16ToF32 exact widening and AMD VOP3 modifier order (-(|src0|)), followed by [0, 65535] / [-32768, 32767] clamping, FpToSi, and pred::UNO NaN-to-zero.
  • emit/lower.rs size on 63bcca43: 520,800 B (+237 B, 3,488 B below the 512 KiB policy limit).

Local verification:

  • cargo test --locked -p victory-shader -- cvt_16bit_int_from_f16 v_cvt_: 5/5 passed (including cvt_16bit_int_from_f16_saturates_and_honors_modifiers via valu_tests::run_cases on RTX 5090 + WARP + dxil.dll)
  • cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
  • cargo xtask policy: 191 files ok
**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#pullrequestreview-6067518970) · **reviewed** Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`) — clean and ready to merge: - `crates/victory-shader/src/emit/lower.rs:7107-7129` restricts `abs`/`neg` relaxation to `v_cvt_u16_f16` / `v_cvt_i16_f16` (still rejecting `clamp`/`omod` and modifiers on other 16-bit integer ops); `half_fsrc(inst, 0)` applies `legacyF16ToF32` exact widening and AMD VOP3 modifier order (`-(|src0|)`), followed by `[0, 65535]` / `[-32768, 32767]` clamping, `FpToSi`, and `pred::UNO` NaN-to-zero. - `emit/lower.rs` size on `63bcca43`: **520,800 B** (`+237 B`, **3,488 B** below the 512 KiB policy limit). **Local verification**: - `cargo test --locked -p victory-shader -- cvt_16bit_int_from_f16 v_cvt_`: **5/5 passed** (including `cvt_16bit_int_from_f16_saturates_and_honors_modifiers` via `valu_tests::run_cases` on RTX 5090 + WARP + `dxil.dll`) - `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `cargo xtask policy`: 191 files ok
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 02:19 UTC · original · reviewed

Verified: VOP3 abs/neg modifiers are legal on these two conversions because their source is float — the restriction stays in place for the integer-source ops via the float_src carve-out, and half_fsrc applies the modifiers. The vop3_mod encoding is correct (clamp bit 15, abs 8:10, omod 27:28, neg 29:31) and the cases pin saturation (not wrap), NaN→0, and both modifiers.

**@⁠kotekompotek** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#pullrequestreview-6067696274) · **reviewed** Verified: VOP3 abs/neg modifiers are legal on these two conversions because their source is float — the restriction stays in place for the integer-source ops via the float_src carve-out, and half_fsrc applies the modifiers. The vop3_mod encoding is correct (clamp bit 15, abs 8:10, omod 27:28, neg 29:31) and the cases pin saturation (not wrap), NaN→0, and both modifiers.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-26 17:21 UTC · original

Checked 81cf605 on RDNA2 hardware: VOP3 v_cvt_u16_f16 and v_cvt_i16_f16 with abs/neg, using the same instruction words on both sides.

  • Hardware: Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs all four abs/neg combinations on 192 halves:

    • ±0, ±0.5, ±1, ±2.5, ±max, ±inf, NaNs and subnormals;
    • the saturation edges (32752, 32768, 32784, ±65504);
    • random values.

    Each destination is preset, and the other half of the source holds a different value.

  • Translator: the same words through a local copy of the build_valu_cs harness (a local test, not part of this PR). I ran it on main 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in hardware_adapter).

With op_sel 0 (see below), 2 opcodes × 4 modifier combinations × 192 inputs give 1,536 results:

Host branch matches the hardware bit for bit other differences refused
Radeon gfx1036 main 0 0 1,536 (modifiers on a 16-bit integer operation)
Radeon gfx1036 #2963 1,536 0 0
RTX 5080 main 0 0 1,536
RTX 5080 #2963 1,536 0 0

So these all match the hardware: -|x| order, saturation, NaN → 0, and the kept high half. Without modifiers, main and the PR both match all 384 results.

op_sel, outside this PR. This is the same on main. On this GPU, VOP3 op_sel has no effect on these two opcodes:

  • With op_sel[0] (source high half) or op_sel[3] (destination high half) set, the hardware still reads and writes the low half.
  • The results are bit for bit the same as op_sel 0, on all 192 inputs × 4 modifier combinations.
  • The translator honours op_sel, so those forms differ. For example, with source 0x45358000 and op_sel[0], the hardware gives 0 (from the low half, -0) and the translator gives 5 (from the high half, 5.207).

Compiled code probably never sets op_sel on these. Still, the source/destination half-select cases in the larger check above follow the translator's model, not the hardware.

No game data was used.

AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.

**@⁠Lyrnc** on GitHub · 2026-11-26 17:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2963#issuecomment-7198888151) Checked `81cf605` on RDNA2 hardware: VOP3 `v_cvt_u16_f16` and `v_cvt_i16_f16` with `abs`/`neg`, using the same instruction words on both sides. - **Hardware:** Radeon iGPU (Ryzen 7 9800X3D), gfx1036 / RDNA2, driver 32.0.21042.62. A HIP kernel (assembled by the driver's amd_comgr) runs all four `abs`/`neg` combinations on 192 halves: - ±0, ±0.5, ±1, ±2.5, ±max, ±inf, NaNs and subnormals; - the saturation edges (32752, 32768, 32784, ±65504); - random values. Each destination is preset, and the other half of the source holds a different value. - **Translator:** the same words through a local copy of the `build_valu_cs` harness (a local test, not part of this PR). I ran it on `main` 63bcca4 and on the PR merged onto it, on the RTX 5080 (610.88) and on the same Radeon (picked with a local adapter-name filter in `hardware_adapter`). With `op_sel` 0 (see below), 2 opcodes × 4 modifier combinations × 192 inputs give 1,536 results: | Host | branch | matches the hardware bit for bit | other differences | refused | |---|---|---|---|---| | Radeon gfx1036 | main | 0 | 0 | 1,536 (`modifiers on a 16-bit integer operation`) | | Radeon gfx1036 | #2963 | 1,536 | **0** | 0 | | RTX 5080 | main | 0 | 0 | 1,536 | | RTX 5080 | #2963 | 1,536 | **0** | 0 | So these all match the hardware: `-|x|` order, saturation, NaN → 0, and the kept high half. Without modifiers, main and the PR both match all 384 results. **op_sel, outside this PR.** This is the same on main. On this GPU, VOP3 `op_sel` has no effect on these two opcodes: - With op_sel[0] (source high half) or op_sel[3] (destination high half) set, the hardware still reads and writes the low half. - The results are bit for bit the same as op_sel 0, on all 192 inputs × 4 modifier combinations. - The translator honours `op_sel`, so those forms differ. For example, with source `0x45358000` and op_sel[0], the hardware gives 0 (from the low half, -0) and the translator gives 5 (from the high half, 5.207). Compiled code probably never sets `op_sel` on these. Still, the source/destination half-select cases in the larger check above follow the translator's model, not the hardware. No game data was used. AI use: Claude Code (Claude Opus 5.5) wrote the probe and the comparison and ran them on the GPUs above; the numbers come from those runs.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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