summaryrefslogtreecommitdiff
path: root/video.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-12-19 19:35:36 +1100
committerquou <quou@disroot.org>2024-12-19 19:35:36 +1100
commitb8278db0cd73676c74fade8d30ec48f660b0c41d (patch)
tree3ee20c33bc3498404632372c385fef44b8760907 /video.cpp
parent4542c811bf48a7fde3916d3d0eee4bd77a68bccc (diff)
properly destroy objects on device destruction
Diffstat (limited to 'video.cpp')
-rw-r--r--video.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/video.cpp b/video.cpp
index c274e65..03b822b 100644
--- a/video.cpp
+++ b/video.cpp
@@ -242,6 +242,7 @@ struct Context_Vk : public Context {
void begin_record(Device_Vk* dev);
Context_Vk& acquire(Device_Vk* dev);
void release();
+ void destroy(Device_Vk* dev);
};
struct Texture_Vk : public Texture {
@@ -631,9 +632,18 @@ void Device_Vk::init_internal() {
}
void Device_Vk::deinit_internal() {
+ int i;
+ vkDeviceWaitIdle(dev);
swapchain.destroy(this);
deinit_swap_cap(this, &swap_cap);
app_destroy_vk_surface(app, inst, surf);
+ for (auto& i : rpo_cache)
+ i.second.destroy(this);
+ for (i = 0; i < max_contexts; i++) {
+ auto& context = contexts[i];
+ if (context.state & context_state_init)
+ context.destroy(this);
+ }
vkDestroyDevice(dev, &ac);
#ifdef DEBUG
destroy_dmesg(
@@ -1140,6 +1150,13 @@ void Context_Vk::release() {
state |= context_state_avail;
}
+void Context_Vk::destroy(Device_Vk* dev) {
+ state &= ~context_state_init;
+ vkDestroyCommandPool(dev->dev, pool, &dev->ac);
+ vkDestroySemaphore(dev->dev, semaphore, &dev->ac);
+ vkDestroyFence(dev->dev, fence, &dev->ac);
+}
+
Context& Device::acquire() {
Device_Vk* vk = (Device_Vk*)this;
int i;