Shaders: scalar memory loads align each address term independently #3349
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3349
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3349"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Moon0755 on GitHub · 2026-11-26 19:34 UTC · original
Moon0755:fix/smem-load-align→main· +163 −3 · 2 files · 1 commits · openWhat
s_load_dword*from title memory (Lower::memory_smem) added the 64-bit base address, the signed 21-bit immediate offset, and the unsigned SGPRsoffsetbefore passing the byte address toself.memory. On RDNA2 hardware, scalar memory loads truncate each address component to a dword boundary independently before adding them:(base & ~3) + (soffset & ~3) + (imm & ~3) + 4*i.Because the unaligned low bits of each term were added together instead of dropped first, combinations such as
base = TITLE + 1withimm = 3orsoffset = 2withimm = 6read the next dword (+4/+8) instead of+0/+4. Each term (lo,offset, andsoffsetwhen present) is now masked with!3beforeadd64.For dword-aligned inputs the result is unchanged.
How
In
crates/victory-shader/src/emit/lower.rs(Lower::memory_smem), masklo,offset, andsoffset(when notNULL) with!3before summing them inadd64. For negative 21-bit immediates,(offset as u32) & !3preserves the sign-extended rounding down to a multiple of 4 (e.g.-1 & !3 = -4), keepingoffset < 0foradd64.lower.rsgrows by 329 bytes (520,563 to 520,892).Evidence
87d7bf7c43reports raw compute kernel measurements on AMD Radeon RX 6800 (gfx1030, driver 32.0.21045.29003, wave32 = wave64, 155 runs): each ofbase,soffset, andimmis truncated to a multiple of 4 before addition (base & 3 = 1withimm = 3 -> data@0;soffset = 8withimm = -4 -> @4;soffset = 0xbwithimm = -1 -> @4; same rule fors_load*withpointer & 3 = 1or3). Only the stated rule and measured cases are used; no code is taken.devin/ci-smem-load-align-negative): run 45883071279 — 302 passed, 1 failed (scalar_loads_truncate_address_terms_to_dwords_independently: returned[0xA110_0001, 0xA110_0002]instead of[0xA110_0000, 0xA110_0001]).devin/ci-smem-load-align): run 45883064141 — 303 passed, 0 failed; both Clippy runs clean;policy::tests::repository_passes_policy ... ok.96d6ddb(control) and0f68e4d(fix) on AMD Radeon(TM) Graphics, NVIDIA GeForce RTX 2060 Max-Q, and WARP: fails with[0xA110_0001, 0xA110_0002]without the fix and passes on all three with the fix.Other pull requests
triage: merge candidate) and #1336 cover independent dword truncation fors_buffer_load*(Lower::smem) and do not touchLower::memory_smem.memory_smem.memory_tests.rs.Not checked
s_load_dwordx2/x4/...loads, ands_store*are not covered by the new test.s_load_dword*terms (no game corpus).Synthetic tests only; no game files.
— Devin & Neon
@Dukestar69 on GitHub · 2026-11-26 19:48 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).lo), immediateoffset, andsoffsetindependently with& !3before summing accurately matches RDNA2 SMEM dword-aligned address formation.cargo test -p victory-shader --lib emit::memory_tests:: -- --skip heap_direct_texture_reads_mark_their_heap_index --test-threads=1: 5 passed, 0 failed on RTX 5090 and 5 passed, 0 failed onVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 20:02 UTC · original · approved these changes
Looks good to me — masking
lo, the sign-extended 21-bitoffset, andsoffsetindependently with!3beforeadd64matches RDNA2SMEMeffective-address calculation ((SBASE & ~3) + (sext(OFFSET) & ~3) + (zext(SOFFSET) & ~3)), including negative immediates and 32-bit carry propagation.Verified locally on Windows 11 with head
0f68e4d6cleanly merged ontomain(63bcca43):crates/victory-shader/src/emit/lower.rsis520,892bytes (3,396bytes below the524,288limit), and the newly added lines inlower.rs:4495-4501matchrustfmt --edition 2024.cargo run -p xtask -- policy(191 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(both default and--all-features) pass.cargo test --locked -p victory-shader --lib emit::memory_tests(withWindows Kits\10\bin\10.0.26100.0\x64\dxil.dllpresent):VICTORY_WARP=0(--skip heap_direct_texture_reads_mark_their_heap_index):5 passed; 0 failed(1.56s, includingscalar_loads_truncate_address_terms_to_dwords_independently).VICTORY_WARP=1(fullemit::memory_tests):6 passed; 0 failed(0.30s).Minor non-blocking formatting nit:
rustfmt --edition 2024 --checkreports two line-wrap diffs on added lines atcrates/victory-shader/src/emit/memory_tests.rs:1020and1061. (Also note the sibling PC-relativeCODEpath inLower::smemstill combines unmaskedimm + soffsetseparately.)@oni-swr on GitHub · 2026-11-26 20:10 UTC · original
WARP verification of head
0f68e4d6d43287c4ade1765a1eb660728ad303c2(control: main63bcca43).New test present at head (in
emit/memory_tests.rs):scalar_loads_truncate_address_terms_to_dwords_independently.--exact)scalar_loads_truncate_address_terms_to_dwords_independentlyhardwareassertion mismatch)So the test catches a real bug on main and is fixed by the PR. victory-shader lib: head 299 passed / 4 failed (the unrelated four below); control 299 passed / 7 failed (the same four plus this PR's test and #3351's two, which I carried in the same control checkout). Note the PR does not cover negative immediates or wide loads (it says so itself); I did not extend it.
Setup (Windows 11, no physical GPU):
VICTORY_WARP=1,VICTORY_D3D12_WARP=1,VICTORY_DXIL= Windows SDK 10.0.26100.0x64\dxil.dll, toolchain 1.98.1,-j 4. Head and control are separate checkouts with separate target dirs. Control = main63bcca43c6a00a758510398fa43096ce7e4f7df0plus only the PR's new/changed test code (no source change).Suites (
cargo test -j 4 --locked -p victory-shader --lib,-p victory-gpu --lib): victory-gpu lib 231 passed / 0 failed / 1 ignored on head and control. victory-shader lib has the same 4 failures on head and control, all inemit::synthetic_testsand independent of this PR:a_mask_joined_with_data_at_a_uniform_loop_is_its_number,permutes_mask_high_address_bits_and_divergent_branchesandpermutes_read_the_lane_named_and_zero_from_lanes_left_out(no pipeline for a wave of 32, a WARP limitation), andgathers_at_a_level_match_the_hardware(lane-4 gather values differ on WARP). Re-running one of them alone in its own process fails the same way on main and on the head, so they are deterministic on WARP, not flaky. No flakes seen in the PR's tests.Synthetic tests only; no game files, dumps, shader names or hashes. Test report only, no code changes. Claimed on #1633. AI use: Claude Code (Claude Sonnet 5.5).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.