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