Skip to content

Shaders: fix 16-bit VALU SDWA placement/sext and inline float constants - #112

Open
hamdog0203 wants to merge 1 commit into
Zettrox:mainfrom
hamdog0203:fix/valu16-sdwa-inline-const
Open

hamdog0203 wants to merge 1 commit into
Zettrox:mainfrom
hamdog0203:fix/valu16-sdwa-inline-const

Conversation

@hamdog0203

Copy link
Copy Markdown

Summary

Fixes three 16-bit VALU lowering bugs in crates/victory-shader/src/emit/lower.rs, adapted from Marvisak/VIctory#1285 (including the follow-up guard for reserved dst_unused=3 with dst_sel:DWORD):

  1. SDWA destination placement, UNUSED_SEXT, and reserved dst_unused=3 (write_half): Previously rejected byte dst_sel (0..=3) and ignored dst_unused = UNUSED_SEXT (1) for word targets, while allowing reserved dst_unused = 3 on dst_sel:DWORD. write_half now delegates dst_sel 0..=5 with dst_unused 0..=2 to place_bits, zero-extends the low 16 bits for dst_sel:DWORD (6) with dst_unused 0..=2, and rejects reserved dst_unused = 3.
  2. SDWA source byte selection and sext (half_src / half_int_src): Previously rejected byte src_sel (0..=3) and ignored SDWA sext on 16-bit operations. half_src_typed now handles src_sel 0..=5 via select_bits, applying sext for 16-bit integer sources (half_int_src).
  3. Inline float constants on 16-bit integer operations (half_int_src): On GFX10, 16-bit integer VALU and compare instructions (v_cvt_f16_u16/v_cvt_f16_i16, 16-bit integer VALU ops, and 16-bit integer compare) read inline float constants as raw f32 bit patterns rather than f16 values. Splitting half_int_src (operand) from half_src (f16_operand) preserves f16 inline constants for f16 ops while giving 16-bit integer ops their f32 bits.

Negative Control (unpatched main 90b529f)

Verified in a separate detached worktree on 90b529f with only the new tests applied:

  • sdwa_16bit_dst_word0_sext_and_byte_placement: failed on RTX 4060 (hardware: add_sext returned 0x0000_BC00 instead of 0xFFFF_BC00).
  • sdwa_16bit_src_byte_select_and_sext: failed lowering (Unsupported { offset: 36, what: "a byte select on a 16-bit operation" }).
  • int16_inline_float_constants_use_f32_bits: failed on RTX 4060 (hardware: v_add_nc_u16(248, 0) returned 0x3118 instead of 0xF983).

Verification (at d316e3d)

Environment: Windows 11 x64 (26200.9974), NVIDIA GeForce RTX 4060 (8 GB, Wave32, driver 621.35), Microsoft WARP, Windows SDK dxil.dll (10.0.26100.0), rustc 1.98.1.

  • cargo test --locked -p victory-shader --lib -- sdwa_16bit_dst_word0_sext_and_byte_placement sdwa_16bit_src_byte_select_and_sext int16_inline_float_constants_use_f32_bits --nocapture: 3 passed, 0 failed (validated via dxil.dll and executed on both RTX 4060 and WARP with no skips).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings).
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings).
  • cargo test --workspace --locked: all crates passed with 0 failures (victory 1, victory_core 11, victory_formats 24 / 4 ignored, victory_game 2, victory_gpu 110 / 1 ignored, victory_hle 95 + no_dll_planting 1, victory_loader 24 + load_probe 2 + title_dlls 1, victory_pe 7, victory_pipeline 4, victory_shader 213 / 2 ignored, xtask 4 including repository_passes_policy).
  • .githooks/pre-commit: passed (asset policy: 2 files ok).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant