Shaders: lower indexed tbuffer_load_format_* and indexed buffer_store_{byte,short} #1869

Open
ESAT586 wants to merge 1 commit from upstream-pr/1871 into main
ESAT586 commented 2026-11-24 23:56:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T23:56:19Z.


Summary

Lowers indexed tbuffer_load_format_* (idxen) and indexed buffer_store_{byte,short} (idxen) in crates/victory-shader/src/emit/lower.rs, removing "a typed-format load by index" and "a byte or half buffer store by index":

  • Indexed tbuffer_load_format_* (format.is_some()):
    • Root views (Source::Built): MTBUF instructions supply their own format over raw/structured descriptors rather than requiring a typed buffer view, so root views without swizzling or a record limit (bits >> 30 == 0 && words[0] == u32::MAX) fold index * stride into the byte offset.
    • Bindless heap views (used.is_none()): folds index * view_stride(src) via VIEW_STRIDES into the byte offset.
    • Declared StructuredBuffer / RWStructuredBuffer (used.stride >= 4 && used.stride % 4 == 0): extends format_load to accept index: Option<V> and emit dx.op.rawBufferLoad.f32(handle, index, elementOffset, mask, 4) on (12 | u, stride) for both sub-dword formats (dword-aligned load + shift) and 32-128-bit formats, with idxen, offen, immediate offset, and soffset.
    • Uses exact format transfer width (total.div_ceil(32) * 4) for raw_view.
  • Indexed buffer_store_byte / buffer_store_short:
    • Declared RWStructuredBuffer UAVs (stride >= 4 && stride % 4 == 0) lower to structured dx.op.atomicBinOp.i32(handle, And/Or, index, at, undef, keep/val) on (12 | 0x1000, stride), preserving concurrent neighboring bytes/halves in the same dword and EXEC guards.
  • Refusals preserved: declared structured buffers with stride < 4 or stride % 4 != 0 still refuse with "a structured buffer of unknown stride"; root views with swizzling or a record limit still refuse with "a root view indexed with swizzling or a record limit".
  • Scope / non-overlap: intentionally does not touch tbuffer_load_format_d16_* packing (#169), byte-offset-3 16-bit straddling (#1669), buffer_load_{ubyte,sbyte,ushort,sshort} (#1572), or buffer_store_{byte,short}_d16_hi (#164).

Test Plan

Added View::StructuredUav (#[cfg(test)]) in crates/victory-shader/src/emit/host.rs and 5 synthetic tests in crates/victory-shader/src/emit/stride_tests.rs, validated with dxil.dll and executed on NVIDIA GeForce RTX 3060 Ti and Microsoft D3D12 WARP:

  • indexed_tbuffer_load_format_reads_structured_srv_formats: StructuredBuffer SRV (stride 20) testing 8_8_8_8_UNORM, unaligned sub-dword 8_UNORM at offset 5, 8_8_SINT at offset 6, 64-bit 16_16_16_16_FLOAT at offset 8, channel-padded 8_UINT, and runtime idxen + offen + soffset 16_16_SNORM.
  • indexed_tbuffer_load_format_reads_structured_uav: RWStructuredBuffer UAV (stride 16) testing 8_8_8_8_UINT and 32_32_FLOAT with (0.0, 1.0) channel padding.
  • indexed_tbuffer_load_format_reads_root_view_and_heap_view: Source::Built root SRV (stride 16) and bindless ResourceDescriptorHeap via VIEW_STRIDES (stride 12).
  • indexed_byte_and_short_buffer_stores_preserve_neighbors_and_guard: pre-populated non-zero sentinel RWStructuredBuffer UAV (stride 16) testing concurrent 4-lane byte writes sharing a dword (including 0x00 clearing non-zero sentinel bits), divergent EXEC-guarded short writes sharing a dword, divergent idxen + soffset byte writes, and untouched sentinel dwords.
  • indexed_tbuffer_and_subdword_stores_refuse_unknown_stride_and_record_limit: verifies refusal on stride 0, stride 6, and record-limited root views.

Verification Results

  • cargo test -p victory-shader --lib emit::stride_tests::indexed_ -- --test-threads=1 --nocapture: 5 passed, 0 failed (RTX 3060 Ti + WARP + dxil.dll).
  • cargo test -p victory-shader --lib emit::memory_tests -- --test-threads=1: 2 passed, 0 failed.
  • cargo test -p victory-shader --lib emit::lower::tests -- --test-threads=1: 17 passed, 0 failed.
  • cargo clippy --workspace --all-targets -- -D warnings: clean (0 warnings).
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: clean (0 warnings).
  • cargo xtask policy: asset policy: 174 files ok.

Disclosure

  • AI Assistance: Implemented and verified with Gemini 4 Neon (Extra High Mode).
  • Clean-Room: Based strictly on public AMD RDNA2 ISA documentation, DXIL specification, and synthetic unit tests; zero game binaries, dumps, or copyrighted assets were used.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5482409210 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-24T23:56:19Z. --- ## Summary Lowers indexed `tbuffer_load_format_*` (`idxen`) and indexed `buffer_store_{byte,short}` (`idxen`) in `crates/victory-shader/src/emit/lower.rs`, removing `"a typed-format load by index"` and `"a byte or half buffer store by index"`: - **Indexed `tbuffer_load_format_*` (`format.is_some()`):** - **Root views (`Source::Built`)**: MTBUF instructions supply their own format over raw/structured descriptors rather than requiring a typed buffer view, so root views without swizzling or a record limit (`bits >> 30 == 0 && words[0] == u32::MAX`) fold `index * stride` into the byte offset. - **Bindless heap views (`used.is_none()`)**: folds `index * view_stride(src)` via `VIEW_STRIDES` into the byte offset. - **Declared `StructuredBuffer` / `RWStructuredBuffer` (`used.stride >= 4 && used.stride % 4 == 0`)**: extends `format_load` to accept `index: Option<V>` and emit `dx.op.rawBufferLoad.f32(handle, index, elementOffset, mask, 4)` on `(12 | u, stride)` for both sub-dword formats (dword-aligned load + shift) and 32-128-bit formats, with `idxen`, `offen`, immediate `offset`, and `soffset`. - Uses exact format transfer width (`total.div_ceil(32) * 4`) for `raw_view`. - **Indexed `buffer_store_byte` / `buffer_store_short`:** - Declared `RWStructuredBuffer` UAVs (`stride >= 4 && stride % 4 == 0`) lower to structured `dx.op.atomicBinOp.i32(handle, And/Or, index, at, undef, keep/val)` on `(12 | 0x1000, stride)`, preserving concurrent neighboring bytes/halves in the same dword and `EXEC` guards. - **Refusals preserved:** declared structured buffers with `stride < 4` or `stride % 4 != 0` still refuse with `"a structured buffer of unknown stride"`; root views with swizzling or a record limit still refuse with `"a root view indexed with swizzling or a record limit"`. - **Scope / non-overlap:** intentionally does not touch `tbuffer_load_format_d16_*` packing (#169), byte-offset-3 16-bit straddling (#1669), `buffer_load_{ubyte,sbyte,ushort,sshort}` (#1572), or `buffer_store_{byte,short}_d16_hi` (#164). ## Test Plan Added `View::StructuredUav` (`#[cfg(test)]`) in `crates/victory-shader/src/emit/host.rs` and 5 synthetic tests in `crates/victory-shader/src/emit/stride_tests.rs`, validated with `dxil.dll` and executed on **NVIDIA GeForce RTX 3060 Ti** and **Microsoft D3D12 WARP**: - `indexed_tbuffer_load_format_reads_structured_srv_formats`: `StructuredBuffer` SRV (stride 20) testing `8_8_8_8_UNORM`, unaligned sub-dword `8_UNORM` at offset 5, `8_8_SINT` at offset 6, 64-bit `16_16_16_16_FLOAT` at offset 8, channel-padded `8_UINT`, and runtime `idxen + offen + soffset` `16_16_SNORM`. - `indexed_tbuffer_load_format_reads_structured_uav`: `RWStructuredBuffer` UAV (stride 16) testing `8_8_8_8_UINT` and `32_32_FLOAT` with `(0.0, 1.0)` channel padding. - `indexed_tbuffer_load_format_reads_root_view_and_heap_view`: `Source::Built` root SRV (stride 16) and bindless `ResourceDescriptorHeap` via `VIEW_STRIDES` (stride 12). - `indexed_byte_and_short_buffer_stores_preserve_neighbors_and_guard`: pre-populated non-zero sentinel `RWStructuredBuffer` UAV (stride 16) testing concurrent 4-lane byte writes sharing a dword (including `0x00` clearing non-zero sentinel bits), divergent `EXEC`-guarded short writes sharing a dword, divergent `idxen + soffset` byte writes, and untouched sentinel dwords. - `indexed_tbuffer_and_subdword_stores_refuse_unknown_stride_and_record_limit`: verifies refusal on stride `0`, stride `6`, and record-limited root views. ### Verification Results - `cargo test -p victory-shader --lib emit::stride_tests::indexed_ -- --test-threads=1 --nocapture`: **5 passed, 0 failed** (RTX 3060 Ti + WARP + `dxil.dll`). - `cargo test -p victory-shader --lib emit::memory_tests -- --test-threads=1`: **2 passed, 0 failed**. - `cargo test -p victory-shader --lib emit::lower::tests -- --test-threads=1`: **17 passed, 0 failed**. - `cargo clippy --workspace --all-targets -- -D warnings`: **clean (0 warnings)**. - `cargo clippy --workspace --all-targets --all-features -- -D warnings`: **clean (0 warnings)**. - `cargo xtask policy`: **`asset policy: 174 files ok`**. ## Disclosure - **AI Assistance:** Implemented and verified with **Gemini 4 Neon (Extra High Mode)**. - **Clean-Room:** Based strictly on public AMD RDNA2 ISA documentation, DXIL specification, and synthetic unit tests; **zero game binaries, dumps, or copyrighted assets were used**.
Marvisak commented 2026-11-25 02:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:37:29Z.


Automated triage for the maintainers.

Merge candidate.

This lowers indexed tbuffer_load_format_* and indexed buffer_store_byte/short in emit/lower.rs, which main refuses today. Built root views and bindless heap views fold index * stride into the byte offset, as the untyped paths already do. Declared structured views use a (12 | u, stride) handle with (index, offset) coordinates, and stride below 4 or not a multiple of 4 still refuses, as on the other structured paths in main. Sub-dword stores keep the clear-then-set atomic pair and the EXEC guard, and mark_view_write gets index * stride + at. One side change: raw_view is now given the format's real width instead of 4 * count. That tightens the title-memory bounds check, and I see no read past it. The added shortcut: comments note the remaining limit, an offset past the stride. Five synthetic tests in stride_tests.rs cover SRV, UAV, root and heap views, neighbour-preserving byte/short stores and the refusals. The thread reports they pass on an RTX 3060 Ti and on WARP.

CI (check): passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149764524 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#issuecomment-7149764524). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:37:29Z. --- <!-- victory-triage v1 head=e4a4f2c88cf678870ae96a724cc2722f59f15710 verdict=merge-candidate at=2026-11-25T16:48:22Z --> Automated triage for the maintainers. **Merge candidate.** This lowers indexed `tbuffer_load_format_*` and indexed `buffer_store_byte`/`short` in `emit/lower.rs`, which `main` refuses today. Built root views and bindless heap views fold `index * stride` into the byte offset, as the untyped paths already do. Declared structured views use a `(12 | u, stride)` handle with `(index, offset)` coordinates, and stride below 4 or not a multiple of 4 still refuses, as on the other structured paths in `main`. Sub-dword stores keep the clear-then-set atomic pair and the `EXEC` guard, and `mark_view_write` gets `index * stride + at`. One side change: `raw_view` is now given the format's real width instead of `4 * count`. That tightens the title-memory bounds check, and I see no read past it. The added `shortcut:` comments note the remaining limit, an offset past the stride. Five synthetic tests in `stride_tests.rs` cover SRV, UAV, root and heap views, neighbour-preserving byte/short stores and the refusals. The thread reports they pass on an RTX 3060 Ti and on WARP. CI (`check`): passing. --- _Generated by [Claude Code](https://claude.ai/code)_
catminou4 commented 2026-11-25 02:17:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:17:14Z.

Review: COMMENTED


Merge conflict with current main (940d32f69b) — git merge origin/main fails on the PR head. The lowering work itself (indexed tbuffer_load_format_* / buffer_store_) looks like the right direction; a rebase is needed before it can land. Will re-test after the author rebases.

<!-- greyfinch-sync:Marvisak/VIctory:review:6050698496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#pullrequestreview-6050698496). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:17:14Z. **Review:** COMMENTED --- Merge conflict with current main (940d32f69b) — `git merge origin/main` fails on the PR head. The lowering work itself (indexed tbuffer_load_format_* / buffer_store_) looks like the right direction; a rebase is needed before it can land. Will re-test after the author rebases.
ESAT586 commented 2026-11-25 12:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T11:08:19Z.


Rebased onto \main\ (\940d32f) at \ d38a61\ (preserving \d16_channels\ on \ ormat_load\ and passing \index * stride + at\ / adjusted
aw_view\ byte offset to \mark_view_write\ from \cd94d35). Verified on RTX 3060 Ti + WARP: all 5 \indexed_*\ tests and \writes_through_views_mark_their_pages\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160643116 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#issuecomment-7160643116). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-25T11:08:19Z. --- Rebased onto \main\ (\940d32f\) at \ d38a61\ (preserving \d16_channels\ on \ ormat_load\ and passing \index * stride + at\ / adjusted \ aw_view\ byte offset to \mark_view_write\ from \cd94d35\). Verified on RTX 3060 Ti + WARP: all 5 \indexed_*\ tests and \writes_through_views_mark_their_pages\ passed, strict Clippy (\--all-targets\ and \--all-features\) clean, \cargo xtask policy\ ok.
ESAT586 commented 2026-11-25 12:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T11:31:03Z.


Fixed the three UTF-8 \×\ comments in \stride_tests.rs\ (diff is now purely additive) and added the \shortcut:\ comments on the structured view paths in \lower.rs\ at $sha. Re-verified: 5/5 \indexed_*\ tests on RTX 3060 Ti + WARP, strict Clippy clean, \cargo xtask policy\ ok.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161148858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#issuecomment-7161148858). Originally posted by [ESAT586](https://github.com/ESAT586) on 2026-11-25T11:31:03Z. --- Fixed the three UTF-8 \×\ comments in \stride_tests.rs\ (diff is now purely additive) and added the \shortcut:\ comments on the structured view paths in \lower.rs\ at \$sha\. Re-verified: 5/5 \indexed_*\ tests on RTX 3060 Ti + WARP, strict Clippy clean, \cargo xtask policy\ ok.
fuzeofficlal commented 2026-11-26 18:59:27 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified e4a4f2c88cf678870ae96a724cc2722f59f15710 cleanly merged onto main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK dxil.dll):

  • emit/lower.rs size: 522,692 B (under the 524,288 B cap); cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed (asset policy: 191 files ok).
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features): clean.
  • indexed_ (6 passed, 0 failed, covering all 5 new stride_tests::indexed_* cases across SRV, UAV, root/heap views, sub-dword stores, and refusals), writes_through_views_mark_their_pages, emit::tests::constant_color_validates, and emit::lower::tests:: (33 passed, 0 failed) all pass on both RTX 5090 and WARP.

