reformatting via rust fmt
This commit is contained in:
parent
5dfd07098c
commit
962f1ba830
|
@ -49,7 +49,7 @@ 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_refs = [vk::AttachmentReference {
|
let color_attachment_refs = [vk::AttachmentReference {
|
||||||
|
@ -66,19 +66,19 @@ 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 subpasses = [vk::SubpassDescription::builder()
|
let subpasses = [vk::SubpassDescription::builder()
|
||||||
.color_attachments( &color_attachment_refs)
|
.color_attachments(&color_attachment_refs)
|
||||||
.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( &subpasses)
|
.subpasses(&subpasses)
|
||||||
.dependencies( &dependencies);
|
.dependencies(&dependencies);
|
||||||
|
|
||||||
let renderpass = base
|
let renderpass = base
|
||||||
.device
|
.device
|
||||||
|
@ -91,22 +91,23 @@ fn main() {
|
||||||
.map(|&present_image_view| {
|
.map(|&present_image_view| {
|
||||||
let framebuffer_attachments = [present_image_view, base.depth_image_view];
|
let framebuffer_attachments = [present_image_view, base.depth_image_view];
|
||||||
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);
|
||||||
|
|
||||||
base.device
|
base.device
|
||||||
.create_framebuffer(&frame_buffer_create_info, None)
|
.create_framebuffer(&frame_buffer_create_info, None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
let index_buffer_data = [0u32, 1, 2, 2, 3, 0];
|
let index_buffer_data = [0u32, 1, 2, 2, 3, 0];
|
||||||
let index_buffer_info = vk::BufferCreateInfo {
|
let index_buffer_info = vk::BufferCreateInfo {
|
||||||
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);
|
||||||
|
@ -114,7 +115,8 @@ fn main() {
|
||||||
&index_buffer_memory_req,
|
&index_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
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,
|
||||||
|
@ -131,7 +133,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
index_buffer_memory_req.size,
|
index_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut index_slice = Align::new(
|
let mut index_slice = Align::new(
|
||||||
index_ptr,
|
index_ptr,
|
||||||
align_of::<u32>() as u64,
|
align_of::<u32>() as u64,
|
||||||
|
@ -178,7 +181,8 @@ fn main() {
|
||||||
&vertex_input_buffer_memory_req,
|
&vertex_input_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
let vertex_buffer_allocate_info = vk::MemoryAllocateInfo {
|
||||||
allocation_size: vertex_input_buffer_memory_req.size,
|
allocation_size: vertex_input_buffer_memory_req.size,
|
||||||
|
@ -197,7 +201,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
vertex_input_buffer_memory_req.size,
|
vertex_input_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut slice = Align::new(
|
let mut slice = Align::new(
|
||||||
vert_ptr,
|
vert_ptr,
|
||||||
align_of::<Vertex>() as u64,
|
align_of::<Vertex>() as u64,
|
||||||
|
@ -219,7 +224,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
|
||||||
|
@ -232,7 +237,8 @@ fn main() {
|
||||||
&uniform_color_buffer_memory_req,
|
&uniform_color_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
let uniform_color_buffer_allocate_info = vk::MemoryAllocateInfo {
|
||||||
allocation_size: uniform_color_buffer_memory_req.size,
|
allocation_size: uniform_color_buffer_memory_req.size,
|
||||||
|
@ -250,7 +256,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
uniform_color_buffer_memory_req.size,
|
uniform_color_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut uniform_aligned_slice = Align::new(
|
let mut uniform_aligned_slice = Align::new(
|
||||||
uniform_ptr,
|
uniform_ptr,
|
||||||
align_of::<Vector3>() as u64,
|
align_of::<Vector3>() as u64,
|
||||||
|
@ -277,7 +284,8 @@ fn main() {
|
||||||
&image_buffer_memory_req,
|
&image_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
let image_buffer_allocate_info = vk::MemoryAllocateInfo {
|
||||||
allocation_size: image_buffer_memory_req.size,
|
allocation_size: image_buffer_memory_req.size,
|
||||||
|
@ -295,7 +303,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
image_buffer_memory_req.size,
|
image_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut image_slice = Align::new(
|
let mut image_slice = Align::new(
|
||||||
image_ptr,
|
image_ptr,
|
||||||
std::mem::align_of::<u8>() as u64,
|
std::mem::align_of::<u8>() as u64,
|
||||||
|
@ -332,7 +341,8 @@ fn main() {
|
||||||
&texture_memory_req,
|
&texture_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
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 texture_allocate_info = vk::MemoryAllocateInfo {
|
let texture_allocate_info = vk::MemoryAllocateInfo {
|
||||||
allocation_size: texture_memory_req.size,
|
allocation_size: texture_memory_req.size,
|
||||||
|
@ -387,7 +397,7 @@ fn main() {
|
||||||
height: image_dimensions.1,
|
height: image_dimensions.1,
|
||||||
depth: 1,
|
depth: 1,
|
||||||
},
|
},
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
}];
|
}];
|
||||||
device.cmd_copy_buffer_to_image(
|
device.cmd_copy_buffer_to_image(
|
||||||
texture_command_buffer,
|
texture_command_buffer,
|
||||||
|
@ -432,7 +442,7 @@ fn main() {
|
||||||
max_anisotropy: 1.0,
|
max_anisotropy: 1.0,
|
||||||
border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE,
|
border_color: vk::BorderColor::FLOAT_OPAQUE_WHITE,
|
||||||
compare_op: vk::CompareOp::NEVER,
|
compare_op: vk::CompareOp::NEVER,
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let sampler = base.device.create_sampler(&sampler_info, None).unwrap();
|
let sampler = base.device.create_sampler(&sampler_info, None).unwrap();
|
||||||
|
@ -453,7 +463,7 @@ fn main() {
|
||||||
..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
|
||||||
|
@ -471,7 +481,7 @@ fn main() {
|
||||||
];
|
];
|
||||||
let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder()
|
let descriptor_pool_info = vk::DescriptorPoolCreateInfo::builder()
|
||||||
.pool_sizes(&descriptor_sizes)
|
.pool_sizes(&descriptor_sizes)
|
||||||
.max_sets( 1);
|
.max_sets(1);
|
||||||
|
|
||||||
let descriptor_pool = base
|
let descriptor_pool = base
|
||||||
.device
|
.device
|
||||||
|
@ -492,8 +502,8 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
let descriptor_info = vk::DescriptorSetLayoutCreateInfo::builder()
|
let descriptor_info =
|
||||||
.bindings(&desc_layout_bindings);
|
vk::DescriptorSetLayoutCreateInfo::builder().bindings(&desc_layout_bindings);
|
||||||
|
|
||||||
let desc_set_layouts = [base
|
let desc_set_layouts = [base
|
||||||
.device
|
.device
|
||||||
|
@ -501,7 +511,7 @@ fn main() {
|
||||||
.unwrap()];
|
.unwrap()];
|
||||||
|
|
||||||
let desc_alloc_info = vk::DescriptorSetAllocateInfo::builder()
|
let desc_alloc_info = vk::DescriptorSetAllocateInfo::builder()
|
||||||
.descriptor_pool( descriptor_pool)
|
.descriptor_pool(descriptor_pool)
|
||||||
.set_layouts(&desc_set_layouts);
|
.set_layouts(&desc_set_layouts);
|
||||||
let descriptor_sets = base
|
let descriptor_sets = base
|
||||||
.device
|
.device
|
||||||
|
@ -526,7 +536,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],
|
||||||
|
@ -534,7 +544,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, &[]);
|
||||||
|
@ -565,8 +575,8 @@ fn main() {
|
||||||
.create_shader_module(&frag_shader_info, None)
|
.create_shader_module(&frag_shader_info, None)
|
||||||
.expect("Fragment shader module error");
|
.expect("Fragment shader module error");
|
||||||
|
|
||||||
let layout_create_info = vk::PipelineLayoutCreateInfo::builder()
|
let layout_create_info =
|
||||||
.set_layouts(&desc_set_layouts);
|
vk::PipelineLayoutCreateInfo::builder().set_layouts(&desc_set_layouts);
|
||||||
|
|
||||||
let pipeline_layout = base
|
let pipeline_layout = base
|
||||||
.device
|
.device
|
||||||
|
@ -579,13 +589,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 {
|
||||||
|
@ -613,7 +623,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,
|
||||||
|
@ -625,7 +635,7 @@ fn main() {
|
||||||
}];
|
}];
|
||||||
let scissors = [vk::Rect2D {
|
let scissors = [vk::Rect2D {
|
||||||
extent: base.surface_resolution.clone(),
|
extent: base.surface_resolution.clone(),
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
}];
|
}];
|
||||||
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder()
|
||||||
.scissors(&scissors)
|
.scissors(&scissors)
|
||||||
|
@ -635,11 +645,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 {
|
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo {
|
||||||
rasterization_samples: vk::SampleCountFlags::TYPE_1,
|
rasterization_samples: vk::SampleCountFlags::TYPE_1,
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder()
|
let multisample_state_info = vk::PipelineMultisampleStateCreateInfo::builder()
|
||||||
|
@ -651,7 +661,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,
|
||||||
|
@ -660,7 +670,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 {
|
||||||
|
@ -674,25 +684,25 @@ 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);
|
||||||
|
|
||||||
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
|
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
|
||||||
let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder()
|
let dynamic_state_info =
|
||||||
.dynamic_states(&dynamic_state);
|
vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state);
|
||||||
|
|
||||||
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
|
||||||
|
@ -710,7 +720,8 @@ fn main() {
|
||||||
std::u64::MAX,
|
std::u64::MAX,
|
||||||
base.present_complete_semaphore,
|
base.present_complete_semaphore,
|
||||||
vk::Fence::null(),
|
vk::Fence::null(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let clear_values = [
|
let clear_values = [
|
||||||
vk::ClearValue {
|
vk::ClearValue {
|
||||||
color: vk::ClearColorValue {
|
color: vk::ClearColorValue {
|
||||||
|
@ -728,7 +739,7 @@ fn main() {
|
||||||
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
||||||
.render_pass(renderpass)
|
.render_pass(renderpass)
|
||||||
.framebuffer(framebuffers[present_index as usize])
|
.framebuffer(framebuffers[present_index as usize])
|
||||||
.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(),
|
||||||
})
|
})
|
||||||
|
@ -794,7 +805,7 @@ fn main() {
|
||||||
swapchain_count: 1,
|
swapchain_count: 1,
|
||||||
p_swapchains: &base.swapchain,
|
p_swapchains: &base.swapchain,
|
||||||
p_image_indices: &present_index,
|
p_image_indices: &present_index,
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
base.swapchain_loader
|
base.swapchain_loader
|
||||||
.queue_present(base.present_queue, &present_info)
|
.queue_present(base.present_queue, &present_info)
|
||||||
|
|
|
@ -37,7 +37,7 @@ 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_refs = [vk::AttachmentReference {
|
let color_attachment_refs = [vk::AttachmentReference {
|
||||||
|
@ -54,19 +54,19 @@ 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 subpasses = [vk::SubpassDescription::builder()
|
let subpasses = [vk::SubpassDescription::builder()
|
||||||
.color_attachments(&color_attachment_refs)
|
.color_attachments(&color_attachment_refs)
|
||||||
.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( &subpasses)
|
.subpasses(&subpasses)
|
||||||
.dependencies( &dependencies);
|
.dependencies(&dependencies);
|
||||||
|
|
||||||
let renderpass = base
|
let renderpass = base
|
||||||
.device
|
.device
|
||||||
|
@ -79,21 +79,22 @@ fn main() {
|
||||||
.map(|&present_image_view| {
|
.map(|&present_image_view| {
|
||||||
let framebuffer_attachments = [present_image_view, base.depth_image_view];
|
let framebuffer_attachments = [present_image_view, base.depth_image_view];
|
||||||
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);
|
||||||
|
|
||||||
base.device
|
base.device
|
||||||
.create_framebuffer(&frame_buffer_create_info, None)
|
.create_framebuffer(&frame_buffer_create_info, None)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
let index_buffer_data = [0u32, 1, 2];
|
let index_buffer_data = [0u32, 1, 2];
|
||||||
let index_buffer_info = vk::BufferCreateInfo::builder()
|
let index_buffer_info = vk::BufferCreateInfo::builder()
|
||||||
.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);
|
||||||
|
|
||||||
let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap();
|
let index_buffer = base.device.create_buffer(&index_buffer_info, None).unwrap();
|
||||||
|
@ -102,12 +103,13 @@ fn main() {
|
||||||
&index_buffer_memory_req,
|
&index_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
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
|
||||||
|
@ -120,7 +122,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
index_buffer_memory_req.size,
|
index_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let mut index_slice = Align::new(
|
let mut index_slice = Align::new(
|
||||||
index_ptr,
|
index_ptr,
|
||||||
align_of::<u32>() as u64,
|
align_of::<u32>() as u64,
|
||||||
|
@ -136,7 +139,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
|
||||||
|
@ -152,12 +155,13 @@ fn main() {
|
||||||
&vertex_input_buffer_memory_req,
|
&vertex_input_buffer_memory_req,
|
||||||
&base.device_memory_properties,
|
&base.device_memory_properties,
|
||||||
vk::MemoryPropertyFlags::HOST_VISIBLE,
|
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 {
|
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
|
||||||
|
@ -187,7 +191,8 @@ fn main() {
|
||||||
0,
|
0,
|
||||||
vertex_input_buffer_memory_req.size,
|
vertex_input_buffer_memory_req.size,
|
||||||
vk::MemoryMapFlags::empty(),
|
vk::MemoryMapFlags::empty(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut vert_align = Align::new(
|
let mut vert_align = Align::new(
|
||||||
vert_ptr,
|
vert_ptr,
|
||||||
|
@ -239,14 +244,14 @@ 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 {
|
||||||
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
|
s_type: vk::StructureType::PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
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 {
|
||||||
|
@ -274,12 +279,11 @@ fn main() {
|
||||||
p_vertex_attribute_descriptions: vertex_input_attribute_descriptions.as_ptr(),
|
p_vertex_attribute_descriptions: vertex_input_attribute_descriptions.as_ptr(),
|
||||||
vertex_binding_description_count: vertex_input_binding_descriptions.len() as u32,
|
vertex_binding_description_count: vertex_input_binding_descriptions.len() as u32,
|
||||||
p_vertex_binding_descriptions: vertex_input_binding_descriptions.as_ptr(),
|
p_vertex_binding_descriptions: vertex_input_binding_descriptions.as_ptr(),
|
||||||
.. Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
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,
|
||||||
|
@ -301,18 +305,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,
|
||||||
|
@ -321,7 +325,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,
|
||||||
|
@ -334,29 +338,27 @@ 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);
|
||||||
|
|
||||||
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
|
let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR];
|
||||||
let dynamic_state_info = vk::PipelineDynamicStateCreateInfo::builder()
|
let dynamic_state_info =
|
||||||
.dynamic_states(&dynamic_state);
|
vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state);
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None)
|
.create_graphics_pipelines(vk::PipelineCache::null(), &[graphic_pipeline_info], None)
|
||||||
|
@ -372,7 +374,8 @@ fn main() {
|
||||||
std::u64::MAX,
|
std::u64::MAX,
|
||||||
base.present_complete_semaphore,
|
base.present_complete_semaphore,
|
||||||
vk::Fence::null(),
|
vk::Fence::null(),
|
||||||
).unwrap();
|
)
|
||||||
|
.unwrap();
|
||||||
let clear_values = [
|
let clear_values = [
|
||||||
vk::ClearValue {
|
vk::ClearValue {
|
||||||
color: vk::ClearColorValue {
|
color: vk::ClearColorValue {
|
||||||
|
@ -389,12 +392,12 @@ fn main() {
|
||||||
|
|
||||||
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
let render_pass_begin_info = vk::RenderPassBeginInfo::builder()
|
||||||
.render_pass(renderpass)
|
.render_pass(renderpass)
|
||||||
.framebuffer( framebuffers[present_index as usize])
|
.framebuffer(framebuffers[present_index as usize])
|
||||||
.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);
|
||||||
|
|
||||||
record_submit_commandbuffer(
|
record_submit_commandbuffer(
|
||||||
&base.device,
|
&base.device,
|
||||||
|
@ -446,9 +449,9 @@ fn main() {
|
||||||
let swapchains = [base.swapchain];
|
let swapchains = [base.swapchain];
|
||||||
let image_indices = [present_index];
|
let image_indices = [present_index];
|
||||||
let present_info = vk::PresentInfoKHR::builder()
|
let present_info = vk::PresentInfoKHR::builder()
|
||||||
.wait_semaphores( &wait_semaphors) // &base.rendering_complete_semaphore)
|
.wait_semaphores(&wait_semaphors) // &base.rendering_complete_semaphore)
|
||||||
.swapchains( &swapchains)
|
.swapchains(&swapchains)
|
||||||
.image_indices( &image_indices);
|
.image_indices(&image_indices);
|
||||||
|
|
||||||
base.swapchain_loader
|
base.swapchain_loader
|
||||||
.queue_present(base.present_queue, &present_info)
|
.queue_present(base.present_queue, &present_info)
|
||||||
|
|
|
@ -36,7 +36,7 @@ use ash::extensions::khr::Win32Surface;
|
||||||
use ash::extensions::mvk::MacOSSurface;
|
use ash::extensions::mvk::MacOSSurface;
|
||||||
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
|
pub use ash::version::{DeviceV1_0, EntryV1_0, InstanceV1_0};
|
||||||
use ash::{vk, Device, Entry, Instance};
|
use ash::{vk, Device, Entry, Instance};
|
||||||
use byteorder::{LittleEndian, BigEndian, ReadBytesExt};
|
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
@ -45,12 +45,11 @@ use std::ops::Drop;
|
||||||
use std::os::raw::{c_char, c_void};
|
use std::os::raw::{c_char, c_void};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
|
||||||
const MAGIC_NUMBER: u32 = 0x07230203;
|
const MAGIC_NUMBER: u32 = 0x07230203;
|
||||||
|
|
||||||
fn spirv_is_little_endian(bytes: &[u8] ) -> bool {
|
fn spirv_is_little_endian(bytes: &[u8]) -> bool {
|
||||||
let buffer: [u8;4] = [bytes[0], bytes[1],bytes[2],bytes[3]];
|
let buffer: [u8; 4] = [bytes[0], bytes[1], bytes[2], bytes[3]];
|
||||||
let number : u32 = Cursor::new(buffer).read_u32::<LittleEndian>().unwrap();
|
let number: u32 = Cursor::new(buffer).read_u32::<LittleEndian>().unwrap();
|
||||||
number == MAGIC_NUMBER
|
number == MAGIC_NUMBER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ pub fn bytes_to_u32_vec(bytes: &[u8]) -> Vec<u32> {
|
||||||
let idx = i % 4;
|
let idx = i % 4;
|
||||||
buffer[idx] = *b;
|
buffer[idx] = *b;
|
||||||
if idx == 3 {
|
if idx == 3 {
|
||||||
let new_word = if is_little_endian {
|
let new_word = if is_little_endian {
|
||||||
Cursor::new(buffer).read_u32::<LittleEndian>().unwrap()
|
Cursor::new(buffer).read_u32::<LittleEndian>().unwrap()
|
||||||
} else {
|
} else {
|
||||||
Cursor::new(buffer).read_u32::<BigEndian>().unwrap()
|
Cursor::new(buffer).read_u32::<BigEndian>().unwrap()
|
||||||
|
@ -131,7 +130,8 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
|
||||||
.reset_command_buffer(
|
.reset_command_buffer(
|
||||||
command_buffer,
|
command_buffer,
|
||||||
vk::CommandBufferResetFlags::RELEASE_RESOURCES,
|
vk::CommandBufferResetFlags::RELEASE_RESOURCES,
|
||||||
).expect("Reset command buffer failed.");
|
)
|
||||||
|
.expect("Reset command buffer failed.");
|
||||||
let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder()
|
let command_buffer_begin_info = vk::CommandBufferBeginInfo::builder()
|
||||||
.flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT);
|
.flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT);
|
||||||
|
|
||||||
|
@ -384,7 +384,8 @@ impl ExampleBase {
|
||||||
.with_dimensions(winit::dpi::LogicalSize::new(
|
.with_dimensions(winit::dpi::LogicalSize::new(
|
||||||
window_width as f64,
|
window_width as f64,
|
||||||
window_height as f64,
|
window_height as f64,
|
||||||
)).build(&events_loop)
|
))
|
||||||
|
.build(&events_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let entry = Entry::new().unwrap();
|
let entry = Entry::new().unwrap();
|
||||||
let app_name = CString::new("VulkanTriangle").unwrap();
|
let app_name = CString::new("VulkanTriangle").unwrap();
|
||||||
|
@ -419,7 +420,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,
|
||||||
|
)
|
||||||
.pfn_callback(Some(vulkan_debug_callback));
|
.pfn_callback(Some(vulkan_debug_callback));
|
||||||
|
|
||||||
let debug_report_loader = DebugReport::new(&entry, &instance);
|
let debug_report_loader = DebugReport::new(&entry, &instance);
|
||||||
|
@ -450,8 +452,10 @@ impl ExampleBase {
|
||||||
true => Some((*pdevice, index)),
|
true => Some((*pdevice, index)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}).nth(0)
|
})
|
||||||
}).filter_map(|v| v)
|
.nth(0)
|
||||||
|
})
|
||||||
|
.filter_map(|v| v)
|
||||||
.nth(0)
|
.nth(0)
|
||||||
.expect("Couldn't find suitable device.");
|
.expect("Couldn't find suitable device.");
|
||||||
let queue_family_index = queue_family_index as u32;
|
let queue_family_index = queue_family_index as u32;
|
||||||
|
@ -463,9 +467,9 @@ 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)
|
.queue_family_index(queue_family_index)
|
||||||
.queue_priorities(&priorities)
|
.queue_priorities(&priorities)
|
||||||
.build()];
|
.build()];
|
||||||
|
|
||||||
let device_create_info = vk::DeviceCreateInfo::builder()
|
let device_create_info = vk::DeviceCreateInfo::builder()
|
||||||
.queue_create_infos(&queue_info)
|
.queue_create_infos(&queue_info)
|
||||||
|
@ -488,7 +492,8 @@ impl ExampleBase {
|
||||||
color_space: sfmt.color_space,
|
color_space: sfmt.color_space,
|
||||||
},
|
},
|
||||||
_ => sfmt.clone(),
|
_ => sfmt.clone(),
|
||||||
}).nth(0)
|
})
|
||||||
|
.nth(0)
|
||||||
.expect("Unable to find suitable surface format.");
|
.expect("Unable to find suitable surface format.");
|
||||||
let surface_capabilities = surface_loader
|
let surface_capabilities = surface_loader
|
||||||
.get_physical_device_surface_capabilities(pdevice, surface)
|
.get_physical_device_surface_capabilities(pdevice, surface)
|
||||||
|
@ -526,17 +531,17 @@ impl ExampleBase {
|
||||||
|
|
||||||
let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder()
|
let swapchain_create_info = vk::SwapchainCreateInfoKHR::builder()
|
||||||
.surface(surface)
|
.surface(surface)
|
||||||
.min_image_count( desired_image_count)
|
.min_image_count(desired_image_count)
|
||||||
.image_color_space( surface_format.color_space)
|
.image_color_space(surface_format.color_space)
|
||||||
.image_format( surface_format.format)
|
.image_format(surface_format.format)
|
||||||
.image_extent( surface_resolution.clone())
|
.image_extent(surface_resolution.clone())
|
||||||
.image_usage( vk::ImageUsageFlags::COLOR_ATTACHMENT)
|
.image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT)
|
||||||
.image_sharing_mode(vk::SharingMode::EXCLUSIVE)
|
.image_sharing_mode(vk::SharingMode::EXCLUSIVE)
|
||||||
.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);
|
||||||
|
|
||||||
let swapchain = swapchain_loader
|
let swapchain = swapchain_loader
|
||||||
.create_swapchain(&swapchain_create_info, None)
|
.create_swapchain(&swapchain_create_info, None)
|
||||||
|
@ -564,39 +569,40 @@ impl ExampleBase {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&image| {
|
.map(|&image| {
|
||||||
let create_view_info = vk::ImageViewCreateInfo::builder()
|
let create_view_info = vk::ImageViewCreateInfo::builder()
|
||||||
.view_type( vk::ImageViewType::TYPE_2D)
|
.view_type(vk::ImageViewType::TYPE_2D)
|
||||||
.format(surface_format.format)
|
.format(surface_format.format)
|
||||||
.components( vk::ComponentMapping {
|
.components(vk::ComponentMapping {
|
||||||
r: vk::ComponentSwizzle::R,
|
r: vk::ComponentSwizzle::R,
|
||||||
g: vk::ComponentSwizzle::G,
|
g: vk::ComponentSwizzle::G,
|
||||||
b: vk::ComponentSwizzle::B,
|
b: vk::ComponentSwizzle::B,
|
||||||
a: vk::ComponentSwizzle::A,
|
a: vk::ComponentSwizzle::A,
|
||||||
})
|
})
|
||||||
.subresource_range( vk::ImageSubresourceRange {
|
.subresource_range(vk::ImageSubresourceRange {
|
||||||
aspect_mask: vk::ImageAspectFlags::COLOR,
|
aspect_mask: vk::ImageAspectFlags::COLOR,
|
||||||
base_mip_level: 0,
|
base_mip_level: 0,
|
||||||
level_count: 1,
|
level_count: 1,
|
||||||
base_array_layer: 0,
|
base_array_layer: 0,
|
||||||
layer_count: 1,
|
layer_count: 1,
|
||||||
})
|
})
|
||||||
.image( image);
|
.image(image);
|
||||||
device.create_image_view(&create_view_info, None).unwrap()
|
device.create_image_view(&create_view_info, None).unwrap()
|
||||||
}).collect();
|
})
|
||||||
|
.collect();
|
||||||
let device_memory_properties = instance.get_physical_device_memory_properties(pdevice);
|
let device_memory_properties = instance.get_physical_device_memory_properties(pdevice);
|
||||||
let depth_image_create_info = vk::ImageCreateInfo::builder()
|
let depth_image_create_info = vk::ImageCreateInfo::builder()
|
||||||
.image_type( vk::ImageType::TYPE_2D)
|
.image_type(vk::ImageType::TYPE_2D)
|
||||||
.format( vk::Format::D16_UNORM)
|
.format(vk::Format::D16_UNORM)
|
||||||
.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)
|
||||||
.tiling( vk::ImageTiling::OPTIMAL)
|
.tiling(vk::ImageTiling::OPTIMAL)
|
||||||
.usage(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT)
|
.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 = 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_req = device.get_image_memory_requirements(depth_image);
|
||||||
|
@ -604,7 +610,8 @@ impl ExampleBase {
|
||||||
&depth_image_memory_req,
|
&depth_image_memory_req,
|
||||||
&device_memory_properties,
|
&device_memory_properties,
|
||||||
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)
|
||||||
|
@ -624,6 +631,7 @@ impl ExampleBase {
|
||||||
setup_command_buffer,
|
setup_command_buffer,
|
||||||
present_queue,
|
present_queue,
|
||||||
&[],
|
&[],
|
||||||
|
// &[vk::PipelineStageFlags::BOTTOM_OF_PIPE],
|
||||||
&[],
|
&[],
|
||||||
&[],
|
&[],
|
||||||
|device, setup_command_buffer| {
|
|device, setup_command_buffer| {
|
||||||
|
|
Loading…
Reference in a new issue