fix(vk): release capture spares before large RADV imports under pressure #1933

Merged
HumanBean merged 1 commit from futondestroyer/Longshot:codex/issue-1842-radv-headroom into main 2026-11-21 00:02:01 +00:00
Member

Summary

On the reported RX 6700 XT Linux setup, Longshot lost the Vulkan device immediately after the cutscene where Saria gives Link the ocarina. RADV refused a command submission after Longshot imported a larger guest-memory range. The reported system heap was nearly full, even though the device-local heap had room. The ordinary idle-import path queued an 8 MiB retirement, whose memory is freed after GPU completion.

This change makes room for large RADV dma-buf imports by releasing completed system-memory capture spares synchronously when the driver budget estimate is tight. It keeps the existing import fallback, mirror inheritance and retirement fences. Start with radv_import_headroom and its call in import_dma_buf in gpu/vk/vk_memory.cpp.

See #1842.

Testing

Tested: Windows game-free fixtures using LLVM-MinGW. The headroom fixture fails on the base at the missing reclaim hook and passes on this head. Import factory (43 cases), import reach, capture spare reuse, asynchronous capture free, retired-import, and memory-accounting checks passed. test_linux_pressure.py reports the same missing pool_pressed = true; source marker on both revisions. Full mise run test, Linux renderer build and gameplay are pending.

Still to test:

  • RX 6700 XT, Linux RADV Mesa 26.2.7, by hand: use the same pre-cutscene state and settings on base and candidate, complete Saria's ocarina cutscene, and play for 60 seconds. Reproduce the base failure before crediting the candidate. Check the candidate's spare-release line, visible scene correctness and absence of RADV submission OOM, device loss or reset. Record a timestamp-matched kernel excerpt if the base or candidate fails. Beanstalk's current repository save starts in Link's house before the Deku Tree. It has no approved pre-cutscene checkpoint. Keep saves and raw traces local.

The issue reporter will run the manual check first. The Beanstalk smoke request was cancelled during planning.

Measurements

Verdict: The game-free check verifies the reclaim path. The workload's driver headroom and crash outcome still need measurement.

Setup uses the same save state, graphics settings, resolution and driver for both builds. Record the system-heap budget before the large import, completed spare bytes released, and whether gameplay continues. If the base and candidate differ, repeat the pair before interpreting the result. Check for a transition stall on the candidate.

Check Before: main @ 3df5c13e After: this PR @ d1ab7729
Game-free headroom fixture Fails at missing pre-import reclaim Passes
Saria transition on RX 6700 XT RADV Pending Pending

Risks

Synchronously freeing capture spares may stall a large import and may cause later captures to allocate replacement buffers. The 64 MiB import threshold and 64 MiB reserve are provisional. Driver budget estimates and buffer sizes can differ from actual heap headroom. A revert removes this policy. Save, options and cache formats are unaffected.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. The changed path requires Linux RADV.
  • mise run test passes (any failure that also fails on main is named). Focused checks are listed above. Full suite pending.
  • Measured against main, or Measurements says why there is nothing to measure. Runtime comparison pending.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Full builds pending.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary On the reported RX 6700 XT Linux setup, Longshot lost the Vulkan device immediately after the cutscene where Saria gives Link the ocarina. RADV refused a command submission after Longshot imported a larger guest-memory range. The reported system heap was nearly full, even though the device-local heap had room. The ordinary idle-import path queued an 8 MiB retirement, whose memory is freed after GPU completion. This change makes room for large RADV dma-buf imports by releasing completed system-memory capture spares synchronously when the driver budget estimate is tight. It keeps the existing import fallback, mirror inheritance and retirement fences. Start with `radv_import_headroom` and its call in `import_dma_buf` in `gpu/vk/vk_memory.cpp`. See #1842. ## Testing **Tested:** Windows game-free fixtures using LLVM-MinGW. The headroom fixture fails on the base at the missing reclaim hook and passes on this head. Import factory (43 cases), import reach, capture spare reuse, asynchronous capture free, retired-import, and memory-accounting checks passed. `test_linux_pressure.py` reports the same missing `pool_pressed = true;` source marker on both revisions. Full `mise run test`, Linux renderer build and gameplay are pending. **Still to test:** - RX 6700 XT, Linux RADV Mesa 26.2.7, by hand: use the same pre-cutscene state and settings on base and candidate, complete Saria's ocarina cutscene, and play for 60 seconds. Reproduce the base failure before crediting the candidate. Check the candidate's spare-release line, visible scene correctness and absence of RADV submission OOM, device loss or reset. Record a timestamp-matched kernel excerpt if the base or candidate fails. Beanstalk's current repository save starts in Link's house before the Deku Tree. It has no approved pre-cutscene checkpoint. Keep saves and raw traces local. The issue reporter will run the manual check first. The Beanstalk smoke request was cancelled during planning. ## Measurements **Verdict:** The game-free check verifies the reclaim path. The workload's driver headroom and crash outcome still need measurement. Setup uses the same save state, graphics settings, resolution and driver for both builds. Record the system-heap budget before the large import, completed spare bytes released, and whether gameplay continues. If the base and candidate differ, repeat the pair before interpreting the result. Check for a transition stall on the candidate. | Check | Before: main @ 3df5c13e | After: this PR @ d1ab7729 | |---|---|---| | Game-free headroom fixture | Fails at missing pre-import reclaim | Passes | | Saria transition on RX 6700 XT RADV | Pending | Pending | ## Risks Synchronously freeing capture spares may stall a large import and may cause later captures to allocate replacement buffers. The 64 MiB import threshold and 64 MiB reserve are provisional. Driver budget estimates and buffer sizes can differ from actual heap headroom. A revert removes this policy. Save, options and cache formats are unaffected. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. The changed path requires Linux RADV. - [ ] `mise run test` passes (any failure that also fails on `main` is named). Focused checks are listed above. Full suite pending. - [ ] Measured against `main`, or Measurements says why there is nothing to measure. Runtime comparison pending. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Full builds pending. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
