shader: handle dword-straddling 16-bit typed buffer loads at byte offset 3 #1668

Open
geiyiliyabumo wants to merge 1 commit from upstream-pr/1669 into main
geiyiliyabumo commented 2026-11-24 20:36:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T20:36:31Z.


Summary

  • Fixes 16-bit typed buffer format loads (total == 16: 16_* and 8_8_* families) in Lower::format_load (crates/victory-shader/src/emit/lower.rs) when the byte offset satisfies off & 3 == 3.
  • Previously format_load aligned at = off & !3, loaded a single dword, and shifted right by (off & 3) * 8, which left bits [15:8] zeroed whenever a 16-bit element straddled into dword at + 4.
  • Now total == 16 loads the second dword at select(byte == 3, at + 4, at) and merges (w0 >> 24) | (w1 << 8) when byte == 3. Re-reading at when byte != 3 ensures loads at buffer_end - 2 never touch past the buffer end; 8-bit formats (total == 8) remain single-dword loads.
  • Intentionally scoped only to 16-bit dword straddling (does not overlap with #1642's float sNaN widening or #1516/#1370's missing-channel filling).

Verification

  • cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), including tbuffer_16bit_format_loads_handle_dword_straddling_and_tail_bounds covering 16_UINT across all byte offsets 0..=6 (including straddling offset 3 and tail offset buffer_end - 2 on both 8-byte and 4-byte buffers), 16_SINT negative sign extension at offset 3, 16_FLOAT at offset 3, and 2-channel 8_8_UINT (tbuffer_load_format_xy) at offset 3.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: pass (154 files).

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590914965 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1669). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T20:36:31Z. --- ## Summary - Fixes 16-bit typed buffer format loads (`total == 16`: `16_*` and `8_8_*` families) in `Lower::format_load` (`crates/victory-shader/src/emit/lower.rs`) when the byte offset satisfies `off & 3 == 3`. - Previously `format_load` aligned `at = off & !3`, loaded a single dword, and shifted right by `(off & 3) * 8`, which left bits `[15:8]` zeroed whenever a 16-bit element straddled into dword `at + 4`. - Now `total == 16` loads the second dword at `select(byte == 3, at + 4, at)` and merges `(w0 >> 24) | (w1 << 8)` when `byte == 3`. Re-reading `at` when `byte != 3` ensures loads at `buffer_end - 2` never touch past the buffer end; 8-bit formats (`total == 8`) remain single-dword loads. - Intentionally scoped only to 16-bit dword straddling (does not overlap with #1642's float sNaN widening or #1516/#1370's missing-channel filling). ## Verification - `cargo test -p victory-shader --lib`: **121 passed, 0 failed, 1 ignored** on both **AMD Radeon RX 9060 XT (D3D12 hardware)** and **Microsoft Basic Render Driver (WARP)**, including `tbuffer_16bit_format_loads_handle_dword_straddling_and_tail_bounds` covering `16_UINT` across all byte offsets `0..=6` (including straddling offset 3 and tail offset `buffer_end - 2` on both 8-byte and 4-byte buffers), `16_SINT` negative sign extension at offset 3, `16_FLOAT` at offset 3, and 2-channel `8_8_UINT` (`tbuffer_load_format_xy`) at offset 3. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: pass (154 files). *AI-assisted; synthetic tests only, no game files.*
catminou4 commented 2026-11-24 22:01:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:40:14Z.

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 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests.

Dword-straddling 16-bit typed buffer loads at byte offset 3 and tail bounds handled (tbuffer_load_format_offen, run_cases_with_uav_dwords); tests cover 16_UINT/16_SINT straddle and tail offsets on hardware/WARP.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047850148 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1669#pullrequestreview-6047850148). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:40:14Z. **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 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows; macOS covers lowering/structure unit tests. Dword-straddling 16-bit typed buffer loads at byte offset 3 and tail bounds handled (tbuffer_load_format_offen, run_cases_with_uav_dwords); tests cover 16_UINT/16_SINT straddle and tail offsets on hardware/WARP.
Marvisak commented 2026-11-25 02:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:34:06Z.


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: evidence (console capture or a title program) that 16-bit format loads at byte offset 3 straddle two dwords on the console.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149696738 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1669#issuecomment-7149696738). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:34:06Z. --- <!-- victory-triage v1 head=7607291d5b8a55ddca4e5272fdb17ff3faaaa36a verdict=needs-rebase at=2026-11-25T22:20:35Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: evidence (console capture or a title program) that 16-bit format loads at byte offset 3 straddle two dwords on the console. --- _Generated by [Claude Code](https://claude.ai/code)_
Headache3318 commented 2026-11-25 02:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Headache3318 on 2026-11-25T01:36:09Z.


Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 70d3a82 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 96 passed, 0 failed, 1 ignored. All tests pass.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 2 unused-import errors in test code — these are pre-existing on main (ccfb029 fails identically). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149737293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1669#issuecomment-7149737293). Originally posted by [Headache3318](https://github.com/Headache3318) on 2026-11-25T01:36:09Z. --- Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `70d3a82` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 96 passed, 0 failed, 1 ignored. All tests pass. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 2 unused-import errors in test code — these are pre-existing on main (`ccfb029` fails identically). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
geiyiliyabumo commented 2026-11-25 03:03:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T02:25:56Z.


Rebased cleanly onto \main\ (\ccfb029). \cargo test -p victory-shader --locked tbuffer\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings, and \cargo xtask policy\ all pass.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150711802 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1669#issuecomment-7150711802). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-25T02:25:56Z. --- Rebased cleanly onto \main\ (\ccfb029\). \cargo test -p victory-shader --locked tbuffer\ (verified on physical AMD RX 9060 XT + WARP + Microsoft \dxil.dll\), \cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings\, and \cargo xtask policy\ all pass.
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/1669:upstream-pr/1669'
git switch 'upstream-pr/1669'

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