Shaders: lower partial-channel typed and indexed sub-dword buffer stores #3377

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

@⁠Texbirds on GitHub · 2026-11-26 20:58 UTC · original
Texbirds:feat/shader-buffer-stores-partial-and-indexed → main · +969 −49 · 5 files · 1 commits · open

Problem

In crates/victory-shader/src/emit/lower.rs (Lower::buffer), two common GFX10 MUBUF store families are currently refused at translation time even though the surrounding load/atomic/d16 paths already support them:

  1. Partial-channel typed buffer stores (buffer_store_format_{x,xy,xyz}, buffer_store_format_d16_{x,xy,xyz}, and buffer_store_format_d16_hi_x): Line 9675 refuses count != 4 ("a typed buffer store of some channels or at an offset") and line 9719 hardcodes write mask 0xF, rejecting shaders that write 1-, 2-, or 3-channel RWBuffer views (R32_FLOAT, R32G32_FLOAT, R16_UINT/R16_FLOAT, R16G16_UINT/R16G16_FLOAT, etc.).
  2. Indexed byte/half buffer stores (buffer_store_byte, buffer_store_short, and _d16_hi variants with idxen): Line 9600 refuses index.is_some() ("a byte or half buffer store by index"), even though buffer_atomic_* right above it already addresses structured UAVs via (index, off) with stride checked to be >= 4 and 4-byte aligned.

Change

  • In Lower::buffer (crates/victory-shader/src/emit/lower.rs):
    • Recognize store && (name.ends_with("_d16_hi") || name == "buffer_store_format_d16_hi_x") (hi16), shifting the source VGPR right by 16 bits for _d16_hi byte/short/typed stores (loads remain untouched).
    • For sub-dword stores (buffer_store_byte* / buffer_store_short*), support index = Some(index) on structured UAVs (stride >= 4 && stride.is_multiple_of(4)) using (index, at, undef) coordinates for the clear/set atomicBinOp.i32 pair and index * stride + at for mark_view_write, matching buffer_atomic_*. Raw index = None lowering is unchanged.
    • For typed buffer stores (buffer_store_format_*), relax count != 4 (still refusing *offen || *offset != 0), pad unused value channels count..4 with undef f32, and pass mask = (1u8 << count) - 1 (0x1/0x3/0x7/0xF) to dx.op.bufferStore.f32 (opcode 69). Existing d16 widening and integer_view handling already loop over 0..count.

Tests

All synthetic GFX10 compute shaders (no game data):

  • emit::lower::tests::partial_typed_and_indexed_subword_buffer_stores_lower_and_validate (cross-platform + dxil.dll validation on Windows): lowers and validates buffer_store_format_{x,xy,xyz}, buffer_store_format_d16_{x,xy,xyz}, buffer_store_format_d16_hi_x, and indexed buffer_store_{byte,short}{,_d16_hi} on a stride-8 structured UAV.
  • emit::stride_tests::partial_typed_buffer_stores_write_float_and_d16_views (Windows hardware GPU + WARP execution readback): dispatches translated shaders writing R32_FLOAT (format_x), R32G32_FLOAT (format_xy), R16G16_UINT/R16G16_FLOAT (format_d16_xy), and R16_UINT/R16_FLOAT (format_d16_x and format_d16_hi_x), asserting exact per-lane output bytes on both adapters.

Verification & scope

  • Not run locally (no Rust toolchain installed on this machine); relying on CI (check) for build, Clippy -D warnings, dxil.dll validation, and hardware/WARP execution tests.
  • Synthetic shaders only; no live title shader count is claimed.
**@⁠Texbirds** on GitHub · 2026-11-26 20:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377) `Texbirds:feat/shader-buffer-stores-partial-and-indexed` → `main` · +969 −49 · 5 files · 1 commits · open ### Problem In `crates/victory-shader/src/emit/lower.rs` (`Lower::buffer`), two common GFX10 MUBUF store families are currently refused at translation time even though the surrounding load/atomic/d16 paths already support them: 1. **Partial-channel typed buffer stores (`buffer_store_format_{x,xy,xyz}`, `buffer_store_format_d16_{x,xy,xyz}`, and `buffer_store_format_d16_hi_x`):** Line 9675 refuses `count != 4` (`"a typed buffer store of some channels or at an offset"`) and line 9719 hardcodes write mask `0xF`, rejecting shaders that write 1-, 2-, or 3-channel `RWBuffer` views (`R32_FLOAT`, `R32G32_FLOAT`, `R16_UINT`/`R16_FLOAT`, `R16G16_UINT`/`R16G16_FLOAT`, etc.). 2. **Indexed byte/half buffer stores (`buffer_store_byte`, `buffer_store_short`, and `_d16_hi` variants with `idxen`):** Line 9600 refuses `index.is_some()` (`"a byte or half buffer store by index"`), even though `buffer_atomic_*` right above it already addresses structured UAVs via `(index, off)` with `stride` checked to be `>= 4` and 4-byte aligned. ### Change - In `Lower::buffer` (`crates/victory-shader/src/emit/lower.rs`): - Recognize `store && (name.ends_with("_d16_hi") || name == "buffer_store_format_d16_hi_x")` (`hi16`), shifting the source VGPR right by 16 bits for `_d16_hi` byte/short/typed stores (loads remain untouched). - For sub-dword stores (`buffer_store_byte*` / `buffer_store_short*`), support `index = Some(index)` on structured UAVs (`stride >= 4 && stride.is_multiple_of(4)`) using `(index, at, undef)` coordinates for the clear/set `atomicBinOp.i32` pair and `index * stride + at` for `mark_view_write`, matching `buffer_atomic_*`. Raw `index = None` lowering is unchanged. - For typed buffer stores (`buffer_store_format_*`), relax `count != 4` (still refusing `*offen || *offset != 0`), pad unused value channels `count..4` with `undef f32`, and pass `mask = (1u8 << count) - 1` (`0x1`/`0x3`/`0x7`/`0xF`) to `dx.op.bufferStore.f32` (opcode 69). Existing `d16` widening and `integer_view` handling already loop over `0..count`. ### Tests All synthetic GFX10 compute shaders (no game data): - `emit::lower::tests::partial_typed_and_indexed_subword_buffer_stores_lower_and_validate` (cross-platform + `dxil.dll` validation on Windows): lowers and validates `buffer_store_format_{x,xy,xyz}`, `buffer_store_format_d16_{x,xy,xyz}`, `buffer_store_format_d16_hi_x`, and indexed `buffer_store_{byte,short}{,_d16_hi}` on a stride-8 structured UAV. - `emit::stride_tests::partial_typed_buffer_stores_write_float_and_d16_views` (Windows hardware GPU + WARP execution readback): dispatches translated shaders writing `R32_FLOAT` (`format_x`), `R32G32_FLOAT` (`format_xy`), `R16G16_UINT`/`R16G16_FLOAT` (`format_d16_xy`), and `R16_UINT`/`R16_FLOAT` (`format_d16_x` and `format_d16_hi_x`), asserting exact per-lane output bytes on both adapters. ### Verification & scope - Not run locally (no Rust toolchain installed on this machine); relying on CI (`check`) for build, Clippy `-D warnings`, `dxil.dll` validation, and hardware/WARP execution tests. - Synthetic shaders only; no live title shader count is claimed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:00:55 +00:00
github-bot force-pushed github-bot/gh-3377 from 3281a54df5 to 0a2027eb3e 2026-11-26 21:13:53 +00:00 Compare
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 21:09 UTC · original · reviewed

