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 2, 2023
1 parent 9c40eb4 commit 92fc6a5
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 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,33 @@ impl crate::Instance<super::Api> for super::Instance {

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

let validation_features_name = vk::ExtValidationFeaturesFn::name();
match entry.enumerate_instance_extension_properties(Some(validation_layer_name)) {
Ok(validation_extensions) => {
if validation_extensions.iter().any(|inst_ext| {
cstr_from_bytes_until_nul(&inst_ext.extension_name)
== Some(validation_features_name)
}) {
extensions.push(validation_features_name);
validation_features = Some(
vk::ValidationFeaturesEXT::builder().enabled_validation_features(
&[vk::ValidationFeatureEnableEXT::DEBUG_PRINTF],
),
);
} else {
log::info!(
"Unable to find validation layer extension {}, not enabling DEBUG_PRINTF",
validation_features_name.to_string_lossy()
)
}
}
Err(e) => {
log::warn!(
"enumerate_instance_extension_properties() failed for validation layer: {:?}", e
)
}
}
} else {
log::warn!(
"InstanceFlags::VALIDATION requested, but unable to find layer: {}",
Expand Down Expand Up @@ -743,6 +771,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 92fc6a5

Please sign in to comment.