Shaders: query untyped buffer dimensions through a raw handle #129

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

@⁠vicennpacheco on GitHub · 2026-11-24 21:43 UTC · original
vicennpacheco:fix/raw-buffer-get-dimensions → main · +147 −4 · 2 files · 1 commits · open

Problem

victory-gpu (raw_window) converts structured buffer views into raw host views (DXGI_FORMAT_R32_TYPELESS, D3D12_BUFFER_SRV_FLAG_RAW), and lower::buffer() (crates/victory-shader/src/emit/lower.rs) lowers idxen structured buffer accesses to raw (ByteAddressBuffer, (11 | u, 0)) handles.

However, when a shader reads a buffer descriptor's record count (dword 2 -> dx.op.getDimensions), lower.rs still annotated Fields::Buffer with *idxen && format.is_none() && stride >= 4 as StructuredBuffer ((12 | u, stride)). Because props.0 & 0xFF was 12 instead of 11, it skipped the n / stride division right below (lower.rs:5687), returning the raw byte count instead of the element count against a raw host view (reproduced on hardware: a 128-byte buffer with stride = 16 returned 128 instead of 8).

Fix

Annotate untyped Fields::Buffer dimension queries as raw ((11 | u, 0)), matching buffer() and victory-gpu's raw_window, so the existing n / stride division returns the element count.

Verification

Tested on Windows 11, AMD Radeon Vega 8 iGPU (Ryzen 7 5825U, GCN 5 / gfx90c, AMD driver 31.0.21921.13001), Windows SDK dxil.dll 10.0.26100.0, Rust 1.98.1 (x86_64-pc-windows-msvc), without game files:

  • Added emit::tests::structured_buffer_record_count_matches_raw_host_view (failed before the fix with 128 != 8; passes after on both Vega 8 hardware and WARP, dxil.dll-validated)
  • VICTORY_D3D12_DEBUG=1: clean, no debug-layer errors
  • cargo clippy -p victory-shader --tests -- -D warnings: clean

(AI-assisted investigation and patch.)

**@⁠vicennpacheco** on GitHub · 2026-11-24 21:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/129) `vicennpacheco:fix/raw-buffer-get-dimensions` → `main` · +147 −4 · 2 files · 1 commits · open ### Problem `victory-gpu` (`raw_window`) converts structured buffer views into raw host views (`DXGI_FORMAT_R32_TYPELESS`, `D3D12_BUFFER_SRV_FLAG_RAW`), and `lower::buffer()` (`crates/victory-shader/src/emit/lower.rs`) lowers `idxen` structured buffer accesses to raw (`ByteAddressBuffer`, `(11 | u, 0)`) handles. However, when a shader reads a buffer descriptor's record count (dword 2 -> `dx.op.getDimensions`), `lower.rs` still annotated `Fields::Buffer` with `*idxen && format.is_none() && stride >= 4` as `StructuredBuffer` (`(12 | u, stride)`). Because `props.0 & 0xFF` was `12` instead of `11`, it skipped the `n / stride` division right below (`lower.rs:5687`), returning the raw byte count instead of the element count against a raw host view (reproduced on hardware: a 128-byte buffer with `stride = 16` returned `128` instead of `8`). ### Fix Annotate untyped `Fields::Buffer` dimension queries as raw (`(11 | u, 0)`), matching `buffer()` and `victory-gpu`'s `raw_window`, so the existing `n / stride` division returns the element count. ### Verification Tested on Windows 11, AMD Radeon Vega 8 iGPU (Ryzen 7 5825U, GCN 5 / `gfx90c`, AMD driver `31.0.21921.13001`), Windows SDK `dxil.dll` `10.0.26100.0`, Rust `1.98.1` (`x86_64-pc-windows-msvc`), without game files: - Added `emit::tests::structured_buffer_record_count_matches_raw_host_view` (failed before the fix with `128 != 8`; passes after on both Vega 8 hardware and WARP, `dxil.dll`-validated) - `VICTORY_D3D12_DEBUG=1`: clean, no debug-layer errors - `cargo clippy -p victory-shader --tests -- -D warnings`: clean *(AI-assisted investigation and patch.)*
`victory-gpu` backs structured buffer views with raw views (`raw_window`),
and `lower::buffer()` already lowers indexed structured buffer accesses
to `ByteAddressBuffer` (`(11 | u, 0)`) handles.

However, descriptor-size lowering (`getDimensions`) still annotated
`idxen` buffers with `stride >= 4` as `StructuredBuffer` (`(12 | u, stride)`),
skipping the `bytes / stride` division below it. Against a raw host view
this returns the raw byte count instead of the element count (e.g. 128
instead of 8 for a 16-byte-stride buffer).

Use a raw handle (`(11 | u, 0)`) for untyped buffers in `getDimensions`
so the existing `UDiv` by `used.stride` produces the element count.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:39 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 21:51 UTC · original

