Shaders: d16 format loads saturate 32-bit integer channels #1927
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1927
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@upipibi on GitHub · 2026-11-25 01:06 UTC · original
upipibi:fix/d16-int-saturate→main· +36 −3 · 2 files · 1 commits · opentbuffer_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
@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
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.
@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 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
@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
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).
@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.
@fuzeofficlal on GitHub · 2026-11-26 18:53 UTC · original · approved these changes
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.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.