Tested on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

Tests and clippy pass cleanly:

  • cargo test -p victory-shader --lib emit::stride_tests::partial_typed_buffer_stores_write_float_and_d16_views -- --test-threads=1: passed on RTX 5090 and VICTORY_WARP=1.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

However, cargo xtask policy fails because crates/victory-shader/src/emit/lower.rs grows to 525,320 bytes (1,032 bytes over the 524,288-byte limit):

POLICY: crates/victory-shader/src/emit/lower.rs: 525320 bytes exceeds the 524288-byte limit
Error: 1 asset-policy violation(s). Nothing from the game may be committed; see docs/asset-policy.md

Moving the new store helper into a submodule under crates/victory-shader/src/emit/lower/ will bring lower.rs back under the 512 KiB cap.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 21:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6080499570) · **reviewed** Tested on RTX 5090 and `VICTORY_WARP=1` (Windows / D3D12) against `origin/main` (`63bcca4`). Tests and clippy pass cleanly: - `cargo test -p victory-shader --lib emit::stride_tests::partial_typed_buffer_stores_write_float_and_d16_views -- --test-threads=1`: passed on RTX 5090 and `VICTORY_WARP=1`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. However, `cargo xtask policy` fails because `crates/victory-shader/src/emit/lower.rs` grows to `525,320` bytes (`1,032` bytes over the `524,288`-byte limit): ``` POLICY: crates/victory-shader/src/emit/lower.rs: 525320 bytes exceeds the 524288-byte limit Error: 1 asset-policy violation(s). Nothing from the game may be committed; see docs/asset-policy.md ``` Moving the new store helper into a submodule under `crates/victory-shader/src/emit/lower/` will bring `lower.rs` back under the 512 KiB cap. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot force-pushed github-bot/gh-3377 from 0a2027eb3e to 0b0fde07c8 2026-11-27 01:10:22 +00:00 Compare
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 21:24 UTC · original · requested changes

Requesting changes after auditing 0a2027eb against origin/main (63bcca43) on Windows x64:

Blocking issues

  1. Asset policy failure (xtask policy):
    • crates/victory-shader/src/emit/lower.rs is 525,320 bytes, exceeding the 524,288-byte (512 KiB) limit enforced by cargo xtask policy (exit 1). Splitting helpers or tests out of lower.rs is needed to keep it under 512 KiB.
  2. [P1] Partial typed stores pad missing channels with 0.0 under write mask 0xF:
    • At crates/victory-shader/src/emit/lower.rs:9703-9710 and 9745, _x, _xy, _xyz, and _d16_* formatted stores pad omitted channels with 0.0 and emit DXIL bufferStore.f32 with mask 0xF. On any host view wider than count channels (e.g. a 1- or 2-channel store into an RGBA view), this zeros untouched channels rather than preserving them, and RDNA2 SRD DST_SEL routing is ignored.
  3. [P1] Formatted stores silently drop soffset / built_offset:
    • lower.rs:9444-9469 accumulates offset, soffset, and built_offset into off, but the typed branch at lower.rs:9695-9700 only rejects *offen || *offset != 0 and passes index.unwrap_or(0) to bufferStore.f32, silently discarding non-zero soffset on the newly enabled opcodes.
  4. [P1] Indexed structured sub-dword atomics lack record byte-offset bounds checking:
    • At lower.rs:9622-9648, index = Some(...) passes at = off & !3 straight to atomicBinOp.i32 without checking at < stride (or handling odd short offsets crossing a dword boundary). RDNA2 drops writes past the record stride, whereas in DXIL/SM 5.1 an out-of-range byte offset within a structured UAV has undefined behavior.

Additional notes

  • [P2] Using two separate atomicBinOp (AND then OR) operations (lower.rs:9641) rather than a CAS loop exposes a zeroed intermediate state and can combine overlapping sub-dword writes; indexed structured sub-dword stores also only have DXIL validation (lower.rs:12260-12286) with no runtime GPU/WARP readback test.
  • Checks:
    • cargo xtask policy: FAILED (crates/victory-shader/src/emit/lower.rs: 525320 bytes exceeds the 524288-byte limit).
    • cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests:: emit::lower::: 43 passed, 0 failed under VICTORY_WARP=1; 41 passed, 2 failed under VICTORY_WARP=0 (same 2 pre-existing baseline failures on 63bcca43; PR's new tests pass).
    • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): clean; rustfmt --edition 2024: clean on changed hunks.

Synthetic tests only; no game data used.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 21:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6080601751) · **requested changes** Requesting changes after auditing `0a2027eb` against `origin/main` (`63bcca43`) on Windows x64: ### Blocking issues 1. **Asset policy failure (`xtask policy`)**: - `crates/victory-shader/src/emit/lower.rs` is **525,320 bytes**, exceeding the **524,288-byte (512 KiB)** limit enforced by `cargo xtask policy` (`exit 1`). Splitting helpers or tests out of `lower.rs` is needed to keep it under 512 KiB. 2. **[P1] Partial typed stores pad missing channels with `0.0` under write mask `0xF`**: - At `crates/victory-shader/src/emit/lower.rs:9703-9710` and `9745`, `_x`, `_xy`, `_xyz`, and `_d16_*` formatted stores pad omitted channels with `0.0` and emit DXIL `bufferStore.f32` with mask `0xF`. On any host view wider than `count` channels (e.g. a 1- or 2-channel store into an RGBA view), this zeros untouched channels rather than preserving them, and RDNA2 SRD `DST_SEL` routing is ignored. 3. **[P1] Formatted stores silently drop `soffset` / `built_offset`**: - `lower.rs:9444-9469` accumulates `offset`, `soffset`, and `built_offset` into `off`, but the typed branch at `lower.rs:9695-9700` only rejects `*offen || *offset != 0` and passes `index.unwrap_or(0)` to `bufferStore.f32`, silently discarding non-zero `soffset` on the newly enabled opcodes. 4. **[P1] Indexed structured sub-dword atomics lack record byte-offset bounds checking**: - At `lower.rs:9622-9648`, `index = Some(...)` passes `at = off & !3` straight to `atomicBinOp.i32` without checking `at < stride` (or handling odd `short` offsets crossing a dword boundary). RDNA2 drops writes past the record stride, whereas in DXIL/SM 5.1 an out-of-range byte offset within a structured UAV has undefined behavior. ### Additional notes - **[P2]** Using two separate `atomicBinOp` (`AND` then `OR`) operations (`lower.rs:9641`) rather than a CAS loop exposes a zeroed intermediate state and can combine overlapping sub-dword writes; indexed structured sub-dword stores also only have DXIL validation (`lower.rs:12260-12286`) with no runtime GPU/WARP readback test. - **Checks**: - `cargo xtask policy`: **FAILED** (`crates/victory-shader/src/emit/lower.rs: 525320 bytes exceeds the 524288-byte limit`). - `cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests:: emit::lower::`: 43 passed, 0 failed under `VICTORY_WARP=1`; 41 passed, 2 failed under `VICTORY_WARP=0` (same 2 pre-existing baseline failures on `63bcca43`; PR's new tests pass). - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): clean; `rustfmt --edition 2024`: clean on changed hunks. Synthetic tests only; no game data used.
Author
Owner

@⁠evan-kolberg on GitHub · 2026-11-26 21:31 UTC · original

