Shaders: lower indexed buffer accesses with used-resource stride 0 as raw #2359

Closed
github-bot wants to merge 1 commit from gh-pr/2359/head into gh-pr/2359/base
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 11:44 UTC · original
fuzeofficlal:fix/shader-stride-zero-indexed-buffer-1482 → main · +297 −3 · 2 files · 1 commits · closed without merging

Part of #1482 (Rule 3, reported by @⁠studiostephe).

Summary

  • In Lower::buffer (crates/victory-shader/src/emit/lower.rs), drop index (index = None) when used.is_some_and(|u| u.stride == 0) && !typed && format.is_none() so indexed buffer_load*, buffer_store*, and buffer_atomic_* instructions on raw buffers route through the existing raw-view (11 | u, 0) path at byte offset off instead of failing with "a structured buffer of unknown stride". Strides 1..=3 remain refused.

UsedResource.stride == 0 in native.rs and hardware semantics

  • FSSM (DXIL containers, native.rs:654): UsedResource.stride is read directly from le32(e, 12) of the 20-byte used entry: structured buffers carry their element byte stride (>= 4), root views carry 1, and raw buffers (ByteAddressBuffer / RWByteAddressBuffer) carry 0 — the same convention Lower::descriptor_data (lower.rs:4088-4110) already relies on. (Unlike Source::Built, a RootType::Table load's descriptor dword 1 sits in the title's heap at draw time rather than in shader code, and HostHeap's VIEW_STRIDES table stores 4 for raw buffers and reserves 0 for non-buffers.)
  • FSPX (ACCC containers, native.rs:530): 0x41 records store view dimension at +12 rather than stride, so fspx_program sets stride: 0; FidelityFX upscaler shaders build raw descriptors (made_raw) and address buffers via offen byte offsets.
  • RDNA2 / GFX10 hardware: Under MUBUF addressing (inst_offset + soffset + (offen ? voffset : 0) + (idxen ? vindex * V#.STRIDE : 0)) with raw-buffer OOB_SELECT = 3, V#.STRIDE == 0 contributes vindex * 0 == 0 to the byte address and checks byte_offset + payload_bytes <= NUM_RECORDS, matching index = None.

Verification

  • emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse: verifies stride = 0 and stride = 4 lower and validate via dxil.dll across load, store, and atomic, while stride = 1, 2, 3 still return Unsupported("a structured buffer of unknown stride").
  • emit::stride_tests::stride_zero_indexed_load_store_and_atomic_address_as_raw_buffers: end-to-end Wave32 compute readback (vindex = lane + 1 with idxen across load, store, and glc atomic add) on NVIDIA GeForce RTX 5090 and D3D12 WARP.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings and cargo xtask policy: passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 11:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2359) `fuzeofficlal:fix/shader-stride-zero-indexed-buffer-1482` → `main` · +297 −3 · 2 files · 1 commits · closed without merging Part of #1482 (Rule 3, reported by @⁠studiostephe). ### Summary - In `Lower::buffer` (`crates/victory-shader/src/emit/lower.rs`), drop `index` (`index = None`) when `used.is_some_and(|u| u.stride == 0) && !typed && format.is_none()` so indexed `buffer_load*`, `buffer_store*`, and `buffer_atomic_*` instructions on raw buffers route through the existing raw-view `(11 | u, 0)` path at byte offset `off` instead of failing with `"a structured buffer of unknown stride"`. Strides `1..=3` remain refused. ### `UsedResource.stride == 0` in `native.rs` and hardware semantics - **`FSSM` (`DXIL` containers, `native.rs:654`)**: `UsedResource.stride` is read directly from `le32(e, 12)` of the 20-byte `used` entry: structured buffers carry their element byte stride (`>= 4`), root views carry `1`, and raw buffers (`ByteAddressBuffer` / `RWByteAddressBuffer`) carry `0` — the same convention `Lower::descriptor_data` (`lower.rs:4088-4110`) already relies on. (Unlike `Source::Built`, a `RootType::Table` load's descriptor dword 1 sits in the title's heap at draw time rather than in shader code, and `HostHeap`'s `VIEW_STRIDES` table stores `4` for raw buffers and reserves `0` for non-buffers.) - **`FSPX` (`ACCC` containers, `native.rs:530`)**: `0x41` records store view dimension at `+12` rather than stride, so `fspx_program` sets `stride: 0`; FidelityFX upscaler shaders build raw descriptors (`made_raw`) and address buffers via `offen` byte offsets. - **RDNA2 / GFX10 hardware**: Under `MUBUF` addressing (`inst_offset + soffset + (offen ? voffset : 0) + (idxen ? vindex * V#.STRIDE : 0)`) with raw-buffer `OOB_SELECT = 3`, `V#.STRIDE == 0` contributes `vindex * 0 == 0` to the byte address and checks `byte_offset + payload_bytes <= NUM_RECORDS`, matching `index = None`. ### Verification - `emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse`: verifies `stride = 0` and `stride = 4` lower and validate via `dxil.dll` across `load`, `store`, and `atomic`, while `stride = 1, 2, 3` still return `Unsupported("a structured buffer of unknown stride")`. - `emit::stride_tests::stride_zero_indexed_load_store_and_atomic_address_as_raw_buffers`: end-to-end Wave32 compute readback (`vindex = lane + 1` with `idxen` across load, store, and `glc` atomic add) on **NVIDIA GeForce RTX 5090** and **D3D12 WARP**. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` and `cargo xtask policy`: passed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:26 +00:00
github-bot closed this pull request 2026-11-26 05:03:26 +00:00
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-25 13:35 UTC · original

Both supplied tests passed on 4e14e76 on an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068). I extended the existing Wave32 test to give the load, atomic and two stores distinct scalar byte offsets of 12, 8, 4 and 8. This checks that dropping a zero-stride index still preserves the scalar offset on all three kinds of access.

Each adapter matched 68/68 values with the original offsets and 72/72 with the new offsets. The shifted load returned 1004–1035, the atomic returned every previous value from 0 to 31, only counter word 3 reached 32, and all four untouched output words stayed zero. Both cases use the same fixture.

Test-only commit 356decf

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2359-index-offset-readback
git cherry-pick 356decff9f80b61bbf9ef0ffddd9e6abde202ba1
cargo test -p victory-shader --lib --locked stride_zero_indexed_load_store_and_atomic_address_as_raw_buffers -- --nocapture --test-threads=1

AI-assisted with Codex. Synthetic compute readbacks.

**@⁠steven-seagull27** on GitHub · 2026-11-25 13:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7163987400) Both supplied tests passed on `4e14e76` on an RTX 5080 (621.40) and built-in Microsoft WARP (10.0.26100.10068). I extended the existing Wave32 test to give the load, atomic and two stores distinct scalar byte offsets of 12, 8, 4 and 8. This checks that dropping a zero-stride index still preserves the scalar offset on all three kinds of access. Each adapter matched **68/68** values with the original offsets and **72/72** with the new offsets. The shifted load returned 1004–1035, the atomic returned every previous value from 0 to 31, only counter word 3 reached 32, and all four untouched output words stayed zero. Both cases use the same fixture. [Test-only commit `356decf`](https://github.com/steven-seagull27/VIctory/commit/356decff9f80b61bbf9ef0ffddd9e6abde202ba1) ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2359-index-offset-readback git cherry-pick 356decff9f80b61bbf9ef0ffddd9e6abde202ba1 cargo test -p victory-shader --lib --locked stride_zero_indexed_load_store_and_atomic_address_as_raw_buffers -- --nocapture --test-threads=1 ``` AI-assisted with Codex. Synthetic compute readbacks.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:27 UTC · original

Automated triage for the maintainers.

In Lower::buffer (crates/victory-shader/src/emit/lower.rs), an indexed MUBUF access is now lowered as raw (index dropped) whenever the used-resource entry has stride == 0. Before, it was refused as "a structured buffer of unknown stride". The address formula cited, vindex * V#.STRIDE, is right per the public RDNA2 ISA. The change, though, keys on the metadata stride (UsedResource.stride), not the descriptor's stride, and two things are not shown:

  1. FSPX programs. In native.rs, fspx_program sets stride: 0 for every resource, because that record carries no stride. With this change, an FSPX structured buffer accessed with idxen would silently get the wrong addresses (index dropped) instead of being refused. Please exclude FSPX programs, or show that they never use idxen on buffers.
  2. Evidence that metadata stride 0 means descriptor stride 0. #1482 states its rule for the V# stride. Please give the evidence for this mapping: a count of the affected programs in the shader cache and what their descriptors hold, or the title's own descriptor setup for these buffers. The host's view-stride table stores 4 for raw views, so this matters. If the real descriptor stride is non-zero, dropping the index is wrong.

The added tests are synthetic and confirm the chosen lowering. They do not show what the console does. With the FSPX case handled and that evidence given, this would be a reasonable fix.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7170944783) <!-- victory-triage v1 head=db74afcccde9ce9116c072d80c11813526a37c1a verdict=needs-work at=2026-11-25T18:27:44Z --> Automated triage for the maintainers. In `Lower::buffer` (`crates/victory-shader/src/emit/lower.rs`), an indexed MUBUF access is now lowered as raw (index dropped) whenever the used-resource entry has `stride == 0`. Before, it was refused as "a structured buffer of unknown stride". The address formula cited, `vindex * V#.STRIDE`, is right per the public RDNA2 ISA. The change, though, keys on the **metadata** stride (`UsedResource.stride`), not the descriptor's stride, and two things are not shown: 1. **FSPX programs.** In `native.rs`, `fspx_program` sets `stride: 0` for every resource, because that record carries no stride. With this change, an FSPX structured buffer accessed with `idxen` would silently get the wrong addresses (index dropped) instead of being refused. Please exclude FSPX programs, or show that they never use `idxen` on buffers. 2. **Evidence that metadata stride 0 means descriptor stride 0.** #1482 states its rule for the V# stride. Please give the evidence for this mapping: a count of the affected programs in the shader cache and what their descriptors hold, or the title's own descriptor setup for these buffers. The host's view-stride table stores 4 for raw views, so this matters. If the real descriptor stride is non-zero, dropping the index is wrong. The added tests are synthetic and confirm the chosen lowering. They do not show what the console does. With the FSPX case handled and that evidence given, this would be a reasonable fix. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:37 UTC · original

Thanks for the detailed triage! Both points are completely fair:

  1. fspx_program sets stride: 0 for all resources regardless of whether a buffer is structured, so keying on UsedResource.stride == 0 without excluding FSPX would silently misaddress indexed FSPX structured buffers.
  2. More fundamentally, I do not have retail shader caches to verify whether non-FSPX UsedResource.stride == 0 metadata always corresponds to V#.STRIDE == 0 in the runtime descriptors (vs. missing metadata where dropping vindex would be wrong).

Closing this PR rather than leaving an unverified metadata-to-descriptor assumption in the review queue.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7172557031) Thanks for the detailed triage! Both points are completely fair: 1. `fspx_program` sets `stride: 0` for all resources regardless of whether a buffer is structured, so keying on `UsedResource.stride == 0` without excluding FSPX would silently misaddress indexed FSPX structured buffers. 2. More fundamentally, I do not have retail shader caches to verify whether non-FSPX `UsedResource.stride == 0` metadata always corresponds to `V#.STRIDE == 0` in the runtime descriptors (vs. missing metadata where dropping `vindex` would be wrong). Closing this PR rather than leaving an unverified metadata-to-descriptor assumption in the review queue.

Pull request closed

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!2359
No description provided.