Shaders: preserve the unwritten high half of packed D16 buffer loads #1441

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

@⁠EatCodeSleep2 on GitHub · 2026-11-24 18:01 UTC · original
EatCodeSleep2:fix/preserve-d16-buffer-high-half-1242 → main · +50 −4 · 2 files · 1 commits · open

Addresses the destination register preservation part of VIC-BT-015 in #1242. For buffer_load_format_d16_x/xyz, merge the last channel into the low half of the final VGPR. A full pair still replaces the whole VGPR. Integer format interpretation is separate.

The synthetic typed-buffer regression covers x, xy and xyz. The one-channel case on main read back 0x00003c00 instead of 0x5a5a3c00. The native D16 buffer probe also checks that the x form preserves the original high half. This PR shares the small test builder extension from #1437 and can land independently.

120 shader tests and strict shader Clippy passed on Windows. The shader suite excluded the existing v_med3_f32 host NaN failure.

AI use: Codex wrote and tested the change.

**@⁠EatCodeSleep2** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441) `EatCodeSleep2:fix/preserve-d16-buffer-high-half-1242` → `main` · +50 −4 · 2 files · 1 commits · open Addresses the destination register preservation part of VIC-BT-015 in #1242. For buffer_load_format_d16_x/xyz, merge the last channel into the low half of the final VGPR. A full pair still replaces the whole VGPR. Integer format interpretation is separate. The synthetic typed-buffer regression covers x, xy and xyz. The one-channel case on main read back 0x00003c00 instead of 0x5a5a3c00. The [native D16 buffer probe](https://github.com/LeonidaReforge/Leonida/blob/main/tools/d16_format_probe.py) also checks that the x form preserves the original high half. This PR shares the small test builder extension from #1437 and can land independently. 120 shader tests and strict shader Clippy passed on Windows. The shader suite excluded the existing v_med3_f32 host NaN failure. AI use: Codex wrote and tested the change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:51 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:33 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 60bf416. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 121 passed, 0 failed, 1 ignored. packed_buffer_load_keeps_unwritten_high_half passes on the hardware adapter and WARP, and nothing on the hardware adapter was skipped. The only skips are the four diff_tests that need the console compiler.

I also merged this with #1437 locally: build_with_handle_count comes out once and both merge cleanly in either order, so they really can land independently.

**@⁠marquezinii** on GitHub · 2026-11-24 18:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7140816832) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `60bf416`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 121 passed, 0 failed, 1 ignored. `packed_buffer_load_keeps_unwritten_high_half` passes on the hardware adapter and WARP, and nothing on the hardware adapter was skipped. The only skips are the four `diff_tests` that need the console compiler. I also merged this with #1437 locally: `build_with_handle_count` comes out once and both merge cleanly in either order, so they really can land independently.
Author
Owner

@⁠AnoHunted on GitHub · 2026-11-24 18:38 UTC · original

Independent NVIDIA run. No game files were used.

Machine: Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, DXC dxil.dll 1.9.2609 (SDK 10.0.26100) validating.

cargo test -p victory-shader --features host -- --test-threads=1 with this PR:

  • 121 passed, 0 failed, 1 ignored (main: 120 / 0 / 1), including the added packed_buffer_load_keeps_unwritten_high_half.

Not tested: the in-game effect; AMD. (Sibling #1437, the image version, reported separately.)

**@⁠AnoHunted** on GitHub · 2026-11-24 18:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7140922992) Independent NVIDIA run. No game files were used. Machine: Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, DXC `dxil.dll` 1.9.2609 (SDK 10.0.26100) validating. `cargo test -p victory-shader --features host -- --test-threads=1` with this PR: - **121 passed, 0 failed, 1 ignored** (main: 120 / 0 / 1), including the added `packed_buffer_load_keeps_unwritten_high_half`. Not tested: the in-game effect; AMD. (Sibling #1437, the image version, reported separately.)
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:43 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head 60bf416 onto main ffe310e (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: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

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

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7143981351) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 60bf416 onto `main` ffe310e (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: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:30 UTC · original · edited 2026-11-25 01:06 UTC

A related measured rule for the same function (d16_channels), in case it's worth folding in here or in a follow-up. Not run here; it comes from reading plus two hardware measurements.

  • 32-bit integer formats saturate rather than truncate. UINT goes to min(x, 0xffff) and SINT to clamp(x, -32768, 32767). For example, a 32_UINT 70000 (0x11170) loads as 0xffff, where & 0xFFFF gives 0x1170. This was measured for buffer_load_format_d16_* on gfx1031 (cited in xcl-dev/xcl#1488 item XCL-BT-020, which xcl-dev/xcl#1977 now implements). It was also measured for D16 image reads on gfx1036 in boykopovar/AnyPS5#22750. 8- and 16-bit formats never leave that range, so they're unaffected. (Now #1927, which merges cleanly with this PR.)
  • 32-bit float texels round toward zero … legacyF32ToF16 rounds to nearest. Correction: on D3D12 the legacy f32→f16 conversion already rounds toward zero. I measured it in XCL's equivalent path on an RTX 3070 (616.56) and on WARP: 1 + 3·2⁻¹¹ → 0x3c01, 70000 → 0x7bff. That matches RDNA2, so only the integer saturation above applies here. AnyPS5's float case came from Vulkan's packHalf2x16.

#1437 has the image-side counterpart, if the image D16 path packs the same way.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 00:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7148581158) · edited 2026-11-25 01:06 UTC A related measured rule for the same function (`d16_channels`), in case it's worth folding in here or in a follow-up. Not run here; it comes from reading plus two hardware measurements. - **32-bit integer formats saturate rather than truncate.** UINT goes to `min(x, 0xffff)` and SINT to `clamp(x, -32768, 32767)`. For example, a 32_UINT 70000 (`0x11170`) loads as `0xffff`, where `& 0xFFFF` gives `0x1170`. This was measured for `buffer_load_format_d16_*` on gfx1031 (cited in xcl-dev/xcl#1488 item XCL-BT-020, which xcl-dev/xcl#1977 now implements). It was also measured for D16 image reads on gfx1036 in boykopovar/AnyPS5#22750. 8- and 16-bit formats never leave that range, so they're unaffected. (Now #1927, which merges cleanly with this PR.) - ~~32-bit float texels round toward zero … `legacyF32ToF16` rounds to nearest.~~ **Correction:** on D3D12 the legacy f32→f16 conversion already rounds toward zero. I measured it in XCL's equivalent path on an RTX 3070 (616.56) and on WARP: `1 + 3·2⁻¹¹` → `0x3c01`, 70000 → `0x7bff`. That matches RDNA2, so only the integer saturation above applies here. AnyPS5's float case came from Vulkan's `packHalf2x16`. #1437 has the image-side counterpart, if the image D16 path packs the same way. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:27 UTC · original · edited 2026-11-25 16:05 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7151938022) · edited 2026-11-25 16:05 UTC <!-- victory-triage v1 head=60bf416db31a782e4d32216171a847f59f2745dc verdict=needs-rebase at=2026-11-25T16:02:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1441'
git switch 'github-bot/gh-1441'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1441'
git switch 'github-bot/gh-1441'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1441'
git switch 'main'
git merge --squash 'github-bot/gh-1441'
git switch 'main'
git merge --ff-only 'github-bot/gh-1441'
git switch 'main'
git merge 'github-bot/gh-1441'
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!1441
No description provided.