M4 Pro / CrossOver 26.3 / D3DMetal 4.0 beta 3 adds an independent hardware result for Texbirds’ exact 0a2027e. All eight authored typed-store cases passed. A new format_xy fixture matched both channels in 32/32 permuted odd RG32_FLOAT elements and preserved 32/32 untouched even elements. Exact #3377 head

A local typed-only Mac adaptation also passed the sparse check on RG32_FLOAT, RG32_UINT, and RG8_UNORM, using the Mac fork’s existing float/integer store split. The UINT case preserves values beyond FP32’s exact integer range. These cases use matching channel widths and zero effective offsets. The wider-view questions from fuzeofficlal and canonical file-size failure from Dukestar69 remain open. Format review · Policy review

Prepared and tested with Codex.

**@⁠evan-kolberg** on GitHub · 2026-11-26 21:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7203800860) M4 Pro / CrossOver 26.3 / D3DMetal 4.0 beta 3 adds an independent hardware result for Texbirds’ exact `0a2027e`. All eight authored typed-store cases passed. A new `format_xy` fixture matched both channels in **32/32 permuted odd RG32_FLOAT elements** and preserved **32/32 untouched even elements**. [Exact #3377 head](https://github.com/Texbirds/VIctory/commit/0a2027eb3ecdd5f99aaf30ef06f97fff91103ac9) A local typed-only Mac adaptation also passed the sparse check on **RG32_FLOAT, RG32_UINT, and RG8_UNORM**, using the Mac fork’s existing float/integer store split. The UINT case preserves values beyond FP32’s exact integer range. These cases use matching channel widths and zero effective offsets. The wider-view questions from fuzeofficlal and canonical file-size failure from Dukestar69 remain open. [Format review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3377) · [Policy review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3377) Prepared and tested with Codex.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-26 22:07 UTC · original

Thanks @⁠Dukestar69, @⁠fuzeofficlal, and @⁠evan-kolberg for the thorough testing and review! Pushed dc03d87 addressing all raised points, and CI / check is now passing:

  • cargo xtask policy (512 KiB cap on lower.rs): Moved the new lowering/validation unit tests into crates/victory-shader/src/emit/lower/buffer_store_tests.rs (alongside bvh.rs), bringing lower.rs down to 522,918 bytes.
  • Typed buffer stores with non-zero soffset / built_offset: Now rejected alongside *offen || *offset != 0, with a new unit test (typed_buffer_store_refuses_nonzero_soffset).
  • Structured sub-dword store bounds & alignment: Added an at < stride (IULT) guard into begin_guarded for indexed structured sub-dword stores so out-of-record writes are dropped cleanly like RDNA2 hardware, and rejected statically odd 16-bit offsets (half_buffer_store_refuses_static_odd_offset).
  • Runtime test coverage for indexed sub-dword stores: Added View::StructuredUav in emit/host.rs and indexed_subword_buffer_stores_write_structured_uav_and_drop_oob in stride_tests.rs covering buffer_store_{byte,short}{,_d16_hi}, untouched-byte preservation, and out-of-bounds offset >= stride drop on hardware + WARP.
  • Typed store 0xF mask / 0.0 padding: DXIL WRITEMASKFORTYPEDUAVSTORE / WRITEMASKMATCHVALUEFORUAVSTORE require mask 0xF and non-undef values, and on RDNA2 buffer_store_format_{x,xy,xyz} writes the full formatted element rather than performing a partial-channel RMW (hardware ignores channels past the view's format width).
  • Sub-dword AND+OR atomics: Kept consistent with the existing raw buffer_store_{byte,short} and ds_write_b{8,16} lowering in lower.rs.

Ready for re-review!

**@⁠Texbirds** on GitHub · 2026-11-26 22:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7204379686) Thanks @⁠Dukestar69, @⁠fuzeofficlal, and @⁠evan-kolberg for the thorough testing and review! Pushed `dc03d87` addressing all raised points, and `CI / check` is now passing: - **`cargo xtask policy` (512 KiB cap on `lower.rs`):** Moved the new lowering/validation unit tests into `crates/victory-shader/src/emit/lower/buffer_store_tests.rs` (alongside `bvh.rs`), bringing `lower.rs` down to 522,918 bytes. - **Typed buffer stores with non-zero `soffset` / `built_offset`:** Now rejected alongside `*offen || *offset != 0`, with a new unit test (`typed_buffer_store_refuses_nonzero_soffset`). - **Structured sub-dword store bounds & alignment:** Added an `at < stride` (`IULT`) guard into `begin_guarded` for indexed structured sub-dword stores so out-of-record writes are dropped cleanly like RDNA2 hardware, and rejected statically odd 16-bit offsets (`half_buffer_store_refuses_static_odd_offset`). - **Runtime test coverage for indexed sub-dword stores:** Added `View::StructuredUav` in `emit/host.rs` and `indexed_subword_buffer_stores_write_structured_uav_and_drop_oob` in `stride_tests.rs` covering `buffer_store_{byte,short}{,_d16_hi}`, untouched-byte preservation, and out-of-bounds `offset >= stride` drop on hardware + WARP. - **Typed store `0xF` mask / `0.0` padding:** DXIL `WRITEMASKFORTYPEDUAVSTORE` / `WRITEMASKMATCHVALUEFORUAVSTORE` require mask `0xF` and non-`undef` values, and on RDNA2 `buffer_store_format_{x,xy,xyz}` writes the full formatted element rather than performing a partial-channel RMW (hardware ignores channels past the view's format width). - **Sub-dword `AND`+`OR` atomics:** Kept consistent with the existing raw `buffer_store_{byte,short}` and `ds_write_b{8,16}` lowering in `lower.rs`. Ready for re-review!
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 22:20 UTC · original · requested changes

Thanks for bringing crates/victory-shader/src/emit/lower.rs under the 512 KiB limit (522,918 bytes), rejecting nonzero soffset on typed stores instead of dropping it, and adding the StructuredUav and buffer_store_tests coverage (verified cargo xtask policy: 192 files ok, clippy clean, and emit::lower:: emit::stride_tests:: 46/46 under VICTORY_WARP=1; under VICTORY_WARP=0 all new tests pass, 44/46 with the two pre-existing a_heap_buffer_read_* failures at stride_tests.rs:301, 351).

However, three blocking correctness issues remain before landing:

  1. Partial typed stores zero-fill remaining channels on wider destination views (crates/victory-shader/src/emit/lower.rs:9722-9728): Padding missing components with 0.0 (args.resize(3 + 4, zero)) for bufferStore.f32 mask 0xF overwrites untouched channels with zero whenever the bound typed UAV has more channels than the opcode (e.g. buffer_store_format_x/_xy on an RGBA format). All new cases in stride_tests.rs only bind 1- or 2-channel views matching the instruction width, so preservation of untouched channels in a multi-channel view is untested and broken.
  2. Indexed structured sub-dword bounds check includes soffset (crates/victory-shader/src/emit/lower.rs:9451, 9644): off already includes soffset, which RDNA2 applies as a base displacement outside the structured in-record offset < stride check. Testing at < stride against off & !3 drops valid writes when soffset advances across records (e.g. stride = 8, index = 0, offset = 0, soffset = 8).
  3. Dynamic odd halfword offsets silently truncate at dword boundaries (crates/victory-shader/src/emit/lower.rs:9605-9617): Only static constant offsets are checked for odd alignment; a runtime byte offset with off & 3 == 3 shifts by 24, writing only the low byte into byte 3 and discarding the upper byte.
  4. Formatting: rustfmt --edition 2024 --check flags new hunks in crates/victory-shader/src/emit/lower/buffer_store_tests.rs:34, 60, 86, 108, stride_tests.rs:998+, and host.rs:1362, 1711.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 22:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6081075849) · **requested changes** Thanks for bringing `crates/victory-shader/src/emit/lower.rs` under the 512 KiB limit (`522,918` bytes), rejecting nonzero `soffset` on typed stores instead of dropping it, and adding the `StructuredUav` and `buffer_store_tests` coverage (verified `cargo xtask policy`: `192 files ok`, `clippy` clean, and `emit::lower:: emit::stride_tests::` **46/46** under `VICTORY_WARP=1`; under `VICTORY_WARP=0` all new tests pass, **44/46** with the two pre-existing `a_heap_buffer_read_*` failures at `stride_tests.rs:301, 351`). However, three blocking correctness issues remain before landing: 1. **Partial typed stores zero-fill remaining channels on wider destination views (`crates/victory-shader/src/emit/lower.rs:9722-9728`)**: Padding missing components with `0.0` (`args.resize(3 + 4, zero)`) for `bufferStore.f32` mask `0xF` overwrites untouched channels with zero whenever the bound typed UAV has more channels than the opcode (e.g. `buffer_store_format_x`/`_xy` on an RGBA format). All new cases in `stride_tests.rs` only bind 1- or 2-channel views matching the instruction width, so preservation of untouched channels in a multi-channel view is untested and broken. 2. **Indexed structured sub-dword bounds check includes `soffset` (`crates/victory-shader/src/emit/lower.rs:9451, 9644`)**: `off` already includes `soffset`, which RDNA2 applies as a base displacement outside the structured in-record `offset < stride` check. Testing `at < stride` against `off & !3` drops valid writes when `soffset` advances across records (e.g. `stride = 8, index = 0, offset = 0, soffset = 8`). 3. **Dynamic odd halfword offsets silently truncate at dword boundaries (`crates/victory-shader/src/emit/lower.rs:9605-9617`)**: Only static constant offsets are checked for odd alignment; a runtime byte offset with `off & 3 == 3` shifts by `24`, writing only the low byte into byte 3 and discarding the upper byte. 4. **Formatting**: `rustfmt --edition 2024 --check` flags new hunks in `crates/victory-shader/src/emit/lower/buffer_store_tests.rs:34, 60, 86, 108`, `stride_tests.rs:998+`, and `host.rs:1362, 1711`.
Author
Owner

@⁠passerbyyhx on GitHub · 2026-11-26 22:33 UTC · original

Tested dc03d87173f4bc4be7540c0cdabd28b41676d380 on Windows D3D12 with an RTX 4090 Laptop GPU (621.14) and Microsoft WARP. One synthetic wave32 issued a single indexed byte-store instruction against a structured UAV with 12-byte records. In one case four lanes each wrote one byte of the same dword. In the other, two lanes wrote bytes 0 and 2 while bytes 1 and 3 retained their nonzero seeds.

Both adapters matched the entire readback buffer in all 8 dispatches per case, including the neighbouring dwords and guard records. The first modified word was 13121110 for the four-lane case and d411f610 for the two-lane case. The D3D12 debug InfoQueue reported zero errors and warning 1328 for the test harness's buffer initial state. The fixture uses synthetic data and covers the host D3D12 lowering.

Parent 63bcca43c6a00a758510398fa43096ce7e4f7df0 rejected both identical instruction streams at lowering with a byte or half buffer store by index.

Synthetic test fixture

AI-assisted with Codex.

**@⁠passerbyyhx** on GitHub · 2026-11-26 22:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7204778897) Tested `dc03d87173f4bc4be7540c0cdabd28b41676d380` on Windows D3D12 with an RTX 4090 Laptop GPU (621.14) and Microsoft WARP. One synthetic wave32 issued a single indexed byte-store instruction against a structured UAV with 12-byte records. In one case four lanes each wrote one byte of the same dword. In the other, two lanes wrote bytes 0 and 2 while bytes 1 and 3 retained their nonzero seeds. Both adapters matched the entire readback buffer in all 8 dispatches per case, including the neighbouring dwords and guard records. The first modified word was `13121110` for the four-lane case and `d411f610` for the two-lane case. The D3D12 debug InfoQueue reported zero errors and warning 1328 for the test harness's buffer initial state. The fixture uses synthetic data and covers the host D3D12 lowering. Parent `63bcca43c6a00a758510398fa43096ce7e4f7df0` rejected both identical instruction streams at lowering with `a byte or half buffer store by index`. [Synthetic test fixture](https://github.com/passerbyyhx/VIctory/commit/ad17733ef84e5c68f044bb84d605beb5daefdf3b) AI-assisted with Codex.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-26 22:45 UTC · original

