diff --git a/Cargo.lock b/Cargo.lock index d8115be1..a41e86b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,11 +116,11 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "ash" -version = "0.37.3+1.3.251" +version = "0.38.0+1.3.281" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e9c3835d686b0a6084ab4234fcd1b07dbf6e4767dce60874b12356a25ecd4a" +checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" dependencies = [ - "libloading 0.7.4", + "libloading", ] [[package]] @@ -458,9 +458,9 @@ dependencies = [ [[package]] name = "gpu-alloc-ash" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2424bc9be88170e1a56e57c25d3d0e2dfdd22e8f328e892786aeb4da1415732" +checksum = "cbda7a18a29bc98c2e0de0435c347df935bf59489935d0cbd0b73f1679b6f79a" dependencies = [ "ash", "gpu-alloc-types", @@ -574,7 +574,7 @@ dependencies = [ "jay-algorithms", "jay-config", "jay-toml-config", - "libloading 0.8.1", + "libloading", "log", "num-derive", "num-traits", @@ -645,16 +645,6 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - [[package]] name = "libloading" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 44a50756..3dfaedac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,9 +51,9 @@ chrono = "0.4.33" parking_lot = "0.12.1" arrayvec = "0.7.4" indexmap = "2.2.0" -ash = "0.37.3" +ash = "0.38.0" gpu-alloc = "0.6.0" -gpu-alloc-ash = "0.6.0" +gpu-alloc-ash = "0.7.0" serde = { version = "1.0.196", features = ["derive"] } enum-map = "2.7.3" png = "0.17.13" diff --git a/deploy-notes.md b/deploy-notes.md index 544dc7b5..43046e41 100644 --- a/deploy-notes.md +++ b/deploy-notes.md @@ -1,5 +1,7 @@ # Unreleased +- Needs jay-compositor release. + # 1.4.0 - Needs jay-config release. diff --git a/src/gfx_apis/vulkan/command.rs b/src/gfx_apis/vulkan/command.rs index e45a2374..e3f737a5 100644 --- a/src/gfx_apis/vulkan/command.rs +++ b/src/gfx_apis/vulkan/command.rs @@ -38,7 +38,7 @@ impl Drop for VulkanCommandBuffer { impl VulkanCommandPool { pub fn allocate_buffer(self: &Rc) -> Result, VulkanError> { - let create_info = CommandBufferAllocateInfo::builder() + let create_info = CommandBufferAllocateInfo::default() .command_pool(self.pool) .command_buffer_count(1) .level(CommandBufferLevel::PRIMARY); @@ -54,7 +54,7 @@ impl VulkanCommandPool { impl VulkanDevice { pub fn create_command_pool(self: &Rc) -> Result, VulkanError> { - let info = CommandPoolCreateInfo::builder() + let info = CommandPoolCreateInfo::default() .queue_family_index(self.graphics_queue_idx) .flags( CommandPoolCreateFlags::TRANSIENT | CommandPoolCreateFlags::RESET_COMMAND_BUFFER, diff --git a/src/gfx_apis/vulkan/descriptor.rs b/src/gfx_apis/vulkan/descriptor.rs index 006efa7c..8282a1e8 100644 --- a/src/gfx_apis/vulkan/descriptor.rs +++ b/src/gfx_apis/vulkan/descriptor.rs @@ -29,13 +29,12 @@ impl VulkanDevice { sampler: &Rc, ) -> Result, VulkanError> { let immutable_sampler = [sampler.sampler]; - let binding = DescriptorSetLayoutBinding::builder() + let binding = DescriptorSetLayoutBinding::default() .stage_flags(ShaderStageFlags::FRAGMENT) .immutable_samplers(&immutable_sampler) .descriptor_count(1) - .descriptor_type(DescriptorType::COMBINED_IMAGE_SAMPLER) - .build(); - let create_info = DescriptorSetLayoutCreateInfo::builder() + .descriptor_type(DescriptorType::COMBINED_IMAGE_SAMPLER); + let create_info = DescriptorSetLayoutCreateInfo::default() .bindings(slice::from_ref(&binding)) .flags(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR_KHR); let layout = unsafe { self.device.create_descriptor_set_layout(&create_info, None) }; diff --git a/src/gfx_apis/vulkan/device.rs b/src/gfx_apis/vulkan/device.rs index 1019f29e..78e7f577 100644 --- a/src/gfx_apis/vulkan/device.rs +++ b/src/gfx_apis/vulkan/device.rs @@ -18,14 +18,18 @@ use { ahash::AHashMap, arrayvec::ArrayVec, ash::{ - extensions::khr::{ExternalFenceFd, ExternalMemoryFd, ExternalSemaphoreFd, PushDescriptor}, + ext::{ + external_memory_dma_buf, image_drm_format_modifier, physical_device_drm, + queue_family_foreign, + }, + khr::{ + driver_properties, external_fence_fd, external_memory_fd, external_semaphore_fd, + push_descriptor, + }, vk::{ - DeviceCreateInfo, DeviceQueueCreateInfo, ExtExternalMemoryDmaBufFn, - ExtImageDrmFormatModifierFn, ExtPhysicalDeviceDrmFn, ExtQueueFamilyForeignFn, - ExternalSemaphoreFeatureFlags, ExternalSemaphoreHandleTypeFlags, - ExternalSemaphoreProperties, KhrDriverPropertiesFn, KhrExternalFenceFdFn, - KhrExternalMemoryFdFn, KhrExternalSemaphoreFdFn, KhrPushDescriptorFn, - MemoryPropertyFlags, MemoryType, PhysicalDevice, PhysicalDeviceDriverProperties, + DeviceCreateInfo, DeviceQueueCreateInfo, ExternalSemaphoreFeatureFlags, + ExternalSemaphoreHandleTypeFlags, ExternalSemaphoreProperties, MemoryPropertyFlags, + MemoryType, PhysicalDevice, PhysicalDeviceDriverProperties, PhysicalDeviceDriverPropertiesKHR, PhysicalDeviceDrmPropertiesEXT, PhysicalDeviceDynamicRenderingFeatures, PhysicalDeviceExternalSemaphoreInfo, PhysicalDeviceProperties, PhysicalDeviceProperties2, @@ -49,10 +53,10 @@ pub struct VulkanDevice { pub(super) sync_ctx: Rc, pub(super) instance: Rc, pub(super) device: Device, - pub(super) external_memory_fd: ExternalMemoryFd, - pub(super) external_semaphore_fd: ExternalSemaphoreFd, - pub(super) external_fence_fd: ExternalFenceFd, - pub(super) push_descriptor: PushDescriptor, + pub(super) external_memory_fd: external_memory_fd::Device, + pub(super) external_semaphore_fd: external_semaphore_fd::Device, + pub(super) external_fence_fd: external_fence_fd::Device, + pub(super) push_descriptor: push_descriptor::Device, pub(super) formats: AHashMap, pub(super) memory_types: ArrayVec, pub(super) graphics_queue: Queue, @@ -129,14 +133,14 @@ impl VulkanInstance { continue; } }; - if !extensions.contains_key(ExtPhysicalDeviceDrmFn::name()) { + if !extensions.contains_key(physical_device_drm::NAME) { devices.push((props, Some(extensions), None)); continue; } - let has_driver_props = extensions.contains_key(KhrDriverPropertiesFn::name()); - let mut drm_props = PhysicalDeviceDrmPropertiesEXT::builder().build(); - let mut driver_props = PhysicalDeviceDriverPropertiesKHR::builder().build(); - let mut props2 = PhysicalDeviceProperties2::builder().push_next(&mut drm_props); + let has_driver_props = extensions.contains_key(driver_properties::NAME); + let mut drm_props = PhysicalDeviceDrmPropertiesEXT::default(); + let mut driver_props = PhysicalDeviceDriverPropertiesKHR::default(); + let mut props2 = PhysicalDeviceProperties2::default().push_next(&mut drm_props); if has_driver_props { props2 = props2.push_next(&mut driver_props); } @@ -181,10 +185,9 @@ impl VulkanInstance { } fn supports_semaphore_import(&self, phy_dev: PhysicalDevice) -> bool { - let mut props = ExternalSemaphoreProperties::builder().build(); - let info = PhysicalDeviceExternalSemaphoreInfo::builder() - .handle_type(ExternalSemaphoreHandleTypeFlags::OPAQUE_FD) - .build(); + let mut props = ExternalSemaphoreProperties::default(); + let info = PhysicalDeviceExternalSemaphoreInfo::default() + .handle_type(ExternalSemaphoreHandleTypeFlags::OPAQUE_FD); unsafe { self.instance .get_physical_device_external_semaphore_properties(phy_dev, &info, &mut props); @@ -217,16 +220,15 @@ impl VulkanInstance { .map(|n| n.as_ptr()) .collect(); let mut semaphore_features = - PhysicalDeviceTimelineSemaphoreFeatures::builder().timeline_semaphore(true); + PhysicalDeviceTimelineSemaphoreFeatures::default().timeline_semaphore(true); let mut synchronization2_features = - PhysicalDeviceSynchronization2Features::builder().synchronization2(true); + PhysicalDeviceSynchronization2Features::default().synchronization2(true); let mut dynamic_rendering_features = - PhysicalDeviceDynamicRenderingFeatures::builder().dynamic_rendering(true); - let queue_create_info = DeviceQueueCreateInfo::builder() + PhysicalDeviceDynamicRenderingFeatures::default().dynamic_rendering(true); + let queue_create_info = DeviceQueueCreateInfo::default() .queue_family_index(graphics_queue_idx) - .queue_priorities(&[1.0]) - .build(); - let device_create_info = DeviceCreateInfo::builder() + .queue_priorities(&[1.0]); + let device_create_info = DeviceCreateInfo::default() .push_next(&mut semaphore_features) .push_next(&mut synchronization2_features) .push_next(&mut dynamic_rendering_features) @@ -258,10 +260,10 @@ impl VulkanInstance { return Err(VulkanError::XRGB8888); } destroy_device.forget(); - let external_memory_fd = ExternalMemoryFd::new(&self.instance, &device); - let external_semaphore_fd = ExternalSemaphoreFd::new(&self.instance, &device); - let external_fence_fd = ExternalFenceFd::new(&self.instance, &device); - let push_descriptor = PushDescriptor::new(&self.instance, &device); + let external_memory_fd = external_memory_fd::Device::new(&self.instance, &device); + let external_semaphore_fd = external_semaphore_fd::Device::new(&self.instance, &device); + let external_fence_fd = external_fence_fd::Device::new(&self.instance, &device); + let push_descriptor = push_descriptor::Device::new(&self.instance, &device); let memory_properties = unsafe { self.instance.get_physical_device_memory_properties(phy_dev) }; let memory_types = memory_properties.memory_types @@ -290,13 +292,13 @@ impl VulkanInstance { } const REQUIRED_DEVICE_EXTENSIONS: &[&CStr] = &[ - KhrExternalMemoryFdFn::name(), - KhrExternalSemaphoreFdFn::name(), - KhrExternalFenceFdFn::name(), - ExtExternalMemoryDmaBufFn::name(), - ExtQueueFamilyForeignFn::name(), - ExtImageDrmFormatModifierFn::name(), - KhrPushDescriptorFn::name(), + external_memory_fd::NAME, + external_semaphore_fd::NAME, + external_fence_fd::NAME, + external_memory_dma_buf::NAME, + queue_family_foreign::NAME, + image_drm_format_modifier::NAME, + push_descriptor::NAME, ]; fn log_device( @@ -322,7 +324,7 @@ fn log_device( log::warn!(" device does not support vulkan 1.3"); } if let Some(extensions) = extensions { - if !extensions.contains_key(ExtPhysicalDeviceDrmFn::name()) { + if !extensions.contains_key(physical_device_drm::NAME) { log::warn!(" device does support not the VK_EXT_physical_device_drm extension"); } } diff --git a/src/gfx_apis/vulkan/fence.rs b/src/gfx_apis/vulkan/fence.rs index a971e173..3d833203 100644 --- a/src/gfx_apis/vulkan/fence.rs +++ b/src/gfx_apis/vulkan/fence.rs @@ -27,9 +27,9 @@ impl Drop for VulkanFence { impl VulkanDevice { pub fn create_fence(self: &Rc) -> Result, VulkanError> { let fence = { - let mut export_info = ExportFenceCreateInfo::builder() + let mut export_info = ExportFenceCreateInfo::default() .handle_types(ExternalFenceHandleTypeFlags::SYNC_FD); - let create_info = FenceCreateInfo::builder().push_next(&mut export_info); + let create_info = FenceCreateInfo::default().push_next(&mut export_info); let fence = unsafe { self.device.create_fence(&create_info, None) }; fence.map_err(VulkanError::CreateFence)? }; @@ -42,7 +42,7 @@ impl VulkanDevice { impl VulkanFence { pub fn export_sync_file(&self) -> Result { - let info = FenceGetFdInfoKHR::builder() + let info = FenceGetFdInfoKHR::default() .fence(self.fence) .handle_type(ExternalFenceHandleTypeFlags::SYNC_FD); let res = unsafe { self.device.external_fence_fd.get_fence_fd(&info) }; diff --git a/src/gfx_apis/vulkan/format.rs b/src/gfx_apis/vulkan/format.rs index 98c1c460..7ad829e6 100644 --- a/src/gfx_apis/vulkan/format.rs +++ b/src/gfx_apis/vulkan/format.rs @@ -10,7 +10,7 @@ use { vk::{ DrmFormatModifierPropertiesEXT, DrmFormatModifierPropertiesListEXT, ExternalImageFormatProperties, ExternalMemoryFeatureFlags, - ExternalMemoryHandleTypeFlags, FormatFeatureFlags, FormatProperties2, + ExternalMemoryHandleTypeFlags, FormatFeatureFlags, FormatProperties, FormatProperties2, ImageFormatProperties2, ImageTiling, ImageType, ImageUsageFlags, PhysicalDevice, PhysicalDeviceExternalImageFormatInfo, PhysicalDeviceImageDrmFormatModifierInfoEXT, PhysicalDeviceImageFormatInfo2, SharingMode, @@ -95,10 +95,8 @@ impl VulkanInstance { format: &'static Format, dst: &mut AHashMap, ) -> Result<(), VulkanError> { - let mut modifier_props = DrmFormatModifierPropertiesListEXT::builder().build(); - let mut format_properties = FormatProperties2::builder() - .push_next(&mut modifier_props) - .build(); + let mut modifier_props = DrmFormatModifierPropertiesListEXT::default(); + let mut format_properties = FormatProperties2::default().push_next(&mut modifier_props); unsafe { self.instance.get_physical_device_format_properties2( phy_dev, @@ -106,9 +104,13 @@ impl VulkanInstance { &mut format_properties, ); } - let shm = self.load_shm_format(phy_dev, format, &format_properties)?; - let modifiers = - self.load_drm_format(phy_dev, format, &format_properties, &modifier_props)?; + let shm = self.load_shm_format(phy_dev, format, &format_properties.format_properties)?; + let modifiers = self.load_drm_format( + phy_dev, + format, + &format_properties.format_properties, + &modifier_props, + )?; if shm.is_some() || modifiers.is_not_empty() { dst.insert( format.drm, @@ -126,7 +128,7 @@ impl VulkanInstance { &self, phy_dev: PhysicalDevice, format: &Format, - props: &FormatProperties2, + props: &FormatProperties, ) -> Result, VulkanError> { if format.shm_info.is_none() { return Ok(None); @@ -138,23 +140,19 @@ impl VulkanInstance { &self, phy_dev: PhysicalDevice, format: &Format, - props: &FormatProperties2, + props: &FormatProperties, features: FormatFeatureFlags, usage: ImageUsageFlags, ) -> Result, VulkanError> { - if !props - .format_properties - .optimal_tiling_features - .contains(features) - { + if !props.optimal_tiling_features.contains(features) { return Ok(None); } - let format_info = PhysicalDeviceImageFormatInfo2::builder() + let format_info = PhysicalDeviceImageFormatInfo2::default() .ty(ImageType::TYPE_2D) .format(format.vk_format) .tiling(ImageTiling::OPTIMAL) .usage(usage); - let mut format_properties = ImageFormatProperties2::builder(); + let mut format_properties = ImageFormatProperties2::default(); let res = unsafe { self.instance.get_physical_device_image_format_properties2( phy_dev, @@ -180,7 +178,7 @@ impl VulkanInstance { &self, phy_dev: PhysicalDevice, format: &Format, - internal_format_properties: &FormatProperties2, + internal_format_properties: &FormatProperties, props: &DrmFormatModifierPropertiesListEXT, ) -> Result, VulkanError> { if props.drm_format_modifier_count == 0 { @@ -190,12 +188,9 @@ impl VulkanInstance { DrmFormatModifierPropertiesEXT::default(); props.drm_format_modifier_count as usize ]; - let mut modifier_props = DrmFormatModifierPropertiesListEXT::builder() - .drm_format_modifier_properties(&mut drm_mods) - .build(); - let mut format_properties = FormatProperties2::builder() - .push_next(&mut modifier_props) - .build(); + let mut modifier_props = DrmFormatModifierPropertiesListEXT::default() + .drm_format_modifier_properties(&mut drm_mods); + let mut format_properties = FormatProperties2::default().push_next(&mut modifier_props); unsafe { self.instance.get_physical_device_format_properties2( phy_dev, @@ -245,7 +240,7 @@ impl VulkanInstance { &self, phy_dev: PhysicalDevice, format: &Format, - internal_format_properties: &FormatProperties2, + internal_format_properties: &FormatProperties, modifier: &DrmFormatModifierPropertiesEXT, ) -> Result, VulkanError> { let transfer_dst_max_extents = self.get_max_extents( @@ -291,26 +286,22 @@ impl VulkanInstance { if !props.drm_format_modifier_tiling_features.contains(features) { return Ok(None); } - let mut modifier_info = PhysicalDeviceImageDrmFormatModifierInfoEXT::builder() + let mut modifier_info = PhysicalDeviceImageDrmFormatModifierInfoEXT::default() .drm_format_modifier(props.drm_format_modifier) - .sharing_mode(SharingMode::EXCLUSIVE) - .build(); - let mut external_image_format_info = PhysicalDeviceExternalImageFormatInfo::builder() - .handle_type(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) - .build(); - let image_format_info = PhysicalDeviceImageFormatInfo2::builder() + .sharing_mode(SharingMode::EXCLUSIVE); + let mut external_image_format_info = PhysicalDeviceExternalImageFormatInfo::default() + .handle_type(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT); + let image_format_info = PhysicalDeviceImageFormatInfo2::default() .ty(ImageType::TYPE_2D) .format(format.vk_format) .usage(usage) .tiling(ImageTiling::DRM_FORMAT_MODIFIER_EXT) .push_next(&mut external_image_format_info) - .push_next(&mut modifier_info) - .build(); + .push_next(&mut modifier_info); - let mut external_image_format_props = ExternalImageFormatProperties::builder().build(); - let mut image_format_props = ImageFormatProperties2::builder() - .push_next(&mut external_image_format_props) - .build(); + let mut external_image_format_props = ExternalImageFormatProperties::default(); + let mut image_format_props = + ImageFormatProperties2::default().push_next(&mut external_image_format_props); let res = unsafe { self.instance.get_physical_device_image_format_properties2( @@ -326,6 +317,7 @@ impl VulkanInstance { _ => Err(VulkanError::LoadImageProperties(e)), }; } + let image_format_props = &image_format_props.image_format_properties; let importable = external_image_format_props .external_memory_properties .external_memory_features @@ -335,8 +327,8 @@ impl VulkanInstance { } Ok(Some(VulkanMaxExtents { - width: image_format_props.image_format_properties.max_extent.width, - height: image_format_props.image_format_properties.max_extent.height, + width: image_format_props.max_extent.width, + height: image_format_props.max_extent.height, })) } } diff --git a/src/gfx_apis/vulkan/image.rs b/src/gfx_apis/vulkan/image.rs index 7216498e..bd638574 100644 --- a/src/gfx_apis/vulkan/image.rs +++ b/src/gfx_apis/vulkan/image.rs @@ -17,8 +17,8 @@ use { ImageDrmFormatModifierExplicitCreateInfoEXT, ImageLayout, ImageMemoryRequirementsInfo2, ImagePlaneMemoryRequirementsInfo, ImageSubresourceRange, ImageTiling, ImageType, ImageUsageFlags, ImageView, ImageViewCreateInfo, ImageViewType, ImportMemoryFdInfoKHR, - MemoryAllocateInfo, MemoryDedicatedAllocateInfo, MemoryPropertyFlags, MemoryRequirements2, - SampleCountFlags, SharingMode, SubresourceLayout, + MemoryAllocateInfo, MemoryDedicatedAllocateInfo, MemoryFdPropertiesKHR, + MemoryPropertyFlags, MemoryRequirements2, SampleCountFlags, SharingMode, SubresourceLayout, }, gpu_alloc::UsageFlags, std::{ @@ -165,7 +165,7 @@ impl VulkanDevice { format: &'static Format, for_rendering: bool, ) -> Result { - let create_info = ImageViewCreateInfo::builder() + let create_info = ImageViewCreateInfo::default() .image(image) .view_type(ImageViewType::TYPE_2D) .format(format.vk_format) @@ -222,13 +222,11 @@ impl VulkanDmaBufImageTemplate { depth_pitch: 0, }) .collect(); - let mut mod_info = ImageDrmFormatModifierExplicitCreateInfoEXT::builder() + let mut mod_info = ImageDrmFormatModifierExplicitCreateInfoEXT::default() .drm_format_modifier(self.dmabuf.modifier) - .plane_layouts(&plane_layouts) - .build(); - let mut memory_image_create_info = ExternalMemoryImageCreateInfo::builder() - .handle_types(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) - .build(); + .plane_layouts(&plane_layouts); + let mut memory_image_create_info = ExternalMemoryImageCreateInfo::default() + .handle_types(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT); let flags = match self.disjoint { true => ImageCreateFlags::DISJOINT, false => ImageCreateFlags::empty(), @@ -240,7 +238,7 @@ impl VulkanDmaBufImageTemplate { }, false => ImageUsageFlags::TRANSFER_SRC | ImageUsageFlags::SAMPLED, }; - let create_info = ImageCreateInfo::builder() + let create_info = ImageCreateInfo::default() .image_type(ImageType::TYPE_2D) .format(self.dmabuf.format.vk_format) .mip_levels(1) @@ -257,8 +255,7 @@ impl VulkanDmaBufImageTemplate { .usage(usage) .flags(flags) .push_next(&mut memory_image_create_info) - .push_next(&mut mod_info) - .build(); + .push_next(&mut mod_info); let image = unsafe { device.device.create_image(&create_info, None) }; image.map_err(VulkanError::CreateImage)? }; @@ -272,16 +269,19 @@ impl VulkanDmaBufImageTemplate { let mut bind_image_plane_memory_infos = PlaneVec::new(); for plane_idx in 0..num_device_memories { let dma_buf_plane = &self.dmabuf.planes[plane_idx]; - let memory_fd_properties = unsafe { - device.external_memory_fd.get_memory_fd_properties( - ExternalMemoryHandleTypeFlags::DMA_BUF_EXT, - dma_buf_plane.fd.raw(), - ) - }; - let memory_fd_properties = - memory_fd_properties.map_err(VulkanError::MemoryFdProperties)?; + let mut memory_fd_properties = MemoryFdPropertiesKHR::default(); + unsafe { + device + .external_memory_fd + .get_memory_fd_properties( + ExternalMemoryHandleTypeFlags::DMA_BUF_EXT, + dma_buf_plane.fd.raw(), + &mut memory_fd_properties, + ) + .map_err(VulkanError::MemoryFdProperties)?; + } let mut image_memory_requirements_info = - ImageMemoryRequirementsInfo2::builder().image(image); + ImageMemoryRequirementsInfo2::default().image(image); let mut image_plane_memory_requirements_info; if self.disjoint { let plane_aspect = match plane_idx { @@ -292,14 +292,11 @@ impl VulkanDmaBufImageTemplate { _ => unreachable!(), }; image_plane_memory_requirements_info = - ImagePlaneMemoryRequirementsInfo::builder().plane_aspect(plane_aspect); + ImagePlaneMemoryRequirementsInfo::default().plane_aspect(plane_aspect); image_memory_requirements_info = image_memory_requirements_info .push_next(&mut image_plane_memory_requirements_info); - bind_image_plane_memory_infos.push( - BindImagePlaneMemoryInfo::builder() - .plane_aspect(plane_aspect) - .build(), - ); + bind_image_plane_memory_infos + .push(BindImagePlaneMemoryInfo::default().plane_aspect(plane_aspect)); } let mut memory_requirements = MemoryRequirements2::default(); unsafe { @@ -318,17 +315,15 @@ impl VulkanDmaBufImageTemplate { let fd = uapi::fcntl_dupfd_cloexec(dma_buf_plane.fd.raw(), 0) .map_err(|e| VulkanError::Dupfd(e.into()))?; let mut memory_dedicated_allocate_info = - MemoryDedicatedAllocateInfo::builder().image(image).build(); - let mut import_memory_fd_info = ImportMemoryFdInfoKHR::builder() + MemoryDedicatedAllocateInfo::default().image(image); + let mut import_memory_fd_info = ImportMemoryFdInfoKHR::default() .fd(fd.raw()) - .handle_type(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) - .build(); - let memory_allocate_info = MemoryAllocateInfo::builder() + .handle_type(ExternalMemoryHandleTypeFlags::DMA_BUF_EXT); + let memory_allocate_info = MemoryAllocateInfo::default() .allocation_size(memory_requirements.memory_requirements.size) .memory_type_index(memory_type_index) .push_next(&mut import_memory_fd_info) - .push_next(&mut memory_dedicated_allocate_info) - .build(); + .push_next(&mut memory_dedicated_allocate_info); let device_memory = unsafe { device.device.allocate_memory(&memory_allocate_info, None) }; let device_memory = device_memory.map_err(VulkanError::AllocateMemory)?; @@ -339,12 +334,13 @@ impl VulkanDmaBufImageTemplate { })); } let mut bind_image_memory_infos = Vec::with_capacity(num_device_memories); - for (i, mem) in device_memories.iter().copied().enumerate() { - let mut info = BindImageMemoryInfo::builder().image(image).memory(mem); + let mut bind_image_plane_memory_infos = bind_image_plane_memory_infos.iter_mut(); + for mem in device_memories.iter().copied() { + let mut info = BindImageMemoryInfo::default().image(image).memory(mem); if self.disjoint { - info = info.push_next(&mut bind_image_plane_memory_infos[i]); + info = info.push_next(bind_image_plane_memory_infos.next().unwrap()); } - bind_image_memory_infos.push(info.build()); + bind_image_memory_infos.push(info); } let res = unsafe { device.device.bind_image_memory2(&bind_image_memory_infos) }; res.map_err(VulkanError::BindImageMemory)?; @@ -387,7 +383,7 @@ impl VulkanDmaBufImageTemplate { } fn create_bridge(&self) -> Result<(Image, VulkanAllocation), VulkanError> { - let create_info = ImageCreateInfo::builder() + let create_info = ImageCreateInfo::default() .image_type(ImageType::TYPE_2D) .format(self.dmabuf.format.vk_format) .mip_levels(1) @@ -401,8 +397,7 @@ impl VulkanDmaBufImageTemplate { height: self.height, depth: 1, }) - .usage(ImageUsageFlags::COLOR_ATTACHMENT | ImageUsageFlags::TRANSFER_SRC) - .build(); + .usage(ImageUsageFlags::COLOR_ATTACHMENT | ImageUsageFlags::TRANSFER_SRC); let image = unsafe { self.renderer.device.device.create_image(&create_info, None) }; let image = image.map_err(VulkanError::CreateImage)?; let destroy_image = diff --git a/src/gfx_apis/vulkan/instance.rs b/src/gfx_apis/vulkan/instance.rs index 56985968..f68a99fa 100644 --- a/src/gfx_apis/vulkan/instance.rs +++ b/src/gfx_apis/vulkan/instance.rs @@ -6,14 +6,13 @@ use { }, ahash::{AHashMap, AHashSet}, ash::{ - extensions::ext::DebugUtils, + ext::{debug_utils, validation_features}, vk::{ api_version_major, api_version_minor, api_version_patch, api_version_variant, ApplicationInfo, Bool32, DebugUtilsMessageSeverityFlagsEXT, DebugUtilsMessageTypeFlagsEXT, DebugUtilsMessengerCallbackDataEXT, - DebugUtilsMessengerCreateInfoEXT, DebugUtilsMessengerEXT, ExtDebugUtilsFn, - ExtValidationFeaturesFn, ExtensionProperties, InstanceCreateInfo, LayerProperties, - ValidationFeaturesEXT, API_VERSION_1_3, FALSE, + DebugUtilsMessengerCreateInfoEXT, DebugUtilsMessengerEXT, ExtensionProperties, + InstanceCreateInfo, LayerProperties, ValidationFeaturesEXT, API_VERSION_1_3, FALSE, }, Entry, Instance, LoadingError, }, @@ -34,7 +33,7 @@ use { pub struct VulkanInstance { pub(super) _entry: &'static Entry, pub(super) instance: Instance, - pub(super) debug_utils: DebugUtils, + pub(super) debug_utils: debug_utils::Instance, pub(super) messenger: DebugUtilsMessengerEXT, pub(super) eng: Rc, pub(super) ring: Rc, @@ -62,7 +61,7 @@ impl VulkanInstance { .iter() .map(|c| c.as_ptr()) .collect(); - let app_info = ApplicationInfo::builder() + let app_info = ApplicationInfo::default() .api_version(API_VERSION) .application_name(ustr!("jay").as_c_str().unwrap()) .application_version(1); @@ -77,7 +76,7 @@ impl VulkanInstance { | DebugUtilsMessageTypeFlagsEXT::VALIDATION | DebugUtilsMessageTypeFlagsEXT::PERFORMANCE | DebugUtilsMessageTypeFlagsEXT::GENERAL; - let mut debug_info = DebugUtilsMessengerCreateInfoEXT::builder() + let mut debug_info = DebugUtilsMessengerCreateInfoEXT::default() .message_severity(severity) .message_type(types) .pfn_user_callback(Some(debug_callback)); @@ -88,8 +87,8 @@ impl VulkanInstance { // ash::vk::ValidationFeatureEnableEXT::GPU_ASSISTED, ]; let mut validation_info = - ValidationFeaturesEXT::builder().enabled_validation_features(&validation_features); - let mut create_info = InstanceCreateInfo::builder() + ValidationFeaturesEXT::default().enabled_validation_features(&validation_features); + let mut create_info = InstanceCreateInfo::default() .application_info(&app_info) .push_next(&mut debug_info); let validation_layer_name = VALIDATION_LAYER.as_ptr(); @@ -98,11 +97,11 @@ impl VulkanInstance { create_info = create_info.enabled_layer_names(slice::from_ref(&validation_layer_name)); let extensions = get_instance_extensions(entry, Some(VALIDATION_LAYER))?; - if extensions.contains_key(ExtValidationFeaturesFn::name()) { - enabled_extensions.push(ExtValidationFeaturesFn::name().as_ptr()); + if extensions.contains_key(validation_features::NAME) { + enabled_extensions.push(validation_features::NAME.as_ptr()); create_info = create_info.push_next(&mut validation_info); } else { - log::warn!("{:?} is not available", ExtValidationFeaturesFn::name(),); + log::warn!("{:?} is not available", validation_features::NAME); } } else { log::warn!( @@ -116,7 +115,7 @@ impl VulkanInstance { Err(e) => return Err(VulkanError::CreateInstance(e)), }; let destroy_instance = OnDrop(|| unsafe { instance.destroy_instance(None) }); - let debug_utils = DebugUtils::new(entry, &instance); + let debug_utils = debug_utils::Instance::new(entry, &instance); let messenger = unsafe { debug_utils.create_debug_utils_messenger(&debug_info, None) }; let messenger = match messenger { Ok(m) => m, @@ -144,24 +143,28 @@ impl Drop for VulkanInstance { } } -const REQUIRED_INSTANCE_EXTENSIONS: &[&CStr] = &[ExtDebugUtilsFn::name()]; +const REQUIRED_INSTANCE_EXTENSIONS: &[&CStr] = &[debug_utils::NAME]; const VALIDATION_LAYER: &CStr = c"VK_LAYER_KHRONOS_validation"; pub type Extensions = AHashMap; fn get_instance_extensions(entry: &Entry, layer: Option<&CStr>) -> Result { - entry - .enumerate_instance_extension_properties(layer) - .map_err(VulkanError::InstanceExtensions) - .map(map_extension_properties) + unsafe { + entry + .enumerate_instance_extension_properties(layer) + .map_err(VulkanError::InstanceExtensions) + .map(map_extension_properties) + } } fn get_available_layers(entry: &Entry) -> Result, VulkanError> { - entry - .enumerate_instance_layer_properties() - .map_err(VulkanError::InstanceLayers) - .map(map_layer_properties) + unsafe { + entry + .enumerate_instance_layer_properties() + .map_err(VulkanError::InstanceLayers) + .map(map_layer_properties) + } } fn map_layer_properties(props: Vec) -> AHashSet { diff --git a/src/gfx_apis/vulkan/pipeline.rs b/src/gfx_apis/vulkan/pipeline.rs index cd309581..e5701cae 100644 --- a/src/gfx_apis/vulkan/pipeline.rs +++ b/src/gfx_apis/vulkan/pipeline.rs @@ -56,21 +56,19 @@ impl VulkanDevice { let mut push_constant_offset = 0; if vert_push_size > 0 { push_constant_ranges.push( - PushConstantRange::builder() + PushConstantRange::default() .stage_flags(ShaderStageFlags::VERTEX) .offset(0) - .size(vert_push_size) - .build(), + .size(vert_push_size), ); push_constant_offset += vert_push_size; } if frag_push_size > 0 { push_constant_ranges.push( - PushConstantRange::builder() + PushConstantRange::default() .stage_flags(ShaderStageFlags::FRAGMENT) .offset(push_constant_offset) - .size(frag_push_size) - .build(), + .size(frag_push_size), ); #[allow(unused_assignments)] { @@ -80,7 +78,7 @@ impl VulkanDevice { let mut descriptor_set_layouts = ArrayVec::<_, 1>::new(); descriptor_set_layouts .extend(info.frag_descriptor_set_layout.as_ref().map(|l| l.layout)); - let create_info = PipelineLayoutCreateInfo::builder() + let create_info = PipelineLayoutCreateInfo::default() .push_constant_ranges(&push_constant_ranges) .set_layouts(&descriptor_set_layouts); let layout = unsafe { self.device.create_pipeline_layout(&create_info, None) }; @@ -91,29 +89,27 @@ impl VulkanDevice { let pipeline = { let main = ustr!("main").as_c_str().unwrap(); let stages = [ - PipelineShaderStageCreateInfo::builder() + PipelineShaderStageCreateInfo::default() .stage(ShaderStageFlags::VERTEX) .module(info.vert.module) - .name(main) - .build(), - PipelineShaderStageCreateInfo::builder() + .name(main), + PipelineShaderStageCreateInfo::default() .stage(ShaderStageFlags::FRAGMENT) .module(info.frag.module) - .name(main) - .build(), + .name(main), ]; - let input_assembly_state = PipelineInputAssemblyStateCreateInfo::builder() + let input_assembly_state = PipelineInputAssemblyStateCreateInfo::default() .topology(PrimitiveTopology::TRIANGLE_STRIP); - let vertex_input_state = PipelineVertexInputStateCreateInfo::builder(); - let rasterization_state = PipelineRasterizationStateCreateInfo::builder() + let vertex_input_state = PipelineVertexInputStateCreateInfo::default(); + let rasterization_state = PipelineRasterizationStateCreateInfo::default() .polygon_mode(PolygonMode::FILL) .cull_mode(CullModeFlags::NONE) .line_width(1.0) .front_face(FrontFace::COUNTER_CLOCKWISE); - let multisampling_state = PipelineMultisampleStateCreateInfo::builder() + let multisampling_state = PipelineMultisampleStateCreateInfo::default() .sample_shading_enable(false) .rasterization_samples(SampleCountFlags::TYPE_1); - let mut blending = PipelineColorBlendAttachmentState::builder() + let mut blending = PipelineColorBlendAttachmentState::default() .color_write_mask(ColorComponentFlags::RGBA); if info.alpha { blending = blending @@ -125,17 +121,17 @@ impl VulkanDevice { .dst_alpha_blend_factor(BlendFactor::ONE_MINUS_SRC_ALPHA) .alpha_blend_op(BlendOp::ADD); } - let color_blend_state = PipelineColorBlendStateCreateInfo::builder() + let color_blend_state = PipelineColorBlendStateCreateInfo::default() .attachments(slice::from_ref(&blending)); let dynamic_states = [DynamicState::VIEWPORT, DynamicState::SCISSOR]; let dynamic_state = - PipelineDynamicStateCreateInfo::builder().dynamic_states(&dynamic_states); - let viewport_state = PipelineViewportStateCreateInfo::builder() + PipelineDynamicStateCreateInfo::default().dynamic_states(&dynamic_states); + let viewport_state = PipelineViewportStateCreateInfo::default() .viewport_count(1) .scissor_count(1); - let mut pipeline_rendering_create_info = PipelineRenderingCreateInfo::builder() + let mut pipeline_rendering_create_info = PipelineRenderingCreateInfo::default() .color_attachment_formats(slice::from_ref(&ARGB8888.vk_format)); - let create_info = GraphicsPipelineCreateInfo::builder() + let create_info = GraphicsPipelineCreateInfo::default() .push_next(&mut pipeline_rendering_create_info) .stages(&stages) .input_assembly_state(&input_assembly_state) diff --git a/src/gfx_apis/vulkan/renderer.rs b/src/gfx_apis/vulkan/renderer.rs index 3a478ebe..df7c9fa8 100644 --- a/src/gfx_apis/vulkan/renderer.rs +++ b/src/gfx_apis/vulkan/renderer.rs @@ -34,10 +34,10 @@ use { CommandBufferBeginInfo, CommandBufferSubmitInfo, CommandBufferUsageFlags, CopyImageInfo2, DependencyInfo, DependencyInfoKHR, DescriptorImageInfo, DescriptorType, Extent2D, Extent3D, Fence, ImageAspectFlags, ImageCopy2, ImageLayout, - ImageMemoryBarrier2, ImageMemoryBarrier2Builder, ImageSubresourceLayers, - ImageSubresourceRange, PipelineBindPoint, PipelineStageFlags2, Rect2D, - RenderingAttachmentInfo, RenderingInfo, SemaphoreSubmitInfo, SemaphoreSubmitInfoKHR, - ShaderStageFlags, SubmitInfo2, Viewport, WriteDescriptorSet, QUEUE_FAMILY_FOREIGN_EXT, + ImageMemoryBarrier2, ImageSubresourceLayers, ImageSubresourceRange, PipelineBindPoint, + PipelineStageFlags2, Rect2D, RenderingAttachmentInfo, RenderingInfo, + SemaphoreSubmitInfo, SemaphoreSubmitInfoKHR, ShaderStageFlags, SubmitInfo2, Viewport, + WriteDescriptorSet, QUEUE_FAMILY_FOREIGN_EXT, }, Device, }, @@ -93,9 +93,9 @@ pub(super) enum TexSourceType { pub(super) struct Memory { sample: Vec>, textures: Vec, - image_barriers: Vec, + image_barriers: Vec>, wait_semaphores: Vec>, - wait_semaphore_infos: Vec, + wait_semaphore_infos: Vec>, release_fence: Option>, release_sync_file: Option, } @@ -226,7 +226,7 @@ impl VulkanRenderer { fn begin_command_buffer(&self, buf: CommandBuffer) -> Result<(), VulkanError> { let begin_info = - CommandBufferBeginInfo::builder().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); + CommandBufferBeginInfo::default().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); unsafe { self.device .device @@ -265,7 +265,6 @@ impl VulkanRenderer { ImageLayout::GENERAL }); } - let fb_image_memory_barrier = fb_image_memory_barrier.build(); memory.image_barriers.push(fb_image_memory_barrier); for img in &memory.sample { let image_memory_barrier = image_barrier() @@ -275,11 +274,10 @@ impl VulkanRenderer { .old_layout(ImageLayout::GENERAL) .new_layout(ImageLayout::SHADER_READ_ONLY_OPTIMAL) .dst_access_mask(AccessFlags2::SHADER_SAMPLED_READ) - .dst_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER) - .build(); + .dst_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER); memory.image_barriers.push(image_memory_barrier); } - let dep_info = DependencyInfoKHR::builder().image_memory_barriers(&memory.image_barriers); + let dep_info = DependencyInfoKHR::default().image_memory_barriers(&memory.image_barriers); unsafe { self.device.device.cmd_pipeline_barrier2(buf, &dep_info); } @@ -287,7 +285,7 @@ impl VulkanRenderer { fn begin_rendering(&self, buf: CommandBuffer, fb: &VulkanImage, clear: Option<&Color>) { let rendering_attachment_info = { - let mut rai = RenderingAttachmentInfo::builder() + let mut rai = RenderingAttachmentInfo::default() .image_view(fb.render_view.unwrap_or(fb.texture_view)) .image_layout(ImageLayout::GENERAL) .load_op(AttachmentLoadOp::LOAD) @@ -303,7 +301,7 @@ impl VulkanRenderer { } rai }; - let rendering_info = RenderingInfo::builder() + let rendering_info = RenderingInfo::default() .render_area(Rect2D { offset: Default::default(), extent: Extent2D { @@ -400,13 +398,12 @@ impl VulkanRenderer { pos: c.target.to_points(), tex_pos: c.source.to_points(), }; - let image_info = DescriptorImageInfo::builder() + let image_info = DescriptorImageInfo::default() .image_view(tex.texture_view) .image_layout(ImageLayout::SHADER_READ_ONLY_OPTIMAL); - let write_descriptor_set = WriteDescriptorSet::builder() + let write_descriptor_set = WriteDescriptorSet::default() .descriptor_type(DescriptorType::COMBINED_IMAGE_SAMPLER) - .image_info(slice::from_ref(&image_info)) - .build(); + .image_info(slice::from_ref(&image_info)); unsafe { self.device.push_descriptor.cmd_push_descriptor_set( buf, @@ -462,8 +459,7 @@ impl VulkanRenderer { ) .src_stage_mask(PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT) .dst_access_mask(AccessFlags2::TRANSFER_READ) - .dst_stage_mask(PipelineStageFlags2::TRANSFER) - .build(); + .dst_stage_mask(PipelineStageFlags2::TRANSFER); memory.image_barriers.push(bridge_image_memory_barrier); let dmabuf_image_memory_barrier = image_barrier() .src_queue_family_index(QUEUE_FAMILY_FOREIGN_EXT) @@ -476,35 +472,31 @@ impl VulkanRenderer { }) .new_layout(ImageLayout::TRANSFER_DST_OPTIMAL) .dst_access_mask(AccessFlags2::TRANSFER_WRITE) - .dst_stage_mask(PipelineStageFlags2::TRANSFER) - .build(); + .dst_stage_mask(PipelineStageFlags2::TRANSFER); memory.image_barriers.push(dmabuf_image_memory_barrier); - let dep_info = DependencyInfoKHR::builder().image_memory_barriers(&memory.image_barriers); + let dep_info = DependencyInfoKHR::default().image_memory_barriers(&memory.image_barriers); unsafe { self.device.device.cmd_pipeline_barrier2(buf, &dep_info); } - let image_subresource_layers = ImageSubresourceLayers::builder() + let image_subresource_layers = ImageSubresourceLayers::default() .aspect_mask(ImageAspectFlags::COLOR) .layer_count(1) .base_array_layer(0) - .mip_level(0) - .build(); - let image_copy = ImageCopy2::builder() + .mip_level(0); + let image_copy = ImageCopy2::default() .src_subresource(image_subresource_layers) .dst_subresource(image_subresource_layers) .extent(Extent3D { width: fb.width, height: fb.height, depth: 1, - }) - .build(); - let copy_image_info = CopyImageInfo2::builder() + }); + let copy_image_info = CopyImageInfo2::default() .src_image(fb.image) .src_image_layout(ImageLayout::TRANSFER_SRC_OPTIMAL) .dst_image(bridge.dmabuf_image) .dst_image_layout(ImageLayout::TRANSFER_DST_OPTIMAL) - .regions(slice::from_ref(&image_copy)) - .build(); + .regions(slice::from_ref(&image_copy)); unsafe { self.device.device.cmd_copy_image2(buf, ©_image_info); } @@ -533,7 +525,6 @@ impl VulkanRenderer { ) .src_stage_mask(PipelineStageFlags2::COLOR_ATTACHMENT_OUTPUT); } - let fb_image_memory_barrier = fb_image_memory_barrier.build(); memory.image_barriers.push(fb_image_memory_barrier); for img in &memory.sample { let image_memory_barrier = image_barrier() @@ -543,11 +534,10 @@ impl VulkanRenderer { .new_layout(ImageLayout::GENERAL) .image(img.image) .src_access_mask(AccessFlags2::SHADER_SAMPLED_READ) - .src_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER) - .build(); + .src_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER); memory.image_barriers.push(image_memory_barrier); } - let dep_info = DependencyInfoKHR::builder().image_memory_barriers(&memory.image_barriers); + let dep_info = DependencyInfoKHR::default().image_memory_barriers(&memory.image_barriers); unsafe { self.device.device.cmd_pipeline_barrier2(buf, &dep_info); } @@ -577,10 +567,9 @@ impl VulkanRenderer { let semaphore = self.allocate_semaphore()?; semaphore.import_sync_file(fd)?; infos.push( - SemaphoreSubmitInfo::builder() + SemaphoreSubmitInfo::default() .semaphore(semaphore.semaphore) - .stage_mask(PipelineStageFlags2::TOP_OF_PIPE) - .build(), + .stage_mask(PipelineStageFlags2::TOP_OF_PIPE), ); semaphores.push(semaphore); Ok(()) @@ -659,13 +648,10 @@ impl VulkanRenderer { fn submit(&self, buf: CommandBuffer) -> Result<(), VulkanError> { let mut memory = self.memory.borrow_mut(); let release_fence = self.device.create_fence()?; - let command_buffer_info = CommandBufferSubmitInfo::builder() - .command_buffer(buf) - .build(); - let submit_info = SubmitInfo2::builder() + let command_buffer_info = CommandBufferSubmitInfo::default().command_buffer(buf); + let submit_info = SubmitInfo2::default() .wait_semaphore_infos(&memory.wait_semaphore_infos) - .command_buffer_infos(slice::from_ref(&command_buffer_info)) - .build(); + .command_buffer_infos(slice::from_ref(&command_buffer_info)); unsafe { self.device .device @@ -776,7 +762,7 @@ impl VulkanRenderer { if size != dst.len() as u64 { return Err(VulkanError::InvalidBufferSize); } - let region = BufferImageCopy::builder() + let region = BufferImageCopy::default() .buffer_row_length(stride / shm_info.bpp) .buffer_image_height(tex.height) .image_subresource(ImageSubresourceLayers { @@ -789,17 +775,16 @@ impl VulkanRenderer { width: tex.width, height: tex.height, depth: 1, - }) - .build(); + }); let staging = self.create_staging_buffer(size, false, true, true)?; let initial_tex_barrier; - let initial_buffer_barrier = BufferMemoryBarrier2::builder() + let initial_buffer_barrier = BufferMemoryBarrier2::default() .buffer(staging.buffer) .offset(0) .size(staging.size) .dst_access_mask(AccessFlags2::TRANSFER_WRITE) .dst_stage_mask(PipelineStageFlags2::TRANSFER); - let mut initial_barriers = DependencyInfo::builder() + let mut initial_barriers = DependencyInfo::default() .buffer_memory_barriers(slice::from_ref(&initial_buffer_barrier)); if tex.bridge.is_none() { initial_tex_barrier = image_barrier() @@ -814,7 +799,7 @@ impl VulkanRenderer { initial_barriers.image_memory_barriers(slice::from_ref(&initial_tex_barrier)); } let final_tex_barrier; - let final_buffer_barrier = BufferMemoryBarrier2::builder() + let final_buffer_barrier = BufferMemoryBarrier2::default() .buffer(staging.buffer) .offset(0) .size(staging.size) @@ -822,7 +807,7 @@ impl VulkanRenderer { .src_stage_mask(PipelineStageFlags2::TRANSFER) .dst_access_mask(AccessFlags2::HOST_READ) .dst_stage_mask(PipelineStageFlags2::HOST); - let mut final_barriers = DependencyInfo::builder() + let mut final_barriers = DependencyInfo::default() .buffer_memory_barriers(slice::from_ref(&final_buffer_barrier)); if tex.bridge.is_none() { final_tex_barrier = image_barrier() @@ -845,20 +830,19 @@ impl VulkanRenderer { .map_err(VulkanError::IoctlExportSyncFile)?; let semaphore = self.allocate_semaphore()?; semaphore.import_sync_file(fd)?; - let semaphore_info = SemaphoreSubmitInfo::builder() + let semaphore_info = SemaphoreSubmitInfo::default() .semaphore(semaphore.semaphore) - .stage_mask(PipelineStageFlags2::TOP_OF_PIPE) - .build(); + .stage_mask(PipelineStageFlags2::TOP_OF_PIPE); semaphores.push(semaphore); semaphore_infos.push(semaphore_info); } } - let command_buffer_info = CommandBufferSubmitInfo::builder().command_buffer(buf.buffer); - let submit_info = SubmitInfo2::builder() + let command_buffer_info = CommandBufferSubmitInfo::default().command_buffer(buf.buffer); + let submit_info = SubmitInfo2::default() .wait_semaphore_infos(&semaphore_infos) .command_buffer_infos(slice::from_ref(&command_buffer_info)); let begin_info = - CommandBufferBeginInfo::builder().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); + CommandBufferBeginInfo::default().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); unsafe { self.device .device @@ -1023,13 +1007,12 @@ impl dyn GfxTexture { } } -pub(super) fn image_barrier() -> ImageMemoryBarrier2Builder<'static> { - ImageMemoryBarrier2::builder().subresource_range( - ImageSubresourceRange::builder() +pub(super) fn image_barrier() -> ImageMemoryBarrier2<'static> { + ImageMemoryBarrier2::default().subresource_range( + ImageSubresourceRange::default() .aspect_mask(ImageAspectFlags::COLOR) .layer_count(1) - .level_count(1) - .build(), + .level_count(1), ) } diff --git a/src/gfx_apis/vulkan/sampler.rs b/src/gfx_apis/vulkan/sampler.rs index dd6d9a53..c7630da1 100644 --- a/src/gfx_apis/vulkan/sampler.rs +++ b/src/gfx_apis/vulkan/sampler.rs @@ -13,7 +13,7 @@ pub struct VulkanSampler { impl VulkanDevice { pub(super) fn create_sampler(self: &Rc) -> Result, VulkanError> { - let create_info = SamplerCreateInfo::builder() + let create_info = SamplerCreateInfo::default() .mag_filter(Filter::LINEAR) .min_filter(Filter::LINEAR) .mipmap_mode(SamplerMipmapMode::NEAREST) diff --git a/src/gfx_apis/vulkan/semaphore.rs b/src/gfx_apis/vulkan/semaphore.rs index 0e25b801..aeee83ec 100644 --- a/src/gfx_apis/vulkan/semaphore.rs +++ b/src/gfx_apis/vulkan/semaphore.rs @@ -24,7 +24,7 @@ impl Drop for VulkanSemaphore { impl VulkanDevice { pub fn create_semaphore(self: &Rc) -> Result, VulkanError> { let sem = { - let create_info = SemaphoreCreateInfo::builder(); + let create_info = SemaphoreCreateInfo::default(); let sem = unsafe { self.device.create_semaphore(&create_info, None) }; sem.map_err(VulkanError::CreateSemaphore)? }; @@ -37,7 +37,7 @@ impl VulkanDevice { impl VulkanSemaphore { pub fn import_sync_file(&self, sync_file: OwnedFd) -> Result<(), VulkanError> { - let fd_info = ImportSemaphoreFdInfoKHR::builder() + let fd_info = ImportSemaphoreFdInfoKHR::default() .fd(sync_file.raw()) .flags(SemaphoreImportFlags::TEMPORARY) .handle_type(ExternalSemaphoreHandleTypeFlags::SYNC_FD) diff --git a/src/gfx_apis/vulkan/shaders.rs b/src/gfx_apis/vulkan/shaders.rs index 2ded4418..f32948b3 100644 --- a/src/gfx_apis/vulkan/shaders.rs +++ b/src/gfx_apis/vulkan/shaders.rs @@ -57,7 +57,7 @@ impl VulkanDevice { src: &[u8], ) -> Result, VulkanError> { let src: Vec = uapi::pod_iter(src).unwrap().collect(); - let create_info = ShaderModuleCreateInfo::builder().code(&src); + let create_info = ShaderModuleCreateInfo::default().code(&src); let module = unsafe { self.device.create_shader_module(&create_info, None) }; module .map_err(VulkanError::CreateShaderModule) diff --git a/src/gfx_apis/vulkan/shm_image.rs b/src/gfx_apis/vulkan/shm_image.rs index c280d4ac..d2a8666c 100644 --- a/src/gfx_apis/vulkan/shm_image.rs +++ b/src/gfx_apis/vulkan/shm_image.rs @@ -48,7 +48,7 @@ impl VulkanShmImage { } } let copy = |full: bool, off, x, y, width, height| { - let mut builder = BufferImageCopy2::builder() + let mut builder = BufferImageCopy2::default() .buffer_offset(off) .image_offset(Offset3D { x, y, z: 0 }) .image_extent(Extent3D { @@ -67,7 +67,7 @@ impl VulkanShmImage { .buffer_image_height(img.height) .buffer_row_length(img.stride / self.shm_info.bpp); } - builder.build() + builder }; let mut total_size; let cpy_one; @@ -130,7 +130,7 @@ impl VulkanShmImage { } })?; let memory_barrier = |sam, ssm, dam, dsm| { - BufferMemoryBarrier2::builder() + BufferMemoryBarrier2::default() .buffer(staging.buffer) .offset(0) .size(staging.size) @@ -138,7 +138,6 @@ impl VulkanShmImage { .src_stage_mask(ssm) .dst_access_mask(dam) .dst_stage_mask(dsm) - .build() }; let initial_image_barrier = image_barrier() .image(img.image) @@ -151,15 +150,14 @@ impl VulkanShmImage { }) .new_layout(ImageLayout::TRANSFER_DST_OPTIMAL) .dst_access_mask(AccessFlags2::TRANSFER_WRITE) - .dst_stage_mask(PipelineStageFlags2::TRANSFER) - .build(); + .dst_stage_mask(PipelineStageFlags2::TRANSFER); let initial_buffer_barrier = memory_barrier( AccessFlags2::HOST_WRITE, PipelineStageFlags2::HOST, AccessFlags2::TRANSFER_READ, PipelineStageFlags2::TRANSFER, ); - let initial_dep_info = DependencyInfoKHR::builder() + let initial_dep_info = DependencyInfoKHR::default() .buffer_memory_barriers(slice::from_ref(&initial_buffer_barrier)) .image_memory_barriers(slice::from_ref(&initial_image_barrier)); let final_image_barrier = image_barrier() @@ -169,29 +167,28 @@ impl VulkanShmImage { .old_layout(ImageLayout::TRANSFER_DST_OPTIMAL) .new_layout(ImageLayout::SHADER_READ_ONLY_OPTIMAL) .dst_access_mask(AccessFlags2::SHADER_SAMPLED_READ) - .dst_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER) - .build(); + .dst_stage_mask(PipelineStageFlags2::FRAGMENT_SHADER); let final_buffer_barrier = memory_barrier( AccessFlags2::TRANSFER_READ, PipelineStageFlags2::TRANSFER, AccessFlags2::HOST_WRITE, PipelineStageFlags2::HOST, ); - let final_dep_info = DependencyInfoKHR::builder() + let final_dep_info = DependencyInfoKHR::default() .buffer_memory_barriers(slice::from_ref(&final_buffer_barrier)) .image_memory_barriers(slice::from_ref(&final_image_barrier)); - let cpy_info = CopyBufferToImageInfo2::builder() + let cpy_info = CopyBufferToImageInfo2::default() .src_buffer(staging.buffer) .dst_image(img.image) .dst_image_layout(ImageLayout::TRANSFER_DST_OPTIMAL) .regions(cpy); let cmd = img.renderer.allocate_command_buffer()?; let dev = &img.renderer.device.device; - let command_buffer_info = CommandBufferSubmitInfo::builder().command_buffer(cmd.buffer); + let command_buffer_info = CommandBufferSubmitInfo::default().command_buffer(cmd.buffer); let submit_info = - SubmitInfo2::builder().command_buffer_infos(slice::from_ref(&command_buffer_info)); + SubmitInfo2::default().command_buffer_infos(slice::from_ref(&command_buffer_info)); let begin_info = - CommandBufferBeginInfo::builder().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); + CommandBufferBeginInfo::default().flags(CommandBufferUsageFlags::ONE_TIME_SUBMIT); let release_fence = img.renderer.device.create_fence()?; unsafe { dev.begin_command_buffer(cmd.buffer, &begin_info) @@ -294,7 +291,7 @@ impl VulkanRenderer { true => ImageUsageFlags::COLOR_ATTACHMENT, false => ImageUsageFlags::SAMPLED | ImageUsageFlags::TRANSFER_DST, }; - let create_info = ImageCreateInfo::builder() + let create_info = ImageCreateInfo::default() .image_type(ImageType::TYPE_2D) .format(format.vk_format) .mip_levels(1) @@ -308,8 +305,7 @@ impl VulkanRenderer { height, depth: 1, }) - .usage(usage) - .build(); + .usage(usage); let image = unsafe { self.device.device.create_image(&create_info, None) }; let image = image.map_err(VulkanError::CreateImage)?; let destroy_image = OnDrop(|| unsafe { self.device.device.destroy_image(image, None) }); @@ -324,7 +320,7 @@ impl VulkanRenderer { .bind_image_memory(image, allocation.memory, allocation.offset) }; res.map_err(VulkanError::BindImageMemory)?; - let image_view_create_info = ImageViewCreateInfo::builder() + let image_view_create_info = ImageViewCreateInfo::default() .image(image) .format(format.vk_format) .view_type(ImageViewType::TYPE_2D) diff --git a/src/gfx_apis/vulkan/staging.rs b/src/gfx_apis/vulkan/staging.rs index cdf4a2c6..d74d0c19 100644 --- a/src/gfx_apis/vulkan/staging.rs +++ b/src/gfx_apis/vulkan/staging.rs @@ -37,7 +37,7 @@ impl VulkanRenderer { usage |= UsageFlags::TRANSIENT; } let buffer = { - let create_info = BufferCreateInfo::builder().size(size).usage(vk_usage); + let create_info = BufferCreateInfo::default().size(size).usage(vk_usage); let buffer = unsafe { self.device.device.create_buffer(&create_info, None) }; buffer.map_err(VulkanError::CreateBuffer)? }; @@ -86,11 +86,10 @@ impl VulkanStagingBuffer { fn range(&self) -> MappedMemoryRange { let atom_mask = self.allocation.allocator.non_coherent_atom_mask; - MappedMemoryRange::builder() + MappedMemoryRange::default() .memory(self.allocation.memory) .offset(self.allocation.offset & !atom_mask) .size((self.allocation.size + atom_mask) & !atom_mask) - .build() } }