Shaders: fold literals in packed f16 conversion toward zero #3773

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3773 into main
andrewpozdnakov7-jpg commented 2026-11-28 18:02:32 +00:00 (Migrated from github.com)

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


Fold direct, unmodified operands of v_cvt_pkrtz_f16_f32 when the literal is zero or has a finite normal half result. The fold preserves the sign of zero, truncates the significand and clamps finite overflow to the largest half of the same sign. The host conversion handles the other operands.

I compared 423 generated shaders on Windows WARP 1.0.22 with the DXIL validator. All 4,653 output words matched main. An independent rounding oracle checked 4,279 folded halves. The 34 control modules, including dynamic and modified operands, subnormal inputs, infinities and NaNs, stayed byte-identical.

Each of the 388 one-literal modules removes eight DXIL instructions and saves 56–64 bytes. The two-inline-operand module removes 16 instructions and saves 276 bytes. The new boundary regression, all 34 lowerer tests and 35 VALU tests, strict shader Clippy, and the asset policy passed.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5543098415 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3773). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T18:02:32Z. --- Fold direct, unmodified operands of v_cvt_pkrtz_f16_f32 when the literal is zero or has a finite normal half result. The fold preserves the sign of zero, truncates the significand and clamps finite overflow to the largest half of the same sign. The host conversion handles the other operands. I compared 423 generated shaders on Windows WARP 1.0.22 with the DXIL validator. All 4,653 output words matched main. An independent rounding oracle checked 4,279 folded halves. The 34 control modules, including dynamic and modified operands, subnormal inputs, infinities and NaNs, stayed byte-identical. Each of the 388 one-literal modules removes eight DXIL instructions and saves 56–64 bytes. The two-inline-operand module removes 16 instructions and saves 276 bytes. The new boundary regression, all 34 lowerer tests and 35 VALU tests, strict shader Clippy, and the asset policy passed. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 18:05:52 +00:00 (Migrated from github.com)

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


Windows CI passed on 0265559, including both Clippy configurations and the workspace tests. All 4,653 WARP output words matched. Each one-literal module removes eight DXIL instructions, the two-inline-operand module removes sixteen, and all 34 control modules remain byte-identical.

The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7243527133 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3773#issuecomment-7243527133). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T18:05:52Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46173680868/job/141067498880) passed on `0265559`, including both Clippy configurations and the workspace tests. All 4,653 WARP output words matched. Each one-literal module removes eight DXIL instructions, the two-inline-operand module removes sixteen, and all 34 control modules remain byte-identical. The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
ColorMeBoom commented 2026-11-28 23:37:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T23:37:58Z.


Full victory-shader --lib --features host on AMD hardware: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head 026555972 on 63bcca4: 303 passed; 0 failed; 3 ignored. That suite includes the GPU semantics tests, which run on the hardware adapter and WARP in turn. I didn't check which of them reach the changed code. The new packed_rtz_literals_keep_sign_and_truncate_toward_zero passes; it runs on the CPU.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247560288 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3773#issuecomment-7247560288). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T23:37:58Z. --- Full `victory-shader --lib --features host` on AMD hardware: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `026555972` on `63bcca4`: 303 passed; 0 failed; 3 ignored. That suite includes the GPU semantics tests, which run on the hardware adapter and WARP in turn. I didn't check which of them reach the changed code. The new `packed_rtz_literals_keep_sign_and_truncate_toward_zero` passes; it runs on the CPU. AI use: Claude Code (Claude Opus 5.5).
cloph-dsp commented 2026-11-30 11:23:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-30T11:23:00Z.


AI-assisted verification (Hy4 flash) — Windows, Rust 1.100.0/MSVC, cargo test --locked.

  • New synthetic test emit::lower::tests::packed_rtz_literals_keep_sign_and_truncate_toward_zero for the literal_f16_toward_zero folding.
  • Isolated worktree D:\Victory-Contrib\pr-3773-watch with dedicated CARGO_TARGET_DIR=D:\Victory-Contrib\target-3773.
  • git grep -F packed_rtz_literals_keep_sign_and_truncate_toward_zero 63bcca43c6a00a758510398fa43096ce7e4f7df0 -- crates/victory-shader/src/emit/lower.rs → exit 1 (test is new on the base).
  • git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0..HEAD → exit 0.
  • cargo test --locked -p victory-shader --lib -- emit::lower::tests::packed_rtz_literals_keep_sign_and_truncate_toward_zero --exact --test-threads=1 --quiet → 1 passed; 0 failed; 305 filtered out, exit 0.

GPU/driver: N/A — CPU-only synthetic test. No game data, assets, extracted shaders, DRM or decrypt were used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7276948172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3773#issuecomment-7276948172). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-30T11:23:00Z. --- AI-assisted verification (Hy4 flash) — Windows, Rust 1.100.0/MSVC, `cargo test --locked`. - New synthetic test `emit::lower::tests::packed_rtz_literals_keep_sign_and_truncate_toward_zero` for the `literal_f16_toward_zero` folding. - Isolated worktree `D:\Victory-Contrib\pr-3773-watch` with dedicated `CARGO_TARGET_DIR=D:\Victory-Contrib\target-3773`. - `git grep -F packed_rtz_literals_keep_sign_and_truncate_toward_zero 63bcca43c6a00a758510398fa43096ce7e4f7df0 -- crates/victory-shader/src/emit/lower.rs` → exit 1 (test is new on the base). - `git diff --check 63bcca43c6a00a758510398fa43096ce7e4f7df0..HEAD` → exit 0. - `cargo test --locked -p victory-shader --lib -- emit::lower::tests::packed_rtz_literals_keep_sign_and_truncate_toward_zero --exact --test-threads=1 --quiet` → `1 passed; 0 failed; 305 filtered out`, exit 0. GPU/driver: N/A — CPU-only synthetic test. No game data, assets, extracted shaders, DRM or decrypt were used.
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/3773:upstream-pr/3773'
git switch 'upstream-pr/3773'

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