Thanks @⁠fuzeofficlal for the detailed review catching those three edge cases, and thanks @⁠passerbyyhx for the independent RTX 4090 Laptop + WARP verification!

Pushed 5648e3e fixing all four items, and CI / check is now green:

  1. Preserving untouched channels on wider typed UAVs (lower.rs):

    • Replaced the 0.0f padding on partial typed stores (typed && count < 4) with a guarded dx.op.bufferLoad.f32 (setting flags::TYPED_UAV_LOADS) inside begin_guarded(guard), extracting channels count..4 from the existing element and passing them to bufferStore.f32 with DXIL write mask 0xF.
    • buffer_store_format_xyzw (count == 4) is unchanged (no load, no TYPED_UAV_LOADS flag).
    • Added hardware + WARP readback test emit::stride_tests::partial_typed_buffer_stores_preserve_untouched_rgba_channels initializing an R32G32B32A32_FLOAT UAV with non-zero RGBA values and verifying format_x and format_xy preserve untouched channels bit-exact.
  2. Structured sub-dword bounds check excluding soffset (lower.rs, lower/buffer_store.rs):

    • Captured record_off (voffset + inst_offset) before adding soffset and descriptor-built base offsets, and perform the RDNA2 in-record check (record_off & !3) < stride on record_off only.
    • When soffset or a built base offset is present (has_base_off), total dword offset at = off & !3 is folded into structured UAV coordinates via eff_idx = index + (at / stride) (UDiv) and eff_at = at % stride (URem), so cross-record soffset (e.g. stride = 8, index = 0, offset = 0, soffset = 8) targets record 1 byte 0 instead of being dropped. No UDiv/URem is emitted when has_base_off is false.
  3. Dynamic (and static) straddling halfword stores at off & 3 == 3 (lower/buffer_store.rs):

    • For width == 16 whenever the byte offset may land at off & 3 == 3 (*offen || has_base_off || (offset & 3) == 3), emitted a second guarded clear+set atomicBinOp.i32 pair on at + 4 when byte == 3, writing (raw_val >> 8) & 0xFF into byte 0 of the next dword while leaving bytes 1..3 intact (for raw UAVs via raw_view so 64 KiB page crossings are handled too; for structured UAVs guarded by record_off < stride - 1 to avoid wrap-around on 0xFFFF_FFFF and drop byte 1 if record_off == stride - 1).
    • Static aligned halfword offsets emit no extra instructions.
    • Added emit::lower::buffer_store_tests::straddling_half_and_soffset_structured_stores_lower_and_validate and hardware + WARP readback test emit::stride_tests::indexed_subword_buffer_stores_handle_soffset_and_straddling_half.
  4. Formatting & file-size headroom:

    • Extracted sub-dword lowering into crates/victory-shader/src/emit/lower/buffer_store.rs, bringing lower.rs down to 520,719 bytes.
    • Cleaned up formatting across host.rs, buffer_store_tests.rs, and stride_tests.rs for rustfmt --edition 2024 --check (max_width = 100).

