Shaders: split flat byte-offset accesses to structured buffers #984

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

@⁠CitizenCinema on GitHub · 2026-11-24 14:40 UTC · original
CitizenCinema:fix/structured-buffer-flat-offset → main · +275 −6 · 2 files · 1 commits · open

Root cause

Table-bound StructuredBuffer / RWStructuredBuffer descriptors carry StructureByteStride in the host descriptor heap, and UsedResource.stride records that stride (>= 4, multiple of 4; raw ByteAddressBuffer records stride = 1).

Previously, lower.rs only checked UsedResource.stride for indexed (idxen) buffer operations. Flat byte-offset accesses—scalar s_buffer_load_dword* in smem() and non-idxen buffer_load/buffer_store/buffer_atomic in buffer()—always annotated the handle as ByteAddressBuffer ((11, 0)) and passed the flat byte offset as the index argument.

On NVIDIA D3D12 (tested on RTX 5090), reading a StructuredBuffer<stride> heap descriptor through a ByteAddressBuffer handle bounds-checks any byte offset >= stride to 0. In GTA VI's vfx_proj_decal_hit_detection (CS_ComputeHitDetectionSkinnedResults, eeed82b877b44b5f), buffer B (s1+0) is a StructuredBuffer<56> read with s_buffer_load_dword: record 1 (byte_offset = 80 >= 56) returned base = 0, causing the shader to read A + 0 (which overlaps VIctory's descriptor heap 0x45495676 view tags), hit the loop abort ret before a workgroup barrier, and trigger a ~4.9 s DXGI_ERROR_DEVICE_HUNG TDR.

Fix

  • Added structured_stride(used) in crates/victory-shader/src/emit/lower.rs matching table-bound resources (RootType::Table) with stride >= 4 && stride % 4 == 0 (root descriptors have no D3D12 descriptor stride and stay raw (11, 0)).
  • Updated smem() (handling both ResourceType::Srv and ResourceType::Uav) and buffer() (index == None loads, stores, and atomics) to annotate structured handles as (12 | uav, stride) and split each flat byte address into (addr / stride, addr % stride) (one dword at a time for multi-dword loads/stores so cross-element accesses stay in-bounds).
  • Added hardware + WARP regression test structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first in crates/victory-shader/src/emit/valu_tests.rs verifying s_buffer_load_dword and flat buffer_load_dword offen across elements 0, 1, and 2 of a StructuredBuffer<56>.

Verification

  • cargo test -p victory-shader: 121 passed, 0 failed (including the new regression test on both RTX 5090 hardware and WARP) and cargo test -p victory-gpu: 50 passed, 0 failed.
  • Isolated GPU harness of eeed82b877b44b5f with B bound as StructuredBuffer<56> and A + 0 populated with 0x45495676 tags: previously hung u6 = 1 in 4896 ms (DEVICE_HUNG); after fix, both u6 = 0 (61.5 ms) and u6 = 1 (52.2 ms) succeed.
  • Offline validation across all 26,084 programs in shaders.rpf (translate --validate --pipelines --list): 21,973 emitted, 21,645 RTX 5090 PSOs created, 0 new DXIL validator errors.
  • Combined with the companion unaligned buffer SRV fix (fix/unaligned-buffer-srv), GTA VI ran live on RTX 5090 for 8m19s with no VICTORY_SKIP_PIPELINES (0 slow submissions, 0 GPU hangs, eeed82b877b44b5f executing cleanly across u6 = 0 and u6 = 1 every frame).
**@⁠CitizenCinema** on GitHub · 2026-11-24 14:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/984) `CitizenCinema:fix/structured-buffer-flat-offset` → `main` · +275 −6 · 2 files · 1 commits · open ### Root cause Table-bound `StructuredBuffer` / `RWStructuredBuffer` descriptors carry `StructureByteStride` in the host descriptor heap, and `UsedResource.stride` records that stride (`>= 4`, multiple of 4; raw `ByteAddressBuffer` records `stride = 1`). Previously, `lower.rs` only checked `UsedResource.stride` for indexed (`idxen`) buffer operations. Flat byte-offset accesses—scalar `s_buffer_load_dword*` in `smem()` and non-`idxen` `buffer_load`/`buffer_store`/`buffer_atomic` in `buffer()`—always annotated the handle as `ByteAddressBuffer` (`(11, 0)`) and passed the flat byte offset as the index argument. On NVIDIA D3D12 (tested on RTX 5090), reading a `StructuredBuffer<stride>` heap descriptor through a `ByteAddressBuffer` handle bounds-checks any byte offset `>= stride` to `0`. In GTA VI's `vfx_proj_decal_hit_detection` (`CS_ComputeHitDetectionSkinnedResults`, `eeed82b877b44b5f`), buffer `B` (`s1+0`) is a `StructuredBuffer<56>` read with `s_buffer_load_dword`: record 1 (`byte_offset = 80 >= 56`) returned `base = 0`, causing the shader to read `A + 0` (which overlaps VIctory's descriptor heap `0x45495676` view tags), hit the loop abort `ret` before a workgroup barrier, and trigger a ~4.9 s `DXGI_ERROR_DEVICE_HUNG` TDR. ### Fix - Added `structured_stride(used)` in `crates/victory-shader/src/emit/lower.rs` matching table-bound resources (`RootType::Table`) with `stride >= 4 && stride % 4 == 0` (root descriptors have no D3D12 descriptor stride and stay raw `(11, 0)`). - Updated `smem()` (handling both `ResourceType::Srv` and `ResourceType::Uav`) and `buffer()` (`index == None` loads, stores, and atomics) to annotate structured handles as `(12 | uav, stride)` and split each flat byte address into `(addr / stride, addr % stride)` (one dword at a time for multi-dword loads/stores so cross-element accesses stay in-bounds). - Added hardware + WARP regression test `structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first` in `crates/victory-shader/src/emit/valu_tests.rs` verifying `s_buffer_load_dword` and flat `buffer_load_dword offen` across elements 0, 1, and 2 of a `StructuredBuffer<56>`. ### Verification - `cargo test -p victory-shader`: 121 passed, 0 failed (including the new regression test on both RTX 5090 hardware and WARP) and `cargo test -p victory-gpu`: 50 passed, 0 failed. - Isolated GPU harness of `eeed82b877b44b5f` with `B` bound as `StructuredBuffer<56>` and `A + 0` populated with `0x45495676` tags: previously hung `u6 = 1` in 4896 ms (`DEVICE_HUNG`); after fix, both `u6 = 0` (61.5 ms) and `u6 = 1` (52.2 ms) succeed. - Offline validation across all 26,084 programs in `shaders.rpf` (`translate --validate --pipelines --list`): 21,973 emitted, 21,645 RTX 5090 PSOs created, 0 new DXIL validator errors. - Combined with the companion unaligned buffer SRV fix (`fix/unaligned-buffer-srv`), GTA VI ran live on RTX 5090 for 8m19s with **no** `VICTORY_SKIP_PIPELINES` (0 slow submissions, 0 GPU hangs, `eeed82b877b44b5f` executing cleanly across `u6 = 0` and `u6 = 1` every frame).
Table-bound structured buffers carry StructureByteStride on the host descriptor. Flat byte-offset scalar loads (s_buffer_load_dword*) and non-idxen buffer loads/stores/atomics previously annotated these handles as ByteAddressBuffer (11, 0), causing NVIDIA drivers to bounds-check offsets >= stride to 0 (reproducing the RTX 5090 hit-detection TDR hang). Annotate table-bound structured buffers as (12 | uav, stride) and split flat byte addresses into (addr / stride, addr % stride); keep root descriptors raw (11, 0).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:15:51 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 14:54 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 5011645: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 14:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7135154653) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 5011645: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) was green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠R0D4X on GitHub · 2026-11-24 15:17 UTC · original