Minor non-blocking test-helper note: host::view_strides (crates/victory-shader/src/emit/host.rs:1363-1370) does not map the new View::StructuredUav { stride, .. } variant yet (returns 0), which isn't hit by the current stride_tests cases but would matter for any bindless fixture using StructuredUav. Ready to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6079256736 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#pullrequestreview-6079256736). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:59:27Z. **Review:** APPROVED --- Verified `e4a4f2c88cf678870ae96a724cc2722f59f15710` cleanly merged onto `main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDK `dxil.dll`): - `emit/lower.rs` size: **522,692 B** (under the 524,288 B cap); `cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed` (`asset policy: 191 files ok`). - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`): clean. - `indexed_` (`6 passed, 0 failed`, covering all 5 new `stride_tests::indexed_*` cases across SRV, UAV, root/heap views, sub-dword stores, and refusals), `writes_through_views_mark_their_pages`, `emit::tests::constant_color_validates`, and `emit::lower::tests::` (`33 passed, 0 failed`) all pass on both RTX 5090 and WARP. Minor non-blocking test-helper note: `host::view_strides` (`crates/victory-shader/src/emit/host.rs:1363-1370`) does not map the new `View::StructuredUav { stride, .. }` variant yet (returns `0`), which isn't hit by the current `stride_tests` cases but would matter for any bindless fixture using `StructuredUav`. Ready to merge.
Dukestar69 commented 2026-11-26 23:49:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T23:49:25Z.

