Repository navigation
AMD: clamp view heap indices on every host (fixes device removal on RDNA3); add v_cvt_f32_f64, v_permlane16/x16 - #134
Conversation
…ermlane16/x16 The clamp that sends an out-of-range view index to a null slot at the end of the host view heap was only switched on when the host caps view heaps at 1,000,000 views (NVIDIA). A host that takes the title's whole heap (AMD) got no clamp and no null slot, so an index past the heap read past its end. On an RX 7900 XT (RDNA3) that is a GPU page fault and a removed device on the first world frame: DRED put the fault at view slot 16,777,088 (0xffff80) of a 1,507,328-slot heap, from compute program ebe4e53f031f5249. - probe_view_limit picks the null slot on every host: 2^21 views where the host takes a heap that size, else the old 1,000,000 cap. - HostHeap::new sizes every view heap to end at that null slot (title slots, then the dynamic slots, then null), and caps the title's slots only when they do not fit, as before. - The shader cache key includes the null slot, so a translation cached without the clamp (or for another GPU) is not served. Shader translation: - v_cvt_f32_f64, on 32-bit integers (no double support needed): round to nearest even, infinities and NaN kept, results below the smallest normal float flushed to signed zero. - v_permlane16_b32 and v_permlanex16_b32 through WaveReadLaneAt with a per-lane index from the nibble selectors; the pick stays inside a 32-lane half, so wave64 programs split in two host waves need no exchange. Tests: GPU tests for both (cvt on hardware and WARP, 20 values; permlane on hardware, 36 cases). cargo test --workspace and clippy -D warnings pass. In game on the RX 7900 XT: the world renders with no device loss and no black frames; one previously dropped compute shader (a929109552ce1e84) now translates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No regressions on a second RDNA3 card (RX 7700 16 GB, driver 32.0.32029.2010), at PR head
Not verified here: the first-world-frame device removal itself, because I'm testing without game files. The test run also didn't print which view-heap size This overlaps with #98 ("Cap the host view heap on every GPU"), which changes the same view-heap capping. Worth deciding which one goes in. Setup: AMD Radeon RX 7700 (RDNA3, 16 GB), driver 32.0.32029.2010, Ryzen 7 8700F, 16 GB RAM, Windows 11 (build 26300), Rust 1.98.1 from AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this comment; posted at my request. |
|
The DRED trace here is a great piece of diagnosis: slot 16,777,088 in a 1,507,328-slot heap, and the explanation of why the clamp only switched on for NVIDIA, make the cause very clear. For comparison, each of the three parts overlaps another open PR, which may help whoever merges them avoid doing it twice:
If one of those lands first, it might be worth trimming this PR to whatever it still adds on top, for example your hardware tests for the permlane selector patterns. Written with an AI assistant (Claude). |
… it refused 30 more compute shaders next to fxceless#134's v_permlanex16; lower/tests.rs stays Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Summary
On AMD GPUs the game removes the graphics device on its first world frame. The cause is that the view-heap index clamp only ever switched on for NVIDIA. This PR turns it on for every host, and adds three shader instructions the world uses that did not translate.
Tested on Windows 11, AMD Radeon RX 7900 XT (RDNA3, 20 GB), Ryzen 7 7800X3D, 64 GB RAM, Series X profile, on top of
4e17478.1. The AMD crash: view indices past the end of the host heap
What happened
Boot, menus and the opening load all worked, then the device was lost as the first world (mesh) pipelines were bound:
A diagnostics build with
VICTORY_D3D12_DRED=1put the fault in list 4 of 7, which stopped at command 569 of 2,363. The last dispatch before it was computeebe4e53f031f5249, which reads about 15 placed SRVs from title memory. The faulting address is exactly view slot 16,777,088 (0xffff80) at 32 bytes per slot, in a heap of 1,507,328 slots. The index is a garbage table offset, not a real descriptor.Why only on AMD
set_view_heap_limitalready sends any view index at or past a null slot to that slot. Butprobe_view_limitandHostHeap::newonly set it when creating a heap of more thanPORTABLE_VIEWS(1,000,000) failed, which is the NVIDIA case. A host that accepts the title's whole heap (AMD, resource binding tier 3) got no clamp and no null slot. The code already noted this as a shortcut: "a heap that fits is not capped and keeps no null slot there (an index past it is as undefined as before)". The comment onVIEW_LIMITsaid AMD's driver forgives the read. On RDNA3 it does not: it raises a page fault and removes the device.Fix (
crates/victory-gpu/src/descriptor/host.rs)probe_view_limitnow always picks a null slot:UNCAPPED_VIEWS - 1(2^21 views, 64 MiB of descriptors on AMD) where the host takes a heap that size, otherwise the old 1,000,000 cap. It logs which one it picked.HostHeap::new(views) calls the probe, then sizes every view heap to end at that null slot: the title's slots, thenDYNAMIC, then null slots up to and including the clamp target (all slots are already made null byfill_null). The title's slots are only capped whencount + DYNAMICdoes not fit, which is the existing NVIDIA behaviour.GPU_RANGESrecords the real heap size, so device-removed reports stay right.shader_cache::build()now includesview_heap_limit()in the cache key. A translation cached without the clamp, or for a GPU with a different null slot, is never served. This matters for anyone who already ran on AMD, or who moves a cache between GPUs.victory_shader::emit::view_heap_limit()was added as the getter for that key, and theVIEW_LIMITdoc comment was corrected.The sampler clamp (2,047) is unchanged.
2. Shader instructions (
crates/victory-shader/src/emit/lower.rs)v_cvt_f32_f64Doublesrequirement on the host. Rounds to nearest even; infinities kept; NaN stays a quiet NaN; results below the smallest normal float become signed zero (the console's default flush). New helperf64_bits_to_f32_bits.v_permlane16_b32/v_permlanex16_b32a929109552ce1e84WaveReadLaneAtwith a per-lane source:row | nibble(lane & 15)of the 64-bit selector{src2, src1}.rowis the lane's own row of 16, or forx16the other row of its 32-lane half. The pick never leaves a 32-lane half, so a wave64 program split into two host waves needs no exchange. Shortcut (documented in the code): a source lane with EXEC clear is read as the host has it; the console keepsvdstunless op_sel's fetch-inactive bit is set.Testing
Unit and GPU tests (
crates/victory-shader/src/emit/valu_tests.rs):v_cvt_f32_f64_rounds_to_nearest_even: 20 values, including both kinds of tie, values just pastf32::MAX(rounding to infinity), ±1e300, a value in the float denormal range (flushed),f32::MIN_POSITIVE, ±infinity and NaN. Checked against Rust'sas f32with denormals flushed, on the RX 7900 XT and WARP.v_permlane16_and_x16_read_the_lanes_their_selectors_pick: both instructions, 3 selector patterns (identity, reversed, repeating), read back at lanes 0, 5, 15, 16, 22 and 31 (36 cases). Hardware only, following the existing convention, because WARP refuses theWaveSize(32)the program declares.cargo test --workspace --locked: all pass.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo xtask policy: 169 files ok.In game (RX 7900 XT, release build):
VICTORY_RELAY=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024a black frame after a frame that was not)The speed switches are not changed by this PR. The last column is only there to show that the existing switches also work on AMD, and that they roughly double the world frame rate there.
Not fixed here (still dropped on this machine)
v_cvt_f32_f64programs now get past that instruction, but then stop at "a whole-wave section step the simulation does not follow" at 0x7e8 / 0x7f8.7d0f14ce44746d7e,6b6db9f1a526daeb, and others) and "a descriptor's address or format read as data".b22a16a178976e1b).0x1c8/0x218(29 calls per run): XCL's console device map names theseDeserializePipelineStateX. XCL leaves them unimplemented too, and relies on the title creating those pipelines from their description instead.E_INVALIDARG(mesh f5e50eb2108c425b, pixel ce3f0432a08f1d35), and the host pipeline library logs "the library did not load it: The parameter is incorrect" for most pipelines on this driver.Notes
cargo fmt --checkreports differences in 55 files across the workspace that were already there before this PR. I did not reformat anything, to keep the diff to the actual changes.🤖 Generated with Claude Code