shader: a 16-bit load at a byte address ending in 3 reads its high byte as 0 #454

Open
opened 2026-11-27 20:07:55 +00:00 by github-bot · 2 comments
Owner

@⁠gagarinyury on GitHub · 2026-11-27 20:07 UTC · original

Two load sites in crates/victory-shader/src/emit/lower.rs take a byte or 16-bit field from the single dword that holds its first byte (// shortcut: the field is taken not to cross a dword.): Lower::flat (global and flat loads such as global_load_ushort) and the buffer path (buffer_load_ushort and buffer_load_sshort through a buffer descriptor). A 16-bit field whose byte address ends in 3 continues into the next dword, so its high byte reads as 0, and a signed load gets the wrong sign. Bytes cannot cross a dword.

The VIctory forks on Windows fixed the same shortcut by also reading the next dword (TaynanGT/Vice-Tay, crates/victory-shader/src/emit/lower.rs, straddles).

I have not measured yet whether the title hits it. Plan: a Metal test of 16-bit loads at byte offsets 0 to 3 that fails on main at offset 3; the fix for loads only (byte and half stores keep their two-atomic form for now); and a corpus sweep with no regressions.

**@⁠gagarinyury** on GitHub · 2026-11-27 20:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/450) Two load sites in `crates/victory-shader/src/emit/lower.rs` take a byte or 16-bit field from the single dword that holds its first byte (`// shortcut: the field is taken not to cross a dword.`): `Lower::flat` (global and flat loads such as `global_load_ushort`) and the buffer path (`buffer_load_ushort` and `buffer_load_sshort` through a buffer descriptor). A 16-bit field whose byte address ends in 3 continues into the next dword, so its high byte reads as 0, and a signed load gets the wrong sign. Bytes cannot cross a dword. The VIctory forks on Windows fixed the same shortcut by also reading the next dword (TaynanGT/Vice-Tay, `crates/victory-shader/src/emit/lower.rs`, `straddles`). I have not measured yet whether the title hits it. Plan: a Metal test of 16-bit loads at byte offsets 0 to 3 that fails on main at offset 3; the fix for loads only (byte and half stores keep their two-atomic form for now); and a corpus sweep with no regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:07:55 +00:00
Author
Owner

@⁠gagarinyury on GitHub · 2026-11-27 20:07 UTC · original

/claim

**@⁠gagarinyury** on GitHub · 2026-11-27 20:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/450#issuecomment-7227191875) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 20:07 UTC · original

Claimed by @⁠gagarinyury. Open a draft pull request with Refs #450 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 20:07 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/450#issuecomment-7227195017) Claimed by @⁠gagarinyury. Open a draft pull request with `Refs #450` in its description within 24 hours, or the claim expires.
This discussion has been locked. Commenting is limited to contributors.
No description provided.