Repository navigation
D3D12-AMD-RDNA4-SIZE-HANDLE: give a buffer's size query its own non-uniform handle (RDNA 4 compiler crash) - #2778
prosperkartik wants to merge 2 commits into
Conversation
…niform handle 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 ProjectLeonida#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.
|
Checked by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup),
AI-assisted: Claude Code |
|
Independent check on Windows (not the author), at
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. The AMD-specific behaviour itself needs RDNA4 hardware; this covers compile + unit tests. AI-assisted: yes (opencode). |
…of its own 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.
|
Thanks @OreoFR and @KelboLive for checking. Added a red/green test in bcb6087:
Also on the RX 9070 GRE at |
|
RTX 3090 / 621.40, validation on, bcb6087 merged onto main 0f86bd5: leonida-shader size_tests 11 passed, 0 failed, incl. a_buffers_size_is_asked_through_a_handle_of_its_own and the_record_count_of_a_structured_buffer_read_by_index, dxil.dll validation ran (main 10 passed; the PR's size_tests.rs doesn't compile there, no field nonuniform_marked on Lowered). No validation errors. |
|
Independent A/B check of The same existing integer image-store test failed for an identical bit-pattern comparison on each device both before and after the PR. Totals were 9 passed and 1 failed on the base, and 10 passed and 1 failed with the PR, on each device. This is coverage of lowering and offscreen behavior on these Wine drivers. Native Windows RDNA4 coverage remains open. AI-assisted with OpenAI Codex. |
KelboLive
left a comment
There was a problem hiding this comment.
Ran it: full leonida-shader --lib is 388 passed / 5 ignored, size_tests 11/11, and the same tests pass on a merged tree with current main. The dedicated handle is built from the same heap_index(site, first, false), Source::Loaded{load:site,first}, raw_twin/bias and props as handle() (amd_size.rs:29-37 vs lower.rs:9533-9553), so it still names the loads' view — only the nonuniform argument differs. No different-view bug.
The mechanism is sound, and the reason no REUSE tag is needed here is worth writing down: Module::key uses Key::Call(f, args) with the constant non-uniform operand included, so the size handle and the uniform access handle cannot fold together. That is also why #2698's Tag::SizeHandle matters only because that one does not skip waterfall loads (where both handles are non-uniform).
Overlap: #2698 is the same class at the same call site — gated on LEONIDA_SEPARATE_SIZE_HANDLES=1, while this is always on — and the two conflict textually in lower.rs and shader.rs (both add a counter next to nonuniform_handles and edit the same descriptor_data line). Land one and rebase the other; for the non-waterfall case they are redundant, not complementary.
One nit worth fixing before merge: self.s.nonuniform_handles -= 1 (amd_size.rs:36) is a production decrement of a test counter, safe only while twin_handle is hard-coded nonuniform = true. Mutating that flag while keeping the line underflows and panics every size test in debug — I hit it. A counted/separate argument or a #[cfg(test)] guard would remove the trap.
Merge is clean against current main and the merged tree passes; the branch is ~510 commits behind, but main refactored around the handle(...) line without touching it, so the clean merge is genuine. GitHub still says mergeable: UNKNOWN — worth a re-check after the next push.
Claim: #2570 (comment) (
D3D12-AMD-RDNA4-SIZE-HANDLE)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:
The programs involved ask a buffer's size (
dx.op.getDimensionson 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+0x861b9fon 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, newemit/amd_size.rs). The handle is marked non-uniform and not counted innonuniform_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'stwin_handlestands in for VIctory'sraw_twin+heap_handle_atpair; otherwise it's unchanged. The shader cache keys onleonida-shader's sources, so stale translations aren't served.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.ad25611closed at the start of the first story cutscene, on two of two starts.0ab92d33b2800cac,2cc6decf9a73aedd,4c573a76d2eeba04,5ddd2ca380fd74d8,5ececdeb8cd235c2,b2ff2ef0d6c98dd7,e5742545a3591526,ffa23aec3187f880) all built. About 21.6 rendered FPS on average.cargo test -p leonida-shader size_tests -- --test-threads=1: 9 passed on this branch, rebased on6cdc0a0d.size_tests::the_record_count_of_a_structured_buffer_read_by_indexcrashes the test process (STATUS_ACCESS_VIOLATION) on this card both with and without this change, so it was skipped above. VIctory's GPU test: NVIDIA GeForce RTX 3060 Ti (Vulkan 1.4, wave64-emulate) — 26497/26501 pass, 4 cs modules crash driver #559 notes and skips the same test.Not tested on NVIDIA or older AMD cards. The change only affects how the size query's handle is made.