diff --git a/ash/src/entry.rs b/ash/src/entry.rs index f5393de..b349612 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -181,13 +181,11 @@ pub trait EntryV1_1: EntryV1_0 { impl EntryCustom> { /// ```rust,no_run - /// # #[macro_use] - /// # extern crate ash; /// use ash::{vk, Entry, version::EntryV1_0}; /// # fn main() -> Result<(), Box> { /// 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 EntryCustom { #[doc = ""] /// ```rust,no_run - /// # #[macro_use] - /// # extern crate ash; - /// # use ash::Entry; + /// # use ash::{Entry, vk}; /// # fn main() -> Result<(), Box> { /// 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 => {}, diff --git a/ash/src/lib.rs b/ash/src/lib.rs index caa2ad3..d887a37 100644 --- a/ash/src/lib.rs +++ b/ash/src/lib.rs @@ -5,13 +5,11 @@ //! ## Examples //! //! ```rust,no_run -//! # #[macro_use] -//! # extern crate ash; //! use ash::{vk, Entry, version::EntryV1_0}; //! # fn main() -> Result<(), Box> { //! 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 { diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 711b0e4..95bb663 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -21,32 +21,20 @@ pub trait Handle { fn from_raw(_: u64) -> Self; } #[doc = ""] -#[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 = ""] -#[macro_export] -macro_rules! vk_version_major { - ( $ major : expr ) => { - ($major as u32) >> 22 - }; +pub const fn version_major(version: u32) -> u32 { + version >> 22 } #[doc = ""] -#[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 = ""] -#[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; diff --git a/ash/tests/constant_size_arrays.rs b/ash/tests/constant_size_arrays.rs index c546027..c58cd5e 100644 --- a/ash/tests/constant_size_arrays.rs +++ b/ash/tests/constant_size_arrays.rs @@ -27,15 +27,10 @@ fn assert_struct_field_is_array() { #[allow(dead_code)] fn assert_ffi_array_param_is_pointer() { use ash::version::DeviceV1_0; - unsafe { - // don't run it, just make sure it compiles - if false { - let device: ash::Device = std::mem::zeroed(); - let cmd_buffer = std::mem::zeroed(); + // don't run it, just make sure it compiles + unsafe fn dummy(device: &ash::Device, cmd_buffer: ash::vk::CommandBuffer) { + let blend_constants: [f32; 4] = [0.0, 0.0, 0.0, 0.0]; - let blend_constants: [f32; 4] = [0.0, 0.0, 0.0, 0.0]; - - device.cmd_set_blend_constants(cmd_buffer, &blend_constants); - } + device.cmd_set_blend_constants(cmd_buffer, &blend_constants); } } diff --git a/examples/src/lib.rs b/examples/src/lib.rs index fb43a4d..d06508a 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -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) diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 9c0587b..f713ef0 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -185,35 +185,23 @@ pub fn handle_nondispatchable_macro() -> Tokens { pub fn vk_version_macros() -> Tokens { quote! { #[doc = ""] - #[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 = ""] - #[macro_export] - macro_rules! vk_version_major { - ($major:expr) => { - ($major as u32) >> 22 - }; + pub const fn version_major(version: u32) -> u32 { + version >> 22 } #[doc = ""] - #[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 = ""] - #[macro_export] - macro_rules! vk_version_patch { - ($minor:expr) => { - ($minor as u32) & 0xfff - }; + pub const fn version_patch(version: u32) -> u32 { + version & 0xfff } } }