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

Open
github-bot wants to merge 2 commits from github-bot/gh-3334 into main AGit
Owner

@⁠prosperkartik on GitHub · 2026-12-03 14:13 UTC · original
prosperkartik:amd-rdna4-size-handle-2 → main · +87 −4 · 4 files · 2 commits · open

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

**@⁠prosperkartik** on GitHub · 2026-12-03 14:13 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3334) `prosperkartik:amd-rdna4-size-handle-2` → `main` · +87 −4 · 4 files · 2 commits · open Claimed in the coordination issue as: `D3D12-AMD-RDNA4-SIZE-HANDLE` ([claim in #2570](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/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
On AMD RDNA 4 (RX 9070 GRE, driver 32.0.32015.7029, Windows 11) the driver's
shader compiler crashes the title (0xc0000005 in amdxc64.dll+0x85fd0f) while
building compute pipelines at the first story cutscene. These programs ask a
buffer's size through the same uniform heap handle the buffer's loads use.

In descriptor_data the size query now gets a heap handle of its own, marked
non-uniform and not counted in nonuniform_handles (emit/amd_size.rs). Waterfall
loads and images keep the shared handle as before.

Port of trustno1-coder/VIctory-NVIDIA #559 (66da8aaa), the size-query part of
DexNom/VIctory PR 62 (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 unchanged.
Adds a_buffers_size_is_asked_through_a_handle_of_its_own (emit/size_tests.rs) and a
test-only count of the heap handles marked non-uniform (nonuniform_marked): the size
handle is marked non-uniform but on purpose not counted in nonuniform_handles, so that
count alone cannot tell the change.

The program of the_record_count_of_a_structured_buffer_read_by_index asks two buffers'
sizes (descriptor_data: the structured buffer's at s[8:11], the raw UAV's at s[20:23]).
With the change both get a handle of their own: marked 2, counted 0. With the change's
call in descriptor_data reverted the test fails (marked 0). It only lowers the program,
so it runs on any host and needs no RDNA 4 card. size_tests' build is split into
lower_cs (the lowering) and build (the host shader) for it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 14:17:08 +00:00
This pull request has changes conflicting with the target branch.
  • d3d12/crates/leonida-shader/src/emit/lower.rs
  • d3d12/crates/leonida-shader/src/emit/shader.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/3334/head:github-bot/gh-3334'
git switch 'github-bot/gh-3334'

Merge

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