fix(vk): release capture spares before large RADV imports under pressure
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 26s
CI / Workflow lint (actionlint) (pull_request) Successful in 36s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 37s
Third-party parts / As their notes say (pull_request) Successful in 42s
PR description / Description follows the template (pull_request_target) Failing after 11s
beanstalk/approval cancelled: comment @Beanstalk to start it again
beanstalk/any cancelled
CI / Website build and checks (pull_request) Failing after 22s
d1ab7729ff
Assisted-by: OpenAI Codex
Co-Authored-By: Codex <[email protected]>
Member

Possibly related, for context:

  • PR #1605 perf(vk): fit mid-size captures to tight spare budgets — Merged Vulkan capture-spare budgeting change; adjacent context, not the same RADV import-reclaim fix
Possibly related, for context: - PR #1605 perf(vk): fit mid-size captures to tight spare budgets — Merged Vulkan capture-spare budgeting change; adjacent context, not the same RADV import-reclaim fix
Author
Member

@Beanstalk Test only Linux AMD RADV discrete Radeon RX 6700 XT, using the exact PR head d1ab7729 against its merge base 3df5c13e. Use the explicit GPU model constraint gpu = "rx 6700 xt" and tags linux, amd, radv, dgpu. Leave it queued if there is no matching agent. Do not select Steam Deck, Windows, another GPU model, or a generic fallback target.

This is a short RADV area-arrival smoke check for issue #1842. Start both sides from the approved save:kokiri-start checkpoint, with the same defaults, no synthetic memory-pressure switches, and the same teleport route to Hyrule Field and then Market, allowing each arrival to settle. Use two starts per side if practical. Check for a RADV command-submission memory refusal, batched-submit failure, device loss, or game crash. If supported, record whether the candidate's RADV system heap line reports actually releasing capture spares. No such line means the reclaim condition was not observed. This route does not reproduce the Saria cutscene. The exact cutscene check remains a separate manual test on Mesa 26.2.7.

@Beanstalk Test only Linux AMD RADV discrete Radeon RX 6700 XT, using the exact PR head d1ab7729 against its merge base 3df5c13e. Use the explicit GPU model constraint `gpu = "rx 6700 xt"` and tags `linux`, `amd`, `radv`, `dgpu`. Leave it queued if there is no matching agent. Do not select Steam Deck, Windows, another GPU model, or a generic fallback target. This is a short RADV area-arrival smoke check for issue #1842. Start both sides from the approved `save:kokiri-start` checkpoint, with the same defaults, no synthetic memory-pressure switches, and the same teleport route to Hyrule Field and then Market, allowing each arrival to settle. Use two starts per side if practical. Check for a RADV command-submission memory refusal, batched-submit failure, device loss, or game crash. If supported, record whether the candidate's `RADV system heap` line reports actually releasing capture spares. No such line means the reclaim condition was not observed. This route does not reproduce the Saria cutscene. The exact cutscene check remains a separate manual test on Mesa 26.2.7.
BeanBot left a comment

Recommendation: Request changes. The proposed fix has not yet been shown to prevent the reported device loss, and it adds synchronous buffer destruction on a path where that work has previously caused substantial stalls. Its runtime cost and the amount of driver headroom it actually restores are unmeasured.

The change tries to make room for large Linux RADV dma-buf imports by destroying completed system-memory capture spares before importing. It preserves the existing fallback and retirement paths, but may stall an import and force later capture allocations. Measure and address that cost before merging.

