Skip to content
New issue

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

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

Already on GitHub? # to your account

Improve debug messenger, remove second Instance constructor #2275

Merged
merged 10 commits into from
Aug 5, 2023
65 changes: 34 additions & 31 deletions examples/src/bin/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

use std::sync::Arc;
use vulkano::{
device::{
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
},
instance::{
debug::{
DebugUtilsMessageSeverity, DebugUtilsMessageType, DebugUtilsMessenger,
DebugUtilsMessengerCreateInfo,
DebugUtilsMessengerCallback, DebugUtilsMessengerCreateInfo,
},
Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions,
},
Expand Down Expand Up @@ -86,37 +85,41 @@ fn main() {
message_type: DebugUtilsMessageType::GENERAL
| DebugUtilsMessageType::VALIDATION
| DebugUtilsMessageType::PERFORMANCE,
..DebugUtilsMessengerCreateInfo::user_callback(Arc::new(|msg| {
let severity = if msg.severity.intersects(DebugUtilsMessageSeverity::ERROR) {
"error"
} else if msg.severity.intersects(DebugUtilsMessageSeverity::WARNING) {
"warning"
} else if msg.severity.intersects(DebugUtilsMessageSeverity::INFO) {
"information"
} else if msg.severity.intersects(DebugUtilsMessageSeverity::VERBOSE) {
"verbose"
} else {
panic!("no-impl");
};
..DebugUtilsMessengerCreateInfo::user_callback(DebugUtilsMessengerCallback::new(
|message_severity, message_type, callback_data| {
let severity = if message_severity
.intersects(DebugUtilsMessageSeverity::ERROR)
{
"error"
} else if message_severity.intersects(DebugUtilsMessageSeverity::WARNING) {
"warning"
} else if message_severity.intersects(DebugUtilsMessageSeverity::INFO) {
"information"
} else if message_severity.intersects(DebugUtilsMessageSeverity::VERBOSE) {
"verbose"
} else {
panic!("no-impl");
};

let ty = if msg.ty.intersects(DebugUtilsMessageType::GENERAL) {
"general"
} else if msg.ty.intersects(DebugUtilsMessageType::VALIDATION) {
"validation"
} else if msg.ty.intersects(DebugUtilsMessageType::PERFORMANCE) {
"performance"
} else {
panic!("no-impl");
};
let ty = if message_type.intersects(DebugUtilsMessageType::GENERAL) {
"general"
} else if message_type.intersects(DebugUtilsMessageType::VALIDATION) {
"validation"
} else if message_type.intersects(DebugUtilsMessageType::PERFORMANCE) {
"performance"
} else {
panic!("no-impl");
};

println!(
"{} {} {}: {}",
msg.layer_prefix.unwrap_or("unknown"),
ty,
severity,
msg.description
);
}))
println!(
"{} {} {}: {}",
callback_data.message_id_name.unwrap_or("unknown"),
ty,
severity,
callback_data.message
);
},
))
},
)
.ok()
Expand Down
24 changes: 14 additions & 10 deletions examples/src/bin/gl-interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ mod linux {
Image, ImageCreateFlags, ImageCreateInfo, ImageType, ImageUsage,
},
instance::{
debug::{DebugUtilsMessenger, DebugUtilsMessengerCreateInfo},
debug::{
DebugUtilsMessenger, DebugUtilsMessengerCallback, DebugUtilsMessengerCreateInfo,
},
Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions,
},
memory::{
Expand Down Expand Up @@ -478,15 +480,17 @@ mod linux {
let _debug_callback = unsafe {
DebugUtilsMessenger::new(
instance.clone(),
DebugUtilsMessengerCreateInfo::user_callback(Arc::new(|msg| {
println!(
"{} {:?} {:?}: {}",
msg.layer_prefix.unwrap_or("unknown"),
msg.ty,
msg.severity,
msg.description,
);
})),
DebugUtilsMessengerCreateInfo::user_callback(DebugUtilsMessengerCallback::new(
|message_severity, message_type, callback_data| {
println!(
"{} {:?} {:?}: {}",
callback_data.message_id_name.unwrap_or("unknown"),
message_type,
message_severity,
callback_data.message,
);
},
)),
)
.unwrap()
};
Expand Down
12 changes: 4 additions & 8 deletions vulkano-util/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,10 @@ impl VulkanoContext {
Instance::new(library, config.instance_create_info).expect("failed to create instance");

// Create debug callback
let _debug_utils_messenger =
config
.debug_create_info
.take()
.map(|dbg_create_info| unsafe {
DebugUtilsMessenger::new(instance.clone(), dbg_create_info)
.expect("failed to create debug callback")
});
let _debug_utils_messenger = config.debug_create_info.take().map(|dbg_create_info| {
DebugUtilsMessenger::new(instance.clone(), dbg_create_info)
.expect("failed to create debug callback")
});

// Get prioritized device
let physical_device = instance
Expand Down
10 changes: 10 additions & 0 deletions vulkano/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,16 @@ vulkan_bitflags! {
pub unsafe trait DeviceOwned {
/// Returns the device that owns `self`.
fn device(&self) -> &Arc<Device>;

/// Assigns a human-readable name to `object` for debugging purposes.
///
/// If `object_name` is `None`, a previously set object name is removed.
fn set_debug_utils_object_name(&self, object_name: Option<&str>) -> Result<(), OomError>
where
Self: VulkanObject + Sized,
Rua marked this conversation as resolved.
Show resolved Hide resolved
{
self.device().set_debug_utils_object_name(self, object_name)
}
}

unsafe impl<T> DeviceOwned for T
Expand Down
Loading