Include device extension functions under instance functions if they use a physical device (#1974)

This commit is contained in:
Rua 2022-09-13 11:07:30 +02:00 committed by GitHub
parent 9d8cc36a32
commit d4d0575850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,12 +21,12 @@ pub fn write(vk_data: &VkRegistryData) {
"Raw Vulkan global entry point-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.", "Raw Vulkan global entry point-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.",
); );
let instance_fns_output = fns_output( let instance_fns_output = fns_output(
&extension_fns_members("instance", &vk_data.extensions), &instance_extension_fns_members(&vk_data.extensions),
"Instance", "Instance",
"Raw Vulkan instance-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.", "Raw Vulkan instance-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.",
); );
let device_fns_output = fns_output( let device_fns_output = fns_output(
&extension_fns_members("device", &vk_data.extensions), &device_extension_fns_members(&vk_data.extensions),
"Device", "Device",
"Raw Vulkan device-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.", "Raw Vulkan device-level functions.\n\nTo use these, you need to include the Ash crate, using the same version Vulkano uses.",
); );
@ -97,11 +97,11 @@ fn fns_output(extension_members: &[FnsMember], fns_level: &str, doc: &str) -> To
} }
} }
fn extension_fns_members(ty: &str, extensions: &IndexMap<&str, &Extension>) -> Vec<FnsMember> { fn device_extension_fns_members(extensions: &IndexMap<&str, &Extension>) -> Vec<FnsMember> {
extensions extensions
.values() .values()
.filter(|ext| ext.ext_type.as_ref().unwrap() == ty) // Include any device extensions that have functions.
// Filter only extensions that have functions .filter(|ext| ext.ext_type.as_ref().unwrap() == "device")
.filter(|ext| { .filter(|ext| {
ext.children.iter().any(|ch| { ext.children.iter().any(|ch| {
if let ExtensionChild::Require { items, .. } = ch { if let ExtensionChild::Require { items, .. } = ch {
@ -121,3 +121,41 @@ fn extension_fns_members(ty: &str, extensions: &IndexMap<&str, &Extension>) -> V
}) })
.collect() .collect()
} }
fn instance_extension_fns_members(extensions: &IndexMap<&str, &Extension>) -> Vec<FnsMember> {
extensions
.values()
.filter(|ext| {
match ext.ext_type.as_deref().unwrap() {
// Include any instance extensions that have functions.
"instance" => ext.children.iter().any(|ch| {
if let ExtensionChild::Require { items, .. } = ch {
items
.iter()
.any(|i| matches!(i, InterfaceItem::Command { .. }))
} else {
false
}
}),
// Include device extensions that have functions containing "PhysicalDevice".
// Note: this test might not be sufficient in the long run...
"device" => ext.children.iter().any(|ch| {
if let ExtensionChild::Require { items, .. } = ch {
items
.iter()
.any(|i| matches!(i, InterfaceItem::Command { name, .. } if name.contains("PhysicalDevice")))
} else {
false
}
}),
_ => unreachable!(),
}
})
.map(|ext| {
let base = ext.name.strip_prefix("VK_").unwrap().to_snake_case();
let name = format_ident!("{}", base);
let fn_struct = format_ident!("{}Fn", base.to_upper_camel_case());
FnsMember { name, fn_struct }
})
.collect()
}