diff --git a/Cargo.toml b/Cargo.toml index d7406d5..eff82f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,20 +10,16 @@ license = "MIT" version = "0.3.0" authors = ["Adrien Bennadji "] edition = "2021" - -exclude = [ - "assets/*", - "scripts/*", -] +include = ["/src", "LICENSE", "README.md", "CHANGELOG.md"] [dependencies] thiserror = "1.0" log = "0.4" egui = { version = ">=0.26, <=0.27", default-features = false } -ash = { version = ">=0.34, <=0.37", default-features = false, features = ["debug"] } +ash = { version = "0.38", default-features = false, features = ["std"] } gpu-allocator = { version = ">=0.25, <=0.26", default-features = false, features = ["vulkan"], optional = true } -vk-mem = { version = "0.3", optional = true } +vk-mem = { version = "0.3", default-features = false, optional = true } [features] default = [] @@ -33,10 +29,10 @@ vk-mem = ["dep:vk-mem"] [dev-dependencies] simple_logger = "5.0" -winit = { version = "0.29", default-features = false, features = ["rwh_05", "x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]} -ash = { version = "0.37", default-features = false, features = ["debug", "linked"] } -ash-window = "0.12" -raw-window-handle = "0.5" +winit = "0.29" +ash = { version = "0.38", default-features = false, features = ["debug", "linked", "std"] } +ash-window = "0.13" +raw-window-handle = "0.6" image = "0.24" egui = "0.27" egui-winit = "0.27" diff --git a/examples/common/mod.rs b/examples/common/mod.rs index b73fcc1..e46323b 100644 --- a/examples/common/mod.rs +++ b/examples/common/mod.rs @@ -3,16 +3,14 @@ pub mod vulkan; #[cfg(any(target_os = "macos", target_os = "ios"))] use ash::vk::{KhrGetPhysicalDeviceProperties2Fn, KhrPortabilityEnumerationFn}; use ash::{ - extensions::{ - ext::DebugUtils, - khr::{Surface, Swapchain as SwapchainLoader}, - }, + ext::debug_utils, + khr::{surface, swapchain}, vk, Device, Entry, Instance, }; use egui::{ClippedPrimitive, Context, TextureId, ViewportId}; use egui_ash_renderer::{Options, Renderer}; use egui_winit::State; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::{ error::Error, ffi::{CStr, CString}, @@ -62,7 +60,7 @@ impl App { let vulkan_context = VulkanContext::new(&window, title)?; let command_buffer = { - let allocate_info = vk::CommandBufferAllocateInfo::builder() + let allocate_info = vk::CommandBufferAllocateInfo::default() .command_pool(vulkan_context.command_pool) .level(vk::CommandBufferLevel::PRIMARY) .command_buffer_count(1); @@ -78,7 +76,7 @@ impl App { // Semaphore use for presentation let image_available_semaphore = { - let semaphore_info = vk::SemaphoreCreateInfo::builder(); + let semaphore_info = vk::SemaphoreCreateInfo::default(); unsafe { vulkan_context .device @@ -86,7 +84,7 @@ impl App { } }; let render_finished_semaphore = { - let semaphore_info = vk::SemaphoreCreateInfo::builder(); + let semaphore_info = vk::SemaphoreCreateInfo::default(); unsafe { vulkan_context .device @@ -94,7 +92,7 @@ impl App { } }; let fence = { - let fence_info = vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED); + let fence_info = vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED); unsafe { vulkan_context.device.create_fence(&fence_info, None)? } }; @@ -320,12 +318,11 @@ impl App { .expect("Failed to record command buffer"); let command_buffers = [command_buffer]; - let submit_info = [vk::SubmitInfo::builder() + let submit_info = [vk::SubmitInfo::default() .wait_semaphores(&wait_semaphores) .wait_dst_stage_mask(&wait_stages) .command_buffers(&command_buffers) - .signal_semaphores(&signal_semaphores) - .build()]; + .signal_semaphores(&signal_semaphores)]; unsafe { vulkan_context .device @@ -335,7 +332,7 @@ impl App { let swapchains = [swapchain.khr]; let images_indices = [image_index]; - let present_info = vk::PresentInfoKHR::builder() + let present_info = vk::PresentInfoKHR::default() .wait_semaphores(&signal_semaphores) .swapchains(&swapchains) .image_indices(&images_indices); @@ -412,9 +409,9 @@ impl App { pub struct VulkanContext { _entry: Entry, pub instance: Instance, - debug_utils: DebugUtils, + debug_utils: debug_utils::Instance, debug_utils_messenger: vk::DebugUtilsMessengerEXT, - surface: Surface, + surface: surface::Instance, surface_khr: vk::SurfaceKHR, pub physical_device: vk::PhysicalDevice, graphics_q_index: u32, @@ -433,13 +430,13 @@ impl VulkanContext { create_vulkan_instance(&entry, window, name)?; // Vulkan surface - let surface = Surface::new(&entry, &instance); + let surface = surface::Instance::new(&entry, &instance); let surface_khr = unsafe { ash_window::create_surface( &entry, &instance, - window.raw_display_handle(), - window.raw_window_handle(), + window.display_handle()?.as_raw(), + window.window_handle()?.as_raw(), None, )? }; @@ -463,7 +460,7 @@ impl VulkanContext { // Command pool & buffer let command_pool = { - let command_pool_info = vk::CommandPoolCreateInfo::builder() + let command_pool_info = vk::CommandPoolCreateInfo::default() .queue_family_index(graphics_q_index) .flags(vk::CommandPoolCreateFlags::empty()); unsafe { device.create_command_pool(&command_pool_info, None)? } @@ -502,7 +499,7 @@ impl Drop for VulkanContext { } struct Swapchain { - loader: SwapchainLoader, + loader: swapchain::Device, extent: vk::Extent2D, khr: vk::SwapchainKHR, images: Vec, @@ -599,26 +596,25 @@ fn create_vulkan_instance( entry: &Entry, window: &Window, title: &str, -) -> Result<(Instance, DebugUtils, vk::DebugUtilsMessengerEXT), Box> { +) -> Result<(Instance, debug_utils::Instance, vk::DebugUtilsMessengerEXT), Box> { log::debug!("Creating vulkan instance"); // Vulkan instance let app_name = CString::new(title)?; - let engine_name = CString::new("No Engine")?; - let app_info = vk::ApplicationInfo::builder() + let app_info = vk::ApplicationInfo::default() .application_name(app_name.as_c_str()) .application_version(vk::make_api_version(0, 0, 1, 0)) - .engine_name(engine_name.as_c_str()) + .engine_name(c"No Engine") .engine_version(vk::make_api_version(0, 0, 1, 0)) .api_version(vk::make_api_version(0, 1, 0, 0)); let mut extension_names = - ash_window::enumerate_required_extensions(window.raw_display_handle())?.to_vec(); - extension_names.push(DebugUtils::name().as_ptr()); + ash_window::enumerate_required_extensions(window.display_handle()?.as_raw())?.to_vec(); + extension_names.push(debug_utils::NAME.as_ptr()); #[cfg(any(target_os = "macos", target_os = "ios"))] { - extension_names.push(KhrPortabilityEnumerationFn::name().as_ptr()); - extension_names.push(KhrGetPhysicalDeviceProperties2Fn::name().as_ptr()); + extension_names.push(ash::khr::portability_enumeration::NAME.as_ptr()); + extension_names.push(ash::khr::get_physical_device_properties2::NAME.as_ptr()); } let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) { @@ -627,7 +623,7 @@ fn create_vulkan_instance( vk::InstanceCreateFlags::default() }; - let instance_create_info = vk::InstanceCreateInfo::builder() + let instance_create_info = vk::InstanceCreateInfo::default() .application_info(&app_info) .flags(create_flags) .enabled_extension_names(&extension_names); @@ -635,7 +631,7 @@ fn create_vulkan_instance( let instance = unsafe { entry.create_instance(&instance_create_info, None)? }; // Vulkan debug report - let create_info = vk::DebugUtilsMessengerCreateInfoEXT::builder() + let create_info = vk::DebugUtilsMessengerCreateInfoEXT::default() .flags(vk::DebugUtilsMessengerCreateFlagsEXT::empty()) .message_severity( vk::DebugUtilsMessageSeverityFlagsEXT::INFO @@ -648,7 +644,7 @@ fn create_vulkan_instance( | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION, ) .pfn_user_callback(Some(vulkan_debug_callback)); - let debug_utils = DebugUtils::new(entry, &instance); + let debug_utils = debug_utils::Instance::new(entry, &instance); let debug_utils_messenger = unsafe { debug_utils.create_debug_utils_messenger(&create_info, None)? }; @@ -675,7 +671,7 @@ unsafe extern "system" fn vulkan_debug_callback( fn create_vulkan_physical_device_and_get_graphics_and_present_qs_indices( instance: &Instance, - surface: &Surface, + surface: &surface::Instance, surface_khr: vk::SurfaceKHR, ) -> Result<(vk::PhysicalDevice, u32, u32), Box> { log::debug!("Creating vulkan physical device"); @@ -723,7 +719,7 @@ fn create_vulkan_physical_device_and_get_graphics_and_present_qs_indices( }; let extention_support = extension_props.iter().any(|ext| { let name = unsafe { CStr::from_ptr(ext.extension_name.as_ptr()) }; - SwapchainLoader::name() == name + swapchain::NAME == name }); // Does the device have available formats for the given surface @@ -772,17 +768,20 @@ fn create_vulkan_device_and_graphics_and_present_qs( indices .iter() .map(|index| { - vk::DeviceQueueCreateInfo::builder() + vk::DeviceQueueCreateInfo::default() .queue_family_index(*index) .queue_priorities(&queue_priorities) - .build() }) .collect::>() }; - let device_extensions_ptrs = [SwapchainLoader::name().as_ptr()]; + let device_extensions_ptrs = [ + swapchain::NAME.as_ptr(), + #[cfg(any(target_os = "macos", target_os = "ios"))] + ash::khr::portability_subset::NAME.as_ptr(), + ]; - let device_create_info = vk::DeviceCreateInfo::builder() + let device_create_info = vk::DeviceCreateInfo::default() .queue_create_infos(&queue_create_infos) .enabled_extension_names(&device_extensions_ptrs); @@ -797,7 +796,7 @@ fn create_vulkan_swapchain( vulkan_context: &VulkanContext, ) -> Result< ( - SwapchainLoader, + swapchain::Device, vk::SwapchainKHR, vk::Extent2D, vk::Format, @@ -877,7 +876,7 @@ fn create_vulkan_swapchain( vulkan_context.present_q_index, ]; let create_info = { - let mut builder = vk::SwapchainCreateInfoKHR::builder() + let mut builder = vk::SwapchainCreateInfoKHR::default() .surface(vulkan_context.surface_khr) .min_image_count(image_count) .image_format(format.format) @@ -901,7 +900,7 @@ fn create_vulkan_swapchain( .clipped(true) }; - let swapchain = SwapchainLoader::new(&vulkan_context.instance, &vulkan_context.device); + let swapchain = swapchain::Device::new(&vulkan_context.instance, &vulkan_context.device); let swapchain_khr = unsafe { swapchain.create_swapchain(&create_info, None)? }; // Swapchain images and image views @@ -909,7 +908,7 @@ fn create_vulkan_swapchain( let views = images .iter() .map(|image| { - let create_info = vk::ImageViewCreateInfo::builder() + let create_info = vk::ImageViewCreateInfo::default() .image(*image) .view_type(vk::ImageViewType::TYPE_2D) .format(format.format) @@ -940,26 +939,23 @@ fn create_vulkan_render_pass( format: vk::Format, ) -> Result> { log::debug!("Creating vulkan render pass"); - let attachment_descs = [vk::AttachmentDescription::builder() + let attachment_descs = [vk::AttachmentDescription::default() .format(format) .samples(vk::SampleCountFlags::TYPE_1) .load_op(vk::AttachmentLoadOp::CLEAR) .store_op(vk::AttachmentStoreOp::STORE) .initial_layout(vk::ImageLayout::UNDEFINED) - .final_layout(vk::ImageLayout::PRESENT_SRC_KHR) - .build()]; + .final_layout(vk::ImageLayout::PRESENT_SRC_KHR)]; - let color_attachment_refs = [vk::AttachmentReference::builder() + let color_attachment_refs = [vk::AttachmentReference::default() .attachment(0) - .layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL) - .build()]; + .layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL)]; - let subpass_descs = [vk::SubpassDescription::builder() + let subpass_descs = [vk::SubpassDescription::default() .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS) - .color_attachments(&color_attachment_refs) - .build()]; + .color_attachments(&color_attachment_refs)]; - let subpass_deps = [vk::SubpassDependency::builder() + let subpass_deps = [vk::SubpassDependency::default() .src_subpass(vk::SUBPASS_EXTERNAL) .dst_subpass(0) .src_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT) @@ -967,10 +963,9 @@ fn create_vulkan_render_pass( .dst_stage_mask(vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT) .dst_access_mask( vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE, - ) - .build()]; + )]; - let render_pass_info = vk::RenderPassCreateInfo::builder() + let render_pass_info = vk::RenderPassCreateInfo::default() .attachments(&attachment_descs) .subpasses(&subpass_descs) .dependencies(&subpass_deps); @@ -989,7 +984,7 @@ fn create_vulkan_framebuffers( .iter() .map(|view| [*view]) .map(|attachments| { - let framebuffer_info = vk::FramebufferCreateInfo::builder() + let framebuffer_info = vk::FramebufferCreateInfo::default() .render_pass(render_pass) .attachments(&attachments) .width(extent.width) @@ -1015,10 +1010,10 @@ fn record_command_buffers( unsafe { device.reset_command_pool(command_pool, vk::CommandPoolResetFlags::empty())? }; let command_buffer_begin_info = - vk::CommandBufferBeginInfo::builder().flags(vk::CommandBufferUsageFlags::SIMULTANEOUS_USE); + vk::CommandBufferBeginInfo::default().flags(vk::CommandBufferUsageFlags::SIMULTANEOUS_USE); unsafe { device.begin_command_buffer(command_buffer, &command_buffer_begin_info)? }; - let render_pass_begin_info = vk::RenderPassBeginInfo::builder() + let render_pass_begin_info = vk::RenderPassBeginInfo::default() .render_pass(render_pass) .framebuffer(framebuffer) .render_area(vk::Rect2D { diff --git a/examples/common/vulkan.rs b/examples/common/vulkan.rs index fb7e9e3..787130f 100644 --- a/examples/common/vulkan.rs +++ b/examples/common/vulkan.rs @@ -23,11 +23,10 @@ mod buffer { usage: vk::BufferUsageFlags, mem_properties: vk::PhysicalDeviceMemoryProperties, ) -> RendererResult<(vk::Buffer, vk::DeviceMemory)> { - let buffer_info = vk::BufferCreateInfo::builder() + let buffer_info = vk::BufferCreateInfo::default() .size(size as _) .usage(usage) - .sharing_mode(vk::SharingMode::EXCLUSIVE) - .build(); + .sharing_mode(vk::SharingMode::EXCLUSIVE); let buffer = unsafe { device.create_buffer(&buffer_info, None)? }; let mem_requirements = unsafe { device.get_buffer_memory_requirements(buffer) }; @@ -37,7 +36,7 @@ mod buffer { vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT, ); - let alloc_info = vk::MemoryAllocateInfo::builder() + let alloc_info = vk::MemoryAllocateInfo::default() .allocation_size(mem_requirements.size) .memory_type_index(mem_type); let memory = unsafe { device.allocate_memory(&alloc_info, None)? }; @@ -159,7 +158,7 @@ pub mod texture { depth: 1, }; - let image_info = vk::ImageCreateInfo::builder() + let image_info = vk::ImageCreateInfo::default() .image_type(vk::ImageType::TYPE_2D) .extent(extent) .mip_levels(1) @@ -180,7 +179,7 @@ pub mod texture { vk::MemoryPropertyFlags::DEVICE_LOCAL, ); - let alloc_info = vk::MemoryAllocateInfo::builder() + let alloc_info = vk::MemoryAllocateInfo::default() .allocation_size(mem_requirements.size) .memory_type_index(mem_type_index); let memory = unsafe { @@ -195,7 +194,7 @@ pub mod texture { // Transition the image layout and copy the buffer into the image // and transition the layout again to be readable from fragment shader. { - let mut barrier = vk::ImageMemoryBarrier::builder() + let mut barrier = vk::ImageMemoryBarrier::default() .old_layout(vk::ImageLayout::UNDEFINED) .new_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL) .src_queue_family_index(vk::QUEUE_FAMILY_IGNORED) @@ -209,8 +208,7 @@ pub mod texture { layer_count: 1, }) .src_access_mask(vk::AccessFlags::empty()) - .dst_access_mask(vk::AccessFlags::TRANSFER_WRITE) - .build(); + .dst_access_mask(vk::AccessFlags::TRANSFER_WRITE); unsafe { device.cmd_pipeline_barrier( @@ -224,7 +222,7 @@ pub mod texture { ) }; - let region = vk::BufferImageCopy::builder() + let region = vk::BufferImageCopy::default() .buffer_offset(0) .buffer_row_length(0) .buffer_image_height(0) @@ -239,8 +237,7 @@ pub mod texture { width, height, depth: 1, - }) - .build(); + }); unsafe { device.cmd_copy_buffer_to_image( command_buffer, @@ -270,7 +267,7 @@ pub mod texture { } let image_view = { - let create_info = vk::ImageViewCreateInfo::builder() + let create_info = vk::ImageViewCreateInfo::default() .image(image) .view_type(vk::ImageViewType::TYPE_2D) .format(format) @@ -286,7 +283,7 @@ pub mod texture { }; let sampler = { - let sampler_info = vk::SamplerCreateInfo::builder() + let sampler_info = vk::SamplerCreateInfo::default() .mag_filter(vk::Filter::LINEAR) .min_filter(vk::Filter::LINEAR) .address_mode_u(vk::SamplerAddressMode::REPEAT) @@ -334,7 +331,7 @@ pub mod texture { executor: F, ) -> RendererResult { let command_buffer = { - let alloc_info = vk::CommandBufferAllocateInfo::builder() + let alloc_info = vk::CommandBufferAllocateInfo::default() .level(vk::CommandBufferLevel::PRIMARY) .command_pool(pool) .command_buffer_count(1); @@ -345,7 +342,7 @@ pub mod texture { // Begin recording { - let begin_info = vk::CommandBufferBeginInfo::builder() + let begin_info = vk::CommandBufferBeginInfo::default() .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT); unsafe { device.begin_command_buffer(command_buffer, &begin_info)? }; } @@ -358,9 +355,7 @@ pub mod texture { // Submit and wait { - let submit_info = vk::SubmitInfo::builder() - .command_buffers(&command_buffers) - .build(); + let submit_info = vk::SubmitInfo::default().command_buffers(&command_buffers); let submit_infos = [submit_info]; unsafe { device.queue_submit(queue, &submit_infos, vk::Fence::null())?; diff --git a/src/lib.rs b/src/lib.rs index fbd1ca4..afc351f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ //! //! You can indicate wether you will target an sRGB framebuffer or not by passing the option `srgb_framebuffer` when initializing the renderer. //! When you target an sRGB framebuffer, the fragment shader will output linear color values, otherwise it will convert the colors to sRGB. -//! +//! //! ### Managed textures //! //! Textures managed by egui must be kept in sync with the renderer. To do so, the user should call `Renderer::set_textures` and diff --git a/src/renderer/allocator/default.rs b/src/renderer/allocator/default.rs index ed74006..cb7703d 100644 --- a/src/renderer/allocator/default.rs +++ b/src/renderer/allocator/default.rs @@ -44,11 +44,10 @@ impl Allocate for Allocator { size: usize, usage: vk::BufferUsageFlags, ) -> RendererResult<(vk::Buffer, Self::Memory)> { - let buffer_info = vk::BufferCreateInfo::builder() + let buffer_info = vk::BufferCreateInfo::default() .size(size as _) .usage(usage) - .sharing_mode(vk::SharingMode::EXCLUSIVE) - .build(); + .sharing_mode(vk::SharingMode::EXCLUSIVE); let buffer = unsafe { device.create_buffer(&buffer_info, None)? }; @@ -58,7 +57,7 @@ impl Allocate for Allocator { vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT, )?; - let alloc_info = vk::MemoryAllocateInfo::builder() + let alloc_info = vk::MemoryAllocateInfo::default() .allocation_size(mem_requirements.size) .memory_type_index(mem_type); let memory = unsafe { device.allocate_memory(&alloc_info, None)? }; @@ -79,7 +78,7 @@ impl Allocate for Allocator { depth: 1, }; - let image_info = vk::ImageCreateInfo::builder() + let image_info = vk::ImageCreateInfo::default() .image_type(vk::ImageType::TYPE_2D) .extent(extent) .mip_levels(1) @@ -97,7 +96,7 @@ impl Allocate for Allocator { let mem_type_index = self.find_memory_type(mem_requirements, vk::MemoryPropertyFlags::DEVICE_LOCAL)?; - let alloc_info = vk::MemoryAllocateInfo::builder() + let alloc_info = vk::MemoryAllocateInfo::default() .allocation_size(mem_requirements.size) .memory_type_index(mem_type_index); let memory = unsafe { diff --git a/src/renderer/allocator/gpu.rs b/src/renderer/allocator/gpu.rs index 96df771..281855c 100644 --- a/src/renderer/allocator/gpu.rs +++ b/src/renderer/allocator/gpu.rs @@ -36,11 +36,10 @@ impl Allocate for Allocator { size: usize, usage: vk::BufferUsageFlags, ) -> RendererResult<(vk::Buffer, Self::Memory)> { - let buffer_info = vk::BufferCreateInfo::builder() + let buffer_info = vk::BufferCreateInfo::default() .size(size as _) .usage(usage) - .sharing_mode(vk::SharingMode::EXCLUSIVE) - .build(); + .sharing_mode(vk::SharingMode::EXCLUSIVE); let buffer = unsafe { device.create_buffer(&buffer_info, None)? }; let requirements = unsafe { device.get_buffer_memory_requirements(buffer) }; @@ -72,7 +71,7 @@ impl Allocate for Allocator { depth: 1, }; - let image_info = vk::ImageCreateInfo::builder() + let image_info = vk::ImageCreateInfo::default() .image_type(vk::ImageType::TYPE_2D) .extent(extent) .mip_levels(1) diff --git a/src/renderer/allocator/vkmem.rs b/src/renderer/allocator/vkmem.rs index e0bad25..63b823d 100644 --- a/src/renderer/allocator/vkmem.rs +++ b/src/renderer/allocator/vkmem.rs @@ -35,11 +35,10 @@ impl Allocate for Allocator { size: usize, usage: vk::BufferUsageFlags, ) -> RendererResult<(vk::Buffer, Self::Memory)> { - let buffer_info = vk::BufferCreateInfo::builder() + let buffer_info = vk::BufferCreateInfo::default() .size(size as _) .usage(usage) - .sharing_mode(vk::SharingMode::EXCLUSIVE) - .build(); + .sharing_mode(vk::SharingMode::EXCLUSIVE); let buffer_alloc_info = AllocationCreateInfo { usage: MemoryUsage::AutoPreferHost, @@ -67,7 +66,7 @@ impl Allocate for Allocator { depth: 1, }; - let image_info = vk::ImageCreateInfo::builder() + let image_info = vk::ImageCreateInfo::default() .image_type(vk::ImageType::TYPE_2D) .extent(extent) .mip_levels(1) diff --git a/src/renderer/vulkan.rs b/src/renderer/vulkan.rs index 821e2d7..530906e 100644 --- a/src/renderer/vulkan.rs +++ b/src/renderer/vulkan.rs @@ -26,15 +26,14 @@ pub fn create_vulkan_descriptor_set_layout( device: &Device, ) -> RendererResult { log::debug!("Creating vulkan descriptor set layout"); - let bindings = [vk::DescriptorSetLayoutBinding::builder() + let bindings = [vk::DescriptorSetLayoutBinding::default() .binding(0) .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) .descriptor_count(1) - .stage_flags(vk::ShaderStageFlags::FRAGMENT) - .build()]; + .stage_flags(vk::ShaderStageFlags::FRAGMENT)]; let descriptor_set_create_info = - vk::DescriptorSetLayoutCreateInfo::builder().bindings(&bindings); + vk::DescriptorSetLayoutCreateInfo::default().bindings(&bindings); unsafe { Ok(device.create_descriptor_set_layout(&descriptor_set_create_info, None)?) } } @@ -51,7 +50,7 @@ pub(crate) fn create_vulkan_pipeline_layout( }]; let descriptor_set_layouts = [descriptor_set_layout]; - let layout_info = vk::PipelineLayoutCreateInfo::builder() + let layout_info = vk::PipelineLayoutCreateInfo::default() .set_layouts(&descriptor_set_layouts) .push_constant_ranges(&push_const_range); let pipeline_layout = unsafe { device.create_pipeline_layout(&layout_info, None)? }; @@ -71,11 +70,11 @@ pub(crate) fn create_vulkan_pipeline( let fragment_shader_source = std::include_bytes!("../shaders/shader.frag.spv"); let vertex_source = read_shader_from_source(vertex_shader_source)?; - let vertex_create_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_source); + let vertex_create_info = vk::ShaderModuleCreateInfo::default().code(&vertex_source); let vertex_module = unsafe { device.create_shader_module(&vertex_create_info, None)? }; let fragment_source = read_shader_from_source(fragment_shader_source)?; - let fragment_create_info = vk::ShaderModuleCreateInfo::builder().code(&fragment_source); + let fragment_create_info = vk::ShaderModuleCreateInfo::default().code(&fragment_source); let fragment_module = unsafe { device.create_shader_module(&fragment_create_info, None)? }; let specialization_entries = [vk::SpecializationMapEntry { @@ -85,59 +84,53 @@ pub(crate) fn create_vulkan_pipeline( }]; let data = [vk::Bool32::from(options.srgb_framebuffer)]; let data_raw = unsafe { any_as_u8_slice(&data) }; - let specialization_info = vk::SpecializationInfo::builder() + let specialization_info = vk::SpecializationInfo::default() .map_entries(&specialization_entries) .data(data_raw); let shader_states_infos = [ - vk::PipelineShaderStageCreateInfo::builder() + vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::VERTEX) .module(vertex_module) - .name(&entry_point_name) - .build(), - vk::PipelineShaderStageCreateInfo::builder() + .name(&entry_point_name), + vk::PipelineShaderStageCreateInfo::default() .stage(vk::ShaderStageFlags::FRAGMENT) .module(fragment_module) .specialization_info(&specialization_info) - .name(&entry_point_name) - .build(), + .name(&entry_point_name), ]; - let binding_desc = [vk::VertexInputBindingDescription::builder() + let binding_desc = [vk::VertexInputBindingDescription::default() .binding(0) .stride(20) - .input_rate(vk::VertexInputRate::VERTEX) - .build()]; + .input_rate(vk::VertexInputRate::VERTEX)]; let attribute_desc = [ - vk::VertexInputAttributeDescription::builder() + vk::VertexInputAttributeDescription::default() .binding(0) .location(0) .format(vk::Format::R32G32_SFLOAT) - .offset(0) - .build(), - vk::VertexInputAttributeDescription::builder() + .offset(0), + vk::VertexInputAttributeDescription::default() .binding(0) .location(1) .format(vk::Format::R32G32_SFLOAT) - .offset(8) - .build(), - vk::VertexInputAttributeDescription::builder() + .offset(8), + vk::VertexInputAttributeDescription::default() .binding(0) .location(2) .format(vk::Format::R8G8B8A8_UNORM) - .offset(16) - .build(), + .offset(16), ]; - let vertex_input_info = vk::PipelineVertexInputStateCreateInfo::builder() + let vertex_input_info = vk::PipelineVertexInputStateCreateInfo::default() .vertex_binding_descriptions(&binding_desc) .vertex_attribute_descriptions(&attribute_desc); - let input_assembly_info = vk::PipelineInputAssemblyStateCreateInfo::builder() + let input_assembly_info = vk::PipelineInputAssemblyStateCreateInfo::default() .topology(vk::PrimitiveTopology::TRIANGLE_LIST) .primitive_restart_enable(false); - let rasterizer_info = vk::PipelineRasterizationStateCreateInfo::builder() + let rasterizer_info = vk::PipelineRasterizationStateCreateInfo::default() .depth_clamp_enable(false) .rasterizer_discard_enable(false) .polygon_mode(vk::PolygonMode::FILL) @@ -151,18 +144,18 @@ pub(crate) fn create_vulkan_pipeline( let viewports = [Default::default()]; let scissors = [Default::default()]; - let viewport_info = vk::PipelineViewportStateCreateInfo::builder() + let viewport_info = vk::PipelineViewportStateCreateInfo::default() .viewports(&viewports) .scissors(&scissors); - let multisampling_info = vk::PipelineMultisampleStateCreateInfo::builder() + let multisampling_info = vk::PipelineMultisampleStateCreateInfo::default() .sample_shading_enable(false) .rasterization_samples(vk::SampleCountFlags::TYPE_1) .min_sample_shading(1.0) .alpha_to_coverage_enable(false) .alpha_to_one_enable(false); - let color_blend_attachments = [vk::PipelineColorBlendAttachmentState::builder() + let color_blend_attachments = [vk::PipelineColorBlendAttachmentState::default() .color_write_mask( vk::ColorComponentFlags::R | vk::ColorComponentFlags::G @@ -175,27 +168,25 @@ pub(crate) fn create_vulkan_pipeline( .color_blend_op(vk::BlendOp::ADD) .src_alpha_blend_factor(vk::BlendFactor::ONE_MINUS_DST_ALPHA) .dst_alpha_blend_factor(vk::BlendFactor::ONE) - .alpha_blend_op(vk::BlendOp::ADD) - .build()]; - let color_blending_info = vk::PipelineColorBlendStateCreateInfo::builder() + .alpha_blend_op(vk::BlendOp::ADD)]; + let color_blending_info = vk::PipelineColorBlendStateCreateInfo::default() .logic_op_enable(false) .logic_op(vk::LogicOp::COPY) .attachments(&color_blend_attachments) .blend_constants([0.0, 0.0, 0.0, 0.0]); - let depth_stencil_state_create_info = vk::PipelineDepthStencilStateCreateInfo::builder() + let depth_stencil_state_create_info = vk::PipelineDepthStencilStateCreateInfo::default() .depth_test_enable(options.enable_depth_test) .depth_write_enable(options.enable_depth_write) .depth_compare_op(vk::CompareOp::ALWAYS) .depth_bounds_test_enable(false) - .stencil_test_enable(false) - .build(); + .stencil_test_enable(false); let dynamic_states = [vk::DynamicState::SCISSOR, vk::DynamicState::VIEWPORT]; let dynamic_states_info = - vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_states); + vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_states); - let pipeline_info = vk::GraphicsPipelineCreateInfo::builder() + let pipeline_info = vk::GraphicsPipelineCreateInfo::default() .stages(&shader_states_infos) .vertex_input_state(&vertex_input_info) .input_assembly_state(&input_assembly_info) @@ -259,7 +250,7 @@ pub fn create_vulkan_descriptor_pool( ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, descriptor_count: max_sets, }]; - let create_info = vk::DescriptorPoolCreateInfo::builder() + let create_info = vk::DescriptorPoolCreateInfo::default() .pool_sizes(&sizes) .max_sets(max_sets) .flags(vk::DescriptorPoolCreateFlags::FREE_DESCRIPTOR_SET); @@ -278,7 +269,7 @@ pub fn create_vulkan_descriptor_set( let set = { let set_layouts = [set_layout]; - let allocate_info = vk::DescriptorSetAllocateInfo::builder() + let allocate_info = vk::DescriptorSetAllocateInfo::default() .descriptor_pool(descriptor_pool) .set_layouts(&set_layouts); @@ -292,12 +283,11 @@ pub fn create_vulkan_descriptor_set( image_layout: vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, }]; - let writes = [vk::WriteDescriptorSet::builder() + let writes = [vk::WriteDescriptorSet::default() .dst_set(set) .dst_binding(0) .descriptor_type(vk::DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(&image_info) - .build()]; + .image_info(&image_info)]; device.update_descriptor_sets(&writes, &[]) } @@ -376,7 +366,7 @@ mod texture { let (image, image_mem) = allocator.create_image(device, width, height)?; let image_view = { - let create_info = vk::ImageViewCreateInfo::builder() + let create_info = vk::ImageViewCreateInfo::default() .image(image) .view_type(vk::ImageViewType::TYPE_2D) .format(vk::Format::R8G8B8A8_SRGB) @@ -392,7 +382,7 @@ mod texture { }; let sampler = { - let sampler_info = vk::SamplerCreateInfo::builder() + let sampler_info = vk::SamplerCreateInfo::default() .mag_filter(vk::Filter::LINEAR) .min_filter(vk::Filter::LINEAR) .address_mode_u(vk::SamplerAddressMode::CLAMP_TO_EDGE) @@ -466,7 +456,7 @@ mod texture { // Transition the image layout and copy the buffer into the image // and transition the layout again to be readable from fragment shader. { - let mut barrier = vk::ImageMemoryBarrier::builder() + let mut barrier = vk::ImageMemoryBarrier::default() .old_layout(vk::ImageLayout::UNDEFINED) .new_layout(vk::ImageLayout::TRANSFER_DST_OPTIMAL) .src_queue_family_index(vk::QUEUE_FAMILY_IGNORED) @@ -480,8 +470,7 @@ mod texture { layer_count: 1, }) .src_access_mask(vk::AccessFlags::empty()) - .dst_access_mask(vk::AccessFlags::TRANSFER_WRITE) - .build(); + .dst_access_mask(vk::AccessFlags::TRANSFER_WRITE); unsafe { device.cmd_pipeline_barrier( @@ -495,7 +484,7 @@ mod texture { ) }; - let region = vk::BufferImageCopy::builder() + let region = vk::BufferImageCopy::default() .buffer_offset(0) .buffer_row_length(0) .buffer_image_height(0) @@ -514,8 +503,7 @@ mod texture { width: region.extent.width, height: region.extent.height, depth: 1, - }) - .build(); + }); unsafe { device.cmd_copy_buffer_to_image( command_buffer, @@ -565,7 +553,7 @@ mod texture { executor: F, ) -> RendererResult { let command_buffer = { - let alloc_info = vk::CommandBufferAllocateInfo::builder() + let alloc_info = vk::CommandBufferAllocateInfo::default() .level(vk::CommandBufferLevel::PRIMARY) .command_pool(pool) .command_buffer_count(1); @@ -576,7 +564,7 @@ mod texture { // Begin recording { - let begin_info = vk::CommandBufferBeginInfo::builder() + let begin_info = vk::CommandBufferBeginInfo::default() .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT); unsafe { device.begin_command_buffer(command_buffer, &begin_info)? }; } @@ -589,9 +577,7 @@ mod texture { // Submit and wait { - let submit_info = vk::SubmitInfo::builder() - .command_buffers(&command_buffers) - .build(); + let submit_info = vk::SubmitInfo::default().command_buffers(&command_buffers); let submit_infos = [submit_info]; unsafe { device.queue_submit(queue, &submit_infos, vk::Fence::null())?;