Expose header version and extension spec version constants (#322)

* Generate constants for value defines

* Expose versioning constants containing macros

* Expose extension SPEC_VERSION constant
This commit is contained in:
Marijn Suijten 2020-09-10 20:46:42 +02:00 committed by GitHub
parent df504f8121
commit 6f488cd3db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 377 additions and 0 deletions

View file

@ -6,6 +6,11 @@ use crate::vk::platform_types::*;
use crate::vk::{ptr_chain_iter, Handle}; use crate::vk::{ptr_chain_iter, Handle};
use std::fmt; use std::fmt;
use std::os::raw::*; use std::os::raw::*;
pub const API_VERSION_1_0: u32 = crate::vk::make_version(1, 0, 0);
pub const API_VERSION_1_1: u32 = crate::vk::make_version(1, 1, 0);
pub const API_VERSION_1_2: u32 = crate::vk::make_version(1, 2, 0);
pub const HEADER_VERSION: u32 = 135u32;
pub const HEADER_VERSION_COMPLETE: u32 = crate::vk::make_version(1, 2, HEADER_VERSION);
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkSampleMask.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkSampleMask.html>"]
pub type SampleMask = u32; pub type SampleMask = u32;
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkBool32.html>"] #[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkBool32.html>"]

File diff suppressed because it is too large Load diff

View file

@ -1075,6 +1075,28 @@ pub fn generate_extension_commands<'a>(
let fp = generate_function_pointers(ident, &commands, &aliases, fn_cache); let fp = generate_function_pointers(ident, &commands, &aliases, fn_cache);
let byte_name = format!("{}\0", extension_name); let byte_name = format!("{}\0", extension_name);
let spec_version = items
.iter()
.find_map(|ext_item| match ext_item {
vk_parse::ExtensionChild::Require { items, .. } => {
items.iter().find_map(|item| match item {
vk_parse::InterfaceItem::Enum(ref e) if e.name.contains("SPEC_VERSION") => {
Some(e)
}
_ => None,
})
}
_ => None,
})
.and_then(|e| {
if let vk_parse::EnumSpec::Value { value, .. } = &e.spec {
let v: u32 = str::parse(value).unwrap();
Some(quote!(pub const SPEC_VERSION: u32 = #v;))
} else {
None
}
});
let byte_name_ident = let byte_name_ident =
syn::LitByteStr::new(byte_name.as_bytes(), proc_macro2::Span::call_site()); syn::LitByteStr::new(byte_name.as_bytes(), proc_macro2::Span::call_site());
let extension_cstr = quote! { let extension_cstr = quote! {
@ -1082,6 +1104,7 @@ pub fn generate_extension_commands<'a>(
pub fn name() -> &'static ::std::ffi::CStr { pub fn name() -> &'static ::std::ffi::CStr {
::std::ffi::CStr::from_bytes_with_nul(#byte_name_ident).expect("Wrong extension string") ::std::ffi::CStr::from_bytes_with_nul(#byte_name_ident).expect("Wrong extension string")
} }
#spec_version
} }
}; };
quote! { quote! {
@ -1123,6 +1146,33 @@ pub fn generate_extension<'a>(
}; };
Some(q) Some(q)
} }
pub fn generate_define(define: &vkxml::Define) -> Tokens {
let name = constant_name(&define.name);
let ident = Ident::from(name.as_str());
let deprecated = define
.comment
.as_ref()
.map_or(false, |c| c.contains("DEPRECATED"));
if name == "NULL_HANDLE" || deprecated {
quote!()
} else if let Some(value) = &define.value {
str::parse::<u32>(value).map_or(quote!(), |v| quote!(pub const #ident: u32 = #v;))
} else if let Some(c_expr) = &define.c_expression {
if define.defref.contains(&"VK_MAKE_VERSION".to_string()) {
let c_expr = c_expr.replace("VK_", "");
let c_expr = c_expr.replace("MAKE_VERSION", "crate::vk::make_version");
use proc_macro2::TokenStream;
use std::str::FromStr;
let c_expr = TokenStream::from_str(&c_expr).unwrap();
quote!(pub const #ident: u32 = #c_expr;)
} else {
quote!()
}
} else {
quote!()
}
}
pub fn generate_typedef(typedef: &vkxml::Typedef) -> Tokens { pub fn generate_typedef(typedef: &vkxml::Typedef) -> Tokens {
let typedef_name = to_type_tokens(&typedef.name, None); let typedef_name = to_type_tokens(&typedef.name, None);
let typedef_ty = to_type_tokens(&typedef.basetype, None); let typedef_ty = to_type_tokens(&typedef.basetype, None);
@ -2024,6 +2074,7 @@ pub fn generate_definition(
const_values: &mut BTreeMap<Ident, Vec<ConstantMatchInfo>>, const_values: &mut BTreeMap<Ident, Vec<ConstantMatchInfo>>,
) -> Option<Tokens> { ) -> Option<Tokens> {
match *definition { match *definition {
vkxml::DefinitionsElement::Define(ref define) => Some(generate_define(define)),
vkxml::DefinitionsElement::Typedef(ref typedef) => Some(generate_typedef(typedef)), vkxml::DefinitionsElement::Typedef(ref typedef) => Some(generate_typedef(typedef)),
vkxml::DefinitionsElement::Struct(ref _struct) => { vkxml::DefinitionsElement::Struct(ref _struct) => {
Some(generate_struct(_struct, root_structs, union_types)) Some(generate_struct(_struct, root_structs, union_types))