diff --git a/ash/src/vk/const_debugs.rs b/ash/src/vk/const_debugs.rs index 2298522..a767228 100644 --- a/ash/src/vk/const_debugs.rs +++ b/ash/src/vk/const_debugs.rs @@ -2350,7 +2350,12 @@ impl fmt::Debug for PeerMemoryFeatureFlags { } impl fmt::Debug for PerformanceConfigurationTypeINTEL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let name = match * self { Self :: PERFORMANCE_CONFIGURATION_TYPE_COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED_INTEL => Some ("PERFORMANCE_CONFIGURATION_TYPE_COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED_INTEL") , _ => None , } ; + let name = match *self { + Self::COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED => { + Some("COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED") + } + _ => None, + }; if let Some(x) = name { f.write_str(x) } else { @@ -2432,12 +2437,8 @@ impl fmt::Debug for PerformanceCounterUnitKHR { impl fmt::Debug for PerformanceOverrideTypeINTEL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match *self { - Self::PERFORMANCE_OVERRIDE_TYPE_NULL_HARDWARE_INTEL => { - Some("PERFORMANCE_OVERRIDE_TYPE_NULL_HARDWARE_INTEL") - } - Self::PERFORMANCE_OVERRIDE_TYPE_FLUSH_GPU_CACHES_INTEL => { - Some("PERFORMANCE_OVERRIDE_TYPE_FLUSH_GPU_CACHES_INTEL") - } + Self::NULL_HARDWARE => Some("NULL_HARDWARE"), + Self::FLUSH_GPU_CACHES => Some("FLUSH_GPU_CACHES"), _ => None, }; if let Some(x) = name { @@ -2450,12 +2451,8 @@ impl fmt::Debug for PerformanceOverrideTypeINTEL { impl fmt::Debug for PerformanceParameterTypeINTEL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match *self { - Self::PERFORMANCE_PARAMETER_TYPE_HW_COUNTERS_SUPPORTED_INTEL => { - Some("PERFORMANCE_PARAMETER_TYPE_HW_COUNTERS_SUPPORTED_INTEL") - } - Self::PERFORMANCE_PARAMETER_TYPE_STREAM_MARKER_VALIDS_INTEL => { - Some("PERFORMANCE_PARAMETER_TYPE_STREAM_MARKER_VALIDS_INTEL") - } + Self::HW_COUNTERS_SUPPORTED => Some("HW_COUNTERS_SUPPORTED"), + Self::STREAM_MARKER_VALIDS => Some("STREAM_MARKER_VALIDS"), _ => None, }; if let Some(x) = name { @@ -2468,17 +2465,11 @@ impl fmt::Debug for PerformanceParameterTypeINTEL { impl fmt::Debug for PerformanceValueTypeINTEL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match *self { - Self::PERFORMANCE_VALUE_TYPE_UINT32_INTEL => { - Some("PERFORMANCE_VALUE_TYPE_UINT32_INTEL") - } - Self::PERFORMANCE_VALUE_TYPE_UINT64_INTEL => { - Some("PERFORMANCE_VALUE_TYPE_UINT64_INTEL") - } - Self::PERFORMANCE_VALUE_TYPE_FLOAT_INTEL => Some("PERFORMANCE_VALUE_TYPE_FLOAT_INTEL"), - Self::PERFORMANCE_VALUE_TYPE_BOOL_INTEL => Some("PERFORMANCE_VALUE_TYPE_BOOL_INTEL"), - Self::PERFORMANCE_VALUE_TYPE_STRING_INTEL => { - Some("PERFORMANCE_VALUE_TYPE_STRING_INTEL") - } + Self::UINT32 => Some("UINT32"), + Self::UINT64 => Some("UINT64"), + Self::FLOAT => Some("FLOAT"), + Self::BOOL => Some("BOOL"), + Self::STRING => Some("STRING"), _ => None, }; if let Some(x) = name { @@ -3000,9 +2991,7 @@ impl fmt::Debug for QueryPoolCreateFlags { impl fmt::Debug for QueryPoolSamplingModeINTEL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let name = match *self { - Self::QUERY_POOL_SAMPLING_MODE_MANUAL_INTEL => { - Some("QUERY_POOL_SAMPLING_MODE_MANUAL_INTEL") - } + Self::MANUAL => Some("MANUAL"), _ => None, }; if let Some(x) = name { diff --git a/ash/src/vk/enums.rs b/ash/src/vk/enums.rs index e5510b2..3ec0991 100644 --- a/ash/src/vk/enums.rs +++ b/ash/src/vk/enums.rs @@ -2004,8 +2004,7 @@ impl PerformanceConfigurationTypeINTEL { } } impl PerformanceConfigurationTypeINTEL { - pub const PERFORMANCE_CONFIGURATION_TYPE_COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED_INTEL: Self = - Self(0); + pub const COMMAND_QUEUE_METRICS_DISCOVERY_ACTIVATED: Self = Self(0); } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] @@ -2020,7 +2019,7 @@ impl QueryPoolSamplingModeINTEL { } } impl QueryPoolSamplingModeINTEL { - pub const QUERY_POOL_SAMPLING_MODE_MANUAL_INTEL: Self = Self(0); + pub const MANUAL: Self = Self(0); } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] @@ -2035,8 +2034,8 @@ impl PerformanceOverrideTypeINTEL { } } impl PerformanceOverrideTypeINTEL { - pub const PERFORMANCE_OVERRIDE_TYPE_NULL_HARDWARE_INTEL: Self = Self(0); - pub const PERFORMANCE_OVERRIDE_TYPE_FLUSH_GPU_CACHES_INTEL: Self = Self(1); + pub const NULL_HARDWARE: Self = Self(0); + pub const FLUSH_GPU_CACHES: Self = Self(1); } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] @@ -2051,8 +2050,8 @@ impl PerformanceParameterTypeINTEL { } } impl PerformanceParameterTypeINTEL { - pub const PERFORMANCE_PARAMETER_TYPE_HW_COUNTERS_SUPPORTED_INTEL: Self = Self(0); - pub const PERFORMANCE_PARAMETER_TYPE_STREAM_MARKER_VALIDS_INTEL: Self = Self(1); + pub const HW_COUNTERS_SUPPORTED: Self = Self(0); + pub const STREAM_MARKER_VALIDS: Self = Self(1); } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] @@ -2067,11 +2066,11 @@ impl PerformanceValueTypeINTEL { } } impl PerformanceValueTypeINTEL { - pub const PERFORMANCE_VALUE_TYPE_UINT32_INTEL: Self = Self(0); - pub const PERFORMANCE_VALUE_TYPE_UINT64_INTEL: Self = Self(1); - pub const PERFORMANCE_VALUE_TYPE_FLOAT_INTEL: Self = Self(2); - pub const PERFORMANCE_VALUE_TYPE_BOOL_INTEL: Self = Self(3); - pub const PERFORMANCE_VALUE_TYPE_STRING_INTEL: Self = Self(4); + pub const UINT32: Self = Self(0); + pub const UINT64: Self = Self(1); + pub const FLOAT: Self = Self(2); + pub const BOOL: Self = Self(3); + pub const STRING: Self = Self(4); } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] diff --git a/generator/src/lib.rs b/generator/src/lib.rs index bb0fe15..0b96eb0 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -1318,13 +1318,28 @@ pub enum EnumType { Enum(TokenStream), } +fn is_enum_variant_with_typo(variant_name: &str) -> bool { + // All these names are aliases and make little sense in our + // enum structure, they are better omitted entirely. + matches!( + variant_name, + "VK_STENCIL_FRONT_AND_BACK" + | "VK_COLORSPACE_SRGB_NONLINEAR" + | "VK_QUERY_SCOPE_COMMAND_BUFFER" + | "VK_QUERY_SCOPE_RENDER_PASS" + | "VK_QUERY_SCOPE_COMMAND" + ) +} + pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident { let variant_name = variant_name.to_uppercase(); let _name = enum_name.replace("FlagBits", ""); // TODO: Should be read from vk.xml id:2 // TODO: Also needs to be more robust, vendor names can be substrings from itself, id:4 // like NVX and NV - let vendors = ["_NVX", "_KHR", "_EXT", "_NV", "_AMD", "_ANDROID", "_GOOGLE"]; + let vendors = [ + "_NVX", "_KHR", "_EXT", "_NV", "_AMD", "_ANDROID", "_GOOGLE", "_INTEL", + ]; let struct_name = _name.to_shouty_snake_case(); let vendor = vendors .iter() @@ -1332,14 +1347,23 @@ pub fn variant_ident(enum_name: &str, variant_name: &str) -> Ident { .cloned() .unwrap_or(""); let struct_name = struct_name.strip_suffix(vendor).unwrap(); - let new_variant_name = variant_name - .strip_prefix(struct_name) - .unwrap_or_else(|| variant_name.strip_prefix("VK").unwrap()); + let variant_name = variant_name + .strip_suffix(vendor) + .unwrap_or_else(|| variant_name.as_str()); + + let new_variant_name = variant_name.strip_prefix(struct_name).unwrap_or_else(|| { + if enum_name == "VkResult" || is_enum_variant_with_typo(variant_name) { + variant_name.strip_prefix("VK").unwrap() + } else { + panic!( + "Failed to strip {} prefix from enum variant {}", + struct_name, variant_name + ) + } + }); + // Both of the above strip_prefix leave a leading `_`: let new_variant_name = new_variant_name.strip_prefix("_").unwrap(); - let new_variant_name = new_variant_name - .strip_suffix(vendor) - .unwrap_or(new_variant_name); // Replace _BIT anywhere in the string, also works when there's a trailing // vendor extension in the variant name that's not in the enum/type name: let new_variant_name = new_variant_name.replace("_BIT", "");