Skip to content

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

Open
9hvn9yt2vk-netizen wants to merge 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:valu-packing-dot-ldexp
Open

9hvn9yt2vk-netizen wants to merge 1 commit into
Marvisak:mainfrom
9hvn9yt2vk-netizen:valu-packing-dot-ldexp

Conversation

@9hvn9yt2vk-netizen

Copy link
Copy Markdown
Contributor

…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).

…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 9hvn9yt2vk-netizen left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey
fast

@DaviTostes

Copy link
Copy Markdown

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

No game data used.

@Sunkiller-qc

Copy link
Copy Markdown

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.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…t packs, integer dot products and v_ldexp_f32) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
Baconzido added a commit to Baconzido/VIctory that referenced this pull request Nov 24, 2026
Marvisak#157 adds a vop3p helper without modifiers to the same file; a distinct name and a place before the file's last test let the two changes merge.
@Baconzido

Copy link
Copy Markdown

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.

sahajiscoding added a commit to sahajiscoding/VIctory that referenced this pull request Nov 24, 2026
… & shader ops

- Prefer high-performance discrete GPU via IDXGIFactory6::EnumAdapterByGpuPreference
  and VICTORY_ADAPTER (index or name substring) in victory-gpu and victory-shader (Marvisak#208/Marvisak#1132)
- Cap shader-visible sampler heaps at D3D12's 2,048 architectural limit instead of
  failing heap creation (Marvisak#100/Marvisak#86)
- Fall back to the in-memory translated shader if shader-cache disk write fails (Marvisak#358)
- Add F11 / Alt+Enter borderless fullscreen toggle and clean WM_CLOSE handling to
  both title windows (lifecycle.rs) and VIctory's fallback window (host.rs); clamp
  fit_into() dimensions to >= 1 (Marvisak#451)
- Enhance PC keyboard+mouse fallback gamepad with Space/LShift/R/LCtrl aliases,
  LMB/RMB/MMB triggers, and RMB/F9 mouse camera look; support null-device
  cross-device previous/next reading walk (Marvisak#361)
- Fall back to a no-op display deferral when PowerSetRequest returns ERROR_NOT_SUPPORTED
- Clamp short virtual-drive '..' paths at the virtual drive root (Marvisak#182)
- Wake and cancel sleeping delayed callbacks immediately on XTaskQueueTerminate (Marvisak#132)
- Cache XMA IMDCT rotation sin/cos tables across subframes (Marvisak#172)
- Lower additional RDNA2 VALU instructions (v_mul_hi_{u,i}32_{u,i}24, v_mad_{u,i}32_{u,i}16,
  v_lerp_u8, v_sad_u{8,16,32}, v_cvt_pk_{u,i}16_{u,i}32, v_dot{2,4}_{i,u}32_{i,u}{16,8})
  with DXIL validation and conditional INT64 feature flagging (Marvisak#157)
- Add portable victory.toml lookup next to victory.exe, interactive [S] Setup wizard
  and [K] Controls guide in victory.exe, and scripts/build-windows.ps1 release packager

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants