Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 05f050f

Browse files
teoxoykvark
authored andcommitted
insert padding between struct members
1 parent e66a66a commit 05f050f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/back/hlsl/writer.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
712712
let struct_name = &self.names[&NameKey::Type(handle)];
713713
writeln!(self.out, "struct {} {{", struct_name)?;
714714

715+
let mut last_offset = 0;
715716
for (index, member) in members.iter().enumerate() {
717+
if member.binding.is_none() && member.offset > last_offset {
718+
// using int as padding should work as long as the backend
719+
// doesn't support a type that's less than 4 bytes in size
720+
// (Error::UnsupportedScalar catches this)
721+
let padding = (member.offset - last_offset) / 4;
722+
for i in 0..padding {
723+
writeln!(self.out, "{}int _pad{}_{};", back::INDENT, index, i)?;
724+
}
725+
}
726+
let ty_inner = &module.types[member.ty].inner;
727+
last_offset = member.offset + ty_inner.size(&module.constants);
728+
716729
// The indentation is only for readability
717730
write!(self.out, "{}", back::INDENT)?;
718731

0 commit comments

Comments
 (0)