Naga update with offsets and strides

This commit is contained in:
Dzmitry Malyshau 2020-06-19 11:14:29 -04:00
parent d7d0fd5dfe
commit ff5c9c9ffc
3 changed files with 19 additions and 9 deletions

2
Cargo.lock generated
View File

@ -742,7 +742,7 @@ dependencies = [
[[package]]
name = "naga"
version = "0.1.0"
source = "git+https://github.com/gfx-rs/naga?rev=e3aea9619865b16a24164d46ab29cca36ad7daf2#e3aea9619865b16a24164d46ab29cca36ad7daf2"
source = "git+https://github.com/gfx-rs/naga?rev=a9228d2aed38c71388489a95817238ff98198fa3#a9228d2aed38c71388489a95817238ff98198fa3"
dependencies = [
"bitflags",
"fxhash",

View File

@ -35,7 +35,7 @@ vec_map = "0.8.1"
[dependencies.naga]
git = "https://github.com/gfx-rs/naga"
rev = "e3aea9619865b16a24164d46ab29cca36ad7daf2"
rev = "a9228d2aed38c71388489a95817238ff98198fa3"
[dependencies.gfx-descriptor]
git = "https://github.com/gfx-rs/gfx-extras"

View File

@ -83,16 +83,26 @@ fn get_aligned_type_size(
Ti::Pointer { .. } => 4,
Ti::Array {
base,
size: naga::ArraySize::Static(size),
} => size as wgt::BufferAddress * get_aligned_type_size(module, base, false),
size: naga::ArraySize::Static(count),
stride,
} => {
let base_size = match stride {
Some(stride) => stride.get() as wgt::BufferAddress,
None => get_aligned_type_size(module, base, false),
};
base_size * count as wgt::BufferAddress
}
Ti::Array {
base,
size: naga::ArraySize::Dynamic,
} if allow_unbound => get_aligned_type_size(module, base, false),
Ti::Struct { ref members } => members
.iter()
.map(|member| get_aligned_type_size(module, member.ty, false))
.sum(),
stride,
} if allow_unbound => match stride {
Some(stride) => stride.get() as wgt::BufferAddress,
None => get_aligned_type_size(module, base, false),
},
Ti::Struct { ref members } => members.last().map_or(0, |member| {
member.offset as wgt::BufferAddress + get_aligned_type_size(module, member.ty, false)
}),
_ => panic!("Unexpected struct field"),
}
}