Does it help: Unproven. The PR reports a game-free fixture failing on base at a missing hook and passing on the candidate, but the RX 6700 XT cutscene reproduction and candidate gameplay are pending. No paired runtime headroom or stall measurements are available.
Other systems: The reclaim path is restricted to Linux RADV imports of at least 64 MiB. Windows, other drivers and smaller imports do not enter it. RADV configurations with unknown system-heap budgets do not reclaim; shared VMA blocks may return less driver-visible memory than the spare sizes suggest. Steam Deck and other affected RADV hardware have no reported runs.
Switches: None added, changed or removed. Existing capture spare and allocation switches can affect how much memory is reclaimable.

Reviewed: d1ab7729ff against 3df5c13ed2: Read the diff, changed test files, repository contribution rules, PR template and relevant capture-spare, import and VMA paths. Skimmed the remainder of the large vk_memory.cpp file and the standards document; did not read the entire changed code file in full. No earlier reviews or recorded gameplay runs were supplied. The network-only Tooling rules and overlapping PRs were unavailable.; nothing run (a code review).
Checked and fine:

  • The reclaim loop holds the spare-list mutex and only removes completed spares; it skips device-local allocations.
  • The import fallback remains in place when dma-buf import fails.
  • The new fixture covers thresholds, an unknown budget, device-local spares and spare accounting.
  • The commit records AI assistance; the diff does not touch third_party or generated files.

Blocking (to change before merge)

  1. gpu/vk/vk_memory.cpp:5412: Synchronous destruction can run while an import holds the pool lock and delays other users of that lock. Existing capture-free documentation reports 25–49 ms retirement stalls from freeing these buffers, and this loop can destroy several at once; later captures may also have to allocate replacements. Measure paired base and candidate transition and frame times on affected RADV hardware, including repeated imports and later captures, and bound or redesign the synchronous work if the cost is material.

Suggestions (the author may take or leave)

  • Measure driver-reported heap usage before and after reclamation, including with RX_VK_CAP_BLOCKS enabled, because freed suballocations may not release their full sizes to the driver.
  • Exercise the actual import and fallback path in a behavioral fixture; the new test currently checks the hook's presence as source text and tests the reclaim function separately.

Testing: Review only; no code, tests, builds or project scripts were run. The PR reports focused Windows game-free checks, while Linux builds, the full suite and gameplay remain pending.
Overlaps and merge order: Unknown; the network is closed and no overlapping pull requests were supplied.


Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The proposed fix has not yet been shown to prevent the reported device loss, and it adds synchronous buffer destruction on a path where that work has previously caused substantial stalls. Its runtime cost and the amount of driver headroom it actually restores are unmeasured. The change tries to make room for large Linux RADV dma-buf imports by destroying completed system-memory capture spares before importing. It preserves the existing fallback and retirement paths, but may stall an import and force later capture allocations. Measure and address that cost before merging. **Does it help:** Unproven. The PR reports a game-free fixture failing on base at a missing hook and passing on the candidate, but the RX 6700 XT cutscene reproduction and candidate gameplay are pending. No paired runtime headroom or stall measurements are available. **Other systems:** The reclaim path is restricted to Linux RADV imports of at least 64 MiB. Windows, other drivers and smaller imports do not enter it. RADV configurations with unknown system-heap budgets do not reclaim; shared VMA blocks may return less driver-visible memory than the spare sizes suggest. Steam Deck and other affected RADV hardware have no reported runs. **Switches:** None added, changed or removed. Existing capture spare and allocation switches can affect how much memory is reclaimable. **Reviewed:** d1ab7729ff2f against 3df5c13ed2ec: Read the diff, changed test files, repository contribution rules, PR template and relevant capture-spare, import and VMA paths. Skimmed the remainder of the large vk_memory.cpp file and the standards document; did not read the entire changed code file in full. No earlier reviews or recorded gameplay runs were supplied. The network-only Tooling rules and overlapping PRs were unavailable.; nothing run (a code review). **Checked and fine:** - The reclaim loop holds the spare-list mutex and only removes completed spares; it skips device-local allocations. - The import fallback remains in place when dma-buf import fails. - The new fixture covers thresholds, an unknown budget, device-local spares and spare accounting. - The commit records AI assistance; the diff does not touch third_party or generated files. **Blocking** (to change before merge) 1. gpu/vk/vk_memory.cpp:5412: Synchronous destruction can run while an import holds the pool lock and delays other users of that lock. Existing capture-free documentation reports 25–49 ms retirement stalls from freeing these buffers, and this loop can destroy several at once; later captures may also have to allocate replacements. Measure paired base and candidate transition and frame times on affected RADV hardware, including repeated imports and later captures, and bound or redesign the synchronous work if the cost is material. **Suggestions** (the author may take or leave) - Measure driver-reported heap usage before and after reclamation, including with RX_VK_CAP_BLOCKS enabled, because freed suballocations may not release their full sizes to the driver. - Exercise the actual import and fallback path in a behavioral fixture; the new test currently checks the hook's presence as source text and tests the reclaim function separately. **Testing:** Review only; no code, tests, builds or project scripts were run. The PR reports focused Windows game-free checks, while Linux builds, the full suite and gameplay remain pending. **Overlaps and merge order:** Unknown; the network is closed and no overlapping pull requests were supplied. --- <sub>Automated code review by BeanBot (gpt-6.1-terra), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -5388,0 +5409,4 @@
if (allocation_in_vram(spare.alloc)) continue;
cap_free.erase(cap_free.begin() + i);
cap_free_bytes -= spare.size;
destroy_buffer(spare.buffer, spare.alloc);
Member

