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

Open
vicennpacheco wants to merge 1 commit from upstream-pr/129 into main
vicennpacheco commented 2026-11-24 21:43:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by vicennpacheco on 2026-11-24T21:43:11Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6592001334 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/129). Originally posted by [vicennpacheco](https://github.com/vicennpacheco) on 2026-11-24T21:43:11Z. --- ### 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.)*
adriaespii commented 2026-11-24 22:07:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adriaespii on 2026-11-24T21:51:59Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7145492109 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7145492109). Originally posted by [adriaespii](https://github.com/adriaespii) on 2026-11-24T21:51:59Z. --- 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.*
vicennpacheco commented 2026-11-24 23:09:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by vicennpacheco on 2026-11-24T22:28:38Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7146276060 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7146276060). Originally posted by [vicennpacheco](https://github.com/vicennpacheco) on 2026-11-24T22:28:38Z. --- 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.
sawetco commented 2026-11-25 01:12:01 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by sawetco on 2026-11-25T00:31:44Z.


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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7148600272 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7148600272). Originally posted by [sawetco](https://github.com/sawetco) on 2026-11-25T00:31:44Z. --- 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).
HAL9000RELOADED commented 2026-11-25 20:09:26 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T19:28:58Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7172358511 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/129#issuecomment-7172358511). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T19:28:58Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/129:upstream-pr/129'
git switch 'upstream-pr/129'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/129'
git switch 'upstream-pr/129'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/129'
git switch 'upstream-pr/129'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/129'
git switch 'main'
git merge --squash 'upstream-pr/129'
git switch 'main'
git merge --ff-only 'upstream-pr/129'
git switch 'main'
git merge 'upstream-pr/129'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!129
No description provided.