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

[spv-out] Always give structs with runtime arrays a Block decoration #2455

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/back/spv/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,12 +1016,27 @@ impl Writer {
ref members,
span: _,
} => {
let mut has_runtime_array = false;
let mut member_ids = Vec::with_capacity(members.len());
for (index, member) in members.iter().enumerate() {
let member_ty = &arena[member.ty];
match member_ty.inner {
crate::TypeInner::Array {
base: _,
size: crate::ArraySize::Dynamic,
stride: _,
} => {
has_runtime_array = true;
}
_ => (),
}
self.decorate_struct_member(id, index, member, arena)?;
let member_id = self.get_type_id(LookupType::Handle(member.ty));
member_ids.push(member_id);
}
if has_runtime_array {
self.decorate(id, Decoration::Block, &[]);
}
Instruction::type_struct(id, member_ids.as_slice())
}

Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/access.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ OpMemberDecorate %20 2 Offset 96
OpMemberDecorate %20 3 Offset 100
OpMemberDecorate %20 4 Offset 144
OpMemberDecorate %20 5 Offset 160
OpDecorate %20 Block
OpMemberDecorate %22 0 Offset 0
OpMemberDecorate %22 0 ColMajor
OpMemberDecorate %22 0 MatrixStride 8
Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/boids.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OpMemberDecorate %7 5 Offset 20
OpMemberDecorate %7 6 Offset 24
OpDecorate %8 ArrayStride 16
OpMemberDecorate %9 0 Offset 0
OpDecorate %9 Block
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 0
OpDecorate %14 Block
Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/bounds-check-restrict.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ OpMemberDecorate %10 2 Offset 64
OpMemberDecorate %10 2 ColMajor
OpMemberDecorate %10 2 MatrixStride 16
OpMemberDecorate %10 3 Offset 112
OpDecorate %10 Block
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 0
OpDecorate %10 Block
Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/bounds-check-zero.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ OpMemberDecorate %10 2 Offset 64
OpMemberDecorate %10 2 ColMajor
OpMemberDecorate %10 2 MatrixStride 16
OpMemberDecorate %10 3 Offset 112
OpDecorate %10 Block
OpDecorate %13 DescriptorSet 0
OpDecorate %13 Binding 0
OpDecorate %10 Block
Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/collatz.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ OpName %48 "global_id"
OpName %51 "main"
OpDecorate %4 ArrayStride 4
OpMemberDecorate %5 0 Offset 0
OpDecorate %5 Block
OpDecorate %7 DescriptorSet 0
OpDecorate %7 Binding 0
OpDecorate %5 Block
Expand Down
2 changes: 2 additions & 0 deletions tests/out/spv/debug-symbol-terrain.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ OpMemberDecorate %14 0 Offset 0
OpMemberDecorate %14 1 Offset 16
OpDecorate %15 ArrayStride 32
OpMemberDecorate %16 0 Offset 0
OpDecorate %16 Block
OpDecorate %17 ArrayStride 4
OpMemberDecorate %18 0 Offset 0
OpDecorate %18 Block
OpMemberDecorate %20 0 Offset 0
OpMemberDecorate %20 1 Offset 8
OpMemberDecorate %20 2 Offset 16
Expand Down
1 change: 1 addition & 0 deletions tests/out/spv/pointers.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ OpName %35 "v"
OpName %36 "index_dynamic_array"
OpDecorate %6 ArrayStride 4
OpMemberDecorate %7 0 Offset 0
OpDecorate %7 Block
OpDecorate %10 DescriptorSet 0
OpDecorate %10 Binding 0
OpDecorate %7 Block
Expand Down