Shaders: split 16-bit raw buffer stores across dword boundaries #3576

Open
github-bot wants to merge 1 commit from github-bot/gh-3576 into main AGit
Owner

@⁠Moon0755 on GitHub · 2026-11-27 18:58 UTC · original
Moon0755:fix/buffer-short-store-straddle → main · +102 −12 · 2 files · 1 commits · open

On RDNA2, buffer_store_short stores the low 16 bits byte-addressably across dword boundaries: at byte offset 3 mod 4, the low byte lands in byte 3 of the current dword and the high byte lands in byte 0 of the next dword (at_base + 4). On main, Lower::buffer only wrote the enclosing dword (// shortcut: the field is taken not to cross a dword.), silently dropping the high byte.

Changes

  • crates/victory-shader/src/emit/lower.rs (Lower::buffer, 521,778 bytes / +1,215 vs main, 2,510 bytes below the 524,288 limit):
    • Share a local write_field clear/set atomic helper across both writes; for width == 16 at byte == 3, write byte 0 of at_base + 4 guarded by no_wrap = IUGT(at_base + 4, at_base) so an out-of-bounds offset at u32::MAX cannot wrap back to dword 0.
    • Note: touches the sub-dword store path alongside #2208 (CAS loop) — happy to rebase once #2208 lands.
  • crates/victory-shader/src/emit/valu_tests.rs:
    • Added short_store_at_byte_three_writes_both_dwords and short_store_at_u32_max_does_not_wrap_to_dword_zero (encodings verified with llvm-mc -triple=amdgcn -mcpu=gfx1013 -disassemble, LLVM 23.1.5).

Verification

  • Fork CI control (tests only on main): https://github.com/Moon0755/VIctory/actions/runs/46052583913 (failure — 303 passed, 1 failed solely on short_store_at_byte_three_writes_both_dwords)
  • Fork CI fix (gemini/ci-buffer-short-store-straddle, 813c866): https://github.com/Moon0755/VIctory/actions/runs/46052578194 (success — full workspace CI + both Clippy builds clean)
  • Local verification (813c866): short_store_at_ (2/2, hardware + WARP), both Clippy configs, and cargo xtask policy (191 files ok) clean.
  • Not tested: indexed (idxen) byte/half stores, all-or-nothing OOB when a 16-bit store starts at view_size - 1, interaction with CAS-loop #2208, dxil.dll 1.7, game files. Synthetic tests only (AI-assisted).

— Devin & Neon

**@⁠Moon0755** on GitHub · 2026-11-27 18:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3576) `Moon0755:fix/buffer-short-store-straddle` → `main` · +102 −12 · 2 files · 1 commits · open On RDNA2, `buffer_store_short` stores the low 16 bits byte-addressably across dword boundaries: at byte offset `3 mod 4`, the low byte lands in byte `3` of the current dword and the high byte lands in byte `0` of the next dword (`at_base + 4`). On `main`, `Lower::buffer` only wrote the enclosing dword (`// shortcut: the field is taken not to cross a dword.`), silently dropping the high byte. ### Changes - **`crates/victory-shader/src/emit/lower.rs`** (`Lower::buffer`, `521,778` bytes / `+1,215` vs `main`, `2,510` bytes below the `524,288` limit): - Share a local `write_field` clear/set atomic helper across both writes; for `width == 16` at `byte == 3`, write byte `0` of `at_base + 4` guarded by `no_wrap = IUGT(at_base + 4, at_base)` so an out-of-bounds offset at `u32::MAX` cannot wrap back to dword `0`. - Note: touches the sub-dword store path alongside `#2208` (CAS loop) — happy to rebase once `#2208` lands. - **`crates/victory-shader/src/emit/valu_tests.rs`**: - Added `short_store_at_byte_three_writes_both_dwords` and `short_store_at_u32_max_does_not_wrap_to_dword_zero` (encodings verified with `llvm-mc -triple=amdgcn -mcpu=gfx1013 -disassemble`, LLVM `23.1.5`). ### Verification - **Fork CI control** (tests only on `main`): https://github.com/Moon0755/VIctory/actions/runs/46052583913 (`failure` — 303 passed, 1 failed solely on `short_store_at_byte_three_writes_both_dwords`) - **Fork CI fix** (`gemini/ci-buffer-short-store-straddle`, `813c866`): https://github.com/Moon0755/VIctory/actions/runs/46052578194 (`success` — full workspace CI + both Clippy builds clean) - **Local verification** (`813c866`): `short_store_at_` (`2/2`, hardware + WARP), both Clippy configs, and `cargo xtask policy` (`191 files ok`) clean. - **Not tested**: indexed (`idxen`) byte/half stores, all-or-nothing OOB when a 16-bit store starts at `view_size - 1`, interaction with CAS-loop `#2208`, `dxil.dll` 1.7, game files. Synthetic tests only (AI-assisted). — Devin & Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:00:57 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 19:29 UTC · original

