mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Implement layouting for composite types
This commit is contained in:
committed by
Dzmitry Malyshau
parent
e0e840b22c
commit
56ce439ff5
@@ -115,7 +115,39 @@ pub fn calculate_offset(
|
||||
|
||||
(align, align * columns as u32)
|
||||
}
|
||||
TypeInner::Struct { .. } => todo!(),
|
||||
TypeInner::Struct {
|
||||
ref members,
|
||||
top_level,
|
||||
..
|
||||
} => {
|
||||
let mut span = 0;
|
||||
let mut align = 0;
|
||||
let mut members = members.clone();
|
||||
let name = types[ty].name.clone();
|
||||
|
||||
for member in members.iter_mut() {
|
||||
let info = calculate_offset(member.ty, meta, layout, types, constants)?;
|
||||
|
||||
span = align_up(span, info.align);
|
||||
align = align.max(info.align);
|
||||
|
||||
member.ty = info.ty;
|
||||
member.offset = span;
|
||||
|
||||
span += info.span;
|
||||
}
|
||||
|
||||
ty = types.fetch_or_append(Type {
|
||||
name,
|
||||
inner: TypeInner::Struct {
|
||||
top_level,
|
||||
members,
|
||||
span,
|
||||
},
|
||||
});
|
||||
|
||||
(align, span)
|
||||
}
|
||||
_ => {
|
||||
return Err(ErrorKind::SemanticError(
|
||||
meta,
|
||||
|
||||
@@ -993,6 +993,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
layout: StructLayout,
|
||||
) -> Result<u32> {
|
||||
let mut span = 0;
|
||||
let mut align = 0;
|
||||
|
||||
loop {
|
||||
// TODO: type_qualifier
|
||||
@@ -1016,6 +1017,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
)?;
|
||||
|
||||
span = offset::align_up(span, info.align);
|
||||
align = align.max(info.align);
|
||||
|
||||
members.push(StructMember {
|
||||
name: Some(name),
|
||||
@@ -1031,6 +1033,8 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
}
|
||||
}
|
||||
|
||||
span = offset::align_up(span, align);
|
||||
|
||||
Ok(span)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[[block]]
|
||||
struct PrimeIndices {
|
||||
indices: [[stride(4)]] array<u32>;
|
||||
indices: [[stride(16)]] array<u32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]]
|
||||
|
||||
Reference in New Issue
Block a user