Review: APPROVED


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

  • Lowering indexed tbuffer_load_format_* and indexed buffer_store_{byte,short} (preserving neighboring bytes, honoring guards, and refusing unknown stride/record limits) passes cleanly on both RTX 5090 and WARP.
  • cargo test -p victory-shader --lib emit::stride_tests::indexed_ -- --test-threads=1: 5 passed, 0 failed on RTX 5090 and 5 passed, 0 failed on VICTORY_WARP=1.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6081673460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1871#pullrequestreview-6081673460). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T23:49:25Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 and `VICTORY_WARP=1` (Windows / D3D12) against `origin/main` (`63bcca4`). - Lowering indexed `tbuffer_load_format_*` and indexed `buffer_store_{byte,short}` (preserving neighboring bytes, honoring guards, and refusing unknown stride/record limits) passes cleanly on both RTX 5090 and WARP. - `cargo test -p victory-shader --lib emit::stride_tests::indexed_ -- --test-threads=1`: 5 passed, 0 failed on RTX 5090 and 5 passed, 0 failed on `VICTORY_WARP=1`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 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/1871:upstream-pr/1871'
git switch 'upstream-pr/1871'

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/1871'
git switch 'upstream-pr/1871'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1871'
git switch 'upstream-pr/1871'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1871'
git switch 'main'
git merge --squash 'upstream-pr/1871'
git switch 'main'
git merge --ff-only 'upstream-pr/1871'
git switch 'main'
git merge 'upstream-pr/1871'
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!1869
No description provided.