Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Debug impls optional #482

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Device extension `khr::PipelineExecutableProperties` and `khr::TimelineSemaphore` now expose `fn device()` instead of `fn instance()` (#499)
- Changed `khr::PipelineExecutableProperties::new()` and `khr::TimelineSemaphore::new()` to take `instance` and `device` as arguments (#499)
- To allow faster builds, Vulkan structures only implement `Debug` if the `debug` feature is enabled, which is the default (#482)

### Removed

Expand Down
4 changes: 3 additions & 1 deletion ash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ edition = "2018"
libloading = { version = "0.7", optional = true }

[features]
default = ["linked"]
default = ["linked", "debug"]
# Link the Vulkan loader at compile time.
linked = []
# Support searching for the Vulkan loader manually at runtime.
loaded = ["libloading"]
# Whether Vulkan structs should implement Debug
debug = []

[package.metadata.release]
no-dev-version = true
Expand Down
40 changes: 28 additions & 12 deletions ash/src/extensions/experimental/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
*
**********************************************************************************************************************/

#[cfg(feature = "debug")]
use crate::prelude::debug_flags;
use crate::vk::*;

use std::fmt;
use std::os::raw::*;

Expand All @@ -35,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)] = &[
Expand Down Expand Up @@ -67,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 {
Expand All @@ -87,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 {
Expand Down Expand Up @@ -133,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 {
Expand All @@ -153,15 +160,17 @@ 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,
pub secondary_copy_source: GpaSessionAmd,
}

#[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,
Expand All @@ -173,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,
Expand All @@ -184,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,
Expand Down Expand Up @@ -242,15 +253,17 @@ 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,
pub event_id: u32,
}

#[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,
Expand All @@ -271,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,
Expand Down Expand Up @@ -630,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,
Expand Down Expand Up @@ -690,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,
Expand Down
30 changes: 30 additions & 0 deletions ash/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::convert::TryInto;
#[cfg(feature = "debug")]
use std::fmt;

use crate::vk;
pub type VkResult<T> = Result<T, vk::Result>;
Expand Down Expand Up @@ -81,3 +83,31 @@ where
}
}
}

#[cfg(feature = "debug")]
pub(crate) fn debug_flags<Value: Into<u64> + 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(())
}
2 changes: 1 addition & 1 deletion ash/src/vk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod aliases;
pub use aliases::*;
mod bitflags;
pub use bitflags::*;
#[cfg(feature = "debug")]
mod const_debugs;
pub(crate) use const_debugs::*;
mod constants;
pub use constants::*;
mod definitions;
Expand Down
141 changes: 1 addition & 140 deletions ash/src/vk/const_debugs.rs
Original file line number Diff line number Diff line change
@@ -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<Value: Into<u64> + 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 {
Expand Down Expand Up @@ -2573,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)] = &[
Expand Down Expand Up @@ -3581,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)] = &[
Expand Down
Loading