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

Merged
Sandile-0511 merged 4 commits from upstream-pr/56 into main 2026-11-26 13:26:37 +00:00
Sandile-0511 commented 2026-11-26 11:35:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-26T11:35:16Z.


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)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625790686 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-26T11:35:16Z. --- ## 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)
LakshanSivakumar commented 2026-11-26 11:51:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:51:45Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073657100 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6073657100). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:51:45Z. **Review:** CHANGES_REQUESTED --- 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`.
Sandile-0511 commented 2026-11-26 12:30:39 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-26T12:30:39Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192094655 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#issuecomment-7192094655). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-26T12:30:39Z. --- 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.
LakshanSivakumar commented 2026-11-26 12:48:06 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:48:06Z.

Review: DISMISSED


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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074382626 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6074382626). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:48:06Z. **Review:** DISMISSED --- Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.
LakshanSivakumar commented 2026-11-26 12:59:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:59:07Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192718949 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#issuecomment-7192718949). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:59:07Z. --- 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 commented 2026-11-26 13:26:34 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T13:26:34Z.

Review: APPROVED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074926703 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/56#pullrequestreview-6074926703). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T13:26:34Z. **Review:** APPROVED --- 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.
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
LakshanSivakumar/Native-Victory-macOS!56
No description provided.