Skip to content

Commit

Permalink
[spv-out] Fixed validation error: "OpTypeStruct containing an OpTypeR…
Browse files Browse the repository at this point in the history
…untimeArray must be decorated with Block or BufferBlock."
  • Loading branch information
TheoDulka committed Aug 25, 2023
1 parent 6aca2e2 commit 58aa529
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 0 deletions.
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

0 comments on commit 58aa529

Please sign in to comment.