reformatted with fmt

This commit is contained in:
colin 2018-12-06 13:18:37 -06:00
parent 2855192145
commit 046989ad75
3 changed files with 109 additions and 132 deletions

View file

@ -41,7 +41,7 @@ fn main() {
load_op: vk::AttachmentLoadOp::CLEAR, load_op: vk::AttachmentLoadOp::CLEAR,
store_op: vk::AttachmentStoreOp::STORE, store_op: vk::AttachmentStoreOp::STORE,
final_layout: vk::ImageLayout::PRESENT_SRC_KHR, final_layout: vk::ImageLayout::PRESENT_SRC_KHR,
.. Default::default() ..Default::default()
}, },
vk::AttachmentDescription { vk::AttachmentDescription {
format: vk::Format::D16_UNORM, format: vk::Format::D16_UNORM,
@ -49,11 +49,10 @@ fn main() {
load_op: vk::AttachmentLoadOp::CLEAR, load_op: vk::AttachmentLoadOp::CLEAR,
initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, initial_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.. Default::default() ..Default::default()
}, },
]; ];
let color_attachment_ref = vk::AttachmentReference { let color_attachment_ref = vk::AttachmentReference {
attachment: 0, attachment: 0,
layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL, layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
@ -69,21 +68,18 @@ fn main() {
dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ
| vk::AccessFlags::COLOR_ATTACHMENT_WRITE, | vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT,
.. Default::default() ..Default::default()
}; };
let subpass = vk::SubpassDescription::builder() let subpass = vk::SubpassDescription::builder()
.color_attachments(&[color_attachment_ref]) .color_attachments(&[color_attachment_ref])
.depth_stencil_attachment(&depth_attachment_ref) .depth_stencil_attachment(&depth_attachment_ref)
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS)
.build(); .build();
let renderpass_create_info = vk::RenderPassCreateInfo::builder() let renderpass_create_info = vk::RenderPassCreateInfo::builder()
.attachments(&renderpass_attachments) .attachments(&renderpass_attachments)
.subpasses( &[subpass]) .subpasses(&[subpass])
.dependencies(&[dependency]) .dependencies(&[dependency])
.build(); .build();
@ -100,9 +96,9 @@ fn main() {
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
.render_pass(renderpass) .render_pass(renderpass)
.attachments(&framebuffer_attachments) .attachments(&framebuffer_attachments)
.width( base.surface_resolution.width) .width(base.surface_resolution.width)
.height( base.surface_resolution.height) .height(base.surface_resolution.height)
.layers( 1) .layers(1)
.build(); .build();
base.device base.device
@ -114,7 +110,7 @@ fn main() {
size: std::mem::size_of_val(&index_buffer_data) as u64, size: std::mem::size_of_val(&index_buffer_data) as u64,
usage: vk::BufferUsageFlags::INDEX_BUFFER, usage: vk::BufferUsageFlags::INDEX_BUFFER,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let index_buffer = base.device.create_buffer(&index_buffer_info, None).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_req = base.device.get_buffer_memory_requirements(index_buffer);
@ -126,7 +122,7 @@ fn main() {
let index_allocate_info = vk::MemoryAllocateInfo { let index_allocate_info = vk::MemoryAllocateInfo {
allocation_size: index_buffer_memory_req.size, allocation_size: index_buffer_memory_req.size,
memory_type_index: index_buffer_memory_index, memory_type_index: index_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let index_buffer_memory = base let index_buffer_memory = base
.device .device
@ -173,7 +169,7 @@ fn main() {
size: std::mem::size_of_val(&vertices) as u64, size: std::mem::size_of_val(&vertices) as u64,
usage: vk::BufferUsageFlags::VERTEX_BUFFER, usage: vk::BufferUsageFlags::VERTEX_BUFFER,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let vertex_input_buffer = base let vertex_input_buffer = base
.device .device
@ -191,7 +187,7 @@ fn main() {
let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { let vertex_buffer_allocate_info = vk::MemoryAllocateInfo {
allocation_size: vertex_input_buffer_memory_req.size, allocation_size: vertex_input_buffer_memory_req.size,
memory_type_index: vertex_input_buffer_memory_index, memory_type_index: vertex_input_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let vertex_input_buffer_memory = base let vertex_input_buffer_memory = base
.device .device
@ -227,7 +223,7 @@ fn main() {
size: std::mem::size_of_val(&uniform_color_buffer_data) as u64, size: std::mem::size_of_val(&uniform_color_buffer_data) as u64,
usage: vk::BufferUsageFlags::UNIFORM_BUFFER, usage: vk::BufferUsageFlags::UNIFORM_BUFFER,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let uniform_color_buffer = base let uniform_color_buffer = base
.device .device
@ -245,7 +241,7 @@ fn main() {
let uniform_color_buffer_allocate_info = vk::MemoryAllocateInfo { let uniform_color_buffer_allocate_info = vk::MemoryAllocateInfo {
allocation_size: uniform_color_buffer_memory_req.size, allocation_size: uniform_color_buffer_memory_req.size,
memory_type_index: uniform_color_buffer_memory_index, memory_type_index: uniform_color_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let uniform_color_buffer_memory = base let uniform_color_buffer_memory = base
.device .device
@ -277,7 +273,7 @@ fn main() {
size: (std::mem::size_of::<u8>() * image_data.len()) as u64, size: (std::mem::size_of::<u8>() * image_data.len()) as u64,
usage: vk::BufferUsageFlags::TRANSFER_SRC, usage: vk::BufferUsageFlags::TRANSFER_SRC,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let image_buffer = base.device.create_buffer(&image_buffer_info, None).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_req = base.device.get_buffer_memory_requirements(image_buffer);
@ -290,7 +286,7 @@ fn main() {
let image_buffer_allocate_info = vk::MemoryAllocateInfo { let image_buffer_allocate_info = vk::MemoryAllocateInfo {
allocation_size: image_buffer_memory_req.size, allocation_size: image_buffer_memory_req.size,
memory_type_index: image_buffer_memory_index, memory_type_index: image_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let image_buffer_memory = base let image_buffer_memory = base
.device .device
@ -329,7 +325,7 @@ fn main() {
tiling: vk::ImageTiling::OPTIMAL, tiling: vk::ImageTiling::OPTIMAL,
usage: vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED, usage: vk::ImageUsageFlags::TRANSFER_DST | vk::ImageUsageFlags::SAMPLED,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let texture_image = base let texture_image = base
.device .device
@ -345,7 +341,7 @@ fn main() {
let texture_allocate_info = vk::MemoryAllocateInfo { let texture_allocate_info = vk::MemoryAllocateInfo {
allocation_size: texture_memory_req.size, allocation_size: texture_memory_req.size,
memory_type_index: texture_memory_index, memory_type_index: texture_memory_index,
.. Default::default() ..Default::default()
}; };
let texture_memory = base let texture_memory = base
.device .device
@ -371,9 +367,9 @@ fn main() {
aspect_mask: vk::ImageAspectFlags::COLOR, aspect_mask: vk::ImageAspectFlags::COLOR,
level_count: 1, level_count: 1,
layer_count: 1, layer_count: 1,
.. Default::default() ..Default::default()
}, },
.. Default::default() ..Default::default()
}; };
device.cmd_pipeline_barrier( device.cmd_pipeline_barrier(
texture_command_buffer, texture_command_buffer,
@ -384,22 +380,17 @@ fn main() {
&[], &[],
&[texture_barrier], &[texture_barrier],
); );
let buffer_copy_regions = [ let buffer_copy_regions = [vk::BufferImageCopy::builder()
vk::BufferImageCopy::builder()
.image_subresource( .image_subresource(
vk::ImageSubresourceLayers::builder() vk::ImageSubresourceLayers::builder()
.aspect_mask( vk::ImageAspectFlags::COLOR) .aspect_mask(vk::ImageAspectFlags::COLOR)
.layer_count(1) .layer_count(1)
.build() .build(),
) ).image_extent(vk::Extent3D {
.image_extent(
vk::Extent3D {
width: image_dimensions.0, width: image_dimensions.0,
height: image_dimensions.1, height: image_dimensions.1,
depth: 1, depth: 1,
}) }).build()];
.build()
];
device.cmd_copy_buffer_to_image( device.cmd_copy_buffer_to_image(
texture_command_buffer, texture_command_buffer,
image_buffer, image_buffer,
@ -417,9 +408,9 @@ fn main() {
aspect_mask: vk::ImageAspectFlags::COLOR, aspect_mask: vk::ImageAspectFlags::COLOR,
level_count: 1, level_count: 1,
layer_count: 1, layer_count: 1,
.. Default::default() ..Default::default()
}, },
.. Default::default() ..Default::default()
}; };
device.cmd_pipeline_barrier( device.cmd_pipeline_barrier(
texture_command_buffer, texture_command_buffer,
@ -441,7 +432,7 @@ fn main() {
address_mode_v: vk::SamplerAddressMode::MIRRORED_REPEAT, address_mode_v: vk::SamplerAddressMode::MIRRORED_REPEAT,
address_mode_w: vk::SamplerAddressMode::MIRRORED_REPEAT, address_mode_w: vk::SamplerAddressMode::MIRRORED_REPEAT,
max_anisotropy: 1.0, max_anisotropy: 1.0,
.. Default::default() ..Default::default()
}; };
let sampler = base.device.create_sampler(&sampler_info, None).unwrap(); let sampler = base.device.create_sampler(&sampler_info, None).unwrap();
@ -459,10 +450,10 @@ fn main() {
aspect_mask: vk::ImageAspectFlags::COLOR, aspect_mask: vk::ImageAspectFlags::COLOR,
level_count: 1, level_count: 1,
layer_count: 1, layer_count: 1,
.. Default::default() ..Default::default()
}, },
image: texture_image, image: texture_image,
.. Default::default() ..Default::default()
}; };
let tex_image_view = base let tex_image_view = base
.device .device
@ -491,14 +482,14 @@ fn main() {
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
descriptor_count: 1, descriptor_count: 1,
stage_flags: vk::ShaderStageFlags::FRAGMENT, stage_flags: vk::ShaderStageFlags::FRAGMENT,
.. Default::default() ..Default::default()
}, },
vk::DescriptorSetLayoutBinding { vk::DescriptorSetLayoutBinding {
binding: 1, binding: 1,
descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
descriptor_count: 1, descriptor_count: 1,
stage_flags: vk::ShaderStageFlags::FRAGMENT, stage_flags: vk::ShaderStageFlags::FRAGMENT,
.. Default::default() ..Default::default()
}, },
]; ];
let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder() let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder()
@ -536,7 +527,7 @@ fn main() {
descriptor_count: 1, descriptor_count: 1,
descriptor_type: vk::DescriptorType::UNIFORM_BUFFER, descriptor_type: vk::DescriptorType::UNIFORM_BUFFER,
p_buffer_info: &uniform_color_buffer_descriptor, p_buffer_info: &uniform_color_buffer_descriptor,
.. Default::default() ..Default::default()
}, },
vk::WriteDescriptorSet { vk::WriteDescriptorSet {
dst_set: descriptor_sets[0], dst_set: descriptor_sets[0],
@ -544,7 +535,7 @@ fn main() {
descriptor_count: 1, descriptor_count: 1,
descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
p_image_info: &tex_descriptor, p_image_info: &tex_descriptor,
.. Default::default() ..Default::default()
}, },
]; ];
base.device.update_descriptor_sets(&write_desc_sets, &[]); base.device.update_descriptor_sets(&write_desc_sets, &[]);
@ -564,9 +555,7 @@ fn main() {
.code(&vertex_bytes) .code(&vertex_bytes)
.build(); .build();
let frag_bytes: Vec<u8> = frag_spv_file.bytes() let frag_bytes: Vec<u8> = frag_spv_file.bytes().filter_map(|byte| byte.ok()).collect();
.filter_map(|byte| byte.ok())
.collect();
let frag_bytes = examples::bytes_to_u32_vec(frag_bytes.iter().cloned()); let frag_bytes = examples::bytes_to_u32_vec(frag_bytes.iter().cloned());
@ -599,13 +588,13 @@ fn main() {
module: vertex_shader_module, module: vertex_shader_module,
p_name: shader_entry_name.as_ptr(), p_name: shader_entry_name.as_ptr(),
stage: vk::ShaderStageFlags::VERTEX, stage: vk::ShaderStageFlags::VERTEX,
.. Default::default() ..Default::default()
}, },
vk::PipelineShaderStageCreateInfo { vk::PipelineShaderStageCreateInfo {
module: fragment_shader_module, module: fragment_shader_module,
p_name: shader_entry_name.as_ptr(), p_name: shader_entry_name.as_ptr(),
stage: vk::ShaderStageFlags::FRAGMENT, stage: vk::ShaderStageFlags::FRAGMENT,
.. Default::default() ..Default::default()
}, },
]; ];
let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription { let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription {
@ -658,11 +647,11 @@ fn main() {
front_face: vk::FrontFace::COUNTER_CLOCKWISE, front_face: vk::FrontFace::COUNTER_CLOCKWISE,
line_width: 1.0, line_width: 1.0,
polygon_mode: vk::PolygonMode::FILL, polygon_mode: vk::PolygonMode::FILL,
.. Default::default() ..Default::default()
}; };
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder() let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder()
.rasterization_samples( vk::SampleCountFlags::TYPE_1) .rasterization_samples(vk::SampleCountFlags::TYPE_1)
.build(); .build();
let noop_stencil_state = vk::StencilOpState { let noop_stencil_state = vk::StencilOpState {
@ -670,7 +659,7 @@ fn main() {
pass_op: vk::StencilOp::KEEP, pass_op: vk::StencilOp::KEEP,
depth_fail_op: vk::StencilOp::KEEP, depth_fail_op: vk::StencilOp::KEEP,
compare_op: vk::CompareOp::ALWAYS, compare_op: vk::CompareOp::ALWAYS,
.. Default::default() ..Default::default()
}; };
let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { let depth_state_info = vk::PipelineDepthStencilStateCreateInfo {
depth_test_enable: 1, depth_test_enable: 1,
@ -679,7 +668,7 @@ fn main() {
front: noop_stencil_state.clone(), front: noop_stencil_state.clone(),
back: noop_stencil_state.clone(), back: noop_stencil_state.clone(),
max_depth_bounds: 1.0, max_depth_bounds: 1.0,
.. Default::default() ..Default::default()
}; };
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
@ -752,8 +741,7 @@ fn main() {
.render_area(vk::Rect2D { .render_area(vk::Rect2D {
offset: vk::Offset2D { x: 0, y: 0 }, offset: vk::Offset2D { x: 0, y: 0 },
extent: base.surface_resolution.clone(), extent: base.surface_resolution.clone(),
}) }).clear_values(&clear_values)
.clear_values(&clear_values)
.build(); .build();
record_submit_commandbuffer( record_submit_commandbuffer(
@ -813,8 +801,8 @@ fn main() {
let present_info = vk::PresentInfoKHR::builder() let present_info = vk::PresentInfoKHR::builder()
.wait_semaphores(&[base.rendering_complete_semaphore]) .wait_semaphores(&[base.rendering_complete_semaphore])
.swapchains( &[base.swapchain]) .swapchains(&[base.swapchain])
.image_indices( &[present_index]) .image_indices(&[present_index])
.build(); .build();
base.swapchain_loader base.swapchain_loader

View file

@ -29,14 +29,14 @@ fn main() {
load_op: vk::AttachmentLoadOp::CLEAR, load_op: vk::AttachmentLoadOp::CLEAR,
store_op: vk::AttachmentStoreOp::STORE, store_op: vk::AttachmentStoreOp::STORE,
final_layout: vk::ImageLayout::PRESENT_SRC_KHR, final_layout: vk::ImageLayout::PRESENT_SRC_KHR,
.. Default::default() ..Default::default()
}, },
vk::AttachmentDescription { vk::AttachmentDescription {
format: vk::Format::D16_UNORM, format: vk::Format::D16_UNORM,
samples: vk::SampleCountFlags::TYPE_1, samples: vk::SampleCountFlags::TYPE_1,
load_op: vk::AttachmentLoadOp::CLEAR, load_op: vk::AttachmentLoadOp::CLEAR,
final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL, final_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
.. Default::default() ..Default::default()
}, },
]; ];
let color_attachment_ref = vk::AttachmentReference { let color_attachment_ref = vk::AttachmentReference {
@ -53,11 +53,11 @@ fn main() {
dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ dst_access_mask: vk::AccessFlags::COLOR_ATTACHMENT_READ
| vk::AccessFlags::COLOR_ATTACHMENT_WRITE, | vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT, dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT,
.. Default::default() ..Default::default()
}; };
let subpass = vk::SubpassDescription::builder() let subpass = vk::SubpassDescription::builder()
.color_attachments( &[color_attachment_ref]) .color_attachments(&[color_attachment_ref])
.depth_stencil_attachment( &depth_attachment_ref) .depth_stencil_attachment(&depth_attachment_ref)
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS)
.build(); .build();
@ -78,9 +78,9 @@ fn main() {
let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() let frame_buffer_create_info = vk::FramebufferCreateInfo::builder()
.render_pass(renderpass) .render_pass(renderpass)
.attachments(&framebuffer_attachments) .attachments(&framebuffer_attachments)
.width( base.surface_resolution.width) .width(base.surface_resolution.width)
.height( base.surface_resolution.height) .height(base.surface_resolution.height)
.layers( 1) .layers(1)
.build(); .build();
base.device base.device
.create_framebuffer(&frame_buffer_create_info, None) .create_framebuffer(&frame_buffer_create_info, None)
@ -91,7 +91,7 @@ fn main() {
size: std::mem::size_of_val(&index_buffer_data) as u64, size: std::mem::size_of_val(&index_buffer_data) as u64,
usage: vk::BufferUsageFlags::INDEX_BUFFER, usage: vk::BufferUsageFlags::INDEX_BUFFER,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let index_buffer = base.device.create_buffer(&index_buffer_info, None).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_req = base.device.get_buffer_memory_requirements(index_buffer);
@ -103,7 +103,7 @@ fn main() {
let index_allocate_info = vk::MemoryAllocateInfo { let index_allocate_info = vk::MemoryAllocateInfo {
allocation_size: index_buffer_memory_req.size, allocation_size: index_buffer_memory_req.size,
memory_type_index: index_buffer_memory_index, memory_type_index: index_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let index_buffer_memory = base let index_buffer_memory = base
.device .device
@ -132,7 +132,7 @@ fn main() {
size: 3 * std::mem::size_of::<Vertex>() as u64, size: 3 * std::mem::size_of::<Vertex>() as u64,
usage: vk::BufferUsageFlags::VERTEX_BUFFER, usage: vk::BufferUsageFlags::VERTEX_BUFFER,
sharing_mode: vk::SharingMode::EXCLUSIVE, sharing_mode: vk::SharingMode::EXCLUSIVE,
.. Default::default() ..Default::default()
}; };
let vertex_input_buffer = base let vertex_input_buffer = base
.device .device
@ -150,7 +150,7 @@ fn main() {
let vertex_buffer_allocate_info = vk::MemoryAllocateInfo { let vertex_buffer_allocate_info = vk::MemoryAllocateInfo {
allocation_size: vertex_input_buffer_memory_req.size, allocation_size: vertex_input_buffer_memory_req.size,
memory_type_index: vertex_input_buffer_memory_index, memory_type_index: vertex_input_buffer_memory_index,
.. Default::default() ..Default::default()
}; };
let vertex_input_buffer_memory = base let vertex_input_buffer_memory = base
.device .device
@ -232,13 +232,13 @@ fn main() {
module: vertex_shader_module, module: vertex_shader_module,
p_name: shader_entry_name.as_ptr(), p_name: shader_entry_name.as_ptr(),
stage: vk::ShaderStageFlags::VERTEX, stage: vk::ShaderStageFlags::VERTEX,
.. Default::default() ..Default::default()
}, },
vk::PipelineShaderStageCreateInfo { vk::PipelineShaderStageCreateInfo {
module: fragment_shader_module, module: fragment_shader_module,
p_name: shader_entry_name.as_ptr(), p_name: shader_entry_name.as_ptr(),
stage: vk::ShaderStageFlags::FRAGMENT, stage: vk::ShaderStageFlags::FRAGMENT,
.. Default::default() ..Default::default()
}, },
]; ];
let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription { let vertex_input_binding_descriptions = [vk::VertexInputBindingDescription {
@ -267,7 +267,7 @@ fn main() {
let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo {
topology: vk::PrimitiveTopology::TRIANGLE_LIST, topology: vk::PrimitiveTopology::TRIANGLE_LIST,
.. Default::default() ..Default::default()
}; };
let viewports = [vk::Viewport { let viewports = [vk::Viewport {
x: 0.0, x: 0.0,
@ -289,18 +289,18 @@ fn main() {
front_face: vk::FrontFace::COUNTER_CLOCKWISE, front_face: vk::FrontFace::COUNTER_CLOCKWISE,
line_width: 1.0, line_width: 1.0,
polygon_mode: vk::PolygonMode::FILL, polygon_mode: vk::PolygonMode::FILL,
.. Default::default() ..Default::default()
}; };
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo { let multisample_state_info = vk::PipelineMultisampleStateCreateInfo {
rasterization_samples: vk::SampleCountFlags::TYPE_1, rasterization_samples: vk::SampleCountFlags::TYPE_1,
.. Default::default() ..Default::default()
}; };
let noop_stencil_state = vk::StencilOpState { let noop_stencil_state = vk::StencilOpState {
fail_op: vk::StencilOp::KEEP, fail_op: vk::StencilOp::KEEP,
pass_op: vk::StencilOp::KEEP, pass_op: vk::StencilOp::KEEP,
depth_fail_op: vk::StencilOp::KEEP, depth_fail_op: vk::StencilOp::KEEP,
compare_op: vk::CompareOp::ALWAYS, compare_op: vk::CompareOp::ALWAYS,
.. Default::default() ..Default::default()
}; };
let depth_state_info = vk::PipelineDepthStencilStateCreateInfo { let depth_state_info = vk::PipelineDepthStencilStateCreateInfo {
depth_test_enable: 1, depth_test_enable: 1,
@ -309,7 +309,7 @@ fn main() {
front: noop_stencil_state.clone(), front: noop_stencil_state.clone(),
back: noop_stencil_state.clone(), back: noop_stencil_state.clone(),
max_depth_bounds: 1.0, max_depth_bounds: 1.0,
.. Default::default() ..Default::default()
}; };
let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState { let color_blend_attachment_states = [vk::PipelineColorBlendAttachmentState {
blend_enable: 0, blend_enable: 0,
@ -322,7 +322,7 @@ fn main() {
color_write_mask: vk::ColorComponentFlags::all(), color_write_mask: vk::ColorComponentFlags::all(),
}]; }];
let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder()
.logic_op( vk::LogicOp::CLEAR) .logic_op(vk::LogicOp::CLEAR)
.attachments(&color_blend_attachment_states) .attachments(&color_blend_attachment_states)
.build(); .build();
@ -333,16 +333,16 @@ fn main() {
let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() let graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder()
.stages(&shader_stage_create_infos) .stages(&shader_stage_create_infos)
.vertex_input_state( &vertex_input_state_info) .vertex_input_state(&vertex_input_state_info)
.input_assembly_state( &vertex_input_assembly_state_info) .input_assembly_state(&vertex_input_assembly_state_info)
.viewport_state( &viewport_state_info) .viewport_state(&viewport_state_info)
.rasterization_state( &rasterization_info) .rasterization_state(&rasterization_info)
.multisample_state( &multisample_state_info) .multisample_state(&multisample_state_info)
.depth_stencil_state( &depth_state_info) .depth_stencil_state(&depth_state_info)
.color_blend_state( &color_blend_state) .color_blend_state(&color_blend_state)
.dynamic_state( &dynamic_state_info) .dynamic_state(&dynamic_state_info)
.layout( pipeline_layout) .layout(pipeline_layout)
.render_pass( renderpass) .render_pass(renderpass)
.build(); .build();
let graphics_pipelines = base let graphics_pipelines = base
.device .device
@ -433,9 +433,9 @@ fn main() {
); );
//let mut present_info_err = mem::uninitialized(); //let mut present_info_err = mem::uninitialized();
let present_info = vk::PresentInfoKHR::builder() let present_info = vk::PresentInfoKHR::builder()
.wait_semaphores( &[base.rendering_complete_semaphore]) .wait_semaphores(&[base.rendering_complete_semaphore])
.swapchains( &[base.swapchain]) .swapchains(&[base.swapchain])
.image_indices( &[present_index]) .image_indices(&[present_index])
.build(); .build();
base.swapchain_loader base.swapchain_loader
.queue_present_khr(base.present_queue, &present_info) .queue_present_khr(base.present_queue, &present_info)

View file

@ -54,33 +54,31 @@ macro_rules! offset_of {
} }
fn u32_from_bytes(bytes: &[u8; 4]) -> u32 { fn u32_from_bytes(bytes: &[u8; 4]) -> u32 {
unsafe { unsafe { std::mem::transmute(*bytes) }
std::mem::transmute(*bytes)
}
} }
pub fn bytes_to_u32_vec<B>(bytes:B) -> Vec<u32> pub fn bytes_to_u32_vec<B>(bytes: B) -> Vec<u32>
where B: Iterator<Item=u8> where
B: Iterator<Item = u8>,
{ {
let mut output = vec![]; let mut output = vec![];
let mut buffer: [u8;4] = [0,0,0,0]; let mut buffer: [u8; 4] = [0, 0, 0, 0];
for (i,b) in bytes.enumerate() { for (i, b) in bytes.enumerate() {
match i % 4 { match i % 4 {
3 => { 3 => {
buffer[3] = b; buffer[3] = b;
output.push(u32_from_bytes(&buffer)); output.push(u32_from_bytes(&buffer));
buffer = [0,0,0,0]; buffer = [0, 0, 0, 0];
}, }
idx => buffer[idx] = b idx => buffer[idx] = b,
} }
} }
if buffer != [0,0,0,0] { if buffer != [0, 0, 0, 0] {
output.push(u32_from_bytes(&buffer)); output.push(u32_from_bytes(&buffer));
} }
output output
} }
pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffer)>( pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffer)>(
device: &D, device: &D,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
@ -361,17 +359,17 @@ impl ExampleBase {
let extension_names_raw = extension_names(); let extension_names_raw = extension_names();
let appinfo = vk::ApplicationInfo::builder() let appinfo = vk::ApplicationInfo::builder()
.application_name(&app_name ) .application_name(&app_name)
.application_version(0) .application_version(0)
.engine_name(&app_name) .engine_name(&app_name)
.engine_version(0) .engine_version(0)
.api_version(vk_make_version!(1,0,36)) .api_version(vk_make_version!(1, 0, 36))
.build(); .build();
let create_info = vk::InstanceCreateInfo::builder() let create_info = vk::InstanceCreateInfo::builder()
.application_info(&appinfo) .application_info(&appinfo)
.enabled_layer_names(&layers_names_raw) .enabled_layer_names(&layers_names_raw)
.enabled_extension_names(&extension_names_raw ) .enabled_extension_names(&extension_names_raw)
.build(); .build();
let instance: Instance = entry let instance: Instance = entry
@ -383,9 +381,8 @@ impl ExampleBase {
.flags( .flags(
vk::DebugReportFlagsEXT::ERROR vk::DebugReportFlagsEXT::ERROR
| vk::DebugReportFlagsEXT::WARNING | vk::DebugReportFlagsEXT::WARNING
| vk::DebugReportFlagsEXT::PERFORMANCE_WARNING | vk::DebugReportFlagsEXT::PERFORMANCE_WARNING,
) ).build();
.build();
let debug_report_loader = DebugReport::new(&entry, &instance); let debug_report_loader = DebugReport::new(&entry, &instance);
let debug_call_back = debug_report_loader let debug_call_back = debug_report_loader
@ -428,7 +425,7 @@ impl ExampleBase {
let priorities = [1.0]; let priorities = [1.0];
let queue_info = vk::DeviceQueueCreateInfo::builder() let queue_info = vk::DeviceQueueCreateInfo::builder()
.queue_family_index(queue_family_index as u32 ) .queue_family_index(queue_family_index as u32)
.queue_priorities(&priorities) .queue_priorities(&priorities)
.build(); .build();
@ -500,7 +497,7 @@ impl ExampleBase {
.pre_transform(pre_transform) .pre_transform(pre_transform)
.composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE) .composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE)
.present_mode(present_mode) .present_mode(present_mode)
// .clipped(true) // .clipped(true)
.image_array_layers(1) .image_array_layers(1)
.build(); .build();
let swapchain = swapchain_loader let swapchain = swapchain_loader
@ -512,7 +509,6 @@ impl ExampleBase {
.flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER)
.build(); .build();
let pool = device.create_command_pool(&pool_create_info, None).unwrap(); let pool = device.create_command_pool(&pool_create_info, None).unwrap();
let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder() let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder()
@ -539,9 +535,8 @@ impl ExampleBase {
.aspect_mask(vk::ImageAspectFlags::COLOR) .aspect_mask(vk::ImageAspectFlags::COLOR)
.level_count(1) .level_count(1)
.layer_count(1) .layer_count(1)
.build() .build(),
) ).image(image)
.image(image)
.format(surface_format.format) .format(surface_format.format)
.view_type(vk::ImageViewType::TYPE_2D) .view_type(vk::ImageViewType::TYPE_2D)
.build(); .build();
@ -556,9 +551,8 @@ impl ExampleBase {
.extent(vk::Extent3D { .extent(vk::Extent3D {
width: surface_resolution.width, width: surface_resolution.width,
height: surface_resolution.height, height: surface_resolution.height,
depth: 1 depth: 1,
}) }).mip_levels(1)
.mip_levels(1)
.array_layers(1) .array_layers(1)
.samples(vk::SampleCountFlags::TYPE_1) .samples(vk::SampleCountFlags::TYPE_1)
.usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT) .usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT)
@ -572,7 +566,6 @@ impl ExampleBase {
vk::MemoryPropertyFlags::DEVICE_LOCAL, 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() let depth_image_allocate_info = vk::MemoryAllocateInfo::builder()
.allocation_size(depth_image_memory_req.size) .allocation_size(depth_image_memory_req.size)
.memory_type_index(depth_image_memory_index) .memory_type_index(depth_image_memory_index)
@ -598,18 +591,16 @@ impl ExampleBase {
.image(depth_image) .image(depth_image)
.dst_access_mask( .dst_access_mask(
vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ
| vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE,
) ).new_layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
.new_layout(vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL)
.old_layout(vk::ImageLayout::UNDEFINED) .old_layout(vk::ImageLayout::UNDEFINED)
.subresource_range( .subresource_range(
vk::ImageSubresourceRange::builder() vk::ImageSubresourceRange::builder()
.aspect_mask(vk::ImageAspectFlags::DEPTH) .aspect_mask(vk::ImageAspectFlags::DEPTH)
.layer_count(1) .layer_count(1)
.level_count(1) .level_count(1)
.build() .build(),
) ).build();
.build();
device.cmd_pipeline_barrier( device.cmd_pipeline_barrier(
setup_command_buffer, setup_command_buffer,
@ -629,9 +620,8 @@ impl ExampleBase {
.aspect_mask(vk::ImageAspectFlags::DEPTH) .aspect_mask(vk::ImageAspectFlags::DEPTH)
.level_count(1) .level_count(1)
.layer_count(1) .layer_count(1)
.build() .build(),
) ).image(depth_image)
.image(depth_image)
.format(depth_image_create_info.format) .format(depth_image_create_info.format)
.view_type(vk::ImageViewType::TYPE_2D) .view_type(vk::ImageViewType::TYPE_2D)
.build(); .build();
@ -640,7 +630,6 @@ impl ExampleBase {
.create_image_view(&depth_image_view_info, None) .create_image_view(&depth_image_view_info, None)
.unwrap(); .unwrap();
let semaphore_create_info = vk::SemaphoreCreateInfo::default(); let semaphore_create_info = vk::SemaphoreCreateInfo::default();
let present_complete_semaphore = device let present_complete_semaphore = device