Shaders: lower 24-bit mul_hi, saturating 16-bit packs, integer dot pr… #157

Open
9hvn9yt2vk-netizen wants to merge 1 commit from upstream-pr/157 into main
9hvn9yt2vk-netizen commented 2026-11-24 01:01:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-24T01:01:15Z.


…oducts and v_ldexp_f32

Ten VALU instructions the translator refused, so any shader using one dropped its draws or dispatches:

  • v_mul_hi_u32_u24 / v_mul_hi_i32_i24: the high 32 bits of the 48-bit product, with the operands taken as v_mul_u32_u24 takes them;
  • v_cvt_pk_u16_u32 / v_cvt_pk_i16_i32: both sources saturated to 16 bits and packed (src0 low);
  • v_dot2_i32_i16, v_dot2_u32_u16, v_dot4_i32_i8, v_dot4_u32_u8, v_dot8_u32_u4: products of the packed fields summed into src2, wrapping; clamp and operand selects are refused;
  • v_ldexp_f32: src0 * 2^src1 as three exact power-of-two factors whose exponents stay in the normal range (src1 clamped to +-375, past which every finite nonzero src0 has over- or underflowed).

Found by lowering every GFX10 ALU opcode alone in a pixel shader whose export depends on it. The formulas were checked against the ISA definitions on random inputs (0 differences; ldexp differs only where a result turns denormal before the last factor, noted as a shortcut).

Tests: packing_dot_and_ldexp_instructions_translate (each one goes through the whole translation; fails without this change), and GPU tests in valu_tests comparing every instruction with its definition on edge values. The GPU tests were type-checked and clippy-clean for x86_64-pc-windows-msvc but not run (no Windows machine here).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572181629 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157). Originally posted by [9hvn9yt2vk-netizen](https://github.com/9hvn9yt2vk-netizen) on 2026-11-24T01:01:15Z. --- …oducts and v_ldexp_f32 Ten VALU instructions the translator refused, so any shader using one dropped its draws or dispatches: - v_mul_hi_u32_u24 / v_mul_hi_i32_i24: the high 32 bits of the 48-bit product, with the operands taken as v_mul_u32_u24 takes them; - v_cvt_pk_u16_u32 / v_cvt_pk_i16_i32: both sources saturated to 16 bits and packed (src0 low); - v_dot2_i32_i16, v_dot2_u32_u16, v_dot4_i32_i8, v_dot4_u32_u8, v_dot8_u32_u4: products of the packed fields summed into src2, wrapping; clamp and operand selects are refused; - v_ldexp_f32: src0 * 2^src1 as three exact power-of-two factors whose exponents stay in the normal range (src1 clamped to +-375, past which every finite nonzero src0 has over- or underflowed). Found by lowering every GFX10 ALU opcode alone in a pixel shader whose export depends on it. The formulas were checked against the ISA definitions on random inputs (0 differences; ldexp differs only where a result turns denormal before the last factor, noted as a shortcut). Tests: packing_dot_and_ldexp_instructions_translate (each one goes through the whole translation; fails without this change), and GPU tests in valu_tests comparing every instruction with its definition on edge values. The GPU tests were type-checked and clippy-clean for x86_64-pc-windows-msvc but not run (no Windows machine here).
9hvn9yt2vk-netizen commented 2026-11-24 01:02:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 9hvn9yt2vk-netizen on 2026-11-24T01:02:10Z.

Review: COMMENTED


hey
fast

<!-- greyfinch-sync:Marvisak/VIctory:review:6032026623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157#pullrequestreview-6032026623). Originally posted by [9hvn9yt2vk-netizen](https://github.com/9hvn9yt2vk-netizen) on 2026-11-24T01:02:10Z. **Review:** COMMENTED --- hey fast
DaviTostes commented 2026-11-24 06:54:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:18:43Z.


Tested 13d984a on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the 5 tests this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118974699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7118974699). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:18:43Z. --- Tested `13d984a` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the 5 tests this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Sunkiller-qc commented 2026-11-24 06:54:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:29:40Z.


Overlap note: v_mul_hi_u32_u24/v_mul_hi_i32_i24 are also in #156 (and #162 is stacked on #156), and #163 lowers all ten of these. The rest of this PR (cvt_pk, dot*, ldexp) isn't in #156, so dropping the two mul_hi arms here, or there, would avoid the duplicate match arms.

Static review, not built or run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119153770 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7119153770). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:29:40Z. --- Overlap note: `v_mul_hi_u32_u24`/`v_mul_hi_i32_i24` are also in #156 (and #162 is stacked on #156), and #163 lowers all ten of these. The rest of this PR (`cvt_pk`, `dot*`, `ldexp`) isn't in #156, so dropping the two `mul_hi` arms here, or there, would avoid the duplicate match arms. Static review, not built or run.
Baconzido commented 2026-11-24 06:55:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Baconzido on 2026-11-24T03:51:07Z.


Ran this PR's tests on Windows, since the description says the GPU tests have not run yet.

Windows 11 (26300), AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP, dxil.dll from SDK 10.0.26100, at this PR's head 13d984a:

Test Result
packing_dot_and_ldexp_instructions_translate pass
v_mul_hi_24_bit_products pass (hardware and WARP)
v_cvt_pk_16_saturates_each_half pass (hardware and WARP)
v_dot_products_of_packed_fields pass (hardware and WARP)
v_ldexp_f32_scales_by_powers_of_two pass (hardware and WARP)

cargo test -p victory-shader: 74 passed, 0 failed. cargo clippy -p victory-shader --all-targets and cargo fmt -p victory-shader -- --check are clean.

Merged together with #465 (the f16 dot products) on main d2a4bae: no conflict, 78 passed, clippy clean. Both PRs had added a vop3p test helper to valu_tests.rs; #465 now names its own vop3p_mods, so the two compose in either order.

AI-assisted (Claude Code ran the builds over SSH and read the logs); every run is on my machine. No game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121481257 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7121481257). Originally posted by [Baconzido](https://github.com/Baconzido) on 2026-11-24T03:51:07Z. --- Ran this PR's tests on Windows, since the description says the GPU tests have not run yet. Windows 11 (26300), AMD Radeon RX 5700 (RDNA1, driver 26.11.2) and WARP, `dxil.dll` from SDK 10.0.26100, at this PR's head `13d984a`: | Test | Result | |---|---| | `packing_dot_and_ldexp_instructions_translate` | pass | | `v_mul_hi_24_bit_products` | pass (hardware and WARP) | | `v_cvt_pk_16_saturates_each_half` | pass (hardware and WARP) | | `v_dot_products_of_packed_fields` | pass (hardware and WARP) | | `v_ldexp_f32_scales_by_powers_of_two` | pass (hardware and WARP) | `cargo test -p victory-shader`: 74 passed, 0 failed. `cargo clippy -p victory-shader --all-targets` and `cargo fmt -p victory-shader -- --check` are clean. Merged together with #465 (the f16 dot products) on `main` `d2a4bae`: no conflict, 78 passed, clippy clean. Both PRs had added a `vop3p` test helper to `valu_tests.rs`; #465 now names its own `vop3p_mods`, so the two compose in either order. AI-assisted (Claude Code ran the builds over SSH and read the logs); every run is on my machine. No game files.
Marvisak commented 2026-11-25 01:07:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:18:15Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148368113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7148368113). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:18:15Z. --- <!-- victory-triage v1 head=13d984adfd77f09b884af6a508802fbf0c9720ef verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/valu_tests.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/157:upstream-pr/157'
git switch 'upstream-pr/157'

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