Shaders: drop unaligned 32-bit buffer atomics #3389
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!3389
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3389"
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 21:26 UTC · original
Moon0755:fix/buffer-atomic-align→main· +101 −11 · 2 files · 1 commits · openOn RDNA2 (
gfx1036, measured natively in wave32 and wave64 in Leonidadocs/design.md), 32-bitbuffer_atomic*enforces natural dword alignment ((addr & 3) == 0), including underOOB_SELECT = 2. An unaligned atomic leaves memory untouched, returns0to activeglclanes, and preservesvdst/vdataon inactive lanes. Without a guard, D3D12/WARP truncates the offset to a dword and executes the atomic against the aligned dword.Changes
crates/victory-shader/src/emit/lower.rs(Lower::buffer,521,509bytes /+946vsmain,2,779bytes below the524,288limit):(addr & 3) == 0combined with the lane guard before enteringbegin_guarded, checkingrow + offon structured buffers,lo + offbeforeraw_viewon title memory (so dropped unaligned atomics do not mark title-memory pages dirty), and returnedoff(includingroot_view_offset) on raw/root views.0throughend_guardedfor active unalignedglclanes and preserve inactive lanes viaself.write(inst, Reg::V(reg), r, guard).buffer_atomic*_x2ops are not yet lowered onmain, and low base bits of heap-loaded V# descriptors remain a broader view-metadata limitation.crates/victory-shader/src/emit/stride_tests.rs:unaligned_buffer_atomics_are_dropped_and_return_zero.Verification
main): https://github.com/Moon0755/VIctory/actions/runs/45893611204 (failure— 302 passed, 1 failed solely onunaligned_buffer_atomics_are_dropped_and_return_zero, writing[0, 14, ...]and returning7)a38641b): https://github.com/Moon0755/VIctory/actions/runs/45897727776 (success— 303 passed / 0 failed, Clippy + diagnostics Clippy clean,policy::tests::repository_passes_policy ... ok)WARP,AMD Radeon(TM) Graphics, andNVIDIA GeForce RTX 2060 with Max-Q Design— all fail without the fix and pass ona38641b.— Devin & Neon
@fuzeofficlal on GitHub · 2026-11-26 21:38 UTC · original · approved these changes
LGTM — verified against
origin/main(63bcca43) on Windows x64 (RTX 5090 +dxil.dlland WARP).buffer_atomic_*ops (includingcmpswap) on dword alignment combined with the EXEC guard (crates/victory-shader/src/emit/lower.rs:9544-9612) skips DXIL atomics,mark_view_write, and title-memory page-table/dirty updates on misaligned lanes, returning0on activeglc = 1lanes whileself.write(..., guard)preserves inactive EXEC lanes.unaligned_buffer_atomics_are_dropped_and_return_zero(crates/victory-shader/src/emit/stride_tests.rs:503-548) explicitly reloadsv2 = 7before the misalignedglcadd and confirms both memory preservation (7) and the0return on hardware and WARP.off >= stride) still rely on host structured bounds behavior.cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests:: emit::lower::: 40 passed, 0 failed underVICTORY_WARP=0(skipping the 2 baseline failures); 42 passed, 0 failed underVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): clean.cargo xtask policy: 191 files ok (lower.rs= 521,509 B);rustfmt --edition 2024: clean on changed hunks.Synthetic tests only; no game data used.
@Aniseto on GitHub · 2026-11-26 22:01 UTC · original
Ran the unaligned-atomic test at
a38641bon an NVIDIA Blackwell desktop part:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env), debug build.The one matching test is
emit::stride_tests::unaligned_buffer_atomics_are_dropped_and_return_zero; it passes here. It is a translation/reference test and does not issue a real unaligned D3D12 atomic on the adapter. The PR has no comments yet, so this is the first datapoint in the thread.Not tested: real unaligned
buffer_atomic*dispatches on hardware, 64-bit_x2atomics, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
@Jackster on GitHub · 2026-11-26 22:32 UTC · original
AMD check at
a38641bwith a red baseline on63bcca4, on an RX 7900 XTX (RDNA3, driver 32.0.32029.2010, Windows 11):cargo test -p victory-shader --lib unaligned_buffer_atomics— 1 passed, with nono SM 6.6 …; skippedline, so both hardware and WARP ran.63bcca4with onlystride_tests.rsfrom this head: the same test fails on the card — the misaligned buffer atomic is applied (14where the fixture expects7), so the guard is doing its job.Synthetic shaders only, no game files. AI-assisted.
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.