AMD: clamp view heap indices on every host (fixes device removal on RDNA3); add v_cvt_f32_f64, v_permlane16/x16 #134
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!134
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-134"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@triippywhale on GitHub · 2026-11-24 21:45 UTC · original
triippywhale:fix/amd-view-heap-clamp→main· +303 −43 · 6 files · 1 commits · openSummary
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
@bawhen on GitHub · 2026-11-24 22:19 UTC · original
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_evenandv_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_limitpicked 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. Baselinemainat4e17478: 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 on GitHub · 2026-11-24 23:15 UTC · original
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:
VICTORY_PORTABLE_HEAP, on by default with an opt-out, and keys the shader cache on it). The two conflict indescriptor/host.rs, so only one of them can go in as is;v_cvt_f32_f64: #9;v_permlane16_b32/v_permlanex16_b32: #40 (it also handles permlane fetches from lanes outside the host branch).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).
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.Merge
Merge the changes and update on Forgejo.