Replace version macros with const fns

This commit is contained in:
Benjamin Saunders 2019-10-05 11:02:58 -07:00
parent 9838cf9566
commit 4e8090f0bb
5 changed files with 23 additions and 53 deletions

View file

@ -181,13 +181,11 @@ pub trait EntryV1_1: EntryV1_0 {
impl EntryCustom<Arc<DynamicLibrary>> {
/// ```rust,no_run
/// # #[macro_use]
/// # extern crate ash;
/// use ash::{vk, Entry, version::EntryV1_0};
/// # fn main() -> Result<(), Box<std::error::Error>> {
/// let entry = Entry::new()?;
/// let app_info = vk::ApplicationInfo {
/// api_version: vk_make_version!(1, 0, 0),
/// api_version: vk::make_version(1, 0, 0),
/// ..Default::default()
/// };
/// let create_info = vk::InstanceCreateInfo {
@ -240,17 +238,15 @@ impl<L> EntryCustom<L> {
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkEnumerateInstanceVersion.html>"]
/// ```rust,no_run
/// # #[macro_use]
/// # extern crate ash;
/// # use ash::Entry;
/// # use ash::{Entry, vk};
/// # fn main() -> Result<(), Box<std::error::Error>> {
/// let entry = Entry::new()?;
/// match entry.try_enumerate_instance_version()? {
/// // Vulkan 1.1+
/// Some(version) => {
/// let major = vk_version_major!(version);
/// let minor = vk_version_minor!(version);
/// let patch = vk_version_patch!(version);
/// let major = vk::version_major(version);
/// let minor = vk::version_minor(version);
/// let patch = vk::version_patch(version);
/// },
/// // Vulkan 1.0
/// None => {},

View file

@ -5,13 +5,11 @@
//! ## Examples
//!
//! ```rust,no_run
//! # #[macro_use]
//! # extern crate ash;
//! use ash::{vk, Entry, version::EntryV1_0};
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let entry = Entry::new()?;
//! let app_info = vk::ApplicationInfo {
//! api_version: vk_make_version!(1, 0, 0),
//! api_version: vk::make_version(1, 0, 0),
//! ..Default::default()
//! };
//! let create_info = vk::InstanceCreateInfo {

View file

@ -21,32 +21,20 @@ pub trait Handle {
fn from_raw(_: u64) -> Self;
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_MAKE_VERSION.html>"]
#[macro_export]
macro_rules! vk_make_version {
( $ major : expr , $ minor : expr , $ patch : expr ) => {
(($major as u32) << 22) | (($minor as u32) << 12) | $patch as u32
};
pub const fn make_version(major: u32, minor: u32, patch: u32) -> u32 {
(major << 22) | (minor << 12) | patch
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_MAJOR.html>"]
#[macro_export]
macro_rules! vk_version_major {
( $ major : expr ) => {
($major as u32) >> 22
};
pub const fn version_major(version: u32) -> u32 {
version >> 22
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_MINOR.html>"]
#[macro_export]
macro_rules! vk_version_minor {
( $ minor : expr ) => {
(($minor as u32) >> 12) & 0x3ff
};
pub const fn version_minor(version: u32) -> u32 {
(version >> 12) & 0x3ff
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_PATCH.html>"]
#[macro_export]
macro_rules! vk_version_patch {
( $ minor : expr ) => {
($minor as u32) & 0xfff
};
pub const fn version_patch(version: u32) -> u32 {
version & 0xfff
}
pub type RROutput = c_ulong;
pub type VisualID = c_uint;

View file

@ -340,7 +340,7 @@ impl ExampleBase {
.application_version(0)
.engine_name(&app_name)
.engine_version(0)
.api_version(vk_make_version!(1, 0, 0));
.api_version(vk::make_version(1, 0, 0));
let create_info = vk::InstanceCreateInfo::builder()
.application_info(&appinfo)

View file

@ -185,35 +185,23 @@ pub fn handle_nondispatchable_macro() -> Tokens {
pub fn vk_version_macros() -> Tokens {
quote! {
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_MAKE_VERSION.html>"]
#[macro_export]
macro_rules! vk_make_version {
($major:expr, $minor:expr, $patch:expr) => {
(($major as u32) << 22) | (($minor as u32) << 12) | $patch as u32
};
pub const fn make_version(major: u32, minor: u32, patch: u32) -> u32 {
(major << 22) | (minor << 12) | patch
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_MAJOR.html>"]
#[macro_export]
macro_rules! vk_version_major {
($major:expr) => {
($major as u32) >> 22
};
pub const fn version_major(version: u32) -> u32 {
version >> 22
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_MINOR.html>"]
#[macro_export]
macro_rules! vk_version_minor {
($minor:expr) => {
(($minor as u32) >> 12) & 0x3ff
};
pub const fn version_minor(version: u32) -> u32 {
(version >> 12) & 0x3ff
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VK_VERSION_PATCH.html>"]
#[macro_export]
macro_rules! vk_version_patch {
($minor:expr) => {
($minor as u32) & 0xfff
};
pub const fn version_patch(version: u32) -> u32 {
version & 0xfff
}
}
}