D3D12-AMD-RDNA4-SIZE-HANDLE: give a buffer's size query its own non-uniform handle (RDNA 4 compiler crash) #3334

Open
prosperkartik wants to merge 2 commits from upstream-pr/3334 into main
prosperkartik commented 2026-12-03 14:13:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by prosperkartik on 2026-12-03T14:13:36Z.


Claimed in the coordination issue as: D3D12-AMD-RDNA4-SIZE-HANDLE (claim in #2570; the thread continues in #3312)

This is #2778 rebased on current main (b053a181). #2778 was closed on 2026-12-02 only because it no longer merged with main (a conflict in emit/lower.rs), and it can't be reopened from my side. The two commits are unchanged apart from the rebase. The only conflict was the module list at the top of lower.rs, where main added rayquery; both modules are kept. #2778 also has the outside checks from the earlier base.

Problem

On AMD RDNA 4 the driver's shader compiler crashes the title while it builds compute pipelines. Here it happens every time just as the first story cutscene (the kitchen) starts:

Leonida: first-chance exception 0xc0000005 at amdxc64.dll+0x85fd0f (read 0x8: nothing mapped there)

The programs involved ask a buffer's size (dx.op.getDimensions on a raw/structured view) through the same uniform heap handle that the buffer's loads use, and the compiler reads a null pointer when it merges the two. This is the crash VIctory tracked as RDNA 4 (amdxc64.dll+0x861b9f on an RX 9070 XT), fixed there by trustno1-coder/VIctory-NVIDIA#559.

This is a different crash from #2694. That one serializes pipeline creation for a concurrency crash on RDNA 3. This one is deterministic for these shaders, with any number of workers.

Fix

In descriptor_data (emit/lower.rs), a buffer's size query now gets a heap handle of its own (size_view_handle, new emit/amd_size.rs). The handle is marked non-uniform and not counted in nonuniform_handles, because its index is the same in every lane. It uses the loads' index, raw twin included, so the size is still the one of the view the loads read. Waterfall loads and images keep the shared handle as before.

It's a port of trustno1-coder/VIctory-NVIDIA#559 (66da8aaa), the size-query part of DexNom/VIctory PR 62 by MrToucann; the approach is IxMxAMAR's (fxceless/victory-fork#1213). Mandy's twin_handle stands in for VIctory's raw_twin + heap_handle_at pair; otherwise it's unchanged. The shader cache keys on leonida-shader's sources, so stale translations aren't served.

It applies on every GPU, not only AMD: marking a handle non-uniform is valid everywhere, and the NVIDIA checks on #2778 (RTX 3090 with DXIL validation on, RTX 4070 SUPER) passed.

A test, size_tests::a_buffers_size_is_asked_through_a_handle_of_its_own, lowers the program of the_record_count_of_a_structured_buffer_read_by_index, which makes two size queries (the structured buffer's and a raw UAV's), and checks that both get a handle of their own, marked non-uniform but not counted (nonuniform_marked == 2, nonuniform_handles == 0). nonuniform_marked is a new test-only count, since the existing nonuniform_handles deliberately leaves the size handle out. It only lowers, so it runs on any host.

Tested

RX 9070 GRE (12 GB), driver 32.0.32015.7029, i7-14700F, 32 GB, Windows 11; Series X profile, -Resolution 1080, no frame generation.

  • Before: ad25611 closed at the start of the first story cutscene, on two of two starts.
  • After (on ad25611 + this change): 30+ minutes of play through the cutscene and into the swamp mission (RV park, kennels), with 0 exceptions. The 8 compute shaders that were being built when it crashed before (0ab92d33b2800cac, 2cc6decf9a73aedd, 4c573a76d2eeba04, 5ddd2ca380fd74d8, 5ececdeb8cd235c2, b2ff2ef0d6c98dd7, e5742545a3591526, ffa23aec3187f880) all built. About 21.6 rendered FPS on average.
  • Rebased on main b053a181 (2026-12-03); unit tests only on this base, no game run:
    • cargo test --locked -p leonida-shader --lib size_tests -- --test-threads=1 --skip the_record_count_of_a_structured_buffer_read_by_index: 10 passed, 0 failed.
    • Red/green again: with the size_view_handle call in descriptor_data put back to self.handle(site, &src, false, props), the new test fails (left: 0, right: 2); with the change it passes.
    • python -I scripts/check_no_game_data.py on the four changed files: clean.
  • size_tests::the_record_count_of_a_structured_buffer_read_by_index crashes the test process (STATUS_ACCESS_VIOLATION) on this card both with and without this change, so it was skipped above. VIctory's #559 notes and skips the same test.

Outside checks on the earlier base are in #2778's comments: RTX 3090 with DXIL validation on (no validation errors), AMD Raphael (RADV) and RTX 4070 SUPER under Wine, Apple M5, and Ryzen 9 7950X3D. Native Windows RDNA 4 coverage is this card only.

GPUs tested: AMD Radeon RX 9070 GRE, driver 32.0.32015.7029, Windows 11

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5628199547 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3334). Originally posted by [prosperkartik](https://github.com/prosperkartik) on 2026-12-03T14:13:36Z. --- Claimed in the coordination issue as: `D3D12-AMD-RDNA4-SIZE-HANDLE` ([claim in #2570](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7287739557); the thread continues in #3312) This is #2778 rebased on current `main` (`b053a181`). #2778 was closed on 2026-12-02 only because it no longer merged with `main` (a conflict in `emit/lower.rs`), and it can't be reopened from my side. The two commits are unchanged apart from the rebase. The only conflict was the module list at the top of `lower.rs`, where `main` added `rayquery`; both modules are kept. #2778 also has the outside checks from the earlier base. ### Problem On AMD RDNA 4 the driver's shader compiler crashes the title while it builds compute pipelines. Here it happens every time just as the first story cutscene (the kitchen) starts: ``` Leonida: first-chance exception 0xc0000005 at amdxc64.dll+0x85fd0f (read 0x8: nothing mapped there) ``` The programs involved ask a buffer's size (`dx.op.getDimensions` on a raw/structured view) through the **same uniform heap handle** that the buffer's loads use, and the compiler reads a null pointer when it merges the two. This is the crash VIctory tracked as RDNA 4 (`amdxc64.dll+0x861b9f` on an RX 9070 XT), fixed there by trustno1-coder/VIctory-NVIDIA#559. This is a different crash from #2694. That one serializes pipeline creation for a concurrency crash on RDNA 3. This one is deterministic for these shaders, with any number of workers. ### Fix In `descriptor_data` (`emit/lower.rs`), a buffer's size query now gets a heap handle of its own (`size_view_handle`, new `emit/amd_size.rs`). The handle is marked non-uniform and not counted in `nonuniform_handles`, because its index is the same in every lane. It uses the loads' index, raw twin included, so the size is still the one of the view the loads read. Waterfall loads and images keep the shared handle as before. It's a port of trustno1-coder/VIctory-NVIDIA#559 (`66da8aaa`), the size-query part of DexNom/VIctory PR 62 by MrToucann; the approach is IxMxAMAR's (fxceless/victory-fork#1213). Mandy's `twin_handle` stands in for VIctory's `raw_twin` + `heap_handle_at` pair; otherwise it's unchanged. The shader cache keys on `leonida-shader`'s sources, so stale translations aren't served. It applies on every GPU, not only AMD: marking a handle non-uniform is valid everywhere, and the NVIDIA checks on #2778 (RTX 3090 with DXIL validation on, RTX 4070 SUPER) passed. A test, `size_tests::a_buffers_size_is_asked_through_a_handle_of_its_own`, lowers the program of `the_record_count_of_a_structured_buffer_read_by_index`, which makes two size queries (the structured buffer's and a raw UAV's), and checks that both get a handle of their own, marked non-uniform but not counted (`nonuniform_marked == 2`, `nonuniform_handles == 0`). `nonuniform_marked` is a new test-only count, since the existing `nonuniform_handles` deliberately leaves the size handle out. It only lowers, so it runs on any host. ### Tested RX 9070 GRE (12 GB), driver 32.0.32015.7029, i7-14700F, 32 GB, Windows 11; Series X profile, `-Resolution 1080`, no frame generation. - **Before:** `ad25611` closed at the start of the first story cutscene, on two of two starts. - **After** (on `ad25611` + this change): 30+ minutes of play through the cutscene and into the swamp mission (RV park, kennels), with **0 exceptions**. The 8 compute shaders that were being built when it crashed before (`0ab92d33b2800cac`, `2cc6decf9a73aedd`, `4c573a76d2eeba04`, `5ddd2ca380fd74d8`, `5ececdeb8cd235c2`, `b2ff2ef0d6c98dd7`, `e5742545a3591526`, `ffa23aec3187f880`) all built. About 21.6 rendered FPS on average. - **Rebased on `main` `b053a181` (2026-12-03); unit tests only on this base, no game run:** - `cargo test --locked -p leonida-shader --lib size_tests -- --test-threads=1 --skip the_record_count_of_a_structured_buffer_read_by_index`: **10 passed, 0 failed**. - Red/green again: with the `size_view_handle` call in `descriptor_data` put back to `self.handle(site, &src, false, props)`, the new test fails (`left: 0, right: 2`); with the change it passes. - `python -I scripts/check_no_game_data.py` on the four changed files: clean. - `size_tests::the_record_count_of_a_structured_buffer_read_by_index` crashes the test process (`STATUS_ACCESS_VIOLATION`) on this card **both with and without this change**, so it was skipped above. VIctory's #559 notes and skips the same test. Outside checks on the earlier base are in #2778's comments: RTX 3090 with DXIL validation on (no validation errors), AMD Raphael (RADV) and RTX 4070 SUPER under Wine, Apple M5, and Ryzen 9 7950X3D. Native Windows RDNA 4 coverage is this card only. GPUs tested: AMD Radeon RX 9070 GRE, driver 32.0.32015.7029, Windows 11
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/3334:upstream-pr/3334'
git switch 'upstream-pr/3334'

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/3334'
git switch 'upstream-pr/3334'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3334'
git switch 'upstream-pr/3334'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3334'
git switch 'main'
git merge --squash 'upstream-pr/3334'
git switch 'main'
git merge --ff-only 'upstream-pr/3334'
git switch 'main'
git merge 'upstream-pr/3334'
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
ProjectLeonida/mandy!3334
No description provided.