Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Minimise amount of code behind conditional compilation #2362

Merged
merged 6 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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