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

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/2359 into main
fuzeofficlal commented 2026-11-25 11:44:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T11:44:25Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6603720160 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T11:44:25Z. --- 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.
Xvania7 commented 2026-11-25 12:03:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T11:55:43Z.

Review: APPROVED


Static review and local verification of 4e14e76:

  • Indexed buffer accesses with stride 0 lower as raw (falling through the raw-view path), while unaligned strides 1..3 continue to be rejected
  • emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse (passed)
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings
  • cargo xtask policy: 182 files ok
  • GitHub Actions Windows CI is verified green.

Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057140661 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359#pullrequestreview-6057140661). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T11:55:43Z. **Review:** APPROVED --- Static review and local verification of `4e14e76`: - Indexed buffer accesses with stride 0 lower as raw (falling through the raw-view path), while unaligned strides 1..3 continue to be rejected - `emit::stride_tests::indexed_buffer_accesses_with_stride_zero_lower_as_raw_while_one_to_three_refuse` (passed) - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings - `cargo xtask policy`: 182 files ok - GitHub Actions Windows CI is verified green. Approving.
catminou4 commented 2026-11-25 12:03:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:56:18Z.

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — indexed buffer accesses lowered with used-resource strides.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057148394 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359#pullrequestreview-6057148394). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:56:18Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — indexed buffer accesses lowered with used-resource strides.
steven-seagull27 commented 2026-11-25 14:07:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-25T13:35:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163987400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7163987400). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-25T13:35:00Z. --- 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.
Marvisak commented 2026-11-25 19:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:27:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170944783 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7170944783). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:27:58Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 20:05:31 +00:00
fuzeofficlal commented 2026-11-25 20:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:37:44Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7172557031 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2359#issuecomment-7172557031). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:37:44Z. --- 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

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