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

[hlsl-out] Insert padding between struct members #1786

Merged
merged 1 commit into from
Mar 21, 2022
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
13 changes: 13 additions & 0 deletions src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
let struct_name = &self.names[&NameKey::Type(handle)];
writeln!(self.out, "struct {} {{", struct_name)?;

let mut last_offset = 0;
for (index, member) in members.iter().enumerate() {
if member.binding.is_none() && member.offset > last_offset {
// using int as padding should work as long as the backend
// doesn't support a type that's less than 4 bytes in size
// (Error::UnsupportedScalar catches this)
let padding = (member.offset - last_offset) / 4;
for i in 0..padding {
writeln!(self.out, "{}int _pad{}_{};", back::INDENT, index, i)?;
kvark marked this conversation as resolved.
Show resolved Hide resolved
}
}
let ty_inner = &module.types[member.ty].inner;
last_offset = member.offset + ty_inner.size(&module.constants);

// The indentation is only for readability
write!(self.out, "{}", back::INDENT)?;

Expand Down