Ready for re-review!

**@⁠Texbirds** on GitHub · 2026-11-26 22:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7204962219) Thanks @⁠fuzeofficlal for the detailed review catching those three edge cases, and thanks @⁠passerbyyhx for the independent RTX 4090 Laptop + WARP verification! Pushed `5648e3e` fixing all four items, and `CI / check` is now green: 1. **Preserving untouched channels on wider typed UAVs (`lower.rs`):** - Replaced the `0.0f` padding on partial typed stores (`typed && count < 4`) with a guarded `dx.op.bufferLoad.f32` (setting `flags::TYPED_UAV_LOADS`) inside `begin_guarded(guard)`, extracting channels `count..4` from the existing element and passing them to `bufferStore.f32` with DXIL write mask `0xF`. - `buffer_store_format_xyzw` (`count == 4`) is unchanged (no load, no `TYPED_UAV_LOADS` flag). - Added hardware + WARP readback test `emit::stride_tests::partial_typed_buffer_stores_preserve_untouched_rgba_channels` initializing an `R32G32B32A32_FLOAT` UAV with non-zero RGBA values and verifying `format_x` and `format_xy` preserve untouched channels bit-exact. 2. **Structured sub-dword bounds check excluding `soffset` (`lower.rs`, `lower/buffer_store.rs`):** - Captured `record_off` (`voffset + inst_offset`) before adding `soffset` and descriptor-built base offsets, and perform the RDNA2 in-record check `(record_off & !3) < stride` on `record_off` only. - When `soffset` or a built base offset is present (`has_base_off`), total dword offset `at = off & !3` is folded into structured UAV coordinates via `eff_idx = index + (at / stride)` (`UDiv`) and `eff_at = at % stride` (`URem`), so cross-record `soffset` (e.g. `stride = 8, index = 0, offset = 0, soffset = 8`) targets record 1 byte 0 instead of being dropped. No `UDiv`/`URem` is emitted when `has_base_off` is false. 3. **Dynamic (and static) straddling halfword stores at `off & 3 == 3` (`lower/buffer_store.rs`):** - For `width == 16` whenever the byte offset may land at `off & 3 == 3` (`*offen || has_base_off || (offset & 3) == 3`), emitted a second guarded clear+set `atomicBinOp.i32` pair on `at + 4` when `byte == 3`, writing `(raw_val >> 8) & 0xFF` into byte 0 of the next dword while leaving bytes 1..3 intact (for raw UAVs via `raw_view` so 64 KiB page crossings are handled too; for structured UAVs guarded by `record_off < stride - 1` to avoid wrap-around on `0xFFFF_FFFF` and drop byte 1 if `record_off == stride - 1`). - Static aligned halfword offsets emit no extra instructions. - Added `emit::lower::buffer_store_tests::straddling_half_and_soffset_structured_stores_lower_and_validate` and hardware + WARP readback test `emit::stride_tests::indexed_subword_buffer_stores_handle_soffset_and_straddling_half`. 4. **Formatting & file-size headroom:** - Extracted sub-dword lowering into `crates/victory-shader/src/emit/lower/buffer_store.rs`, bringing `lower.rs` down to **520,719 bytes**. - Cleaned up formatting across `host.rs`, `buffer_store_tests.rs`, and `stride_tests.rs` for `rustfmt --edition 2024 --check` (`max_width = 100`). Ready for re-review!
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 23:04 UTC · original · requested changes

Splitting buffer_store.rs brings lower.rs safely below the 512 KiB limit (520,719 bytes), cargo xtask policy and cargo clippy pass, and all new buffer_store_tests and stride_tests pass on both RTX 5090 and WARP (the two a_heap_buffer_read_* failures on RTX 5090 also fail identically on base 63bcca43 and are pre-existing).

Several blockers still need fixing before merge:

  1. rustfmt --edition 2024 --check still fails on PR-modified lines:
    • crates/victory-shader/src/emit/lower.rs:21 (mod buffer_store_tests; belongs alphabetically before mod bvh;),
    • crates/victory-shader/src/emit/lower/buffer_store.rs:138, host.rs (1350, 1362), and stride_tests.rs (672, 699, 785, 812, 821, 828, 837, 848, 862, 893, 901, 1036, 1122).
  2. P1 — Built root-view index folding misses may_cross_dword (crates/victory-shader/src/emit/lower.rs:9479-9491, 9609-9610):
    When a Source::Built root view folds ix * stride into off and sets index = None, may_cross_dword only checks *offen || has_base_off || (u32::from(*offset) & 3) == 3. For idxen with a non-dword-multiple stride (e.g., stride = 1, ix = 3), may_cross_dword stays false and a halfword store at off & 3 == 3 silently drops its upper byte.
  3. P1 — 32-bit offset wraparound and unaligned soffset bounds bypass (crates/victory-shader/src/emit/lower/buffer_store.rs:43, 70, 104, 111):
    • On st.off = 0xFFFF_FFFF (at = 0xFFFF_FFFC), at2 = at + 4 wraps in i32 to 0, writing the upper byte to byte 0 (and similarly on structured record_off = 3, soffset = 0xFFFF_FFFC).
    • On a structured buffer with stride = 8, record_off = 7, soffset = 1, st.off = 8 yields byte == 0, so only the first atomic pair runs and checks (record_off & !3) < stride (4 < 8), writing the out-of-record upper byte into the next record instead of clamping it.
  4. P1 (non-trivial) — Partial typed bufferLoad.f32 / bufferStore.f32 RMW on integer UAVs & cross-lane races (lower.rs:9634, 9720-9737):
    count < 4 uses a float-typed (0x409) bufferLoad.f32 + 0xF bufferStore.f32 RMW even on integer views, and two lanes writing disjoint partial channels of the same element can overwrite each other's untouched channels. (Non-blocking P2: mark_view_write(..., 16, None) at lower.rs:9685 still marks 16 bytes on narrower typed formats, and has_base_off treats an soffset SGPR holding 0 as an offset.)
