Skip to content

Commit

Permalink
Test struct in struct, array in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmed92 committed Aug 24, 2024
1 parent fb6401f commit d200ffe
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/CodeGen/structs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ struct MyStruct {
bool d;
}

struct MyStruct2 {
MyStruct structMember;
int b;
}

struct StructWithArr {
int[4] a;
}

void main() {
// CHECK: %0 = spirv.CompositeConstruct %cst_f32, %cst2_si32, %cst3_ui32, %true : (f32, si32, ui32, i1) -> !spirv.struct<(f32, si32, ui32, i1)>
MyStruct myStruct = MyStruct(0.1, 2, 3u, true);
Expand All @@ -28,4 +37,26 @@ void main() {
// CHECK-NEXT: %13 = spirv.Variable : !spirv.ptr<i1, Function>
// CHECK-NEXT: spirv.Store "Function" %13, %12 : i1
bool d = myStruct.d;

// Struct in struct

// CHECK: %14 = spirv.CompositeConstruct %cst_f32_0, %cst2_si32_1, %cst3_ui32_2, %true_3 : (f32, si32, ui32, i1) -> !spirv.struct<(f32, si32, ui32, i1)>
// CHECK-NEXT: %cst1_si32 = spirv.Constant 1 : si32
// CHECK-NEXT: %15 = spirv.CompositeConstruct %14, %cst1_si32 : (!spirv.struct<(f32, si32, ui32, i1)>, si32) -> !spirv.struct<(!spirv.struct<(f32, si32, ui32, i1)>, si32)>
MyStruct2 myStruct2 = MyStruct2(MyStruct(0.1, 2, 3u, true), 1);

// CHECK: %17 = spirv.Load "Function" %16 : !spirv.struct<(!spirv.struct<(f32, si32, ui32, i1)>, si32)>
// CHECK-NEXT: %cst0_i32_4 = spirv.Constant 0 : i32
// CHECK-NEXT: %cst1_i32_5 = spirv.Constant 1 : i32
// CHECK-NEXT: %18 = spirv.CompositeExtract %17[0 : i32, 1 : i32] : !spirv.struct<(!spirv.struct<(f32, si32, ui32, i1)>, si32)>
b = myStruct2.structMember.b;


// Struct with array
// CHECK: %19 = spirv.CompositeConstruct %cst1_si32_6, %cst2_si32_7, %cst3_si32, %cst4_si32 : (si32, si32, si32, si32) -> !spirv.array<4 x si32>
// CHECK-NEXT: %20 = spirv.CompositeConstruct %19 : (!spirv.array<4 x si32>) -> !spirv.struct<(!spirv.array<4 x si32>)>
StructWithArr structWithArr = StructWithArr(int[4](1, 2, 3, 4));

// TODO: This currently fails at the Parser level. Implement member parsing for arrays.
// int arrElemFromStruct = structWithArr.a[0];
}

0 comments on commit d200ffe

Please sign in to comment.