summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics/frame.rs32
-rw-r--r--src/graphics/render.rs22
2 files changed, 37 insertions, 17 deletions
diff --git a/src/graphics/frame.rs b/src/graphics/frame.rs
index 721eced..749b5ac 100644
--- a/src/graphics/frame.rs
+++ b/src/graphics/frame.rs
@@ -77,6 +77,8 @@ impl Frame {
                 texture: &Texture, render_pass: &vk::RenderPass)
       -> Result<()>
   {
+    Frame::destroy_replaceable(frames, permanent);
+
     let device = &permanent.device;
     let primary_command_pool = &permanent.primary_command_pool;
     let descriptor_set_layout = &for_reinit.descriptor_set_layout;
@@ -116,6 +118,35 @@ impl Frame {
 
     Ok(())
   }
+
+  //   This relies on its caller to have already waited for the device to be
+  // idle.
+  #[allow(unsafe_code)]
+  pub fn destroy(frames: &mut Vec<Self>, permanent: &Permanent) {
+    Frame::destroy_replaceable(frames, permanent);
+  }
+
+  #[allow(unsafe_code)]
+  pub fn destroy_replaceable(frames: &mut Vec<Self>, permanent: &Permanent) {
+    let device = &permanent.device;
+
+    let mut command_buffers = Vec::new();
+    for frame in frames {
+      unsafe { device.destroy_framebuffer(frame.framebuffer, None) };
+
+      command_buffers.push(frame.command_buffer);
+    }
+
+    //   Notice that we free the buffers in the pool, but do not destroy the
+    // pool itself. Notice also that we only do this for the primary command
+    // pool, because that's the only one where we've kept track of the
+    // buffers. We promise ourselves to free buffers in the transient pool
+    // immediately after using them.
+    unsafe {
+      device.free_command_buffers(permanent.primary_command_pool,
+                                  &command_buffers)
+    };
+  }
 }
 
 
@@ -225,3 +256,4 @@ fn init_descriptor_sets(count: usize, device: &Device,
 
   Ok(sets)
 }
+
diff --git a/src/graphics/render.rs b/src/graphics/render.rs
index 00e55ee..30f4b62 100644
--- a/src/graphics/render.rs
+++ b/src/graphics/render.rs
@@ -98,6 +98,8 @@ impl Render {
   pub fn destroy(mut self, permanent: &Permanent) {
     self.destroy_replaceable(permanent);
 
+    Frame::destroy(&mut self.per_frame, permanent);
+
     if let Some(model) = self.model {
       model.destroy(&permanent.device);
     }
@@ -105,24 +107,10 @@ impl Render {
 
   #[allow(unsafe_code)]
   fn destroy_replaceable(&mut self, permanent: &Permanent) {
-    let device = &permanent.device;
-
-    let mut command_buffers = Vec::new();
-    for frame in &self.per_frame {
-      unsafe { device.destroy_framebuffer(frame.framebuffer, None) };
+    // We skip calling Frame::destroy_replaceable() here because then it would
+    // be called twice during Render::reinit(), and that seems excessive.
 
-      command_buffers.push(frame.command_buffer);
-    }
-
-    //   Notice that we free the buffers in the pool, but do not destroy the
-    // pool itself. Notice also that we only do this for the primary command
-    // pool, because that's the only one where we've kept track of the
-    // buffers. We promise ourselves to free buffers in the transient pool
-    // immediately after using them.
-    unsafe {
-      device.free_command_buffers(permanent.primary_command_pool,
-                                  &command_buffers)
-    };
+    let device = &permanent.device;
 
     unsafe { device.destroy_pipeline(self.pipeline, None) };
     unsafe { device.destroy_pipeline_layout(self.pipeline_layout, None) };