Adjust lib.rs for examples

This commit is contained in:
Tim 2018-07-31 12:45:29 +02:00
parent f04df1e1df
commit 7c8ab2a876

View file

@ -43,14 +43,14 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
device device
.reset_command_buffer( .reset_command_buffer(
command_buffer, command_buffer,
vk::COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT, vk::CommandBufferResetFlags::RELEASE_RESOURCES,
) )
.expect("Reset command buffer failed."); .expect("Reset command buffer failed.");
let command_buffer_begin_info = vk::CommandBufferBeginInfo { let command_buffer_begin_info = vk::CommandBufferBeginInfo {
s_type: vk::StructureType::CommandBufferBeginInfo, s_type: vk::StructureType::COMMAND_BUFFER_BEGIN_INFO,
p_next: ptr::null(), p_next: ptr::null(),
p_inheritance_info: ptr::null(), p_inheritance_info: ptr::null(),
flags: vk::COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, flags: vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT,
}; };
device device
.begin_command_buffer(command_buffer, &command_buffer_begin_info) .begin_command_buffer(command_buffer, &command_buffer_begin_info)
@ -60,7 +60,7 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
.end_command_buffer(command_buffer) .end_command_buffer(command_buffer)
.expect("End commandbuffer"); .expect("End commandbuffer");
let fence_create_info = vk::FenceCreateInfo { let fence_create_info = vk::FenceCreateInfo {
s_type: vk::StructureType::FenceCreateInfo, s_type: vk::StructureType::FENCE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: vk::FenceCreateFlags::empty(), flags: vk::FenceCreateFlags::empty(),
}; };
@ -68,7 +68,7 @@ pub fn record_submit_commandbuffer<D: DeviceV1_0, F: FnOnce(&D, vk::CommandBuffe
.create_fence(&fence_create_info, None) .create_fence(&fence_create_info, None)
.expect("Create fence failed."); .expect("Create fence failed.");
let submit_info = vk::SubmitInfo { let submit_info = vk::SubmitInfo {
s_type: vk::StructureType::SubmitInfo, s_type: vk::StructureType::SUBMIT_INFO,
p_next: ptr::null(), p_next: ptr::null(),
wait_semaphore_count: wait_semaphores.len() as u32, wait_semaphore_count: wait_semaphores.len() as u32,
p_wait_semaphores: wait_semaphores.as_ptr(), p_wait_semaphores: wait_semaphores.as_ptr(),
@ -98,7 +98,7 @@ unsafe fn create_surface<E: EntryV1_0, I: InstanceV1_0>(
let x11_display = window.get_xlib_display().unwrap(); let x11_display = window.get_xlib_display().unwrap();
let x11_window = window.get_xlib_window().unwrap(); let x11_window = window.get_xlib_window().unwrap();
let x11_create_info = vk::XlibSurfaceCreateInfoKHR { let x11_create_info = vk::XlibSurfaceCreateInfoKHR {
s_type: vk::StructureType::XlibSurfaceCreateInfoKhr, s_type: vk::StructureType::XLIB_SURFACE_CREATE_INFO_KHR,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
window: x11_window as vk::Window, window: x11_window as vk::Window,
@ -280,7 +280,7 @@ impl ExampleBase {
let extension_names_raw = extension_names(); let extension_names_raw = extension_names();
let appinfo = vk::ApplicationInfo { let appinfo = vk::ApplicationInfo {
p_application_name: raw_name, p_application_name: raw_name,
s_type: vk::StructureType::ApplicationInfo, s_type: vk::StructureType::APPLICATION_INFO,
p_next: ptr::null(), p_next: ptr::null(),
application_version: 0, application_version: 0,
p_engine_name: raw_name, p_engine_name: raw_name,
@ -288,7 +288,7 @@ impl ExampleBase {
api_version: vk_make_version!(1, 0, 36), api_version: vk_make_version!(1, 0, 36),
}; };
let create_info = vk::InstanceCreateInfo { let create_info = vk::InstanceCreateInfo {
s_type: vk::StructureType::InstanceCreateInfo, s_type: vk::StructureType::INSTANCE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
p_application_info: &appinfo, p_application_info: &appinfo,
@ -301,10 +301,10 @@ impl ExampleBase {
.create_instance(&create_info, None) .create_instance(&create_info, None)
.expect("Instance creation error"); .expect("Instance creation error");
let debug_info = vk::DebugReportCallbackCreateInfoEXT { let debug_info = vk::DebugReportCallbackCreateInfoEXT {
s_type: vk::StructureType::DebugReportCallbackCreateInfoExt, s_type: vk::StructureType::DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
p_next: ptr::null(), p_next: ptr::null(),
flags: vk::DEBUG_REPORT_ERROR_BIT_EXT | vk::DEBUG_REPORT_WARNING_BIT_EXT flags: vk::DebugReportFlagsEXT::ERROR | vk::DebugReportFlagsEXT::WARNING
| vk::DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, | vk::DebugReportFlagsEXT::PERFORMANCE_WARNING,
pfn_callback: vulkan_debug_callback, pfn_callback: vulkan_debug_callback,
p_user_data: ptr::null_mut(), p_user_data: ptr::null_mut(),
}; };
@ -328,7 +328,7 @@ impl ExampleBase {
.enumerate() .enumerate()
.filter_map(|(index, ref info)| { .filter_map(|(index, ref info)| {
let supports_graphic_and_surface = info.queue_flags let supports_graphic_and_surface = info.queue_flags
.subset(vk::QUEUE_GRAPHICS_BIT) .subset(vk::QueueFlags::GRAPHICS)
&& surface_loader.get_physical_device_surface_support_khr( && surface_loader.get_physical_device_surface_support_khr(
*pdevice, *pdevice,
index as u32, index as u32,
@ -352,7 +352,7 @@ impl ExampleBase {
}; };
let priorities = [1.0]; let priorities = [1.0];
let queue_info = vk::DeviceQueueCreateInfo { let queue_info = vk::DeviceQueueCreateInfo {
s_type: vk::StructureType::DeviceQueueCreateInfo, s_type: vk::StructureType::DEVICE_QUEUE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
queue_family_index: queue_family_index as u32, queue_family_index: queue_family_index as u32,
@ -360,7 +360,7 @@ impl ExampleBase {
queue_count: priorities.len() as u32, queue_count: priorities.len() as u32,
}; };
let device_create_info = vk::DeviceCreateInfo { let device_create_info = vk::DeviceCreateInfo {
s_type: vk::StructureType::DeviceCreateInfo, s_type: vk::StructureType::DEVICE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
queue_create_info_count: 1, queue_create_info_count: 1,
@ -382,8 +382,8 @@ impl ExampleBase {
let surface_format = surface_formats let surface_format = surface_formats
.iter() .iter()
.map(|sfmt| match sfmt.format { .map(|sfmt| match sfmt.format {
vk::Format:: => vk::SurfaceFormatKHR { vk::Format::UNDEFINED => vk::SurfaceFormatKHR {
format: vk::Format::B8g8r8Unorm, format: vk::Format::B8G8R8_UNORM,
color_space: sfmt.color_space, color_space: sfmt.color_space,
}, },
_ => sfmt.clone(), _ => sfmt.clone(),
@ -408,9 +408,9 @@ impl ExampleBase {
}; };
let pre_transform = if surface_capabilities let pre_transform = if surface_capabilities
.supported_transforms .supported_transforms
.subset(vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR) .subset(vk::SurfaceTransformFlagsKHR::IDENTITY)
{ {
vk::SURFACE_TRANSFORM_IDENTITY_BIT_KHR vk::SurfaceTransformFlagsKHR::IDENTITY
} else { } else {
surface_capabilities.current_transform surface_capabilities.current_transform
}; };
@ -420,12 +420,12 @@ impl ExampleBase {
let present_mode = present_modes let present_mode = present_modes
.iter() .iter()
.cloned() .cloned()
.find(|&mode| mode == vk::PresentModeKHR::Mailbox) .find(|&mode| mode == vk::PresentModeKHR::MAILBOX)
.unwrap_or(vk::PresentModeKHR::Fifo); .unwrap_or(vk::PresentModeKHR::FIFO);
let swapchain_loader = let swapchain_loader =
Swapchain::new(&instance, &device).expect("Unable to load swapchain"); Swapchain::new(&instance, &device).expect("Unable to load swapchain");
let swapchain_create_info = vk::SwapchainCreateInfoKHR { let swapchain_create_info = vk::SwapchainCreateInfoKHR {
s_type: vk::StructureType::SwapchainCreateInfoKhr, s_type: vk::StructureType::SWAPCHAIN_CREATE_INFO_KHR,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
surface: surface, surface: surface,
@ -433,10 +433,10 @@ impl ExampleBase {
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::IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 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::COMPOSITE_ALPHA_OPAQUE_BIT_KHR, composite_alpha: vk::CompositeAlphaFlagsKHR::OPAQUE,
present_mode: present_mode, present_mode: present_mode,
clipped: 1, clipped: 1,
old_swapchain: vk::SwapchainKHR::null(), old_swapchain: vk::SwapchainKHR::null(),
@ -448,18 +448,18 @@ impl ExampleBase {
.create_swapchain_khr(&swapchain_create_info, None) .create_swapchain_khr(&swapchain_create_info, None)
.unwrap(); .unwrap();
let pool_create_info = vk::CommandPoolCreateInfo { let pool_create_info = vk::CommandPoolCreateInfo {
s_type: vk::StructureType::CommandPoolCreateInfo, s_type: vk::StructureType::COMMAND_POOL_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER_BIT, flags: vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER,
queue_family_index: queue_family_index, queue_family_index: queue_family_index,
}; };
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 { let command_buffer_allocate_info = vk::CommandBufferAllocateInfo {
s_type: vk::StructureType::CommandBufferAllocateInfo, s_type: vk::StructureType::COMMAND_BUFFER_ALLOCATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
command_buffer_count: 2, command_buffer_count: 2,
command_pool: pool, command_pool: pool,
level: vk::CommandBufferLevel::Primary, level: vk::CommandBufferLevel::PRIMARY,
}; };
let command_buffers = device let command_buffers = device
.allocate_command_buffers(&command_buffer_allocate_info) .allocate_command_buffers(&command_buffer_allocate_info)
@ -474,10 +474,10 @@ impl ExampleBase {
.iter() .iter()
.map(|&image| { .map(|&image| {
let create_view_info = vk::ImageViewCreateInfo { let create_view_info = vk::ImageViewCreateInfo {
s_type: vk::StructureType::ImageViewCreateInfo, s_type: vk::StructureType::IMAGE_VIEW_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
view_type: vk::ImageViewType::Type2d, 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,
@ -486,7 +486,7 @@ impl ExampleBase {
a: vk::ComponentSwizzle::A, a: vk::ComponentSwizzle::A,
}, },
subresource_range: vk::ImageSubresourceRange { subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_COLOR_BIT, 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,
@ -499,11 +499,11 @@ impl ExampleBase {
.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 { let depth_image_create_info = vk::ImageCreateInfo {
s_type: vk::StructureType::ImageCreateInfo, s_type: vk::StructureType::IMAGE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
image_type: vk::ImageType::Type2d, image_type: vk::ImageType::TYPE_2D,
format: vk::Format::D16Unorm, 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,
@ -511,13 +511,13 @@ impl ExampleBase {
}, },
mip_levels: 1, mip_levels: 1,
array_layers: 1, array_layers: 1,
samples: vk::SAMPLE_COUNT_1_BIT, samples: vk::SampleCountFlags::TYPE_1,
tiling: vk::ImageTiling::Optimal, tiling: vk::ImageTiling::OPTIMAL,
usage: vk::IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, usage: vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT,
sharing_mode: vk::SharingMode::Exclusive, sharing_mode: vk::SharingMode::EXCLUSIVE,
queue_family_index_count: 0, queue_family_index_count: 0,
p_queue_family_indices: ptr::null(), p_queue_family_indices: ptr::null(),
initial_layout: vk::ImageLayout::Undefined, initial_layout: vk::ImageLayout::UNDEFINED,
}; };
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);
@ -525,11 +525,11 @@ impl ExampleBase {
find_memorytype_index( find_memorytype_index(
&depth_image_memory_req, &depth_image_memory_req,
&device_memory_properties, &device_memory_properties,
vk::MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 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 { let depth_image_allocate_info = vk::MemoryAllocateInfo {
s_type: vk::StructureType::MemoryAllocateInfo, s_type: vk::StructureType::MEMORY_ALLOCATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
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,
@ -544,23 +544,23 @@ impl ExampleBase {
&device, &device,
setup_command_buffer, setup_command_buffer,
present_queue, present_queue,
&[vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT], &[vk::PipelineStageFlags::BOTTOM_OF_PIPE],
&[], &[],
&[], &[],
|device, setup_command_buffer| { |device, setup_command_buffer| {
let layout_transition_barrier = vk::ImageMemoryBarrier { let layout_transition_barrier = vk::ImageMemoryBarrier {
s_type: vk::StructureType::ImageMemoryBarrier, s_type: vk::StructureType::IMAGE_MEMORY_BARRIER,
p_next: ptr::null(), p_next: ptr::null(),
src_access_mask: Default::default(), src_access_mask: Default::default(),
dst_access_mask: vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT dst_access_mask: vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ
| vk::ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE,
old_layout: vk::ImageLayout::Undefined, old_layout: vk::ImageLayout::UNDEFINED,
new_layout: vk::ImageLayout::DepthStencilAttachmentOptimal, new_layout: vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, src_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED, dst_queue_family_index: vk::VK_QUEUE_FAMILY_IGNORED,
image: depth_image, image: depth_image,
subresource_range: vk::ImageSubresourceRange { subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, aspect_mask: vk::ImageAspectFlags::DEPTH,
base_mip_level: 0, base_mip_level: 0,
level_count: 1, level_count: 1,
base_array_layer: 0, base_array_layer: 0,
@ -569,8 +569,8 @@ impl ExampleBase {
}; };
device.cmd_pipeline_barrier( device.cmd_pipeline_barrier(
setup_command_buffer, setup_command_buffer,
vk::PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, vk::PipelineStageFlags::BOTTOM_OF_PIPE,
vk::PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, vk::PipelineStageFlags::LATE_FRAGMENT_TESTS,
vk::DependencyFlags::empty(), vk::DependencyFlags::empty(),
&[], &[],
&[], &[],
@ -579,19 +579,19 @@ impl ExampleBase {
}, },
); );
let depth_image_view_info = vk::ImageViewCreateInfo { let depth_image_view_info = vk::ImageViewCreateInfo {
s_type: vk::StructureType::ImageViewCreateInfo, s_type: vk::StructureType::IMAGE_VIEW_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
view_type: vk::ImageViewType::Type2d, view_type: vk::ImageViewType::TYPE_2D,
format: depth_image_create_info.format, format: depth_image_create_info.format,
components: vk::ComponentMapping { components: vk::ComponentMapping {
r: vk::ComponentSwizzle::Identity, r: vk::ComponentSwizzle::IDENTITY,
g: vk::ComponentSwizzle::Identity, g: vk::ComponentSwizzle::IDENTITY,
b: vk::ComponentSwizzle::Identity, b: vk::ComponentSwizzle::IDENTITY,
a: vk::ComponentSwizzle::Identity, a: vk::ComponentSwizzle::IDENTITY,
}, },
subresource_range: vk::ImageSubresourceRange { subresource_range: vk::ImageSubresourceRange {
aspect_mask: vk::IMAGE_ASPECT_DEPTH_BIT, aspect_mask: vk::ImageAspectFlags::DEPTH,
base_mip_level: 0, base_mip_level: 0,
level_count: 1, level_count: 1,
base_array_layer: 0, base_array_layer: 0,
@ -603,7 +603,7 @@ 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 { let semaphore_create_info = vk::SemaphoreCreateInfo {
s_type: vk::StructureType::SemaphoreCreateInfo, s_type: vk::StructureType::SEMAPHORE_CREATE_INFO,
p_next: ptr::null(), p_next: ptr::null(),
flags: Default::default(), flags: Default::default(),
}; };