From a47dff5086681d8a39986a93e824fc771c44afe5 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 22 Oct 2023 17:17:05 -0700 Subject: [PATCH] Don't destroy textures while they might still be in use --- crates/yakui-vulkan/src/lib.rs | 4 +++- crates/yakui-vulkan/src/vulkan_texture.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/yakui-vulkan/src/lib.rs b/crates/yakui-vulkan/src/lib.rs index 002c5e6d..7126ec0b 100644 --- a/crates/yakui-vulkan/src/lib.rs +++ b/crates/yakui-vulkan/src/lib.rs @@ -599,7 +599,9 @@ impl YakuiVulkan { TextureChange::Removed => { if let Some(removed) = self.yakui_managed_textures.remove(&id) { - unsafe { removed.cleanup(vulkan_context.device) }; + unsafe { + self.uploads.dispose(removed); + } } } diff --git a/crates/yakui-vulkan/src/vulkan_texture.rs b/crates/yakui-vulkan/src/vulkan_texture.rs index a6e2aaf2..7c596c96 100644 --- a/crates/yakui-vulkan/src/vulkan_texture.rs +++ b/crates/yakui-vulkan/src/vulkan_texture.rs @@ -208,6 +208,12 @@ impl UploadQueue { finished.cleanup(vulkan_context.device); } + /// Schedule `texture` to be disposed of after the previous phase completes + pub unsafe fn dispose(&mut self, texture: VulkanTexture) { + let phase = self.in_flight.back_mut().unwrap_or(&mut self.phase); + phase.graveyard.push(texture); + } + unsafe fn push( &mut self, vulkan_context: &VulkanContext, @@ -300,6 +306,7 @@ impl UploadQueue { #[derive(Default)] struct UploadPhase { buffers: Vec<(Buffer, usize)>, + graveyard: Vec, } impl UploadPhase { @@ -307,6 +314,9 @@ impl UploadPhase { for (buffer, _) in &self.buffers { buffer.cleanup(device); } + for texture in &self.graveyard { + texture.cleanup(device); + } } unsafe fn push(&mut self, vulkan_context: &VulkanContext, data: &[u8]) -> (vk::Buffer, usize) {