mod device; mod entry; mod extensions_generated; mod instance; pubmod prelude; mod tables; pubmod util; /// Raw Vulkan bindings and types, generated from `vk.xml` #[macro_use] pubmod vk;
// macros of vk need to be defined beforehand /// Hand-written ergonomic wrappers for extension functions mod extensions;
impl<'r, T> RawPtr<T> for Option<&'r T> { fn as_raw_ptr(&self) -> *const T { match *self {
Some(inner) => inner,
_ => ::core::ptr::null(),
}
}
}
/// Given a mutable raw pointer to a type with an `s_type` member such as [`vk::BaseOutStructure`], /// match on a set of Vulkan structures. The struct will be rebound to the given variable of the /// type of the given Vulkan structure. /// /// Note that all match bodies have to be enclosed by curly braces due to macro parsing limitations. /// It is unfortunately not possible to write `x @ ash::vk::SomeStruct => one_line_expression(),`. /// /// ``` /// let mut info = ash::vk::DeviceCreateInfo::default(); /// let info: *mut ash::vk::BaseOutStructure = <*mut _>::cast(&mut info); /// unsafe { /// ash::match_out_struct!(match info { /// info @ ash::vk::DeviceQueueCreateInfo => { /// dbg!(&info); // Unreachable /// } /// info @ ash::vk::DeviceCreateInfo => { /// dbg!(&info); /// } /// }) /// } /// ``` /// /// In addition this macro propagates implicit return values just like normal `match` blocks, as /// long as a default value or expression is provided in the "any" match arm /// (`_ => { some_value() }`). For the time being said arm must be wrapped in curly braces; an /// expression like `_ => None` is not yet supported. /// /// ``` /// # let mut info = ash::vk::DeviceCreateInfo::default(); /// # let info: *mut ash::vk::BaseOutStructure = <*mut _>::cast(&mut info); /// let device_create_flags: Option<ash::vk::DeviceCreateFlags> = unsafe { /// ash::match_out_struct!(match info { /// info @ ash::vk::DeviceQueueCreateInfo => { /// dbg!(&info); // Unreachable /// Some(ash::vk::DeviceCreateFlags::empty()) /// } /// info @ ash::vk::DeviceCreateInfo => { /// dbg!(&info); /// Some(info.flags) /// } /// _ => { /// None /// } /// }) /// }; /// ``` #[macro_export]
macro_rules! match_out_struct {
(match $p:ident { $($bind:ident @ $ty:path => $body:block $(,)?)+ $(_ => $any:block $(,)?)? }) => { match core::ptr::addr_of!((*$p).s_type).read() {
$(<$ty as $crate::vk::TaggedStructure>::STRUCTURE_TYPE => { let $bind = $p
.cast::<$ty>()
.as_mut()
.unwrap();
$body
}),+
_ => { $($any)? }
}
};
}
/// Given an immutable raw pointer to a type with an `s_type` member such as [`vk::BaseInStructure`], /// match on a set of Vulkan structures. The struct will be rebound to the given variable of the /// type of the given Vulkan structure. /// /// Note that all match bodies have to be enclosed by curly braces due to macro parsing limitations. /// It is unfortunately not possible to write `x @ ash::vk::SomeStruct => one_line_expression(),`. /// /// ``` /// let info = ash::vk::DeviceCreateInfo::default(); /// let info: *const ash::vk::BaseInStructure = <*const _>::cast(&info); /// unsafe { /// ash::match_in_struct!(match info { /// info @ ash::vk::DeviceQueueCreateInfo => { /// dbg!(&info); // Unreachable /// } /// info @ ash::vk::DeviceCreateInfo => { /// dbg!(&info); /// } /// }) /// } /// ``` /// /// See the [`match_out_struct!`] documentation for an example with implicit return values. #[macro_export]
macro_rules! match_in_struct {
(match $p:ident { $($bind:ident @ $ty:path => $body:block $(,)?)+ $(_ => $any:block $(,)?)? }) => { match core::ptr::addr_of!((*$p).s_type).read() {
$(<$ty as $crate::vk::TaggedStructure>::STRUCTURE_TYPE => { let $bind = $p
.cast::<$ty>()
.as_ref()
.unwrap();
$body
}),+
_ => { $($any)? }
}
};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.