shader: lower typed buffer stores of fewer than four channels #56

Manually merged
github merged 4 commits from gh-pr/56/head into gh-pr/56/base 2026-11-26 14:44:21 +00:00
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 11:35 UTC · original
Sandile-0511:fix/typed-store-channels → main · +230 −6 · 5 files · 4 commits · merged 2026-11-26 13:26 UTC

What this changes

A compute shader was refused at world load with a typed buffer store of some channels or at an offset is not supported. The refusal covered MUBUF buffer_store_format_{x,xy,xyz} and the _d16_ forms.

On GFX11 and older the hardware writes 0 to the channels a buffer store does not name (LLVM commit 88421ea "Trim zero components from buffer and image stores"; Mesa "aco: shrink buffer stores with undef/zero components"). So no read-modify-write is needed: the missing bufferStore arguments are padded with 0.0.

Stores at an offset stay refused, now as a typed buffer store at an offset: a typed view cannot address bytes inside an element.

One behaviour change to review: a typed store whose computed offset is not constant is now refused too, as on the load side. Before, such an offset was silently dropped for xyzw stores, so a shader that used to translate (wrongly) may now be refused. Drop the matches!(off, V::Inst(_)) clause if you would rather keep the old behaviour.

How it was tested

  • cargo test -p victory-shader: 221 passed, 0 failed, 2 ignored. New tests typed_buffer_stores_of_some_channels_lower and typed_buffer_stores_at_an_offset_remain_refused.
  • typed_buffer_stores_of_some_channels_zero_the_others in stride_tests is Windows-only; type-checked only.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (clean, run on a Mac)
  • cargo xtask policy (365 files ok)
  • Ran the game in a combined local build: the refusal no longer appears. I do not know whether the real shader had fewer channels or an offset.

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 (zero fill is from the cited sources, not a guess)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Sandile-0511** on GitHub · 2026-11-26 11:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56) `Sandile-0511:fix/typed-store-channels` → `main` · +230 −6 · 5 files · 4 commits · merged 2026-11-26 13:26 UTC ## What this changes A compute shader was refused at world load with `a typed buffer store of some channels or at an offset is not supported`. The refusal covered MUBUF `buffer_store_format_{x,xy,xyz}` and the `_d16_` forms. On GFX11 and older the hardware writes 0 to the channels a buffer store does not name (LLVM commit 88421ea "Trim zero components from buffer and image stores"; Mesa "aco: shrink buffer stores with undef/zero components"). So no read-modify-write is needed: the missing `bufferStore` arguments are padded with 0.0. Stores at an offset stay refused, now as `a typed buffer store at an offset`: a typed view cannot address bytes inside an element. One behaviour change to review: a typed store whose computed offset is not constant is now refused too, as on the load side. Before, such an offset was silently dropped for xyzw stores, so a shader that used to translate (wrongly) may now be refused. Drop the `matches!(off, V::Inst(_))` clause if you would rather keep the old behaviour. ## How it was tested - [x] `cargo test -p victory-shader`: 221 passed, 0 failed, 2 ignored. New tests `typed_buffer_stores_of_some_channels_lower` and `typed_buffer_stores_at_an_offset_remain_refused`. - [ ] `typed_buffer_stores_of_some_channels_zero_the_others` in `stride_tests` is Windows-only; type-checked only. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (clean, run on a Mac) - [x] `cargo xtask policy` (365 files ok) - [x] Ran the game in a combined local build: the refusal no longer appears. I do not know whether the real shader had fewer channels or an offset. ## 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 (zero fill is from the cited sources, not a guess) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:20 +00:00
github manually merged commit bf7851bf1b into gh-pr/56/base 2026-11-26 14:44:21 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:51 UTC · original · requested changes

I reproduced a regression with buffer_store_format_xyzw using s2 as its scalar offset after s_mov_b32 s2, 0. Main lowers it, but the new guard refuses it. Please preserve stores with a provably zero offset, keep the refusal for unsupported offsets, and add a regression for the zero-SGPR case. Please also record the zero-fill and offset behavior in docs/native-host.md.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:51 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6073657100) · **requested changes** I reproduced a regression with `buffer_store_format_xyzw` using `s2` as its scalar offset after `s_mov_b32 s2, 0`. Main lowers it, but the new guard refuses it. Please preserve stores with a provably zero offset, keep the refusal for unsupported offsets, and add a regression for the zero-SGPR case. Please also record the zero-fill and offset behavior in `docs/native-host.md`.
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 12:30 UTC · original

Reproduced the regression and fixed it: a typed store whose scalar offset register is proved to hold 0 by constant moves (s_mov_b32 s2, 0, s_movk_i32, chains of them) lowers again. typed_buffer_stores_at_a_zero_sgpr_offset_lower failed before the change. A non-zero offset (s_mov_b32 s2, 4) and an unknown one (s_mov_b32 s2, s0) stay refused, with a test.

One difference from main remains, on purpose: an offset that may be 0 at run time but is not proved so is still refused, where main dropped it. A zero reached through a phi, arithmetic or a load is not proved. Say if you want that loosened. The zero-fill and offset behaviour are recorded in docs/native-host.md, and main is merged in.

**@⁠Sandile-0511** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#issuecomment-7192094655) Reproduced the regression and fixed it: a typed store whose scalar offset register is proved to hold 0 by constant moves (`s_mov_b32 s2, 0`, `s_movk_i32`, chains of them) lowers again. `typed_buffer_stores_at_a_zero_sgpr_offset_lower` failed before the change. A non-zero offset (`s_mov_b32 s2, 4`) and an unknown one (`s_mov_b32 s2, s0`) stay refused, with a test. One difference from `main` remains, on purpose: an offset that may be 0 at run time but is not proved so is still refused, where `main` dropped it. A zero reached through a phi, arithmetic or a load is not proved. Say if you want that loosened. The zero-fill and offset behaviour are recorded in `docs/native-host.md`, and `main` is merged in.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:48 UTC · original · review (dismissed)

Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6074382626) · **review (dismissed)** Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:59 UTC · original

Approved, but #55 just landed and both add tests at the same spot in gfx_refusal_tests.rs (and this changes its use line), so this now conflicts. Please rebase on main and keep both blocks; I'll merge once CI is green.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:59 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#issuecomment-7192718949) Approved, but #55 just landed and both add tests at the same spot in `gfx_refusal_tests.rs` (and this changes its `use` line), so this now conflicts. Please rebase on main and keep both blocks; I'll merge once CI is green.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 13:26 UTC · original · approved these changes

Rebase cleanly preserves both the #55 v_cvt_pknorm_* tests and the typed-store tests, s_mov_b32 s2, 0 zero-offset handling and docs look good, and CI is green. Merging.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 13:26 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6074926703) · **approved these changes** Rebase cleanly preserves both the #55 `v_cvt_pknorm_*` tests and the typed-store tests, `s_mov_b32 s2, 0` zero-offset handling and docs look good, and CI is green. Merging.
This discussion has been locked. Commenting is limited to contributors.
No description provided.