RTX 5080 (Blackwell, Wave32) A/B Verification of #984 + #986 + #452 (+ #946, #948, #688)

Environment:

  • GPU: NVIDIA GeForce RTX 5080 (Wave32: min=32, max=32), Windows 11
  • Base: main ffe310e
  • Build: cargo build --profile diag -p victory --features diagnostics
  • Env: VICTORY_D3D12_DRED=1, VICTORY_D3D12_DEBUG=1, VICTORY_LOG=victory_gpu=info, scripted menu entry (VICTORY_KEYS), no VICTORY_SKIP_WAVE64, no VICTORY_SHADER_LOOP_LIMIT override
  • Title: GTA VI Xbox Series X build 1.0.2.1 (no game assets or dumps attached)

Runs:

  • Run A (Baseline stack): ffe310e + #439, #578, #334, #492, #646, #635, #987, #669
  • Run B (+ new fixes): Run A + #984, #986, #452, #946, #948, #688
Metric Run A (Baseline) Run B (+ #984, #986, #452, #946, #948, #688)
Result Device Hung (0x887A0006) at 152.1 s 210.1 s (timeout), 0 crashes / 0 hangs
DRED stop List 21/29, cmd 4/12 (op 6): dispatch 12x1x1 [compute eeed82b877b44b5f] (4293 ms) None (eeed82b877b44b5f bound & ran cleanly from frame 1542 onward)
slow host submission (>250 ms) 27 (849–901 ms every world frame, containing compute 9146291b38ea9ce1) 0
World GPU time / frame 45–980 ms (frequent 500–980 ms spikes) 116–139 ms steady
World FPS (diag + DRED + Debug Layer) 0.7–1.6 fps 1.4–1.6 fps (CPU-bound by preparing ~235 ms + copying back ~243–356 ms)
Runtime D3D12 Debug Layer errors 0 (only the 4 startup probes: 1M view heap cap + B5G5R5A1/B4G4R4A4) 0
Dynamic descriptor drops (NVIDIA 1M cap) dropped=256 (n=178) dropped=512 (n=254, even with #688 reclaiming finished lists)

Takeaways:

  1. #984 + #986 eliminate the deterministic eeed82b877b44b5f TDR hang on RTX 5080 (Wave32) without needing VICTORY_SKIP_WAVE64.
  2. #452 eliminates all 27 recurring ~850–900 ms GPU stalls (9146291b38ea9ce1), dropping peak world GPU time from ~980 ms to 116–139 ms.
  3. Interaction note for #986 + #688 / #747 (#949): On NVIDIA's 1M capped shader-visible view heap (MIN_DYNAMIC = 65,536), promoting unaligned SRV tables to fresh dynamic slots in #986 pushed dynamic slot drops from 256 to 512 (n=254) even with #688 active — reinforcing the need for #949.
  4. The world image remains black (subtitles/UI render) due to refused wave64 mesh shaders (#578) and untranslated lighting/BVH shaders (#995, #704, #710, #979).
**@⁠R0D4X** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7135779770) ### RTX 5080 (Blackwell, Wave32) A/B Verification of #984 + #986 + #452 (+ #946, #948, #688) **Environment:** - GPU: NVIDIA GeForce RTX 5080 (Wave32: `min=32, max=32`), Windows 11 - Base: `main` `ffe310e` - Build: `cargo build --profile diag -p victory --features diagnostics` - Env: `VICTORY_D3D12_DRED=1`, `VICTORY_D3D12_DEBUG=1`, `VICTORY_LOG=victory_gpu=info`, scripted menu entry (`VICTORY_KEYS`), **no** `VICTORY_SKIP_WAVE64`, **no** `VICTORY_SHADER_LOOP_LIMIT` override - Title: GTA VI Xbox Series X build `1.0.2.1` (no game assets or dumps attached) **Runs:** - **Run A (Baseline stack):** `ffe310e` + `#439`, `#578`, `#334`, `#492`, `#646`, `#635`, `#987`, `#669` - **Run B (+ new fixes):** Run A + `#984`, `#986`, `#452`, `#946`, `#948`, `#688` | Metric | Run A (Baseline) | Run B (+ `#984`, `#986`, `#452`, `#946`, `#948`, `#688`) | |---|---|---| | Result | **Device Hung (`0x887A0006`) at 152.1 s** | **210.1 s (timeout), 0 crashes / 0 hangs** | | DRED stop | List 21/29, cmd 4/12 (`op 6`): `dispatch 12x1x1 [compute eeed82b877b44b5f]` (`4293 ms`) | None (`eeed82b877b44b5f` bound & ran cleanly from frame 1542 onward) | | `slow host submission` (>250 ms) | **27** (`849–901 ms` every world frame, containing `compute 9146291b38ea9ce1`) | **0** | | World GPU time / frame | `45–980 ms` (frequent `500–980 ms` spikes) | **`116–139 ms` steady** | | World FPS (diag + DRED + Debug Layer) | `0.7–1.6 fps` | `1.4–1.6 fps` (CPU-bound by `preparing` ~235 ms + `copying back` ~243–356 ms) | | Runtime D3D12 Debug Layer errors | `0` (only the 4 startup probes: 1M view heap cap + `B5G5R5A1`/`B4G4R4A4`) | `0` | | Dynamic descriptor drops (NVIDIA 1M cap) | `dropped=256` (`n=178`) | `dropped=512` (`n=254`, even with `#688` reclaiming finished lists) | **Takeaways:** 1. **`#984` + `#986` eliminate the deterministic `eeed82b877b44b5f` TDR hang** on RTX 5080 (Wave32) without needing `VICTORY_SKIP_WAVE64`. 2. **`#452` eliminates all 27 recurring ~850–900 ms GPU stalls** (`9146291b38ea9ce1`), dropping peak world GPU time from ~980 ms to `116–139 ms`. 3. **Interaction note for `#986` + `#688` / `#747` (`#949`):** On NVIDIA's 1M capped shader-visible view heap (`MIN_DYNAMIC = 65,536`), promoting unaligned SRV tables to `fresh` dynamic slots in `#986` pushed dynamic slot drops from `256` to `512` (`n=254`) even with `#688` active — reinforcing the need for `#949`. 4. The world image remains black (subtitles/UI render) due to refused wave64 mesh shaders (`#578`) and untranslated lighting/BVH shaders (`#995`, `#704`, `#710`, `#979`).
Author
Owner

@⁠SantannaCarlos on GitHub · 2026-11-24 15:50 UTC · original

In-game data for this PR on an RTX 4070 (Windows 11): diagnostics build, Series X mode, VICTORY_SHADER_LOOP_LIMIT=64, DRED, Enter-only input to the world, runs of 10 minutes. Every tree is main ffe310e + #493 + #439 (with #223, #233, #320) + #116 and a local tracing patch; the rows add:

Added Result
first commit of #1019 device hung 7 s after the first bind of eeed82b877b44b5f; DRED stops at command 6 of 11, the second of its two dispatches in that list
first commit of #1019, #876 hung 3 s after the first bind, same command
#1019 at 617aba9, #876, this PR no stop: the pass ran from its first bind (frame 2695) to the end of the run, 5 min 43 s
#1019 at 85d813c, #876, this PR, #688 no stop, 5 min 14 s after the first bind
#1019 at 85d813c, #876, this PR, #949 no stop, 5 min 7 s after the first bind

So 2 of 2 hung in that dispatch without this PR and 3 of 3 ran to the time limit with it, which fits your reading of the second dispatch. Caveat: between the two groups #1019 also went from its first commit to its full head (which adds unordered views off an element), so this is not an A/B of this PR alone.

**@⁠SantannaCarlos** on GitHub · 2026-11-24 15:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7136693841) In-game data for this PR on an RTX 4070 (Windows 11): diagnostics build, Series X mode, `VICTORY_SHADER_LOOP_LIMIT=64`, DRED, Enter-only input to the world, runs of 10 minutes. Every tree is `main` `ffe310e` + #493 + #439 (with #223, #233, #320) + #116 and a local tracing patch; the rows add: | Added | Result | |---|---| | first commit of #1019 | device hung 7 s after the first bind of `eeed82b877b44b5f`; DRED stops at `command 6 of 11`, the second of its two dispatches in that list | | first commit of #1019, #876 | hung 3 s after the first bind, same command | | #1019 at `617aba9`, #876, this PR | no stop: the pass ran from its first bind (frame 2695) to the end of the run, 5 min 43 s | | #1019 at `85d813c`, #876, this PR, #688 | no stop, 5 min 14 s after the first bind | | #1019 at `85d813c`, #876, this PR, #949 | no stop, 5 min 7 s after the first bind | So 2 of 2 hung in that dispatch without this PR and 3 of 3 ran to the time limit with it, which fits your reading of the second dispatch. Caveat: between the two groups #1019 also went from its first commit to its full head (which adds unordered views off an element), so this is not an A/B of this PR alone.
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-24 15:56 UTC · original

RTX 2070 SUPER (Turing, Wave32), driver 617.42, Windows 11: this PR + CitizenCinema:fix/unaligned-buffer-srv clears the eeed82b877b44b5f hang, and a scalar-only control still hangs.

Diag build, Series X mode, VICTORY_D3D12_DRED=1, default loop limit, Enter-only scripted input into the world, 30-minute runs. Common tree: main ffe310e + #493 + #587 + #282 + #876 + #67 + #490 + #464 + alessiodeia:fix/reuse-aligned-cbv-tables (#840) + alessiodeia:perf/fast-texture-content-hash (#916).

Added Result
a local scalar-only change: s_buffer_load_dword* on a table SRV with a used stride ≥ 4 (multiple of 4) annotated StructuredBuffer<stride>, address split into (addr & ~3) / stride, % stride; no vector offen change, no unaligned-SRV change 2 of 2 hung, 12 s after the first bind: DRED list 21 of 28, command 4 of 9 (op 6), dispatch 12x1x1 [compute eeed82b877b44b5f]
this PR at 5011645 + fix/unaligned-buffer-srv at d8d7c2c no stop: first bind at frame 5280, then 21.5 min to the time limit with 0 device removals; world at 0.4–1.5 fps

So on this card the scalar split alone is not enough. The flat vector-load part of this PR, the unaligned-view companion, or both are needed. Two details from the hung runs:

  • The DRED dump shows the title's view for the 56-byte record as structured (Format 0, NumElements 1, StructureByteStride 56), so the structured annotation matches the descriptor here.
  • The record's dword at +24 (title memory) was 0x70008, an offset into the 182,452,224-byte SRV at s0+304. The title has no CPU mapping at that offset, so its contents are whatever the host copy holds there.

Synthetic check of the underlying mismatch on the same GPU: a raw rawBufferLoad through a StructuredBuffer<56> descriptor at byte 80 returned dword 40 on NVIDIA and dword 20 on WARP.

No game data attached. AI-assisted (Claude Code).

**@⁠alessiodeia** on GitHub · 2026-11-24 15:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7136875713) **RTX 2070 SUPER (Turing, Wave32), driver 617.42, Windows 11: this PR + `CitizenCinema:fix/unaligned-buffer-srv` clears the `eeed82b877b44b5f` hang, and a scalar-only control still hangs.** Diag build, Series X mode, `VICTORY_D3D12_DRED=1`, default loop limit, Enter-only scripted input into the world, 30-minute runs. Common tree: `main` `ffe310e` + #493 + #587 + #282 + #876 + #67 + #490 + #464 + `alessiodeia:fix/reuse-aligned-cbv-tables` (#840) + `alessiodeia:perf/fast-texture-content-hash` (#916). | Added | Result | |---|---| | a local scalar-only change: `s_buffer_load_dword*` on a table SRV with a used stride ≥ 4 (multiple of 4) annotated `StructuredBuffer<stride>`, address split into `(addr & ~3) / stride`, `% stride`; no vector `offen` change, no unaligned-SRV change | **2 of 2 hung**, 12 s after the first bind: DRED list 21 of 28, `command 4 of 9 (op 6)`, `dispatch 12x1x1 [compute eeed82b877b44b5f]` | | this PR at `5011645` + `fix/unaligned-buffer-srv` at `d8d7c2c` | **no stop**: first bind at frame 5280, then 21.5 min to the time limit with 0 device removals; world at 0.4–1.5 fps | So on this card the scalar split alone is not enough. The flat vector-load part of this PR, the unaligned-view companion, or both are needed. Two details from the hung runs: - The DRED dump shows the title's view for the 56-byte record as structured (`Format 0, NumElements 1, StructureByteStride 56`), so the structured annotation matches the descriptor here. - The record's dword at +24 (title memory) was `0x70008`, an offset into the 182,452,224-byte SRV at `s0+304`. The title has no CPU mapping at that offset, so its contents are whatever the host copy holds there. Synthetic check of the underlying mismatch on the same GPU: a raw `rawBufferLoad` through a `StructuredBuffer<56>` descriptor at byte 80 returned dword 40 on NVIDIA and dword 20 on WARP. No game data attached. AI-assisted (Claude Code).
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 16:47 UTC · original

