shader: a 16-bit load at a dword's last byte reads the next dword (#450) #456

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

@⁠gagarinyury on GitHub · 2026-11-27 20:17 UTC · original
gagarinyury:fix/half-across-dword → main · +213 −18 · 5 files · 1 commits · open

What this changes

Refs #454

global_load_ushort/sshort and buffer_load_ushort/sshort read only the dword that holds the field's first byte (// shortcut: the field is taken not to cross a dword.), so a 16-bit value at a byte address ending in 3 lost its high byte: it read 0, or the wrong sign for sshort.

Both load sites in crates/victory-shader/src/emit/lower.rs (Lower::flat and the buffer path) now also read the next dword, at + 4 in the same view. For title memory that goes through the same page lookup, as multi-dword loads already do. The two dwords are joined as (w0 >> 24) | (w1 << 8) before the 16-bit extension.

  • Byte loads are unchanged.
  • Byte and half stores (two atomics) keep their shortcut.
  • It is the same fix as the Windows forks' straddles (TaynanGT/Vice-Tay).

How it was tested

  • half_load_tests (victory-gpu, Metal) has a global case and a buffer case: ushort at byte offsets 0 to 3, and sshort at 3.
    • On main both fail at offset 3, reading 0x44 for 0x8544.
    • Both pass with the change.
  • cargo test -p victory-shader: 402 + 5 passed.
  • cargo test -p victory-gpu --lib split_wave_tests: 47 passed.
  • cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.
  • cargo xtask policy: 399 files ok.
  • Corpus sweep against b998bb65 (sweep -j 4 and tools/corpus/compare.sh, 25,985 containers from my own boot dump):
    • 0 regressions and 0 newly translated.
    • 5 compute outputs changed.
    • Each of the five has 16-bit loads that take the new path (51 buffer_load_ushort and 6 global_load_ushort between them), so the change in each is the added read of the next dword.
  • A headless game run of this commit (Series S, base M5, 32 GB, 330 s) reached the world (first world frame at about +160 s, then 0.7 to 1.3 fps) with no GPU errors and no crash. The run was not compared with a run of main.

Not measured: whether the title reads halves at byte 3 at run time.

**@⁠gagarinyury** on GitHub · 2026-11-27 20:17 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/452) `gagarinyury:fix/half-across-dword` → `main` · +213 −18 · 5 files · 1 commits · open ## What this changes Refs #454 `global_load_ushort`/`sshort` and `buffer_load_ushort`/`sshort` read only the dword that holds the field's first byte (`// shortcut: the field is taken not to cross a dword.`), so a 16-bit value at a byte address ending in 3 lost its high byte: it read 0, or the wrong sign for `sshort`. Both load sites in `crates/victory-shader/src/emit/lower.rs` (`Lower::flat` and the buffer path) now also read the next dword, at `+ 4` in the same view. For title memory that goes through the same page lookup, as multi-dword loads already do. The two dwords are joined as `(w0 >> 24) | (w1 << 8)` before the 16-bit extension. - Byte loads are unchanged. - Byte and half stores (two atomics) keep their shortcut. - It is the same fix as the Windows forks' `straddles` (TaynanGT/Vice-Tay). ## How it was tested - `half_load_tests` (`victory-gpu`, Metal) has a global case and a buffer case: `ushort` at byte offsets 0 to 3, and `sshort` at 3. - On `main` both fail at offset 3, reading `0x44` for `0x8544`. - Both pass with the change. - `cargo test -p victory-shader`: 402 + 5 passed. - `cargo test -p victory-gpu --lib split_wave_tests`: 47 passed. - `cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings`: clean. - `cargo xtask policy`: 399 files ok. - Corpus sweep against `b998bb65` (`sweep -j 4` and `tools/corpus/compare.sh`, 25,985 containers from my own boot dump): - 0 regressions and 0 newly translated. - 5 compute outputs changed. - Each of the five has 16-bit loads that take the new path (51 `buffer_load_ushort` and 6 `global_load_ushort` between them), so the change in each is the added read of the next dword. - A headless game run of this commit (Series S, base M5, 32 GB, 330 s) reached the world (first world frame at about +160 s, then 0.7 to 1.3 fps) with no GPU errors and no crash. The run was not compared with a run of `main`. Not measured: whether the title reads halves at byte 3 at run time.
global_load_ushort/sshort and buffer_load_ushort/sshort read only the dword
holding the field's first byte, so a half at byte address & 3 == 3 lost its high
byte. Both sites now read the next dword too (at + 4 in the same view) and join
(w0 >> 24) | (w1 << 8) before extending from 16 bits; byte loads and the code
for width 8 are unchanged. The byte/half store site keeps its shortcut.

half_load_tests runs both loads on Metal at byte offsets 0 to 3 (ushort) and 3
(sshort); it failed at offset 3 before the fix. The tests file's translate
helper is split so a test can translate a NativeProgram of its own.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:18:39 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:37 UTC · original · requested changes

Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in crates/victory-gpu/src/native/addr_tests.rs.

Could you merge current main into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? Main may now have a test helper of the same name (try_translate_native); if so, keep one copy. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.

**@⁠Olima34** on GitHub · 2026-11-28 00:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/452#pullrequestreview-6094669383) · **requested changes** Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in `crates/victory-gpu/src/native/addr_tests.rs`. Could you merge current `main` into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? Main may now have a test helper of the same name (`try_translate_native`); if so, keep one copy. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:46 UTC · original

The maintainer is handling this one himself; please follow his lead rather than my review.

**@⁠Olima34** on GitHub · 2026-11-28 00:46 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/452#issuecomment-7231186490) The maintainer is handling this one himself; please follow his lead rather than my review.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/native/addr_tests.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/456/head:github-bot/gh-452'
git switch 'github-bot/gh-452'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-452'
git switch 'github-bot/gh-452'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-452'
git switch 'github-bot/gh-452'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-452'
git switch 'main'
git merge --squash 'github-bot/gh-452'
git switch 'main'
git merge --ff-only 'github-bot/gh-452'
git switch 'main'
git merge 'github-bot/gh-452'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.