Skip to content

AMD: clamp view heap indices on every host (fixes device removal on RDNA3); add v_cvt_f32_f64, v_permlane16/x16 - #134

Open
triippywhale wants to merge 1 commit into
fxceless:mainfrom
triippywhale:fix/amd-view-heap-clamp
Open

triippywhale wants to merge 1 commit into
fxceless:mainfrom
triippywhale:fix/amd-view-heap-clamp

Conversation

@triippywhale

Copy link
Copy Markdown

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:

host GPU device removed after a submission of 7 lists; page fault at 0x12287f000; ...
view heap 0x102880000+0x2e00000: 0x1d1ff000 past its end (slot 16777088)

A diagnostics build with VICTORY_D3D12_DRED=1 put the fault in list 4 of 7, which stopped at command 569 of 2,363. The last dispatch before it was compute ebe4e53f031f5249, 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_limit already sends any view index at or past a null slot to that slot. But probe_view_limit and HostHeap::new only set it when creating a heap of more than PORTABLE_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 on VIEW_LIMIT said 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_limit now 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, then DYNAMIC, then null slots up to and including the clamp target (all slots are already made null by fill_null). The title's slots are only capped when count + DYNAMIC does not fit, which is the existing NVIDIA behaviour.
  • GPU_RANGES records the real heap size, so device-removed reports stay right.
  • shader_cache::build() now includes view_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 the VIEW_LIMIT doc comment was corrected.

The sampler clamp (2,047) is unchanged.

2. Shader instructions (crates/victory-shader/src/emit/lower.rs)

Instruction Seen in How
v_cvt_f32_f64 2 world compute programs On 32-bit integers from the VGPR pair: no double type, so no Doubles requirement 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 helper f64_bits_to_f32_bits.
v_permlane16_b32 / v_permlanex16_b32 compute a929109552ce1e84 WaveReadLaneAt with a per-lane source: row | nibble(lane & 15) of the 64-bit selector {src2, src1}. row is the lane's own row of 16, or for x16 the 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 keeps vdst unless 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 past f32::MAX (rounding to infinity), ±1e300, a value in the float denormal range (flushed), f32::MIN_POSITIVE, ±infinity and NaN. Checked against Rust's as f32 with 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 the WaveSize(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):

Before After this PR After this PR, plus VICTORY_RELAY=2 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024
Entering the world device removed on the first world frame (2 of 2 runs) renders, about 5½ minutes in the world, no device loss renders, about 5½ minutes in the world, no device loss
Black frames (a black frame after a frame that was not) 3 0 0
Shaders that do not translate 10 10 (this run was before the instruction changes) 9
World frame rate (from logged frame numbers) – about 2.8–2.9 fps about 5–6 fps
Card time per frame, late in the run – 200–270 ms, card 38–46% busy 57–78 ms, card 61–67% busy
CPU write-compare per frame – about 415–430 MB about 25 MB

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)

  • The two v_cvt_f32_f64 programs now get past that instruction, but then stop at "a whole-wave section step the simulation does not follow" at 0x7e8 / 0x7f8.
  • 4 programs: "a descriptor read only as data" (pixel 7d0f14ce44746d7e, 6b6db9f1a526daeb, and others) and "a descriptor's address or format read as data".
  • 2 programs: "the first half of an interpolation".
  • 1 program: "a wave sum of 16-bit floats where not every lane runs" (compute b22a16a178976e1b).
  • Device slots 0x1c8 / 0x218 (29 calls per run): XCL's console device map names these DeserializePipelineStateX. XCL leaves them unimplemented too, and relies on the title creating those pipelines from their description instead.
  • One host mesh pipeline is refused with 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

  • XCL (GPL-2.0-only) was read only to identify the console device slots. No code from it is in this PR.
  • cargo fmt --check reports 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

…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>
@bawhen

bawhen commented Nov 24, 2026

Copy link
Copy Markdown

No regressions on a second RDNA3 card (RX 7700 16 GB, driver 32.0.32029.2010), at PR head 8698a80:

  • v_cvt_f32_f64_rounds_to_nearest_even and v_permlane16_and_x16_read_the_lanes_their_selectors_pick: pass on hardware and WARP.
  • cargo test --workspace --locked: 498 passed, 0 failed, 7 ignored (main's 496 plus these two).

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 probe_view_limit picked on this card.

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 rust-toolchain.toml. Baseline main at 4e17478: 496 passed, 0 failed, 7 ignored. No game files used.

AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this comment; posted at my request.

@ericomeehan

Copy link
Copy Markdown

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).

SaymonMaster14 added a commit to SaymonMaster14/victory-fork that referenced this pull request Nov 25, 2026
… 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>
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.

3 participants