Reviewed on Windows 11 / Rust 1.98.1, 5011645 on current main (ffe310e, merges as it stands), isolated target dir. Verified: cargo test -p victory-shader --lib 121 passed / 1 ignored including the new structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first (run on the hardware GPU here, under ONE_AT_A_TIME — good, that lock is the one #383 missed); clippy --all-targets --all-features --locked -D warnings clean; cargo build --release -p victory builds.

The test pins the bug, red and green. With lower.rs reverted to main and the test kept, it fails on hardware:

assertion `left == right` failed: hardware: s_buffer_load_dword at byte 24 = 0xa0000c13, want 0xa000060d

i.e. the flat byte-offset load at byte 24 of a 56-byte-stride structured buffer read a dword out of element 0 instead of element 0's later bytes — exactly "elements past the first are dropped". With the branch's lowering it passes. The test is also the right shape: the same dword read two ways (indexed s_buffer_load_dword and flat buffer_load_dword offen) and asserted equal, so it is a differential test, not a golden value.

What I checked in the lowering, and it held. structured_stride gates on root == Table && stride >= 4 && stride % 4 == 0, so root descriptors (no host stride) and raw views (stride = 1) stay on the old raw path, as the comment says. The structured annotation (12 | uav, stride) is the same props pair the already-existing indexed path uses (lower.rs:6317-area), so loads, stores and atomics now agree on one annotation instead of two. The (index, offset) split is UDiv/URem by a constant stride, and the operand order [h, idx, eoff, mask, al] matches the indexed path's [index, off, iu] shape with the same mask = 1, align = 4. All four flat paths are covered — buffer_load (the f32 loop), atomics, and both store paths — and each is guarded by !typed && index.is_none(), so typed and indexed accesses are untouched.

Two things worth a second look, neither blocking.

  • The alignment argument stays 4 while the element offset is now URem(a, stride) — fine for dword-sized flat accesses, but a flat byte or short access (buffer_load_ubyte/_ushort with a non-4-aligned addr) would hand the validator an offset the structured annotation may reject. If the title only ever does dword-aligned flat accesses to structured buffers, the al = 4 is right and a comment saying so would settle it; if not, the alignment should come from the access width.
  • UDiv/URem by the stride are emitted per access; for a loop of flat loads that is a divide per element where the console's raw view does none. With the stride a compile-time constant the backend usually turns it into a multiply-shift, so I do not expect this to show up, but it is the one place this PR adds work per element, and a VICTORY_GPU_TIMING run on the world would be the way to confirm it costs nothing.

Bottom line: the defect is real, the test proves it both ways, and the lowering is consistent with the indexed path it mirrors. The only open question is the alignment assumption for sub-dword flat accesses.

**@⁠adamdotpy** on GitHub · 2026-11-24 16:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7138216683) Reviewed on Windows 11 / Rust 1.98.1, `5011645` on current `main` (`ffe310e`, merges as it stands), isolated target dir. Verified: `cargo test -p victory-shader --lib` 121 passed / 1 ignored including the new `structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first` (run on the hardware GPU here, under `ONE_AT_A_TIME` — good, that lock is the one #383 missed); clippy `--all-targets --all-features --locked -D warnings` clean; `cargo build --release -p victory` builds. **The test pins the bug, red and green.** With `lower.rs` reverted to `main` and the test kept, it fails on hardware: ``` assertion `left == right` failed: hardware: s_buffer_load_dword at byte 24 = 0xa0000c13, want 0xa000060d ``` i.e. the flat byte-offset load at byte 24 of a 56-byte-stride structured buffer read a dword out of element 0 instead of element 0's later bytes — exactly "elements past the first are dropped". With the branch's lowering it passes. The test is also the right shape: the same dword read two ways (indexed `s_buffer_load_dword` and flat `buffer_load_dword offen`) and asserted equal, so it is a differential test, not a golden value. **What I checked in the lowering, and it held.** `structured_stride` gates on `root == Table && stride >= 4 && stride % 4 == 0`, so root descriptors (no host stride) and raw views (`stride = 1`) stay on the old raw path, as the comment says. The structured annotation `(12 | uav, stride)` is the same props pair the already-existing indexed path uses (`lower.rs:6317`-area), so loads, stores and atomics now agree on one annotation instead of two. The `(index, offset)` split is `UDiv`/`URem` by a constant stride, and the operand order `[h, idx, eoff, mask, al]` matches the indexed path's `[index, off, iu]` shape with the same `mask = 1`, `align = 4`. All four flat paths are covered — `buffer_load` (the f32 loop), atomics, and both store paths — and each is guarded by `!typed && index.is_none()`, so typed and indexed accesses are untouched. **Two things worth a second look, neither blocking.** - The alignment argument stays `4` while the element offset is now `URem(a, stride)` — fine for dword-sized flat accesses, but a flat *byte* or *short* access (`buffer_load_ubyte`/`_ushort` with a non-4-aligned `addr`) would hand the validator an offset the structured annotation may reject. If the title only ever does dword-aligned flat accesses to structured buffers, the `al = 4` is right and a comment saying so would settle it; if not, the alignment should come from the access width. - `UDiv`/`URem` by the stride are emitted per access; for a loop of flat loads that is a divide per element where the console's raw view does none. With the stride a compile-time constant the backend usually turns it into a multiply-shift, so I do not expect this to show up, but it is the one place this PR adds work per element, and a `VICTORY_GPU_TIMING` run on the world would be the way to confirm it costs nothing. Bottom line: the defect is real, the test proves it both ways, and the lowering is consistent with the indexed path it mirrors. The only open question is the alignment assumption for sub-dword flat accesses.
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 18:04 UTC · original

I found a scalar vertex-buffer case worth covering alongside the structured-host-view compute test. On a physical RTX 5070, a draw-side observer matched the active vertex shader by its guest container and inspected its selected graphics root table (slot 0, offset 0). The title supplied a buffer SRV with DXGI_FORMAT_R32_TYPELESS, RAW set, 32 elements and StructureByteStride = 0. The same shader's native table metadata says stride 64. This was observed on a local baseline that renders the account picker.

Offline replay of that exact shader on ffe310eb produced 16 raw byte-addressed scalar reads. Replay on this PR at 50116450 produced a structured handle with stride 64 and 16 index/offset splits. Both passed the Windows SDK DXIL validator. Comparing the emitted vertex programs, the values from these reads feed all four position output components. #995 at 78c8078a also produced the structured version for this shader.

This provides a concrete input for the raw-host-view concern in #437. For a synthetic regression test, the observed combination is a 64-byte guest stride with a 32-DWORD raw host SRV. The descriptor observation and translation comparison are verified; the effect on the picture has not yet been isolated in a run where only this lowering differs.

**@⁠jeremygold02** on GitHub · 2026-11-24 18:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7140118647) I found a scalar vertex-buffer case worth covering alongside the structured-host-view compute test. On a physical RTX 5070, a draw-side observer matched the active vertex shader by its guest container and inspected its selected graphics root table (slot 0, offset 0). The title supplied a buffer SRV with `DXGI_FORMAT_R32_TYPELESS`, RAW set, 32 elements and `StructureByteStride = 0`. The same shader's native table metadata says stride 64. This was observed on a local baseline that renders the account picker. Offline replay of that exact shader on `ffe310eb` produced 16 raw byte-addressed scalar reads. Replay on this PR at `50116450` produced a structured handle with stride 64 and 16 index/offset splits. Both passed the Windows SDK DXIL validator. Comparing the emitted vertex programs, the values from these reads feed all four position output components. #995 at `78c8078a` also produced the structured version for this shader. This provides a concrete input for the raw-host-view concern in #437. For a synthetic regression test, the observed combination is a 64-byte guest stride with a 32-DWORD raw host SRV. The descriptor observation and translation comparison are verified; the effect on the picture has not yet been isolated in a run where only this lowering differs.
Author
Owner

