From 0eaf851afa3cfce848179ed246835904bc4dfa1a Mon Sep 17 00:00:00 2001 From: maik klein Date: Wed, 28 Dec 2016 09:24:24 +0100 Subject: [PATCH] Added allocators to the examples --- examples/src/bin/texture.rs | 65 +++++++++++++++++++----------------- examples/src/bin/triangle.rs | 42 ++++++++++++----------- examples/src/lib.rs | 52 +++++++++++++---------------- 3 files changed, 80 insertions(+), 79 deletions(-) diff --git a/examples/src/bin/texture.rs b/examples/src/bin/texture.rs index 6576b33..0bab0f3 100644 --- a/examples/src/bin/texture.rs +++ b/examples/src/bin/texture.rs @@ -87,7 +87,7 @@ fn main() { dependency_count: 1, p_dependencies: &dependency, }; - let renderpass = base.device.create_render_pass(&renderpass_create_info).unwrap(); + let renderpass = base.device.create_render_pass(&renderpass_create_info, None).unwrap(); let framebuffers: Vec = base.present_image_views .iter() .map(|&present_image_view| { @@ -103,7 +103,7 @@ fn main() { height: base.surface_resolution.height, layers: 1, }; - base.device.create_framebuffer(&frame_buffer_create_info).unwrap() + base.device.create_framebuffer(&frame_buffer_create_info, None).unwrap() }) .collect(); let index_buffer_data = [0u32, 1, 2, 2, 3, 0]; @@ -117,7 +117,7 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let index_buffer = base.device.create_buffer(&index_buffer_info).unwrap(); + let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); let index_buffer_memory_index = find_memorytype_index(&index_buffer_memory_req, &base.device_memory_properties, @@ -129,7 +129,7 @@ fn main() { allocation_size: index_buffer_memory_req.size, memory_type_index: index_buffer_memory_index, }; - let index_buffer_memory = base.device.allocate_memory(&index_allocate_info).unwrap(); + let index_buffer_memory = base.device.allocate_memory(&index_allocate_info, None).unwrap(); let index_slice = base.device .map_memory::(index_buffer_memory, 0, @@ -166,7 +166,8 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let vertex_input_buffer = base.device.create_buffer(&vertex_input_buffer_info).unwrap(); + let vertex_input_buffer = + base.device.create_buffer(&vertex_input_buffer_info, None).unwrap(); let vertex_input_buffer_memory_req = base.device .get_buffer_memory_requirements(vertex_input_buffer); let vertex_input_buffer_memory_index = @@ -182,7 +183,7 @@ fn main() { memory_type_index: vertex_input_buffer_memory_index, }; let vertex_input_buffer_memory = base.device - .allocate_memory(&vertex_buffer_allocate_info) + .allocate_memory(&vertex_buffer_allocate_info, None) .unwrap(); let slice = base.device .map_memory::(vertex_input_buffer_memory, @@ -205,7 +206,8 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let uniform_color_buffer = base.device.create_buffer(&uniform_color_buffer_info).unwrap(); + let uniform_color_buffer = + base.device.create_buffer(&uniform_color_buffer_info, None).unwrap(); let uniform_color_buffer_memory_req = base.device .get_buffer_memory_requirements(uniform_color_buffer); let uniform_color_buffer_memory_index = @@ -221,7 +223,7 @@ fn main() { memory_type_index: uniform_color_buffer_memory_index, }; let uniform_color_buffer_memory = base.device - .allocate_memory(&uniform_color_buffer_allocate_info) + .allocate_memory(&uniform_color_buffer_allocate_info, None) .unwrap(); let uniform_slice = base.device .map_memory::(uniform_color_buffer_memory, @@ -248,7 +250,7 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let image_buffer = base.device.create_buffer(&image_buffer_info).unwrap(); + let image_buffer = base.device.create_buffer(&image_buffer_info, None).unwrap(); let image_buffer_memory_req = base.device.get_buffer_memory_requirements(image_buffer); let image_buffer_memory_index = find_memorytype_index(&image_buffer_memory_req, &base.device_memory_properties, @@ -261,7 +263,8 @@ fn main() { allocation_size: image_buffer_memory_req.size, memory_type_index: image_buffer_memory_index, }; - let image_buffer_memory = base.device.allocate_memory(&image_buffer_allocate_info).unwrap(); + let image_buffer_memory = + base.device.allocate_memory(&image_buffer_allocate_info, None).unwrap(); let image_buffer_slice = base.device .map_memory::(image_buffer_memory, 0, @@ -293,7 +296,7 @@ fn main() { p_queue_family_indices: ptr::null(), initial_layout: vk::ImageLayout::Undefined, }; - let texture_image = base.device.create_image(&texture_create_info).unwrap(); + let texture_image = base.device.create_image(&texture_create_info, None).unwrap(); let texture_memory_req = base.device.get_image_memory_requirements(texture_image); let texture_memory_index = find_memorytype_index(&texture_memory_req, &base.device_memory_properties, @@ -306,7 +309,7 @@ fn main() { allocation_size: texture_memory_req.size, memory_type_index: texture_memory_index, }; - let texture_memory = base.device.allocate_memory(&texture_allocate_info).unwrap(); + let texture_memory = base.device.allocate_memory(&texture_allocate_info, None).unwrap(); base.device .bind_image_memory(texture_image, texture_memory, 0) .expect("Unable to bind depth image memory"); @@ -416,7 +419,7 @@ fn main() { unnormalized_coordinates: 0, }; - let sampler = base.device.create_sampler(&sampler_info).unwrap(); + let sampler = base.device.create_sampler(&sampler_info, None).unwrap(); let tex_image_view_info = vk::ImageViewCreateInfo { s_type: vk::StructureType::ImageViewCreateInfo, @@ -439,7 +442,7 @@ fn main() { }, image: texture_image, }; - let tex_image_view = base.device.create_image_view(&tex_image_view_info).unwrap(); + let tex_image_view = base.device.create_image_view(&tex_image_view_info, None).unwrap(); let descriptor_sizes = [vk::DescriptorPoolSize { typ: vk::DescriptorType::UniformBuffer, descriptor_count: 1, @@ -456,7 +459,8 @@ fn main() { p_pool_sizes: descriptor_sizes.as_ptr(), max_sets: 1, }; - let descriptor_pool = base.device.create_descriptor_pool(&descriptor_pool_info).unwrap(); + let descriptor_pool = + base.device.create_descriptor_pool(&descriptor_pool_info, None).unwrap(); let desc_layout_bindings = [vk::DescriptorSetLayoutBinding { binding: 0, descriptor_type: vk::DescriptorType::UniformBuffer, @@ -481,7 +485,7 @@ fn main() { let desc_set_layouts = - [base.device.create_descriptor_set_layout(&descriptor_info).unwrap()]; + [base.device.create_descriptor_set_layout(&descriptor_info, None).unwrap()]; let desc_alloc_info = vk::DescriptorSetAllocateInfo { s_type: vk::StructureType::DescriptorSetAllocateInfo, p_next: ptr::null(), @@ -551,11 +555,11 @@ fn main() { p_code: frag_bytes.as_ptr() as *const u32, }; let vertex_shader_module = base.device - .create_shader_module(&vertex_shader_info) + .create_shader_module(&vertex_shader_info, None) .expect("Vertex shader module error"); let fragment_shader_module = base.device - .create_shader_module(&frag_shader_info) + .create_shader_module(&frag_shader_info, None) .expect("Fragment shader module error"); let layout_create_info = vk::PipelineLayoutCreateInfo { @@ -568,7 +572,8 @@ fn main() { p_push_constant_ranges: ptr::null(), }; - let pipeline_layout = base.device.create_pipeline_layout(&layout_create_info).unwrap(); + let pipeline_layout = + base.device.create_pipeline_layout(&layout_create_info, None).unwrap(); let shader_entry_name = CString::new("main").unwrap(); let shader_stage_create_infos = @@ -744,7 +749,7 @@ fn main() { base_pipeline_index: 0, }; let graphics_pipelines = base.device - .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info]) + .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None) .unwrap(); let graphic_pipeline = graphics_pipelines[0]; @@ -827,18 +832,18 @@ fn main() { }); for pipeline in graphics_pipelines { - base.device.destroy_pipeline(pipeline); + base.device.destroy_pipeline(pipeline, None); } - base.device.destroy_pipeline_layout(pipeline_layout); - base.device.destroy_shader_module(vertex_shader_module); - base.device.destroy_shader_module(fragment_shader_module); - base.device.free_memory(index_buffer_memory); - base.device.destroy_buffer(index_buffer); - base.device.free_memory(vertex_input_buffer_memory); - base.device.destroy_buffer(vertex_input_buffer); + base.device.destroy_pipeline_layout(pipeline_layout, None); + base.device.destroy_shader_module(vertex_shader_module, None); + base.device.destroy_shader_module(fragment_shader_module, None); + base.device.free_memory(index_buffer_memory, None); + base.device.destroy_buffer(index_buffer, None); + base.device.free_memory(vertex_input_buffer_memory, None); + base.device.destroy_buffer(vertex_input_buffer, None); for framebuffer in framebuffers { - base.device.destroy_framebuffer(framebuffer); + base.device.destroy_framebuffer(framebuffer, None); } - base.device.destroy_render_pass(renderpass); + base.device.destroy_render_pass(renderpass, None); } } diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 7208110..7da8f02 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -86,7 +86,7 @@ fn main() { dependency_count: 1, p_dependencies: &dependency, }; - let renderpass = base.device.create_render_pass(&renderpass_create_info).unwrap(); + let renderpass = base.device.create_render_pass(&renderpass_create_info, None).unwrap(); let framebuffers: Vec = base.present_image_views .iter() .map(|&present_image_view| { @@ -102,7 +102,7 @@ fn main() { height: base.surface_resolution.height, layers: 1, }; - base.device.create_framebuffer(&frame_buffer_create_info).unwrap() + base.device.create_framebuffer(&frame_buffer_create_info, None).unwrap() }) .collect(); let index_buffer_data = [0u32, 1, 2]; @@ -116,7 +116,7 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let index_buffer = base.device.create_buffer(&index_buffer_info).unwrap(); + let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); let index_buffer_memory_req = base.device.get_buffer_memory_requirements(index_buffer); let index_buffer_memory_index = find_memorytype_index(&index_buffer_memory_req, &base.device_memory_properties, @@ -128,7 +128,7 @@ fn main() { allocation_size: index_buffer_memory_req.size, memory_type_index: index_buffer_memory_index, }; - let index_buffer_memory = base.device.allocate_memory(&index_allocate_info).unwrap(); + let index_buffer_memory = base.device.allocate_memory(&index_allocate_info, None).unwrap(); let index_slice = base.device .map_memory::(index_buffer_memory, 0, @@ -149,7 +149,8 @@ fn main() { queue_family_index_count: 0, p_queue_family_indices: ptr::null(), }; - let vertex_input_buffer = base.device.create_buffer(&vertex_input_buffer_info).unwrap(); + let vertex_input_buffer = + base.device.create_buffer(&vertex_input_buffer_info, None).unwrap(); let vertex_input_buffer_memory_req = base.device .get_buffer_memory_requirements(vertex_input_buffer); let vertex_input_buffer_memory_index = @@ -165,7 +166,7 @@ fn main() { memory_type_index: vertex_input_buffer_memory_index, }; let vertex_input_buffer_memory = base.device - .allocate_memory(&vertex_buffer_allocate_info) + .allocate_memory(&vertex_buffer_allocate_info, None) .unwrap(); let vertices = [Vertex { pos: [-1.0, 1.0, 0.0, 1.0], @@ -210,11 +211,11 @@ fn main() { p_code: frag_bytes.as_ptr() as *const u32, }; let vertex_shader_module = base.device - .create_shader_module(&vertex_shader_info) + .create_shader_module(&vertex_shader_info, None) .expect("Vertex shader module error"); let fragment_shader_module = base.device - .create_shader_module(&frag_shader_info) + .create_shader_module(&frag_shader_info, None) .expect("Fragment shader module error"); let layout_create_info = vk::PipelineLayoutCreateInfo { @@ -227,7 +228,8 @@ fn main() { p_push_constant_ranges: ptr::null(), }; - let pipeline_layout = base.device.create_pipeline_layout(&layout_create_info).unwrap(); + let pipeline_layout = + base.device.create_pipeline_layout(&layout_create_info, None).unwrap(); let shader_entry_name = CString::new("main").unwrap(); let shader_stage_create_infos = @@ -403,7 +405,7 @@ fn main() { base_pipeline_index: 0, }; let graphics_pipelines = base.device - .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info]) + .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None) .unwrap(); let graphic_pipeline = graphics_pipelines[0]; @@ -480,18 +482,18 @@ fn main() { }); for pipeline in graphics_pipelines { - base.device.destroy_pipeline(pipeline); + base.device.destroy_pipeline(pipeline, None); } - base.device.destroy_pipeline_layout(pipeline_layout); - base.device.destroy_shader_module(vertex_shader_module); - base.device.destroy_shader_module(fragment_shader_module); - base.device.free_memory(index_buffer_memory); - base.device.destroy_buffer(index_buffer); - base.device.free_memory(vertex_input_buffer_memory); - base.device.destroy_buffer(vertex_input_buffer); + base.device.destroy_pipeline_layout(pipeline_layout, None); + base.device.destroy_shader_module(vertex_shader_module, None); + base.device.destroy_shader_module(fragment_shader_module, None); + base.device.free_memory(index_buffer_memory, None); + base.device.destroy_buffer(index_buffer, None); + base.device.free_memory(vertex_input_buffer_memory, None); + base.device.destroy_buffer(vertex_input_buffer, None); for framebuffer in framebuffers { - base.device.destroy_framebuffer(framebuffer); + base.device.destroy_framebuffer(framebuffer, None); } - base.device.destroy_render_pass(renderpass); + base.device.destroy_render_pass(renderpass, None); } } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 57bea68..2505594 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -57,7 +57,8 @@ pub fn record_submit_commandbuffer(device p_next: ptr::null(), flags: vk::FenceCreateFlags::empty(), }; - let submit_fence = device.create_fence(&fence_create_info).expect("Create fence failed."); + let submit_fence = device.create_fence(&fence_create_info, None) + .expect("Create fence failed."); let submit_info = vk::SubmitInfo { s_type: vk::StructureType::SubmitInfo, p_next: ptr::null(), @@ -73,7 +74,7 @@ pub fn record_submit_commandbuffer(device .expect("queue submit failed."); device.wait_for_fences(&[submit_fence], true, std::u64::MAX) .expect("Wait for fence failed."); - device.destroy_fence(submit_fence); + device.destroy_fence(submit_fence, None); } } @@ -119,20 +120,12 @@ fn create_surface(instance: &Instance, #[cfg(all(unix, not(target_os = "android")))] fn extension_names() -> Vec<*const i8> { - vec![ - Surface::name().as_ptr(), - XlibSurface::name().as_ptr(), - DebugReport::name().as_ptr() - ] + vec![Surface::name().as_ptr(), XlibSurface::name().as_ptr(), DebugReport::name().as_ptr()] } #[cfg(all(windows))] fn extension_names() -> Vec<*const i8> { - vec![ - Surface::name().as_ptr(), - Win32Surface::name().as_ptr(), - DebugReport::name().as_ptr() - ] + vec![Surface::name().as_ptr(), Win32Surface::name().as_ptr(), DebugReport::name().as_ptr()] } unsafe extern "system" fn vulkan_debug_callback(_: vk::DebugReportFlagsEXT, @@ -313,7 +306,7 @@ impl ExampleBase { pp_enabled_extension_names: device_extension_names_raw.as_ptr(), p_enabled_features: &features, }; - let device: Device = instance.create_device(pdevice, &device_create_info) + let device: Device = instance.create_device(pdevice, &device_create_info, None) .unwrap(); let present_queue = device.get_device_queue(queue_family_index as u32, 0); @@ -393,7 +386,7 @@ impl ExampleBase { flags: vk::COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queue_family_index: queue_family_index, }; - let pool = device.create_command_pool(&pool_create_info).unwrap(); + let pool = device.create_command_pool(&pool_create_info, None).unwrap(); let command_buffer_allocate_info = vk::CommandBufferAllocateInfo { s_type: vk::StructureType::CommandBufferAllocateInfo, p_next: ptr::null(), @@ -430,7 +423,7 @@ impl ExampleBase { }, image: image, }; - device.create_image_view(&create_view_info).unwrap() + device.create_image_view(&create_view_info, None).unwrap() }) .collect(); let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); @@ -455,7 +448,7 @@ impl ExampleBase { p_queue_family_indices: ptr::null(), initial_layout: vk::ImageLayout::Undefined, }; - let depth_image = device.create_image(&depth_image_create_info).unwrap(); + let depth_image = device.create_image(&depth_image_create_info, None).unwrap(); let depth_image_memory_req = device.get_image_memory_requirements(depth_image); let depth_image_memory_index = find_memorytype_index(&depth_image_memory_req, @@ -469,7 +462,8 @@ impl ExampleBase { allocation_size: depth_image_memory_req.size, memory_type_index: depth_image_memory_index, }; - let depth_image_memory = device.allocate_memory(&depth_image_allocate_info).unwrap(); + let depth_image_memory = device.allocate_memory(&depth_image_allocate_info, None) + .unwrap(); device.bind_image_memory(depth_image, depth_image_memory, 0) .expect("Unable to bind depth image memory"); @@ -512,7 +506,7 @@ impl ExampleBase { p_next: ptr::null(), flags: vk::FenceCreateFlags::empty(), }; - let submit_fence = device.create_fence(&fence_create_info).unwrap(); + 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(), @@ -548,15 +542,15 @@ impl ExampleBase { }, image: depth_image, }; - let depth_image_view = device.create_image_view(&depth_image_view_info).unwrap(); + let depth_image_view = device.create_image_view(&depth_image_view_info, None).unwrap(); let semaphore_create_info = vk::SemaphoreCreateInfo { s_type: vk::StructureType::SemaphoreCreateInfo, p_next: ptr::null(), flags: Default::default(), }; - let present_complete_semaphore = device.create_semaphore(&semaphore_create_info) + let present_complete_semaphore = device.create_semaphore(&semaphore_create_info, None) .unwrap(); - let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info) + let rendering_complete_semaphore = device.create_semaphore(&semaphore_create_info, None) .unwrap(); ExampleBase { entry: entry, @@ -593,17 +587,17 @@ impl Drop for ExampleBase { fn drop(&mut self) { unsafe { self.device.device_wait_idle().unwrap(); - self.device.destroy_semaphore(self.present_complete_semaphore); - self.device.destroy_semaphore(self.rendering_complete_semaphore); - self.device.destroy_image_view(self.depth_image_view); - self.device.destroy_image(self.depth_image); - self.device.free_memory(self.depth_image_memory); + self.device.destroy_semaphore(self.present_complete_semaphore, None); + self.device.destroy_semaphore(self.rendering_complete_semaphore, None); + self.device.destroy_image_view(self.depth_image_view, 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() { - self.device.destroy_image_view(image_view); + self.device.destroy_image_view(image_view, None); } - self.device.destroy_command_pool(self.pool); + self.device.destroy_command_pool(self.pool, None); self.swapchain_loader.destroy_swapchain_khr(self.swapchain); - self.device.destroy_device(); + self.device.destroy_device(None); self.surface_loader.destroy_surface_khr(self.surface); self.debug_report_loader.destroy_debug_report_callback_ext(self.debug_call_back); self.instance.destroy_instance();