**@⁠fuzeofficlal** on GitHub · 2026-11-26 23:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6081334905) · **requested changes** Splitting `buffer_store.rs` brings `lower.rs` safely below the 512 KiB limit (`520,719` bytes), `cargo xtask policy` and `cargo clippy` pass, and all new `buffer_store_tests` and `stride_tests` pass on both RTX 5090 and WARP (the two `a_heap_buffer_read_*` failures on RTX 5090 also fail identically on base `63bcca43` and are pre-existing). Several blockers still need fixing before merge: 1. **`rustfmt --edition 2024 --check` still fails on PR-modified lines:** - `crates/victory-shader/src/emit/lower.rs:21` (`mod buffer_store_tests;` belongs alphabetically before `mod bvh;`), - `crates/victory-shader/src/emit/lower/buffer_store.rs:138`, `host.rs` (`1350, 1362`), and `stride_tests.rs` (`672, 699, 785, 812, 821, 828, 837, 848, 862, 893, 901, 1036, 1122`). 2. **P1 — Built root-view index folding misses `may_cross_dword` (`crates/victory-shader/src/emit/lower.rs:9479-9491, 9609-9610`):** When a `Source::Built` root view folds `ix * stride` into `off` and sets `index = None`, `may_cross_dword` only checks `*offen || has_base_off || (u32::from(*offset) & 3) == 3`. For `idxen` with a non-dword-multiple stride (e.g., `stride = 1, ix = 3`), `may_cross_dword` stays `false` and a halfword store at `off & 3 == 3` silently drops its upper byte. 3. **P1 — 32-bit offset wraparound and unaligned `soffset` bounds bypass (`crates/victory-shader/src/emit/lower/buffer_store.rs:43, 70, 104, 111`):** - On `st.off = 0xFFFF_FFFF` (`at = 0xFFFF_FFFC`), `at2 = at + 4` wraps in `i32` to `0`, writing the upper byte to byte `0` (and similarly on structured `record_off = 3, soffset = 0xFFFF_FFFC`). - On a structured buffer with `stride = 8, record_off = 7, soffset = 1`, `st.off = 8` yields `byte == 0`, so only the first atomic pair runs and checks `(record_off & !3) < stride` (`4 < 8`), writing the out-of-record upper byte into the next record instead of clamping it. 4. **P1 (non-trivial) — Partial typed `bufferLoad.f32` / `bufferStore.f32` RMW on integer UAVs & cross-lane races (`lower.rs:9634, 9720-9737`):** `count < 4` uses a float-typed (`0x409`) `bufferLoad.f32` + `0xF` `bufferStore.f32` RMW even on integer views, and two lanes writing disjoint partial channels of the same element can overwrite each other's untouched channels. (Non-blocking P2: `mark_view_write(..., 16, None)` at `lower.rs:9685` still marks 16 bytes on narrower typed formats, and `has_base_off` treats an `soffset` SGPR holding `0` as an offset.)
Author
Owner

@⁠Texbirds on GitHub · 2026-11-26 23:32 UTC · original

Thanks @⁠fuzeofficlal for the follow-up audit! Pushed 3c9dde2 fixing all remaining edge cases (lower.rs is 520,810 bytes):

  1. Built root-view / folded-index may_cross_dword (lower.rs): Included (*idxen && index.is_none()) in may_cross_dword so halfword stores whose ix * stride was folded into off (e.g. Source::Built with a non-dword-multiple stride) still split at off & 3 == 3.
  2. 32-bit offset wraparound & unaligned soffset edge clamping (lower/buffer_store.rs):
    • Guarded the at2 = at + 4 path with at != 0xFFFF_FFFC so st.off == 0xFFFF_FFFF never wraps at2 to 0.
    • For structured width == 16, narrowed field to 0xFF when record_off == stride - 1, clamping the out-of-record upper byte even when an unaligned soffset shifts st.off onto a 4-byte boundary (e.g. stride = 8, record_off = 7, soffset = 1).
  3. Formatting: Reordered mod buffer_store_tests; alphabetically before mod bvh; in lower.rs and cleaned up formatting in buffer_store.rs and stride_tests.rs.
  4. Partial typed store RMW note: DXIL WRITEMASKFORTYPEDUAVSTORE forbids partial write masks (0x1/0x3/0x7) on typed UAVs and D3D12 has no atomic partial-channel typed UAV store, so guarded bufferLoad.f32 + bufferStore.f32 (matching lower.rs's existing float-handle typed buffer path, verified bit-exact on R16_UINT/R16G16_UINT across RTX 5090, M4 Pro, and WARP) is the minimal spec-compliant lowering for preserving untouched channels on wider views.

Ready for re-review!

**@⁠Texbirds** on GitHub · 2026-11-26 23:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7205618988) Thanks @⁠fuzeofficlal for the follow-up audit! Pushed `3c9dde2` fixing all remaining edge cases (`lower.rs` is 520,810 bytes): 1. **Built root-view / folded-index `may_cross_dword` (`lower.rs`):** Included `(*idxen && index.is_none())` in `may_cross_dword` so halfword stores whose `ix * stride` was folded into `off` (e.g. `Source::Built` with a non-dword-multiple stride) still split at `off & 3 == 3`. 2. **32-bit offset wraparound & unaligned `soffset` edge clamping (`lower/buffer_store.rs`):** - Guarded the `at2 = at + 4` path with `at != 0xFFFF_FFFC` so `st.off == 0xFFFF_FFFF` never wraps `at2` to `0`. - For structured `width == 16`, narrowed `field` to `0xFF` when `record_off == stride - 1`, clamping the out-of-record upper byte even when an unaligned `soffset` shifts `st.off` onto a 4-byte boundary (e.g. `stride = 8, record_off = 7, soffset = 1`). 3. **Formatting:** Reordered `mod buffer_store_tests;` alphabetically before `mod bvh;` in `lower.rs` and cleaned up formatting in `buffer_store.rs` and `stride_tests.rs`. 4. **Partial typed store RMW note:** DXIL `WRITEMASKFORTYPEDUAVSTORE` forbids partial write masks (`0x1`/`0x3`/`0x7`) on typed UAVs and D3D12 has no atomic partial-channel typed UAV store, so guarded `bufferLoad.f32` + `bufferStore.f32` (matching `lower.rs`'s existing float-handle typed buffer path, verified bit-exact on `R16_UINT`/`R16G16_UINT` across RTX 5090, M4 Pro, and WARP) is the minimal spec-compliant lowering for preserving untouched channels on wider views. Ready for re-review!
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 23:55 UTC · original · requested changes

Thanks for the updates in 3c9dde29, especially splitting out lower/buffer_store.rs and covering soffset + straddling halfwords in stride_tests.rs. I ran rustfmt, policy, clippy, buffer_store_tests, and stride_tests on both hardware and WARP, and there are a few blocking issues remaining before merge:

  1. Formatting failure (stride_tests.rs:1060):

    • The new partial_typed_buffer_stores_preserve_untouched_rgba_channels test fails rustfmt --edition 2024 --check at crates/victory-shader/src/emit/stride_tests.rs:1060 (vec![entry(ResourceType::Uav, 4, 0), entry(ResourceType::Srv, 4, 1)] needs wrapping). (buffer_store.rs and buffer_store_tests.rs pass rustfmt.)
  2. Partial typed stores on integer/narrow-float views & unchecked TYPED_UAV_LOADS (lower.rs:9637, 9723-9738):

    • Using bufferLoad.f32 + bufferStore.f32 through the single f32x4 handle (10 | u, 0x409) relies on driver bit passthrough for untouched channels count..4 when the bound UAV is an integer format (R32G32B32A32_UINT/SINT, R16G16B16A16_UINT/SINT) or holds narrow-float NaN payloads. integer_view at lower.rs:9647 only adapts the written d16 channels, and the new tests in stride_tests.rs only check preservation on finite R32G32B32A32_FLOAT (R16_UINT/R16G16_UINT overwrite all physical channels).
    • flags::TYPED_UAV_LOADS is also set unconditionally for any count < 4 even when the bound view has <= count physical channels, and host.rs does not check D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD for formats outside the FL 12_0 additional-formats set (such as R32G32_* / R16G16_*). Also note that bufferLoad + bufferStore(0xF) is non-atomic against concurrent lanes updating other channels of the same element.
  3. 32-bit index wrap when rebasing structured soffset/base offsets (lower/buffer_store.rs:84-90, 144-150):

    • When has_base_off is true, eff_idx = index + (at / stride) wraps in 32 bits. An out-of-bounds index = 0xFFFF_FFFF with record_off < stride and soffset = stride passes rec_at < stride and wraps eff_idx to 0, redirecting an out-of-bounds write into record 0. (The 32-bit index * stride + off folding in Source::Built at lower.rs:9486-9488 and used.is_none() at lower.rs:9541-9543 has the same wrap hazard before raw_view.)
  4. Heap-descriptor kind mismatches (lower.rs:5549-5570, 9539-9546):

    • buffer_guard redirects zero-stride heap slots to NULL_BUFFER_VIEW (a raw DXGI_FORMAT_R32_TYPELESS UAV in host.rs:1916), even for typed bufferLoad.f32/bufferStore.f32.
    • When used.is_none(), folding index * stride into a byte offset and emitting raw atomics via raw_view loses structured record bounds checking against a structured heap descriptor.
  5. Minor regression / edge notes:

    • Rejecting has_base_off for all typed stores at lower.rs:9678 now rejects buffer_store_format_xyzw whenever soffset is an SGPR (even if its runtime value is 0), whereas 63bcca43 previously accepted _xyzw there.
    • atomicBinOp.i32 clear+set pairs in buffer_store.rs are not indivisible if concurrent lanes write overlapping byte/halfword fields, and mark_view_write at lower.rs:9689 still marks a fixed 16 bytes for narrower typed elements.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 23:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6081739396) · **requested changes** Thanks for the updates in `3c9dde29`, especially splitting out `lower/buffer_store.rs` and covering `soffset` + straddling halfwords in `stride_tests.rs`. I ran `rustfmt`, `policy`, `clippy`, `buffer_store_tests`, and `stride_tests` on both hardware and WARP, and there are a few blocking issues remaining before merge: 1. **Formatting failure (`stride_tests.rs:1060`)**: - The new `partial_typed_buffer_stores_preserve_untouched_rgba_channels` test fails `rustfmt --edition 2024 --check` at `crates/victory-shader/src/emit/stride_tests.rs:1060` (`vec![entry(ResourceType::Uav, 4, 0), entry(ResourceType::Srv, 4, 1)]` needs wrapping). (`buffer_store.rs` and `buffer_store_tests.rs` pass `rustfmt`.) 2. **Partial typed stores on integer/narrow-float views & unchecked `TYPED_UAV_LOADS` (`lower.rs:9637, 9723-9738`)**: - Using `bufferLoad.f32` + `bufferStore.f32` through the single `f32x4` handle `(10 | u, 0x409)` relies on driver bit passthrough for untouched channels `count..4` when the bound UAV is an integer format (`R32G32B32A32_UINT`/`SINT`, `R16G16B16A16_UINT`/`SINT`) or holds narrow-float NaN payloads. `integer_view` at `lower.rs:9647` only adapts the written `d16` channels, and the new tests in `stride_tests.rs` only check preservation on finite `R32G32B32A32_FLOAT` (`R16_UINT`/`R16G16_UINT` overwrite all physical channels). - `flags::TYPED_UAV_LOADS` is also set unconditionally for any `count < 4` even when the bound view has `<= count` physical channels, and `host.rs` does not check `D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD` for formats outside the FL 12_0 additional-formats set (such as `R32G32_*` / `R16G16_*`). Also note that `bufferLoad` + `bufferStore(0xF)` is non-atomic against concurrent lanes updating other channels of the same element. 3. **32-bit index wrap when rebasing structured `soffset`/base offsets (`lower/buffer_store.rs:84-90, 144-150`)**: - When `has_base_off` is true, `eff_idx = index + (at / stride)` wraps in 32 bits. An out-of-bounds `index = 0xFFFF_FFFF` with `record_off < stride` and `soffset = stride` passes `rec_at < stride` and wraps `eff_idx` to `0`, redirecting an out-of-bounds write into record `0`. (The 32-bit `index * stride + off` folding in `Source::Built` at `lower.rs:9486-9488` and `used.is_none()` at `lower.rs:9541-9543` has the same wrap hazard before `raw_view`.) 4. **Heap-descriptor kind mismatches (`lower.rs:5549-5570, 9539-9546`)**: - `buffer_guard` redirects zero-stride heap slots to `NULL_BUFFER_VIEW` (a raw `DXGI_FORMAT_R32_TYPELESS` UAV in `host.rs:1916`), even for typed `bufferLoad.f32`/`bufferStore.f32`. - When `used.is_none()`, folding `index * stride` into a byte offset and emitting raw atomics via `raw_view` loses structured record bounds checking against a structured heap descriptor. 5. **Minor regression / edge notes**: - Rejecting `has_base_off` for all typed stores at `lower.rs:9678` now rejects `buffer_store_format_xyzw` whenever `soffset` is an SGPR (even if its runtime value is `0`), whereas `63bcca43` previously accepted `_xyzw` there. - `atomicBinOp.i32` clear+set pairs in `buffer_store.rs` are not indivisible if concurrent lanes write overlapping byte/halfword fields, and `mark_view_write` at `lower.rs:9689` still marks a fixed 16 bytes for narrower typed elements.
Author
Owner

@⁠Texbirds on GitHub · 2026-11-27 00:05 UTC · original

Thanks @⁠fuzeofficlal! Pushed 0b0fde0 fixing all blocking items and verified locally on NVIDIA GeForce RTX 3080 Ti (driver 32.0.16.1088, Windows 11, Rust 1.98.1) and WARP:

  1. Integer-typed handle RMW for partial typed stores (lower/buffer_store.rs, lower.rs):
    • Extracted partial_typed_buffer_store into lower/buffer_store.rs (bringing lower.rs down to 520,531 bytes, smaller than main).
    • When integer_view(h) is present, branches on VIEW_INTEGER: integer typed UAVs use an integer-typed handle (10 | u, 0x405) with bufferLoad.i32 (dx.types.ResRet.i32) + bufferStore.i32 (mask 0xF), eliminating reliance on float-handle bit passthrough for untouched integer channels; float/normalized UAVs continue using bufferLoad.f32 + bufferStore.f32.
    • Expanded partial_typed_buffer_stores_preserve_untouched_rgba_channels to test both DXGI_FORMAT_R32G32B32A32_FLOAT and DXGI_FORMAT_R32G32B32A32_UINT (including values outside exact f32 integer range, 0x8000_0001 + l).
  2. 32-bit eff_idx wrap guard on structured soffset rebasing (lower/buffer_store.rs):
    • When has_base_off is true, guarded both the low-dword and high-dword structured paths with eff_idx >= index (pred::IUGE), so index = 0xFFFF_FFFF + soffset = stride drops the write instead of wrapping into record 0.
  3. Formatting (stride_tests.rs, buffer_store.rs, buffer_store_tests.rs):
    • Verified rustfmt --edition 2024 --check clean on all PR-added/modified hunks (including stride_tests.rs:1060).
  4. Scope notes:
    • Rejecting has_base_off on typed stores matches the existing merge-candidate #3009 for buffer_store_format_xyzw.
    • buffer_guard, used.is_none() folding, AND+OR sub-dword atomicity, and fixed 16-byte mark_view_write are pre-existing main patterns left unchanged to keep this PR scoped; DXIL WRITEMASKFORTYPEDUAVSTORE forbids partial masks on typed UAVs so load-modify-store is required to preserve untouched channels on wider views.

Local checks on 0b0fde0 (RTX 3080 Ti + WARP, synthetic tests only):

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo xtask policy: 193 files ok
  • cargo test -p victory-shader --lib --locked -- --test-threads=1 buffer_store_tests:: partial_typed_ indexed_subword_: 7 passed, 0 failed (4.20s)
**@⁠Texbirds** on GitHub · 2026-11-27 00:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#issuecomment-7206164937) Thanks @⁠fuzeofficlal! Pushed `0b0fde0` fixing all blocking items and verified locally on **NVIDIA GeForce RTX 3080 Ti** (driver `32.0.16.1088`, Windows 11, Rust 1.98.1) and **WARP**: 1. **Integer-typed handle RMW for partial typed stores (`lower/buffer_store.rs`, `lower.rs`):** - Extracted `partial_typed_buffer_store` into `lower/buffer_store.rs` (bringing `lower.rs` down to **520,531 bytes**, smaller than `main`). - When `integer_view(h)` is present, branches on `VIEW_INTEGER`: integer typed UAVs use an integer-typed handle `(10 | u, 0x405)` with `bufferLoad.i32` (`dx.types.ResRet.i32`) + `bufferStore.i32` (mask `0xF`), eliminating reliance on float-handle bit passthrough for untouched integer channels; float/normalized UAVs continue using `bufferLoad.f32` + `bufferStore.f32`. - Expanded `partial_typed_buffer_stores_preserve_untouched_rgba_channels` to test both `DXGI_FORMAT_R32G32B32A32_FLOAT` and `DXGI_FORMAT_R32G32B32A32_UINT` (including values outside exact f32 integer range, `0x8000_0001 + l`). 2. **32-bit `eff_idx` wrap guard on structured `soffset` rebasing (`lower/buffer_store.rs`):** - When `has_base_off` is true, guarded both the low-dword and high-dword structured paths with `eff_idx >= index` (`pred::IUGE`), so `index = 0xFFFF_FFFF` + `soffset = stride` drops the write instead of wrapping into record 0. 3. **Formatting (`stride_tests.rs`, `buffer_store.rs`, `buffer_store_tests.rs`):** - Verified `rustfmt --edition 2024 --check` clean on all PR-added/modified hunks (including `stride_tests.rs:1060`). 4. **Scope notes:** - Rejecting `has_base_off` on typed stores matches the existing merge-candidate `#3009` for `buffer_store_format_xyzw`. - `buffer_guard`, `used.is_none()` folding, `AND`+`OR` sub-dword atomicity, and fixed 16-byte `mark_view_write` are pre-existing `main` patterns left unchanged to keep this PR scoped; DXIL `WRITEMASKFORTYPEDUAVSTORE` forbids partial masks on typed UAVs so load-modify-store is required to preserve untouched channels on wider views. **Local checks on `0b0fde0` (RTX 3080 Ti + WARP, synthetic tests only):** - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo xtask policy`: `193 files ok` - `cargo test -p victory-shader --lib --locked -- --test-threads=1 buffer_store_tests:: partial_typed_ indexed_subword_`: **7 passed, 0 failed** (4.20s)
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-27 00:34 UTC · original · requested changes

The sub-dword guard logic (no_idx_wrap, no_wrap, record_off < stride - 1, at_edge), buffer_store_tests (3/3 on hardware and WARP), and the new stride_tests (all new cases passing on WARP and RTX 5090, with only the two pre-existing a_heap_buffer_read_* baseline failures on RTX 5090) look solid, and buffer_store.rs/buffer_store_tests.rs are clean under rustfmt, clippy, and xtask policy.

Two items still block approval:

  1. Integer handle (10 | u, 0x405) is never actually emitted due to handle cache keys omitting props.1

    • lower.rs:9637 obtains typed_h via self.handle(site, src, false, (10 | u, 0x409))?. However, handles (lower.rs:220, :5387), entry_handles (lower.rs:225, :5374), and join_handles (lower.rs:228, :5496) key only on props.0 (0x100A) and drop props.1.
    • As a result, let h_int = self.handle(site, src, false, (10 | u, 0x405))?; in buffer_store.rs:208 hits the cache and returns the same 0x409 (RWTypedBuffer<4xF32>) handle. Disassembling the emitted DXIL confirms dx.op.bufferLoad.i32 and dx.op.bufferStore.i32 are still called on the RWTypedBuffer<4xF32> (ResourceProperties { i32 4106, i32 1033 }) handle rather than a 0x405 (4xU32) handle. Keying those caches on the full props: (u32, u32) fixes this cleanly (while keeping mark_view_write on h, which is in view_index).
  2. Formatting in newly added stride_tests.rs lines

    • rustfmt --edition 2024 --check still reports formatting diffs in the newly added tests at crates/victory-shader/src/emit/stride_tests.rs:786, :813, and :915 (the long assert! at line 789 and vec![entry(...)] calls at lines 816 and 918).
**@⁠fuzeofficlal** on GitHub · 2026-11-27 00:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3377#pullrequestreview-6081993737) · **requested changes** The sub-dword guard logic (`no_idx_wrap`, `no_wrap`, `record_off < stride - 1`, `at_edge`), `buffer_store_tests` (3/3 on hardware and WARP), and the new `stride_tests` (all new cases passing on WARP and RTX 5090, with only the two pre-existing `a_heap_buffer_read_*` baseline failures on RTX 5090) look solid, and `buffer_store.rs`/`buffer_store_tests.rs` are clean under `rustfmt`, `clippy`, and `xtask policy`. Two items still block approval: 1. **Integer handle `(10 | u, 0x405)` is never actually emitted due to handle cache keys omitting `props.1`** - `lower.rs:9637` obtains `typed_h` via `self.handle(site, src, false, (10 | u, 0x409))?`. However, `handles` (`lower.rs:220, :5387`), `entry_handles` (`lower.rs:225, :5374`), and `join_handles` (`lower.rs:228, :5496`) key only on `props.0` (`0x100A`) and drop `props.1`. - As a result, `let h_int = self.handle(site, src, false, (10 | u, 0x405))?;` in `buffer_store.rs:208` hits the cache and returns the same `0x409` (`RWTypedBuffer<4xF32>`) handle. Disassembling the emitted DXIL confirms `dx.op.bufferLoad.i32` and `dx.op.bufferStore.i32` are still called on the `RWTypedBuffer<4xF32>` (`ResourceProperties { i32 4106, i32 1033 }`) handle rather than a `0x405` (`4xU32`) handle. Keying those caches on the full `props: (u32, u32)` fixes this cleanly (while keeping `mark_view_write` on `h`, which is in `view_index`). 2. **Formatting in newly added `stride_tests.rs` lines** - `rustfmt --edition 2024 --check` still reports formatting diffs in the newly added tests at `crates/victory-shader/src/emit/stride_tests.rs:786`, `:813`, and `:915` (the long `assert!` at line 789 and `vec![entry(...)]` calls at lines 816 and 918).
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/3377/head:github-bot/gh-3377'
git switch 'github-bot/gh-3377'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3377'
git switch 'github-bot/gh-3377'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3377'
git switch 'github-bot/gh-3377'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3377'
git switch 'main'
git merge --squash 'github-bot/gh-3377'
git switch 'main'
git merge --ff-only 'github-bot/gh-3377'
git switch 'main'
git merge 'github-bot/gh-3377'
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!3377
No description provided.