From 962f1ba8304530f6352a06806dff7e95b96ad677 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 7 Dec 2018 11:47:57 -0600 Subject: [PATCH] reformatting via rust fmt --- examples/src/bin/texture.rs | 127 +++++++++++++++++++---------------- examples/src/bin/triangle.rs | 107 +++++++++++++++-------------- examples/src/lib.rs | 84 ++++++++++++----------- 3 files changed, 170 insertions(+), 148 deletions(-) diff --git a/examples/src/bin/texture.rs b/examples/src/bin/texture.rs index 822e70e..e3cdfd9 100644 --- a/examples/src/bin/texture.rs +++ b/examples/src/bin/texture.rs @@ -49,7 +49,7 @@ fn main() { load_op: vk::AttachmentLoadOp::CLEAR, initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - .. Default::default() + ..Default::default() }, ]; let color_attachment_refs = [vk::AttachmentReference { @@ -66,19 +66,19 @@ fn main() { dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, - .. Default::default() + ..Default::default() }]; let subpasses = [vk::SubpassDescription::builder() - .color_attachments( &color_attachment_refs) - .depth_stencil_attachment( &depth_attachment_ref) - .pipeline_bind_point( vk::PipelineBindPoint::GRAPHICS) - .build()]; + .color_attachments(&color_attachment_refs) + .depth_stencil_attachment(&depth_attachment_ref) + .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) + .build()]; let renderpass_create_info = vk::RenderPassCreateInfo::builder() .attachments(&renderpass_attachments) - .subpasses( &subpasses) - .dependencies( &dependencies); + .subpasses(&subpasses) + .dependencies(&dependencies); let renderpass = base .device @@ -91,22 +91,23 @@ fn main() { .map(|&present_image_view| { let framebuffer_attachments = [present_image_view, base.depth_image_view]; let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() - .render_pass( renderpass) + .render_pass(renderpass) .attachments(&framebuffer_attachments) .width(base.surface_resolution.width) - .height( base.surface_resolution.height) + .height(base.surface_resolution.height) .layers(1); base.device .create_framebuffer(&frame_buffer_create_info, None) .unwrap() - }).collect(); + }) + .collect(); let index_buffer_data = [0u32, 1, 2, 2, 3, 0]; let index_buffer_info = vk::BufferCreateInfo { size: std::mem::size_of_val(&index_buffer_data) as u64, usage: vk::BufferUsageFlags::INDEX_BUFFER, sharing_mode: vk::SharingMode::EXCLUSIVE, - .. Default::default() + ..Default::default() }; 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); @@ -114,7 +115,8 @@ fn main() { &index_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the index buffer."); + ) + .expect("Unable to find suitable memorytype for the index buffer."); let index_allocate_info = vk::MemoryAllocateInfo { allocation_size: index_buffer_memory_req.size, memory_type_index: index_buffer_memory_index, @@ -131,7 +133,8 @@ fn main() { 0, index_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut index_slice = Align::new( index_ptr, align_of::() as u64, @@ -178,7 +181,8 @@ fn main() { &vertex_input_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + ) + .expect("Unable to find suitable memorytype for the vertex buffer."); let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { allocation_size: vertex_input_buffer_memory_req.size, @@ -197,7 +201,8 @@ fn main() { 0, vertex_input_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut slice = Align::new( vert_ptr, align_of::() as u64, @@ -219,7 +224,7 @@ fn main() { size: std::mem::size_of_val(&uniform_color_buffer_data) as u64, usage: vk::BufferUsageFlags::UNIFORM_BUFFER, sharing_mode: vk::SharingMode::EXCLUSIVE, - .. Default::default() + ..Default::default() }; let uniform_color_buffer = base .device @@ -232,7 +237,8 @@ fn main() { &uniform_color_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + ) + .expect("Unable to find suitable memorytype for the vertex buffer."); let uniform_color_buffer_allocate_info = vk::MemoryAllocateInfo { allocation_size: uniform_color_buffer_memory_req.size, @@ -250,7 +256,8 @@ fn main() { 0, uniform_color_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut uniform_aligned_slice = Align::new( uniform_ptr, align_of::() as u64, @@ -277,7 +284,8 @@ fn main() { &image_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + ) + .expect("Unable to find suitable memorytype for the vertex buffer."); let image_buffer_allocate_info = vk::MemoryAllocateInfo { allocation_size: image_buffer_memory_req.size, @@ -295,7 +303,8 @@ fn main() { 0, image_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut image_slice = Align::new( image_ptr, std::mem::align_of::() as u64, @@ -332,7 +341,8 @@ fn main() { &texture_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::DEVICE_LOCAL, - ).expect("Unable to find suitable memory index for depth image."); + ) + .expect("Unable to find suitable memory index for depth image."); let texture_allocate_info = vk::MemoryAllocateInfo { allocation_size: texture_memory_req.size, @@ -387,7 +397,7 @@ fn main() { height: image_dimensions.1, depth: 1, }, - .. Default::default() + ..Default::default() }]; device.cmd_copy_buffer_to_image( texture_command_buffer, @@ -432,7 +442,7 @@ fn main() { max_anisotropy: 1.0, border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE, compare_op: vk::CompareOp::NEVER, - .. Default::default() + ..Default::default() }; let sampler = base.device.create_sampler(&sampler_info, None).unwrap(); @@ -453,7 +463,7 @@ fn main() { ..Default::default() }, image: texture_image, - .. Default::default() + ..Default::default() }; let tex_image_view = base .device @@ -471,7 +481,7 @@ fn main() { ]; let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder() .pool_sizes(&descriptor_sizes) - .max_sets( 1); + .max_sets(1); let descriptor_pool = base .device @@ -492,8 +502,8 @@ fn main() { ..Default::default() }, ]; - let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder() - .bindings(&desc_layout_bindings); + let descriptor_info = + vk::DescriptorSetLayoutCreateInfo::builder().bindings(&desc_layout_bindings); let desc_set_layouts = [base .device @@ -501,7 +511,7 @@ fn main() { .unwrap()]; let desc_alloc_info = vk::DescriptorSetAllocateInfo::builder() - .descriptor_pool( descriptor_pool) + .descriptor_pool(descriptor_pool) .set_layouts(&desc_set_layouts); let descriptor_sets = base .device @@ -526,7 +536,7 @@ fn main() { descriptor_count: 1, descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, p_buffer_info: &uniform_color_buffer_descriptor, - .. Default::default() + ..Default::default() }, vk::WriteDescriptorSet { dst_set: descriptor_sets[0], @@ -534,7 +544,7 @@ fn main() { descriptor_count: 1, descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, p_image_info: &tex_descriptor, - .. Default::default() + ..Default::default() }, ]; base.device.update_descriptor_sets(&write_desc_sets, &[]); @@ -565,8 +575,8 @@ fn main() { .create_shader_module(&frag_shader_info, None) .expect("Fragment shader module error"); - let layout_create_info = vk::PipelineLayoutCreateInfo::builder() - .set_layouts(&desc_set_layouts); + let layout_create_info = + vk::PipelineLayoutCreateInfo::builder().set_layouts(&desc_set_layouts); let pipeline_layout = base .device @@ -579,13 +589,13 @@ fn main() { module: vertex_shader_module, p_name: shader_entry_name.as_ptr(), stage: vk::ShaderStageFlags::VERTEX, - .. Default::default() + ..Default::default() }, vk::PipelineShaderStageCreateInfo { module: fragment_shader_module, p_name: shader_entry_name.as_ptr(), stage: vk::ShaderStageFlags::FRAGMENT, - .. Default::default() + ..Default::default() }, ]; let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription { @@ -613,7 +623,7 @@ fn main() { let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { topology: vk::PrimitiveTopology::TRIANGLE_LIST, - .. Default::default() + ..Default::default() }; let viewports = [vk::Viewport { x: 0.0, @@ -625,7 +635,7 @@ fn main() { }]; let scissors = [vk::Rect2D { extent: base.surface_resolution.clone(), - .. Default::default() + ..Default::default() }]; let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder() .scissors(&scissors) @@ -635,11 +645,11 @@ fn main() { front_face: vk::FrontFace::COUNTER_CLOCKWISE, line_width: 1.0, polygon_mode: vk::PolygonMode::FILL, - .. Default::default() + ..Default::default() }; let multisample_state_info = vk::PipelineMultisampleStateCreateInfo { rasterization_samples: vk::SampleCountFlags::TYPE_1, - .. Default::default() + ..Default::default() }; let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder() @@ -651,7 +661,7 @@ fn main() { pass_op: vk::StencilOp::KEEP, depth_fail_op: vk::StencilOp::KEEP, compare_op: vk::CompareOp::ALWAYS, - .. Default::default() + ..Default::default() }; let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { depth_test_enable: 1, @@ -660,7 +670,7 @@ fn main() { front: noop_stencil_state.clone(), back: noop_stencil_state.clone(), max_depth_bounds: 1.0, - .. Default::default() + ..Default::default() }; let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { @@ -674,25 +684,25 @@ fn main() { color_write_mask: vk::ColorComponentFlags::all(), }]; let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() - .logic_op( vk::LogicOp::CLEAR) - .attachments( &color_blend_attachment_states); + .logic_op(vk::LogicOp::CLEAR) + .attachments(&color_blend_attachment_states); let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; - let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder() - .dynamic_states(&dynamic_state); + let dynamic_state_info = + vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state); let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() .stages(&shader_stage_create_infos) - .vertex_input_state( &vertex_input_state_info) - .input_assembly_state( &vertex_input_assembly_state_info) - .viewport_state( &viewport_state_info) - .rasterization_state( &rasterization_info) - .multisample_state( &multisample_state_info) - .depth_stencil_state( &depth_state_info) - .color_blend_state( &color_blend_state) - .dynamic_state( &dynamic_state_info) - .layout( pipeline_layout) - .render_pass( renderpass) + .vertex_input_state(&vertex_input_state_info) + .input_assembly_state(&vertex_input_assembly_state_info) + .viewport_state(&viewport_state_info) + .rasterization_state(&rasterization_info) + .multisample_state(&multisample_state_info) + .depth_stencil_state(&depth_state_info) + .color_blend_state(&color_blend_state) + .dynamic_state(&dynamic_state_info) + .layout(pipeline_layout) + .render_pass(renderpass) .build(); let graphics_pipelines = base @@ -710,7 +720,8 @@ fn main() { std::u64::MAX, base.present_complete_semaphore, vk::Fence::null(), - ).unwrap(); + ) + .unwrap(); let clear_values = [ vk::ClearValue { color: vk::ClearColorValue { @@ -728,7 +739,7 @@ fn main() { let render_pass_begin_info = vk::RenderPassBeginInfo::builder() .render_pass(renderpass) .framebuffer(framebuffers[present_index as usize]) - .render_area( vk::Rect2D { + .render_area(vk::Rect2D { offset: vk::Offset2D { x: 0, y: 0 }, extent: base.surface_resolution.clone(), }) @@ -794,7 +805,7 @@ fn main() { swapchain_count: 1, p_swapchains: &base.swapchain, p_image_indices: &present_index, - .. Default::default() + ..Default::default() }; base.swapchain_loader .queue_present(base.present_queue, &present_info) diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 60a6efd..13f1d84 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -37,7 +37,7 @@ fn main() { load_op: vk::AttachmentLoadOp::CLEAR, initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - .. Default::default() + ..Default::default() }, ]; let color_attachment_refs = [vk::AttachmentReference { @@ -54,19 +54,19 @@ fn main() { dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, - .. Default::default() + ..Default::default() }]; let subpasses = [vk::SubpassDescription::builder() - .color_attachments(&color_attachment_refs) - .depth_stencil_attachment( &depth_attachment_ref) - .pipeline_bind_point( vk::PipelineBindPoint::GRAPHICS) - .build()]; + .color_attachments(&color_attachment_refs) + .depth_stencil_attachment(&depth_attachment_ref) + .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) + .build()]; let renderpass_create_info = vk::RenderPassCreateInfo::builder() - .attachments( &renderpass_attachments) - .subpasses( &subpasses) - .dependencies( &dependencies); + .attachments(&renderpass_attachments) + .subpasses(&subpasses) + .dependencies(&dependencies); let renderpass = base .device @@ -79,21 +79,22 @@ fn main() { .map(|&present_image_view| { let framebuffer_attachments = [present_image_view, base.depth_image_view]; let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() - .render_pass( renderpass) - .attachments( &framebuffer_attachments) - .width( base.surface_resolution.width) - .height( base.surface_resolution.height) + .render_pass(renderpass) + .attachments(&framebuffer_attachments) + .width(base.surface_resolution.width) + .height(base.surface_resolution.height) .layers(1); base.device .create_framebuffer(&frame_buffer_create_info, None) .unwrap() - }).collect(); + }) + .collect(); let index_buffer_data = [0u32, 1, 2]; let index_buffer_info = vk::BufferCreateInfo::builder() - .size( std::mem::size_of_val(&index_buffer_data) as u64) - .usage( vk::BufferUsageFlags::INDEX_BUFFER) + .size(std::mem::size_of_val(&index_buffer_data) as u64) + .usage(vk::BufferUsageFlags::INDEX_BUFFER) .sharing_mode(vk::SharingMode::EXCLUSIVE); let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap(); @@ -102,12 +103,13 @@ fn main() { &index_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the index buffer."); + ) + .expect("Unable to find suitable memorytype for the index buffer."); let index_allocate_info = vk::MemoryAllocateInfo { allocation_size: index_buffer_memory_req.size, memory_type_index: index_buffer_memory_index, - .. Default::default() + ..Default::default() }; let index_buffer_memory = base .device @@ -120,7 +122,8 @@ fn main() { 0, index_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut index_slice = Align::new( index_ptr, align_of::() as u64, @@ -136,7 +139,7 @@ fn main() { size: 3 * std::mem::size_of::() as u64, usage: vk::BufferUsageFlags::VERTEX_BUFFER, sharing_mode: vk::SharingMode::EXCLUSIVE, - .. Default::default() + ..Default::default() }; let vertex_input_buffer = base @@ -152,12 +155,13 @@ fn main() { &vertex_input_buffer_memory_req, &base.device_memory_properties, vk::MemoryPropertyFlags::HOST_VISIBLE, - ).expect("Unable to find suitable memorytype for the vertex buffer."); + ) + .expect("Unable to find suitable memorytype for the vertex buffer."); let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { allocation_size: vertex_input_buffer_memory_req.size, memory_type_index: vertex_input_buffer_memory_index, - .. Default::default() + ..Default::default() }; let vertex_input_buffer_memory = base @@ -187,7 +191,8 @@ fn main() { 0, vertex_input_buffer_memory_req.size, vk::MemoryMapFlags::empty(), - ).unwrap(); + ) + .unwrap(); let mut vert_align = Align::new( vert_ptr, @@ -239,14 +244,14 @@ fn main() { module: vertex_shader_module, p_name: shader_entry_name.as_ptr(), stage: vk::ShaderStageFlags::VERTEX, - .. Default::default() + ..Default::default() }, vk::PipelineShaderStageCreateInfo { s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO, module: fragment_shader_module, p_name: shader_entry_name.as_ptr(), stage: vk::ShaderStageFlags::FRAGMENT, - .. Default::default() + ..Default::default() }, ]; let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription { @@ -274,12 +279,11 @@ fn main() { p_vertex_attribute_descriptions: vertex_input_attribute_descriptions.as_ptr(), vertex_binding_description_count: vertex_input_binding_descriptions.len() as u32, p_vertex_binding_descriptions: vertex_input_binding_descriptions.as_ptr(), - .. Default::default() + ..Default::default() }; let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { topology: vk::PrimitiveTopology::TRIANGLE_LIST, - .. Default::default() - + ..Default::default() }; let viewports = [vk::Viewport { x: 0.0, @@ -301,18 +305,18 @@ fn main() { front_face: vk::FrontFace::COUNTER_CLOCKWISE, line_width: 1.0, polygon_mode: vk::PolygonMode::FILL, - .. Default::default() + ..Default::default() }; let multisample_state_info = vk::PipelineMultisampleStateCreateInfo { rasterization_samples: vk::SampleCountFlags::TYPE_1, - .. Default::default() + ..Default::default() }; let noop_stencil_state = vk::StencilOpState { fail_op: vk::StencilOp::KEEP, pass_op: vk::StencilOp::KEEP, depth_fail_op: vk::StencilOp::KEEP, compare_op: vk::CompareOp::ALWAYS, - .. Default::default() + ..Default::default() }; let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { depth_test_enable: 1, @@ -321,7 +325,7 @@ fn main() { front: noop_stencil_state.clone(), back: noop_stencil_state.clone(), max_depth_bounds: 1.0, - .. Default::default() + ..Default::default() }; let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { blend_enable: 0, @@ -334,29 +338,27 @@ fn main() { color_write_mask: vk::ColorComponentFlags::all(), }]; let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() - .logic_op( vk::LogicOp::CLEAR) - .attachments( &color_blend_attachment_states); + .logic_op(vk::LogicOp::CLEAR) + .attachments(&color_blend_attachment_states); let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; - let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder() - .dynamic_states(&dynamic_state); - + let dynamic_state_info = + vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state); let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() .stages(&shader_stage_create_infos) - .vertex_input_state( &vertex_input_state_info) - .input_assembly_state( &vertex_input_assembly_state_info) + .vertex_input_state(&vertex_input_state_info) + .input_assembly_state(&vertex_input_assembly_state_info) .viewport_state(&viewport_state_info) - .rasterization_state( &rasterization_info) - .multisample_state( &multisample_state_info) + .rasterization_state(&rasterization_info) + .multisample_state(&multisample_state_info) .depth_stencil_state(&depth_state_info) - .color_blend_state( &color_blend_state) - .dynamic_state( &dynamic_state_info) - .layout( pipeline_layout) + .color_blend_state(&color_blend_state) + .dynamic_state(&dynamic_state_info) + .layout(pipeline_layout) .render_pass(renderpass) .build(); - let graphics_pipelines = base .device .create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None) @@ -372,7 +374,8 @@ fn main() { std::u64::MAX, base.present_complete_semaphore, vk::Fence::null(), - ).unwrap(); + ) + .unwrap(); let clear_values = [ vk::ClearValue { color: vk::ClearColorValue { @@ -389,12 +392,12 @@ fn main() { let render_pass_begin_info = vk::RenderPassBeginInfo::builder() .render_pass(renderpass) - .framebuffer( framebuffers[present_index as usize]) - .render_area( vk::Rect2D { + .framebuffer(framebuffers[present_index as usize]) + .render_area(vk::Rect2D { offset: vk::Offset2D { x: 0, y: 0 }, extent: base.surface_resolution.clone(), }) - .clear_values( &clear_values); + .clear_values(&clear_values); record_submit_commandbuffer( &base.device, @@ -446,9 +449,9 @@ fn main() { let swapchains = [base.swapchain]; let image_indices = [present_index]; let present_info = vk::PresentInfoKHR::builder() - .wait_semaphores( &wait_semaphors) // &base.rendering_complete_semaphore) - .swapchains( &swapchains) - .image_indices( &image_indices); + .wait_semaphores(&wait_semaphors) // &base.rendering_complete_semaphore) + .swapchains(&swapchains) + .image_indices(&image_indices); base.swapchain_loader .queue_present(base.present_queue, &present_info) diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 69c7196..7a96d3e 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -36,7 +36,7 @@ use ash::extensions::khr::Win32Surface; use ash::extensions::mvk::MacOSSurface; pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0}; use ash::{vk, Device, Entry, Instance}; -use byteorder::{LittleEndian, BigEndian, ReadBytesExt}; +use byteorder::{BigEndian, LittleEndian, ReadBytesExt}; use std::cell::RefCell; use std::default::Default; use std::ffi::{CStr, CString}; @@ -45,12 +45,11 @@ use std::ops::Drop; use std::os::raw::{c_char, c_void}; use std::ptr; - const MAGIC_NUMBER: u32 = 0x07230203; -fn spirv_is_little_endian(bytes: &[u8] ) -> bool { - let buffer: [u8;4] = [bytes[0], bytes[1],bytes[2],bytes[3]]; - let number : u32 = Cursor::new(buffer).read_u32::().unwrap(); +fn spirv_is_little_endian(bytes: &[u8]) -> bool { + let buffer: [u8; 4] = [bytes[0], bytes[1], bytes[2], bytes[3]]; + let number: u32 = Cursor::new(buffer).read_u32::().unwrap(); number == MAGIC_NUMBER } @@ -62,7 +61,7 @@ pub fn bytes_to_u32_vec(bytes: &[u8]) -> Vec { let idx = i % 4; buffer[idx] = *b; if idx == 3 { - let new_word = if is_little_endian { + let new_word = if is_little_endian { Cursor::new(buffer).read_u32::().unwrap() } else { Cursor::new(buffer).read_u32::().unwrap() @@ -131,7 +130,8 @@ pub fn record_submit_commandbuffer Some((*pdevice, index)), _ => None, } - }).nth(0) - }).filter_map(|v| v) + }) + .nth(0) + }) + .filter_map(|v| v) .nth(0) .expect("Couldn't find suitable device."); let queue_family_index = queue_family_index as u32; @@ -463,9 +467,9 @@ impl ExampleBase { let priorities = [1.0]; let queue_info = [vk::DeviceQueueCreateInfo::builder() - .queue_family_index(queue_family_index) - .queue_priorities(&priorities) - .build()]; + .queue_family_index(queue_family_index) + .queue_priorities(&priorities) + .build()]; let device_create_info = vk::DeviceCreateInfo::builder() .queue_create_infos(&queue_info) @@ -488,7 +492,8 @@ impl ExampleBase { color_space: sfmt.color_space, }, _ => sfmt.clone(), - }).nth(0) + }) + .nth(0) .expect("Unable to find suitable surface format."); let surface_capabilities = surface_loader .get_physical_device_surface_capabilities(pdevice, surface) @@ -526,17 +531,17 @@ impl ExampleBase { let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder() .surface(surface) - .min_image_count( desired_image_count) - .image_color_space( surface_format.color_space) - .image_format( surface_format.format) - .image_extent( surface_resolution.clone()) - .image_usage( vk::ImageUsageFlags::COLOR_ATTACHMENT) + .min_image_count(desired_image_count) + .image_color_space(surface_format.color_space) + .image_format(surface_format.format) + .image_extent(surface_resolution.clone()) + .image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT) .image_sharing_mode(vk::SharingMode::EXCLUSIVE) - .pre_transform( pre_transform) - .composite_alpha( vk::CompositeAlphaFlagsKHR::OPAQUE) - .present_mode( present_mode) + .pre_transform(pre_transform) + .composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE) + .present_mode(present_mode) .clipped(true) - .image_array_layers( 1); + .image_array_layers(1); let swapchain = swapchain_loader .create_swapchain(&swapchain_create_info, None) @@ -564,39 +569,40 @@ impl ExampleBase { .iter() .map(|&image| { let create_view_info = vk::ImageViewCreateInfo::builder() - .view_type( vk::ImageViewType::TYPE_2D) + .view_type(vk::ImageViewType::TYPE_2D) .format(surface_format.format) - .components( vk::ComponentMapping { + .components(vk::ComponentMapping { r: vk::ComponentSwizzle::R, g: vk::ComponentSwizzle::G, b: vk::ComponentSwizzle::B, a: vk::ComponentSwizzle::A, }) - .subresource_range( vk::ImageSubresourceRange { + .subresource_range(vk::ImageSubresourceRange { aspect_mask: vk::ImageAspectFlags::COLOR, base_mip_level: 0, level_count: 1, base_array_layer: 0, layer_count: 1, }) - .image( image); + .image(image); device.create_image_view(&create_view_info, None).unwrap() - }).collect(); + }) + .collect(); let device_memory_properties = instance.get_physical_device_memory_properties(pdevice); let depth_image_create_info = vk::ImageCreateInfo::builder() - .image_type( vk::ImageType::TYPE_2D) - .format( vk::Format::D16_UNORM) - .extent( vk::Extent3D { + .image_type(vk::ImageType::TYPE_2D) + .format(vk::Format::D16_UNORM) + .extent(vk::Extent3D { width: surface_resolution.width, height: surface_resolution.height, depth: 1, }) - .mip_levels( 1) - .array_layers( 1) - .samples( vk::SampleCountFlags::TYPE_1) - .tiling( vk::ImageTiling::OPTIMAL) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::TYPE_1) + .tiling(vk::ImageTiling::OPTIMAL) .usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT) - .sharing_mode( vk::SharingMode::EXCLUSIVE); + .sharing_mode(vk::SharingMode::EXCLUSIVE); let depth_image = device.create_image(&depth_image_create_info, None).unwrap(); let depth_image_memory_req = device.get_image_memory_requirements(depth_image); @@ -604,7 +610,8 @@ impl ExampleBase { &depth_image_memory_req, &device_memory_properties, vk::MemoryPropertyFlags::DEVICE_LOCAL, - ).expect("Unable to find suitable memory index for depth image."); + ) + .expect("Unable to find suitable memory index for depth image."); let depth_image_allocate_info = vk::MemoryAllocateInfo::builder() .allocation_size(depth_image_memory_req.size) @@ -624,6 +631,7 @@ impl ExampleBase { setup_command_buffer, present_queue, &[], + // &[vk::PipelineStageFlags::BOTTOM_OF_PIPE], &[], &[], |device, setup_command_buffer| {