fix(vk): host-visible buffers stay within their heap's budget, and a submit refused for want of memory is made again #2081
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2081
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/uma-heap-budget-submit-retry"
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
On AMD APUs and handhelds on Windows (Legion Go Z1E/780M with 8 GB UMA in #1879 and #1878, the ROG Ally in #668, the save-load reports in #947), the screen goes black while the sound keeps playing. It happens on a save load, entering Hyrule Castle or the Deku Tree, or leaving the Deku Tree. The log ends in repeated
vk: submit N failed (-2), which is VK_ERROR_OUT_OF_DEVICE_MEMORY.Why. All five #1879 logs show the same thing. VRAM as a whole is fine:
VRAM: 1877 MB used of 7782 MB allowed. But AMD's driver has a second device-local heap: the 256 MB window of the carve-out that the CPU can write. That heap is over its own budget:heap 2 (device): 55 blocks 252 MB ... used 252 of 243 MB. Each failure comes right after new staging arenas are made (a staging arena of 16/25 MB took ... to make) during the load's texture uploads.create_bufferasks VMA for a host-visible buffer that the GPU reads (the staging arenas, STORAGE for the ASTC decoder). VMA puts it in DEVICE_LOCAL | HOST_VISIBLE, which is that 256 MB heap, without checking the heap's budget. The allowance (vram_usage) adds that heap's 243 MB into the 7782 MB total, so no rule saw it fill. Once it was past its budget, the driver refused submits. The replay logged each refusal and dropped the work: the frame's work never ran, and the next submit's signal covered its timeline value. The result is a black screen that does not recover. The total allowance on UMA (the carve-out's heaps summed) is right. What went wrong is one heap's budget.What this changes
gpu/vk/vk_vma.cppcreate_buffer: a host-visible buffer is first made within its heap's budget (VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT). When that heap is full, VMA takes the next memory type (system memory, which on an APU is the same RAM). Where no heap has room, it is made as before.RX_VK_BUFFER_BUDGET=0(kill switch) restores the old behaviour. Device-only buffers andcreate_buffer_cachedare unchanged.gpu/vk/submit_retry.handvk_replay.cppsubmit_or_retry: everyvkQueueSubmit2of the replay goes through it. That covers submit_recording, part_submit, the batched flush, the present's copy and the upload chunk. After VK_ERROR_OUT_OF_DEVICE_MEMORY or OUT_OF_HOST_MEMORY, it waits for the GPU's earlier work (vkQueueWaitIdle, under the queue's lock that the caller already holds) and submits again, up to 3 tries. The Vulkan spec leaves a refused submit's command buffers, fence and semaphores unchanged, so the same submit can be made again. The next present (texture_frame) then frees every idle staging arena and the image reaper's whole queue. Nothing is destroyed under the queue's lock: a destroy'srec::boundarycan wait for the recorder, whose part submit waits for that lock.RX_VK_SUBMIT_RETRY=0(kill switch) drops the submit as before.RX_VK_TEST_SUBMIT_REFUSE=<n>(diag) refuses the first try of every n-th submit, so any card can run this path.Read first:
create_buffer(vk_vma.cpp),submit_or_retryandsubmit_give_back(vk_replay.cpp), and thememory_refusedblock intexture_frame(vk_texture.cpp).To see it on main: a Legion Go or ROG Ally (8 GB UMA, Windows, Adrenalin 25.30.44), load a save or enter the Deku Tree. The log shows
heap 2 ... used 252 of 243 MB, thensubmit N failed (-2), then a black screen. Without the hardware:tests/test_submit_oom.pyfails on main.Fixes #1879. See #1878 (duplicate), #947, #668.
Testing
Tested: Linux, RTX 3090, NVIDIA 620.70.06, this PR @
038d85caas a pack over main 9dd41326's base, through the job queue. A memory tour fromkokiri-startthrough Hyrule Castle (teleport 4) and Inside the Deku Tree (19), 40 s each, withRX_VK_TEST_SUBMIT_REFUSE=200: the log hasvk: the refused submit was taken on try 216 times, nofailed (-2), no crash or device loss, and the tour finished with a clean quit. Peak game total 11.5 GB (resident + swapped), peak private 4.1 GB. On this PC (resizable BAR) the placement path has room in heap 0, so it changes nothing here; the APU heap's overrun can only be shown on the Test Farm.The game-free test
tests/test_submit_oom.pyis written but has not been run on this PC (no tests run locally). CI runs it. It is written to fail on main for the bug's reason: a 16 MB staging arena with heap 2 at 236 of 243 MB lands in heap 2, at 252 of 243 MB, and a refused submit is made only once.Still to test:
kokiri-startthrough Hyrule Castle (teleport 4) and the Deku Tree (19). Run three ways: default; withRX_VK_TEST_SUBMIT_REFUSE=200, expectingvk: the refused submit was taken on try 2, a normal picture and nofailed (-2); and withRX_VK_TEST_SUBMIT_REFUSE=200 RX_VK_SUBMIT_RETRY=0, expecting dropped submits and black or missing frames as on main (by hand).submit ... failed (-2), a picture throughout, andheap 2 (device) ... used X of 243 MBstaying at or under 243 (@Beanstalkbelow).@Beanstalkbelow).Measurements
Verdict: not measured yet. The build was stopped by memory pressure before anything ran.
Setup (planned): Linux, RTX 3090, NVIDIA 620.70.06; memtour
kokiri-startthrough teleports 4 and 19; peak VRAM, RAM and thevk: memory heaps:/vk: budget:lines, main against this PR, 2 runs each. Expected: no change on this PC. With resizable BAR, heap 0 has room, so placement is unchanged, and the retry only runs on a refused submit.9dd41326038d85catests/test_submit_oom.pyEvidence from #1879's logs (v3.0.0, the same 5 attachments):
memory heaps: ... heap 2 (device): 55 blocks 252 MB, 58 allocations 240 MB; used 252 of 243 MBnext toVRAM: 1877 MB used of 7782 MB allowed, andsubmit 7687 / 78536 / 109249 / 194971 failed (-2)in each log after new staging arenas were made.Risks
RX_VK_BUFFER_BUDGET=0turns it off.RX_VK_SUBMIT_RETRY=0turns it off.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (not run on this PC by rule; CI runs it)main, or Measurements says why there is nothing to measure. (not yet)third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (written as test then fix; not run here, CI runs it)gpu/vk/switches.def. (two kill switches, on by default, and a diag)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
https://claude.ai/code/session_017vw8e2uxGKQxzDeQ15jjNK
Tested in game: Linux, RTX 3090, NVIDIA 620.70.06, this PR @
038d85caover main 9dd41326's base, through the job queue: memory tour from kokiri-start through Hyrule Castle and Inside the Deku Tree with RX_VK_TEST_SUBMIT_REFUSE=200. 16 'the refused submit was taken on try 2' lines, no failed (-2), no crash, clean quit. The APU heap overrun itself needs the Test Farm.@Beanstalk test Windows AMD iGPUs (windows+amd+igpu): from the save kokiri-start, load the save, teleport to Hyrule Castle and then Inside the Deku Tree, 30 s in each with the camera turning. Fail on any "vk: submit" or "batched submit" line with "failed (-2)", a black screen, or a "memory heaps" line where a device heap's "used" is over its budget. Compare load times and peak VRAM with main.
@Beanstalk test Steam Deck (steamdeck): from the save kokiri-start, load the save, teleport to Hyrule Castle and Inside the Deku Tree, 30 s each. Compare load time, frame time p99 and peak VRAM with main. Fail on any "failed (-2)" or "failed (-4)" submit line, or a crash.
Beanstalk test farm · 🔄 testing (2 of 2 reports so far, a failure already)
Commit
038d85c· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm cannot compare the two numbers in each heap log line, so it cannot enforce the requested per-device-heap budget limit.
⚠️ Note: Pictures are compared at two sampled moments; this can catch a black-screen regression against main but cannot guarantee detection throughout the tour or when main is also black.
⚠️ Note: Camera turns occur before each 30-second measurement, not during it; the shared submit rule also rejects device-lost submits on Windows.
Done (started 15:49 UTC, last report 16:04 UTC). Run 2: re-planned by HumanBean. Comment
@Beanstalkto run it again.windows+amd+igpusteamdeckWhy it failed
steamdeck:castle-deku-tourscreenshot.max_diff:limit 0.1What was tested
What will be tested · AI plan (
gpt-6.1-terra)Windows AMD iGPUs and Steam Decks will load kokiri-start and visit Hyrule Castle and the Deku Tree, with camera turns and 30-second measurements at each stop. The roughly 13-minute run per tester compares load time, frame-time p99, peak VRAM and pictures with main. Crashes, failed memory or device-lost submits, substantial performance or VRAM regressions, and sufficiently different pictures fail the plan. No tester online now matches windows+amd+igpu: that target waits for one.
kokiri-start, then teleport to Hyrule Castle, move the stick, take the picture castle to compare with main, measure castle for 30 s (after 0 s warm-up), teleport to Inside the Deku Tree, take the picture deku to compare with main, measure deku for 30 s (after 0 s warm-up); 1 run on each side.Measurements on `steamdeck`, for the PR description
Verdict: fail on steamdeck (2 reports):
castle-deku-tour screenshot.max_difffailed.Hardware: 1: linux+amd+radv+igpu+handheld
AMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAM; 2: linux+amd+radv+igpu+handheldAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMScene: castle-deku-tour, from the repository's save kokiri-start; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); castle-deku-tour: 1 game start a side, castle 30 s after 0 s warm-up, deku 30 s after 0 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)9dd4132038d85cFlags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
The testers' hardware
steamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMsteamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMPossibly related, for context:
WIP: fix(vk): host-visible buffers stay within their heap's budget, and a submit refused for want of memory is made againto fix(vk): host-visible buffers stay within their heap's budget, and a submit refused for want of memory is made again