Shaders: truncate s_buffer_load offset terms independently #2438

Closed
github-bot wants to merge 2 commits from gh-pr/2438/head into gh-pr/2438/base
Owner

@⁠makmatvey on GitHub · 2026-11-25 13:30 UTC · original
makmatvey:cursor/shaders-s-buffer-load-align-2ac3 → main · +224 −4 · 2 files · 2 commits · closed without merging

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.

**@⁠makmatvey** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2438) `makmatvey:cursor/shaders-s-buffer-load-align-2ac3` → `main` · +224 −4 · 2 files · 2 commits · closed without merging ## 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.
RDNA ISA §8 ignores the two LSBs of the immediate offset and of soffset
separately before they are summed. Adding first then shifting made
soffset=3 offset:3 load dword 1 instead of dword 0.
Constant 3&!3 folded to 0, so 0+0 tripped -D clippy::identity_op on CI.

Co-authored-by: Matsvey Makushenka <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:05:47 +00:00
github-bot closed this pull request 2026-11-26 05:05:47 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 13:50 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 13:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7164358525) **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._
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 13:55 UTC · original · edited 2026-11-25 14:22 UTC

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.

**@⁠upipibi** on GitHub · 2026-11-25 13:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7164489105) · edited 2026-11-25 14:22 UTC 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.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:26 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 14:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7165290817) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:59 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2438#issuecomment-7167492250) <!-- 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)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2438
No description provided.