Shaders: truncate s_buffer_load offset terms independently #2436

Closed
makmatvey wants to merge 2 commits from upstream-pr/2438 into main
makmatvey commented 2026-11-25 13:30:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by makmatvey on 2026-11-25T13:30:42Z.


What

s_buffer_load_dword* on RDNA adds the immediate offset and soffset after clearing each term's two LSBs (RDNA ISA guide §8, Scalar Memory Operations). On main the terms were summed first, so soffset = 3 with offset:3 loaded dword 1 ((3+3)>>2) instead of dword 0.

Tracked as VIC-BT-025 in #1249. Related open head #1939 (triage: needs work) — this is a focused slice with the citation and distinguishing soffset=3, offset:3 case from that triage.

Change

In crates/victory-shader/src/emit/lower.rs, mask only the instruction operands (imm & !3, soffset & !3) before adding. Descriptor base / dynamic extra stay unmasked.

Tests

  • cargo test -p victory-shader --locked --lib s_buffer_load_with_unaligned_soffset_and_offset_lowers — pass (Linux)
  • s_buffer_load_truncates_offset_terms_independently (Windows GPU / WARP): soffset=3,offset:3 → dword 0; soffset=7,offset:7 → dword 2
  • cargo clippy -p victory-shader --locked -- -D warnings — clean

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6605613266 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438). Originally posted by [makmatvey](https://github.com/makmatvey) on 2026-11-25T13:30:42Z. --- ## What `s_buffer_load_dword*` on RDNA adds the immediate offset and `soffset` after clearing each term's two LSBs (RDNA ISA guide §8, Scalar Memory Operations). On `main` the terms were summed first, so `soffset = 3` with `offset:3` loaded dword 1 (`(3+3)>>2`) instead of dword 0. Tracked as VIC-BT-025 in #1249. Related open head #1939 (`triage: needs work`) — this is a focused slice with the citation and distinguishing `soffset=3, offset:3` case from that triage. ## Change In `crates/victory-shader/src/emit/lower.rs`, mask only the instruction operands (`imm & !3`, `soffset & !3`) before adding. Descriptor `base` / dynamic `extra` stay unmasked. ## Tests - `cargo test -p victory-shader --locked --lib s_buffer_load_with_unaligned_soffset_and_offset_lowers` — pass (Linux) - `s_buffer_load_truncates_offset_terms_independently` (Windows GPU / WARP): `soffset=3,offset:3` → dword 0; `soffset=7,offset:7` → dword 2 - `cargo clippy -p victory-shader --locked -- -D warnings` — clean No game data used.
DenRakEiw commented 2026-11-25 14:06:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:01:10Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Truncating s_buffer_load offset terms independently (& !3 per term before adding) matches hardware semantics and passes live GPU readback tests.
  • cargo test -p victory-shader s_buffer_load: 2/2 passed on RTX 5090, 2/2 passed on WARP (s_buffer_load_with_unaligned_soffset_and_offset_lowers and s_buffer_load_truncates_offset_terms_independently).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6059002755 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#pullrequestreview-6059002755). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:01:10Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Truncating `s_buffer_load` offset terms independently (`& !3` per term before adding) matches hardware semantics and passes live GPU readback tests. - `cargo test -p victory-shader s_buffer_load`: 2/2 passed on RTX 5090, 2/2 passed on WARP (`s_buffer_load_with_unaligned_soffset_and_offset_lowers` and `s_buffer_load_truncates_offset_terms_independently`). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-25 14:07:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T13:50:06Z.


Verification — head 938a3ccea710112a31be4ca05357d793076f4b55

Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, DXC/dxil 1.8.2502.11 (Windows Kits 10.0.26100.0 x64). origin/main = 940d32f69b22265690a0b5a15d6ded572ba33baf; the PR is one commit set on top of it (merge-base = main), so the exact head was tested with no merge needed.

  • cargo test -p victory-shader --lib: 249 passed, 0 failed, 3 ignored (ignored are pre-existing benchmarks/defect markers). New tests emit::lower::tests::s_buffer_load_with_unaligned_soffset_and_offset_lowers and emit::valu_tests::s_buffer_load_truncates_offset_terms_independently both ran and passed (not skipped).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean. cargo xtask policy: ok.
  • Caveat: the victory-shader GPU tests (emit::valu_tests etc.) iterate over a hardware adapter and WARP and ignore VICTORY_D3D12_WARP, so this run was not WARP-only; they passed on both.

Read the full diff first: no process, network or filesystem code beyond what the PR describes; no game data, dumps, shader names or retail hashes involved.

Verified by Claude Code (Claude Sonnet 5.5), an AI assistant; this is a test report, not a code review or approval.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164358525 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7164358525). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T13:50:06Z. --- **Verification — head `938a3ccea710112a31be4ca05357d793076f4b55`** **Environment:** Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, DXC/dxil 1.8.2502.11 (Windows Kits 10.0.26100.0 x64). `origin/main` = `940d32f69b22265690a0b5a15d6ded572ba33baf`; the PR is one commit set on top of it (merge-base = main), so the exact head was tested with no merge needed. - `cargo test -p victory-shader --lib`: **249 passed, 0 failed, 3 ignored** (ignored are pre-existing benchmarks/defect markers). New tests `emit::lower::tests::s_buffer_load_with_unaligned_soffset_and_offset_lowers` and `emit::valu_tests::s_buffer_load_truncates_offset_terms_independently` both ran and passed (not skipped). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. `cargo xtask policy`: ok. - **Caveat:** the victory-shader GPU tests (`emit::valu_tests` etc.) iterate over a hardware adapter *and* WARP and ignore `VICTORY_D3D12_WARP`, so this run was not WARP-only; they passed on both. Read the full diff first: no process, network or filesystem code beyond what the PR describes; no game data, dumps, shader names or retail hashes involved. _Verified by Claude Code (Claude Sonnet 5.5), an AI assistant; this is a test report, not a code review or approval._
upipibi commented 2026-11-25 14:07:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T13:55:29Z.


