From 8fedd8ea1e51dbfad63933267257f035a4a0395b Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Mon, 1 Apr 2024 15:08:00 -0700 Subject: [PATCH] yakui-vulkan: Update ash, ash-window, raw-window-handle --- crates/yakui-vulkan/Cargo.toml | 9 ++-- crates/yakui-vulkan/examples/demo.rs | 54 +++++++++++------------ crates/yakui-vulkan/src/buffer.rs | 2 +- crates/yakui-vulkan/src/descriptors.rs | 12 ++--- crates/yakui-vulkan/src/lib.rs | 22 ++++----- crates/yakui-vulkan/src/vulkan_texture.rs | 8 ++-- 6 files changed, 54 insertions(+), 53 deletions(-) diff --git a/crates/yakui-vulkan/Cargo.toml b/crates/yakui-vulkan/Cargo.toml index f05fc58e..88182ebb 100644 --- a/crates/yakui-vulkan/Cargo.toml +++ b/crates/yakui-vulkan/Cargo.toml @@ -10,12 +10,13 @@ edition = "2021" yakui = { path = "../yakui" } yakui-core = { path = "../yakui-core" } -ash = "0.37.2" +ash = { version = "0.38", default-features = false, features = ["std"] } bytemuck = "1.13.0" thunderdome = "0.6.0" [dev-dependencies] -ash-window = "0.12.0" +ash = { version = "0.38", default-features = false, features = ["loaded"] } +ash-window = "0.13" image = "0.24.5" -raw-window-handle = "0.5.0" -winit = { version = "0.29.2", features = ["rwh_05"] } +raw-window-handle = "0.6.0" +winit = "0.29.2" diff --git a/crates/yakui-vulkan/examples/demo.rs b/crates/yakui-vulkan/examples/demo.rs index c68e04bd..b17cc7b5 100644 --- a/crates/yakui-vulkan/examples/demo.rs +++ b/crates/yakui-vulkan/examples/demo.rs @@ -236,7 +236,7 @@ struct VulkanTest { device: ash::Device, physical_device: vk::PhysicalDevice, instance: ash::Instance, - surface_loader: ash::extensions::khr::Surface, + surface_loader: ash::khr::surface::Instance, device_memory_properties: vk::PhysicalDeviceMemoryProperties, present_queue: vk::Queue, @@ -264,13 +264,13 @@ impl VulkanTest { /// Bring up all the Vulkan pomp and ceremony required to render things. /// Vulkan Broadly lifted from: https://github.com/ash-rs/ash/blob/0.37.2/examples/src/lib.rs pub fn new(window_width: u32, window_height: u32, window: &winit::window::Window) -> Self { - use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; + use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use std::ffi::CStr; let entry = unsafe { ash::Entry::load().expect("failed to load Vulkan") }; let app_name = unsafe { CStr::from_bytes_with_nul_unchecked(b"Yakui Vulkan Test\0") }; - let appinfo = vk::ApplicationInfo::builder() + let appinfo = vk::ApplicationInfo::default() .application_name(app_name) .application_version(0) .engine_name(app_name) @@ -278,11 +278,11 @@ impl VulkanTest { .api_version(vk::make_api_version(0, 1, 3, 0)); let extension_names = - ash_window::enumerate_required_extensions(window.raw_display_handle()) + ash_window::enumerate_required_extensions(window.display_handle().unwrap().as_raw()) .unwrap() .to_vec(); - let create_info = vk::InstanceCreateInfo::builder() + let create_info = vk::InstanceCreateInfo::default() .application_info(&appinfo) .enabled_extension_names(&extension_names); @@ -296,8 +296,8 @@ impl VulkanTest { ash_window::create_surface( &entry, &instance, - window.raw_display_handle(), - window.raw_window_handle(), + window.display_handle().unwrap().as_raw(), + window.window_handle().unwrap().as_raw(), None, ) .unwrap() @@ -308,7 +308,7 @@ impl VulkanTest { .enumerate_physical_devices() .expect("Physical device error") }; - let surface_loader = ash::extensions::khr::Surface::new(&entry, &instance); + let surface_loader = ash::khr::surface::Instance::new(&entry, &instance); let (physical_device, queue_family_index) = unsafe { pdevices .iter() @@ -337,18 +337,18 @@ impl VulkanTest { .expect("Couldn't find suitable device.") }; let queue_family_index = queue_family_index as u32; - let device_extension_names_raw = [ash::extensions::khr::Swapchain::name().as_ptr()]; + let device_extension_names_raw = [ash::khr::swapchain::NAME.as_ptr()]; let priorities = [1.0]; - let queue_info = vk::DeviceQueueCreateInfo::builder() + let queue_info = vk::DeviceQueueCreateInfo::default() .queue_family_index(queue_family_index) .queue_priorities(&priorities); let mut descriptor_indexing_features = - vk::PhysicalDeviceDescriptorIndexingFeatures::builder() + vk::PhysicalDeviceDescriptorIndexingFeatures::default() .descriptor_binding_partially_bound(true); - let device_create_info = vk::DeviceCreateInfo::builder() + let device_create_info = vk::DeviceCreateInfo::default() .queue_create_infos(std::slice::from_ref(&queue_info)) .enabled_extension_names(&device_extension_names_raw) .push_next(&mut descriptor_indexing_features); @@ -395,7 +395,7 @@ impl VulkanTest { .cloned() .find(|&mode| mode == vk::PresentModeKHR::MAILBOX) .unwrap_or(vk::PresentModeKHR::FIFO); - let swapchain_loader = ash::extensions::khr::Swapchain::new(&instance, &device); + let swapchain_loader = ash::khr::swapchain::Device::new(&instance, &device); let swapchain_info = SwapchainInfo::new( swapchain_loader, @@ -429,11 +429,11 @@ impl VulkanTest { ..Default::default() }]; - let subpass = vk::SubpassDescription::builder() + let subpass = vk::SubpassDescription::default() .color_attachments(&color_attachment_refs) .pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS); - let renderpass_create_info = vk::RenderPassCreateInfo::builder() + let renderpass_create_info = vk::RenderPassCreateInfo::default() .attachments(&renderpass_attachments) .subpasses(std::slice::from_ref(&subpass)) .dependencies(&dependencies); @@ -451,13 +451,13 @@ impl VulkanTest { &device, ); - let pool_create_info = vk::CommandPoolCreateInfo::builder() + let pool_create_info = vk::CommandPoolCreateInfo::default() .flags(vk::CommandPoolCreateFlags::RESET_COMMAND_BUFFER) .queue_family_index(queue_family_index); let pool = unsafe { device.create_command_pool(&pool_create_info, None).unwrap() }; - let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::builder() + let command_buffer_allocate_info = vk::CommandBufferAllocateInfo::default() .command_buffer_count(1) .command_pool(pool) .level(vk::CommandBufferLevel::PRIMARY); @@ -470,7 +470,7 @@ impl VulkanTest { let draw_command_buffer = command_buffers[0]; let fence_create_info = - vk::FenceCreateInfo::builder().flags(vk::FenceCreateFlags::SIGNALED); + vk::FenceCreateInfo::default().flags(vk::FenceCreateFlags::SIGNALED); let draw_commands_reuse_fence = unsafe { device @@ -600,7 +600,7 @@ impl VulkanTest { device .begin_command_buffer( self.draw_command_buffer, - &vk::CommandBufferBeginInfo::builder() + &vk::CommandBufferBeginInfo::default() .flags(vk::CommandBufferUsageFlags::ONE_TIME_SUBMIT), ) .unwrap(); @@ -633,7 +633,7 @@ impl VulkanTest { max_depth: 1.0, }]; - let render_pass_begin_info = vk::RenderPassBeginInfo::builder() + let render_pass_begin_info = vk::RenderPassBeginInfo::default() .render_pass(self.render_pass) .framebuffer(self.framebuffers[present_index as usize]) .render_area(self.swapchain_info.surface_resolution.into()) @@ -661,7 +661,7 @@ impl VulkanTest { device.end_command_buffer(self.draw_command_buffer).unwrap(); let swapchains = [self.swapchain]; let image_indices = [present_index]; - let submit_info = vk::SubmitInfo::builder() + let submit_info = vk::SubmitInfo::default() .wait_semaphores(std::slice::from_ref(&self.present_complete_semaphore)) .wait_dst_stage_mask(&[vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]) .command_buffers(std::slice::from_ref(&self.draw_command_buffer)) @@ -677,7 +677,7 @@ impl VulkanTest { match self.swapchain_info.swapchain_loader.queue_present( self.present_queue, - &vk::PresentInfoKHR::builder() + &vk::PresentInfoKHR::default() .image_indices(&image_indices) .wait_semaphores(std::slice::from_ref(&self.rendering_complete_semaphore)) .swapchains(&swapchains), @@ -725,7 +725,7 @@ fn create_swapchain( desired_image_count, } = swapchain_info; - let mut swapchain_create_info = vk::SwapchainCreateInfoKHR::builder() + let mut swapchain_create_info = vk::SwapchainCreateInfoKHR::default() .surface(*surface) .min_image_count(*desired_image_count) .image_color_space(surface_format.color_space) @@ -753,7 +753,7 @@ fn create_swapchain( let present_image_views: Vec = present_images .iter() .map(|&image| { - let create_view_info = vk::ImageViewCreateInfo::builder() + let create_view_info = vk::ImageViewCreateInfo::default() .view_type(vk::ImageViewType::TYPE_2D) .format(surface_format.format) .components(vk::ComponentMapping { @@ -800,7 +800,7 @@ impl Drop for VulkanTest { } struct SwapchainInfo { - pub swapchain_loader: ash::extensions::khr::Swapchain, + pub swapchain_loader: ash::khr::swapchain::Device, pub surface_format: vk::SurfaceFormatKHR, pub surface_resolution: vk::Extent2D, pub present_mode: vk::PresentModeKHR, @@ -810,7 +810,7 @@ struct SwapchainInfo { impl SwapchainInfo { pub fn new( - swapchain_loader: ash::extensions::khr::Swapchain, + swapchain_loader: ash::khr::swapchain::Device, surface_format: vk::SurfaceFormatKHR, surface_resolution: vk::Extent2D, present_mode: vk::PresentModeKHR, @@ -838,7 +838,7 @@ fn create_framebuffers( .iter() .map(|&present_image_view| { let framebuffer_attachments = [present_image_view]; - let frame_buffer_create_info = vk::FramebufferCreateInfo::builder() + let frame_buffer_create_info = vk::FramebufferCreateInfo::default() .render_pass(render_pass) .attachments(&framebuffer_attachments) .width(extent.width) diff --git a/crates/yakui-vulkan/src/buffer.rs b/crates/yakui-vulkan/src/buffer.rs index 99449147..00197c68 100644 --- a/crates/yakui-vulkan/src/buffer.rs +++ b/crates/yakui-vulkan/src/buffer.rs @@ -28,7 +28,7 @@ impl Buffer { let device = vulkan_context.device; let device_memory_properties = &vulkan_context.memory_properties; - let buffer_info = vk::BufferCreateInfo::builder() + let buffer_info = vk::BufferCreateInfo::default() .size(((std::mem::size_of::() * elements) as vk::DeviceSize).max(MIN_BUFFER_SIZE)) .usage(usage) .sharing_mode(vk::SharingMode::EXCLUSIVE); diff --git a/crates/yakui-vulkan/src/descriptors.rs b/crates/yakui-vulkan/src/descriptors.rs index 024f317e..4c84e3c3 100644 --- a/crates/yakui-vulkan/src/descriptors.rs +++ b/crates/yakui-vulkan/src/descriptors.rs @@ -16,7 +16,7 @@ impl Descriptors { let pool = unsafe { device.create_descriptor_pool( - &vk::DescriptorPoolCreateInfo::builder() + &vk::DescriptorPoolCreateInfo::default() .max_sets(1) .pool_sizes(&[vk::DescriptorPoolSize { ty: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, @@ -29,11 +29,11 @@ impl Descriptors { let flags = [vk::DescriptorBindingFlags::PARTIALLY_BOUND]; let mut binding_flags = - vk::DescriptorSetLayoutBindingFlagsCreateInfo::builder().binding_flags(&flags); + vk::DescriptorSetLayoutBindingFlagsCreateInfo::default().binding_flags(&flags); let layout = unsafe { device.create_descriptor_set_layout( - &vk::DescriptorSetLayoutCreateInfo::builder() + &vk::DescriptorSetLayoutCreateInfo::default() .bindings(&[vk::DescriptorSetLayoutBinding { binding: 0, descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER, @@ -49,7 +49,7 @@ impl Descriptors { let set = unsafe { device.allocate_descriptor_sets( - &vk::DescriptorSetAllocateInfo::builder() + &vk::DescriptorSetAllocateInfo::default() .descriptor_pool(pool) .set_layouts(std::slice::from_ref(&layout)), ) @@ -73,9 +73,9 @@ impl Descriptors { let texture_id = self.texture_count; vulkan_context.device.update_descriptor_sets( std::slice::from_ref( - &vk::WriteDescriptorSet::builder() + &vk::WriteDescriptorSet::default() .image_info(std::slice::from_ref( - &vk::DescriptorImageInfo::builder() + &vk::DescriptorImageInfo::default() .sampler(sampler) .image_view(image_view) .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL), diff --git a/crates/yakui-vulkan/src/lib.rs b/crates/yakui-vulkan/src/lib.rs index 7126ec0b..935202e9 100644 --- a/crates/yakui-vulkan/src/lib.rs +++ b/crates/yakui-vulkan/src/lib.rs @@ -161,11 +161,11 @@ impl YakuiVulkan { let vertex_code = read_spv(&mut vertex_spv_file).expect("Failed to read vertex shader spv file"); - let vertex_shader_info = vk::ShaderModuleCreateInfo::builder().code(&vertex_code); + let vertex_shader_info = vk::ShaderModuleCreateInfo::default().code(&vertex_code); let frag_code = read_spv(&mut frag_spv_file).expect("Failed to read fragment shader spv file"); - let frag_shader_info = vk::ShaderModuleCreateInfo::builder().code(&frag_code); + let frag_shader_info = vk::ShaderModuleCreateInfo::default().code(&frag_code); let vertex_shader_module = unsafe { device @@ -182,9 +182,9 @@ impl YakuiVulkan { let pipeline_layout = unsafe { device .create_pipeline_layout( - &vk::PipelineLayoutCreateInfo::builder() + &vk::PipelineLayoutCreateInfo::default() .push_constant_ranges(std::slice::from_ref( - &vk::PushConstantRange::builder() + &vk::PushConstantRange::default() .stage_flags(vk::ShaderStageFlags::FRAGMENT) .size(std::mem::size_of::() as _), )) @@ -240,14 +240,14 @@ impl YakuiVulkan { }, ]; - let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::builder() + let vertex_input_state_info = vk::PipelineVertexInputStateCreateInfo::default() .vertex_attribute_descriptions(&vertex_input_attribute_descriptions) .vertex_binding_descriptions(&vertex_input_binding_descriptions); let vertex_input_assembly_state_info = vk::PipelineInputAssemblyStateCreateInfo { topology: vk::PrimitiveTopology::TRIANGLE_LIST, ..Default::default() }; - let viewport_state_info = vk::PipelineViewportStateCreateInfo::builder() + let viewport_state_info = vk::PipelineViewportStateCreateInfo::default() .scissor_count(1) .viewport_count(1); @@ -287,15 +287,15 @@ impl YakuiVulkan { alpha_blend_op: vk::BlendOp::ADD, color_write_mask: vk::ColorComponentFlags::RGBA, }]; - let color_blend_state = vk::PipelineColorBlendStateCreateInfo::builder() + let color_blend_state = vk::PipelineColorBlendStateCreateInfo::default() .logic_op(vk::LogicOp::CLEAR) .attachments(&color_blend_attachment_states); let dynamic_state = [vk::DynamicState::VIEWPORT, vk::DynamicState::SCISSOR]; let dynamic_state_info = - vk::PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_state); + vk::PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_state); - let mut graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::builder() + let mut graphic_pipeline_info = vk::GraphicsPipelineCreateInfo::default() .stages(&shader_stage_create_infos) .vertex_input_state(&vertex_input_state_info) .input_assembly_state(&vertex_input_assembly_state_info) @@ -315,7 +315,7 @@ impl YakuiVulkan { ); if let Some(format) = options.dynamic_rendering_format { rendering_info_formats = [format]; - rendering_info = vk::PipelineRenderingCreateInfo::builder() + rendering_info = vk::PipelineRenderingCreateInfo::default() .color_attachment_formats(&rendering_info_formats); graphic_pipeline_info = graphic_pipeline_info.push_next(&mut rendering_info); } else { @@ -326,7 +326,7 @@ impl YakuiVulkan { device .create_graphics_pipelines( vk::PipelineCache::null(), - &[graphic_pipeline_info.build()], + &[graphic_pipeline_info], None, ) .expect("Unable to create graphics pipeline") diff --git a/crates/yakui-vulkan/src/vulkan_texture.rs b/crates/yakui-vulkan/src/vulkan_texture.rs index 7c596c96..d0603c27 100644 --- a/crates/yakui-vulkan/src/vulkan_texture.rs +++ b/crates/yakui-vulkan/src/vulkan_texture.rs @@ -65,7 +65,7 @@ impl VulkanTexture { vulkan_context .device .create_sampler( - &vk::SamplerCreateInfo::builder() + &vk::SamplerCreateInfo::default() .address_mode_u(address_mode) .address_mode_v(address_mode) .address_mode_w(address_mode) @@ -111,7 +111,7 @@ impl VulkanTexture { vulkan_context .device .create_sampler( - &vk::SamplerCreateInfo::builder() + &vk::SamplerCreateInfo::default() .address_mode_u(address_mode) .address_mode_v(address_mode) .address_mode_w(address_mode) @@ -186,8 +186,8 @@ pub(crate) struct UploadQueue { phase: UploadPhase, in_flight: VecDeque, textures: Vec<(vk::Image, vk::Extent2D, vk::Buffer, usize)>, - pre_barriers: Vec, - post_barriers: Vec, + pre_barriers: Vec>, + post_barriers: Vec>, } impl UploadQueue {