Ui: free a closed window's GPU objects at once

Since 079b6b0 Crafter.Graphics hands the handles a destroyed buffer,
shader or pipeline owned to a deletion queue, which frames drain. A
hidden window draws no frames, so the closed window's objects stayed
allocated until the next one had drawn a few. Teardown has waited for
the device already, so it drains the queue itself; so does Show's catch,
since a Create that fails past the device's set-up (an asset missing) is
tried again by every Show and each try left its objects queued. Measured
on the workstation, that takes 2 MiB of GPU memory off a hidden window
and 642,822 bytes off what valgrind finds possibly lost at exit.
This commit is contained in:
Jorijn van der Graaf 2026-10-20 23:16:34 +02:00
commit 8e94af86b5
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB

View file

@ -74,6 +74,10 @@ export namespace ImsdMessages::Ui {
day.reset(); day.reset();
frames.reset(); frames.reset();
canvas.reset(); canvas.reset();
// The library queues a window's buffers, shaders and pipelines
// for deletion; with no window left no frame frees them, and
// the device is idle here.
Crafter::Device::DrainDeletions();
gestures = GestureDetector{}; gestures = GestureDetector{};
hits.clear(); hits.clear();
hitKeys.clear(); hitKeys.clear();
@ -167,10 +171,13 @@ export namespace ImsdMessages::Ui {
// No display, a compositor without a global the library // No display, a compositor without a global the library
// needs, no Vulkan device: the library throws, and the app // needs, no Vulkan device: the library throws, and the app
// has no window. It says so and runs on without one — a // has no window. It says so and runs on without one — a
// resident instance keeps importing; a later Show fails at // resident instance keeps importing. A later Show fails at
// once with the same reason, the device's set-up running // once with the same reason when the device's set-up failed
// only once. // (it runs only once), and tries again past it (an asset
// missing): what the failed Create queued is drained here,
// as Teardown drains, since no frame will.
canvas.reset(); canvas.reset();
Crafter::Device::DrainDeletions();
Log(std::format("no window: {}", e.what())); Log(std::format("no window: {}", e.what()));
return; return;
} }