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

Open
github-bot wants to merge 1 commit from github-bot/gh-1927 into main AGit
Owner

@⁠upipibi on GitHub · 2026-11-25 01:06 UTC · original
upipibi:fix/d16-int-saturate → main · +36 −3 · 2 files · 1 commits · open

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

**@⁠upipibi** on GitHub · 2026-11-25 01:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927) `upipibi:fix/d16-int-saturate` → `main` · +36 −3 · 2 files · 1 commits · open `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)
RDNA2 saturates a 32-bit UINT channel of a d16 format load to 0xFFFF and
a SINT one to -32768..32767; d16_channels kept the low 16 bits (70000
loaded as 0x1170). Measured on gfx1031 (xcl-dev/xcl#1488, XCL-BT-020) and
gfx1036 (boykopovar/AnyPS5#22750). 8- and 16-bit formats never leave that
range, so they are unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:49:00 +00:00
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 02:05 UTC · original

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.

**@⁠Headache3318** on GitHub · 2026-11-25 02:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7150302958) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:16 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7156819562) <!-- 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)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 11:28 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 11:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927#issuecomment-7161100015) ### 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 03:05 UTC · original · approved these changes

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.

**@⁠catminou4** on GitHub · 2026-11-25 03:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927#pullrequestreview-6051251309) · **approved these changes** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:53 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1927#pullrequestreview-6079202523) · **approved these changes** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1927/head:github-bot/gh-1927'
git switch 'github-bot/gh-1927'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1927'
git switch 'github-bot/gh-1927'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1927'
git switch 'github-bot/gh-1927'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1927'
git switch 'main'
git merge --squash 'github-bot/gh-1927'
git switch 'main'
git merge --ff-only 'github-bot/gh-1927'
git switch 'main'
git merge 'github-bot/gh-1927'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1927
No description provided.