Verification of #3576 (head 813c866365), independent, WARP only.

Environment: Windows 11 Pro 10.0.26200, WARP d3d10warp.dll 10.0.26100.9818 (VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, no physical GPU used), dxil.dll 1.8.2502.11 (SDK 10.0.26100.0), rustc 1.98.1. Base origin/main 63bcca43c6.
Command: cargo test -p victory-shader --lib --locked -j 4 -- --test-threads=1.
Baseline: on base, 298 passed / 4 failed / 3 ignored. The 4 failures are WARP lane-emulation tests in synthetic_tests (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out). They fail identically on base, each head and the merge, so they are not caused by either PR.

  • Control: base plus only this PR's valu_tests.rs hunk: short_store_at_byte_three_writes_both_dwords FAILS on base (dword 1 stays 0, want 0xA5) as claimed. short_store_at_u32_max_does_not_wrap_to_dword_zero passes on base, since the wrap only exists with the new second write, so it is a regression guard, not a fail-before test.
  • Head: 300 passed / 4 failed (the same 4) / 3 ignored; both new tests pass.
  • Merge of #3572 + #3576 onto base: merges cleanly; 301 passed / 4 failed (same 4) / 3 ignored. Merged lower.rs is 522,289 bytes (limit 524,288). Standalone lower.rs: 521,778.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean (not the whole workspace).
  • Review of Lower::buffer: the low half goes through the same two-atomic clear/set as before; the second write (byte 3, width 16 only) targets at_base + 4 for the high byte, guarded by guard && byte == 3 && next > at_base (unsigned), which correctly stops u32::MAX wrap; the second dword goes through raw_view with that guard, so OOB handling follows the existing path. The two dwords are separate atomics, so the pair is not atomic as a unit (another lane or thread can observe the low byte updated first); each dword is updated atomically with other lanes' fields preserved, and this matches the previous per-dword guarantee. No wave-size dependence. Duplicated lanes writing the same address are not specially ordered, same as before.
  • Textual overlap with #2208 (head 7bad309bbf): YES, they conflict in crates/victory-shader/src/emit/lower.rs (same buffer-store block; git merge-tree and a real merge both report a content conflict). #3572 does not conflict with #2208. Whichever lands second needs a rebase; if #2208's CAS loop lands first, the cross-dword split here must be redone on top of it.

