Print the array stride for debugging purposes as well

This commit is contained in:
Pierre Krieger 2016-04-16 13:22:54 +02:00
parent 9f7e9107fd
commit 8e3c191cd1

View File

@ -64,6 +64,20 @@ fn write_struct(doc: &parse::Spirv, struct_id: u32, members: &[u32]) -> String {
None None
}).next(); }).next();
let spirv_stride = doc.instructions.iter().filter_map(|i| {
match *i {
parse::Instruction::Decorate { target_id,
decoration: enums::Decoration::DecorationArrayStride,
ref params } if target_id == member =>
{
return Some(params[0]);
},
_ => ()
};
None
}).next();
// Some structs don't have `Offset` decorations, in the case they are used as local // Some structs don't have `Offset` decorations, in the case they are used as local
// variables only. Ignoring these. // variables only. Ignoring these.
let spirv_offset = match spirv_offset { let spirv_offset = match spirv_offset {
@ -96,8 +110,8 @@ fn write_struct(doc: &parse::Spirv, struct_id: u32, members: &[u32]) -> String {
current_rust_offset = None; current_rust_offset = None;
} }
members_defs.push(format!("pub {name}: {ty} /* offset: {offset} */", members_defs.push(format!("pub {name}: {ty} /* offset: {offset}, stride: {stride:?} */",
name = member_name, ty = ty, offset = spirv_offset)); name = member_name, ty = ty, offset = spirv_offset, stride = spirv_stride));
} }
// We can only derive common traits if there's no unsized member in the struct. // We can only derive common traits if there's no unsized member in the struct.