This can synchronously free several large buffers while the import holds the pool lock. Existing capture-free notes report 25–49 ms stalls for this work, and later captures may need replacement allocations. Please measure paired transition and frame times, including subsequent captures, and bound or redesign the synchronous work if the cost is material.

This can synchronously free several large buffers while the import holds the pool lock. Existing capture-free notes report 25–49 ms stalls for this work, and later captures may need replacement allocations. Please measure paired transition and frame times, including subsequent captures, and bound or redesign the synchronous work if the cost is material.
Member

Beanstalk test farm · cancelled

Commit d1ab772 · approved by futondestroyer (reviewed) · dashboard

Cancelled. Comment @Beanstalk to start it again.

Target Result Reports Frame time p99 (ms), main → PR VRAM peak (MB) Crashes
any cancelled 0 of 1 — — —
What was tested

What will be tested · default plan (AI failed: the summary says 'manual': the farm is unattended, so it must describe only what the plan's steps do (no one looks at, checks or does anything by hand); write it again)

The AI plan failed: the summary says 'manual': the farm is unattended, so it must describe only what the plan's steps do (no one looks at, checks or does anything by hand); write it again; using the default plan.

  • Where: any (any PC, 1-2 reports).
  • title: from the title screen, then measure title for 20 s (after 5 s warm-up); 2 runs on each side.
  • hyrule-field: from the repository's save kokiri-start, then teleport to Hyrule Field, measure field for 60 s (after 10 s warm-up); 2 runs on each side.
  • Measured: crashes, boot time, frame times, stutters and hitches, VRAM use, the game's log.
  • The PR fails if: it crashes; or peak VRAM is more than 10% above main; or frame time (p99) is more than 15% above main.
  • Time: about 47 min of game runs per tester (8 game starts), plus the two builds.
<!-- beanstalk:sticky --> ### Beanstalk test farm · cancelled Commit `d1ab772` · approved by futondestroyer (reviewed) · [dashboard](https://beanstalk.magicbean.dev/prs/1933) Cancelled. Comment `@Beanstalk` to start it again. | Target | Result | Reports | Frame time p99 (ms), main → PR | VRAM peak (MB) | Crashes | | --- | --- | --- | --- | --- | --- | | `any` | cancelled | 0 of 1 | — | — | — | <details><summary>What was tested</summary> **What will be tested** · default plan (AI failed: the summary says 'manual': the farm is unattended, so it must describe only what the plan's steps do (no one looks at, checks or does anything by hand); write it again) The AI plan failed: the summary says 'manual': the farm is unattended, so it must describe only what the plan's steps do (no one looks at, checks or does anything by hand); write it again; using the default plan. - **Where:** any (any PC, 1-2 reports). - **title:** from the title screen, then measure title for 20 s (after 5 s warm-up); 2 runs on each side. - **hyrule-field:** from the repository's save `kokiri-start`, then teleport to Hyrule Field, measure field for 60 s (after 10 s warm-up); 2 runs on each side. - **Measured:** crashes, boot time, frame times, stutters and hitches, VRAM use, the game's log. - **The PR fails if:** it crashes; or peak VRAM is more than 10% above main; or frame time (p99) is more than 15% above main. - **Time:** about 47 min of game runs per tester (8 game starts), plus the two builds. </details>
Author
Member

@Beanstalk cancel

@Beanstalk cancel
Member

@futondestroyer cancelled 0 queued jobs.

@futondestroyer cancelled 0 queued jobs.
HumanBean changed title from WIP: fix(vk): release capture spares before large RADV imports under pressure to fix(vk): release capture spares before large RADV imports under pressure 2026-11-21 00:01:42 +00:00
HumanBean deleted branch codex/issue-1842-radv-headroom 2026-11-21 00:02:02 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1933
No description provided.