Independent test run on commit 79b5a82 (AMD RDNA4) — deterministic crash in the new test:

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test -p victory-shader --lib structured_buffer_record_count_matches_raw_host_view -- --nocapture: crashes deterministically with 0xc0000005 (STATUS_ACCESS_VIOLATION) both in parallel and when run alone (--test-threads=1).

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 21:51 UTC · [original](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7145492109) Independent test run on commit `79b5a82` (AMD RDNA4) — **deterministic crash in the new test**: - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test -p victory-shader --lib structured_buffer_record_count_matches_raw_host_view -- --nocapture`: crashes deterministically with `0xc0000005` (`STATUS_ACCESS_VIOLATION`) both in parallel and when run alone (`--test-threads=1`). *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠vicennpacheco on GitHub · 2026-11-24 22:28 UTC · original

Thanks for testing this on RDNA4!

I double-checked the emitted DXIL against dxc.exe -T cs_6_6 for ResourceDescriptorHeap[...].GetDimensions() — the IR (createHandleFromHeap -> annotateHandle {11, 0} -> getDimensions(72, h, undef)) and metadata match DXC, and the test passes dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Vega 8 hardware, and WARP cleanly.

This is also the only non-ignored workspace test that runs dx.op.getDimensions on a heap-indexed ByteAddressBuffer through CreateComputePipelineState, so this may be an amdxc64.dll RDNA4 compiler crash (similar to #3). If you have a moment, could you check whether:

  1. the 0xc0000005 happens inside CreateComputePipelineState on "hardware" (and whether "warp" passes on its own), and
  2. whether reverting the lower.rs change (leaving (12, 16)) avoids the crash on 32.0.32015.7029 or crashes there too?

That will tell us whether switching (12, stride) -> (11, 0) in getDimensions itself triggers an RDNA4 driver bug.

**@⁠vicennpacheco** on GitHub · 2026-11-24 22:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7146276060) Thanks for testing this on RDNA4! I double-checked the emitted DXIL against `dxc.exe -T cs_6_6` for `ResourceDescriptorHeap[...].GetDimensions()` — the IR (`createHandleFromHeap` -> `annotateHandle {11, 0}` -> `getDimensions(72, h, undef)`) and metadata match DXC, and the test passes `dxil.dll` `10.0.26100.0`, `VICTORY_D3D12_DEBUG=1`, Vega 8 hardware, and WARP cleanly. This is also the only non-ignored workspace test that runs `dx.op.getDimensions` on a heap-indexed `ByteAddressBuffer` through `CreateComputePipelineState`, so this may be an `amdxc64.dll` RDNA4 compiler crash (similar to #3). If you have a moment, could you check whether: 1. the `0xc0000005` happens inside `CreateComputePipelineState` on `"hardware"` (and whether `"warp"` passes on its own), and 2. whether reverting the `lower.rs` change (leaving `(12, 16)`) avoids the crash on `32.0.32015.7029` or crashes there too? That will tell us whether switching `(12, stride)` -> `(11, 0)` in `getDimensions` itself triggers an RDNA4 driver bug.
Author
Owner

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

On an RTX 5070 the parent lowering returned 32 records for the 128-byte, stride-16 buffer. WARP returned the expected 8 even before the fix. The PR returned 8 on both. All four lanes agreed on each device, and both revisions produced the same indexed data values (1000, 1004, 1008, 1012).

I first ran the unmodified regression test on 79b5a82. For the A/B I kept that test fixture, required both devices to initialize, and printed the count for each lane, once with lower.rs from its parent 4e17478 and once with the PR version. Pipeline creation and dispatch completed on both devices in both runs. Windows 11 Pro build 26300, NVIDIA 621.24, rustc 1.100.0 MSVC, --profile diag --test-threads=1.

A WARP-only run would miss the original wrong count on this machine. The RDNA4 pipeline-creation question still needs a run on that adapter.

AI-assisted testing and write-up (Codex).

**@⁠sawetco** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7148600272) On an RTX 5070 the parent lowering returned **32** records for the 128-byte, stride-16 buffer. WARP returned the expected **8** even before the fix. The PR returned **8** on both. All four lanes agreed on each device, and both revisions produced the same indexed data values (1000, 1004, 1008, 1012). I first ran the unmodified regression test on `79b5a82`. For the A/B I kept that test fixture, required both devices to initialize, and printed the count for each lane, once with `lower.rs` from its parent `4e17478` and once with the PR version. Pipeline creation and dispatch completed on both devices in both runs. Windows 11 Pro build 26300, NVIDIA 621.24, rustc 1.100.0 MSVC, `--profile diag --test-threads=1`. A WARP-only run would miss the original wrong count on this machine. The RDNA4 pipeline-creation question still needs a run on that adapter. AI-assisted testing and write-up (Codex).
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 19:28 UTC · original

RDNA3 data for this PR: on current main the new test fails on the card, and with the PR it passes.

Setup: Radeon RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 Pro 22H2 (19045), Rust 1.98.1 MSVC. Base: fxceless main d510ee4 + #402 (fb5da17, Agility 1.620.2 beside the test binary, which Windows 10 needs for SM 6.6). WARP has no SM 6.6 on this machine, so it skips: these are hardware results only.

  • Test alone on the base (this PR's mod.rs hunk only, 2 runs): hardware lane 0 record count: 128, want 8. So this card returns the byte count, where the RTX 5070 above gave 32 and WARP 8.
  • With the PR (79b5a82, the head where the RX 9070 above crashed): passes, no crash, and the rest of victory-shader --lib is unchanged (216 passed, 0 failed, 3 ignored).

The same run covered other shader PRs whose tests had only been run on NVIDIA or WARP. Each was merged on the same base; "tests only" means the PR's *_tests.rs changes applied on the base without the rest:

PR head new tests with the PR tests only, on the base
#129 79b5a82 pass fail (128 records, want 8)
#615 3600b7a 4/4 pass 4/4 fail
#592 8bc48bf 2/2 pass 1/2 fail
#561 745305c pass fail
#461 d3c96c3 pass fail
#277 6c835cd pass fail
#146 67f7ff0 pass fail
#137 6ccc209 pass fail
#657 fd48164 pass fail
#233 ca5339c 2/2 pass scalar_bit_searches_match_the_console fails (the other is inline)
#1002 eaeb8f1 6/6 pass, hardware part ran 3/6 fail
#377, #354, #219 23b63af, 6273077, ad4022f 2/2 pass each n/a: the tests need the PR's code
#260 d140e4e 2/2 pass n/a: the fix hooks up the new test file
#229 f8e0450 pass passes too: this card already gives the console's result
#102 114cc35 pass passes too: the GCN 5 failure doesn't reproduce on RDNA3
#340 28b317a 3/3 pass, but main's v_permlane16_and_x16_read_the_lanes_their_selectors_pick fails hardware test fails
#808 b220768 f16 denormal case 1 fails v_dot4_i32_i8 unsupported

Apart from #340 and #808, no other test changed against the base (215 passed, 0 failed, 3 ignored). Details for those two are on their PRs.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 19:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511) RDNA3 data for this PR: on current `main` the new test fails on the card, and with the PR it passes. **Setup:** Radeon RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 Pro 22H2 (19045), Rust 1.98.1 MSVC. Base: fxceless `main` `d510ee4` + #402 (`fb5da17`, Agility 1.620.2 beside the test binary, which Windows 10 needs for SM 6.6). WARP has no SM 6.6 on this machine, so it skips: these are hardware results only. - **Test alone on the base** (this PR's `mod.rs` hunk only, 2 runs): `hardware lane 0 record count`: **128**, want 8. So this card returns the byte count, where the RTX 5070 above gave 32 and WARP 8. - **With the PR** (`79b5a82`, the head where the RX 9070 above crashed): passes, no crash, and the rest of `victory-shader --lib` is unchanged (216 passed, 0 failed, 3 ignored). The same run covered other shader PRs whose tests had only been run on NVIDIA or WARP. Each was merged on the same base; "tests only" means the PR's `*_tests.rs` changes applied on the base without the rest: | PR | head | new tests with the PR | tests only, on the base | |---|---|---|---| | #129 | `79b5a82` | pass | fail (128 records, want 8) | | #615 | `3600b7a` | 4/4 pass | 4/4 fail | | #592 | `8bc48bf` | 2/2 pass | 1/2 fail | | #561 | `745305c` | pass | fail | | #461 | `d3c96c3` | pass | fail | | #277 | `6c835cd` | pass | fail | | #146 | `67f7ff0` | pass | fail | | #137 | `6ccc209` | pass | fail | | #657 | `fd48164` | pass | fail | | #233 | `ca5339c` | 2/2 pass | `scalar_bit_searches_match_the_console` fails (the other is inline) | | #1002 | `eaeb8f1` | 6/6 pass, hardware part ran | 3/6 fail | | #377, #354, #219 | `23b63af`, `6273077`, `ad4022f` | 2/2 pass each | n/a: the tests need the PR's code | | #260 | `d140e4e` | 2/2 pass | n/a: the fix hooks up the new test file | | #229 | `f8e0450` | pass | **passes too**: this card already gives the console's result | | #102 | `114cc35` | pass | **passes too**: the GCN 5 failure doesn't reproduce on RDNA3 | | #340 | `28b317a` | 3/3 pass, **but main's `v_permlane16_and_x16_read_the_lanes_their_selectors_pick` fails** | hardware test fails | | #808 | `b220768` | **f16 denormal case 1 fails** | `v_dot4_i32_i8` unsupported | Apart from #340 and #808, no other test changed against the base (215 passed, 0 failed, 3 ignored). Details for those two are on their PRs.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.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/129/head:github-bot/gh-129'
git switch 'github-bot/gh-129'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-129'
git switch 'github-bot/gh-129'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-129'
git switch 'github-bot/gh-129'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-129'
git switch 'main'
git merge --squash 'github-bot/gh-129'
git switch 'main'
git merge --ff-only 'github-bot/gh-129'
git switch 'main'
git merge 'github-bot/gh-129'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.