Verdict: no defect found. AI use: this check was run by Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-27 19:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3576#issuecomment-7226582045) **Verification of #3576** (head 813c866365343f397bce7d56f2846501408f622c), independent, WARP only. Environment: Windows 11 Pro 10.0.26200, WARP d3d10warp.dll 10.0.26100.9818 (VICTORY_WARP=1 and VICTORY_D3D12_WARP=1, no physical GPU used), dxil.dll 1.8.2502.11 (SDK 10.0.26100.0), rustc 1.98.1. Base origin/main 63bcca43c6a00a758510398fa43096ce7e4f7df0. Command: `cargo test -p victory-shader --lib --locked -j 4 -- --test-threads=1`. Baseline: on base, 298 passed / 4 failed / 3 ignored. The 4 failures are WARP lane-emulation tests in `synthetic_tests` (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out). They fail identically on base, each head and the merge, so they are not caused by either PR. - Control: base plus only this PR's `valu_tests.rs` hunk: `short_store_at_byte_three_writes_both_dwords` FAILS on base (dword 1 stays 0, want 0xA5) as claimed. `short_store_at_u32_max_does_not_wrap_to_dword_zero` passes on base, since the wrap only exists with the new second write, so it is a regression guard, not a fail-before test. - Head: 300 passed / 4 failed (the same 4) / 3 ignored; both new tests pass. - Merge of #3572 + #3576 onto base: merges cleanly; 301 passed / 4 failed (same 4) / 3 ignored. Merged lower.rs is 522,289 bytes (limit 524,288). Standalone lower.rs: 521,778. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean (not the whole workspace). - Review of `Lower::buffer`: the low half goes through the same two-atomic clear/set as before; the second write (byte 3, width 16 only) targets `at_base + 4` for the high byte, guarded by `guard && byte == 3 && next > at_base` (unsigned), which correctly stops u32::MAX wrap; the second dword goes through `raw_view` with that guard, so OOB handling follows the existing path. The two dwords are separate atomics, so the pair is not atomic as a unit (another lane or thread can observe the low byte updated first); each dword is updated atomically with other lanes' fields preserved, and this matches the previous per-dword guarantee. No wave-size dependence. Duplicated lanes writing the same address are not specially ordered, same as before. - Textual overlap with #2208 (head 7bad309bbfd9794bc7614be5f8ee499b2de02dcd): YES, they conflict in `crates/victory-shader/src/emit/lower.rs` (same buffer-store block; git merge-tree and a real merge both report a content conflict). #3572 does not conflict with #2208. Whichever lands second needs a rebase; if #2208's CAS loop lands first, the cross-dword split here must be redone on top of it. Verdict: no defect found. AI use: this check was run by Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 19:37 UTC · original

Hardware run, head 813c866: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1.

  • short_store_at_byte_three_writes_both_dwords, short_store_at_u32_max_does_not_wrap_to_dword_zero: 2 passed, 0/5 failures over 5 runs.
  • cargo test -p victory-shader on the 780M: 304 passed, 0 failed.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 19:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3576#issuecomment-7226705445) Hardware run, head 813c866: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1. - `short_store_at_byte_three_writes_both_dwords`, `short_store_at_u32_max_does_not_wrap_to_dword_zero`: 2 passed, 0/5 failures over 5 runs. - `cargo test -p victory-shader` on the 780M: 304 passed, 0 failed. AI-assisted (Claude).
Author
Owner

@⁠pickles976 on GitHub · 2026-11-27 19:43 UTC · original

Matched hardware verification: head 813c866365343f397bce7d56f2846501408f622c versus parent 63bcca43c6a00a758510398fa43096ce7e4f7df0, with identical test-only fixtures/helpers on both. Original instruction words and complete expected outputs retained; SDK DXIL validator and physical NVIDIA DXGI identity are mandatory, duplicate Wine-WARP leg removed. Production unchanged.

Consumer Parent Head
16-bit store 0xA5BE at byte 3 FAIL: [0xBE000000, 0] instead of [0xBE000000, 0xA5] PASS, both dwords exact
u32::MAX offset must not wrap into dword 0 PASS, sentinel 0x11223344 preserved PASS, sentinel preserved

