Skip to content

Shaders: give buffer size queries their own bounded heap handle (AMD compiler crash) - #109

Open
WHOISJARDAS wants to merge 1 commit into
Zettrox:mainfrom
WHOISJARDAS:shaders/amd-size-query-handle
Open

WHOISJARDAS wants to merge 1 commit into
Zettrox:mainfrom
WHOISJARDAS:shaders/amd-size-query-handle

Conversation

@WHOISJARDAS

Copy link
Copy Markdown

Fixes the AMD shader compiler crash 0xc0000005 at amdxc64.dll+0x861b9f ("read 0x8") that ends runs when a pipeline is created, here on an RX 9070 XT and in the reports on other Radeon cards (#81, #46; upstream fxceless/victory-fork#3 and fxceless/victory-fork#120), without leaving any pass out and without skip lists.

What was wrong

Some programs read a buffer's last records at an offset made from that buffer's own size: the record count comes from the descriptor read as data (descriptor_data, lowered to getDimensions), and the read or write goes through the same descriptor. Both went through one heap handle. AMD's compiler (driver 32.0.32029.2010, RDNA 4) crashes building exactly that shape, an access through a handle at an offset computed from that handle's own getDimensions. The DXIL is valid (the validator passes it), so this is the driver, but the shape is ours to avoid.

descriptor_data now asks the size through a handle of its own (Shader::size_handle): its heap index goes through a dx.op.binary UMin, one slot below the view limit when there is one (VIEW_LIMIT - 1), else 2^26 - 1 (past any host heap, below what an index made from a 32-bit address can be), so it is never the access's handle. shortcut: with a limit, an index at or past the slot below the null slot reads that slot's size where reads go to the null slot; neither holds one of the title's views.

This also covers 501f0865fdf45dfd, the program #61 leaves the reuse pass out on AMD for: with this, it builds with every pass on.

Tested

AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26200, Rust 1.98.1, shaders.rpf of the title's build b99f876b.

Offline, one process per program (VICTORY_TRANSLATE_ONLY=<hash> victory translate --validate --pipelines --jobs 1):

main (90b529f) this branch
the 70 compute programs whose pipeline crashes this card's compiler on main (among them 501f0865fdf45dfd) 70 crash 70 pipelines, 0 crash

Whole archive:

In game (diag build, Series X profile, default switches, no skip list, cold shader cache; both runs also carry #108, without which main does not start on this machine):

port only port + this
run 197 s, then 0xc0000005 at amdxc64.dll+0x861b9f (the last compute programs translated were 072f5fe96efd27e1 and 501f0865fdf45dfd) 18 min (closed by hand), 0 exceptions
compute programs from the 70 that got a host pipeline in game - 33
frame rate in the world ~1.3 fps median 3.7 fps (0.6-6.6), 1,600-6,800 draws/frame
pipelines refused - one, mesh f5e50eb2108c425b (integer-target blending, #36)
  • cargo test --workspace --locked: 497 passed, 0 failed, 7 ignored, including the new emit::descriptor_tests::every_lane_reads_the_last_dword_its_buffers_record_count_names, which runs on the GPU and on WARP. Without the lower.rs change its process dies on this card with 0xc0000005 (STATUS_ACCESS_VIOLATION); with it, it passes.
  • Both clippy runs (-D warnings, with and without --all-features): clean. cargo xtask policy: ok.

Overlap

#58 moves the same getDimensions call into a new Lower::dimensions. Whichever lands first, the other is a small rebase: with #58 in, buffer views take size_handle inside dimensions. Happy to rebase this onto it.

Not tested

NVIDIA (where VIEW_LIMIT is set, so the VIEW_LIMIT - 1 bound is what runs) and Intel; RDNA 2/3; Linux/Wine.

AI use

Claude Code (Claude Opus 5.5) reduced the crash, wrote the change and the test, and ran the offline batches. The hardware, the title copy and the runs are mine.

🤖 Generated with Claude Code

AMD's shader compiler (driver 32.0.32029.2010, RX 9070 XT, RDNA 4)
crashed building programs that read or write a buffer at an offset made
from that same buffer's size: an access violation reading 0x8 at
amdxc64.dll+0x861b9f while the pipeline is created, which ends the run.
The title reads the last records of some buffers so, with the record
count from their descriptors read as data, and the size query and the
access went through one handle.

The size query now gets a handle of its own, its heap index bounded by a
dx.op UMin one slot below the view limit (2^26 - 1 without one), so it is
never the handle the access goes through. Nothing else changes.

On the RX 9070 XT: the 70 compute programs that crashed the compiler on
main build their pipelines; every one of the 22,379 programs whose DXIL
changes builds its pipeline (0 refused); translate and validate give the
same outcome as main for all 25,889 programs. New test:
emit::descriptor_tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants