Don't depend on validation layers for setting object names

This commit is contained in:
Daniel McNab 2024-03-05 17:18:12 +00:00 committed by Jim Blandy
parent badb3c88ea
commit 4e851067dd
2 changed files with 69 additions and 49 deletions

View File

@ -35,13 +35,15 @@ unsafe extern "system" fn debug_utils_messenger_callback(
// the debug range start and end appear in different command buffers.
let khronos_validation_layer =
std::ffi::CStr::from_bytes_with_nul(b"Khronos Validation Layer\0").unwrap();
if user_data.validation_layer_description.as_ref() == khronos_validation_layer
&& user_data.validation_layer_spec_version >= vk::make_api_version(0, 1, 3, 240)
&& user_data.validation_layer_spec_version <= vk::make_api_version(0, 1, 3, 250)
if let Some(layer_properties) = &user_data.validation_layer_properties {
if layer_properties.layer_description.as_ref() == khronos_validation_layer
&& layer_properties.layer_spec_version >= vk::make_api_version(0, 1, 3, 240)
&& layer_properties.layer_spec_version <= vk::make_api_version(0, 1, 3, 250)
{
return vk::FALSE;
}
}
}
// Silence Vulkan Validation error "VUID-VkSwapchainCreateInfoKHR-pNext-07781"
// This happens when a surface is configured with a size outside the allowed extent.
@ -684,27 +686,42 @@ impl crate::Instance<super::Api> for super::Instance {
let mut layers: Vec<&'static CStr> = Vec::new();
let has_debug_extension = extensions.contains(&ext::DebugUtils::name());
let mut debug_user_data = has_debug_extension.then(|| {
// Put the callback data on the heap, to ensure it will never be
// moved.
Box::new(super::DebugUtilsMessengerUserData {
validation_layer_properties: None,
has_obs_layer,
})
});
// Request validation layer if asked.
let mut debug_utils = None;
if desc.flags.intersects(wgt::InstanceFlags::VALIDATION)
|| should_enable_gpu_based_validation
{
if let Some(layer_properties) = validation_layer_properties {
layers.push(validation_layer_name);
if extensions.contains(&ext::DebugUtils::name()) {
// Put the callback data on the heap, to ensure it will never be
// moved.
let callback_data = Box::new(super::DebugUtilsMessengerUserData {
validation_layer_description: cstr_from_bytes_until_nul(
if let Some(debug_user_data) = &mut debug_user_data {
debug_user_data.validation_layer_properties =
Some(super::ValidationLayerProperties {
layer_description: cstr_from_bytes_until_nul(
&layer_properties.description,
)
.unwrap()
.to_owned(),
validation_layer_spec_version: layer_properties.spec_version,
has_obs_layer,
layer_spec_version: layer_properties.spec_version,
});
}
} else {
log::warn!(
"InstanceFlags::VALIDATION requested, but unable to find layer: {}",
validation_layer_name.to_string_lossy()
);
}
}
let mut debug_utils = if let Some(callback_data) = debug_user_data {
// having ERROR unconditionally because Vk doesn't like empty flags
let mut severity = vk::DebugUtilsMessageSeverityFlagsEXT::ERROR;
if log::max_level() >= log::LevelFilter::Debug {
@ -729,15 +746,10 @@ impl crate::Instance<super::Api> for super::Instance {
let vk_create_info = create_info.to_vk_create_info().build();
debug_utils = Some((create_info, vk_create_info));
}
Some((create_info, vk_create_info))
} else {
log::warn!(
"InstanceFlags::VALIDATION requested, but unable to find layer: {}",
validation_layer_name.to_string_lossy()
);
}
}
None
};
#[cfg(target_os = "android")]
let android_sdk_version = {

View File

@ -101,17 +101,25 @@ pub struct DebugUtilsCreateInfo {
callback_data: Box<DebugUtilsMessengerUserData>,
}
#[derive(Debug)]
/// The properties related to the validation layer needed for the
/// DebugUtilsMessenger for their workarounds
struct ValidationLayerProperties {
/// Validation layer description, from `vk::LayerProperties`.
layer_description: std::ffi::CString,
/// Validation layer specification version, from `vk::LayerProperties`.
layer_spec_version: u32,
}
/// User data needed by `instance::debug_utils_messenger_callback`.
///
/// When we create the [`vk::DebugUtilsMessengerEXT`], the `pUserData`
/// pointer refers to one of these values.
#[derive(Debug)]
pub struct DebugUtilsMessengerUserData {
/// Validation layer description, from `vk::LayerProperties`.
validation_layer_description: std::ffi::CString,
/// Validation layer specification version, from `vk::LayerProperties`.
validation_layer_spec_version: u32,
/// The properties related to the validation layer, if present
validation_layer_properties: Option<ValidationLayerProperties>,
/// If the OBS layer is present. OBS never increments the version of their layer,
/// so there's no reason to have the version.