Shaders: d16 format loads saturate 32-bit integer channels #1925
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1927"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 to0xFFFF, SINT to-32768..32767. So 70000 in a32_UINTbuffer loaded as0x1170here, and as0xFFFFon 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 throughmin(x, 0xFFFF)and SINT ones through a clamp to-32768..32767before 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_integerscovers32_UINTand32_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
main42363ab:cargo test -p victory-shader --locked -- tbuffer_d16: 2 passed. Without thelower.rschange, 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 onmain.cargo xtask policyandcargo clippy -p victory-shader --all-targets --locked -- -D warnings: pass.Not tested: a title.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
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
53affccapplied cleanly onto currentmainccfb029.cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The newtbuffer_d16_loads_saturate_32_bit_integerstest 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 mainccfb029). The PR introduces no new clippy warnings.Not tested: Windows MSVC build, the title itself. AI-assisted.
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.
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 unsignedmin(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 testtbuffer_d16_loads_saturate_32_bit_integerscovers both ends and the in-range cases, and its expected values match the stated rule.CI:
checkpassing.Generated by Claude Code
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
53affcc9ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:53:27Z.
Review: APPROVED
Verified
53affcc9f14227274f6daac6302c8c9aea155adacleanly merged ontomain(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDKdxil.dll):d16_channels(crates/victory-shader/src/emit/lower.rs:5205-5222) cleanly saturatesNumeric::Uintvia unsignedIULTto0xFFFFandNumeric::Sintvia signedSLT/SGTto-32768..=32767before masking to 16 bits, while leaving non-integer formats untouched.emit/lower.rssize: 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, includingtbuffer_d16_loads_saturate_32_bit_integers),d16_(5 passed),emit::tests::constant_color_validates, andemit::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, andINT_MAXtotbuffer_d16_loads_saturate_32_bit_integerswould also pin sign-bit behavior (IULTvsSLT). Ready to merge.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) againstorigin/main(63bcca4).d16format 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 andVICTORY_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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.