Duplicate check: #1939 (ashrafsdrop, opened 01:22Z, mergeable) makes the same change to s_buffer_load in emit/lower.rs.

Both mask the immediate offset and soffset with !3 separately before summing, then add the descriptor base unmasked. The lowering lines are the same apart from variable names (imm/total here, imm_offset/total_offset there). Neither one masks base. The two PRs differ only in their tests. Both add GPU tests in valu_tests.rs, and this one also adds a unit test in lower.rs (s_buffer_load_with_unaligned_soffset_and_offset_lowers). (Edited: I first wrote that the tests differ only in valu_tests.rs.)

AI-assisted (Claude Code). Read from the two diffs against main 940d32f; nothing run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164489105 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7164489105). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T13:55:29Z. --- Duplicate check: #1939 (ashrafsdrop, opened 01:22Z, mergeable) makes the same change to `s_buffer_load` in `emit/lower.rs`. Both mask the immediate offset and `soffset` with `!3` separately before summing, then add the descriptor `base` unmasked. The lowering lines are the same apart from variable names (`imm`/`total` here, `imm_offset`/`total_offset` there). Neither one masks `base`. The two PRs differ only in their tests. Both add GPU tests in `valu_tests.rs`, and this one also adds a unit test in `lower.rs` (`s_buffer_load_with_unaligned_soffset_and_offset_lowers`). (Edited: I first wrote that the tests differ only in `valu_tests.rs`.) AI-assisted (Claude Code). Read from the two diffs against `main` `940d32f`; nothing run.
catminou4 commented 2026-11-25 15:03:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:03Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — s_buffer_load offset terms truncated independently.

<!-- greyfinch-sync:Marvisak/VIctory:review:6059172653 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#pullrequestreview-6059172653). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T14:11:03Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — s_buffer_load offset terms truncated independently.
kotekompotek commented 2026-11-25 15:04:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:26:49Z.


Verified the semantics against RDNA ISA §8: the two LSBs of soffset and of the immediate offset are ignored independently before summing — soffset=3, offset:3 yields 0, not (3+3)>>2 = 1. The old code folded the immediate into base unmasked and never masked soffset at all. extra staying unmasked is right — it is a dynamic component, not an instruction operand. The lower-test pins the lowering, the valu_tests case verifies the actual dword read on hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165290817 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7165290817). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T14:26:49Z. --- Verified the semantics against RDNA ISA §8: the two LSBs of `soffset` and of the immediate offset are ignored *independently* before summing — `soffset=3, offset:3` yields `0`, not `(3+3)>>2 = 1`. The old code folded the immediate into `base` unmasked and never masked `soffset` at all. `extra` staying unmasked is right — it is a dynamic component, not an instruction operand. The lower-test pins the lowering, the `valu_tests` case verifies the actual dword read on hardware.
Marvisak commented 2026-11-25 16:09:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:59:19Z.


Automated triage for the maintainers.

Proposed close: duplicate of #1939. The lowering change in crates/victory-shader/src/emit/lower.rs (the s_buffer_load_dword* path: mask the immediate offset and soffset with !3 separately, leave base and extra unmasked, use the masked total on the constant path) matches #1939 line for line. #1939 was opened earlier and has since been updated (2d6095e) with the RDNA ISA citation and the distinguishing soffset = 3, offset:3 GPU test in valu_tests.rs, which is essentially the same test as the one here. The extra unit test in lower.rs only checks that the shader lowers, not the address. CI (check) passes. If something here is missing from #1939, please suggest it there.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167492250 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7167492250). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:59:19Z. --- <!-- victory-triage v1 head=938a3ccea710112a31be4ca05357d793076f4b55 verdict=proposed-close at=2026-11-25T15:59:00Z --> Automated triage for the maintainers. **Proposed close: duplicate of #1939.** The lowering change in `crates/victory-shader/src/emit/lower.rs` (the `s_buffer_load_dword*` path: mask the immediate offset and `soffset` with `!3` separately, leave `base` and `extra` unmasked, use the masked total on the constant path) matches #1939 line for line. #1939 was opened earlier and has since been updated (`2d6095e`) with the RDNA ISA citation and the distinguishing `soffset = 3, offset:3` GPU test in `valu_tests.rs`, which is essentially the same test as the one here. The extra unit test in `lower.rs` only checks that the shader lowers, not the address. CI (`check`) passes. If something here is missing from #1939, please suggest it there. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync closed this pull request 2026-11-25 18:02:01 +00:00

Pull request closed

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!2436
No description provided.