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

Open
hamdog0203 wants to merge 1 commit from upstream-pr/112 into main
hamdog0203 commented 2026-11-25 13:06:09 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by hamdog0203 on 2026-11-25T12:15:25Z.


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).
<!-- greyfinch-sync:Zettrox/ztrx:issue:6604250086 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/112). Originally posted by [hamdog0203](https://github.com/hamdog0203) on 2026-11-25T12:15:25Z. --- ## 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`).
Aniseto commented 2026-11-25 15:08:47 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Aniseto on 2026-11-25T15:03:41Z.


Ran the new 16-bit VALU tests at d316e3d (clean PR head on main 90b529f):

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (VICTORY_DXIL), debug build

Results

  • cargo test --locked -p victory-shader --lib sdwa_16bit -- --nocapture: 2 passed, 0 failed, 0 ignored, 213 filtered out (exit 0)
  • cargo test --locked -p victory-shader --lib int16_inline_float_constants_use_f32_bits -- --nocapture: 1 passed, 0 failed, 0 ignored, 214 filtered out (exit 0)
  • cargo test --locked -p victory-shader --lib -- --test-threads=1: 213 passed, 0 failed, 2 ignored (exit 0)

What this adds
No test report exists yet in this thread, so this is the first hardware datapoint. All three new tests pass on this Blackwell wave32 part with DXIL validator 1.9.2609.5. The SDWA placement/sext and inline-constant cases are lowering tests; they do not by themselves prove a shader using them was created as a pipeline on the GPU.

Not tested
The title's shader pack, live pipeline creation, retail runs, a WARP control lane, the console compiler's DXC, release profile, AMD and Intel GPUs.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166240902 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/112#issuecomment-7166240902). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-25T15:03:41Z. --- Ran the new 16-bit VALU tests at `d316e3d` (clean PR head on `main` `90b529f`): **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124 - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (`VICTORY_DXIL`), debug build **Results** - `cargo test --locked -p victory-shader --lib sdwa_16bit -- --nocapture`: 2 passed, 0 failed, 0 ignored, 213 filtered out (exit 0) - `cargo test --locked -p victory-shader --lib int16_inline_float_constants_use_f32_bits -- --nocapture`: 1 passed, 0 failed, 0 ignored, 214 filtered out (exit 0) - `cargo test --locked -p victory-shader --lib -- --test-threads=1`: 213 passed, 0 failed, 2 ignored (exit 0) **What this adds** No test report exists yet in this thread, so this is the first hardware datapoint. All three new tests pass on this Blackwell wave32 part with DXIL validator 1.9.2609.5. The SDWA placement/sext and inline-constant cases are lowering tests; they do not by themselves prove a shader using them was created as a pipeline on the GPU. **Not tested** The title's shader pack, live pipeline creation, retail runs, a WARP control lane, the console compiler's DXC, release profile, AMD and Intel GPUs. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was 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/112:upstream-pr/112'
git switch 'upstream-pr/112'

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