Shaders: reject VALU float/clamp modifiers in I/O and resource analyses #2490

Open
reeledMarek wants to merge 1 commit from upstream-pr/2492 into main
reeledMarek commented 2026-11-25 14:48:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T14:48:20Z.


Problem

Three VALU copy / address analysis helpers in victory-shader did not check the full set of VOP3 modifiers (abs, neg, clamp, omod) — separate from #2448, which covers Lower::konst:

  1. io.rs (Halves::joined): checked only dpp/sdwa on v_mov_b32, silently treating a modified copy of a hardware barycentric (e.g. -v0, abs(v0), clamp, mul:2) as the unmodified hardware barycentric.
  2. resource.rs (Tracer::vorigin and Tracer::vstep): checked abs/neg/sdwa/dpp on v_mov_b32, missing !clamp && omod == 0.
  3. resource.rs (Tracer::vadd): checked abs/neg/sdwa/dpp on v_add_nc_u32 / v_add_co_u32, missing !clamp && omod == 0 (on GFX10, clamped unsigned vector addition saturates at u32::MAX instead of wrapping modulo 2^32).

Fix

  • Require abs == 0 && neg == 0 && !clamp && omod == 0 && sdwa.is_none() && dpp.is_none() in all three helpers (matching range.rs::op_hi and resource.rs::lane_picked).
  • Added synthetic regression tests in io.rs and resource.rs verifying unmodified VOP3 forms still succeed while each modified form is rejected / kept opaque.

Verification

  • cargo test -p victory-shader --locked (146 passed, 0 failed)
  • cargo test -p xtask --locked (repository_passes_policy passed)
  • cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings (0 warnings)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607168912 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T14:48:20Z. --- ### Problem Three VALU copy / address analysis helpers in `victory-shader` did not check the full set of VOP3 modifiers (`abs`, `neg`, `clamp`, `omod`) — separate from #2448, which covers `Lower::konst`: 1. `io.rs` (`Halves::joined`): checked only `dpp`/`sdwa` on `v_mov_b32`, silently treating a modified copy of a hardware barycentric (e.g. `-v0`, `abs(v0)`, `clamp`, `mul:2`) as the unmodified hardware barycentric. 2. `resource.rs` (`Tracer::vorigin` and `Tracer::vstep`): checked `abs`/`neg`/`sdwa`/`dpp` on `v_mov_b32`, missing `!clamp && omod == 0`. 3. `resource.rs` (`Tracer::vadd`): checked `abs`/`neg`/`sdwa`/`dpp` on `v_add_nc_u32` / `v_add_co_u32`, missing `!clamp && omod == 0` (on GFX10, clamped unsigned vector addition saturates at `u32::MAX` instead of wrapping modulo 2^32). ### Fix - Require `abs == 0 && neg == 0 && !clamp && omod == 0 && sdwa.is_none() && dpp.is_none()` in all three helpers (matching `range.rs::op_hi` and `resource.rs::lane_picked`). - Added synthetic regression tests in `io.rs` and `resource.rs` verifying unmodified VOP3 forms still succeed while each modified form is rejected / kept opaque. ### Verification - `cargo test -p victory-shader --locked` (146 passed, 0 failed) - `cargo test -p xtask --locked` (`repository_passes_policy` passed) - `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` (0 warnings)
DenRakEiw commented 2026-11-25 15:04:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:58:00Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Rejecting VALU float/clamp modifiers in I/O and resource analyses prevents treating modified copies/adds as plain barycentric or address ops.
  • cargo test -p victory-shader resource::tests: 34/34 passed (including clamped_vector_add_and_modified_vector_copy_are_not_plain_address_ops).
  • cargo test -p victory-shader io::tests: 5/5 passed on RTX 5090 and WARP (including modified_barycentric_copy_is_not_treated_as_plain_barycentric).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6060003036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492#pullrequestreview-6060003036). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:58:00Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Rejecting VALU float/clamp modifiers in I/O and resource analyses prevents treating modified copies/adds as plain barycentric or address ops. - `cargo test -p victory-shader resource::tests`: 34/34 passed (including `clamped_vector_add_and_modified_vector_copy_are_not_plain_address_ops`). - `cargo test -p victory-shader io::tests`: 5/5 passed on RTX 5090 and WARP (including `modified_barycentric_copy_is_not_treated_as_plain_barycentric`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
cloph-dsp commented 2026-11-25 16:09:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T15:41:48Z.


Independent local validation for PR #2492 (Windows, Rust 1.100.0/MSVC, head 98017a5, no game data): cargo test --locked -p victory-shader --lib -> 249 passed, 0 failed, 3 ignored, exit 0 (90.60s). CPU-only regression run; the synthetic compare-bound scenario was not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A for CPU tests.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167240004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492#issuecomment-7167240004). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T15:41:48Z. --- Independent local validation for PR #2492 (Windows, Rust 1.100.0/MSVC, head 98017a5, no game data): `cargo test --locked -p victory-shader --lib` -> 249 passed, 0 failed, 3 ignored, exit 0 (90.60s). CPU-only regression run; the synthetic compare-bound scenario was not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A for CPU tests.
Marvisak commented 2026-11-25 16:09:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:00:30Z.


Automated triage for the maintainers.

This makes three analyses refuse a VALU copy or add that carries output or input modifiers: Halves::joined in io.rs (a v_mov_b32 of a barycentric, where abs/neg/clamp/omod were not checked at all) and the v_mov_b32 / v_add_nc_u32 walks in resource.rs (clamp and omod not checked). The result is only more conservative: a modified copy is no longer taken for the plain value, and a clamped add, which saturates according to the public RDNA2 ISA, is no longer split into base plus offset. This matches the checks range.rs op_hi already makes. I checked the hand-encoded VOP3 words in the new tests (opcode, clamp bit, abs/neg/omod fields). CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167510000 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492#issuecomment-7167510000). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T16:00:30Z. --- <!-- victory-triage v1 head=98017a5eb0078c9d77975bd6aaf68aff400d8129 verdict=merge-candidate at=2026-11-25T16:00:22Z --> Automated triage for the maintainers. This makes three analyses refuse a VALU copy or add that carries output or input modifiers: `Halves::joined` in `io.rs` (a `v_mov_b32` of a barycentric, where abs/neg/clamp/omod were not checked at all) and the `v_mov_b32` / `v_add_nc_u32` walks in `resource.rs` (clamp and omod not checked). The result is only more conservative: a modified copy is no longer taken for the plain value, and a clamped add, which saturates according to the public RDNA2 ISA, is no longer split into base plus offset. This matches the checks `range.rs` `op_hi` already makes. I checked the hand-encoded VOP3 words in the new tests (opcode, clamp bit, abs/neg/omod fields). CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 01:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:52:43Z.


Code review and RTX 5090 + WARP + DXIL verification at head 98017a5eb007 merged cleanly onto main (63bcca43c6a0):

  • Code review:
    • Checking abs == 0 && neg == 0 && !clamp && omod == 0 (plus dpp/sdwa where applicable) in io.rs:583-590 (Halves::joined), resource.rs:742-747 (Tracer::vadd), resource.rs:770-775 (Tracer::vorigin), and resource.rs:1559-1564 (Tracer::vstep) closes the modifier-blind address/barycentric tracking cases cleanly. (Also verified clean merge with #2923.)
    • Non-blocking follow-up note: Tracer::carried (resource.rs:999-1017) matches Fields::Valu(f) on "v_add_co_ci_u32" without checking !f.clamp && f.omod == 0 && f.abs == 0 && f.neg == 0 && f.sdwa.is_none() && f.dpp.is_none() (per gfx10/fields.rs:589,671, VOP3B v_add_co_ci_u32 supports clamp/omod, and VOP2 supports sdwa/dpp). Worth tightening either here or in a follow-up.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo test -p xtask --locked: 6/6; cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default + --features diagnostics): 0 warnings
    • io::tests: 5/5; resource::tests: 36/36 (including both new modifier tests)
    • emit::tests (17/17) and emit::semantics_tests (34/34, 1 ignored): passed on both RTX 5090 and WARP.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179204400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492#issuecomment-7179204400). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:52:43Z. --- Code review and RTX 5090 + WARP + DXIL verification at head `98017a5eb007` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review**: - Checking `abs == 0 && neg == 0 && !clamp && omod == 0` (plus `dpp`/`sdwa` where applicable) in `io.rs:583-590` (`Halves::joined`), `resource.rs:742-747` (`Tracer::vadd`), `resource.rs:770-775` (`Tracer::vorigin`), and `resource.rs:1559-1564` (`Tracer::vstep`) closes the modifier-blind address/barycentric tracking cases cleanly. (Also verified clean merge with `#2923`.) - Non-blocking follow-up note: `Tracer::carried` (`resource.rs:999-1017`) matches `Fields::Valu(f)` on `"v_add_co_ci_u32"` without checking `!f.clamp && f.omod == 0 && f.abs == 0 && f.neg == 0 && f.sdwa.is_none() && f.dpp.is_none()` (per `gfx10/fields.rs:589,671`, VOP3B `v_add_co_ci_u32` supports `clamp`/`omod`, and VOP2 supports `sdwa`/`dpp`). Worth tightening either here or in a follow-up. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo test -p xtask --locked`: 6/6; `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default + `--features diagnostics`): 0 warnings - `io::tests`: 5/5; `resource::tests`: 36/36 (including both new modifier tests) - `emit::tests` (17/17) and `emit::semantics_tests` (34/34, 1 ignored): passed on both RTX 5090 and WARP. LGTM.
