Shaders: d16 format loads saturate 32-bit integer channels #1925

Open
upipibi wants to merge 1 commit from upstream-pr/1927 into main
upipibi commented 2026-11-25 01:06:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T01:06:12Z.


tbuffer_load_format_d16_* / buffer_load_format_d16_* of a 32-bit integer channel kept its low 16 bits. RDNA2 saturates it instead: UINT to 0xFFFF, SINT to -32768..32767. So 70000 in a 32_UINT buffer loaded as 0x1170 here, and as 0xFFFF on the console's GPU.

Sources for the rule: measured on gfx1031 for buffer format loads (xcl-dev/xcl#1488, item XCL-BT-020) and on gfx1036 for D16 image reads (boykopovar/AnyPS5#22750).

What is in it

  • emit/lower.rs, d16_channels: UINT channels go through min(x, 0xFFFF) and SINT ones through a clamp to -32768..32767 before the 16-bit mask. 8- and 16-bit integer formats never leave that range, so they're unchanged. Float formats are unchanged too: the legacy f32→f16 conversion already rounds toward zero, which matches RDNA2.
  • emit/valu_tests.rs: tbuffer_d16_loads_saturate_32_bit_integers covers 32_UINT and 32_SINT, past both ends and in range. It compares only the low half, so it doesn't depend on what an odd last channel leaves in the high half (#1441 changes that part, and the two merge cleanly).

Tested on Windows 11, RTX 3070 (Ampere, driver 616.56), and WARP, debug, on main 42363ab:

  • cargo test -p victory-shader --locked -- tbuffer_d16: 2 passed. Without the lower.rs change, the new test fails: d16_x format 20 of 0x11170 = 0x00001170, want low half 0xffff.
  • cargo test -p victory-shader --locked: 244 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on main.
  • cargo xtask policy and cargo clippy -p victory-shader --all-targets --locked -- -D warnings: pass.

Not tested: a title.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5483115838 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T01:06:12Z. --- `tbuffer_load_format_d16_*` / `buffer_load_format_d16_*` of a 32-bit integer channel kept its low 16 bits. RDNA2 saturates it instead: UINT to `0xFFFF`, SINT to `-32768..32767`. So 70000 in a `32_UINT` buffer loaded as `0x1170` here, and as `0xFFFF` on the console's GPU. Sources for the rule: measured on gfx1031 for buffer format loads (xcl-dev/xcl#1488, item XCL-BT-020) and on gfx1036 for D16 image reads (boykopovar/AnyPS5#22750). **What is in it** - `emit/lower.rs`, `d16_channels`: UINT channels go through `min(x, 0xFFFF)` and SINT ones through a clamp to `-32768..32767` before the 16-bit mask. 8- and 16-bit integer formats never leave that range, so they're unchanged. Float formats are unchanged too: the legacy f32→f16 conversion already rounds toward zero, which matches RDNA2. - `emit/valu_tests.rs`: `tbuffer_d16_loads_saturate_32_bit_integers` covers `32_UINT` and `32_SINT`, past both ends and in range. It compares only the low half, so it doesn't depend on what an odd last channel leaves in the high half (#1441 changes that part, and the two merge cleanly). **Tested** on Windows 11, RTX 3070 (Ampere, driver 616.56), and WARP, debug, on `main` `42363ab`: - `cargo test -p victory-shader --locked -- tbuffer_d16`: 2 passed. Without the `lower.rs` change, the new test fails: `d16_x format 20 of 0x11170 = 0x00001170, want low half 0xffff`. - `cargo test -p victory-shader --locked`: 244 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on `main`. - `cargo xtask policy` and `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: pass. **Not tested:** a title. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Headache3318 commented 2026-11-25 02:06:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T02:05:20Z.


Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 53affcc applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The new tbuffer_d16_loads_saturate_32_bit_integers test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on main ccfb029). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150302958 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7150302958). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T02:05:20Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `53affcc` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 144 passed, 0 failed, 2 ignored. All tests pass. The new `tbuffer_d16_loads_saturate_32_bit_integers` test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 4 pre-existing errors in test code (fail identically on main `ccfb029`). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
catminou4 commented 2026-11-25 03:05:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:05:20Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. d16 format loads saturate 32-bit integer channels — pairs with #1940 (same d16 load path, UNORM/SNORM rounding); both pass independently, maintainer should check they compose.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051251309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#pullrequestreview-6051251309). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:05:20Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. d16 format loads saturate 32-bit integer channels — **pairs with #1940** (same d16 load path, UNORM/SNORM rounding); both pass independently, maintainer should check they compose.
Marvisak commented 2026-11-25 09:06:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T08:16:15Z.


Automated triage for the maintainers.

Merge candidate.

