Examples now properly free their objects
This commit is contained in:
parent
7ece1e7d5a
commit
0f52807193
3 changed files with 86 additions and 58 deletions
|
@ -830,6 +830,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
base.swapchain_loader.queue_present_khr(base.present_queue, &present_info).unwrap();
|
base.swapchain_loader.queue_present_khr(base.present_queue, &present_info).unwrap();
|
||||||
});
|
});
|
||||||
|
base.device.device_wait_idle().unwrap();
|
||||||
|
|
||||||
for pipeline in graphics_pipelines {
|
for pipeline in graphics_pipelines {
|
||||||
base.device.destroy_pipeline(pipeline, None);
|
base.device.destroy_pipeline(pipeline, None);
|
||||||
|
@ -837,10 +838,22 @@ fn main() {
|
||||||
base.device.destroy_pipeline_layout(pipeline_layout, None);
|
base.device.destroy_pipeline_layout(pipeline_layout, None);
|
||||||
base.device.destroy_shader_module(vertex_shader_module, None);
|
base.device.destroy_shader_module(vertex_shader_module, None);
|
||||||
base.device.destroy_shader_module(fragment_shader_module, None);
|
base.device.destroy_shader_module(fragment_shader_module, None);
|
||||||
|
base.device.free_memory(image_buffer_memory, None);
|
||||||
|
base.device.destroy_buffer(image_buffer, None);
|
||||||
|
base.device.free_memory(texture_memory, None);
|
||||||
|
base.device.destroy_image_view(tex_image_view, None);
|
||||||
|
base.device.destroy_image(texture_image, None);
|
||||||
base.device.free_memory(index_buffer_memory, None);
|
base.device.free_memory(index_buffer_memory, None);
|
||||||
base.device.destroy_buffer(index_buffer, None);
|
base.device.destroy_buffer(index_buffer, None);
|
||||||
|
base.device.free_memory(uniform_color_buffer_memory, None);
|
||||||
|
base.device.destroy_buffer(uniform_color_buffer, None);
|
||||||
base.device.free_memory(vertex_input_buffer_memory, None);
|
base.device.free_memory(vertex_input_buffer_memory, None);
|
||||||
base.device.destroy_buffer(vertex_input_buffer, None);
|
base.device.destroy_buffer(vertex_input_buffer, None);
|
||||||
|
for &descriptor_set_layout in desc_set_layouts.iter() {
|
||||||
|
base.device.destroy_descriptor_set_layout(descriptor_set_layout, None);
|
||||||
|
}
|
||||||
|
base.device.destroy_descriptor_pool(descriptor_pool, None);
|
||||||
|
base.device.destroy_sampler(sampler, None);
|
||||||
for framebuffer in framebuffers {
|
for framebuffer in framebuffers {
|
||||||
base.device.destroy_framebuffer(framebuffer, None);
|
base.device.destroy_framebuffer(framebuffer, None);
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,6 +481,7 @@ fn main() {
|
||||||
base.swapchain_loader.queue_present_khr(base.present_queue, &present_info).unwrap();
|
base.swapchain_loader.queue_present_khr(base.present_queue, &present_info).unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
base.device.device_wait_idle().unwrap();
|
||||||
for pipeline in graphics_pipelines {
|
for pipeline in graphics_pipelines {
|
||||||
base.device.destroy_pipeline(pipeline, None);
|
base.device.destroy_pipeline(pipeline, None);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,19 +141,45 @@ unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT,
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn find_memorytype_index(memory_req: &vk::MemoryRequirements,
|
pub fn find_memorytype_index(memory_req: &vk::MemoryRequirements,
|
||||||
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
||||||
flags: vk::MemoryPropertyFlags)
|
flags: vk::MemoryPropertyFlags)
|
||||||
-> Option<u32> {
|
-> Option<u32> {
|
||||||
|
// Try to find an exactly matching memory flag
|
||||||
|
let best_suitable_index =
|
||||||
|
find_memorytype_index_f(memory_req,
|
||||||
|
memory_prop,
|
||||||
|
flags,
|
||||||
|
|property_flags, flags| property_flags == flags);
|
||||||
|
if best_suitable_index.is_some() {
|
||||||
|
return best_suitable_index;
|
||||||
|
}
|
||||||
|
// Otherwise find a memory flag that works
|
||||||
|
find_memorytype_index_f(memory_req,
|
||||||
|
memory_prop,
|
||||||
|
flags,
|
||||||
|
|property_flags, flags| property_flags & flags == flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_memorytype_index_f<F: Fn(vk::MemoryPropertyFlags, vk::MemoryPropertyFlags) -> bool>
|
||||||
|
(memory_req: &vk::MemoryRequirements,
|
||||||
|
memory_prop: &vk::PhysicalDeviceMemoryProperties,
|
||||||
|
flags: vk::MemoryPropertyFlags,
|
||||||
|
f: F)
|
||||||
|
-> Option<u32> {
|
||||||
let mut memory_type_bits = memory_req.memory_type_bits;
|
let mut memory_type_bits = memory_req.memory_type_bits;
|
||||||
for (index, ref memory_type) in memory_prop.memory_types.iter().enumerate() {
|
for (index, ref memory_type) in memory_prop.memory_types.iter().enumerate() {
|
||||||
if (memory_type.property_flags & flags) == flags {
|
if memory_type_bits & 1 == 1 {
|
||||||
|
if f(memory_type.property_flags, flags) {
|
||||||
return Some(index as u32);
|
return Some(index as u32);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
memory_type_bits = memory_type_bits >> 1;
|
memory_type_bits = memory_type_bits >> 1;
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize_callback(width: u32, height: u32) {
|
fn resize_callback(width: u32, height: u32) {
|
||||||
println!("Window resized to {}x{}", width, height);
|
println!("Window resized to {}x{}", width, height);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +280,8 @@ impl ExampleBase {
|
||||||
};
|
};
|
||||||
let debug_report_loader = DebugReport::new(&entry, &instance)
|
let debug_report_loader = DebugReport::new(&entry, &instance)
|
||||||
.expect("Unable to load debug report");
|
.expect("Unable to load debug report");
|
||||||
let debug_call_back = debug_report_loader.create_debug_report_callback_ext(&debug_info, None)
|
let debug_call_back =
|
||||||
|
debug_report_loader.create_debug_report_callback_ext(&debug_info, None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let surface = create_surface(&instance, &entry, &window).unwrap();
|
let surface = create_surface(&instance, &entry, &window).unwrap();
|
||||||
let pdevices = instance.enumerate_physical_devices().expect("Physical device error");
|
let pdevices = instance.enumerate_physical_devices().expect("Physical device error");
|
||||||
|
@ -379,7 +406,8 @@ impl ExampleBase {
|
||||||
p_queue_family_indices: ptr::null(),
|
p_queue_family_indices: ptr::null(),
|
||||||
queue_family_index_count: 0,
|
queue_family_index_count: 0,
|
||||||
};
|
};
|
||||||
let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info, None).unwrap();
|
let swapchain = swapchain_loader.create_swapchain_khr(&swapchain_create_info, None)
|
||||||
|
.unwrap();
|
||||||
let pool_create_info = vk::CommandPoolCreateInfo {
|
let pool_create_info = vk::CommandPoolCreateInfo {
|
||||||
s_type: vk::StructureType::CommandPoolCreateInfo,
|
s_type: vk::StructureType::CommandPoolCreateInfo,
|
||||||
p_next: ptr::null(),
|
p_next: ptr::null(),
|
||||||
|
@ -473,7 +501,13 @@ impl ExampleBase {
|
||||||
p_inheritance_info: ptr::null(),
|
p_inheritance_info: ptr::null(),
|
||||||
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
|
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
|
||||||
};
|
};
|
||||||
device.begin_command_buffer(setup_command_buffer, &command_buffer_begin_info).unwrap();
|
record_submit_commandbuffer(&device,
|
||||||
|
setup_command_buffer,
|
||||||
|
present_queue,
|
||||||
|
&[vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT],
|
||||||
|
&[],
|
||||||
|
&[],
|
||||||
|
|device, setup_command_buffer| {
|
||||||
let layout_transition_barrier = vk::ImageMemoryBarrier {
|
let layout_transition_barrier = vk::ImageMemoryBarrier {
|
||||||
s_type: vk::StructureType::ImageMemoryBarrier,
|
s_type: vk::StructureType::ImageMemoryBarrier,
|
||||||
p_next: ptr::null(),
|
p_next: ptr::null(),
|
||||||
|
@ -500,27 +534,7 @@ impl ExampleBase {
|
||||||
&[],
|
&[],
|
||||||
&[],
|
&[],
|
||||||
&[layout_transition_barrier]);
|
&[layout_transition_barrier]);
|
||||||
let wait_stage_mask = [vk::PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT];
|
});
|
||||||
let fence_create_info = vk::FenceCreateInfo {
|
|
||||||
s_type: vk::StructureType::FenceCreateInfo,
|
|
||||||
p_next: ptr::null(),
|
|
||||||
flags: vk::FenceCreateFlags::empty(),
|
|
||||||
};
|
|
||||||
let submit_fence = device.create_fence(&fence_create_info, None).unwrap();
|
|
||||||
let submit_info = vk::SubmitInfo {
|
|
||||||
s_type: vk::StructureType::SubmitInfo,
|
|
||||||
p_next: ptr::null(),
|
|
||||||
wait_semaphore_count: 0,
|
|
||||||
p_wait_semaphores: ptr::null(),
|
|
||||||
signal_semaphore_count: 0,
|
|
||||||
p_signal_semaphores: ptr::null(),
|
|
||||||
p_wait_dst_stage_mask: wait_stage_mask.as_ptr(),
|
|
||||||
command_buffer_count: 1,
|
|
||||||
p_command_buffers: &setup_command_buffer,
|
|
||||||
};
|
|
||||||
device.end_command_buffer(setup_command_buffer).unwrap();
|
|
||||||
device.queue_submit(present_queue, &[submit_info], submit_fence).unwrap();
|
|
||||||
device.wait_for_fences(&[submit_fence], true, std::u64::MAX).unwrap();
|
|
||||||
let depth_image_view_info = vk::ImageViewCreateInfo {
|
let depth_image_view_info = vk::ImageViewCreateInfo {
|
||||||
s_type: vk::StructureType::ImageViewCreateInfo,
|
s_type: vk::StructureType::ImageViewCreateInfo,
|
||||||
p_next: ptr::null(),
|
p_next: ptr::null(),
|
||||||
|
@ -589,9 +603,9 @@ impl Drop for ExampleBase {
|
||||||
self.device.device_wait_idle().unwrap();
|
self.device.device_wait_idle().unwrap();
|
||||||
self.device.destroy_semaphore(self.present_complete_semaphore, None);
|
self.device.destroy_semaphore(self.present_complete_semaphore, None);
|
||||||
self.device.destroy_semaphore(self.rendering_complete_semaphore, None);
|
self.device.destroy_semaphore(self.rendering_complete_semaphore, None);
|
||||||
|
self.device.free_memory(self.depth_image_memory, None);
|
||||||
self.device.destroy_image_view(self.depth_image_view, None);
|
self.device.destroy_image_view(self.depth_image_view, None);
|
||||||
self.device.destroy_image(self.depth_image, None);
|
self.device.destroy_image(self.depth_image, None);
|
||||||
self.device.free_memory(self.depth_image_memory, None);
|
|
||||||
for &image_view in self.present_image_views.iter() {
|
for &image_view in self.present_image_views.iter() {
|
||||||
self.device.destroy_image_view(image_view, None);
|
self.device.destroy_image_view(image_view, None);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue