Skip to content

Commit

Permalink
Minimise amount of code behind conditional compilation (#2362)
Browse files Browse the repository at this point in the history
* Minimise amount of code behind conditional compilation

* An additional case

* Copy paste derp

* Fix unreachable warnings

* Typo

* Let's hope this works...
  • Loading branch information
Rua authored Oct 25, 2023
1 parent 94f0f8c commit fa5d127
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 389 deletions.
42 changes: 22 additions & 20 deletions vulkano/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ impl Device {
/// # Safety
///
/// - `file` must be a handle to external memory that was created outside the Vulkan API.
#[cfg_attr(not(unix), allow(unused_variables))]
#[inline]
pub unsafe fn memory_fd_properties(
&self,
Expand Down Expand Up @@ -1009,35 +1008,38 @@ impl Device {
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
#[cfg_attr(not(unix), allow(unused_variables))]
pub unsafe fn memory_fd_properties_unchecked(
&self,
handle_type: ExternalMemoryHandleType,
file: File,
) -> Result<MemoryFdProperties, VulkanError> {
#[cfg(not(unix))]
unreachable!("`khr_external_memory_fd` was somehow enabled on a non-Unix system");
let mut memory_fd_properties = ash::vk::MemoryFdPropertiesKHR::default();

#[cfg(unix)]
{
use std::os::unix::io::IntoRawFd;
let fd = {
use std::os::fd::IntoRawFd;
file.into_raw_fd()
};

let mut memory_fd_properties = ash::vk::MemoryFdPropertiesKHR::default();
#[cfg(not(unix))]
let fd = {
let _ = file;
-1
};

let fns = self.fns();
(fns.khr_external_memory_fd.get_memory_fd_properties_khr)(
self.handle,
handle_type.into(),
file.into_raw_fd(),
&mut memory_fd_properties,
)
.result()
.map_err(VulkanError::from)?;
let fns = self.fns();
(fns.khr_external_memory_fd.get_memory_fd_properties_khr)(
self.handle,
handle_type.into(),
fd,
&mut memory_fd_properties,
)
.result()
.map_err(VulkanError::from)?;

Ok(MemoryFdProperties {
memory_type_bits: memory_fd_properties.memory_type_bits,
})
}
Ok(MemoryFdProperties {
memory_type_bits: memory_fd_properties.memory_type_bits,
})
}

/// Assigns a human-readable name to `object` for debugging purposes.
Expand Down
Loading

0 comments on commit fa5d127

Please # to comment.