Skip to content

Commit

Permalink
debug_printf: Enable debug_printf validation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
exrook committed Nov 1, 2023
1 parent a81525c commit d675cc5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion wgpu-hal/src/vulkan/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ impl crate::Instance<super::Api> for super::Instance {
},
);

let extensions = Self::desired_extensions(&entry, instance_api_version, desc.flags)?;
let mut extensions = Self::desired_extensions(&entry, instance_api_version, desc.flags)?;

let instance_layers = {
profiling::scope!("vkEnumerateInstanceLayerProperties");
Expand Down Expand Up @@ -644,6 +644,7 @@ impl crate::Instance<super::Api> for super::Instance {

// Request validation layer if asked.
let mut debug_utils = None;
let mut validation_features = None;
if desc.flags.contains(wgt::InstanceFlags::VALIDATION) {
let validation_layer_name =
CStr::from_bytes_with_nul(b"VK_LAYER_KHRONOS_validation\0").unwrap();
Expand Down Expand Up @@ -689,6 +690,28 @@ impl crate::Instance<super::Api> for super::Instance {

debug_utils = Some((create_info, vk_create_info));
}

if let Some(validation_extensions) = entry
.enumerate_instance_extension_properties(Some(validation_layer_name))
.map_err(|e| {
log::warn!(
"enumerate_instance_extension_properties() failed for validation layer: {:?}", e
)
})
.ok()
{
if validation_extensions.iter().any(|inst_ext| {
cstr_from_bytes_until_nul(&inst_ext.extension_name)
== Some(vk::ExtValidationFeaturesFn::name())
}) {
extensions.push(vk::ExtValidationFeaturesFn::name());
validation_features = Some(
vk::ValidationFeaturesEXT::builder().enabled_validation_features(&[
vk::ValidationFeatureEnableEXT::DEBUG_PRINTF,
]),
);
}
}
} else {
log::warn!(
"InstanceFlags::VALIDATION requested, but unable to find layer: {}",
Expand Down Expand Up @@ -743,6 +766,10 @@ impl crate::Instance<super::Api> for super::Instance {
.enabled_layer_names(&str_pointers[..layers.len()])
.enabled_extension_names(&str_pointers[layers.len()..]);

if let Some(validation_features) = validation_features.as_mut() {
create_info = create_info.push_next(validation_features);
}

if let Some(&mut (_, ref mut vk_create_info)) = debug_utils.as_mut() {
create_info = create_info.push_next(vk_create_info);
}
Expand Down

0 comments on commit d675cc5

Please sign in to comment.