From e34f755ecec699d708aebcb65b4a01052b9b87ed Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 21 Dec 2021 15:21:49 -0800 Subject: [PATCH] Move debug_flags definition out of the generator --- ash/src/extensions/experimental/amd.rs | 2 ++ ash/src/prelude.rs | 28 ++++++++++++++++++++++++++ ash/src/vk.rs | 1 - ash/src/vk/const_debugs.rs | 27 +------------------------ generator/src/lib.rs | 28 +------------------------- 5 files changed, 32 insertions(+), 54 deletions(-) diff --git a/ash/src/extensions/experimental/amd.rs b/ash/src/extensions/experimental/amd.rs index 6de41bc..33f9fde 100644 --- a/ash/src/extensions/experimental/amd.rs +++ b/ash/src/extensions/experimental/amd.rs @@ -25,7 +25,9 @@ * **********************************************************************************************************************/ +use crate::prelude::debug_flags; use crate::vk::*; + use std::fmt; use std::os::raw::*; diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs index d497e5d..cc00b22 100644 --- a/ash/src/prelude.rs +++ b/ash/src/prelude.rs @@ -1,4 +1,5 @@ use std::convert::TryInto; +use std::fmt; use crate::vk; pub type VkResult = Result; @@ -81,3 +82,30 @@ where } } } + +pub(crate) fn debug_flags + Copy>( + f: &mut fmt::Formatter, + known: &[(Value, &'static str)], + value: Value, +) -> fmt::Result { + let mut first = true; + let mut accum = value.into(); + for &(bit, name) in known { + let bit = bit.into(); + if bit != 0 && accum & bit == bit { + if !first { + f.write_str(" | ")?; + } + f.write_str(name)?; + first = false; + accum &= !bit; + } + } + if accum != 0 { + if !first { + f.write_str(" | ")?; + } + write!(f, "{:b}", accum)?; + } + Ok(()) +} diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 31697d9..1358af8 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -11,7 +11,6 @@ pub use aliases::*; mod bitflags; pub use bitflags::*; mod const_debugs; -pub(crate) use const_debugs::*; mod constants; pub use constants::*; mod definitions; diff --git a/ash/src/vk/const_debugs.rs b/ash/src/vk/const_debugs.rs index 93be0d5..14f8056 100644 --- a/ash/src/vk/const_debugs.rs +++ b/ash/src/vk/const_debugs.rs @@ -1,33 +1,8 @@ +use crate::prelude::debug_flags; use crate::vk::bitflags::*; use crate::vk::definitions::*; use crate::vk::enums::*; use std::fmt; -pub(crate) fn debug_flags + Copy>( - f: &mut fmt::Formatter, - known: &[(Value, &'static str)], - value: Value, -) -> fmt::Result { - let mut first = true; - let mut accum = value.into(); - for &(bit, name) in known { - let bit = bit.into(); - if bit != 0 && accum & bit == bit { - if !first { - f.write_str(" | ")?; - } - f.write_str(name)?; - first = false; - accum &= !bit; - } - } - if accum != 0 { - if !first { - f.write_str(" | ")?; - } - write!(f, "{:b}", accum)?; - } - Ok(()) -} impl fmt::Debug for AccelerationStructureBuildTypeKHR { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match *self { diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 06a03be..ec6d61e 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -2461,33 +2461,6 @@ pub fn generate_const_debugs(const_values: &BTreeMap) - } }); quote! { - pub(crate) fn debug_flags + Copy>( - f: &mut fmt::Formatter, - known: &[(Value, &'static str)], - value: Value, - ) -> fmt::Result { - let mut first = true; - let mut accum = value.into(); - for &(bit, name) in known { - let bit = bit.into(); - if bit != 0 && accum & bit == bit { - if !first { - f.write_str(" | ")?; - } - f.write_str(name)?; - first = false; - accum &= !bit; - } - } - if accum != 0 { - if !first { - f.write_str(" | ")?; - } - write!(f, "{:b}", accum)?; - } - Ok(()) - } - #(#impls)* } } @@ -2823,6 +2796,7 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { use crate::vk::bitflags::*; use crate::vk::definitions::*; use crate::vk::enums::*; + use crate::prelude::debug_flags; #const_debugs };