fuzeofficlal commented 2026-11-26 14:01:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:54:57Z.

Review: APPROVED


The new clamp and omod guards cleanly keep saturating adds and modified moves out of the plain-copy (io.rs:581-595, resource.rs:748-761, 1486-1500) and plain-add (resource.rs:714-735) paths without rejecting valid integer instructions, and the added tests cover them well.

Two pre-existing modifier gaps worth noting for follow-up (not blocking this PR):

  • Tracer::carried() (resource.rs:969-979): matches v_add_co_ci_u32 without rejecting sdwa, dpp, clamp, abs, neg, or omod, even though SDWA/DPP/clamped forms can change the high dword while still referencing the root descriptor's high word in src[..2].
  • FP16 interpolation (io.rs:387-401, 515-535): accepts modified v_interp_p1ll_f16 (e.g., an intermediate P1 clamp or input abs/neg), which lowering drops when fusing P1 and P2 and applying only P2's output modifiers.

Local verification on commit 98017a5eb007 (and cleanly merged onto origin/main tree 15c737a3, emit/lower.rs unchanged at 520,563 B): cargo run --locked -p xtask -- policy (182 files ok), cargo clippy -p victory-shader --all-targets (default and --all-features), io::tests (5 passed), resource::tests (34 passed on PR head, 36 merged), emit::lower::tests (21 passed on PR head, 33 merged), and emit::waterfall_tests (5 passed) on both RTX 5090 and VICTORY_WARP=1 all pass. Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6075325153 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2492#pullrequestreview-6075325153). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:54:57Z. **Review:** APPROVED --- The new `clamp` and `omod` guards cleanly keep saturating adds and modified moves out of the plain-copy (`io.rs:581-595`, `resource.rs:748-761, 1486-1500`) and plain-add (`resource.rs:714-735`) paths without rejecting valid integer instructions, and the added tests cover them well. Two pre-existing modifier gaps worth noting for follow-up (not blocking this PR): - **`Tracer::carried()` (`resource.rs:969-979`):** matches `v_add_co_ci_u32` without rejecting `sdwa`, `dpp`, `clamp`, `abs`, `neg`, or `omod`, even though SDWA/DPP/clamped forms can change the high dword while still referencing the root descriptor's high word in `src[..2]`. - **FP16 interpolation (`io.rs:387-401, 515-535`):** accepts modified `v_interp_p1ll_f16` (e.g., an intermediate P1 `clamp` or input `abs`/`neg`), which lowering drops when fusing P1 and P2 and applying only P2's output modifiers. Local verification on commit `98017a5eb007` (and cleanly merged onto `origin/main` tree `15c737a3`, `emit/lower.rs` unchanged at `520,563 B`): `cargo run --locked -p xtask -- policy` (182 files ok), `cargo clippy -p victory-shader --all-targets` (`default` and `--all-features`), `io::tests` (5 passed), `resource::tests` (34 passed on PR head, 36 merged), `emit::lower::tests` (21 passed on PR head, 33 merged), and `emit::waterfall_tests` (5 passed) on both RTX 5090 and `VICTORY_WARP=1` all pass. Approving.
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/2492:upstream-pr/2492'
git switch 'upstream-pr/2492'

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