@⁠clypeal6 on GitHub · 2026-11-24 19:02 UTC · original

Independent confirmation of this root cause from a second shader and GPU.

Hardware: RTX 4070 Laptop GPU, Windows 11, title v1.0.2.1, Series X mode.

The shader: compute 42683eebec081520. It reads its loop bounds with s_buffer_load_dwordx4 from a 16-byte StructuredBuffer (s1+0). Title and host copies both hold [1024, 512, 2560, 1440]. On NVIDIA the raw read returns 0 past the first dword, so the shader divides by zero and its loops run to LOOP_LIMIT.

In game: VICTORY_GPU_TIMING=1 timed it at 1.5–1.7 s per 128×64 dispatch, and DEVICE_HUNG (0x887A0006) followed after 2–10 minutes in the world.

Our fix: we made the same change independently. Unindexed s_buffer_load, buffer_load, buffer_store and buffer_atomic use (12 | uav, stride) and (byte / stride, byte % stride) when the stride is above 4. With the default loop limit:

Without the fix With the fix
42683eebec081520 per dispatch ~1,538 ms 2 ms
Slow submissions in 8 min 83 5
Result Hung at 456 s No hang

Your version restricts the change to table-bound resources and also covers stride 4, which is more careful than ours. We'd suggest #984 over a second PR.

