Skip to content

Commit

Permalink
Don't destroy textures while they might still be in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Oct 23, 2023
1 parent 1e1fffa commit 6d95688
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/yakui-vulkan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,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);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/yakui-vulkan/src/vulkan_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -300,13 +306,17 @@ impl UploadQueue {
#[derive(Default)]
struct UploadPhase {
buffers: Vec<(Buffer<u8>, usize)>,
graveyard: Vec<VulkanTexture>,
}

impl UploadPhase {
unsafe fn cleanup(&mut self, device: &ash::Device) {
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) {
Expand Down

0 comments on commit 6d95688

Please sign in to comment.