Shaders/Lower: reject non-zero soffset/built_offset on typed buffer_store_format_xyzw #3007

Open
RVZO6 wants to merge 1 commit from upstream-pr/3009 into main
RVZO6 commented 2026-11-26 03:19:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T03:19:30Z.


Lower::buffer's typed buffer_load_format_* path (crates/victory-shader/src/emit/lower.rs:9785) rejects any non-zero soffset or built_offset via if *offen || matches!(off, V::Inst(_)) || *offset != 0, whereas the typed buffer_store_format_xyzw path (L9675) checked only count != 4 || *offen || *offset != 0.

When soffset was a scalar register or non-zero inline constant (or built_offset added a non-zero base/extra), buffer_store_format_xyzw silently discarded off and wrote to element index at offset 0 instead of returning Err.

Add matches!(off, V::Inst(_)) to match buffer_load_format_*. Tests live in crates/victory-shader/src/emit/lower/typed_store_tests.rs (keeping lower.rs at 520,628 B, well under the 512 KiB limit).

Verification

  • Negative control (before fix): typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero failed (typed buffer store with inline soffset=16 must not silently drop the offset).
  • After fix: refuses both inline soffset = 16 and SGPR soffset = s0, while soffset = 0 continues lowering cleanly and passing dxil.dll validation.
  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45747688145 (green, combined Wave 9 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6618764160 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T03:19:30Z. --- `Lower::buffer`'s typed `buffer_load_format_*` path (`crates/victory-shader/src/emit/lower.rs:9785`) rejects any non-zero `soffset` or `built_offset` via `if *offen || matches!(off, V::Inst(_)) || *offset != 0`, whereas the typed `buffer_store_format_xyzw` path (`L9675`) checked only `count != 4 || *offen || *offset != 0`. When `soffset` was a scalar register or non-zero inline constant (or `built_offset` added a non-zero base/extra), `buffer_store_format_xyzw` silently discarded `off` and wrote to element `index` at offset 0 instead of returning `Err`. Add `matches!(off, V::Inst(_))` to match `buffer_load_format_*`. Tests live in `crates/victory-shader/src/emit/lower/typed_store_tests.rs` (keeping `lower.rs` at `520,628 B`, well under the 512 KiB limit). ### Verification - **Negative control (before fix):** `typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero` failed (`typed buffer store with inline soffset=16 must not silently drop the offset`). - **After fix:** refuses both inline `soffset = 16` and SGPR `soffset = s0`, while `soffset = 0` continues lowering cleanly and passing `dxil.dll` validation. - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45747688145](https://github.com/RVZO6/VIctory/actions/runs/45747688145) (green, combined Wave 9 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Dukestar69 commented 2026-11-26 04:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:31:59Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-shader --lib typed_store_tests: 1 passed, 0 failed (typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068186358 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009#pullrequestreview-6068186358). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T03:31:59Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-shader --lib typed_store_tests`: **1 passed, 0 failed** (`typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 04:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:38:39Z.

Review: CHANGES_REQUESTED


Code review on 4eeb2eb1 (static source inspection; no runtime GPU/DXIL validation executed):

  • P2 — Guard rejects typed buffer stores whose SGPR soffset is provably constant zero (crates/victory-shader/src/emit/lower.rs:9443-9449, 9677):
    • At lower.rs:9443-9449, any soffset other than NULL or inline constant 128 (0) emits off = self.s.m.bin(c, Bin::Add, off, so), which unconditionally returns V::Inst(_) without constant-folding 0 + 0.
    • Consequently, matches!(off, V::Inst(_)) at lower.rs:9677 rejects a valid typed store whose scalar register holds constant zero (for instance, passing s13 — initialized via s_mov_b32 s13, 0 in typed_store_tests.rs:44 — as soffset), regressing shaders that previously lowered cleanly.
    • Suggest skipping the Bin::Add when so resolves to V::Const(0) (and adding lower_typed_store(0x0d) as a positive test case alongside inline zero and nonzero soffset).
  • File size check: patched emit/lower.rs is 520,628 B (within the 512 KiB limit).
<!-- greyfinch-sync:Marvisak/VIctory:review:6068227330 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009#pullrequestreview-6068227330). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T03:38:39Z. **Review:** CHANGES_REQUESTED --- Code review on `4eeb2eb1` (static source inspection; no runtime GPU/DXIL validation executed): - **P2 — Guard rejects typed buffer stores whose SGPR `soffset` is provably constant zero (`crates/victory-shader/src/emit/lower.rs:9443-9449, 9677`)**: - At `lower.rs:9443-9449`, any `soffset` other than `NULL` or inline constant `128` (`0`) emits `off = self.s.m.bin(c, Bin::Add, off, so)`, which unconditionally returns `V::Inst(_)` without constant-folding `0 + 0`. - Consequently, `matches!(off, V::Inst(_))` at `lower.rs:9677` rejects a valid typed store whose scalar register holds constant zero (for instance, passing `s13` — initialized via `s_mov_b32 s13, 0` in `typed_store_tests.rs:44` — as `soffset`), regressing shaders that previously lowered cleanly. - Suggest skipping the `Bin::Add` when `so` resolves to `V::Const(0)` (and adding `lower_typed_store(0x0d)` as a positive test case alongside inline zero and nonzero `soffset`). - File size check: patched `emit/lower.rs` is `520,628 B` (within the 512 KiB limit).
futurepro62 commented 2026-11-26 04:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T03:58:36Z.


NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head 4eeb2eb (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7182185637 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009#issuecomment-7182185637). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T03:58:36Z. --- NVIDIA full-suite run, to go with the reports above by Dukestar69, since none of them names a GPU run. Tested exact head `4eeb2eb` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **867 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `typed_buffer_store_rejects_nonzero_soffset_and_accepts_zero`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
kotekompotek commented 2026-11-26 05:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:39:50Z.

Review: APPROVED


LGTM — matches the load-side check: a nonzero soffset carried in an SGPR (V::Inst) was silently discarded before; now refused. Test covers scalar and inline-constant soffset.

<!-- greyfinch-sync:Marvisak/VIctory:review:6068630565 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009#pullrequestreview-6068630565). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T04:39:50Z. **Review:** APPROVED --- LGTM — matches the load-side check: a nonzero soffset carried in an SGPR (V::Inst) was silently discarded before; now refused. Test covers scalar and inline-constant soffset.
Marvisak commented 2026-11-26 07:01:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:17:03Z.


Automated triage for the maintainers.

This is a one-line change to the typed-store branch of Lower::buffer (emit/lower.rs). Today that branch drops a non-zero soffset, or a built_offset base or extra, without warning and writes at element index. The PR adds matches!(off, V::Inst(_)) to the refusal condition, the same check the typed-load branch already uses. I confirmed that Module::bin doesn't fold constants, so any offset added to off makes it a V::Inst, and only a zero or null soffset with no built offset keeps the store. The new test typed_store_tests.rs checks refusal for an inline soffset of 16 and for an SGPR soffset, and acceptance for zero.

Trade-off for the maintainer: a typed store whose SGPR soffset happens to be zero at run time now refuses the shader, where today it works. That matches the typed-load behaviour.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184276191 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3009#issuecomment-7184276191). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T06:17:03Z. --- <!-- victory-triage v1 head=4eeb2eb1698e5912bed0d61d3bd4552503eb2e3a verdict=merge-candidate at=2026-11-26T06:20:00Z --> Automated triage for the maintainers. This is a one-line change to the typed-store branch of `Lower::buffer` (`emit/lower.rs`). Today that branch drops a non-zero `soffset`, or a `built_offset` base or extra, without warning and writes at element `index`. The PR adds `matches!(off, V::Inst(_))` to the refusal condition, the same check the typed-load branch already uses. I confirmed that `Module::bin` doesn't fold constants, so any offset added to `off` makes it a `V::Inst`, and only a zero or null `soffset` with no built offset keeps the store. The new test `typed_store_tests.rs` checks refusal for an inline `soffset` of 16 and for an SGPR `soffset`, and acceptance for zero. Trade-off for the maintainer: a typed store whose SGPR `soffset` happens to be zero at run time now refuses the shader, where today it works. That matches the typed-load behaviour. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3009:upstream-pr/3009'
git switch 'upstream-pr/3009'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3009'
git switch 'upstream-pr/3009'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3009'
git switch 'upstream-pr/3009'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3009'
git switch 'main'
git merge --squash 'upstream-pr/3009'
git switch 'main'
git merge --ff-only 'upstream-pr/3009'
git switch 'main'
git merge 'upstream-pr/3009'
git push origin 'main'
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
Marvisak/VIctory!3007
No description provided.