A GPU test that reproduces it, in case it helps. It runs a scalar load of dword 3 from a 16-byte structured element:

  • Setup: View::Buffer { stride: Stride::Structured(16) }, with s_buffer_load_dwordx4 s[12:15], s[4:7], 0, then dword 3 stored from every lane.
  • Without the change on the RTX 4070: all 32 lanes read 0.
  • With it: all 32 lanes read 1440.

It's at clypeal6/VIctory, branch fix/structured-buffer-reads, in waterfall_tests.rs: a_scalar_load_reads_a_structured_buffer_element_whole. You're welcome to take it.

Related:

  • AnyXboxX's integration currently runs with VICTORY_SHADER_LOOP_LIMIT=32 because "translated loops were almost endless". This bug is very likely the reason for that.
  • It probably also explains NVIDIA world hangs reported in #625, #619 and #653.

AI-assisted (Claude Code). Measured on our own copy of the game. No game data shared.

**@⁠clypeal6** on GitHub · 2026-11-24 19:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7141510914) Independent confirmation of this root cause from a second shader and GPU. **Hardware:** RTX 4070 Laptop GPU, Windows 11, title v1.0.2.1, Series X mode. **The shader:** compute `42683eebec081520`. It reads its loop bounds with `s_buffer_load_dwordx4` from a 16-byte `StructuredBuffer` (`s1+0`). Title and host copies both hold `[1024, 512, 2560, 1440]`. On NVIDIA the raw read returns 0 past the first dword, so the shader divides by zero and its loops run to `LOOP_LIMIT`. **In game:** `VICTORY_GPU_TIMING=1` timed it at 1.5–1.7 s per 128×64 dispatch, and `DEVICE_HUNG` (0x887A0006) followed after 2–10 minutes in the world. **Our fix:** we made the same change independently. Unindexed `s_buffer_load`, `buffer_load`, `buffer_store` and `buffer_atomic` use `(12 | uav, stride)` and `(byte / stride, byte % stride)` when the stride is above 4. With the default loop limit: | | Without the fix | With the fix | |---|---|---| | `42683eebec081520` per dispatch | ~1,538 ms | 2 ms | | Slow submissions in 8 min | 83 | 5 | | Result | Hung at 456 s | No hang | Your version restricts the change to table-bound resources and also covers stride 4, which is more careful than ours. We'd suggest #984 over a second PR. **A GPU test that reproduces it,** in case it helps. It runs a scalar load of dword 3 from a 16-byte structured element: - **Setup:** `View::Buffer { stride: Stride::Structured(16) }`, with `s_buffer_load_dwordx4 s[12:15], s[4:7], 0`, then dword 3 stored from every lane. - **Without the change** on the RTX 4070: all 32 lanes read 0. - **With it:** all 32 lanes read 1440. It's at clypeal6/VIctory, branch `fix/structured-buffer-reads`, in `waterfall_tests.rs`: `a_scalar_load_reads_a_structured_buffer_element_whole`. You're welcome to take it. **Related:** - AnyXboxX's integration currently runs with `VICTORY_SHADER_LOOP_LIMIT=32` because "translated loops were almost endless". This bug is very likely the reason for that. - It probably also explains NVIDIA world hangs reported in #625, #619 and #653. AI-assisted (Claude Code). Measured on our own copy of the game. No game data shared.
@ -6401,1 +6470,4 @@
}
if !typed
&& index.is_none()
&& let Some(stride) = structured_stride(used)
Author
Owner

