Skip to content

Shaders: truncate s_buffer_load offset terms independently - #2438

Closed
makmatvey wants to merge 2 commits into
Marvisak:mainfrom
makmatvey:cursor/shaders-s-buffer-load-align-2ac3
Closed

makmatvey wants to merge 2 commits into
Marvisak:mainfrom
makmatvey:cursor/shaders-s-buffer-load-align-2ac3

Conversation

@makmatvey

Copy link
Copy Markdown
Contributor

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 <matvey.myown@gmail.com>
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

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

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown

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.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: merged into main 940d32f, 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

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants