Shaders: widen and pack 16-bit integer stage IO without f16 conversion #3805

Open
Vemast wants to merge 1 commit from upstream-pr/3805 into main
Vemast commented 2026-11-28 23:33:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Vemast on 2026-11-28T23:33:19Z.


Summary

  • Fixed Lower::export and Lower::interp in crates/victory-shader/src/emit/lower.rs so 16-bit integer stage attributes (uint16 / sint16) in VS/MS exports and PS flat inputs are widened/masked and packed directly as integers rather than passed through legacyF16ToF32 and narrow16, which corrupted integer bit patterns, NaN/infinity-range patterns, and negative signed values.
  • Preserved float-to-f16/f16-to-float conversion for floating-point stage attributes.
  • Added synthetic end-to-end test emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs covering both unsigned and signed 16-bit stage IO across vertex/pixel pipelines.

Verification

  • cargo test -p victory-shader --lib sixteen_bit_integer_stage_io_preserves_bits_and_signs (validated by dxil.dll, ran on hardware D3D12 + WARP)
  • cargo clippy -p victory-shader --all-targets
  • cargo run -p xtask -- policy
  • No game data used.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5545658866 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805). Originally posted by [Vemast](https://github.com/Vemast) on 2026-11-28T23:33:19Z. --- ### Summary - Fixed `Lower::export` and `Lower::interp` in `crates/victory-shader/src/emit/lower.rs` so 16-bit integer stage attributes (`uint16` / `sint16`) in VS/MS exports and PS flat inputs are widened/masked and packed directly as integers rather than passed through `legacyF16ToF32` and `narrow16`, which corrupted integer bit patterns, NaN/infinity-range patterns, and negative signed values. - Preserved float-to-f16/f16-to-float conversion for floating-point stage attributes. - Added synthetic end-to-end test `emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs` covering both unsigned and signed 16-bit stage IO across vertex/pixel pipelines. ### Verification - `cargo test -p victory-shader --lib sixteen_bit_integer_stage_io_preserves_bits_and_signs` (validated by `dxil.dll`, ran on hardware D3D12 + WARP) - `cargo clippy -p victory-shader --all-targets` - `cargo run -p xtask -- policy` - No game data used.
copilot-pull-request-reviewer[bot] commented 2026-11-28 23:33:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-28T23:33:30Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Marvisak/VIctory:review:6100555408 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#pullrequestreview-6100555408). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-28T23:33:30Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
andrewpozdnakov7-jpg commented 2026-11-28 23:55:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T23:55:32Z.


I ran the original sixteen_bit_integer_stage_io_preserves_bits_and_signs fixture from 1279ffa on both 63bcca4 and the PR head. It passed on both on app-local WARP.

The test-only follow-up a98a99c changes the upper packed unsigned value from 3 to 0x7c01 (31,745). That bit pattern is a signalling NaN when interpreted as an FP16 value. With the exact same fixture, main returns [65535, 32257, -16, -23] because the FP16 round trip quiets 0x7c01 to 0x7e01. The PR with the stronger fixture returns the expected [65535, 31745, -16, -23].

This used WARP 1.0.22, Agility 1.620.2 and the DXIL validator. Both strict shader Clippy configurations and the asset policy passed. The test-only commit is based directly on your PR head. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the regression into another commit. Test branch

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247753636 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#issuecomment-7247753636). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T23:55:32Z. --- I ran the original `sixteen_bit_integer_stage_io_preserves_bits_and_signs` fixture from `1279ffa` on both `63bcca4` and the PR head. It passed on both on app-local WARP. The test-only follow-up `a98a99c` changes the upper packed unsigned value from 3 to `0x7c01` (31,745). That bit pattern is a signalling NaN when interpreted as an FP16 value. With the exact same fixture, main returns `[65535, 32257, -16, -23]` because the FP16 round trip quiets `0x7c01` to `0x7e01`. The PR with the stronger fixture returns the expected `[65535, 31745, -16, -23]`. This used WARP 1.0.22, Agility 1.620.2 and the DXIL validator. Both strict shader Clippy configurations and the asset policy passed. The test-only commit is based directly on your PR head. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the regression into another commit. [Test branch](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/3805-stage-io-regression) AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-29 00:08:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-29T00:08:55Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3805 at head 1279ffa6680fa8d59d02b24674aa76e3a1eb12ff, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new); git diff --check HEAD^ HEAD clean (2 files, +273/-12; just over the usual size preference, but CPU-only).
  • The single review is a copilot-pull-request-reviewer COMMENTED note about insufficient quota, not an approval; zero APPROVED reviews, no cloph-dsp comment before posting.
  • Used a per-worktree CARGO_TARGET_DIR (target-3805-watch) with CARGO_BUILD_JOBS=2, never shared.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only shader IR test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247909027 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#issuecomment-7247909027). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-29T00:08:55Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3805 at head `1279ffa6680fa8d59d02b24674aa76e3a1eb12ff`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new); `git diff --check HEAD^ HEAD` clean (2 files, +273/-12; just over the usual size preference, but CPU-only). - The single review is a copilot-pull-request-reviewer COMMENTED note about insufficient quota, not an approval; zero APPROVED reviews, no cloph-dsp comment before posting. - Used a per-worktree `CARGO_TARGET_DIR` (`target-3805-watch`) with `CARGO_BUILD_JOBS=2`, never shared. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only shader IR test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
lmouz823-lang commented 2026-11-29 03:51:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lmouz823-lang on 2026-11-29T03:51:55Z.


@Vemast @andrewpozdnakov7-jpg, independent native Windows / RTX 4060 Laptop verification of the stronger stage-IO regression.

I compared main 63bcca43c6a00a758510398fa43096ce7e4f7df0 with this PR's 1279ffa6680fa8d59d02b24674aa76e3a1eb12ff, using the same fixture from Andrew's test-only a98a99cbd3b0b2f7036f3c8c71021e56a9fb5938. The production fix and test authors' commits were retained. Coordination claim.

Environment

Windows 11 build 26200, i9-14900HX, RTX 4060 Laptop 8 GB, NVIDIA 610.88, Rust 1.98.1 MSVC, release/locked, separate target directories. Microsoft SDK DXIL validator 1.8.2502.11. WARP identified as Microsoft Basic Render Driver. The installed system d3d10warp.dll file version is 10.0.26100.8521.

Identical-fixture results

The table uses 20 fresh processes with matching archived test EXEs. All four returned pixels agreed in each trial.

Source / input RTX 4060 WARP Pixel readback
Main, upper uint16 = 0x7c01 3/3 expected assertion failures 3/3 expected assertion failures [65535, 32257, -16, -23]
Full fix, same stronger input, rebuilt after controls 3/3 passed 3/3 passed [65535, 31745, -16, -23]
Main, original upper value 3 passed passed [65535, 3, -16, -23]
Full fix, original upper value 3 passed passed [65535, 3, -16, -23]
Revert only the interp method expected assertion failure expected assertion failure [0, 0, -1, 0]
Revert only the export method expected assertion failure expected assertion failure [57344, 8192, 0, 1]

On the RTX 4060 as well as WARP, main changes the integer pattern 0x7c01 (31745) into 0x7e01 (32257). The full fix preserves it. The original value 3 passes both versions, and the single-method controls separately exercise both production changes.

To establish actual execution, temporary probes in the identical fixture required successful validator loading and validation for both VS and PS, required the selected backend to run, and resolved the D3D12 device's LUID through DXGI. Hardware identified as NVIDIA GeForce RTX 4060 Laptop, vendor 0x10de, software=false. WARP identified as Microsoft Basic Render Driver, software=true. Device creation errors failed the probe. Successful trials asserted all four pixels. Failure trials stopped at the first pixel assertion, with all four readbacks retained in the log.

Final unchanged-source checks

After restoring the unchanged a98a99c source and rebuilding, the exact original stronger test passed three more times, each 1 passed, 0 failed, 0 ignored. The 33 lowerer tests also passed. Package all-target Clippy passed with -D warnings in default and all-features configurations, the asset policy passed, and git diff --check main HEAD passed.

cargo test --release --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --nocapture --test-threads=1

Coverage is the generated VS-to-PS, pack2=true path, including the signed-integer and float16 control channels. The full workspace suite, MS-output path, pack2=false path and gameplay performance remain unmeasured in this verification.

AI-assisted with OpenAI Codex. Raw logs, source/binary hashes and the primary 20-process matrix were independently cross-checked.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7250305800 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#issuecomment-7250305800). Originally posted by [lmouz823-lang](https://github.com/lmouz823-lang) on 2026-11-29T03:51:55Z. --- @Vemast @andrewpozdnakov7-jpg, independent native Windows / RTX 4060 Laptop verification of the stronger stage-IO regression. I compared main `63bcca43c6a00a758510398fa43096ce7e4f7df0` with this PR's `1279ffa6680fa8d59d02b24674aa76e3a1eb12ff`, using the same fixture from Andrew's test-only `a98a99cbd3b0b2f7036f3c8c71021e56a9fb5938`. The production fix and test authors' commits were retained. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7250107449). **Environment** Windows 11 build 26200, i9-14900HX, RTX 4060 Laptop 8 GB, NVIDIA 610.88, Rust 1.98.1 MSVC, release/locked, separate target directories. Microsoft SDK DXIL validator 1.8.2502.11. WARP identified as Microsoft Basic Render Driver. The installed system `d3d10warp.dll` file version is 10.0.26100.8521. **Identical-fixture results** The table uses 20 fresh processes with matching archived test EXEs. All four returned pixels agreed in each trial. | Source / input | RTX 4060 | WARP | Pixel readback | | --- | --- | --- | --- | | Main, upper uint16 = `0x7c01` | 3/3 expected assertion failures | 3/3 expected assertion failures | `[65535, 32257, -16, -23]` | | Full fix, same stronger input, rebuilt after controls | 3/3 passed | 3/3 passed | `[65535, 31745, -16, -23]` | | Main, original upper value 3 | passed | passed | `[65535, 3, -16, -23]` | | Full fix, original upper value 3 | passed | passed | `[65535, 3, -16, -23]` | | Revert only the `interp` method | expected assertion failure | expected assertion failure | `[0, 0, -1, 0]` | | Revert only the `export` method | expected assertion failure | expected assertion failure | `[57344, 8192, 0, 1]` | On the RTX 4060 as well as WARP, main changes the integer pattern `0x7c01` (31745) into `0x7e01` (32257). The full fix preserves it. The original value 3 passes both versions, and the single-method controls separately exercise both production changes. To establish actual execution, temporary probes in the identical fixture required successful validator loading and validation for both VS and PS, required the selected backend to run, and resolved the D3D12 device's LUID through DXGI. Hardware identified as NVIDIA GeForce RTX 4060 Laptop, vendor `0x10de`, software=false. WARP identified as Microsoft Basic Render Driver, software=true. Device creation errors failed the probe. Successful trials asserted all four pixels. Failure trials stopped at the first pixel assertion, with all four readbacks retained in the log. **Final unchanged-source checks** After restoring the unchanged `a98a99c` source and rebuilding, the exact original stronger test passed three more times, each **1 passed, 0 failed, 0 ignored**. The 33 lowerer tests also passed. Package all-target Clippy passed with `-D warnings` in default and all-features configurations, the asset policy passed, and `git diff --check main HEAD` passed. ```powershell cargo test --release --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --nocapture --test-threads=1 ``` Coverage is the generated VS-to-PS, `pack2=true` path, including the signed-integer and float16 control channels. The full workspace suite, MS-output path, `pack2=false` path and gameplay performance remain unmeasured in this verification. _AI-assisted with OpenAI Codex. Raw logs, source/binary hashes and the primary 20-process matrix were independently cross-checked._
cloph-dsp commented 2026-11-30 16:23:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-30T16:23:15Z.


Verified locally on Windows, Rust 1.100.0 (MSVC, Scoop rust-msvc), synthetic inputs only — no game data.

Base 63bcca43c6a00a758510398fa43096ce7e4f7df0, head 1279ffa6 (worktree pr-3805-watch, dedicated CARGO_TARGET_DIR=D:\Victory-Contrib\target-3805).

Negative control: git grep -F sixteen_bit_integer_stage_io_preserves_bits_and_signs 63bcca43 -- crates/victory-shader/src → no match, so the test is new on the base.

git diff --check 63bcca43..1279ffa6 → clean.

Command and result:

  • cargo test --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --test-threads=1 --quiet → 1 passed; 0 failed; 305 filtered out

GPU/driver: N/A (CPU-only codegen assertion, no device used).

AI-assisted: Hy4 flash. No game data, assets, extracted shaders or DRM used at any point.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7284582114 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#issuecomment-7284582114). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-30T16:23:15Z. --- Verified locally on Windows, Rust 1.100.0 (MSVC, Scoop rust-msvc), synthetic inputs only — no game data. Base `63bcca43c6a00a758510398fa43096ce7e4f7df0`, head `1279ffa6` (worktree `pr-3805-watch`, dedicated `CARGO_TARGET_DIR=D:\Victory-Contrib\target-3805`). Negative control: `git grep -F sixteen_bit_integer_stage_io_preserves_bits_and_signs 63bcca43 -- crates/victory-shader/src` → no match, so the test is new on the base. `git diff --check 63bcca43..1279ffa6` → clean. Command and result: - `cargo test --locked -p victory-shader --lib -- emit::synthetic_tests::sixteen_bit_integer_stage_io_preserves_bits_and_signs --exact --test-threads=1 --quiet` → 1 passed; 0 failed; 305 filtered out GPU/driver: N/A (CPU-only codegen assertion, no device used). AI-assisted: Hy4 flash. No game data, assets, extracted shaders or DRM used at any point.
passerbyyhx commented 2026-12-01 14:03:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-12-01T14:03:09Z.


I separated the two stage changes at 1279ffa6 by cross-linking VS and PS containers from the head and 63bcca43. On both the RTX 4090 Laptop and WARP, a packed fixture containing 0x7e01, 0x7c00, 0x8000 and 0x7fff gave the following four-component result at every pixel of a 2×2 draw. The final channel adds a float16 control of 1.

VS PS Readback
head head [32257, 31744, -32768, 32768]
parent parent [32257, 31744, -32768, 32768]
parent head [8192, 0, 0, -8191]
head parent [0, 0, -4, 1]

For these inputs the parent's two conversions cancel in the end-to-end draw. Holding one stage fixed exposes the representation difference at each side of the interface.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7313615663 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3805#issuecomment-7313615663). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-12-01T14:03:09Z. --- I separated the two stage changes at `1279ffa6` by cross-linking VS and PS containers from the head and `63bcca43`. On both the RTX 4090 Laptop and WARP, a packed fixture containing `0x7e01`, `0x7c00`, `0x8000` and `0x7fff` gave the following four-component result at every pixel of a 2×2 draw. The final channel adds a float16 control of 1. | VS | PS | Readback | |---|---|---| | head | head | `[32257, 31744, -32768, 32768]` | | parent | parent | `[32257, 31744, -32768, 32768]` | | parent | head | `[8192, 0, 0, -8191]` | | head | parent | `[0, 0, -4, 1]` | For these inputs the parent's two conversions cancel in the end-to-end draw. Holding one stage fixed exposes the representation difference at each side of the interface.
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/3805:upstream-pr/3805'
git switch 'upstream-pr/3805'

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