fix(vk): cut sparse unbinds at 8 MiB so the Steam Machine stops losing the device #2998
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2998
Loading…
Reference in a new issue
No description provided.
Delete branch "decohered/Longshot:fix/sparse-unbind-8mib"
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?
Summary
If you have a Steam Machine, you've probably run into #1622: you start the game, play for a few seconds, and as soon as a sparse mirror frees up some memory, it crashes with
VK_ERROR_DEVICE_LOST.I found the culprit: it's RADV. The Mesa that SteamOS 3.10 uses binds sparse memory via the new GEM_VA2 ioctl, and when it unbinds it fills the hole from an 8 MiB buffer of zeroes -- but it does so in chunks, and each chunk's mapping is the size of the entire unbind. So if the unbind is larger than 8 MiB, it overflows the buffer, the kernel rejects it, and Vulkan reports the device as lost. I saw this happen with kprobes on my machine. #1624 made it more likely to occur because it coalesces blocks returned one at a time into one long range.
amdgpu_vm_verify_parameters; kprobes showed the 8 MiB buffer mapped for 0x870000 bytesradv_sparse_buffer_bind_memoryI implemented this in
sparse_bind_infos: on RADV, it breaks up every unbind into pieces of 8 MiB or less, always at the boundaries of the mirrors' blocks, or one block per piece if the block is larger than 8 MiB. There's a small wrinkle here: RADV will coalesce touching binds that share an info, which would re-join my pieces, so each piece that touches the previous one gets its own bind info. All other drivers get exactly what main gives them.To see it on main: a Steam Machine on SteamOS 3.10 with sparse mirrors on (the default). Start the game and play; it crashes at the first mirror give-back.
RX_VK_MIRROR_SPARSE=0works around it.Start with
sparse_bind_infosingpu/vk/vk_memory.cpp, thentests/test_sparse_bind_ranges.py.Fixes #1622
Testing
Tested: I've been testing this on my own Steam Machine with sparse mirrors enabled. Before the fix it would crash a few seconds in; since the fix I've had 5 logged sessions, the longest of which was 132 minutes, and I've been all over Hyrule. I've had 52,392 sparse binds with zero refused and no device lost. Those builds also included a few other changes of mine -- this hunk is the same one and applies to current main as is.
Steam Machine: Navi 33 8 GB, SteamOS 3.10.1, kernel 7.3.1-valve3, RADV steamos-26.05.20
tests/test_sparse_bind_ranges.pyfails on the test commit (bda665258), on the number of bind infos the driver gets, and passes on the fix (b1a978ad9), with clang++ and g++ 16.2.0. It fails again with the separate info per piece taken out.After review (
f2a802ec3), the cut is RADV's only and falls on the mirrors' block edges. The test checks that NVIDIA gets main's ranges and that blocks of 3 MiB and 16 MiB are cut on their edges; it fails atdae45c625and passes atf2a802ec3with clang++ and g++, and fails with the RADV check or the rounding to whole blocks taken out.tests/test_sparse_mirror.pyandtests/test_sparse_spare.pyread the same file and pass.The renderer builds whole at
f2a802ec3on Linux.mise run teston Linux (atb1a978ad9): 863 pass, 10 skip (Windows only), 54 fail. The same 54 fail on main @56823e27awith the same tools (nixpkgs' toolchain rather than mise's pinned one), so none come from this change.The 54
byte_compile_tracked, f2i_immediate, global_load_16, native_suatom, test_blocks_at_start, test_bug_report, test_check_cache, test_checks_container, test_cloth_kernels, test_control_picture, test_crash_record, test_crt_options, test_dav1d_av1, test_dev_update, test_draw_stream_visibility, test_framegen_hdr, test_framegen_resources, test_fsr_uniform_ownership, test_game_boundary, test_guest_holes, test_image_reaper_threads, test_image_view_retry, test_input_background, test_keyboard_option, test_lifter, test_lifter_semantics, test_linux_pressure, test_loaded_modules_drop, test_log_levels, test_menu_keys, test_menu_save_atomic, test_native_zstd, test_oot_cloth, test_oot_occ_raster, test_option_ids, test_perf_send, test_pipeline_tour, test_present_acquire_ahead, test_present_image_free, test_present_source_crop, test_program_cache_cleanup, test_program_cache_one_variant, test_readback_timeout_reuse, test_recording_admission, test_screensaver, test_switch_table, test_target_retention, test_temporal_present_bandwidth, test_tex_desc_memo, test_thinlto_tls, test_upscaler_round_trip, test_vram_compact, test_windows_display_startup, test_windows_on_linux
Still to test:
blocks not boundline in the log (@Beanstalk play through a few zone changes on a Steam Deck and check the log for sparse bind failures)Measurements
This is a crash fix and it doesn't change anything on any driver other than RADV.
Risks
This is only visible to RADV: more and smaller unbinds of the same blocks. Revert to undo it. Saves, settings, and caches are not affected.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Possibly related, for context:
WIP: fix(vk): unbind sparse mirrors in ranges of at most 8 MiB, so RADV on SteamOS 3.10 no longer loses the deviceto fix(vk): cut sparse unbinds at 8 MiB so the Steam Machine stops losing the device@review
Recommendation: Approve. The reported Steam Machine sessions support the fix, but the other Tier 1 systems whose sparse binds this changes still need coverage. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
The change limits sparse unbinds to 8 MiB and separates touching pieces into bind infos, avoiding the reported RADV device loss. It adds bind ranges and infos on all drivers, with an unmeasured effect on give-back frame times.
Should fix (1): not blocking, but worth doing before merging.
gpu/vk/vk_memory.cpp:4570: The fixed 8 MiB split does not account for the buffer's sparse block alignment. (more on the line) Do: Carry the sparse buffer alignment into this path and avoid creating sub-block unbinds; fall back from sparse mirrors when the affected driver cannot accept an aligned unbind within the limit.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_memory.cpp:4578: The additional bind infos are submitted on Windows AMD and NVIDIA without reported game or frame-time coverage. (more on the line) Do: Run the requested zone-change comparisons on AMD and NVIDIA Windows against the base, recording sparse bind activity and frame times. (@fixdoes its part first: Restrict the workaround to the affected driver path to remove the extra infos on unaffected systems.)gpu/vk/vk_memory.cpp:4578: Linux NVIDIA and Steam Deck coverage is also missing for the changed sparse submission path. (more on the line) Do: Run sparse-mirror zone changes on Linux NVIDIA and Steam Deck against the base, checking for bind failures and comparing give-back frame times. (@fixdoes its part first: Restrict the workaround to the affected driver path where it can be identified reliably.)@fixcan do L1, L2 and L3.Questions (1) (not confirmed from the code; they don't hold the recommendation)
gpu/vk/vk_memory.cpp:4543: Is there a reason to expect the other changes in the tested builds were necessary to prevent the device loss?Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for this head: the author reports five sessions and 52,392 sparse binds without a device loss on a build containing this hunk and other changes. The game-free test checks the submitted ranges and reportedly fails without the fix.
Other systems: Sparse mirrors use this path on Windows and Linux when the device supports them. AMD and NVIDIA Windows, NVIDIA Linux, and Steam Deck coverage remains outstanding; the additional bind infos can affect driver work and frame pacing. Saves, audio, input and builds do not use the changed path.
Switches: None added, changed or removed. Existing RX_VK_MIRROR_SPARSE defaults on where supported and can disable sparse mirrors.
Reviewed:
b1a978ad93against56823e27a1: Read the repository rules, PR template, standards, commits, full test, changed function and its sparse mirror callers and lifetime handling. Skimmed other portions of the 7,833-line vk_memory.cpp; it was not read in full. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).Checked and fine:
Testing: No commands from the project, builds or tests were run during review. CI is still running; the author's test results are reported in the PR.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -4555,2 +4567,4 @@}for (; !b.memory && b.size > kUnbindMost; b.resourceOffset += kUnbindMost, b.size -= kUnbindMost)ranges.push_back({b.resourceOffset, kUnbindMost, VK_NULL_HANDLE, 0, b.flags});ranges.push_back(b);L1 (should fix): The fixed 8 MiB split does not account for the buffer's sparse block alignment.
When: If a device reports a sparse buffer alignment greater than 8 MiB, a released block or spare-mirror range is split at an offset smaller than that alignment. The resulting sparse binds violate Vulkan's alignment requirements and may be rejected or produce undefined behavior.
Do: Carry the sparse buffer alignment into this path and avoid creating sub-block unbinds; fall back from sparse mirrors when the affected driver cannot accept an aligned unbind within the limit.
@ -4560,1 +4575,4 @@if (k == first || meets) cut.push_back({info.buffer, 0, ranges.data() + k});cut.back().bindCount++;}}L2 (should fix): The additional bind infos are submitted on Windows AMD and NVIDIA without reported game or frame-time coverage.
When: During mirror give-backs, these drivers receive more bind infos than on main; their handling and the effect on frame pacing have not been measured.
Do: Run the requested zone-change comparisons on AMD and NVIDIA Windows against the base, recording sparse bind activity and frame times.
L3 (should fix): Linux NVIDIA and Steam Deck coverage is also missing for the changed sparse submission path.
When: Where sparse mirrors are supported, give-backs submit the new ranges and infos on these Tier 1 systems too; no run shows their behavior or frame-time cost.
Do: Run sparse-mirror zone changes on Linux NVIDIA and Steam Deck against the base, checking for bind failures and comparing give-back frame times.
@fix
I didn't fix this pull request: it doesn't allow edits from maintainers (the author can turn on Allow edits from maintainers).
Automated fix by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
I pushed
f2a802ec3which fixes L1-L3. The cut is now only on RADV and it's on the mirrors' block edges, so a block larger than 8 MiB is never split. All other drivers get the same ranges and bind info as main, so we no longer need to run Windows or NVIDIA. The test covers both: NVIDIA gets main's ranges, and blocks of 3 MiB and 16 MiB get cut correctly.To answer your question: no, the other changes were not necessary. The build that fixed the crash was 805 nightly with this commit on top and no other changes.
@review
Recommendation: Approve. The RADV workaround preserves sparse block boundaries and avoids changing other drivers’ submitted ranges. The reported Steam Machine sessions support the crash fix, but Steam Deck testing and the required CI checks are still pending. Nothing blocking is left. Recommend approval; not approved on the forge.
The change limits RADV sparse unbind ranges to avoid the reported device loss, while keeping cuts on mirror block boundaries. It adds bind infos on RADV and test coverage for the packing behavior.
Since the last review (on
b1a978ad93)Resolved: L1 (The fixed 8 MiB split does not account for the buffer's sparse block alignment.); L2 (The additional bind infos are submitted on Windows AMD and NVIDIA without reported game or…); L3 (Linux NVIDIA and Steam Deck coverage is also missing for the changed sparse submission pat…)
Checks: Still running: 10 checks.
Also noticed (2; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes: the author reports five Steam Machine sessions, up to 132 minutes and 52,392 sparse binds without a device loss, compared with a crash within seconds before the fix. The author says the successful build contained this change on top of nightly 805.
Other systems: The cut and additional bind infos are limited to RADV; other drivers retain the original ranges. Steam Deck also uses RADV and still needs the requested game run; Windows and NVIDIA no longer receive the workaround.
Switches: None added, changed or removed. The existing RX_VK_MIRROR_SPARSE switch controls sparse mirrors.
Reviewed:
f2a802ec34against56823e27a1: Read the changed sparse submission and mirror-fill code, its unbind callers, the full sparse range test, the diff and commits, AGENTS.md and CONTRIBUTING.md. The rest of vk_memory.cpp and the referenced developer standards were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project or tests were run. The author reports a Linux renderer build and game-free tests at the current head; the Steam Deck run and CI results are pending.
Overlaps and merge order: Not checked; network access is unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.