One real NVIDIA dispatch and full UAV readback per fixture; two validated shaders / three checked output words per checkout. Parent 1 pass/1 fail (1.27 s), head 2 pass/0 fail (1.25 s); fresh intended-tree compilations on both. This directly reproduces the dropped high byte on this Wine/NVIDIA path and verifies the correction. It does not certify indexed addressing, an in-range store crossing a resource boundary, two-dword atomicity, #2208 interaction, original title shaders or gameplay.

Linux 6.17 / Wine 11 / RTX 4060 Laptop 8 GiB / NVIDIA 590.48.1; masking disabled. Diagnostic-relaxed-vtable vkd3d 2576c0b4adfae4a+, not stock certification. Existing guards unchanged; no title launch.

Evidence under .compat-runtime/logs/: verify-pr3576-parent-short-store-20261127T194050Z/, verify-pr3576-head-short-store-20261127T194058Z/. Local fixture changes retained as provenance; no source PR or assets published.

AI-assisted verification.

**@⁠pickles976** on GitHub · 2026-11-27 19:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3576#issuecomment-7226816754) Matched hardware verification: head `813c866365343f397bce7d56f2846501408f622c` versus parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`, with identical test-only fixtures/helpers on both. Original instruction words and complete expected outputs retained; SDK DXIL validator and physical NVIDIA DXGI identity are mandatory, duplicate Wine-WARP leg removed. Production unchanged. | Consumer | Parent | Head | |---|---|---| | 16-bit store 0xA5BE at byte 3 | **FAIL**: `[0xBE000000, 0]` instead of `[0xBE000000, 0xA5]` | **PASS**, both dwords exact | | u32::MAX offset must not wrap into dword 0 | **PASS**, sentinel 0x11223344 preserved | **PASS**, sentinel preserved | One real NVIDIA dispatch and full UAV readback per fixture; two validated shaders / three checked output words per checkout. Parent 1 pass/1 fail (1.27 s), head 2 pass/0 fail (1.25 s); fresh intended-tree compilations on both. This directly reproduces the dropped high byte on this Wine/NVIDIA path and verifies the correction. It does not certify indexed addressing, an in-range store crossing a resource boundary, two-dword atomicity, #2208 interaction, original title shaders or gameplay. Linux 6.17 / Wine 11 / RTX 4060 Laptop 8 GiB / NVIDIA 590.48.1; masking disabled. Diagnostic-relaxed-vtable vkd3d `2576c0b4adfae4a+`, not stock certification. Existing guards unchanged; no title launch. Evidence under `.compat-runtime/logs/`: `verify-pr3576-parent-short-store-20261127T194050Z/`, `verify-pr3576-head-short-store-20261127T194058Z/`. Local fixture changes retained as provenance; no source PR or assets published. AI-assisted verification.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 19:58 UTC · original

Before/after on the same 780M: with this PR's test file on main 63bcca4, short_store_at_byte_three_writes_both_dwords fails on hardware ([0xBE000000, 0], want [0xBE000000, 0xA5]) and short_store_at_u32_max_does_not_wrap_to_dword_zero passes, the same split pickles976 saw on NVIDIA; with the PR both pass (0/5 failures above).

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 19:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3576#issuecomment-7227045858) Before/after on the same 780M: with this PR's test file on main 63bcca4, `short_store_at_byte_three_writes_both_dwords` fails on hardware (`[0xBE000000, 0]`, want `[0xBE000000, 0xA5]`) and `short_store_at_u32_max_does_not_wrap_to_dword_zero` passes, the same split pickles976 saw on NVIDIA; with the PR both pass (0/5 failures above). AI-assisted (Claude).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3576/head:github-bot/gh-3576'
git switch 'github-bot/gh-3576'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3576'
git switch 'github-bot/gh-3576'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3576'
git switch 'github-bot/gh-3576'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3576'
git switch 'main'
git merge --squash 'github-bot/gh-3576'
git switch 'main'
git merge --ff-only 'github-bot/gh-3576'
git switch 'main'
git merge 'github-bot/gh-3576'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3576
No description provided.