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

Open
EatCodeSleep2 wants to merge 1 commit from upstream-pr/1441 into main
EatCodeSleep2 commented 2026-11-24 18:01:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T18:01:46Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588196780 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441). Originally posted by [EatCodeSleep2](https://github.com/EatCodeSleep2) on 2026-11-24T18:01:46Z. --- 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.
marquezinii commented 2026-11-24 19:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:33:42Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140816832 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7140816832). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:33:42Z. --- 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.
AnoHunted commented 2026-11-24 19:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AnoHunted on 2026-11-24T18:38:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140922992 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7140922992). Originally posted by [AnoHunted](https://github.com/AnoHunted) on 2026-11-24T18:38:12Z. --- 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.)
catminou4 commented 2026-11-24 20:02:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:25:01Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 96. GPU/valu execution tests are Windows-gated and were not run here.

Same unwritten-high-half fix as #1437 but for packed D16 buffer loads: the last odd channel goes through low_half so the high half of the destination VGPR survives. Three waterfall cases across 1/2/3-channel buffer_load_format_d16_* (Windows-only); macOS 96 green.

Note: conflicts with #1437 in waterfall_tests.rs (identical build_with_handle_count refactor); complementary in lower.rs — land one, rebase the other.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045876394 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#pullrequestreview-6045876394). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:25:01Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), `cargo test -p victory-shader --locked` → 96. GPU/valu execution tests are Windows-gated and were not run here. Same unwritten-high-half fix as #1437 but for packed D16 buffer loads: the last odd channel goes through `low_half` so the high half of the destination VGPR survives. Three waterfall cases across 1/2/3-channel `buffer_load_format_d16_*` (Windows-only); macOS 96 green. Note: conflicts with #1437 in `waterfall_tests.rs` (identical `build_with_handle_count` refactor); complementary in `lower.rs` — land one, rebase the other.
sinan-cmyk commented 2026-11-24 21:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:43:55Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143981351 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7143981351). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:43:55Z. --- ### 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).
upipibi commented 2026-11-25 01:08:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T00:30:32Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148581158 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7148581158). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T00:30:32Z. --- 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).
Marvisak commented 2026-11-25 04:06:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:27:53Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151938022 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1441#issuecomment-7151938022). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:27:53Z. --- <!-- 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 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/1441:upstream-pr/1441'
git switch 'upstream-pr/1441'

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