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

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

@⁠9hvn9yt2vk-netizen on GitHub · 2026-11-24 01:01 UTC · original
9hvn9yt2vk-netizen:valu-packing-dot-ldexp → main · +336 −0 · 3 files · 1 commits · open

…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** on GitHub · 2026-11-24 01:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/157) `9hvn9yt2vk-netizen:valu-packing-dot-ldexp` → `main` · +336 −0 · 3 files · 1 commits · open …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).
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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:34 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:18 UTC · original

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.

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

@⁠Sunkiller-qc on GitHub · 2026-11-24 01:29 UTC · original

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.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7119153770) 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.
Author
Owner

@⁠Baconzido on GitHub · 2026-11-24 03:51 UTC · original

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.

**@⁠Baconzido** on GitHub · 2026-11-24 03:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7121481257) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:18 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/157#issuecomment-7148368113) <!-- 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.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/157/head:github-bot/gh-157'
git switch 'github-bot/gh-157'

Merge

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