From 45301fffa41760463e8ce77a14f755a740e99528 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 21 Dec 2021 15:43:48 -0800 Subject: [PATCH] Optional flag/bitfield Debug impls --- ash/src/extensions/experimental/amd.rs | 38 ++++++--- ash/src/prelude.rs | 2 + ash/src/vk.rs | 1 + ash/src/vk/const_debugs.rs | 114 ------------------------- ash/src/vk/enums.rs | 114 +++++++++++++++++++++++++ generator/src/lib.rs | 36 ++++++-- 6 files changed, 172 insertions(+), 133 deletions(-) diff --git a/ash/src/extensions/experimental/amd.rs b/ash/src/extensions/experimental/amd.rs index 33f9fde..c39c5a7 100644 --- a/ash/src/extensions/experimental/amd.rs +++ b/ash/src/extensions/experimental/amd.rs @@ -25,6 +25,7 @@ * **********************************************************************************************************************/ +#[cfg(feature = "debug")] use crate::prelude::debug_flags; use crate::vk::*; @@ -37,6 +38,7 @@ use std::os::raw::*; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct GpaSqShaderStageFlags(pub(crate) Flags); vk_bitflags_wrapped!(GpaSqShaderStageFlags, Flags); +#[cfg(feature = "debug")] impl fmt::Debug for GpaSqShaderStageFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { const KNOWN: &[(Flags, &str)] = &[ @@ -69,7 +71,8 @@ impl StructureType { pub const GPA_DEVICE_CLOCK_MODE_INFO_AMD: Self = Self(1000133004); } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[repr(transparent)] pub struct GpaDeviceClockModeAmd(pub(crate) i32); impl GpaDeviceClockModeAmd { @@ -89,7 +92,8 @@ impl GpaDeviceClockModeAmd { pub const PEAK: Self = Self(5); } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[repr(transparent)] pub struct GpaPerfBlockAmd(pub(crate) i32); impl GpaPerfBlockAmd { @@ -135,7 +139,8 @@ impl GpaPerfBlockAmd { pub const RMI: Self = Self(31); } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[cfg_attr(feature = "debug", derive(Debug))] #[repr(transparent)] pub struct GpaSampleTypeAmd(pub(crate) i32); impl GpaSampleTypeAmd { @@ -155,7 +160,8 @@ impl GpaSampleTypeAmd { handle_nondispatchable!(GpaSessionAmd, UNKNOWN); #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct GpaSessionCreateInfoAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -163,7 +169,8 @@ pub struct GpaSessionCreateInfoAmd { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct GpaPerfBlockPropertiesAmd { pub block_type: GpaPerfBlockAmd, pub flags: Flags, @@ -175,7 +182,8 @@ pub struct GpaPerfBlockPropertiesAmd { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct PhysicalDeviceGpaFeaturesAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -186,7 +194,8 @@ pub struct PhysicalDeviceGpaFeaturesAmd { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct PhysicalDeviceGpaPropertiesAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -244,7 +253,8 @@ impl<'a> PhysicalDeviceGpaPropertiesAmdBuilder<'a> { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct GpaPerfCounterAmd { pub block_type: GpaPerfBlockAmd, pub block_instance: u32, @@ -252,7 +262,8 @@ pub struct GpaPerfCounterAmd { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct GpaSampleBeginInfoAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -273,7 +284,8 @@ pub struct GpaSampleBeginInfoAmd { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct GpaDeviceClockModeInfoAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -632,7 +644,8 @@ impl StructureType { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct PhysicalDeviceWaveLimitPropertiesAmd { pub s_type: StructureType, pub p_next: *const c_void, @@ -692,7 +705,8 @@ impl<'a> PhysicalDeviceWaveLimitPropertiesAmdBuilder<'a> { } #[repr(C)] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] +#[cfg_attr(feature = "debug", derive(Debug))] pub struct PipelineShaderStageCreateInfoWaveLimitAmd { pub s_type: StructureType, pub p_next: *const c_void, diff --git a/ash/src/prelude.rs b/ash/src/prelude.rs index cc00b22..2a29c39 100644 --- a/ash/src/prelude.rs +++ b/ash/src/prelude.rs @@ -1,4 +1,5 @@ use std::convert::TryInto; +#[cfg(feature = "debug")] use std::fmt; use crate::vk; @@ -83,6 +84,7 @@ where } } +#[cfg(feature = "debug")] pub(crate) fn debug_flags + Copy>( f: &mut fmt::Formatter, known: &[(Value, &'static str)], diff --git a/ash/src/vk.rs b/ash/src/vk.rs index 1358af8..32aedb2 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -10,6 +10,7 @@ mod aliases; pub use aliases::*; mod bitflags; pub use bitflags::*; +#[cfg(feature = "debug")] mod const_debugs; mod constants; pub use constants::*; diff --git a/ash/src/vk/const_debugs.rs b/ash/src/vk/const_debugs.rs index 14f8056..c3e4c07 100644 --- a/ash/src/vk/const_debugs.rs +++ b/ash/src/vk/const_debugs.rs @@ -2548,64 +2548,6 @@ impl fmt::Debug for MetalSurfaceCreateFlagsEXT { debug_flags(f, KNOWN, self.0) } } -impl fmt::Debug for ObjectType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let name = match *self { - Self::UNKNOWN => Some("UNKNOWN"), - Self::INSTANCE => Some("INSTANCE"), - Self::PHYSICAL_DEVICE => Some("PHYSICAL_DEVICE"), - Self::DEVICE => Some("DEVICE"), - Self::QUEUE => Some("QUEUE"), - Self::SEMAPHORE => Some("SEMAPHORE"), - Self::COMMAND_BUFFER => Some("COMMAND_BUFFER"), - Self::FENCE => Some("FENCE"), - Self::DEVICE_MEMORY => Some("DEVICE_MEMORY"), - Self::BUFFER => Some("BUFFER"), - Self::IMAGE => Some("IMAGE"), - Self::EVENT => Some("EVENT"), - Self::QUERY_POOL => Some("QUERY_POOL"), - Self::BUFFER_VIEW => Some("BUFFER_VIEW"), - Self::IMAGE_VIEW => Some("IMAGE_VIEW"), - Self::SHADER_MODULE => Some("SHADER_MODULE"), - Self::PIPELINE_CACHE => Some("PIPELINE_CACHE"), - Self::PIPELINE_LAYOUT => Some("PIPELINE_LAYOUT"), - Self::RENDER_PASS => Some("RENDER_PASS"), - Self::PIPELINE => Some("PIPELINE"), - Self::DESCRIPTOR_SET_LAYOUT => Some("DESCRIPTOR_SET_LAYOUT"), - Self::SAMPLER => Some("SAMPLER"), - Self::DESCRIPTOR_POOL => Some("DESCRIPTOR_POOL"), - Self::DESCRIPTOR_SET => Some("DESCRIPTOR_SET"), - Self::FRAMEBUFFER => Some("FRAMEBUFFER"), - Self::COMMAND_POOL => Some("COMMAND_POOL"), - Self::SURFACE_KHR => Some("SURFACE_KHR"), - Self::SWAPCHAIN_KHR => Some("SWAPCHAIN_KHR"), - Self::DISPLAY_KHR => Some("DISPLAY_KHR"), - Self::DISPLAY_MODE_KHR => Some("DISPLAY_MODE_KHR"), - Self::DEBUG_REPORT_CALLBACK_EXT => Some("DEBUG_REPORT_CALLBACK_EXT"), - Self::VIDEO_SESSION_KHR => Some("VIDEO_SESSION_KHR"), - Self::VIDEO_SESSION_PARAMETERS_KHR => Some("VIDEO_SESSION_PARAMETERS_KHR"), - Self::CU_MODULE_NVX => Some("CU_MODULE_NVX"), - Self::CU_FUNCTION_NVX => Some("CU_FUNCTION_NVX"), - Self::DEBUG_UTILS_MESSENGER_EXT => Some("DEBUG_UTILS_MESSENGER_EXT"), - Self::ACCELERATION_STRUCTURE_KHR => Some("ACCELERATION_STRUCTURE_KHR"), - Self::VALIDATION_CACHE_EXT => Some("VALIDATION_CACHE_EXT"), - Self::ACCELERATION_STRUCTURE_NV => Some("ACCELERATION_STRUCTURE_NV"), - Self::PERFORMANCE_CONFIGURATION_INTEL => Some("PERFORMANCE_CONFIGURATION_INTEL"), - Self::DEFERRED_OPERATION_KHR => Some("DEFERRED_OPERATION_KHR"), - Self::INDIRECT_COMMANDS_LAYOUT_NV => Some("INDIRECT_COMMANDS_LAYOUT_NV"), - Self::PRIVATE_DATA_SLOT_EXT => Some("PRIVATE_DATA_SLOT_EXT"), - Self::BUFFER_COLLECTION_FUCHSIA => Some("BUFFER_COLLECTION_FUCHSIA"), - Self::SAMPLER_YCBCR_CONVERSION => Some("SAMPLER_YCBCR_CONVERSION"), - Self::DESCRIPTOR_UPDATE_TEMPLATE => Some("DESCRIPTOR_UPDATE_TEMPLATE"), - _ => None, - }; - if let Some(x) = name { - f.write_str(x) - } else { - self.0.fmt(f) - } - } -} impl fmt::Debug for PeerMemoryFeatureFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { const KNOWN: &[(Flags, &str)] = &[ @@ -3556,62 +3498,6 @@ impl fmt::Debug for ResolveModeFlags { debug_flags(f, KNOWN, self.0) } } -impl fmt::Debug for Result { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let name = match *self { - Self::SUCCESS => Some("SUCCESS"), - Self::NOT_READY => Some("NOT_READY"), - Self::TIMEOUT => Some("TIMEOUT"), - Self::EVENT_SET => Some("EVENT_SET"), - Self::EVENT_RESET => Some("EVENT_RESET"), - Self::INCOMPLETE => Some("INCOMPLETE"), - Self::ERROR_OUT_OF_HOST_MEMORY => Some("ERROR_OUT_OF_HOST_MEMORY"), - Self::ERROR_OUT_OF_DEVICE_MEMORY => Some("ERROR_OUT_OF_DEVICE_MEMORY"), - Self::ERROR_INITIALIZATION_FAILED => Some("ERROR_INITIALIZATION_FAILED"), - Self::ERROR_DEVICE_LOST => Some("ERROR_DEVICE_LOST"), - Self::ERROR_MEMORY_MAP_FAILED => Some("ERROR_MEMORY_MAP_FAILED"), - Self::ERROR_LAYER_NOT_PRESENT => Some("ERROR_LAYER_NOT_PRESENT"), - Self::ERROR_EXTENSION_NOT_PRESENT => Some("ERROR_EXTENSION_NOT_PRESENT"), - Self::ERROR_FEATURE_NOT_PRESENT => Some("ERROR_FEATURE_NOT_PRESENT"), - Self::ERROR_INCOMPATIBLE_DRIVER => Some("ERROR_INCOMPATIBLE_DRIVER"), - Self::ERROR_TOO_MANY_OBJECTS => Some("ERROR_TOO_MANY_OBJECTS"), - Self::ERROR_FORMAT_NOT_SUPPORTED => Some("ERROR_FORMAT_NOT_SUPPORTED"), - Self::ERROR_FRAGMENTED_POOL => Some("ERROR_FRAGMENTED_POOL"), - Self::ERROR_UNKNOWN => Some("ERROR_UNKNOWN"), - Self::ERROR_SURFACE_LOST_KHR => Some("ERROR_SURFACE_LOST_KHR"), - Self::ERROR_NATIVE_WINDOW_IN_USE_KHR => Some("ERROR_NATIVE_WINDOW_IN_USE_KHR"), - Self::SUBOPTIMAL_KHR => Some("SUBOPTIMAL_KHR"), - Self::ERROR_OUT_OF_DATE_KHR => Some("ERROR_OUT_OF_DATE_KHR"), - Self::ERROR_INCOMPATIBLE_DISPLAY_KHR => Some("ERROR_INCOMPATIBLE_DISPLAY_KHR"), - Self::ERROR_VALIDATION_FAILED_EXT => Some("ERROR_VALIDATION_FAILED_EXT"), - Self::ERROR_INVALID_SHADER_NV => Some("ERROR_INVALID_SHADER_NV"), - Self::ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT => { - Some("ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT") - } - Self::ERROR_NOT_PERMITTED_EXT => Some("ERROR_NOT_PERMITTED_EXT"), - Self::ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT => { - Some("ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT") - } - Self::THREAD_IDLE_KHR => Some("THREAD_IDLE_KHR"), - Self::THREAD_DONE_KHR => Some("THREAD_DONE_KHR"), - Self::OPERATION_DEFERRED_KHR => Some("OPERATION_DEFERRED_KHR"), - Self::OPERATION_NOT_DEFERRED_KHR => Some("OPERATION_NOT_DEFERRED_KHR"), - Self::PIPELINE_COMPILE_REQUIRED_EXT => Some("PIPELINE_COMPILE_REQUIRED_EXT"), - Self::ERROR_OUT_OF_POOL_MEMORY => Some("ERROR_OUT_OF_POOL_MEMORY"), - Self::ERROR_INVALID_EXTERNAL_HANDLE => Some("ERROR_INVALID_EXTERNAL_HANDLE"), - Self::ERROR_FRAGMENTATION => Some("ERROR_FRAGMENTATION"), - Self::ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => { - Some("ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS") - } - _ => None, - }; - if let Some(x) = name { - f.write_str(x) - } else { - self.0.fmt(f) - } - } -} impl fmt::Debug for SampleCountFlags { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { const KNOWN: &[(Flags, &str)] = &[ diff --git a/ash/src/vk/enums.rs b/ash/src/vk/enums.rs index 00fbbb3..dda54dd 100644 --- a/ash/src/vk/enums.rs +++ b/ash/src/vk/enums.rs @@ -2242,3 +2242,117 @@ impl QueryResultStatusKHR { pub const NOT_READY: Self = Self(0); pub const COMPLETE: Self = Self(1); } +impl fmt::Debug for ObjectType { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let name = match *self { + Self::UNKNOWN => Some("UNKNOWN"), + Self::INSTANCE => Some("INSTANCE"), + Self::PHYSICAL_DEVICE => Some("PHYSICAL_DEVICE"), + Self::DEVICE => Some("DEVICE"), + Self::QUEUE => Some("QUEUE"), + Self::SEMAPHORE => Some("SEMAPHORE"), + Self::COMMAND_BUFFER => Some("COMMAND_BUFFER"), + Self::FENCE => Some("FENCE"), + Self::DEVICE_MEMORY => Some("DEVICE_MEMORY"), + Self::BUFFER => Some("BUFFER"), + Self::IMAGE => Some("IMAGE"), + Self::EVENT => Some("EVENT"), + Self::QUERY_POOL => Some("QUERY_POOL"), + Self::BUFFER_VIEW => Some("BUFFER_VIEW"), + Self::IMAGE_VIEW => Some("IMAGE_VIEW"), + Self::SHADER_MODULE => Some("SHADER_MODULE"), + Self::PIPELINE_CACHE => Some("PIPELINE_CACHE"), + Self::PIPELINE_LAYOUT => Some("PIPELINE_LAYOUT"), + Self::RENDER_PASS => Some("RENDER_PASS"), + Self::PIPELINE => Some("PIPELINE"), + Self::DESCRIPTOR_SET_LAYOUT => Some("DESCRIPTOR_SET_LAYOUT"), + Self::SAMPLER => Some("SAMPLER"), + Self::DESCRIPTOR_POOL => Some("DESCRIPTOR_POOL"), + Self::DESCRIPTOR_SET => Some("DESCRIPTOR_SET"), + Self::FRAMEBUFFER => Some("FRAMEBUFFER"), + Self::COMMAND_POOL => Some("COMMAND_POOL"), + Self::SURFACE_KHR => Some("SURFACE_KHR"), + Self::SWAPCHAIN_KHR => Some("SWAPCHAIN_KHR"), + Self::DISPLAY_KHR => Some("DISPLAY_KHR"), + Self::DISPLAY_MODE_KHR => Some("DISPLAY_MODE_KHR"), + Self::DEBUG_REPORT_CALLBACK_EXT => Some("DEBUG_REPORT_CALLBACK_EXT"), + Self::VIDEO_SESSION_KHR => Some("VIDEO_SESSION_KHR"), + Self::VIDEO_SESSION_PARAMETERS_KHR => Some("VIDEO_SESSION_PARAMETERS_KHR"), + Self::CU_MODULE_NVX => Some("CU_MODULE_NVX"), + Self::CU_FUNCTION_NVX => Some("CU_FUNCTION_NVX"), + Self::DEBUG_UTILS_MESSENGER_EXT => Some("DEBUG_UTILS_MESSENGER_EXT"), + Self::ACCELERATION_STRUCTURE_KHR => Some("ACCELERATION_STRUCTURE_KHR"), + Self::VALIDATION_CACHE_EXT => Some("VALIDATION_CACHE_EXT"), + Self::ACCELERATION_STRUCTURE_NV => Some("ACCELERATION_STRUCTURE_NV"), + Self::PERFORMANCE_CONFIGURATION_INTEL => Some("PERFORMANCE_CONFIGURATION_INTEL"), + Self::DEFERRED_OPERATION_KHR => Some("DEFERRED_OPERATION_KHR"), + Self::INDIRECT_COMMANDS_LAYOUT_NV => Some("INDIRECT_COMMANDS_LAYOUT_NV"), + Self::PRIVATE_DATA_SLOT_EXT => Some("PRIVATE_DATA_SLOT_EXT"), + Self::BUFFER_COLLECTION_FUCHSIA => Some("BUFFER_COLLECTION_FUCHSIA"), + Self::SAMPLER_YCBCR_CONVERSION => Some("SAMPLER_YCBCR_CONVERSION"), + Self::DESCRIPTOR_UPDATE_TEMPLATE => Some("DESCRIPTOR_UPDATE_TEMPLATE"), + _ => None, + }; + if let Some(x) = name { + f.write_str(x) + } else { + self.0.fmt(f) + } + } +} +impl fmt::Debug for Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let name = match *self { + Self::SUCCESS => Some("SUCCESS"), + Self::NOT_READY => Some("NOT_READY"), + Self::TIMEOUT => Some("TIMEOUT"), + Self::EVENT_SET => Some("EVENT_SET"), + Self::EVENT_RESET => Some("EVENT_RESET"), + Self::INCOMPLETE => Some("INCOMPLETE"), + Self::ERROR_OUT_OF_HOST_MEMORY => Some("ERROR_OUT_OF_HOST_MEMORY"), + Self::ERROR_OUT_OF_DEVICE_MEMORY => Some("ERROR_OUT_OF_DEVICE_MEMORY"), + Self::ERROR_INITIALIZATION_FAILED => Some("ERROR_INITIALIZATION_FAILED"), + Self::ERROR_DEVICE_LOST => Some("ERROR_DEVICE_LOST"), + Self::ERROR_MEMORY_MAP_FAILED => Some("ERROR_MEMORY_MAP_FAILED"), + Self::ERROR_LAYER_NOT_PRESENT => Some("ERROR_LAYER_NOT_PRESENT"), + Self::ERROR_EXTENSION_NOT_PRESENT => Some("ERROR_EXTENSION_NOT_PRESENT"), + Self::ERROR_FEATURE_NOT_PRESENT => Some("ERROR_FEATURE_NOT_PRESENT"), + Self::ERROR_INCOMPATIBLE_DRIVER => Some("ERROR_INCOMPATIBLE_DRIVER"), + Self::ERROR_TOO_MANY_OBJECTS => Some("ERROR_TOO_MANY_OBJECTS"), + Self::ERROR_FORMAT_NOT_SUPPORTED => Some("ERROR_FORMAT_NOT_SUPPORTED"), + Self::ERROR_FRAGMENTED_POOL => Some("ERROR_FRAGMENTED_POOL"), + Self::ERROR_UNKNOWN => Some("ERROR_UNKNOWN"), + Self::ERROR_SURFACE_LOST_KHR => Some("ERROR_SURFACE_LOST_KHR"), + Self::ERROR_NATIVE_WINDOW_IN_USE_KHR => Some("ERROR_NATIVE_WINDOW_IN_USE_KHR"), + Self::SUBOPTIMAL_KHR => Some("SUBOPTIMAL_KHR"), + Self::ERROR_OUT_OF_DATE_KHR => Some("ERROR_OUT_OF_DATE_KHR"), + Self::ERROR_INCOMPATIBLE_DISPLAY_KHR => Some("ERROR_INCOMPATIBLE_DISPLAY_KHR"), + Self::ERROR_VALIDATION_FAILED_EXT => Some("ERROR_VALIDATION_FAILED_EXT"), + Self::ERROR_INVALID_SHADER_NV => Some("ERROR_INVALID_SHADER_NV"), + Self::ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT => { + Some("ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT") + } + Self::ERROR_NOT_PERMITTED_EXT => Some("ERROR_NOT_PERMITTED_EXT"), + Self::ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT => { + Some("ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT") + } + Self::THREAD_IDLE_KHR => Some("THREAD_IDLE_KHR"), + Self::THREAD_DONE_KHR => Some("THREAD_DONE_KHR"), + Self::OPERATION_DEFERRED_KHR => Some("OPERATION_DEFERRED_KHR"), + Self::OPERATION_NOT_DEFERRED_KHR => Some("OPERATION_NOT_DEFERRED_KHR"), + Self::PIPELINE_COMPILE_REQUIRED_EXT => Some("PIPELINE_COMPILE_REQUIRED_EXT"), + Self::ERROR_OUT_OF_POOL_MEMORY => Some("ERROR_OUT_OF_POOL_MEMORY"), + Self::ERROR_INVALID_EXTERNAL_HANDLE => Some("ERROR_INVALID_EXTERNAL_HANDLE"), + Self::ERROR_FRAGMENTATION => Some("ERROR_FRAGMENTATION"), + Self::ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS => { + Some("ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS") + } + _ => None, + }; + if let Some(x) = name { + f.write_str(x) + } else { + self.0.fmt(f) + } + } +} diff --git a/generator/src/lib.rs b/generator/src/lib.rs index bc63621..438eaac 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -2407,10 +2407,17 @@ pub struct ConstantTypeInfo { bitwidth: Option, } -pub fn generate_const_debugs(const_values: &BTreeMap) -> TokenStream { - let impls = const_values.iter().map(|(ty, values)| { +pub struct ConstDebugs { + core: TokenStream, + extras: TokenStream, +} + +pub fn generate_const_debugs(const_values: &BTreeMap) -> ConstDebugs { + let mut core = Vec::new(); + let mut extras = Vec::new(); + for (ty, values) in const_values { let ConstantTypeInfo { values, bitwidth } = values; - if ty.to_string().contains("Flags") { + let out = if ty.to_string().contains("Flags") { let cases = values.iter().filter_map(|value| { if value.is_alias { None @@ -2460,10 +2467,21 @@ pub fn generate_const_debugs(const_values: &BTreeMap) - } } } + }; + if ty == "Result" || ty == "ObjectType" { + core.push(out); + } else { + extras.push(out); } - }); - quote! { - #(#impls)* + } + + ConstDebugs { + core: quote! { + #(#core)* + }, + extras: quote! { + #(#extras)* + }, } } pub fn extract_native_types(registry: &vk_parse::Registry) -> (Vec<(String, String)>, Vec) { @@ -2708,7 +2726,10 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { let feature_extensions_code = generate_feature_extension(&spec2, &mut const_cache, &mut const_values); - let const_debugs = generate_const_debugs(&const_values); + let ConstDebugs { + core: core_debugs, + extras: const_debugs, + } = generate_const_debugs(&const_values); let bitflags_macro = vk_bitflags_wrapped_macro(); let handle_nondispatchable_macro = handle_nondispatchable_macro(); @@ -2765,6 +2786,7 @@ pub fn write_source_code>(vk_headers_dir: &Path, src_dir: P) { let enum_code = quote! { use std::fmt; #(#enum_code)* + #core_debugs }; let bitflags_code = quote! {