Make a refused upload submission again once the batches in flight have finished and the kept buffers are given back.

vkQueueSubmit of an upload batch that the driver refused for memory ended the game at once ("upload submit failed (-2)": five logs of three reports, all on integrated GPUs, whose device heap is the machine's memory and fills before any commit check sees it). A refused submit leaves the command buffer and its fence as they were, so the batch is now submitted a second time after the batches in flight are waited for, the objects that waited for them are destroyed and the staging cache, the arena's free chunks, the snapshot pool and the spare blocks go back to the driver, as a refused staging buffer already does. A second refusal ends the run as before. Compiled; the refusal was not reproduced here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 15:21:06 -05:00
parent 18aa16f2df
commit e1b1691e28

View File

@@ -5396,6 +5396,28 @@ uint64_t vk_upload_flush(int wait) {
open_b.sub_ns = plat_now_ns();
VkResult r = vkQueueSubmit(c->gfx_queue, 1, &si, open_b.fence);
vk_queue_unlock();
if (r == VK_ERROR_OUT_OF_DEVICE_MEMORY || r == VK_ERROR_OUT_OF_HOST_MEMORY) {
// The driver had no memory to take the batch, which ended the game here (five logs of three reports, all on
// integrated GPUs, one with 9 GB of commit to spare: the device's own heap was full). A refused
// submit leaves the command buffer and the fence as they were, so it can be made again: first the batches
// in flight are waited for, which gives their staging back and lets the objects that waited for them be
// destroyed, then the kept buffers and spare blocks go back to the driver (vk_mem_give_back), as for a
// refused staging buffer. Only a second refusal ends the run.
VkResult first = r;
int flying = ninflight;
retire(c, 1);
collect_locked(c);
uint64_t freed = vk_mem_give_back();
vk_queue_lock();
open_b.sub_ns = plat_now_ns();
r = vkQueueSubmit(c->gfx_queue, 1, &si, open_b.fence);
vk_queue_unlock();
static volatile int32_t told;
if (plat_inc32(&told) <= 16)
rt_log("vk: upload submit refused (%d): waited for %d batches in flight, %.1f MiB of kept buffers and "
"spare blocks given back, %s", (int)first, flying, freed / 1048576.0,
r == VK_SUCCESS ? "taken at the second try" : "refused again");
}
if (r != VK_SUCCESS) {
vk_mem_oom_report("upload submit", r);
vk_device_lost_check(r, "the submit of an upload batch");