@⁠Rezwo on GitHub · 2026-11-24 19:41 UTC · original

Could we verify that all descriptor choices have the same layout before using this stride? For merged sources, used_kind() takes the first alternative's metadata, while handle() selects the actual descriptor at runtime. If a flat load can select between stride 56 and stride 32, byte offset 80 becomes (1, 24) with the first stride even when the second view is selected; that view needs (2, 16).

Either reject differing layouts during lowering or use each choice's own layout. A two-descriptor regression would cover this; the current stride-56 test already covers reads past the first element. This is from source inspection, not a game repro.

**@⁠Rezwo** on GitHub · 2026-11-24 19:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#discussion_r4685537007) Could we verify that all descriptor choices have the same layout before using this stride? For merged sources, `used_kind()` takes the first alternative's metadata, while `handle()` selects the actual descriptor at runtime. If a flat load can select between stride 56 and stride 32, byte offset 80 becomes `(1, 24)` with the first stride even when the second view is selected; that view needs `(2, 16)`. Either reject differing layouts during lowering or use each choice's own layout. A two-descriptor regression would cover this; the current stride-56 test already covers reads past the first element. This is from source inspection, not a game repro.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:31 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#issuecomment-7148591775) <!-- victory-triage v1 head=501164509d220fd643300e080b8e68bb498ce562 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
@ -6401,1 +6470,4 @@
}
if !typed
&& index.is_none()
&& let Some(stride) = structured_stride(used)
Author
Owner

@⁠Rezwo on GitHub · 2026-11-25 06:21 UTC · original

Follow-up: reproduced on unchanged PR head 501164509d220fd643300e080b8e68bb498ce562, Windows / RTX 2080 Ti, with a synthetic one-thread shader; no game files.

The shader selects between table-bound structured SRVs (strides 56 and 32) via a runtime root constant, then reads byte offset 80 through scalar s_buffer_load_dword and flat vector buffer_load_dword offen.

  • Pristine: original test passes, exit 0.
  • Mixed strides: hardware choice 0 correct; choice 1 returns 0x00000000 for both reads instead of 0xb000141b. Original test passes, added test fails, exit 101.
  • WARP: both choices correct.
  • Corrected control: both metadata and actual views use stride 56, each backed by 42 distinctly tagged dwords. Both choices correct on hardware and WARP; 2 tests pass, exit 0.
  • Rollback: pristine source hash restored, original test passes, exit 0.

Each scenario started with cargo clean -p victory-shader, then:

cargo test --locked -p victory-shader structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first -- --nocapture

This is a test-only patch, not a compiler fix or an in-game diagnosis. Apply against this head with git -c core.autocrlf=false apply. Expected patched file SHA-256: 1eccfc898b3b6a207e74ea2955f59a268dfabfde183de04a4a61bde543f356af.

AI-assisted (OpenAI Codex); measurements executed locally.

Synthetic regression patch
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -1108,3 +1108,201 @@
     }
     assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available");
 }
