shader: lower subword, indexed, and OOB-checked code-table buffer loads (#4) #486

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

@⁠lucasferreira1610 on GitHub · 2026-11-27 22:00 UTC · original
lucasferreira1610:vibe/code-table-buffer-loads-6f14bc → main · +316 −37 · 3 files · 1 commits · open

What this changes

Refs #4

Extends Lower::code_buffer_load in crates/victory-shader/src/emit/lower.rs for buffer descriptors built around a constant table appended to shader code (s_getpc_b64):

  • Subword loads (buffer_load_ubyte, buffer_load_sbyte, buffer_load_ushort, buffer_load_sshort): lowers 1- and 2-byte loads via Lower::code_subword, including unaligned 16-bit loads straddling two dwords, instead of refusing them as non-dword loads.
  • Indexed loads (idxen): uses the descriptor's stride in dword 1 (bits 16–29) instead of refusing indexed loads.
  • Full RDNA2 ISA table 35 OOB_SELECT bounds checking (modes 0–3): replaces the hardcoded mode-3 shortcut and fixes a 32-bit unsigned wrap-around bug in mode 3 (voffset + immediate + payload_end <= records could previously wrap on large/negative offsets). Uses 64-bit widening only when index * stride is present in mode 3 with non-zero stride; keeps SOFFSET excluded from bounds.
  • Descriptor validation: rejects swizzled dword 1 (bits >> 30 != 0), ADD_TID_ENABLE, non-buffer types (control & 0xC080_0000 != 0), and stores/atomics/format loads, matching computed_buffer.
  • Adds hand-assembled GFX10 unit tests in crates/victory-shader/src/emit/gfx_refusal_tests.rs and updates docs/native-host.md.

How it was tested

  • cargo test -p victory-shader -p xtask (404 passed, 0 failed, 3 ignored) and cargo test --target x86_64-apple-darwin --lib -p victory-shader -p victory-loader -p victory (victory-shader: 404 passed, 0 failed; victory-loader: 29 passed, 0 failed) and cargo test -p victory-hle --lib (144 passed, 0 failed)
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (0 warnings) and cargo clippy -p victory-shader --all-targets -- -D warnings (0 warnings) and cargo xtask policy (398 files ok)
  • Ran the game (not needed; translation-only change without Metal Shader Converter on this machine)

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented
**@⁠lucasferreira1610** on GitHub · 2026-11-27 22:00 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/482) `lucasferreira1610:vibe/code-table-buffer-loads-6f14bc` → `main` · +316 −37 · 3 files · 1 commits · open ## What this changes Refs #4 Extends `Lower::code_buffer_load` in `crates/victory-shader/src/emit/lower.rs` for buffer descriptors built around a constant table appended to shader code (`s_getpc_b64`): - **Subword loads (`buffer_load_ubyte`, `buffer_load_sbyte`, `buffer_load_ushort`, `buffer_load_sshort`)**: lowers 1- and 2-byte loads via `Lower::code_subword`, including unaligned 16-bit loads straddling two dwords, instead of refusing them as non-dword loads. - **Indexed loads (`idxen`)**: uses the descriptor's stride in dword 1 (bits 16–29) instead of refusing indexed loads. - **Full RDNA2 ISA table 35 `OOB_SELECT` bounds checking (modes 0–3)**: replaces the hardcoded mode-3 shortcut and fixes a 32-bit unsigned wrap-around bug in mode 3 (`voffset + immediate + payload_end <= records` could previously wrap on large/negative offsets). Uses 64-bit widening only when `index * stride` is present in mode 3 with non-zero stride; keeps `SOFFSET` excluded from bounds. - **Descriptor validation**: rejects swizzled dword 1 (`bits >> 30 != 0`), `ADD_TID_ENABLE`, non-buffer types (`control & 0xC080_0000 != 0`), and stores/atomics/format loads, matching `computed_buffer`. - Adds hand-assembled GFX10 unit tests in `crates/victory-shader/src/emit/gfx_refusal_tests.rs` and updates `docs/native-host.md`. ## How it was tested - [x] `cargo test -p victory-shader -p xtask` (404 passed, 0 failed, 3 ignored) and `cargo test --target x86_64-apple-darwin --lib -p victory-shader -p victory-loader -p victory` (victory-shader: 404 passed, 0 failed; victory-loader: 29 passed, 0 failed) and `cargo test -p victory-hle --lib` (144 passed, 0 failed) - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (0 warnings) and `cargo clippy -p victory-shader --all-targets -- -D warnings` (0 warnings) and `cargo xtask policy` (398 files ok) - [ ] Ran the game (not needed; translation-only change without Metal Shader Converter on this machine) ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 22:05:16 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 18:36 UTC · original · approved these changes

Reviewed and verified locally on head 59ca4f75 (worktree /private/tmp/review-482):

  • cargo test -p victory-shader -p xtask --locked: all green, including the new code_table_buffer_subword_and_indexed_loads_lower_across_oob_modes and code_table_buffer_rejects_swizzled_add_tid_non_buffer_and_stores.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: exit 0.
  • cargo xtask policy: exit 0.
  • No conflicts with current main (merge-tree clean).

The rewrite is careful where it matters: mode 3's payload-end check is now computed in u64 (const_end and rem are u64), with 64-bit widening of index*stride+voffset only when an indexed, non-zero-stride mode-3 access could wrap u32 — that fixes the wrap-around the old shortcut had. Modes 0/1/2 follow table 35 (mode 0 checks voffset against stride minus the constant part plus index < records; mode 2 disables checks but an empty descriptor still reads 0), SOFFSET stays out of the bounds as in computed_buffer, and code_subword assembles 1/2-byte loads byte-by-byte so an unaligned halfword straddling two dwords reads correctly, with sign extension via shl/ashr. Descriptor validation (swizzle bits, ADD_TID, non-buffer control) matches computed_buffer. Approving.

**@⁠AnastasisKon** on GitHub · 2026-11-28 18:36 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/482#pullrequestreview-6099578782) · **approved these changes** Reviewed and verified locally on head 59ca4f75 (worktree /private/tmp/review-482): - cargo test -p victory-shader -p xtask --locked: all green, including the new code_table_buffer_subword_and_indexed_loads_lower_across_oob_modes and code_table_buffer_rejects_swizzled_add_tid_non_buffer_and_stores. - cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: exit 0. - cargo xtask policy: exit 0. - No conflicts with current main (merge-tree clean). The rewrite is careful where it matters: mode 3's payload-end check is now computed in u64 (const_end and rem are u64), with 64-bit widening of index*stride+voffset only when an indexed, non-zero-stride mode-3 access could wrap u32 — that fixes the wrap-around the old shortcut had. Modes 0/1/2 follow table 35 (mode 0 checks voffset against stride minus the constant part plus index < records; mode 2 disables checks but an empty descriptor still reads 0), SOFFSET stays out of the bounds as in computed_buffer, and code_subword assembles 1/2-byte loads byte-by-byte so an unaligned halfword straddling two dwords reads correctly, with sign extension via shl/ashr. Descriptor validation (swizzle bits, ADD_TID, non-buffer control) matches computed_buffer. Approving.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/gfx_refusal_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/486/head:github-bot/gh-482'
git switch 'github-bot/gh-482'

Merge

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