emit/lower.rs, d16_channels: d16 format loads of 32-bit integer channels now saturate (UINT via unsigned min(x, 0xFFFF), SINT via a clamp to -32768..32767 before the 16-bit mask) instead of keeping the low 16 bits. 8/16-bit integer formats can't go past those bounds, so they behave as before, and float formats are untouched. The cited measurements exist: xcl-dev/xcl#1488 (XCL-BT-020, gfx1031, with a gfx1036 confirmation in a comment) and boykopovar/AnyPS5#22750 (gfx1036 image d16). These are third-party hardware results, not official documentation. The new test tbuffer_d16_loads_saturate_32_bit_integers covers both ends and the in-range cases, and its expected values match the stated rule.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7156819562 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7156819562). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T08:16:15Z. --- <!-- victory-triage v1 head=53affcc9f14227274f6daac6302c8c9aea155ada verdict=merge-candidate at=2026-11-25T08:16:06Z --> Automated triage for the maintainers. **Merge candidate.** `emit/lower.rs`, `d16_channels`: d16 format loads of 32-bit integer channels now saturate (UINT via unsigned `min(x, 0xFFFF)`, SINT via a clamp to -32768..32767 before the 16-bit mask) instead of keeping the low 16 bits. 8/16-bit integer formats can't go past those bounds, so they behave as before, and float formats are untouched. The cited measurements exist: xcl-dev/xcl#1488 (XCL-BT-020, gfx1031, with a gfx1036 confirmation in a comment) and boykopovar/AnyPS5#22750 (gfx1036 image d16). These are third-party hardware results, not official documentation. The new test `tbuffer_d16_loads_saturate_32_bit_integers` covers both ends and the in-range cases, and its expected values match the stated rule. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 12:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T11:28:45Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head 53affcc9 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161100015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7161100015). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T11:28:45Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 53affcc9 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
fuzeofficlal commented 2026-11-26 18:53:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:53:27Z.

Review: APPROVED


Verified 53affcc9f14227274f6daac6302c8c9aea155ada cleanly merged onto main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK dxil.dll):

  • d16_channels (crates/victory-shader/src/emit/lower.rs:5205-5222) cleanly saturates Numeric::Uint via unsigned IULT to 0xFFFF and Numeric::Sint via signed SLT/SGT to -32768..=32767 before masking to 16 bits, while leaving non-integer formats untouched.
  • emit/lower.rs size: 521,145 B (under 524,288 B); cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • tbuffer_d16_loads (2 passed, including tbuffer_d16_loads_saturate_32_bit_integers), d16_ (5 passed), emit::tests::constant_color_validates, and emit::lower::tests:: (33 passed, 0 failed) all pass on both RTX 5090 and WARP.

Minor non-blocking test note: adding UINT_MAX (0xFFFF_FFFF -> 0xFFFF), INT_MIN, and INT_MAX to tbuffer_d16_loads_saturate_32_bit_integers would also pin sign-bit behavior (IULT vs SLT). Ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079202523 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#pullrequestreview-6079202523). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:53:27Z. **Review:** APPROVED --- Verified `53affcc9f14227274f6daac6302c8c9aea155ada` cleanly merged onto `main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK `dxil.dll`): - `d16_channels` (`crates/victory-shader/src/emit/lower.rs:5205-5222`) cleanly saturates `Numeric::Uint` via unsigned `IULT` to `0xFFFF` and `Numeric::Sint` via signed `SLT`/`SGT` to `-32768..=32767` before masking to 16 bits, while leaving non-integer formats untouched. - `emit/lower.rs` size: **521,145 B** (under 524,288 B); `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `tbuffer_d16_loads` (`2 passed`, including `tbuffer_d16_loads_saturate_32_bit_integers`), `d16_` (`5 passed`), `emit::tests::constant_color_validates`, and `emit::lower::tests::` (`33 passed, 0 failed`) all pass on both RTX 5090 and WARP. Minor non-blocking test note: adding `UINT_MAX` (`0xFFFF_FFFF` -> `0xFFFF`), `INT_MIN`, and `INT_MAX` to `tbuffer_d16_loads_saturate_32_bit_integers` would also pin sign-bit behavior (`IULT` vs `SLT`). Ready to merge.
Dukestar69 commented 2026-11-26 23:30:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:30:01Z.

Review: APPROVED


LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

  • Saturating 32-bit integer channels to 16-bit bounds on d16 format loads matches RDNA2 hardware behavior cleanly on both RTX 5090 and WARP.
  • cargo test -p victory-shader --lib emit::valu_tests::d16 -- --test-threads=1: passed on RTX 5090 and VICTORY_WARP=1.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6081469494 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1927#pullrequestreview-6081469494). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T23:30:01Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 and `VICTORY_WARP=1` (Windows / D3D12) against `origin/main` (`63bcca4`). - Saturating 32-bit integer channels to 16-bit bounds on `d16` format loads matches RDNA2 hardware behavior cleanly on both RTX 5090 and WARP. - `cargo test -p victory-shader --lib emit::valu_tests::d16 -- --test-threads=1`: passed on RTX 5090 and `VICTORY_WARP=1`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/1927:upstream-pr/1927'
git switch 'upstream-pr/1927'

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