+
+#[test]
+fn structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first_mixed_stride() {
+    use super::host::Stride;
+
+    // Select one of two structured SRVs at runtime, then read flat byte offset 80.
+    let mut words = Vec::new();
+    words.push(s_mov_b32(5, 0x80)); // s5 = 0
+    words.extend_from_slice(&s_load_dwordx4(8, 4)); // s[8:11] = UAV at table+0
+    // s_load_dwordx4 s[12:15], s[4:5], 32 (table+8 dwords = slot 1)
+    words.extend_from_slice(&[
+        0x3D << 26 | 0x02 << 18 | (12 << 6) | (4 >> 1),
+        125 << 25 | 32,
+    ]);
+    // Slot 2: stride-32 descriptor at table+64.
+    words.extend_from_slice(&[0xF408_0402, 0xFA00_0040]);
+    words.extend_from_slice(&[
+        0xBF06_8001, // s_cmp_eq_u32 s1, 0
+        0x8594_100C, // s_cselect_b64 s[20:21], s[12:13], s[16:17]
+        0x8596_120E, // s_cselect_b64 s[22:23], s[14:15], s[18:19]
+    ]);
+    // s_buffer_load_dword s24, s[20:23], s0
+    words.extend_from_slice(&[0x3D << 26 | 0x08 << 18 | (24 << 6) | (20 >> 1), 0]);
+    words.push(vop1(0x001, 1, sgpr(0))); // v1 = s0 (flat byte offset)
+    // buffer_load_dword v2, v1, s[20:23], 0 offen
+    words.extend_from_slice(&[
+        0x38 << 26 | 0x0C << 18 | 0x1000,
+        0x80 << 24 | ((20 >> 2) << 16) | (2 << 8) | 1,
+    ]);
+    words.push(vop1(0x001, 0, sgpr(24))); // v0 = s24
+    words.extend_from_slice(&buffer_store_dword(0, 8, 0));
+    words.extend_from_slice(&buffer_store_dword(2, 8, 4));
+    words.push(S_ENDPGM);
+
+    let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
+    let native = NativeProgram {
+        stage: HwStage::Cs,
+        wave64: false,
+        vgprs: 4,
+        layout: vec![
+            RootParam {
+                root: RootType::Constants,
+                table_offset_dwords: 0,
+                sgprs: 2,
+                base_register: 0,
+                user_data: 0,
+                slot: 0,
+            },
+            RootParam {
+                root: RootType::Table,
+                table_offset_dwords: 0,
+                sgprs: 1,
+                base_register: 0,
+                user_data: 4,
+                slot: 1,
+            },
+        ],
+        used: vec![
+            UsedResource {
+                kind: ResourceType::Uav,
+                root: RootType::Table,
+                table_offset_dwords: 0,
+                lower_bound: 0,
+                stride: 0,
+                dwords: 4,
+                user_data: 4,
+                slot: 1,
+            },
+            UsedResource {
+                kind: ResourceType::Srv,
+                root: RootType::Table,
+                table_offset_dwords: 8,
+                lower_bound: 0,
+                stride: 56,
+                dwords: 4,
+                user_data: 4,
+                slot: 1,
+            },
+            UsedResource {
+                kind: ResourceType::Srv,
+                root: RootType::Table,
+                table_offset_dwords: 16,
+                lower_bound: 0,
+                stride: 32,
+                dwords: 4,
+                user_data: 4,
+                slot: 1,
+            },
+        ],
+        io: StageIo::Cs(ComputeIo {
+            rsrc2: 5 << 1,
+            threads: [1, 1, 1],
+        }),
+        code,
+    };
+
+    let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
+    let st = structure::structure(&p).expect("structure");
+    let res =
+        resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource::track");
+    let io = io::raise(&p, &native).expect("io::raise");
+    let lowered = lower::lower(&lower::Parts {
+        native: &native,
+        p: &p,
+        st: &st,
+        io: &io,
+        res: &res,
+        inputs: Vec::new(),
+        outputs: Vec::new(),
+        prims: Vec::new(),
+        mesh_stride: 0,
+    })
+    .expect("lower");
+
+    let shader = HostShader {
+        stage: HwStage::Cs,
+        dxil: lowered.dxil,
+        user_data: lowered.user_data,
+        samplers: lowered.samplers,
+        static_samplers: Vec::new(),
+        root_cbvs: lowered.root_cbvs,
+        root_srvs: lowered.root_srvs,
+    };
+    if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
+        let mut copy = shader.dxil.clone();
+        v.validate(&mut copy).expect("DXIL validation failed");
+    }
+
+    // Distinct per-buffer tags also catch accidental selection of the wrong SRV.
+    let data: Vec<u32> = (0..42u32).map(|i| 0xA000_0000 | (i * 0x101 + 7)).collect();
+    let narrow: Vec<u32> = (0..24u32).map(|i| 0xB000_0000 | (i * 0x101 + 7)).collect();
+    let views = [
+        View::RawUav(2),
+        View::Buffer {
+            data: &data,
+            stride: Stride::Structured(56),
+        },
+        View::Buffer {
+            data: &narrow,
+            stride: Stride::Structured(32),
+        },
+    ];
+
+    let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
+    let mut ran = 0;
+    let mut failures = Vec::new();
+    for (label, warp) in [("hardware", false), ("warp", true)] {
+        let Ok(host) = Host::new(warp) else {
+            eprintln!("{label}: unavailable");
+            continue;
+        };
+        let (root, pso) = host
+            .compute_pipeline(&shader)
+            .unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}"));
+        for (choice, input) in [&data, &narrow].into_iter().enumerate() {
+            let byte_off = 80u32;
+            let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
+            for u in &shader.user_data {
+                ud[u.index as usize] = match (u.root, u.slot) {
+                    (RootType::Constants, 0) => byte_off,
+                    (RootType::Table, 1) => 0,
+                    other => panic!("unexpected user data {other:?}"),
+                };
+            }
+            let selector = shader
+                .user_data
+                .iter()
+                .find(|u| u.root == RootType::Constants && u.slot == 0)
+                .expect("constant block")
+                .index as usize + 1;
+            ud[selector] = choice as u32;
+            let out = host
+                .dispatch(
+                    &root,
+                    &pso,
+                    &Dispatch {
+                        roots: vec![(0, Root::Constants(ud))],
+                        views: &views,
+                        samplers: &[],
+                        groups: [1, 1, 1],
+                    },
+                )
+                .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}"));
+            let want = input[(byte_off / 4) as usize];
+            let (scalar, vector) = (out[0][0], out[0][1]);
+            let msg = format!(
+                "{label}: choice={choice} byte={byte_off} scalar={scalar:#010x} vector={vector:#010x} expected={want:#010x}"
+            );
+            eprintln!("{msg}");
+            if scalar != want || vector != want {
+                failures.push(msg);
+            }
+        }
+        ran += 1;
+    }
+    assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available");
+    assert!(failures.is_empty(), "{}", failures.join("\n"));
+}

