Skip to content

Commit fa5d127

Browse files
authored
Minimise amount of code behind conditional compilation (#2362)
* Minimise amount of code behind conditional compilation * An additional case * Copy paste derp * Fix unreachable warnings * Typo * Let's hope this works...
1 parent 94f0f8c commit fa5d127

File tree

4 files changed

+382
-389
lines changed

4 files changed

+382
-389
lines changed

vulkano/src/device/mod.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ impl Device {
965965
/// # Safety
966966
///
967967
/// - `file` must be a handle to external memory that was created outside the Vulkan API.
968-
#[cfg_attr(not(unix), allow(unused_variables))]
969968
#[inline]
970969
pub unsafe fn memory_fd_properties(
971970
&self,
@@ -1009,35 +1008,38 @@ impl Device {
10091008
}
10101009

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

10211018
#[cfg(unix)]
1022-
{
1023-
use std::os::unix::io::IntoRawFd;
1019+
let fd = {
1020+
use std::os::fd::IntoRawFd;
1021+
file.into_raw_fd()
1022+
};
10241023

1025-
let mut memory_fd_properties = ash::vk::MemoryFdPropertiesKHR::default();
1024+
#[cfg(not(unix))]
1025+
let fd = {
1026+
let _ = file;
1027+
-1
1028+
};
10261029

1027-
let fns = self.fns();
1028-
(fns.khr_external_memory_fd.get_memory_fd_properties_khr)(
1029-
self.handle,
1030-
handle_type.into(),
1031-
file.into_raw_fd(),
1032-
&mut memory_fd_properties,
1033-
)
1034-
.result()
1035-
.map_err(VulkanError::from)?;
1030+
let fns = self.fns();
1031+
(fns.khr_external_memory_fd.get_memory_fd_properties_khr)(
1032+
self.handle,
1033+
handle_type.into(),
1034+
fd,
1035+
&mut memory_fd_properties,
1036+
)
1037+
.result()
1038+
.map_err(VulkanError::from)?;
10361039

1037-
Ok(MemoryFdProperties {
1038-
memory_type_bits: memory_fd_properties.memory_type_bits,
1039-
})
1040-
}
1040+
Ok(MemoryFdProperties {
1041+
memory_type_bits: memory_fd_properties.memory_type_bits,
1042+
})
10411043
}
10421044

10431045
/// Assigns a human-readable name to `object` for debugging purposes.

0 commit comments

Comments
 (0)