Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2165 #2167

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions vulkano/macros/src/derive_vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn derive_vertex(ast: syn::DeriveInput) -> Result<TokenStream> {
} else if attr_ident == "format" {
let format_ident = attr.parse_args_with(Ident::parse)?;
format = quote! {
let format = ::#crate_ident::format::Format::#format_ident;
::#crate_ident::format::Format::#format_ident;
};
}
}
Expand All @@ -66,23 +66,34 @@ pub fn derive_vertex(ast: syn::DeriveInput) -> Result<TokenStream> {
members = quote! {
#members

let field_size = ::std::mem::size_of::<#field_ty>() as u32;
{
#format
let format_size = format.block_size().expect("no block size for format") as u32;
let field_align = ::std::mem::align_of::<#field_ty>();
offset = (offset + field_align - 1) & !(field_align - 1);

let field_size = ::std::mem::size_of::<#field_ty>();
let format = #format;
let format_size = format
.block_size()
.expect("no block size for format") as usize;
let num_elements = field_size / format_size;
let remainder = field_size % format_size;
::std::assert!(remainder == 0, "struct field `{}` size does not fit multiple of format size", #field_name_lit);
::std::assert!(
remainder == 0,
"struct field `{}` size does not fit multiple of format size",
#field_name_lit,
);

members.insert(
#name.to_string(),
::#crate_ident::pipeline::graphics::vertex_input::VertexMemberInfo {
offset,
offset: offset.try_into().unwrap(),
format,
num_elements,
num_elements: num_elements.try_into().unwrap(),
},
);

offset += field_size;
}
offset += field_size as usize;
};
}
}
Expand Down