Skip to content

Commit

Permalink
version_data is static yet dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Nov 23, 2020
1 parent 2c58d94 commit a9b79a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ash/src/vk/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45321,7 +45321,7 @@ impl<'a> AccelerationStructureDeviceAddressInfoKHRBuilder<'a> {
pub struct AccelerationStructureVersionInfoKHR {
pub s_type: StructureType,
pub p_next: *const c_void,
pub p_version_data: *const u8,
pub p_version_data: [u8; 2 * UUID_SIZE],
}
impl ::std::default::Default for AccelerationStructureVersionInfoKHR {
fn default() -> AccelerationStructureVersionInfoKHR {
Expand Down Expand Up @@ -45360,9 +45360,9 @@ impl<'a> ::std::ops::DerefMut for AccelerationStructureVersionInfoKHRBuilder<'a>
impl<'a> AccelerationStructureVersionInfoKHRBuilder<'a> {
pub fn version_data(
mut self,
version_data: &'a [u8; 2 * UUID_SIZE],
version_data: [u8; 2 * UUID_SIZE],
) -> AccelerationStructureVersionInfoKHRBuilder<'a> {
self.inner.p_version_data = version_data.as_ptr();
self.inner.p_version_data = version_data;
self
}
#[doc = r" Prepends the given extension struct between the root and the first pointer. This"]
Expand Down
47 changes: 21 additions & 26 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,24 @@ impl FieldExt for vkxml::Field {
let pointer_ty = quote! {
#pointer #ty
};
let array = self.array.as_ref().and_then(|arraytype| match arraytype {
vkxml::ArrayType::Static => {

let array = self.array.as_ref().and_then(|arraytype| {
// TODO: Move this heuristic into vk-parse?
let static_size = self.size.as_ref().map_or(false, |sz| sz.contains("ename:"));

if matches!(arraytype, vkxml::ArrayType::Static)
|| matches!(arraytype, vkxml::ArrayType::Dynamic) && static_size
{
dbg!(&self.size, &self.c_size);
let size = self
.size
.c_size
.as_ref()
.or_else(|| self.size.as_ref())
.or_else(|| self.size_enumref.as_ref())
.expect("Should have size");
// Make sure we also rename the constant, that is
// used inside the static array
let size = constant_name(size);
let size = Term::intern(&size);
let size = convert_c_expression(size);
// arrays in c are always passed as a pointer
if is_ffi_param {
Some(quote! {
Expand All @@ -757,8 +764,9 @@ impl FieldExt for vkxml::Field {
[#ty; #size]
})
}
} else {
None
}
_ => None,
});
array.unwrap_or(pointer_ty)
}
Expand Down Expand Up @@ -1755,7 +1763,9 @@ pub fn derive_setters(
});
}

if matches!(field.array, Some(vkxml::ArrayType::Dynamic)) {
let static_size= field.size.as_ref().map_or(false, |sz|sz.contains("ename:"));

if matches!(field.array, Some(vkxml::ArrayType::Dynamic)) && !static_size {
if let Some(ref array_size) = field.size {
if !array_size.starts_with("latexmath") {
let param_ty = param_ty_string.splitn(2, ' ').collect_vec();
Expand All @@ -1781,28 +1791,13 @@ pub fn derive_setters(
ptr = quote!(#ptr as *#mutable c_void);
};

let mutable_ref = if mutable { quote!(mut) } else { quote!() };

let (slice_param_ty_tokens, set_size_stmt) = if array_size.contains("ename:") {
// Should contain the same minus `ename:`-prefixed identifiers
let array_size = field.c_size.as_ref().unwrap();
let c_size = convert_c_expression(array_size);

(
quote!(&'a #mutable_ref [#slice_type; #c_size]),
quote!(),
)
} else {
let array_size_ident = Ident::from(array_size.to_snake_case().as_str());
(
quote!(&'a #mutable_ref [#slice_type]),
quote!(self.inner.#array_size_ident = #param_ident_short.len() as _;),
)
};
let array_size_ident = Ident::from(array_size.to_snake_case().as_str());
let mutable = if mutable { quote!(mut) } else { quote!() };
let slice_param_ty_tokens = quote!(&'a #mutable [#slice_type]);

return Some(quote! {
pub fn #param_ident_short(mut self, #param_ident_short: #slice_param_ty_tokens) -> #name_builder<'a> {
#set_size_stmt
self.inner.#array_size_ident = #param_ident_short.len() as _;
self.inner.#param_ident = #param_ident_short#ptr;
self
}
Expand Down

0 comments on commit a9b79a3

Please sign in to comment.