**@⁠Rezwo** on GitHub · 2026-11-25 06:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/984#discussion_r4691148118) Follow-up: reproduced on unchanged PR head `501164509d220fd643300e080b8e68bb498ce562`, Windows / RTX 2080 Ti, with a synthetic one-thread shader; no game files. The shader selects between table-bound structured SRVs (strides 56 and 32) via a runtime root constant, then reads byte offset 80 through scalar `s_buffer_load_dword` and flat vector `buffer_load_dword offen`. - Pristine: original test passes, exit 0. - Mixed strides: hardware choice 0 correct; choice 1 returns `0x00000000` for both reads instead of `0xb000141b`. Original test passes, added test fails, exit 101. - WARP: both choices correct. - Corrected control: both metadata and actual views use stride 56, each backed by 42 distinctly tagged dwords. Both choices correct on hardware and WARP; 2 tests pass, exit 0. - Rollback: pristine source hash restored, original test passes, exit 0. Each scenario started with `cargo clean -p victory-shader`, then: ```text cargo test --locked -p victory-shader structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first -- --nocapture ``` This is a test-only patch, not a compiler fix or an in-game diagnosis. Apply against this head with `git -c core.autocrlf=false apply`. Expected patched file SHA-256: `1eccfc898b3b6a207e74ea2955f59a268dfabfde183de04a4a61bde543f356af`. AI-assisted (OpenAI Codex); measurements executed locally. <details><summary>Synthetic regression patch</summary> ~~~diff --- a/crates/victory-shader/src/emit/valu_tests.rs +++ b/crates/victory-shader/src/emit/valu_tests.rs @@ -1108,3 +1108,201 @@ } assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available"); } + +#[test] +fn structured_buffer_flat_byte_offset_loads_reach_elements_past_the_first_mixed_stride() { + use super::host::Stride; + + // Select one of two structured SRVs at runtime, then read flat byte offset 80. + let mut words = Vec::new(); + words.push(s_mov_b32(5, 0x80)); // s5 = 0 + words.extend_from_slice(&s_load_dwordx4(8, 4)); // s[8:11] = UAV at table+0 + // s_load_dwordx4 s[12:15], s[4:5], 32 (table+8 dwords = slot 1) + words.extend_from_slice(&[ + 0x3D << 26 | 0x02 << 18 | (12 << 6) | (4 >> 1), + 125 << 25 | 32, + ]); + // Slot 2: stride-32 descriptor at table+64. + words.extend_from_slice(&[0xF408_0402, 0xFA00_0040]); + words.extend_from_slice(&[ + 0xBF06_8001, // s_cmp_eq_u32 s1, 0 + 0x8594_100C, // s_cselect_b64 s[20:21], s[12:13], s[16:17] + 0x8596_120E, // s_cselect_b64 s[22:23], s[14:15], s[18:19] + ]); + // s_buffer_load_dword s24, s[20:23], s0 + words.extend_from_slice(&[0x3D << 26 | 0x08 << 18 | (24 << 6) | (20 >> 1), 0]); + words.push(vop1(0x001, 1, sgpr(0))); // v1 = s0 (flat byte offset) + // buffer_load_dword v2, v1, s[20:23], 0 offen + words.extend_from_slice(&[ + 0x38 << 26 | 0x0C << 18 | 0x1000, + 0x80 << 24 | ((20 >> 2) << 16) | (2 << 8) | 1, + ]); + words.push(vop1(0x001, 0, sgpr(24))); // v0 = s24 + words.extend_from_slice(&buffer_store_dword(0, 8, 0)); + words.extend_from_slice(&buffer_store_dword(2, 8, 4)); + words.push(S_ENDPGM); + + let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect(); + let native = NativeProgram { + stage: HwStage::Cs, + wave64: false, + vgprs: 4, + layout: vec![ + RootParam { + root: RootType::Constants, + table_offset_dwords: 0, + sgprs: 2, + base_register: 0, + user_data: 0, + slot: 0, + }, + RootParam { + root: RootType::Table, + table_offset_dwords: 0, + sgprs: 1, + base_register: 0, + user_data: 4, + slot: 1, + }, + ], + used: vec![ + UsedResource { + kind: ResourceType::Uav, + root: RootType::Table, + table_offset_dwords: 0, + lower_bound: 0, + stride: 0, + dwords: 4, + user_data: 4, + slot: 1, + }, + UsedResource { + kind: ResourceType::Srv, + root: RootType::Table, + table_offset_dwords: 8, + lower_bound: 0, + stride: 56, + dwords: 4, + user_data: 4, + slot: 1, + }, + UsedResource { + kind: ResourceType::Srv, + root: RootType::Table, + table_offset_dwords: 16, + lower_bound: 0, + stride: 32, + dwords: 4, + user_data: 4, + slot: 1, + }, + ], + io: StageIo::Cs(ComputeIo { + rsrc2: 5 << 1, + threads: [1, 1, 1], + }), + code, + }; + + let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build"); + let st = structure::structure(&p).expect("structure"); + let res = + resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource::track"); + let io = io::raise(&p, &native).expect("io::raise"); + let lowered = lower::lower(&lower::Parts { + native: &native, + p: &p, + st: &st, + io: &io, + res: &res, + inputs: Vec::new(), + outputs: Vec::new(), + prims: Vec::new(), + mesh_stride: 0, + }) + .expect("lower"); + + let shader = HostShader { + stage: HwStage::Cs, + dxil: lowered.dxil, + user_data: lowered.user_data, + samplers: lowered.samplers, + static_samplers: Vec::new(), + root_cbvs: lowered.root_cbvs, + root_srvs: lowered.root_srvs, + }; + if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) { + let mut copy = shader.dxil.clone(); + v.validate(&mut copy).expect("DXIL validation failed"); + } + + // Distinct per-buffer tags also catch accidental selection of the wrong SRV. + let data: Vec<u32> = (0..42u32).map(|i| 0xA000_0000 | (i * 0x101 + 7)).collect(); + let narrow: Vec<u32> = (0..24u32).map(|i| 0xB000_0000 | (i * 0x101 + 7)).collect(); + let views = [ + View::RawUav(2), + View::Buffer { + data: &data, + stride: Stride::Structured(56), + }, + View::Buffer { + data: &narrow, + stride: Stride::Structured(32), + }, + ]; + + let _one = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner()); + let mut ran = 0; + let mut failures = Vec::new(); + for (label, warp) in [("hardware", false), ("warp", true)] { + let Ok(host) = Host::new(warp) else { + eprintln!("{label}: unavailable"); + continue; + }; + let (root, pso) = host + .compute_pipeline(&shader) + .unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}")); + for (choice, input) in [&data, &narrow].into_iter().enumerate() { + let byte_off = 80u32; + let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize]; + for u in &shader.user_data { + ud[u.index as usize] = match (u.root, u.slot) { + (RootType::Constants, 0) => byte_off, + (RootType::Table, 1) => 0, + other => panic!("unexpected user data {other:?}"), + }; + } + let selector = shader + .user_data + .iter() + .find(|u| u.root == RootType::Constants && u.slot == 0) + .expect("constant block") + .index as usize + 1; + ud[selector] = choice as u32; + let out = host + .dispatch( + &root, + &pso, + &Dispatch { + roots: vec![(0, Root::Constants(ud))], + views: &views, + samplers: &[], + groups: [1, 1, 1], + }, + ) + .unwrap_or_else(|e| panic!("{label}: dispatch failed: {e}")); + let want = input[(byte_off / 4) as usize]; + let (scalar, vector) = (out[0][0], out[0][1]); + let msg = format!( + "{label}: choice={choice} byte={byte_off} scalar={scalar:#010x} vector={vector:#010x} expected={want:#010x}" + ); + eprintln!("{msg}"); + if scalar != want || vector != want { + failures.push(msg); + } + } + ran += 1; + } + assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available"); + assert!(failures.is_empty(), "{}", failures.join("\n")); +} ~~~ </details>
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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