Shaders: drop unaligned 32-bit buffer atomics #3389

Open
Moon0755 wants to merge 1 commit from upstream-pr/3389 into main
Moon0755 commented 2026-11-26 21:26:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-26T21:26:30Z.


On RDNA2 (gfx1036, measured natively in wave32 and wave64 in Leonida docs/design.md), 32-bit buffer_atomic* enforces natural dword alignment ((addr & 3) == 0), including under OOB_SELECT = 2. An unaligned atomic leaves memory untouched, returns 0 to active glc lanes, and preserves vdst/vdata on 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,509 bytes / +946 vs main, 2,779 bytes below the 524,288 limit):
    • Compute natural-alignment guard (addr & 3) == 0 combined with the lane guard before entering begin_guarded, checking row + off on structured buffers, lo + off before raw_view on title memory (so dropped unaligned atomics do not mark title-memory pages dirty), and returned off (including root_view_offset) on raw/root views.
    • Return 0 through end_guarded for active unaligned glc lanes and preserve inactive lanes via self.write(inst, Reg::V(reg), r, guard).
    • Note: 64-bit buffer_atomic*_x2 ops are not yet lowered on main, and low base bits of heap-loaded V# descriptors remain a broader view-metadata limitation.
  • crates/victory-shader/src/emit/stride_tests.rs:
    • Added unaligned_buffer_atomics_are_dropped_and_return_zero.

Verification

— Devin & Neon

<!-- greyfinch-sync:Marvisak/VIctory:issue:5517353524 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3389). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-26T21:26:30Z. --- On RDNA2 (`gfx1036`, measured natively in wave32 and wave64 in Leonida `docs/design.md`), 32-bit `buffer_atomic*` enforces natural dword alignment (`(addr & 3) == 0`), including under `OOB_SELECT = 2`. An unaligned atomic leaves memory untouched, returns `0` to active `glc` lanes, and preserves `vdst`/`vdata` on 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,509` bytes / `+946` vs `main`, `2,779` bytes below the `524,288` limit): - Compute natural-alignment guard `(addr & 3) == 0` combined with the lane guard before entering `begin_guarded`, checking `row + off` on structured buffers, `lo + off` before `raw_view` on title memory (so dropped unaligned atomics do not mark title-memory pages dirty), and returned `off` (including `root_view_offset`) on raw/root views. - Return `0` through `end_guarded` for active unaligned `glc` lanes and preserve inactive lanes via `self.write(inst, Reg::V(reg), r, guard)`. - Note: 64-bit `buffer_atomic*_x2` ops are not yet lowered on `main`, and low base bits of heap-loaded V# descriptors remain a broader view-metadata limitation. - **`crates/victory-shader/src/emit/stride_tests.rs`**: - Added `unaligned_buffer_atomics_are_dropped_and_return_zero`. ### Verification - **Fork CI control** (test only on `main`): https://github.com/Moon0755/VIctory/actions/runs/45893611204 (`failure` — 302 passed, 1 failed solely on `unaligned_buffer_atomics_are_dropped_and_return_zero`, writing `[0, 14, ...]` and returning `7`) - **Fork CI fix** (`a38641b`): https://github.com/Moon0755/VIctory/actions/runs/45897727776 (`success` — 303 passed / 0 failed, Clippy + diagnostics Clippy clean, `policy::tests::repository_passes_policy ... ok`) - **Local 3-host verification**: `WARP`, `AMD Radeon(TM) Graphics`, and `NVIDIA GeForce RTX 2060 with Max-Q Design` — all fail without the fix and pass on `a38641b`. — Devin & Neon
fuzeofficlal commented 2026-11-26 21:38:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T21:38:59Z.

Review: APPROVED


LGTM — verified against origin/main (63bcca43) on Windows x64 (RTX 5090 + dxil.dll and WARP).

  • Guarding all supported 32-bit buffer_atomic_* ops (including cmpswap) 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, returning 0 on active glc = 1 lanes while self.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 reloads v2 = 7 before the misaligned glc add and confirms both memory preservation (7) and the 0 return on hardware and WARP.
  • Pre-existing non-blocking notes: Table/heap descriptors without a tracked guest base check the view-relative offset's low bits, and structured atomics with an aligned out-of-record byte offset (off >= stride) still rely on host structured bounds behavior.
  • Checks:
    • cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests:: emit::lower::: 40 passed, 0 failed under VICTORY_WARP=0 (skipping the 2 baseline failures); 42 passed, 0 failed under VICTORY_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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6080746297 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3389#pullrequestreview-6080746297). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T21:38:59Z. **Review:** APPROVED --- LGTM — verified against `origin/main` (`63bcca43`) on Windows x64 (RTX 5090 + `dxil.dll` and WARP). - Guarding all supported 32-bit `buffer_atomic_*` ops (including `cmpswap`) 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, returning `0` on active `glc = 1` lanes while `self.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 reloads `v2 = 7` before the misaligned `glc` add and confirms both memory preservation (`7`) and the `0` return on hardware and WARP. - **Pre-existing non-blocking notes**: Table/heap descriptors without a tracked guest base check the view-relative offset's low bits, and structured atomics with an aligned out-of-record byte offset (`off >= stride`) still rely on host structured bounds behavior. - **Checks**: - `cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests:: emit::lower::`: 40 passed, 0 failed under `VICTORY_WARP=0` (skipping the 2 baseline failures); 42 passed, 0 failed under `VICTORY_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 commented 2026-11-26 22:01:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Aniseto on 2026-11-26T22:01:22Z.


Ran the unaligned-atomic test at a38641b on 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.

cargo test -p victory-shader --lib unaligned_buffer_atomics -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out      (exit 0)

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 _x2 atomics, 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204281280 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3389#issuecomment-7204281280). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-26T22:01:22Z. --- Ran the unaligned-atomic test at `a38641b` on 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. ``` cargo test -p victory-shader --lib unaligned_buffer_atomics -- --test-threads=1 1 passed; 0 failed; 0 ignored; 0 measured; 305 filtered out (exit 0) ``` 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 `_x2` atomics, 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 commented 2026-11-26 22:32:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:32:21Z.


AMD check at a38641b with a red baseline on 63bcca4, on an RX 7900 XTX (RDNA3, driver 32.0.32029.2010, Windows 11):

  • Head: cargo test -p victory-shader --lib unaligned_buffer_atomics — 1 passed, with no no SM 6.6 …; skipped line, so both hardware and WARP ran.
  • Control on 63bcca4 with only stride_tests.rs from this head: the same test fails on the card — the misaligned buffer atomic is applied (14 where the fixture expects 7), so the guard is doing its job.

Synthetic shaders only, no game files. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7204768227 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3389#issuecomment-7204768227). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:32:21Z. --- AMD check at `a38641b` with a red baseline on `63bcca4`, on an RX 7900 XTX (RDNA3, driver 32.0.32029.2010, Windows 11): - Head: `cargo test -p victory-shader --lib unaligned_buffer_atomics` — 1 passed, with no `no SM 6.6 …; skipped` line, so both hardware and WARP ran. - Control on `63bcca4` with only `stride_tests.rs` from this head: the same test fails on the card — the misaligned buffer atomic is applied (`14` where the fixture expects `7`), so the guard is doing its job. Synthetic shaders only, no game files. AI-assisted.
Dukestar69 commented 2026-11-27 01:30:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T01:30:14Z.

Review: APPROVED


LGTM — verified on Windows (RTX 5090 + WARP):

  • Guarding structured and raw buffer 32-bit atomics with 4-byte alignment (including full title address alignment for root views) and returning zero on unaligned active GLC lanes is clean and consistent
  • cargo test -p victory-shader --lib unaligned_buffer_atomics_are_dropped_and_return_zero passed on RTX 5090 and under VICTORY_WARP=1
  • cargo clippy -p victory-shader --all-targets -- -D warnings passed with 0 warnings
  • cargo xtask policy passed (191 files ok)

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6082287513 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3389#pullrequestreview-6082287513). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-27T01:30:14Z. **Review:** APPROVED --- LGTM — verified on Windows (RTX 5090 + WARP): - Guarding structured and raw buffer 32-bit atomics with 4-byte alignment (including full title address alignment for root views) and returning zero on unaligned active GLC lanes is clean and consistent - `cargo test -p victory-shader --lib unaligned_buffer_atomics_are_dropped_and_return_zero` passed on RTX 5090 and under `VICTORY_WARP=1` - `cargo clippy -p victory-shader --all-targets -- -D warnings` passed with 0 warnings - `cargo xtask policy` passed (`191 files ok`) Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3389:upstream-pr/3389'
git switch 'upstream-pr/3389'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3389'
git switch 'upstream-pr/3389'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3389'
git switch 'upstream-pr/3389'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3389'
git switch 'main'
git merge --squash 'upstream-pr/3389'
git switch 'main'
git merge --ff-only 'upstream-pr/3389'
git switch 'main'
git merge 'upstream-pr/3389'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3389
No description provided.